Hi,
Under which circumstances, an NME PBR material doesnt find the scene.environmentexture for the reflection in the PBR node?
Referring to : Babylon.js docs
In my actual project it doesnt work, in previous ones it did, but I remembered beeing somehow buggy, sometimes the editor wouldnt take it, but I reconnected a new reflection node to the PBR materialblock and then it came back.
Can/should I assign the scene.env… directly as texture to the reflection block?
Sry for not making a reproduction PG.
Hi.
Somehow there is something going on with the Alphablending which I cannot figure out.
I have the material and set the transparency mode to
nodeMaterial.transparencyMode = 2;
in the script.
The proper mode appears in the NME but the environment texture is not present.
As soon as I flip the switch “alpha blending” in the NME, the environment texture appears.
Then it ignores the switch completely when turning it off/on again.
Here is the snippet as well from the material: TBZW72
I think I am doing something wrong, but dont know how to debug that.
Best.
Werner
Somehow its not initialized…
Maybe something in our code.
Will check and comeback…
Best.
Werner
I am setting the Blocktexture for the reflection now
this.ReflSource = nodeMaterial.getBlockByName("Reflection");
this.ReflSource.texture = envTex;
but it isnt updated.
As soon as I open the NME and i flip the switch “alpha blending” in the NME, the material recompiles and it works, so that the texture is updates per frame.
Is this a bug?
Wicked…
Naja somehow its working now, as we set the env texture somewhere else in the code, its updated every frame… not sure if that is clever/bad but its works now.
Thx
Werner
Sounds like you got it working in your case, but it also sounds like there is an order of operations bug. Do you have a PG using this material and setting the env texture where the issue repros?
You should assign a Reflection
block to the PBR reflection
input:
- if the block is empty, the env texture used will be the one from
scene.environmentTexture
(if any - else, there will be no env texture for your material) - if you set a texture in the
Reflection
block, the system will use this texture as the environement texture
If it does not work that way for you, could you setup a repro so that we can investigate the problem?
In the NME snippet (Babylon.js Node Material Editor), it looks like this is already happening. From what @yamaciller said above:
as we set the env texture somewhere else in the code, its updated every frame… not sure if that is clever/bad but its works now.
it sounds like if they move where the env texture is assigned, then it works (and I assume this is assigning it via the reflection block given the this.ReflSource.texture = envTex;
, but would be good to confirm). But ultimately a PG with a repro will be most helpful!
Thank you for your answers.
So first I leave the block empty and want the scene.environmentTexture
to be assigned ( as described in the docu).
That works, but only if I …
So it seems that the scene.environmentTexture
is not initialized.
We do modify the scene.environmentTexture
per frame as we are rotating it and also switch to a different one as we have a day/night cycle and we want the reflections to change according the light.
So as that didnt work, we created a function, which assigns the scene.environmentTexture
per frame to the Reflection
block earlier in the code as we assume, that the material is created before the scene.environmentTexture
is initialized.
That works now.
Assuming that behavior, I think, that when starting the scene and then manually opening the NME, fliping the alpha blend switch, and the NME recompliles the material, the scene.environmentTexture
at that point is present and assigned sucessfully.
I need to go a bit closer into the project with our programmer and analyze that.
I dont know how to repro that case in the PG but will see.
My wider question would be, if assigning a texture per frame to the Reflection
block is a clever idea? As mentioned, we are rotation the texture (because of the suns positions in the cubemap) as well switching to a different one (this we could do at the time that happens) but the rotation would need to be updated regularly.
But I assume, updating the scene.environmentTexture
and leaving the block emtpy would “cost” the same perfomance wise?
Other than that, we could “write” a shader or material as well instead of using the NME, but I made use of that (as I am no programmer) but I can use the NME and create materials, which is so lovely and efficient and useful.
Thx and best
Werner
If you assign the same texture each time, there’s an early exit in the setter which should make the call nearly free (though, not doing the call is even better!).
You don’t have to change the texture if you only want to rotate it. You can simply update the uAng
/ vAng
/ wAng
properties.
Ah cool,
ah, rotation in the material would make sense, so I would update the texture only when I change the source, good idea.
Thank you!