]> git.tdb.fi Git - libs/gl.git/blob - demos/forestpond/data/water_variance_x.glsl
Implement water simulation and surface shader for forest pond
[libs/gl.git] / demos / forestpond / data / water_variance_x.glsl
1 #pragma MSP stage(compute)
2 layout(local_size_x=8, local_size_y=8) in;
3
4 uniform sampler2D surface_in;
5 uniform sampler2D bottom_in;
6 uniform sampler2D normals_in;
7 layout(r16f) uniform image2D variance_out;
8
9 void main()
10 {
11         ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+ivec2(4, 1);
12         float variance = 0.0;
13         for(int i=-3; i<=3; ++i)
14         {
15                 ivec2 c = coord+ivec2(i, 0);
16                 float depth = texelFetch(surface_in, c, 0).x-texelFetch(bottom_in, c, 0).x;
17                 vec2 normal_xy = texelFetch(normals_in, c, 0).xy*2.0-1.0;
18                 float xy_sq = dot(normal_xy, normal_xy);
19                 float slope_sq = xy_sq/max(1-xy_sq, 0.001);
20                 variance += slope_sq*clamp(depth, 0.0, 1.0);
21         }
22         imageStore(variance_out, coord, vec4(variance/7.0, 0.0, 0.0, 0.0));
23 }