Clipping fur meshes to not render through other meshes

Hello!

I’m puzzled how to solve a problem with fur material (high level fur).
I need to prevent it from rendering through adjacent meshes.

Tried to use clipping planes but it doesn’t work for my geometry.
Rendering groups also can’t help — because you can view that object from different angles.

Maybe there are some tricks to clip rendering by a mesh?

Any suggestions?

You could use the stencil buffer:

  • make sure the hat is drawn before the fur (for eg, create the hat object before the fur ball)
  • draw the hat in the stencil buffer with a 1 value
  • draw the fur ball with a comparison function “!= 1” so that it does not overwrite the hat

For eg:
https://playground.babylonjs.com/#XJ6J92#3

However, you will see that depending on the view, you can still see the tip of the sphere, and you would need to enable the stencil writing only for the front faces, not the ones on the back. In your case, the hat has some thick edges and you may not need to look from behind, so maybe it would work.

I think a clipping plane that would clip the tip of the fur ball would work, however:
https://playground.babylonjs.com#XJ6J92#4

Of course, you will need to adjust the plane if the fur ball is rotating.

3 Likes

Thank you, will dig into it.

Clipping plane produces some aesthetic issues because hat isn’t flat at the bottom.

I’ve also tried to “cut some fur” via vertex shaders, but it’s getting complicated when you have more than one hat :slight_smile:

Stencil buffer did the trick perfectly! Thank you, Evgeni, once again! You’re super helpful :love_you_gesture:

2 Likes

He is the soul of that forum :slight_smile:

3 Likes