Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #version 400
  2.  
  3. in vec4 v_position; // view space position
  4.  
  5. uniform sampler2D s_normalDepthTex; // Normals and Depth
  6.  
  7. uniform mat4 u_worldTrans;
  8. uniform mat4 u_projTrans;
  9. uniform mat4 u_viewTrans;
  10. uniform mat4 u_projViewTrans;
  11.  
  12. uniform vec3 u_lightPosition;
  13. uniform vec3 u_lightDiffuse = vec3(1.0,1.0,0);
  14. uniform vec3 u_lightSpecular = vec3(1.0,1.0,1.0);
  15. uniform vec3 u_lightAttenuation = vec3(0.2,0,0.2);
  16. uniform float u_lightIntensity = 1;
  17. uniform float u_lightRadius = 50f;
  18.  
  19. uniform vec2 u_inverseScreenSize;
  20. uniform float u_farDistance;
  21.  
  22.  
  23. void main()
  24. {
  25. vec2 texCoord = gl_FragCoord.xy * u_inverseScreenSize.xy;
  26.  
  27. float linearDepth = texture2D(s_normalDepthTex, texCoord.st).a;
  28. vec3 lightPos = (u_viewTrans * vec4(u_lightPosition,1)).rgb;
  29.  
  30. // vector to far plane
  31. vec3 viewRay = vec3(v_position.xy * (u_farDistance/v_position.z), u_farDistance);
  32. // scale viewRay by linear depth to get view space position
  33. vec3 vertex = viewRay * linearDepth;
  34. vec3 normal = texture2D(s_normalDepthTex, texCoord.st).xyz;
  35.  
  36. vec3 ambient = vec3(0.0, 0.0, 0.0);
  37. vec3 diffuse = vec3(0.0, 0.0, 0.0);
  38. vec3 specular = vec3(0.0, 0.0, 0.0);
  39.  
  40. vec3 lightDir = lightPos - vertex;
  41.  
  42. float distance = length(lightDir);
  43. float fallof = max(0.0, 1.0 - distance / u_lightRadius);
  44.  
  45.  
  46. gl_FragColor = vec4(fallof,fallof,fallof, 1.0);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement