I have a forest with trees (an imported mesh file, and created with createInstance) and I’m using a CascadedShadowGenerator to display shadows of the trees on the ground. When I move the camera I make sure trees that are blocking the view are hidden with tree.isVisible = false; , so the player is always visible.
But this also removes the shadow of the tree, which looks a bit unnatural when you move slowly.
Is there any way to hide the tree mesh, but still see the shadow on the ground?
Ideally, I would like to make the tree half-transparent, and keep the full shadow.
I couldn’t find out how to make the material of that specific instance transparent, if possible at all.
yeah you cannot play with alpha of only one instance unfortunately if we want to get the shadows
I don’t know how to do what you need. Maybe having a special version of the mesh that you could move exactly where the hidden instance is to generate the shadows?
const material = new BABYLON.StandardMaterial('do-not-render', scene);
material.disableColorWrite = true;
material.disableDepthWrite = true; // if you want to remove the mesh from the depth buffer as well
mesh.material = material;
@deltakosh We need a PG from @BobDylan so we can precisely answer his question. I believe we both agree.
He could remove the non-visible instances and add regular meshes. How many trees? How many vertices? How performant would replacing the non-visible instances with regular meshes be… Etc…
He could prepare the meshes and disable them so adding a shadow-only-mesh could be just enabling it…
Thanks for the tips. I’ll try to create a shadow-only mesh (don’t know how, yet ) or a half-transparent mesh and switch those when needed. I also saw a solution somewhere that worked with a shader, but I have no knowledge of shaders.
I find setting up a playground to be quite hard, since everything is in several typescript files and classes, (and I’m a bit hesitant to reveal too much of the game already).