X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fmodel_character_view.h;h=55f88315930ada60967f19ca9a849fe215ea3eb2;hb=02e009ae6e20938675277e9ce2f467e17b170cc7;hp=23cba2514f184805f593d432f4e1dbaadcad6589;hpb=a1056ed8198f0f5be0e0f341da8bd49aa6c47198;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/model_character_view.h b/shaders/model_character_view.h index 23cba25..55f8831 100644 --- a/shaders/model_character_view.h +++ b/shaders/model_character_view.h @@ -65,7 +65,7 @@ static struct vg_shader _shader_model_character_view = { " aCo = a_co;\n" " aWorldCo = world_pos;\n" "\n" -" // TODO:\n" +" // TODO: motion vectors\n" " aMotionVec0 = vec3(1.0);\n" " aMotionVec1 = vec3(1.0);\n" "}\n" @@ -75,7 +75,10 @@ static struct vg_shader _shader_model_character_view = { .orig_file = "shaders/model_character_view.fs", .static_src = "uniform sampler2D uTexMain;\n" +"uniform sampler2D uTexSceneDepth;\n" "uniform vec3 uCamera;\n" +"uniform vec3 uInverseRatioDepth;\n" +"uniform vec3 uInverseRatioMain;\n" "\n" "in vec4 aColour;\n" "in vec2 aUv;\n" @@ -102,6 +105,8 @@ static struct vg_shader _shader_model_character_view = { " vec4 g_sunset_ambient;\n" " vec4 g_sun_colour;\n" " vec4 g_sun_dir;\n" +" vec4 g_board_0;\n" +" vec4 g_board_1;\n" "\n" " float g_water_fog;\n" " float g_time;\n" @@ -202,7 +207,7 @@ static struct vg_shader _shader_model_character_view = { " return ambient + (light_sun + sky_reflection) * shadow;\n" "}\n" "\n" -"#line 42 0 \n" +"#line 44 0 \n" "\n" "float world_depth_sample( vec3 pos )\n" "{\n" @@ -212,9 +217,8 @@ static struct vg_shader _shader_model_character_view = { "\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" +" return world_depth_sample( pos ) - ref_depth;\n" "}\n" "\n" "float shadow_sample( vec3 vdir )\n" @@ -384,7 +388,7 @@ static struct vg_shader _shader_model_character_view = { " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n" "}\n" "\n" -"#line 11 0 \n" +"#line 14 0 \n" "#line 1 2 \n" "const float k_motion_lerp_amount = 0.01;\n" "\n" @@ -404,19 +408,39 @@ static struct vg_shader _shader_model_character_view = { " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n" "}\n" "\n" -"#line 12 0 \n" +"#line 15 0 \n" +"\n" +"float linear_depth( float depth, float near, float far ) \n" +"{\n" +" float z = depth * 2.0 - 1.0;\n" +" return (2.0 * near * far) / (far + near - z * (far - near)); \n" +"}\n" "\n" "void main()\n" "{\n" " compute_motion_vectors();\n" "\n" -" vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n" +" vec3 qnorm = aNorm;\n" " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n" " vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n" "\n" " float dist = distance( aWorldCo, uCamera ) - 0.08;\n" " float opacity = clamp( dist*dist, 0.0, 1.0 );\n" "\n" +" vec2 back_coord = gl_FragCoord.xy*uInverseRatioMain.xy*uInverseRatioDepth.xy;\n" +" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n" +" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n" +"\n" +" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n" +" float diff = back_depth - front_depth;\n" +"\n" +" vec2 ssuv = gl_FragCoord.xy;\n" +" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n" +" float dither = fract( vDither.g / 71.0 ) - 0.5;\n" +"\n" +" if( step(0.0,diff)+dither<0.3 )\n" +" discard;\n" +"\n" " oColour = vec4( composite, opacity );\n" "}\n" ""}, @@ -425,7 +449,10 @@ static struct vg_shader _shader_model_character_view = { static GLuint _uniform_model_character_view_uPv; static GLuint _uniform_model_character_view_uTransforms; static GLuint _uniform_model_character_view_uTexMain; +static GLuint _uniform_model_character_view_uTexSceneDepth; static GLuint _uniform_model_character_view_uCamera; +static GLuint _uniform_model_character_view_uInverseRatioDepth; +static GLuint _uniform_model_character_view_uInverseRatioMain; static GLuint _uniform_model_character_view_g_world_depth; static GLuint _uniform_model_character_view_uLightsArray; static GLuint _uniform_model_character_view_uLightsIndex; @@ -435,9 +462,18 @@ static void shader_model_character_view_uPv(m4x4f m){ static void shader_model_character_view_uTexMain(int i){ glUniform1i(_uniform_model_character_view_uTexMain,i); } +static void shader_model_character_view_uTexSceneDepth(int i){ + glUniform1i(_uniform_model_character_view_uTexSceneDepth,i); +} static void shader_model_character_view_uCamera(v3f v){ glUniform3fv(_uniform_model_character_view_uCamera,1,v); } +static void shader_model_character_view_uInverseRatioDepth(v3f v){ + glUniform3fv(_uniform_model_character_view_uInverseRatioDepth,1,v); +} +static void shader_model_character_view_uInverseRatioMain(v3f v){ + glUniform3fv(_uniform_model_character_view_uInverseRatioMain,1,v); +} static void shader_model_character_view_g_world_depth(int i){ glUniform1i(_uniform_model_character_view_g_world_depth,i); } @@ -449,7 +485,10 @@ static void shader_model_character_view_link(void){ _uniform_model_character_view_uPv = glGetUniformLocation( _shader_model_character_view.id, "uPv" ); _uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" ); _uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" ); + _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" ); _uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" ); + _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" ); + _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" ); _uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" ); _uniform_model_character_view_uLightsArray = glGetUniformLocation( _shader_model_character_view.id, "uLightsArray" ); _uniform_model_character_view_uLightsIndex = glGetUniformLocation( _shader_model_character_view.id, "uLightsIndex" );