| 1 |
uniform vec4 u_LightOrigin; |
| 2 |
uniform float u_LightRadius; |
| 3 |
|
| 4 |
varying vec3 var_Position; |
| 5 |
|
| 6 |
void main() |
| 7 |
{ |
| 8 |
#if defined(USE_DEPTH) |
| 9 |
float depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius; |
| 10 |
#if 0 |
| 11 |
// 32 bit precision |
| 12 |
const vec4 bitSh = vec4( 256 * 256 * 256, 256 * 256, 256, 1); |
| 13 |
const vec4 bitMsk = vec4( 0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0); |
| 14 |
|
| 15 |
vec4 comp; |
| 16 |
comp = depth * bitSh; |
| 17 |
comp.xyz = fract(comp.xyz); |
| 18 |
comp -= comp.xxyz * bitMsk; |
| 19 |
gl_FragColor = comp; |
| 20 |
#endif |
| 21 |
|
| 22 |
#if 1 |
| 23 |
// 24 bit precision |
| 24 |
const vec3 bitSh = vec3( 256 * 256, 256, 1); |
| 25 |
const vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0); |
| 26 |
|
| 27 |
vec3 comp; |
| 28 |
comp = depth * bitSh; |
| 29 |
comp.xy = fract(comp.xy); |
| 30 |
comp -= comp.xxy * bitMsk; |
| 31 |
gl_FragColor = vec4(comp, 1.0); |
| 32 |
#endif |
| 33 |
|
| 34 |
#if 0 |
| 35 |
// 8 bit precision |
| 36 |
gl_FragColor = vec4(depth, depth, depth, 1); |
| 37 |
#endif |
| 38 |
#else |
| 39 |
gl_FragColor = vec4(0, 0, 0, 1); |
| 40 |
#endif |
| 41 |
} |