X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fmodel_font.h;h=67ce50d090f32deaac5e64a5495a14f88fa034a3;hb=e311bbe2fa903a7e2a922f202f389b799193195d;hp=65d53e3f83d1a1a43d97cdbb0661af2643e5a1cb;hpb=b3ca3b7a45eec11c46eb19772e10021177665adb;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/model_font.h b/shaders/model_font.h index 65d53e3..67ce50d 100644 --- a/shaders/model_font.h +++ b/shaders/model_font.h @@ -12,9 +12,6 @@ static struct vg_shader _shader_model_font = { "layout (location=0) in vec3 a_co;\n" "layout (location=1) in vec3 a_norm;\n" "layout (location=2) in vec2 a_uv;\n" -"layout (location=3) in vec4 a_colour;\n" -"layout (location=4) in vec4 a_weights;\n" -"layout (location=5) in ivec4 a_groups;\n" "\n" "#line 1 1 \n" "const float k_motion_lerp_amount = 0.01;\n" @@ -34,16 +31,15 @@ static struct vg_shader _shader_model_font = { " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n" "}\n" "\n" -"#line 9 0 \n" +"#line 6 0 \n" "\n" "uniform mat4x3 uMdl;\n" "uniform mat4 uPv;\n" "uniform mat4 uPvmPrev;\n" "uniform vec4 uOffset;\n" "\n" -"out vec4 aColour;\n" "out vec2 aUv;\n" -"out vec3 aNorm;\n" +"out vec4 aNorm;\n" "out vec3 aCo;\n" "out vec3 aWorldCo;\n" "\n" @@ -57,25 +53,24 @@ static struct vg_shader _shader_model_font = { " vs_motion_out( vproj0, vproj1 );\n" "\n" " gl_Position = vproj0;\n" -" aWorldCo = world_pos0;\n" -" aColour = a_colour;\n" +"\n" " aUv = a_uv;\n" -" aNorm = mat3(uMdl) * a_norm;\n" -" aCo = a_co;\n" +" aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n" +" aCo = co;\n" +" aWorldCo = world_pos0;\n" "}\n" ""}, .fs = { .orig_file = "shaders/model_font.fs", .static_src = -"out vec4 FragColor;\n" +"layout (location = 0) out vec4 oColour;\n" "\n" "uniform sampler2D uTexMain;\n" "uniform vec4 uColour;\n" "\n" -"in vec4 aColour;\n" "in vec2 aUv;\n" -"in vec3 aNorm;\n" +"in vec4 aNorm;\n" "in vec3 aCo;\n" "\n" "#line 1 1 \n" @@ -97,12 +92,43 @@ static struct vg_shader _shader_model_font = { " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n" "}\n" "\n" +"#line 11 0 \n" +"#line 1 2 \n" +"uniform sampler2D uTexSceneDepth;\n" +"uniform vec3 uInverseRatioDepth;\n" +"uniform vec3 uInverseRatioMain;\n" +"uniform bool uDepthCompare;\n" +"\n" +"float linear_depth( float depth, float near, float far ) {\n" +" float z = depth * 2.0 - 1.0;\n" +" return (2.0 * near * far) / (far + near - z * (far - near)); \n" +"}\n" +"\n" +"void depth_compare_dither(){\n" +" if( uDepthCompare ){\n" +" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n" +" * 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" +"}\n" +"\n" "#line 12 0 \n" "\n" -"void main()\n" -"{\n" +"void main(){\n" +" depth_compare_dither();\n" " compute_motion_vectors();\n" -" FragColor = texture( uTexMain, aUv ) * uColour;\n" +" oColour = texture( uTexMain, aUv ) * uColour;\n" "}\n" ""}, }; @@ -113,6 +139,10 @@ static GLuint _uniform_model_font_uPvmPrev; static GLuint _uniform_model_font_uOffset; static GLuint _uniform_model_font_uTexMain; static GLuint _uniform_model_font_uColour; +static GLuint _uniform_model_font_uTexSceneDepth; +static GLuint _uniform_model_font_uInverseRatioDepth; +static GLuint _uniform_model_font_uInverseRatioMain; +static GLuint _uniform_model_font_uDepthCompare; static void shader_model_font_uMdl(m4x3f m){ glUniformMatrix4x3fv(_uniform_model_font_uMdl,1,GL_FALSE,(float*)m); } @@ -131,6 +161,18 @@ static void shader_model_font_uTexMain(int i){ static void shader_model_font_uColour(v4f v){ glUniform4fv(_uniform_model_font_uColour,1,v); } +static void shader_model_font_uTexSceneDepth(int i){ + glUniform1i(_uniform_model_font_uTexSceneDepth,i); +} +static void shader_model_font_uInverseRatioDepth(v3f v){ + glUniform3fv(_uniform_model_font_uInverseRatioDepth,1,v); +} +static void shader_model_font_uInverseRatioMain(v3f v){ + glUniform3fv(_uniform_model_font_uInverseRatioMain,1,v); +} +static void shader_model_font_uDepthCompare(int b){ + glUniform1i(_uniform_model_font_uDepthCompare,b); +} static void shader_model_font_register(void){ vg_shader_register( &_shader_model_font ); } @@ -142,5 +184,9 @@ static void shader_model_font_link(void){ _uniform_model_font_uOffset = glGetUniformLocation( _shader_model_font.id, "uOffset" ); _uniform_model_font_uTexMain = glGetUniformLocation( _shader_model_font.id, "uTexMain" ); _uniform_model_font_uColour = glGetUniformLocation( _shader_model_font.id, "uColour" ); + _uniform_model_font_uTexSceneDepth = glGetUniformLocation( _shader_model_font.id, "uTexSceneDepth" ); + _uniform_model_font_uInverseRatioDepth = glGetUniformLocation( _shader_model_font.id, "uInverseRatioDepth" ); + _uniform_model_font_uInverseRatioMain = glGetUniformLocation( _shader_model_font.id, "uInverseRatioMain" ); + _uniform_model_font_uDepthCompare = glGetUniformLocation( _shader_model_font.id, "uDepthCompare" ); } #endif /* SHADER_model_font_H */