Advertisement
Guest User

shadowmap

a guest
Apr 5th, 2012
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. //vertex fragment
  2. #ifdef GL_ES
  3. precision mediump float;  
  4. #endif
  5. uniform float invFar; //   actually this is inverse of distance from camera to frustum corner
  6. const vec4 bitShift = vec4( 256.0, 1.0, 256.0, 1.0);
  7. const vec4 bitMask = vec4(0.0, 1.0 / 256.0, 0.0, 1.0 / 256.0);
  8. varying vec3 pos;
  9.  
  10. void main() {
  11.     float depth = length(pos) * invFar;          
  12.     float moment2 = depth * depth;     
  13.     vec4 comp = fract(vec4depth, depth, moment2, moment2) * bitShift);
  14.     gl_FragColor = comp - comp.xxzz * bitMask; //this give more precission 
  15. }
  16.  
  17. //vertex
  18. attribute vec4 a_position;
  19. uniform mat4 u_projectionViewMatrix;
  20. uniform vec3 lightPos;
  21. varying vec3 pos;
  22.  
  23. void main()
  24. {
  25.     pos = (a_position.rgb - lightPos);
  26.     gl_Position = u_projectionViewMatrix * a_position; 
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement