Clipping Plane Shader but with Bounding Box showing inner box

Hey guys,

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

so far ive tried to achive this effect with these (unsuccesful):

Would be great if someone could point me in the right direction.

Hi gegenlicth, if you dont need the plane rotation you could try to cut it by the uv like that
imagen

in this case in the texture but you could cut the geometry if it is really needed as well by clip or discard function.

hope it helps.GouraudDirectionalCutterAlpha.zip (8.6 KB)

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

@microdee ahh pretty cool way. could you provide a simple example patch of it ?

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 :)

( PS_Slicer )

This might be a good chance to learn a bit of shader stuff. ( at least understanding structure better )

The UV Solution by @colorsound might also create insane effects with more complex UVs :)

image

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)

DfClipping.zip (5.1 KB)

it should look like this:

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:

return -(abs(p.y)-0.5);

2 Likes

HI @microdee, awesome ¡¡ , thanks for that great example.

Crazy effect @microdee thx! Very useful for many scenarios, not sure i will be able to understand the inner workings ;D

Thanks for sharing microdee

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.