X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fscene_depth.h;h=59a3236c740a3bbcf8052c1ff28986c828329656;hb=f3a2490079baf440238b78e54f4476649eddbda2;hp=53b2bfafaf22ebf33896abb1e4cc4dbef2050fcf;hpb=aa4c26eae2208872824e0eb5b71bc05c16d43242;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/scene_depth.h b/shaders/scene_depth.h index 53b2bfa..59a3236 100644 --- a/shaders/scene_depth.h +++ b/shaders/scene_depth.h @@ -76,6 +76,9 @@ static struct vg_shader _shader_scene_depth = { "flat in ivec4 aLights;\n" "\n" "#line 1 1 \n" +"// :D\n" +"\n" +"#line 1 1 \n" "layout (location = 0) out vec4 oColour;\n" "\n" "layout (std140) uniform ub_world_lighting\n" @@ -103,6 +106,13 @@ static struct vg_shader _shader_scene_depth = { " return texture( g_world_depth, depth_coord ).r;\n" "}\n" "\n" +"float world_water_depth( vec3 pos )\n" +"{\n" +" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n" +" float ref_depth = g_water_plane.y*g_water_plane.w;\n" +" return texture( g_world_depth, depth_coord ).g - ref_depth;\n" +"}\n" +"\n" "float shadow_sample( vec3 vdir )\n" "{\n" " vec3 sample_pos = aWorldCo + vdir;\n" @@ -202,6 +212,51 @@ static struct vg_shader _shader_scene_depth = { " return light_colour*attenuation;\n" "}\n" "\n" +"#line 4 0 \n" +"\n" +"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n" +"{\n" +" // Lighting\n" +" vec3 halfview = uCamera - aWorldCo;\n" +" float fdist = length(halfview);\n" +" halfview /= fdist;\n" +"\n" +" vec3 total_light = newlight_compute_ambient();\n" +" \n" +" // Compute world lighting contribution and apply it according to the\n" +" // shadow map\n" +" //\n" +" vec3 world_light = newlight_compute_world_diffuse( wnormal );\n" +" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n" +"\n" +" float world_shadow = newlight_compute_sun_shadow();\n" +"\n" +" total_light += world_light * world_shadow;\n" +"\n" +" // Compute the other lights that exist in the map, not effected by the sun\n" +" // shadow\n" +" total_light += newlight_compute_quadratic\n" +" ( \n" +" wnormal, halfview,\n" +" g_point_light_positions[ aLights.x ].xyz,\n" +" g_point_light_colours[ aLights.x ].rgb \n" +" );\n" +" total_light += newlight_compute_quadratic\n" +" ( \n" +" wnormal, halfview,\n" +" g_point_light_positions[ aLights.y ].xyz,\n" +" g_point_light_colours[ aLights.y ].rgb \n" +" );\n" +" total_light += newlight_compute_quadratic\n" +" ( \n" +" wnormal, halfview,\n" +" g_point_light_positions[ aLights.z ].xyz,\n" +" g_point_light_colours[ aLights.z ].rgb \n" +" );\n" +"\n" +" return apply_fog( diffuse * total_light, fdist );\n" +"}\n" +"\n" "#line 14 0 \n" "\n" "// Water blending\n" @@ -219,9 +274,9 @@ static struct vg_shader _shader_scene_depth = { "\n" "void main()\n" "{\n" -" vec3 halfview = normalize( uCamera - aCo );\n" -" vec3 world_pos = vec3( aCo.y, aCo.x, aCo.z );\n" -" FragColor = vec4( world_pos, water_depth( aCo, halfview ) );\n" +" vec3 halfview = normalize( uCamera - aWorldCo );\n" +" float depth = water_depth( aWorldCo, halfview );\n" +" FragColor = vec4( depth, 0.0, 0.0, 0.0 );\n" "}\n" ""}, };