Not sure at all if I said this correct, but, I´m trying to use the depth buffer within the “effect composer” for a custom shader. I understand that I need to render to a renderTarget first to get the depthbuffer from the renderer…
Now, when I want to use the depthTexture of the renderTarget in my shader, I´m failing… I think ´cause I do not unpack/pack the depthTexture correctly in the shader?
I used the fragment-shader from the threejs´s “wegl_depth_texture” example, but, I only get a black screen without any errors (in the console)…
It seems you are using the code from the official depth texture example. Try to demonstrate the problem with a live example. Please keep in mind that no member of this community has telepathic abilities. Without providing an option for debugging, you probably won’t get any help.
If I setup the depthShader and in the fragmentShader set depth to be the result, it´s not working aka, think the depth´s value is just “0”, so… : http://jsfiddle.net/blackInk/tf1hdvLa/16/
Same shader, but my “reading depth”, taken 1:1 from the working example “webgl_depth_texture” is not working here?
It does not make sense to call clear() right after rendering to depthRenderTarget. This will clear its content.
You have to be aware that passing a shader to ShaderPass means it’s uniforms are cloned (meaning the texture of the WebGLRenderTarget which does not work). So you have to assign the values right after the pass creation.
It’s not necessary to assign tDiffuse since it’s automatically assigned by ShaderPass. It represents the contents of the EffectComposer’s read buffer right before the pass is executed. In your particular case, it’s the result of RenderPass.