im looking for a shader working like the Rastertek Clipping Plane Tutorial but working with 2 Planes to Clip an Object on the Y-axis twice. So Top and Bottom cut off.
In the Rastertek Clipping Plane Shader Multiple Clipping planes will create another shaded Geometry view.
Having a shader with a Bounding box that only shows Vertices within the Boundingbox would be nice
what if I told you you can clip to any shape with distance fields with just 1 line of HLSL in pixel shader (+ couple of boilerplate) ;) ;)
clip(df(input.wpos));
where “df” is your signed distance function (which can be of any arbitrary shape) and you have to write the world position from vertex shader into your PS input struct too
thx @all! i will first try to copy the shader by @antokhio into one of the fancy pbr like shaders. it seems to be easy to spread this with different meshes. Trying to mix similar meshes together :)
I have used the PS slicer example from antokhio recently (thanks for sharing btw!) and it was quite easy to integrate it into other shaders (i am not very experienced with hlsl btw). So this seems a robust way to go, can recommend ;)
And just an additional spin, maybe helpful to others too (just curious): What i wondered if it could be expanded to not discard the pixels hard but have a kind of fade to alpha within a controlled area? Or would it need a completly different technique?
here’s an example for the distance field approach, and it allows for “free” fading like @tgd said. Using with AlphaToCoverage and 8xAA it is even order independent (although a bit banded)
Take a look at lines 86, 109…123 and 127…132. What happens: there’s our distance function lerping between a box and a torus and then we feed it a world position which we can inverse transform before that. That’s how we rotate the thing. Because we’re dealing with distances we can use it to also fade in “approaching” the surface (distance==0) and that’s what you can see with the “alpha” variable. Also if you want to understand more of this, check out the FieldTrip pack.
and to not be offtopic here’s with a different function: