Search Unity

Unity3d render texture based on position

Discussion in 'Scripting' started by Kgpmurray, Jul 30, 2013.

  1. Kgpmurray

    Kgpmurray

    Joined:
    Jul 24, 2013
    Posts:
    7
    I'm currently trying to create a container in Unity with multiple quads inside, and am looking for a way to stop parts of the quad that fall outside of the containers bounds from being rendered?

    I just spent twenty minutes trying to fiqure out how to explain the problem properly (and failed) so created this pretty picture instead. The red line represents the bounds with the black squares representing my textured quads.

    $Example.png
     
  2. groovounet

    groovounet

    Unity Technologies

    Joined:
    Jul 15, 2013
    Posts:
    16
    I think that what you need is a scissor test or maybe a stencil test. I don't believe either of then is exposed by Unity.

    A workaround this, not necessarily very efficient, is to use a uniform to store a rectangle of the area where you want to render and pass it to the fragment shader as a uniform. Then you can use the shader clip function to discard each fragment that doesn't fall into that rectangle.

    To discard the fragments, you will need to get the pixel position in clip space which is stored in VPOS semantics.
     
  3. wolvz38

    wolvz38

    Joined:
    Feb 6, 2013
    Posts:
    66