0

I'm using

Graphics.DrawMesh(mesh, _matrix, material, 0, cam);

and my mesh is too height , so when move camera and when mesh inside in screen , it's not show early. it cullinged. but when I new a Gameobject with MeshRenderer, it's no problem , it culling well, not too early. So what diffrence on here??

And I try to set mesh Bounds like this :

mesh.bounds = new Bounds()
            {
                center = Vector3.zero,
                extents = mesh.bounds.extents * 1000,
                max = mesh.bounds.max * 1000,
                min = mesh.bounds.min * 1000,
                size = mesh.bounds.size * 1000
            }; 

it's still not working .

Is also try this code: still not working...

void OnPreCull()
     {
         cam.cullingMatrix = Matrix4x4.Ortho(-99999, 99999, -99999, 99999, 0.001f, 99999) * 
                             Matrix4x4.Translate(Vector3.forward * -99999 / 2f) * 
                             cam.worldToCameraMatrix;
     }
 
     void OnDisable()
     {
         cam.ResetCullingMatrix();
     }
TimChang
  • 2,249
  • 13
  • 25
  • could you be getting caught up by some simple gotchyas .. https://stackoverflow.com/a/36202761/294884 (notice the paragraph in ( ) brackets ) – Fattie May 12 '21 at 13:51

1 Answers1

1

You shouldn't have to manually set the bounds of a mesh unless you have some crazy custom shader that drastically moves some vertices around.

If you're using a Unity Shader then you should be able to call mesh.RecalculateBounds(); and have no problems

Charly
  • 450
  • 2
  • 13
  • this might help (might be a unity bug?) https://forum.unity.com/threads/graphics-drawmeshinstanced-and-culling-the-how-and-why.633508/ – Charly May 12 '21 at 04:56
  • Yes I also looked this thread , And I don't really understand how to fix that. it's mean chagne vertex positon? – TimChang May 12 '21 at 07:09
  • some discussion .. https://stackoverflow.com/q/55418971/294884 – Fattie May 12 '21 at 13:52