Created
January 11, 2019 15:10
-
-
Save Francesco149/3aeb783d99fce60af2675c507b516855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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