Waterflow
Visualize water in terrain
src/shaders/textureData.comp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 #version 430
00008 
00009 layout(local_size_x = 16, local_size_y = 16) in; 
00010 
00011 layout (std430, binding = 0) readonly buffer inHeight 
00012 {
00013     float terrHeight[];
00014 };
00015 
00016 layout (std430, binding = 1) readonly buffer inNormals 
00017 {
00018     float normals[];
00019 };
00020 
00021 layout (rgba32f, binding = 0) writeonly uniform image2D textureOut; 
00022 uniform ivec2 size; 
00023 uniform float maxHeight; 
00024 
00025 void main () {
00026     ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);
00027 
00028     int x = clamp(storePos.x, 0, size.x-1); 
00029     int y = clamp(storePos.y, 0, size.y-1); 
00030     int offset = x + size.x * y;
00031 
00032     vec3 normal = vec3(normals[offset*3], normals[offset*3 + 1], normals[offset*3 + 2]);
00033     float height = terrHeight[offset] / maxHeight; // divide by max height since textures work with normalized (0-1) values
00034 
00035     imageStore(textureOut, storePos, vec4(normal, height));
00036 
00037 }
 All Classes Files Functions Variables Enumerations