Scissor/Clip Drawing Region

Avatar
  • updated
  • Completed

A lot of immediate mode drawing APIs contain a way to set a scissor/clip region. This is particularly useful for things like scroll views. Is there any way to do that in Shapes? If not, is it something that could potentially be added?

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Completed

sorry, I'm on vacation with no computer!

but something like this:

    Draw.StencilRefID = 1;

    Draw.StencilComp = CompareFunction.Always;

    Draw.StencilOpPass = StencilOp.Replace;

    // draw mask here

    Draw.StencilComp = CompareFunction.Equal;

    // masked things here

Avatar
Freya Holmér creator

You can use the stencil buffer features for that!

First, draw shapes with stencil op replace with stencil id 1. this will define the mask


then, for everything you want to only render inside, set stencil test to equal, and id to 1







Avatar
Cornell Daly
Quote from Freya Holmér

You can use the stencil buffer features for that!

First, draw shapes with stencil op replace with stencil id 1. this will define the mask


then, for everything you want to only render inside, set stencil test to equal, and id to 1







Oh great! Sorry for the potentially dumb question, but when you say "and id to 1" in the last line, what do you mean by that exactly? I'm using the immediate mode API if that matters.

I gathered that stencil op is Draw.StencilOpPass, the initial stencil ID is Draw.StencilRefID, and the stencil test is Draw.StencilComp. Just a little confused on the last part.

Avatar
Freya Holmér creator
  • Answer
  • Completed

sorry, I'm on vacation with no computer!

but something like this:

    Draw.StencilRefID = 1;

    Draw.StencilComp = CompareFunction.Always;

    Draw.StencilOpPass = StencilOp.Replace;

    // draw mask here

    Draw.StencilComp = CompareFunction.Equal;

    // masked things here

Avatar
Cornell Daly
Quote from Freya Holmér

sorry, I'm on vacation with no computer!

but something like this:

    Draw.StencilRefID = 1;

    Draw.StencilComp = CompareFunction.Always;

    Draw.StencilOpPass = StencilOp.Replace;

    // draw mask here

    Draw.StencilComp = CompareFunction.Equal;

    // masked things here

Got it, thank you so much for explaining it! Enjoy your vacation! :)