LuisaGroup / LuisaCompute

High-Performance Rendering Framework on Stream Architectures
BSD 3-Clause "New" or "Revised" License
675 stars 57 forks source link

Support for Sphere Primitives in Ray Tracing #150

Open ACMLCZH opened 1 month ago

ACMLCZH commented 1 month ago

Hello,

I’ve been using LuisaRender for scene rendering and I’m really impressed with its efficiency and performance. However, I’ve noticed that particles (represented as sphere primitives) are created as meshes in the scene. This can be memory-intensive, especially when rendering a large number of spheres or particles, even when the subdivision is set to 0.

I understand that OptiX, which is used in LuisaCompute for ray tracing, supports sphere primitives. This feature could potentially reduce the memory footprint and improve the efficiency of rendering scenes with a large number of spheres or particles.

In the LuisaCompute code, specifically in the file [src/backends/cuda/optix_api.h], I noticed that sphereArray is defined in BuildInput but it doesn’t seem to be used anywhere. I’m wondering if it would be possible to add support for sphere primitives in the ray tracing process using this or a similar approach.

It would also be helpful if you could provide some guidance on how to modify the LuisaCompute and LuisaRender code to support this functionality. For example, how to add spheres in CUDA in LuisaCompute and how to modify the accel_option in LuisaRender.

Mike-Leo-Smith commented 1 month ago

Hi, @ACMLCZH

We're very encouraged to hear that you're using Luisa in your work and thanks for the valuable feedback!

The optix_api.h file is generated from the official OptiX headers so the original sphere interfaces are included but we haven't made wrapper interfaces for it as a LuisaCompute feature.

As an alternative, in LuisaCompute (but not LuisaRender), we currently support procedural primitives, which are generic AABBs with user-defined intersection/any-hit functions. Examples can be found in test_procedural (featuring custom sphere primitives) and test_path_tracing_cutout (featuring user-controlled intersection behavior). I guess this feature should be sufficient for implementing an efficient particle system.

The current LuisaRender design is somewhat coupled with triangle meshes and hasn't incorporated other primitives into its scene geometry representation. To extend the geometry, the main files to change include

This would be a very meaningful extension for the renderer and I'm willing to implement it soon. I might do the refactoring in the following week.