chill out cubemaps
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / model_character_view.fs
1 uniform sampler2D uTexMain;
2 uniform sampler2D uTexSceneDepth;
3 uniform vec3 uCamera;
4 uniform vec3 uInverseRatioDepth;
5 uniform vec3 uInverseRatioMain;
6 uniform bool uDepthCompare;
7
8 in vec4 aColour;
9 in vec2 aUv;
10 in vec3 aNorm;
11 in vec3 aCo;
12 in vec3 aWorldCo;
13
14 #include "common_world.glsl"
15 #include "motion_vectors_fs.glsl"
16
17 float linear_depth( float depth, float near, float far )
18 {
19 float z = depth * 2.0 - 1.0;
20 return (2.0 * near * far) / (far + near - z * (far - near));
21 }
22
23 void main()
24 {
25 compute_motion_vectors();
26
27 vec3 qnorm = aNorm;
28 vec3 diffuse = texture( uTexMain, aUv ).rgb;
29 vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );
30
31 float dist = distance( aWorldCo, uCamera ) - 0.08;
32 float opacity = clamp( dist*dist, 0.0, 1.0 );
33
34 if( uDepthCompare ){
35 vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy
36 * uInverseRatioDepth.xy;
37 float back_depth = texture( uTexSceneDepth, back_coord ).r;
38 float front_depth = gl_FragCoord.z/gl_FragCoord.w;
39
40 back_depth = linear_depth( back_depth, 0.1, 2100.0 );
41 float diff = back_depth - front_depth;
42
43 vec2 ssuv = gl_FragCoord.xy;
44 vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
45 float dither = fract( vDither.g / 71.0 ) - 0.5;
46
47 if( step(0.0,diff)+dither<0.3 )
48 discard;
49 }
50
51 oColour = vec4( composite, opacity );
52 }