Waterflow
Visualize water in terrain
|
00001 00002 00003 00004 #version 150 00005 00006 // ===== Uniforms ===== 00007 00008 uniform sampler2D height_texUnit; 00009 uniform vec3 size; 00010 uniform float maxDepth; 00011 00012 00013 // ===== In/Out params ===== 00014 00015 in vec2 out_TexCoord; 00016 in vec3 out_ObjPos; 00017 00018 out vec4 out_Color; 00019 00020 00021 // ===== Variables needed ===== 00022 00023 float depth; 00024 vec4 terrainDataUnderSurface; 00025 00026 00027 void main(void) 00028 { 00029 // Texture lookup at fragment. 00030 terrainDataUnderSurface = texture(height_texUnit, out_TexCoord); 00031 00032 // Depth at fragment. 00033 depth = out_ObjPos.y - size.y * terrainDataUnderSurface.a; 00034 00035 if (depth < 0 || out_ObjPos.z < 1 || out_ObjPos.x < 1 ) 00036 { 00037 discard; 00038 } 00039 00040 out_Color = vec4(vec3(1.0, 1.0, 1.0) * (1 - depth / maxDepth), 1.0); 00041 }