#Using stencil buffer to cut out two different planes

1 messages · Page 1 of 1 (latest)

coarse sphinx
#

Greetings. I'm a total beginner and need a specific way to cut out some planes of mine. I wanna simulate a very basic and shadow system with two static light sources and parallel shadows. And because you can't have two direct lights that cast shadows, I wanted to do it this way. Its for a quick project, so this should be fine.

In the view we got:

  • basic plane, which is grey and beneath the other two planes
  • Some blocks, where either of them has two shadow-planes, where one goes to the top right and one to the top left
  • red transparent plane, which cuts out the shadow-planes that go to the top right
  • blue transparent plane, which cuts out the shadow-planes that go to the top left

And with a very basic video about stencil, I was able to create the image attached. But there is a problem with the intersection of the shadow-planes. The intersection of the red and blue shadow should create a grey spot, because the red and blue light source are both blocked.

I tried to solve it myself, but to be honest, I still have problems understanding the stencil and shaders options.

Before I invest so much time, I wanted to ask if this is possible with the stencil shader at all, how would I do it if its possible or if there is an easier way to do this?

I use the 3D URP Render pipeline

blissful falcon
#

assuming neutral/default stencil is (0)

coarse sphinx
#

@blissful falcon
I'm actually having a problem to understand where I would put this in or how it would look syntactically. Currently I only wrote one basic shaders. Would I write that inside of that shader or do I need multiple ones for each color? Does the neutral one need a stencil at all, because it should remain intact?

I'm so confused on how this works, even though I watched multiple videos qwq

Blend Zero One
ZWrite Off

Stencil 
{
  Ref [_ID]
  Comp Always
  Pass Replace
}
blissful falcon
#

how do u currently draw the shadows

#

the geometry itself

#

@coarse sphinx

coarse sphinx
#

@blissful falcon sorry for the delayed response. So my shadows are just Quads that are placed on the same Y-axis as the three planes

#

Those shadows have the material of the shader. Blue ones got a stencil ID of 1 and red ones 2.

#

The two planes are on their own layers, red and blue, and I render them in the renderer myself

#

And the problem seem to be in the "Blue Shadows" settings, because when I only have the red shadows on, it looks correct. But when I only activate the blue one, it still has the problem.

blissful falcon
#

I can't help atm

#

sorry

#

The key will probably lie with ReadMask and WriteMask