-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdiagnostic.frag
More file actions
40 lines (32 loc) · 1.04 KB
/
diagnostic.frag
File metadata and controls
40 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
precision highp float;
#define DISPLAY_POS 1
#define DISPLAY_NORMAL 2
#define DISPLAY_COLOR 3
#define DISPLAY_DEPTH 4
uniform sampler2D u_positionTex;
uniform sampler2D u_normalTex;
uniform sampler2D u_colorTex;
uniform sampler2D u_depthTex;
uniform float u_zFar;
uniform float u_zNear;
uniform int u_displayType;
varying vec2 v_texcoord;
float linearizeDepth( float exp_depth, float near, float far ){
return ( 2.0 * near ) / ( far + near - exp_depth * ( far - near ) );
}
void main()
{
vec3 normal = texture2D( u_normalTex, v_texcoord ).xyz;
vec3 position = texture2D( u_positionTex, v_texcoord ).xyz;
vec4 color = texture2D( u_colorTex, v_texcoord );
float depth = texture2D( u_depthTex, v_texcoord ).x;
depth = linearizeDepth( depth, u_zNear, u_zFar );
if( u_displayType == DISPLAY_DEPTH )
gl_FragColor = vec4( depth, depth, depth, 1 );
else if( u_displayType == DISPLAY_COLOR )
gl_FragColor = color;
else if( u_displayType == DISPLAY_NORMAL )
gl_FragColor = vec4( normal, 1 );
else
gl_FragColor = vec4( position, 1 );
}