Skip to content

Instantly share code, notes, and snippets.

@Francesco149
Created January 11, 2019 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Francesco149/3aeb783d99fce60af2675c507b516855 to your computer and use it in GitHub Desktop.
Save Francesco149/3aeb783d99fce60af2675c507b516855 to your computer and use it in GitHub Desktop.
vec4 godrays(float density, float weight, float decay, float exposure,
int numSamples, sampler2D occlusionTexture, vec2 sunPositionScreenSpace,
vec2 uv)
{
vec4 color = vec4(0.0);
vec2 delta = (sunPositionScreenSpace - uv) / float(numSamples) * density;
float intensity = 1.0;
for (int i = 0; i < 1337; ++i) {
if (i >= numSamples) break;
uv += delta;
color += texture2D(occlusionTexture, uv) * intensity * weight;
intensity *= decay;
}
color *= exposure;
return color;
}
varying vec2 vertexUv;
uniform sampler2D textureSampler;
uniform vec2 sunPositionScreenSpace;
void main() {
gl_FragColor = godrays(1.0, 0.005, 1.0, 1.0, 256, textureSampler,
sunPositionScreenSpace, vertexUv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment