-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_light_scattering_v2.glsl
58 lines (39 loc) · 1.25 KB
/
filter_light_scattering_v2.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Modernized shader by
uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;
//uniform float avgL;
const float dens = 0.8; // Density
const float dec = 0.98; // Decay
//const float weight = 0.2;
uniform float weight;
float exp = 0.05; // Exposure
// Light Screen (Origin if effect is not working Play with X & Y)
uniform float sun_x; // 0.0 - 1.0
uniform float sun_y; // 0.0 - 1.0
uniform vec2 lightScreenPos;
// Number of Ray Samples (Quality 1 - 128)
const int raySamples = 33;
void main()
{
vec4 origin = vec4(0);
vec4 sample = vec4(0);
vec4 mask = vec4(0);
vec2 lightScreenPos = vec2(sun_x,sun_y);
vec2 deltaTexCoord = vec2(gl_TexCoord[0]) - lightScreenPos;
vec2 texCoo = gl_TexCoord[0].st;
deltaTexCoord *= 1.0 / float(raySamples) * dens;
float illumDecay = 1.0;
for(int i=0; i < raySamples ; i++)
{
texCoo -= deltaTexCoord;
if (texture2D(bgl_DepthTexture, texCoo).r > 0.9989)
{
sample += texture2D(bgl_RenderedTexture, texCoo);
}
sample *= illumDecay * weight;
origin += sample;
illumDecay *= dec;
}
vec2 texcoord = vec2(gl_TexCoord[0]);
gl_FragColor = texture2D(bgl_RenderedTexture, texcoord) + (origin*exp);
}