medfall

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

commit 3fab8fc96fd345f76ceecd678ee85f9393fe29a4
parent c83bfce1a14a562c54f7f9a9cb7eb64176861288
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Nov 30 20:37:35 +0200

Copy the terrain shader to btt.so

Diffstat:
mod_btt.cc | 41+++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/mod_btt.cc b/mod_btt.cc @@ -46,27 +46,40 @@ static const char * frag_src = GLSL( void main() { vec3 normal = normalize( texture( normals, smooth_position.xy / dimensions ).xyz ); + 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 if( smooth_position.z < 5 ) { + ground = vec3( 0.0, 0.25, 1.0 ); } 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 ); - - vec3 fog = vec3( 0.6, 0.6, 0.6 ); - - float t = smoothstep( 400, 600, depth ); + // sunlight + sky ambient lighting + // TODO: use formula for area of a chord? + float sun_visible_fraction = smoothstep( 0, 0.2, sun - horizon ); + vec3 sun_direction = normalize( vec3( -1, 0, sun ) ); + 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.02, 0.02, 0.15 ); - colour = vec4( ( 1.0 - t ) * ground * light + t * fog, 1.0 ); + colour = vec4( ( sunlight + ambient ) * ground, 1.0 ); } );