-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDepth.frag
More file actions
31 lines (28 loc) · 863 Bytes
/
Depth.frag
File metadata and controls
31 lines (28 loc) · 863 Bytes
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
// Depth.frag
// 注意:这个着色器的是由
// http://www.codeproject.com/Articles/822380/Shadow-Mapping-with-Android-OpenGL-ES
// 改编过来的。
#ifdef GL_ES
precision highp float;
#endif
varying vec4 projectedPosition;
vec4 pack( float depth )
{
const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0,
256.0 * 256.0,
256.0,
1.0 );
const vec4 bitMsk = vec4( 0.0,
1.0 / 256.0,
1.0 / 256.0,
1.0 / 256.0 );
vec4 comp = fract( depth * bitSh );
comp -= comp.xxyz * bitMsk;
return comp;
}
void main( void )
{
float normalizedZ = projectedPosition.z / projectedPosition.w;
normalizedZ = ( normalizedZ + 1.0 ) / 2.0;
gl_FragColor = pack( normalizedZ );
}