Search Unity

Question How to override RenderBounds baking ?

Discussion in 'Graphics for ECS' started by filod, Aug 25, 2023.

  1. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    my shader does some vertex change, but this can not be reflect in frustum culling since it's using bounds.

    my question is how to override the default RenderBounds baking to make culling correct ? thx!
     
  2. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    284
  3. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    224
    i solve this by place my code in `OnValidate`:
    Code (CSharp):
    1.  
    2.     private void OnValidate()
    3.     {
    4.         if (GetComponent<MeshFilter>() != null)
    5.         {
    6.             var mf = GetComponent<MeshFilter>();
    7.             mf.sharedMesh.RecalculateBounds();
    8.             var bounds = mf.sharedMesh.bounds;
    9.             bounds.size = // set bounds what you want;
    10.             mf.sharedMesh.bounds = bounds;
    11.         }
    12. }
    this will auto set the bounds before ECS baking.
     
    apkdev likes this.