RenderTargetTexture - Only render to texture in first pass

Hello!

I have hit a bit of a roadblock w.r.t RenderTargetTexture. It seems like however I try to do this,
the ShaderMaterial ment for the RTT pass ends up also being applied directly to the mesh with a entirely different material?

Here’s the PG of what I have:
https://playground.babylonjs.com/#F7T7YM#2

You can clearly see the firstPassMaterial is applied to “Box” and rendered to screen (since it shows backfaces), which afaik should not happen, since it uses secondPassMaterial.

I have tried to follow this PG:
https://playground.babylonjs.com/#PL5WU0#1

But it seems I am misunderstanding something.

About render targets, your first pg is all good looking with spector. Box which is backside renders on the main canvas while box2 front side renders in the render target:

Now let s check materials and the issue is you are not creating the material 1 for the scene, you left the parameter null also unfortunately as you are relying on source manually instead of the shader store the effect got mixed up :frowning:

I ll look into it shortly but in the meantime you can add a defines to ensure the cache won t get conflicts: https://playground.babylonjs.com/#F7T7YM#6

Mm ok. The null parameter was a last minute change (which I noticed no difference with).

As for the defines. Is this a bug? Or is it simply UB to have many materials built from source shaders without ids? I haven’t looked into the ShaderStore, but I assume it is preferred over raw source glsl, then?

And thank you for rapid response! Been having a lot of fun visualizing medical images using babylonjs :slight_smile:

A bug, I am pushing a fix tonight :slight_smile:

2 Likes

All deployed no need for the define trick anymore: https://playground.babylonjs.com/#F7T7YM#7

1 Like