Waterflow
Visualize water in terrain
src/shaders/normConv.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 height0 
00012 { 
00013     float terrHeightIn[];  
00014 };   
00015 
00016 layout (std430, binding = 1) writeonly buffer height1 
00017 { 
00018     float terrHeightOut[];  
00019 };  
00020 
00021 layout (std430, binding = 2) buffer NoDataCheck 
00022 { 
00023     uint isNODATA; 
00024 };  
00025 
00026 uniform ivec2 size;  
00027 
00028 void main() { 
00029 
00030     ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);  
00031 
00032     int x = clamp(storePos.x, 0, size.x-1); 
00033     int y = clamp(storePos.y, 0, size.y-1); 
00034     int xplus = clamp(x + 1, 0, size.x-1); 
00035     int xminus = clamp(x - 1, 0, size.x-1); 
00036     int yplus = clamp(y + 1, 0, size.y-1); 
00037     int yminus = clamp(y - 1, 0, size.y-1);  
00038     
00039     float filtered_color;
00040 
00041     float conf[9];
00042     float confSum;
00043     conf[0] = float(terrHeightIn[x + y * size.x] > -0.5f);
00044     conf[1] = float(terrHeightIn[xplus + y * size.x] > -0.5f);
00045     conf[2] = float(terrHeightIn[xminus + y * size.x] > -0.5f);
00046     conf[3] = float(terrHeightIn[x + yplus * size.x] > -0.5f);
00047     conf[4] = float(terrHeightIn[x + yminus * size.x] > -0.5f);
00048     conf[5] = float(terrHeightIn[xplus + yplus * size.x] > -0.5f);
00049     conf[6] = float(terrHeightIn[xplus + yminus * size.x] > -0.5f); 
00050     conf[7] = float(terrHeightIn[xminus + yplus * size.x] > -0.5f); 
00051     conf[8] = float(terrHeightIn[xminus + yminus * size.x] > -0.5f); 
00052 
00053     confSum  = 4 * conf[0]; 
00054     confSum += 2 * conf[1]; 
00055     confSum += 2 * conf[2]; 
00056     confSum += 2 * conf[3]; 
00057     confSum += 2 * conf[4]; 
00058     confSum += 1 * conf[5]; 
00059     confSum += 1 * conf[6]; 
00060     confSum += 1 * conf[7]; 
00061     confSum += 1 * conf[8]; 
00062 
00063     filtered_color =  4.0 * conf[0] * terrHeightIn[x + y * size.x]; 
00064     filtered_color += 2.0 * conf[1] * terrHeightIn[xplus + y * size.x];
00065     filtered_color += 2.0 * conf[2] * terrHeightIn[xminus + y * size.x]; 
00066     filtered_color += 2.0 * conf[3] * terrHeightIn[x + yplus * size.x]; 
00067     filtered_color += 2.0 * conf[4] * terrHeightIn[x + yminus * size.x]; 
00068     filtered_color += 1.0 * conf[5] * terrHeightIn[xplus + yplus * size.x]; 
00069     filtered_color += 1.0 * conf[6] * terrHeightIn[xplus + yminus * size.x]; 
00070     filtered_color += 1.0 * conf[7] * terrHeightIn[xminus + yplus * size.x]; 
00071     filtered_color += 1.0 * conf[8] * terrHeightIn[xminus + yminus * size.x]; 
00072     filtered_color = filtered_color / confSum;  
00073   
00074     terrHeightOut[x + y * size.x] = terrHeightIn[x + y * size.x];
00075 
00076     if(confSum > 0.5f && conf[0] < 0.5f)
00077     {
00078         terrHeightOut[x + y * size.x] = filtered_color;  
00079     } else if (confSum < 0.5f && conf[0] < 0.5f) 
00080     {
00081         atomicAdd(isNODATA, 1); 
00082     }
00083 }  
 All Classes Files Functions Variables Enumerations