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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Instancing and Culling ( make it stop! )

Discussion in 'General Graphics' started by mradfo21, Jan 6, 2018.

  1. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Hey guy!

    It looks like Unity is performing some kind of frustrum culling on the geometry i render via the new hardware instancing using Graphics.DrawMeshInstanced. How do I disable this or alter the bounds via Graphics.DrawMeshInstanced ?

    I'm taking geometry and inside the vertex shader snapping it to my terrain surface. This is awesome and fast, but i'm noticing its culling it because the displaced positions are outside of the original geometry's bounds. Is there a way to turn this off / adjust the bounds ?

    You can see in this video I'm moving my camera up and down and the objects are popping on and off because their displaced positions aren't represented by the bounds. Save meeee Unity ?

     
  2. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    so the solution i found is hacky but works.. for anyone else. This is SO a unity problem though. If you just draw all your geometry at the y position of the current rendering camera, it wont be frustrum culled. then in the vertex shader you can transform it using object space. before is was displacing like.. worldPos.y += heightmap.y

    buuut

    worldSpace.y = terrainPositionObject.y + v.vertex.y * worldScale.y;

    works.

    and the world scale of an object is
    float3 worldScale = float3(
    length(float3(unity_ObjectToWorld[0].x, unity_ObjectToWorld[1].x, unity_ObjectToWorld[2].x)), // scale x axis
    length(float3(unity_ObjectToWorld[0].y, unity_ObjectToWorld[1].y, unity_ObjectToWorld[2].y)), // scale y axis
    length(float3(unity_ObjectToWorld[0].z, unity_ObjectToWorld[1].z, unity_ObjectToWorld[2].z)) // scale z axis
    );

    props to Bgolus in the forums for pointing this worldscale thing out. found it after digging around
     
  3. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    This. I'm not sure how methodology can be fixed, but there's a dramatic problem of anticipating usage of any given feature. Most additions to the engine are awesome in the extremely narrow space envisioned at the time of implementation, usually totally failing to see how it could help in the bigger picture if properly exposed. Since 2008 it seems that a vertex's rightful place is where the data says so - not its shader, and frustum culling is a primordial force of the universe. Yay for yet again more bounding box hacks.