- Home /
How do you set up a 3D object so that when you slice it with the camera's clipping planes, it is solid?
I am attempting to create a toggle-able mode on my camera so that it shows a 2D slice of the 3D objects in the world. I found a question similar to this. In fact, I think it is my exact question, except I do not understand the answer.
My scene is fairly simple: The camera, and a sphere at (0,0,0). If I set the camera's clipping plane to only show one unit along the z axis at 0. I would like a set up so that a circle is drawn. How would I achieve this?
Camera clipping won't do this.
Shaders is the way to go I believe.
The words noone has yet mentioned that might help you to search for are "cutaway" or "cross-section" shaders. There's several examples on the forums as well as elsewhere on the net.
Answer by Adam_Myhill · Dec 28, 2016 at 05:05 AM
I'm not sure the camera clip plane is the best method to achieve the look you're going for.
The fact is, that sphere isn't solid. Cutting it with the camera's near clip will just expose the backfaces of that hollow geometry. You could draw it again with a second render pass (like the link you shared) or give them a shader which is a constant value so it appears solid but it won't have any shape to it.
If you want it to look like it's actually holding light / has any illumination falloff, you'll need geometry to 'hold' that light, so maybe look at animating the model instead.
So I have a couple additional questions for you:
1) You mentioned "give them a shader which is a constant value so it appears solid...". Would you be able to explain this a little further? I am still new enough to unity to not know what it means.
2) You also said that cutting it "will just expose the backfaces...". For some reason, when I near clip $$anonymous$$e, it does not show the inside. (The far clip is set to a very large number) Any idea why this is?
3) I don't think I need to care about lighting. I'm doing a fairly constant/even lighting across everything anyway
If it helps, I found an animation of the type of thing I am wanting to do, which is taking a 2D slice of a 3D object. Unfortunately, I can only find a video, and not a gif. I have made the link go straight to an example though. It is slicing 2D cross-sections from a 3D balloon. In my case, imagine the balloon (or sphere) was crossing the z=0 plane, so my camera would render a similar animation as the video. Here is the link.
Finally: For any of the above explanations, if you would rather send a tutorial link, I am more than okay with that! :) I tried a quick Google search, but don't know what to look for. Secondly, if you have a recommendation on a completely different approach to solve this, I would be happy to hear it. I went with this as it was my only lead.
Hi, answers to your questions:
1) A solid / emissive shader will just appear a particular set colour - it won't show the light fallof of the inside of the object, so you can maybe get away with that because the constant colour won't reveal that you're just looking at the inside of the object. The outside and inside are the same - it's all one colour.
2) by default, Unity doesn't render the back sides of polygons. You could put this script on your objects which will make Unity draw the backfaces. It will look like you're seeing the inside of the object though which may be weird and that's why I mentioned the constant shader of answer #1
3) that's cool then, you might get away with it.
Try that link, mess around with 'Emissive' shaders on the object and see if that works out. Good luck.
Awesome. Thanks for the clarifications and explanations. I'll take a look at that script and the shaders. Whether or not I can make it work, I thank you for the help you've given me in understanding.
Cheers!