Search Unity

Bug Hybrid Renderer doesn't render objects past ~ - 32785 units in X direction

Discussion in 'Graphics for ECS' started by Dimetrock, Jan 4, 2021.

  1. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    Hi,

    I found a very weird issue with the Hybrid Renderer. It will not render objects that are more than ~ -32785 units away from the center of the scene on the X-axis. There are no problems with any other axis.

    Here are the scripts that I used:

    Script for making prefab entities:
    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. namespace UnityTemplateProjects
    4. {
    5.     [GenerateAuthoringComponent]
    6.     public struct PrefabsEntityComponent:IComponentData
    7.     {
    8.         public Entity Prefab;
    9.     }
    10. }


    Script for spawning entities:

    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Entities;
    3. using Unity.Mathematics;
    4. using Unity.Transforms;
    5.  
    6. namespace UnityTemplateProjects
    7. {
    8.     public class PrefabSpawnerSystem:ComponentSystem
    9.     {
    10.         private bool _spawned = false;
    11.  
    12.         protected override void OnUpdate()
    13.         {
    14.             if (_spawned) return;
    15.             var treesPrefabs = GetSingleton<PrefabsEntityComponent>();
    16.             var objects = EntityManager.Instantiate(treesPrefabs.Prefab, 128 * 128, Allocator.TempJob);
    17.  
    18.  
    19.             for (int y = 0; y < 128; y++)
    20.             {
    21.                 for (int x = 0; x < 128; x++)
    22.                 {
    23.                     EntityManager.SetComponentData(objects[ y * 128  + x],
    24. new Translation{Value = new float3(-(y * 128 + x) * 5, 0, 0)}); //Here is a problem at ~ -32785
    25.                     //EntityManager.SetComponentData(objects[ y * 128  + x], new Translation{Value = new float3((y * 128 + x) * 5, 0, 0)}); // X Right - Fine
    26.                     //EntityManager.SetComponentData(objects[ y * 128  + x], new Translation{Value = new float3(0, 0, (y * 128 + x) * 5)}); // Z Forward - Fine
    27.                     //EntityManager.SetComponentData(objects[ y * 128  + x], new Translation{Value = new float3(0, 0, -(y * 128 + x) * 5)}); // Z Backward - Fine
    28.                     //EntityManager.SetComponentData(objects[ y * 128  + x], new Translation{Value = new float3(0, -(y * 128 + x) * 5, 0)}); //Y Down - Fine
    29.                     //EntityManager.SetComponentData(objects[ y * 128  + x], new Translation{Value = new float3(0, (y * 128 + x) * 5, 0)}); //Y Up - Fine
    30.                 }
    31.             }
    32.  
    33.             objects.Dispose();
    34.             _spawned = true;
    35.         }
    36.     }
    37. }


    Screenshot_3.png

    Does anyone know how to fix this?

    Thank you in advance.
     
  2. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Aren't you supposed to set positions inside a ForEach using the Entities-loop approach?

    [edit] Also 32-bit float imprecision at longer distances from the origo could be an issue.
     
  3. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    The position is set only during the instancing phase and irrelevant in this case.

    32-bit precision could result in shaking behavior or blinking or anything else. In this case, it just stops rendering past a certain point and only in the negative direction of the X-axis.

    In the code, there are commented lines which I checked for other directions and they are fine for more than 80000 in each direction. And from the project that I am working on, I can tell with confidence that up to 100000 units in each direction there is no problem with floating-point precision.

    There has to be some sort of bug with the Hybrid Renderer.
     
    Nyanpas likes this.
  4. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I am not arguing against the potential bugs in the Hybrid Renderer, but I have tested it myself as well now for the Parametric Object Creator I posted in another thread, and after tweaking the shaders a bit I never had any issues with things not being rendered (within +/- 9999 units of origo). It's so far seemingly only been a shader-issue for me unless I goof'd with the generation code and forgot to write the correct data to the meshes.
     
    Last edited: Jan 5, 2021
  5. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    So you haven't tested placing objects at Vector3(32785,0,0) position and checking if they are rendered by the Hybrid Renderer?
     
  6. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    No, I only place within +/-9999 units from Origo because I am rather paranoid about floating point imprecision.

    (Sorry it seems I left that out.)
     
  7. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    Would it be possible for you to submit a bug report with a repro project about this?
     
  8. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    Already did, the ticket number is: 1303485
     
  9. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    May I ask, why you trying to render something beyond 10k distance?

    This is a range where loosing precision start causing issues as mentioned earlier.
    Camera and physics can become jittery and things start glithing out.

    You should bring anything visually related, below 10k range (abs).
    If you must, use shift origin approach.
     
  10. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    As mentioned before, there are no issues with precision loss at those distances. And I am telling this based on my experience. There is no physics in my game, so I don't have to worry about that. As to everything else I don't see any problems so far.

    The shift origin approach results in frame rate stuttering, the moment origin shifts is quite noticeable as you have to move every object in the scene in one frame.

    As to "Why?" - this is irrelevant in this case. I expect the Renderer to behave the same regardless of where the object is placed. Think of this example: You can place objects in any position in the scene but not at (-500, 0, 0) as there it would not be rendered - would such behavior would be ok or this would be a bug?
     
    Last edited: Jan 20, 2021
    FearIndigo, djsell and xshadowmintx like this.
  11. FearIndigo

    FearIndigo

    Joined:
    Aug 17, 2017
    Posts:
    8
  12. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    This issue should be fixed in the latest published version of Hybrid Renderer, 0.11.0-preview.44
     
  13. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37
    Confirming, the issue is fixed.
     
  14. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
  15. Dimetrock

    Dimetrock

    Joined:
    Dec 9, 2012
    Posts:
    37