Refraction with Node Materials?

This is likely something simple, but in Node Materials there is a node called “RefractionBlock”

In PBR materials, we can set up a refraction texture and set the render list. In Node Materials, I am setting the texture to the RefractionBlock texture prop in code, and it shows up as expected in the Inspector:

image

And in that texture, I am setting the render list to both null and all meshes.

Either way, the texture renders as empty so I get no refraction.

Can anyone share a dead-simple example of:

  1. A mesh with a Node Material
  2. The NM uses the RefractionBlock (or some other way to handle this)
  3. The IoR and other props are controlled via the NM
  4. The render list is correctly set up to render the scene to that texture

Any help is appreciated!

I think refractionBlock.texture expects an environment texture since it defaults to the scene’s environment texture. It looks like setting refractionBlock.texture to a RefractionTexture is essentially telling the renderer to refract a refraction.

Hmm, but that doesn’t seem right, does it? The idea is that we want to set a refraction texture so it shows the mesh behind it as though it’s through some sort of transmissive material such as plastic. Using the environment texture sort of defeats the purpose, no?

Do you have a more complete example?

The Refraction block is supposed to be connected to a SubSurface block, which in turn gets connected to a PBRMetallicRoughness block.

What are you connecting the Refraction block to?

It could be that you have to put your refraction texture in scene.customRenderTargets so that it gets rendered (you don’t have to do it for standard/PBR materials because the system does it automatically for you in these cases).

The blocks are connected as follows.

As you can see, with @Evgeni_Popov 's suggestion, I am now seeing something rendered there, but for some reason it’s rendering itself instead of the other meshes! It seems close, but what is happening there now?

I don’t suppose you have a Playground that demonstrates how to set this up, do you?

@Alex2, could you share a repro in the playground ? This would help us addressing the issue for you

@sebavan Will this work?

The thing that I’m seeing now is that even though I can see through the box, I don’t see any refraction on the sphere, and adjusting the numbers doesn’t seem to have any effect. I’m sure it’s something silly!

Ah, if I wire up the “utility texture” to the albedo texture, that is controlling thickness.

Yup the thickness needs to be wired in NME PBR.

Here is a min setup for it: https://playground.babylonjs.com/#7QAN2T#33

The value would not be used in this configuration. I ll try to make it optional soon but in the meantime, you can put it to any values if not using translucency or tint.