Issue when PrePassRenderer and RenderTargetTexture are used at the same time

Hello,

I’m new here and I don’t really know if my problem is due to a bug or a misunderstanding on my part.

I’m trying to create a new PostProcess using both renderTargetTexture and PrePassRenderer. However, when I use both of them, my renderTargetTexture display the base texture of the scene instead of the the ShaderMaterial result (as if the RendertargetTexture was replaced by something else…)

I didn’t manage to exactly reproduce the problem since I didn’t find how to set the configuration of the PrePassRenderer in a Playground. So, for the example, I applied the SSR postProcess to implicitly set it up instead.

So, here is the playground : https://playground.babylonjs.com/#CHNWS7#17

I’m displaying :

  • only base texture (left)

  • the metallic map (“metallic to texture”) I compute thanks to a RenderTargetTexture (center)

  • the normals I get thanks to GeometryBufferRenderer or PrePassRenderer (right)

When I use the GeometryBufferRenderer it works. But when I use the PrePassRenderer (choose prePass = true, line 282), it doesn’t work: the “metallic to texture” in the inspector is not blue as expected but shows the base color instead.

Notice that when I use the GeometryBufferRenderer and apply the SSR PostProcess the result is the same as using PrePassRenderer.

Is there a known issue about an incompatibility between RenderTargetTexture and PrePassRenderer ?

cc @CraigFeldspar

Hi @Manon,
Looked at your PG and there seems to be an issue with setMaterialForRendering. Prepass seems to ignore that, I’ll look into it.

3 Likes

@CraigFeldspar were you able to have a look ?

I remember having a quick look and it was about the wrong renderingPass id used in prepass, but I didn’t work on a fix as there is a workaround using before/after render observables.

Could you share the workaround back ??? it would greatly help :slight_smile: and I ll be sure to keep the thread

Would you mind sharing the workaround? I met the same issue with material plugins and prepassRenderer. The sphere2 returns red with ssr.

basically instead of using setMaterialForRendering, you just add a function in the onBeforeRenderObservable of the mesh, which replaces the material of the mesh with what you need (making sure you store the original material)

Then in onAfterRenderObservable you set back the original material

1 Like

This PR will fix the problem with the prepass renderer:

Regarding the configuration of the prepass renderer, ScreenSpaceReflectionsConfiguration and PrePassEffectConfiguration are not exported as they are not meant to be used by the end user and are really internal classes. You should instead create your own configuration class (see lines 1-7 and 318 in the PG below).

If you want to use the SSR post process when using the geometry buffer renderer (GBR) in your finalPass post process, you should force the SSR post process to use the GBR (pass true for the last parameter of the constructor) as by default it is using the prepass renderer (PPR): using both the GBR and the PPR is not supported.

Here’s the PG with the fixes:

=> will only work as expected for the PPR when the PR is merged.

@tanpopo I don’t think it’s the same problem in your case, as the PR does not fix it. I’m going to have a look.

3 Likes

@tanpopo The problem lies in the material plugin code. When using the prepass renderer, the final color must be set in glFragData[0] and not in gl_FragColor.

Here’s a fixed PG:

2 Likes