Note that there are some explanatory texts on larger screens.

plurals
  1. POGet position from depth texture
    primarykey
    data
    text
    <p>Im trying to reduce the number of post process textures I have to draw in my scene. The end goal is to support an SSAO shader. The shader requires depth, postion and normal data. Currently I am storing the depth and normals in 1 float texture and the position in another.</p> <p>I've been doing some reading, and it seems possible that you can get the position by simply using the depth stored in the normal texture. You have to unproject the x and y and multiply it by the depth value. I can't seem to get this right however and its probably due to my lack of understanding...</p> <p>So currently my positions are drawn to a position texture. This is what it looks like (this is currently working correctly) <img src="https://i.stack.imgur.com/G5usG.png" alt="drawing position to texture"></p> <p>So is my new method. I pass the normal texture that stores the normal x,y and z in the RGB channels and the depth in the w. In the SSAO shader I need to get the position and so this is how im doing it:</p> <pre><code>//viewport is a vec2 of the viewport width and height //invProj is a mat4 using camera.projectionMatrixInverse (camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );) vec3 get_eye_normal() { vec2 frag_coord = gl_FragCoord.xy/viewport; frag_coord = (frag_coord-0.5)*2.0; vec4 device_normal = vec4(frag_coord, 0.0, 1.0); return normalize((invProj * device_normal).xyz); } ... float srcDepth = texture2D(tNormalsTex, vUv).w; vec3 eye_ray = get_eye_normal(); vec3 srcPosition = vec3( eye_ray.x * srcDepth , eye_ray.y * srcDepth , eye_ray.z * srcDepth ); //Previously was doing this: //vec3 srcPosition = texture2D(tPositionTex, vUv).xyz; </code></pre> <p>However when I render out the positions it looks like this:</p> <p><img src="https://i.stack.imgur.com/GHvRt.png" alt="Not the same - causing problems"></p> <p>The SSAO looks very messed up using the new method. Any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload