]> git.tdb.fi Git - libs/gl.git/blobdiff - demos/forestpond/data/water_normals.glsl
Implement water simulation and surface shader for forest pond
[libs/gl.git] / demos / forestpond / data / water_normals.glsl
diff --git a/demos/forestpond/data/water_normals.glsl b/demos/forestpond/data/water_normals.glsl
new file mode 100644 (file)
index 0000000..7c0da0f
--- /dev/null
@@ -0,0 +1,14 @@
+#pragma MSP stage(compute)
+layout(local_size_x=8, local_size_y=8) in;
+
+uniform sampler2D surface_in;
+layout(rg8) uniform image2D normals_out;
+
+void main()
+{
+       ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+1;
+       float dzdx = (texelFetch(surface_in, coord+ivec2(1, 0), 0).x-texelFetch(surface_in, coord-ivec2(1, 0), 0).x);
+       float dzdy = (texelFetch(surface_in, coord+ivec2(0, 1), 0).x-texelFetch(surface_in, coord-ivec2(0, 1), 0).x);
+       vec3 normal = normalize(vec3(-dzdx, -dzdy, 2.0));
+       imageStore(normals_out, coord, vec4(normal.xy*0.5+0.5, 0.0, 0.0));
+}