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:
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.
asked Jun 25 '10 at 07:29 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.
answered Aug 02 '10 at 05:44 PM