Hi! I recently start to explore raytracing possibilities of HDRP and found one peculiarity that do not know how to handle.
I enabled RTX and found out that Initilization step of HDRP become 3x bigger than before (from 2-2.5ms to 6.5-9.5ms). I expected that frame time increase but not in this place.
I tested on the clean project and I manage to narrow what caused that. It was
BuildRayTracingAccelerationStructure method. I checked the code and I found that it trace all scenes for all
HDAdditionalLightData,
HDAdditionalReflectionData,
LODGroup,
Renderer.
This method uses GetSharedMaterials, GetComponents, null checks for every Renderer, Mesh, Material and Shader in scenes and etc. Frame time always depends for how many objects do you have but Unity managed to cull it if it is not inside Frustrum and it did not trace the scene through C#. With this approach for building RT Acceleration Structure I would have to come back to combining mesh on build and creating atlases instead of rely on SRP Batcher
I also want to mention that this code produce 16KB allocations every frame.
Any thoughts about it? Does anyone know if Unity plan to change it?
There is a new engine side Scripting API function in development RayTracingAccelerationStructure.CullInstances which will replace the C# code. It will filter, cull Renderers and populate the acceleration structure, is multi-threaded and uses SIMD for culling (relative to user defined Sphere/Planes). Target version is 2022.1 - 2022.2.
This is interesting, will it replace the entire C# BuildRayTracingAccelerationStructure function, and will we still be able to use our own optimizations?
I am currently running my own burst/jobs + cached version of the HDRaytracingManager. I calculate an āimportance angleā (using the mesh diameter, distance to camera) and use this value to determine at which interval the transforms need to be updated in the acceleration structure. For example, objects close to the camera (important) could have their transforms rebuilt at 60hz, and smaller objects in the distance (unimportant) at 5hz, to avoid unnecessary CPU main thread & GPU/BVH workload. Renderers that have an āimportance angleā below the specified cutoff threshold are culled on GPU hardware but kept in the HDRaytracingManager cache.
Here is an example of the ray tracing stack running at 200-300 fps.
Also, do you happen to know if this potential API that Anis mentioned around february is still planned? ([original post]( https://discussions.unity.com/t/738275 page-24#post-6823508))
Would be cool if this could work together with RayTracingAccelerationStructure.CullInstances somehow. Iām open to every solution, Iām mainly trying to eliminate all ray tracing CPU cost for VR.
Edit
Just saw this PR pop up, will be keeping an eye on this.