medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit aa63ef9a6ea3e538fe248a0af9dd136b1af57197
parent 764b0daff15d8ab9639bc193e5bf1b6d7a95770d
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Sep 11 15:45:21 +0100

Slightly better terrain shader

Diffstat:
terrain_manager.cc | 48+++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -51,34 +51,39 @@ static const GLchar * frag_src = GLSL( void main() { vec3 normal = normalize( texture( normals, smooth_position.xy / dimensions ).xyz ); + vec3 sun_direction = normalize( vec3( 1, 1, -sun ) ); + float horizon = texture( horizons, smooth_position.xy / dimensions ).r; + // ground colour vec3 ground; - if( normal.z > 0.9 ) { - ground = vec3( 0.4, 1.0, 0.4 ); + if( smooth_position.z > 175 ) { + // snow/rocks + if( normal.z > 0.5 ) { + ground = vec3( 0.8, 0.8, 0.8 ); + } + else { + ground = vec3( 0.6, 0.6, 0.6 ); + } } else { - ground = vec3( 0.7, 0.7, 0.5 ); + if( normal.z > 0.8 ) { + ground = vec3( 0.4, 1.0, 0.4 ); + } + else { + ground = vec3( 0.7, 0.7, 0.5 ); + } } - vec3 sunv = normalize( vec3( 1, 1, -sun ) ); - float horizon = texture( horizons, smooth_position.xy / dimensions ).r; - float l = sun > horizon ? 1.0 : 0.0; - - float d = max( 0, -dot( normal, sunv ) ); - float light = max( 0.2, l * d ); - - // colour *= 0; - // colour = vec4( horizon, horizon, horizon, 1.0 ); + // sunlight + sky ambient lighting + // TODO: use formula for area of a chord? + float sun_visible_fraction = smoothstep( 0, 0.5, sun - horizon ); + float sunlight_lambert = max( 0, -dot( normal, sun_direction ) ); + vec3 sunlight = sun_visible_fraction * sunlight_lambert * vec3( 0.9, 0.9, 0.5 ); + vec3 ambient = vec3( 0.0, 0.1, 0.3 ); - // if( smooth_position.y > 10.5 && smooth_position.y < 11.5 ) { - // colour.r = 1; - // } - // - // int a = int( smooth_position.x ) / 10; - // if( a % 2 == 0 ) colour.g = 1; + vec3 c = ( sunlight + ambient ) * ground; - vec3 c = ground * light; - // place some lights + // lights for( int i = 0; i < 5; i++ ) { vec3 light_position = texelFetch( point_light_origins, i ).xyz; vec3 light_colour = texelFetch( point_light_colours, i ).rgb; @@ -86,9 +91,10 @@ static const GLchar * frag_src = GLSL( vec3 light_direction = normalize( light_position - smooth_position ); float lambert_scale = dot( light_direction, normal ); float distance_scale = 1.0 / sqrt( light_sqdistance ); - c += vec3( light_colour * lambert_scale * distance_scale ); + c += vec3( light_colour * lambert_scale * distance_scale ) * ground; } + // fog vec3 fog = vec3( 0.6, 0.6, 0.6 ); float depth = length( pos );