Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Rotating rect on a billboarded shader

Discussion in 'Shaders' started by jnic00, Apr 20, 2022.

  1. jnic00

    jnic00

    Joined:
    Apr 10, 2016
    Posts:
    3
    I'm a beginner in shader programming so it's probably an easy problem. I have a billboard shader that make a sprite always facing the camera. It's working pretty well, my only issue is that the occlusion culling is not working as expected because the sprite is "standing" on the ground but the shader make it so that its at 30 degrees. So close to the edge of the screen the sprite disappear because the sprite rect is untouched and standing.

    How can I rotate the rect to make it angle the same way as the sprite so that the culling works ?

    Thanks!
     
  2. Glenn-Korver

    Glenn-Korver

    Joined:
    Dec 11, 2015
    Posts:
    34
    sounds like Frustrum culling, which happens when the Camera thinks the bounds of the mesh no longer overlap with its frustrum. The easiest solution would be to manipulate the bounding box of your mesh / meshrenderer in c# once, set it big enough to never cause this issue
     
  3. jnic00

    jnic00

    Joined:
    Apr 10, 2016
    Posts:
    3
    Can I rotate it ? How would that works ?
     
  4. Glenn-Korver

    Glenn-Korver

    Joined:
    Dec 11, 2015
    Posts:
    34
    https://docs.unity3d.com/ScriptReference/Renderer-bounds.html

    the render's bounds is an axis alligned box so you cant rotate it, you could technically keep adjusting the bounding box to most closely encompass your sprite/quad at all times every frame, but instead I advice to you to just make it large enough once to always be large enough to encompas any orientation
     
  5. jnic00

    jnic00

    Joined:
    Apr 10, 2016
    Posts:
    3
    Ok sounds perfect, Ill try this out. Thank you!