- Home /
Render a 3d world as a 2d slice
Hello, I need a way to render the cross-section of a plane (camera) and all the meshes on the scene. My camera is orthographic and has a far clip plane of 1. That means that the typical cross-section shader will not work, because that only works with depth. I have tried raymarching, and it worked perfectly, but I dont want to be limited to signed distance fields.
Answer by Sp1d3r · Aug 14, 2020 at 12:45 PM
Hey, I am looking for the exact same thing as you. Have you come to any solution yet?
Answer by TomArano_Dimenco · Aug 14, 2020 at 03:27 PM
A while back i made a fragment shader that was able to get world positions and discard them when above z=0 (i was making a cross section on z = 0) i also had the problem that i could not make it work with normal camera depth as my camera is doing some weird off axyl custom matrix rendering and my 'slicing' needed to be done straight..
its been a while so poke me again if u cant make it work.
adding a field to the v2f struct:
float4 worldSpacePosition : TEXCOORD0;
filling that field in the vert function:
o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex);
using the field int he frag function to discard pixels.
float4 pixelWorldSpacePosition = i.worldSpacePosition;
if (pixelWorldSpacePosition.z < 0)
{
discard;
}
i can remember u had to add this line to make it work:
Blend SrcAlpha OneMinusSrcAlpha
I think this should be enough info to make this shader, let me know if u cant make it work than i'll clean up my code next week and post a shader here.
Your answer
Follow this Question
Related Questions
Render the scene only using a given a renderType tag 2 Answers
Render object ID to texture 2 Answers
Point light becomes invisible when in front of UI panel 1 Answer
How do I use both a color's alpha and the texture's alpha in a shader pass? 0 Answers
Standard shader's Fade rendering mode won't allow full opacity with a textured material 0 Answers