I try to render a model with realistic shadows and reflection. The model consists of several meshes. Some meshes share a metal material, some other meshes share a glass material. How am I able to display shadows and reflectivity on all meshes from all meshes.
Shadows:
How to show the shadows of meshes on each mesh with pbr material? Setting the receiveShadows = true didn’t solve it. Do I have to use cascadedShadowGenerator?
Reflection:
My idea was to use reflection probes but there are some problems.
First my metal materials diffuse gets black after setting the reflectionTexture if I don’t display the environment. Of course I want to use the reflection of the environment but I don’t want that the environment is visible as background.
Second do I have to create a separate material for each mesh even if they share the same textures? Because the reflectionTexture couldn’t be the same for each mesh, or am I wrong?
I read another thread about reflection probes where you said that it is not recursive so the mesh that gets the probe can’t be part of the renderlist. That is what my initial thought was: Does it mean that a have to give every mesh an own material and problem to get the reflection of all meshes on all meshes? I tried that but it is very bad for performance. I don’t think I have done it how it is supposed to be. Besides that I don’t get how to get the environment reflection back to my metal material without creating a visible skybox. https://playground.babylonjs.com/#X548L8#6
I know and I am really thankful for your work and support. I am glad to be able to use this api for my projects
A few days ago I stumbled across the website of Evan. There is a scene which shows webgl path tracing. The code is accessible on github as well (GitHub - evanw/webgl-path-tracing: Path tracing in GLSL using WebGL). I am convinced that this is extremely difficult to do? Are there some hacks for lighting, reflection and shadows to get a nearly similar result right now with bjs?
Regarding my PG:
With this setup there is no reflection of the environmentTexture on my metal material after enabling the reflectionProbe. Is it possible to get it back?
About the reflection it is because the probe is using a clear color, you should inject a skybox in it to ensure you would see it through the reflection.
@Deltakosh
I read the thread and I am very excited for it. Learned a lot from it about path tracing. I wasn’t aware that for instance Evan’s path tracer only works for spheres and cubes which is not enough if we want to use it with bjs.
First, the skybox is visible in background obviously. I don’t want it to be visible. Setting the refreshRate of each probe to once and disabling color write solve this issue. But I have to wait for the calculation of the reflectionProbe. Is there a better solution?
Second, the material looks very different to my material before creating the probe. It is not rough, but it is more like a mirror.
Third, the reflections are on the wrong side of each mesh. I can see the reflection of the bars outside of the box and inside I just see the skybox.
Fourth, I cloned the material for each mesh to be able to set its own relectionTexture. This clones all diffuseTextures, normalTextures, etc. as well which is not necessary since the materials remains the same. Is it possible to the same textures for each material besides the reflectionsTexture?
To avoid the “Feedback loop formed between Framebuffer and active Texture.” WebGL error you need to remove the reflection texture from the materials before rendering the probe, else this texture is both used in a read (when drawing the meshes in the cube) and a write (the meshes are drawn in the texture cube = the reflection texture) manner, leading to the error.
Yes, this is a much more sophisticated method. Thank you very much!! This solves issue 1 and issue 4
#2
Why is the reflectionTexture so dominant? The material looses its characteristics and doesn’t look like a metal anymore. It would be nice to have the normal look of the material (https://playground.babylonjs.com/#X548L8#15) and some interferences with the reflection of the environment.
#3
In this perspective you can clearly see the reflection of a bar although the camera is outside of the box.(https://playground.babylonjs.com/#X548L8#16). But this is the reflection if the camera would be inside the box. From outside the reflection would be the skybox only.
About #3 your probe is in the middle of the objects so it sees all the foot that when applied you can see in the reflection.
In your case the only way would be several probes like one in the middle of each foot and probably one in the middle of the top which would be way to expensive.
Regarding #2, that’s because the reflection texture must be filtered so that the right mip level can be used depending on the roughness of the material. You can use the realtimeFiltering property to enable this: