Control 3d object´s texture sampler with a mask from 2d viewspace


I would like to render 3d geometry with two different textures. Then having a quad in 2d space i want swap the texture sampler where the quad is occluding the 3d geometry. So basically sample tex1 but when quad overlays then sample tex2.

I have already adapted @antokhio ´s shader from this thread to do this with a 3d box but the cut follows the object geometry depending on the box position and projection. I would like a straight cut as seen from 2d viewspace.
Maybe it would be sufficient to transform the box somehow. Right now i am just making it always face the camera but thats not enough since it has a depth.

Patch and slicer shader: (3.8 KB)

Cutting in 3D:


I would like from 2d (mockup):



The cutting shader transform works in worldspace. You want an orthogonal cut without perspective. A quick and dirty workaround would be rendering two identical scenes with different textures and using a mix.fx to do a 2d composit. But if you need perfomance maybe someone with better hlsl knowledge is able to help you code it.


Yes i have tried projecting the box orthogonal but could not set it up properly, basically the box had no depth then, not sure what i am doing wrong. And yes, want to avoid the compositing route for performance reasons.


you could use ProjectConstant


the screenshots may be misleading, the texture is uv mapped, i dont want to project it. i had already thought of the solution but did not try yet. it should be just checking the pixels 2d coordinates in the shader, so may be very easy.


This normally called projected texture.
You take cords of your screen space and project them on mesh, it’s better to have that in the pixel shader (artifact free).

Basically you still take your original uv of the mesh and do an if switch somewhere:
If (projectedUv.x < 0.5)

more simple:
col = lerp(tex0.Sample(s0,uv), tex1.Sample(s0,uv), projectedUv.x < 0.5);


ah i see, did not know that projected is meant like that. thanks for your help!