Hello,
I want the parts inside a box clipped for every mesh.
Before clip:
After clip:
Can I implement it by the 6 clipPlanes? or any other solution?
Thanks
Hello,
I want the parts inside a box clipped for every mesh.
Before clip:
After clip:
Can I implement it by the 6 clipPlanes? or any other solution?
Thanks
Yup I think clip planes will work fine
Using the standard clip planes wonât work because one plane clips off an entire half of the space: for example, in your example, the leftmost plane will remove everything on the right, so most of the excavator arm will be removed too.
Youâll need to use a custom fragment shader that will check all 6 planes and discard the fragment if the point lies within the interior formed by the 6 planes.
Note, however, that you wonât get exactly what youâve pictured. Meshes arenât volumetric, so when theyâre clipped by a plane, youâll see an empty space, like this:
@Evgeni_Popov , thanks for your reply, you got the two points I need to solve.
And I still need someone to help me:
1ăIâm poor at shader, can anyone give a guide how to implement such a custom fragment shader, as standard clipplanes wonât work here.
2ăAnyone has idea to generate a special plane, so meshes look not empty after clipped? Just like the picture I post.
Afterwards for example create ShaderMaterial for the mesh. Then find and set clipping box shader code like code parts in here:
For 2/, you can try to fake it by disabling backface culling, and if the current pixel of the fragment shader is from a back face, use a fixed color.
You can reuse most of the existing shader code for the clip planes, but you must disable what the fragment shader is doing and replace it by your own one (see line 1 in the PG below).
Hereâs one way to do it with a material plugin:
@Evgeni_Popov , thanks for your fanstanstic idea, it is really close to what I need.
But I have one more question:
After replacing the clip fragment to my own, If I want to resume to the original, how can I do?
I have a PG here, the âswitchâ doesnât work.
https://playground.babylonjs.com/#A8FURG#2
You canât really do it by changing the code in the include shader store because our cache mechanism wonât see the change and wonât recompile the effect.
You can do it with the material plugin from my PG:
Of course, when switching, you wonât see anything because the 6 clip planes are still in effect, and this time each plane removes half of the space!