Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created February 5, 2012 12:49
Show Gist options
  • Select an option

  • Save roxlu/1745363 to your computer and use it in GitHub Desktop.

Select an option

Save roxlu/1745363 to your computer and use it in GitHub Desktop.
Light Rays 0.6 - Fabien Sanglard's light ray shader
uniform float exposure;
uniform float decay;
uniform float density;
uniform float weight;
uniform vec2 lightPositionOnScreen;
uniform sampler2D firstPass;
const int NUM_SAMPLES = 100 ;
void main() {
vec2 deltaTextCoord = vec2( gl_TexCoord[0].st - lightPositionOnScreen.xy );
vec2 textCoo = gl_TexCoord[0].st;
deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
float illuminationDecay = 1.0;
for(int i=0; i < NUM_SAMPLES ; i++) {
textCoo -= deltaTextCoord;
vec4 sample = texture2D(firstPass, textCoo );
sample *= illuminationDecay * weight;
gl_FragColor += sample;
illuminationDecay *= decay;
}
gl_FragColor *= exposure;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment