Skip to content

Instantly share code, notes, and snippets.

@ioxu
Last active December 7, 2021 17:01
Show Gist options
  • Save ioxu/ca848bcfb4bc7d7331a3c43313fe28b0 to your computer and use it in GitHub Desktop.
Save ioxu/ca848bcfb4bc7d7331a3c43313fe28b0 to your computer and use it in GitHub Desktop.
stash of some Godot Engine shader functions
float gamma(float i, float g) {
return pow(i, 1.0/g);
}
float map(float value, float inMin, float inMax, float outMin, float outMax) {
return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}
float fcontrast(float f, float contrast, float pivot){
return clamp((f - pivot) * contrast + pivot, 0.0, 1.0);
}
// fast bias, C. Schlick, Graphics Gems IV
float bias(float t, float b){
return ( t / ((((1.0/b) - 2.0) *(1.0 - t)) + 1.0 ));
}
// fast gain, C. Schlick, Graphics Gems IV
float gain(float t, float g){
if(t < 0.5){
return bias(t * 2.0, g)/2.0;
} else{
return bias( t * 2.0 - 1.0, 1.0 - g )/2.0 + 0.5;
}
}
// conic UV domain
float conic_grad_u = ( atan( UV.x-0.5, UV.y-0.5 ) + PI ) / (PI*2.0) *1.2;
float conic_grad_v = length(vec2(UV.x-0.5, UV.y-0.5)) * 0.65;
vec2 conic_uvs = vec2(conic_grad_u *0.5 + time *0.00, conic_grad_v* 0.5 + (time * -3.0) );
// tonemapping
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 ACESFilm(vec3 x){
float a = 2.51;
float b = 0.03;
float c = 2.43;
float d = 0.59;
float e = 0.14;
return clamp((x*(a*x+b))/(x*(c*x+d)+e), 0.0, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment