Skip to content

Collection of Unity packages designed to enhance the visualization and manipulation of complex geometries through raymarching techniques

License

Notifications You must be signed in to change notification settings

danliukuri/RaymarchedBoundingVolumes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Raymarched Bounding Volumes

Raymarched Bounding Volumes is a collection of Unity packages designed to enhance the visualization and manipulation of complex geometries through raymarching techniques. This repository provides the following packages:

  • RBV: The core package that introduces the fundamental capabilities for raymarched bounding volumes, enabling efficient rendering and manipulation of 3D objects.
  • RBV.4D: An extension package that introduces four-dimensional features, allowing for dynamic exploration of 4D geometries in a familiar 3D space, with full compatibility with RBV Features.
  • RBV.Heatmapping: A specialized extension designed to visualize raymarched bounding volumes using heatmaps, providing intuitive exploration, debugging, and performance analysis by mapping raymarching iterations to color gradients.
By leveraging advanced rendering methods, these packages allow for the dynamic exploration of geometrical forms. The modular architecture ensures seamless integration, enabling users to customize workflows to meet specific needs while maintaining compatibility with existing Unity objects and shaders. Whether creating stunning visual effects or conducting intricate simulations, Raymarched Bounding Volumes equips developers with essential tools for achieving advanced graphical results.





RBV

RBV (short for Raymarched Bounding Volumes) is a core package for raymarching in Unity. It is designed for the effective visualization and manipulation of 3D objects and their combinations.

The name Raymarched Bounding Volumes comes from the idea of using bounding volumes to define the rendering space for raymarching, which has been proven to be more effective than rendering in the entire screen space (refer to RaymarchingRenderingSpacePerformanceTesting).

Features

  • Ready-to-Use Configurable 3D Objects
    A wide variety of 3D objects that can be easily customized to suit your needs.
  • Ready-to-Use Configurable Combining Operations
    Utilize various operations to combine 3D objects in creative ways, enabling complex scene creation with ease.
  • Operation Nesting Support
    Supports nesting of operations up to 10 levels deep (currently a hardcoded value, but could be easily made dynamic, wait for future updates).
  • Editor and Runtime Object Creation/Deletion Support
    Create and delete objects seamlessly during both the editing phase and at runtime.
  • High Reactivity
    All object and operation properties are observable, ensuring immediate feedback and interaction.
  • Render Settings for Each Object
    Customize render settings for each object, currently supporting color adjustments.
  • Advanced Shading Options
    Configurable shading per material, with support for four types of shadows, ambient occlusion, and Unity directional and ambient light.
  • Raymarching Configuration
    Fine-tune raymarching settings on a per-material basis, including iterations, accuracy, and far rendering plane.
  • GPU Instancing
    Leverage GPU instancing for the main RaymarchedVolume shader, improving performance.
  • Shared Shader Depth
    Utilizing the same pixel depth system as Unity, RBV ensures accurate depth calculations and allows for correct intersections and overlapping with standard Unity objects, enhancing the integration between raymarched and conventional elements in your scene.
  • Bounding Volumes
    Limit the rendering space of raymarching to improve performance by confining calculations to specific areas.
  • Raymarched Volume Mesh Configuration
    Change the mesh scale for object bounding volumes to suit various visualization needs.
  • Custom Inspectors
    Features custom property drawers, material property drawers, custom attributes, and editors for a tailored user experience.

Installation

You can install the RBV package using one of the following methods:

  • Unity Package Manager
    1. Open Unity, then go to Window -> Package Manager.
    2. Click on the drop-down and select Add package from git URL....
    3. Paste the following URL and click Add:
      https://github.com/danliukuri/RaymarchedBoundingVolumes.git?path=RaymarchedBoundingVolumes.Unity/Assets/Plugins/RBV
    To install samples, navigate to RBV/Samples in the Package Manager and click Import for the desired ones.
  • Download From Releases
    1. Go to the Releases Page.
    2. Download the desired package(s):
    3. Import the package(s) into your Unity project.

Usage

Scene Construction

