SHARE
TWEET

Untitled

a guest Oct 2nd, 2015 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Depth shader
  2. #VS
  3. void main() {
  4.         vec4 pos = u_projViewTrans * (u_worldTrans * a_position);
  5.  
  6.         v_depth = pos.z;
  7.         gl_Position = pos;
  8. }
  9. #FS
  10. void main() {
  11.         float linearDepth = v_depth * (1.0 / (nearfar.y - nearfar.x));
  12.         gl_FragColor = vec4(linearDepth, 0, 0, 0);
  13. }
  14.  
  15. // Shader.java
  16. setUniformMatrix("u_invProjView", cam.combined.cpy().inv());
  17.  
  18. // Shader.frag
  19. ### Reconstruction from depth
  20. vec3 getPosition(in vec2 uv) {
  21.        
  22.         depthv = texture2D(texture0, uv).x;
  23.         //float depth = (2.0 * nearfar.x) / (nearfar.y + nearfar.x - depthv* (nearfar.y - u_frustumNearFar.x));
  24.  
  25.         // #### IS this right? ####
  26.          vec4 pos = vec4(uv, depthv, 1.0)*2.0-1.0;
  27.          pos = u_invProjView * pos;
  28.          pos = pos/pos.w;
  29.          return pos.xyz;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top