X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fcommon_scene.glsl;h=76658f2151aa1176439cea0d1489673131037d9d;hb=b3ca3b7a45eec11c46eb19772e10021177665adb;hp=4a78fbcf01ca8a721a055dfb21a4b758b52dcb58;hpb=aa4c26eae2208872824e0eb5b71bc05c16d43242;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/common_scene.glsl b/shaders/common_scene.glsl index 4a78fbc..76658f2 100644 --- a/shaders/common_scene.glsl +++ b/shaders/common_scene.glsl @@ -1,46 +1,33 @@ // :D +in vec2 aUv; +in vec4 aNorm; +in vec3 aCo; +in vec3 aWorldCo; + #include "common_world.glsl" -vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal ) +float sdLine( vec3 p, vec3 a, vec3 b ) { - // Lighting - vec3 halfview = uCamera - aWorldCo; - float fdist = length(halfview); - halfview /= fdist; - - vec3 total_light = newlight_compute_ambient(); - - // Compute world lighting contribution and apply it according to the - // shadow map - // - vec3 world_light = newlight_compute_world_diffuse( wnormal ); - world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 ); + vec3 pa = p - a; + vec3 ba = b - a; - float world_shadow = newlight_compute_sun_shadow(); + float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); + return length( pa - ba*h ); +} - total_light += world_light * world_shadow; +float compute_board_shadow() +{ + // player shadow + float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz, + g_board_1.xyz )-0.1 ); + float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 ); + player_shadow *= player_shadow*player_shadow*player_shadow; - // Compute the other lights that exist in the map, not effected by the sun - // shadow - total_light += newlight_compute_quadratic - ( - wnormal, halfview, - g_point_light_positions[ aLights.x ].xyz, - g_point_light_colours[ aLights.x ].rgb - ); - total_light += newlight_compute_quadratic - ( - wnormal, halfview, - g_point_light_positions[ aLights.y ].xyz, - g_point_light_colours[ aLights.y ].rgb - ); - total_light += newlight_compute_quadratic - ( - wnormal, halfview, - g_point_light_positions[ aLights.z ].xyz, - g_point_light_colours[ aLights.z ].rgb - ); + return 1.0 - player_shadow*0.8; +} - return apply_fog( diffuse * total_light, fdist ); +vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co ) +{ + return world_compute_lighting( diffuse, normal, co, compute_board_shadow() ); }