Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Arnebäck Erkaman

View GitHub Profile
View aabb-tri.js
// MIT licensed.
function fabsf (arg) {
return arg >= 0 ? arg : -arg
}
function planeBoxOverlap (normal, vert, maxbox) {
var q
var vmin = []
var vmax = []
var v
View sleepy-bfs.cpp
#include <stdio.h>
#include <vector>
#include <queue>
#include <iostream>
#include <thread>
#include <chrono>
#include <functional>
#include <atomic>
struct Node {
@Erkaman
Erkaman / nan-payload.cpp
Last active Aug 5, 2019
shows how to save a payload into a NaN value.
View nan-payload.cpp
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
int main()
{
{
float f = sqrtf(-1); // this results in f being set to nan.
@Erkaman
Erkaman / CustomTriLerp.shader
Last active Nov 17, 2020
Texture minification using Custom Trilinear Interpolation. From my tweet: https://twitter.com/erkaman2/status/1090645031227191296
View CustomTriLerp.shader
Shader "Custom/CustomTriLerp"
{
Properties
{
[NoScaleOffset] _MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Pass
{
@Erkaman
Erkaman / taa.frag
Last active Sep 16, 2021
rudimentary temporal anti-aliasing solution, that is good as a starting point for more advanced TAA techniques.
View taa.frag
/*
The MIT License (MIT)
Copyright (c) 2018 Eric Arnebäck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Erkaman
Erkaman / three_vids.sh
Created Jun 8, 2018
example script, that uses ffmpeg to make a video that shows three videos side by side
View three_vids.sh
# Example video made by this script: https://twitter.com/erkaman2/status/990873258416361472
ffmpeg \
-y \
-i vid1.mp4 \
-i vid2.mp4 \
-i vid3.mp4 \
-filter_complex '[0:v]pad=iw*3:ih[int];[int][1:v]overlay=W*0.33:0[temp];[temp][2:v]overlay=W*0.66:0[vid]' \
-map [vid] \
-c:v libx264 \
@Erkaman
Erkaman / kmeans_color_quantization.cpp
Last active Jan 29, 2018
This program implements color quantization with K-means clustering using Lloyd's algorithm
View kmeans_color_quantization.cpp
/*
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
View gauss_newton_algorithm.cpp
/*
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
@Erkaman
Erkaman / partition_of_unity.cpp
Last active Apr 22, 2018
Program that provides empirical evidence that the clamped cosine lobes 0.5cos^2 and (5/6)cos^4 form a partition of unity over the unit sphere. This is related to the ambient dice paper: http://www.ppsloan.org/publications/AmbientDice.pdf
View partition_of_unity.cpp
#include <stdio.h>
#include <math.h>
float max(float x, float y) {
return x > y ? x : y;
}
class vec3 {
public:
float x;
@Erkaman
Erkaman / broken.cpp
Created Nov 14, 2017
Program that results in "An internal error has occurred in the compiler" for VC++ in VS 15.4.4
View broken.cpp
class Foo{};
int main(){
Foo foos[1] = { Foo()};
auto lambdaFunctionThatDoesNothing = [foos]() { };
}