To start using the RBV package, follow these steps to set up your scene:

  1. Open your Desired Scene
    Begin by opening the Unity scene where you want to use raymarching.
  2. Navigate to the Prefabs Folder
    Go to the package's prefabs folder located at RBV/Prefabs.
  3. Add the Raymarching Engine
    Drag and drop the RaymarchingEngine prefab into your scene hierarchy. This object contains two crucial components:
    • RaymarchingServicesRegister: Serves as the entry point for the package, handling the creation of services and their dependencies.
    • RaymarchingSceneUpdater: The main loop of the package lifecycle, ensuring proper shader data updates and managing the construction of the raymarching scene.
  4. Add Raymarched Objects and Operations
    Now that your scene is set up, you can start dragging and dropping RaymarchedObject and RaymarchingOperation prefabs into the scene, tailoring it to suit your specific needs.
  5. Configure the Visualization Space
    Last step is to configure the visualization space for the raymarching volume. For more details on how to do this, refer to the Volume Mesh Configuration section.

Volume Mesh Configuration

Since RBV utilizes the concept of bounding volumes, scaling the Transform adjusts the raymarching space scale. To address this, the mesh of the volume itself can be scaled. For simplifying this process, the RaymarchedVolumeMeshConfigurator has been designed, enabling straightforward adjustments to the mesh scale.

To utilize the RaymarchedVolumeMeshConfigurator, follow these steps:

  1. Drag and Drop the Configurator Prefab
    Drag and drop the RaymarchedVolumeMeshConfigurator prefab located at RBV/Prefabs into the desired scene.
  2. Parent Volume GameObjects
    Parent the desired volume-defining GameObjects to the RaymarchedVolumeMeshConfigurator. This can include not only RaymarchedObjects, as the volume is not limited to them; volume mesh renderers can exist as separate GameObjects.
  3. Set the Mesh via Context Menu
    In the context menu of the RaymarchedVolumeMeshConfigurator component, select one of the options to set the mesh for the children.
  4. Adjust the Mesh Size
    Change the size of the mesh by modifying the Size field in the RaymarchedVolumeMeshConfigurator component.
Optionally, you can change the original mesh itself to create a different shape for the raymarching volume. The PentakisDodecahedron is used as the default mesh due to its efficiency in defining an accurate sphere shape with minimal vertices and triangles. Additionally, the package includes the Icosahedron mesh. Moreover, the regular Unity cube mesh can also work well in many cases.

Tip

It’s worth mentioning that when configuring a volume for an object, you should account for its parts that become visible when combined with other objects.

Samples

To demonstrate the capabilities of RBV, the following samples have been created.

Showcase

This sample contains only one scene named Cover, where you can observe how numerous RaymarchedObject instances smoothly unite to create a cohesive composition.

Cover scene preview

RBV cover scene preview

Warning

This represents a rather unconventional usage of RBV and raymarching in general, as this scene has many RaymarchedObject instances concentrated in one area. Since they occupy the entire camera rendering screen space, we do not gain any performance benefits from utilizing bounding volumes. Given that raymarching is inherently slow, this scene may even lead to performance issues for all the aforementioned reasons.

Contribution

Feel free to submit issues or pull requests to improve RBV package.

Note

To simplify working with RBV/Samples, symbolic inks were utilized. If you're using Windows, refer to Symbolic Links in Windows for more information.






RBV.4D

RBV.4D is an extension package for RBV that introduce four-dimensional features. It enables the visualization and manipulation of 4D objects within raymarched volumes by slicing through these objects along a fourth spatial dimension and projecting them into 3D, while leveraging all the techniques provided by the core RBV package. This functionality allows for dynamic exploration of 4D geometry in a familiar 3D space.

Features

  • Support for All RBV Features
    RBV.4D fully supports all Features of the core RBV package. By utilizing the same shader, 4D objects can seamlessly coexist with 3D raymarched objects as well as standard Unity objects.
  • Ready-to-Use Configurable 4D Objects
    Provides pre-configured 4D objects that are easily customizable and ready for immediate use in your scene.
  • 4D Transformations
    Enables movement, rotation, and scaling of 4D objects along the fourth spatial dimension, while remain supporting such transformations in the standard three dimensions.

Installation

Note

