Getting depth texture from PrePassRenderer into particle effect

Hi everyone,

Please have a look at this playground: https://playground.babylonjs.com/#1ASENS#356

In the shader, whenever I access ‘depthColor’ it just stops working (no errors).

I am guessing my setup with the depth texture is not right because if I just provide “{}” to effect.setTexture, I will get the same result. But the texture, by name, checks out as “prePass_Depth”. :face_with_spiral_eyes:

Best wishes
Joe

1 Like

Hi!

I don’t know what are you trying to achieve :slight_smile: Why do you want to get the depth texture from a PrePassRenderer?

You can pass it directly to your particle Effect:

2 Likes

Thanks @roland :slight_smile:

Trying to do soft particles (and learning to write shader code :flushed:).

I would prefer the PrePassRenderer because, in my local project, I have it on already. So I was hoping I could use the depth texture from it rather than having to add the DepthRenderer (+1 draw call).

1 Like

Try this:

const depthIndex = prePassRenderer.getIndex(BABYLON.Constants.PREPASS_DEPTH_TEXTURE_TYPE);
effect.setTexture("depthSampler", prePassRenderer.getRenderTarget().textures[depthIndex]);
1 Like

Nope :frowning: https://playground.babylonjs.com/#1ASENS#359

What is weird also is that this section (LL 34)

float z = depthColor.x;  //<- access crashes?
z = 1.1;   
//float z = 1.0; //works

If I switch them around (to “works”), it only works in Chrome but not in Firefox.

Yes, and also, this is exactly how I use it elsewhere in a Postprocess - and there it works.

1 Like