Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Preventing rendering within an area

Discussion in 'Scripting' started by ATLAS-INTERACTIVE, Jan 11, 2015.

  1. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I am trying to prevent an area from rendering within a collider (or similar), I am aware of how to simply deactivate the renderer within a collider, but I want to hide only the parts within the collider, so I could hide PART of a face for example, I am doing this because my walls require multiple different materials (easier to do with separate pieces) and I also want to include lights, which are models which have to intersect with the wall and appear flush with it, which leads to the Z buffer getting confused and resulting in Z fighting, this is what I want to prevent, the Hammer engine for Portal 2, as well as other games with level editors does this very well, and I am trying to replicate the same effect, allowing me to build my maps easier.
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Multiple renderers?
     
  3. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    This would not prevent rendering in one single area, I want to be able to occlude a part of an object or part of a face, so some clever "smoke and mirrors" may be required for this
     
  4. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    If it has to take place on part of a polygon or object you would need some shader trickery, by blending out the alpha per fragmeant based on its world position.
     
  5. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    This would be a problem because the wall texture is tiled across it. So I am not sure how well a blended shader would work, or whether it would just create loads of tiled holes all over the place
     
  6. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Its done world space dosnt matter if it is tiled it does it based on the location of the frqgmeant in the world. Just a little complex to tight such a shader. But you more or less have to get the collider bounds into the shader, and use that data for some if statements.
     
  7. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Have you done this before, would you be able to supply a shader or example? we have one programmer and he does not work with shaders apparently.
     
  8. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Well I'm not home till late tomorrow but I will see if I can make a sample. Will warn you it would be a expensive shader, since it would need to do a "if" on every fragment