As RBV.4D explicitly depends on RBV, ensure the base package is installed before proceeding. See RBV Installation for more details.
You can install the RBV.4D package using one of the following methods:

  • Unity Package Manager
    1. Open Unity, then go to Window -> Package Manager.
    2. Click on the drop-down and select Add package from git URL....
    3. Paste the following URL and click Add:
      https://github.com/danliukuri/RaymarchedBoundingVolumes.git?path=RaymarchedBoundingVolumes.Unity/Assets/Plugins/RBV.4D
    To install samples, navigate to RBV.4D/Samples in the Package Manager and click Import for the desired ones.

  • Download From Releases
    1. Go to the Releases Page.
    2. Download the desired package(s):
    3. Import the package into your Unity project.

Usage

Scene Construction

To start using the RBV.4D package, follow the same steps for Scene Construction as in the RBV package to set up your scene. The only differences are:

The aforementioned prefabs are located at the path RBV.4D/Prefabs.

Samples

To demonstrate the capabilities of RBV.4D, the following samples have been created.

Showcase

This sample contains only one scene named Cover, where you can observe how numerous RaymarchedObject4D instances smoothly unite to create a cohesive composition. In this scene, you can also observe how seamlessly 4D objects interact with regular raymarched ones.

RBV.4D Cover Scene Preview

RBV.4D cover scene preview

Warning

This represents a rather unconventional usage of RBV.4D and raymarching in general, as this scene has many RaymarchedObject4D instances concentrated in one area. Since they occupy the entire camera rendering screen space, we do not gain any performance benefits from utilizing bounding volumes. Given that raymarching is inherently slow, this scene may even lead to performance issues for all the aforementioned reasons.

Contribution

Feel free to submit issues or pull requests to improve RBV.4D package.

Note

To simplify working with RBV.4D/Samples, symbolic inks were utilized. If you're using Windows, refer to Symbolic Links in Windows for more information.






RBV.Heatmapping

RBV.Heatmapping is a specialized extension package for RBV designed to visualize raymarched bounding volumes using heatmaps by mapping raymarching iterations to color gradients, allowing for intuitive exploration, debugging, and analysis.

Features

  • Settings in Unity Preferences
    Configure heatmapping parameters on a per-user basis through the Unity Editor Preferences, allowing for seamless integration and flexibility.
  • Customizable Textures
    The package comes with three built-in heatmap textures, while also supporting customizable textures to tailor color gradients to specific visualization needs.

Installation

Note

As RBV.Heatmapping explicitly depends on RBV, ensure the base package is installed before proceeding. See RBV Installation for more details.
You can install the RBV.Heatmapping package using one of the following methods:

  • Unity Package Manager
    1. Open Unity, then go to Window -> Package Manager.
    2. Click on the drop-down and select Add package from git URL....
    3. Paste the following URL and click Add:
      https://github.com/danliukuri/RaymarchedBoundingVolumes.git?path=RaymarchedBoundingVolumes.Unity/Assets/Plugins/RBV.Heatmapping
  • Download From Releases
    1. Go to the Releases Page.
    2. Download the desired package: [email protected].
    3. Import the package into your Unity project.

Usage

Enabling Heatmapping in Preferences

To see the RBV.Heatmapping package in action, it must first be enabled in the settings for all materials that utilize the RaymarchedVolume shader.

  1. Open the Unity Editor Preferences and navigate to the Raymarched Bounding Volumes/Heatmapping settings.
  2. Enable the heatmapping feature using the Enabled toggle field.
The texture specified in the Texture field will be used for the heatmap visualization. By default, the HitmapMagma texture is specified.

Heatmapping settings in Unity Editor Preferences

RBV.Heatmapping settings in Unity Editor Preferences

Example

The colors in the heatmap texture represent the number of iterations used in raymarching, arranged from left to right. For instance, in a scene that contains numerous spheres, enabling heatmapping with the HitmapCustom texture selected and setting the maximum number of iterations for ray marching to 32 will result in the following appearance for the scene (for clarity, the background is set to the color corresponding to zero iterations):

Scene heatmap example

Scene heatmap example with texture, showcasing the corresponding color for each iteration

For more details, refer to the RaymarchingRenderingSpacePerformanceTesting

Contribution

Feel free to submit issues or pull requests to improve RBV.Heatmapping package.