]> git.tdb.fi Git - libs/gl.git/blob - demos/forestpond/data/water_normals.glsl
Implement water simulation and surface shader for forest pond
[libs/gl.git] / demos / forestpond / data / water_normals.glsl
1 #pragma MSP stage(compute)
2 layout(local_size_x=8, local_size_y=8) in;
3
4 uniform sampler2D surface_in;
5 layout(rg8) uniform image2D normals_out;
6
7 void main()
8 {
9         ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+1;
10         float dzdx = (texelFetch(surface_in, coord+ivec2(1, 0), 0).x-texelFetch(surface_in, coord-ivec2(1, 0), 0).x);
11         float dzdy = (texelFetch(surface_in, coord+ivec2(0, 1), 0).x-texelFetch(surface_in, coord-ivec2(0, 1), 0).x);
12         vec3 normal = normalize(vec3(-dzdx, -dzdy, 2.0));
13         imageStore(normals_out, coord, vec4(normal.xy*0.5+0.5, 0.0, 0.0));
14 }