Sign in to follow this  
JonVarner

Is it possible to remove a submesh from self shadowing

Recommended Posts

I have a use case where I have a mesh made up of a handful of sub meshes. But I do not need all of them to contribute to the self shadowing to get a convincing shadow. Plus on some of the smaller sub meshes the self shadowing does not look that great.  So I was wondering if anyone could point me in the direction of how to either exclude submeshes from self shadowing or to simply include the ones I do.

I am currently using this to achieve self shadowing on the entire object :

var shadowGenerator = new BABYLON.ShadowGenerator(2048, light2, true,true);
shadowGenerator.getShadowMap().renderList.push(window.complete_model);
shadowGenerator.usePoissonSampling = true;

 

Share this post


Link to post
Share on other sites

i tested a bit but fail to see any difference in shadows...

but to your problem, try push only the meshes you want shadows on.

Like in your code u push the @whole model....

normally there can be about 5-10 meshes in one daddy mesh.

only one of those represent the full object

If you iterate the scene.meshes you can find out what number belong to what meshname 😃

shadowGenerator.getShadowMap().renderList.push(scene.meshes[10])

 

Share this post


Link to post
Share on other sites

I played around with it quite a bit. @droggam I thought your approach was intriguing but the meshes you pointed to don't correlate with the sub meshes. In the end I think it would be sufficient to simply not have the shadow map show up on some of my sub meshes. In other words is there a way to calculate the shadow map as normal with all the sub meshes in the mesh, but not actually display the shadow map on some of the sub-meshes. My primary reason for this is that on some of the smaller objects the shadow map just does not look that great and I don't need the shadows on those pieces anyway. So it would great if I could tell babylon which sub meshes the shadow map would show up on, and simply not show the shadow results on the other submeshes.

Share this post


Link to post
Share on other sites

var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
Next, you have to define which shadows will be rendered. Here we want the shadow of our torus, but you can “push” any meshes you want:

shadowGenerator.getShadowMap().renderList.push(torus);
Introduced with babylon.js v3.1, there are two new helper functions to deal with shadow casters:

addShadowCaster(mesh, includeDescendants): Helper function to add a mesh and its descendants to the list of shadow casters
removeShadowCaster(mesh, includeDescendants): Helper function to remove a mesh and its descendants from the list of shadow casters
And finally, you will have to define where the shadows will be displayed... by setting a mesh parameter to true:

ground.receiveShadows = true;

 

@JonVarner check this out!

Its as much as i can help you its from THE documentation...

You have two helper fn to either add/remove meshes like u asked

Descandents is same submesh

Cheers.

Share this post


Link to post
Share on other sites

@droggam, thanks yes I have seen this. In fact this was why I posted as it seemed possible. However, in the helper function, "includeDescendants" is actually a boolean as opposed to a list, meaning that all descendants would be included. Second, I don't think submeshes are children. I could be wrong, but if you run something like: window.complete_model.getChildren() on a single mesh with many sub meshes you will actually get and empty array.

Anyway, it seems that getting this to work is possible. I just have not discovered it yet. :)

Share this post


Link to post
Share on other sites

Hmm, I have shadows working already. My question was about sub-meshes. If you look at your code you are still working with meshes "newMeshes[0]". What I was trying to do was something more along the lines of "newMeshes[0][2]" for example. Anyway, I have given up and decided to split those sub meshes out as separate meshes for now. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.