commit 42d53bfcb99d1e4932865b7bdc7fe4bfcb7332a5
parent b1e080d86e7cd3320d18a2d4877eb924fe4ff790
Author: Michael Savage <mikejsavage@gmail.com>
Date: Wed, 1 Nov 2017 23:51:35 +0200
Fog in clipmap shader
Diffstat:
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/shaders/clipmap.glsl b/shaders/clipmap.glsl
@@ -15,7 +15,8 @@ layout( std140 ) uniform clipmap {
};
struct VSOut {
- vec3 pos;
+ vec4 view_position;
+ vec3 world_position;
vec2 uv;
};
@@ -35,9 +36,10 @@ void main() {
vec2 uv = snapped_xy / textureSize( heightmap, 0 ) + 0.5;
float z = 255.0 * texture( heightmap, uv ).r + texture( heightmap, uv ).g;
- v2f.pos = vec3( xy, z );
+ v2f.view_position = V * vec4( snapped_xy, z, 1.0 );
+ v2f.world_position = vec3( xy, z );
v2f.uv = uv;
- gl_Position = P * V * vec4( snapped_xy, z, 1.0 );
+ gl_Position = P * v2f.view_position;
}
#else
@@ -54,7 +56,7 @@ void main() {
// ground colour
vec3 ground;
- if( v2f.pos.z > 175 ) {
+ if( v2f.world_position.z > 175 ) {
// snow/rocks
if( normal.z > 0.5 ) {
ground = vec3( 0.8, 0.8, 0.8 );
@@ -63,7 +65,7 @@ void main() {
ground = vec3( 0.6, 0.6, 0.6 );
}
}
- else if( v2f.pos.z < 5 ) {
+ else if( v2f.world_position.z < 5 ) {
ground = vec3( 0.0, 0.25, 1.0 );
}
else {
@@ -87,7 +89,7 @@ void main() {
vec3 dither_noise = texture( blue_noise, gl_FragCoord.xy / textureSize( blue_noise, 0 ) ).xxx;
dither_noise = ( dither_noise - vec3( 0.5 ) ) / 128.0;
- screen_colour = vec4( linear_to_srgb( c + dither_noise ), 1.0 );
+ screen_colour = vec4( linear_to_srgb( apply_fog( c + dither_noise, length( v2f.view_position ) ) ), 1.0 );
}
#endif