Search Unity

Why does my shaders stop rendering at a certain angle?

Discussion in 'Shaders' started by greedyonyoutube, Mar 21, 2017.

  1. greedyonyoutube

    greedyonyoutube

    Joined:
    Oct 31, 2015
    Posts:
    5
    I'm trying to make a nice looking forest to a new game im working on. But theres a problem with the rendering of my shaders. I have it currently setup to render close by trees with an 2d-sprite renderer. And the other trees that arent close enough will get render using the shader instead. But the problem is with the trees that are using the shader. Cause when i look at them and move my camera up they just stop rendering.. why?

    Here's a gif of what i mean.
    https://gyazo.com/64acbf5cadd9a89b0ba2cd5f123605ce

    And here's my shader script.
    http://pastebin.com/QjCwqaK9
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    The objects get frustum culled. The culling is done on the bounding box of the object.

    You're adjusting the vertices in the shader so they fall outside the original bounding box. This means the culling process can sometimes assume they are invisible, while they actually are visible.

    The solution is to match the bounding box with the actual maximum displacement in the vertex shader.
     
    greedyonyoutube likes this.
  3. greedyonyoutube

    greedyonyoutube

    Joined:
    Oct 31, 2015
    Posts:
    5
    Could you explain how i do that?
     
  4. greedyonyoutube

    greedyonyoutube

    Joined:
    Oct 31, 2015
    Posts:
    5
    I found a solution. I created a new quad-gameObject. Added a new scripts and added this to the Start() method and that seems to have fixed it.
    transform.GetChild(0).GetComponent<MeshFilter>().sharedMesh.bounds = new Bounds(new Vector3(0, 0, 0), new Vector3(1, 1,1) * 10.0f);
     
  5. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Yes, you can adjust the bounds like that. You should try to keep it as small as possible of course, because frustum culling is generally a good thing.
     
    greedyonyoutube likes this.
  6. greedyonyoutube

    greedyonyoutube

    Joined:
    Oct 31, 2015
    Posts:
    5
    Okey i'll keep that in mind! Thanks lad for the help! ^^