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. Dismiss Notice

Feedback ObjectBoundingSphere does not take scale into account on frustum culling

Discussion in 'Project Tiny' started by Thaina, Dec 29, 2019.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,049
    Test by making a plane. Scaling to any size does not change the size of the bounding sphere itself

    upload_2019-12-30_2-30-26.png



    Looking at the culling logic also don't taken into account about scaled value

    upload_2019-12-30_2-31-46.png



    As a result it has a bug in frustum culling. Just moving camera pass the center of any object that has scaled will culled that object out

    upload_2019-12-30_2-37-35.png


    updated :

    Found out that the actual problem came from here

    upload_2019-12-30_2-56-32.png

    While the actual component is CompositeScale

    upload_2019-12-30_2-58-9.png

    So the code above actually need to be changed into

    Code (CSharp):
    1.             // update bounds -- spheres
    2.             Entities.WithAny<Scale,NonUniformScale,CompositeScale>().ForEach((Entity e, ref ObjectBoundingSphere ob, ref LocalToWorld tx, ref WorldBoundingSphere b) =>
    3.             {
    4.                 b.position = math.transform(tx.Value, ob.position);
    5.                 // only if there is scale
    6.                 float3 scale = new float3(math.lengthsq(tx.Value.c0), math.lengthsq(tx.Value.c1), math.lengthsq(tx.Value.c2));
    7.                 float s = math.sqrt(math.cmax(scale));
    8.                 b.radius = s * ob.radius;
    9.             });
    10.             Entities.WithNone<Scale,NonUniformScale,CompositeScale>().ForEach((Entity e, ref ObjectBoundingSphere ob, ref LocalToWorld tx, ref WorldBoundingSphere b) =>
    11.             {
    12.                 b.position = math.transform(tx.Value, ob.position);
    13.                 b.radius = ob.radius;
    14.             });
    15.  
     
    Last edited: Dec 29, 2019
  2. v_vuk

    v_vuk

    Unity Technologies

    Joined:
    Jul 11, 2017
    Posts:
    36
    Thanks, I've filed this in our bug tracker -- one wrinkle, the in-Editor Entity Conversion preview does not display the dots runtime/tiny converted values, it's instead displaying the hybrid renderer conversion data. (Will be fixed soon.) Which might mean that the hybrid renderer has the same bug.
     
  3. sebastianm_unity

    sebastianm_unity

    Unity Technologies

    Joined:
    May 3, 2018
    Posts:
    21
    Fixed for next version
     
    Thaina likes this.
  4. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,049
    One Question

    Can Entities query system allowed for query with interface type?

    I think functionality like this should be taken with interface. Such as in this culling system, all of the `struct xxxScale` should attach an `interface IScale { }` so we could just write`Entities.WithAny<IScale>` and `Entities.WithNone<IScale>` and even if, in the next version, we introduce new kind of `ComponentData` that related to scaling we could also attach `IScale` to it and the frustum logic will still work fine

    We could let interface be a group of signature for filtering. It would be more convenient when we have various shape of data that could be grouped and managed together