- Home /
Mesh Clipping / Cross Sections
I've seen a few examples of creating shaders to get a "cross section" effect for objects, as seen in these examples on the Unity Forums:
Shader for Clipping Plane
Simple Cross Section Shader
These shaders affect all objects that have the shader attached to them, however, and I need some way to have a different cross section on different instances of the same mesh (generated at runtime). I've thought about creating a separate instance of a material for each object (and then perhaps replacing the material once the effect is no longer needed), but this seems like it might not be the best idea.
Is there a simple way to get a cross section of a mesh (with or without a shader)? I don't necessarily need the "cut off" sections of the mesh to be capped, so a simple clipping plane is all I need, but I don't know if there's a way to make arbitrary clipping planes and move them around. I also need to be able to change how much of a mesh is "cut off" by moving a clipping plane or adjusting shader values (or something similar) at runtime. For my particular problem I just need everything above a certain point to be transparent - only put the material on the mesh up to a certain point. So if there's a way to dynamically chop the mesh off at a certain point, that would be fine.
Answer by Max Kaufmann · Aug 02, 2010 at 05:44 PM
Dup the material using UnityEngine.Material's cloning constructor, and then feed the clipping plane values as uniforms to the instanced pixel shaders.
Not duplicating the materials means that they have to share uniforms, which exhibits the for-all-objects behavior you describe.
Your answer
Follow this Question
Related Questions
[ problem ] transparent shader !!! 1 Answer
Textures not showing up 0 Answers
Multiple materials on same object 0 Answers
Triplanar surface shader not responding to Mesh.Colors 0 Answers
Texture2D to Texture3D 2 Answers