X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fmodel_character_view.fs;h=efee606c86b7b0151505dd268d258af035f9d8cd;hb=1d06671f87a9d24596fc6808d8e0db889a818750;hp=8bf29bcf899b9ba1700bc79750c269f7502b2fcc;hpb=aa4c26eae2208872824e0eb5b71bc05c16d43242;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/model_character_view.fs b/shaders/model_character_view.fs index 8bf29bc..efee606 100644 --- a/shaders/model_character_view.fs +++ b/shaders/model_character_view.fs @@ -1,7 +1,9 @@ uniform sampler2D uTexMain; +uniform sampler2D uTexSceneDepth; uniform vec3 uCamera; -uniform vec3 uBoard0; -uniform vec3 uBoard1; +uniform vec3 uInverseRatioDepth; +uniform vec3 uInverseRatioMain; +uniform bool uDepthCompare; in vec4 aColour; in vec2 aUv; @@ -12,28 +14,39 @@ in vec3 aWorldCo; #include "common_world.glsl" #include "motion_vectors_fs.glsl" +float linear_depth( float depth, float near, float far ) +{ + float z = depth * 2.0 - 1.0; + return (2.0 * near * far) / (far + near - z * (far - near)); +} + void main() { compute_motion_vectors(); - vec3 vfrag = texture( uTexMain, aUv ).rgb; + vec3 qnorm = aNorm; + vec3 diffuse = texture( uTexMain, aUv ).rgb; + vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 ); - // Lighting - vec3 halfview = uCamera - aWorldCo; - float fdist = length( halfview ); - halfview /= fdist; - fdist -= 0.08; + float dist = distance( aWorldCo, uCamera ) - 0.08; + float opacity = clamp( dist*dist, 0.0, 1.0 ); - vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0); + if( uDepthCompare ){ + vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy + * uInverseRatioDepth.xy; + float back_depth = texture( uTexSceneDepth, back_coord ).r; + float front_depth = gl_FragCoord.z/gl_FragCoord.w; - vec3 total_light = newlight_compute_ambient(); - vec3 world_light = newlight_compute_world_diffuse( qnorm ); + back_depth = linear_depth( back_depth, 0.1, 2100.0 ); + float diff = back_depth - front_depth; - float world_shadow = newlight_compute_sun_shadow(); - total_light += world_light * world_shadow; + vec2 ssuv = gl_FragCoord.xy; + vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) ); + float dither = fract( vDither.g / 71.0 ) - 0.5; - vfrag = apply_fog( vfrag * total_light, fdist ); + if( step(0.0,diff)+dither<0.3 ) + discard; + } - float opacity = clamp( fdist*fdist, 0.0, 1.0 ); - oColour = vec4(vfrag,opacity); + oColour = vec4( composite, opacity ); }