How can I get world space position in shaderPass?

float depthTx = texture2D(tDepth,vUv).r;
float viewZ = getViewZ( depthTx );
float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];
vec4 e = getViewPosition(vUv,depthTx,clipW);
vec4 wPos = CameraMatrixWorld*e;
gl_FragColor = wPos;

i try to render worldPosition,but look still like eye space position.

ok,I know,I forget reset camera.matrixWorld when I move camera position.

new question.How do I want to handle this precision problem?

How do you configure your depth texture?

    function setupRenderTargetLight() {
        var target = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight );
        target.texture.minFilter = THREE.NearestFilter;
        target.texture.magFilter = THREE.NearestFilter;
        target.stencilBuffer = ( THREE.DepthFormat === THREE.DepthStencilFormat ) ? true : false;
        target.depthTexture = new THREE.DepthTexture();
        target.depthTexture.format = THREE.DepthFormat;
        target.depthTexture.type = THREE.UnsignedShortType;
        target.setSize( window.innerWidth, window.innerHeight );
        return target
    }

Your reminder helped me find a solution.thank you!

target.depthTexture.type = THREE.FloatType;
2 Likes

Correct! THREE.FloatType is the highest possible precision for a depth texture and usually mitigates such issues.