Raymarcher Technical & APi Documentation
Raymarcher Materials
Namespace: Raymarcher.Materials
Raymarcher has its own material pipeline that works and handles data in a specific way.
Materials in Raymarcher inherit from ScriptableObject, allowing you to create as many material instances as you wish.
You can watch an official video documentation here.

The Raymarcher's material pipeline is divided into two major categories:

- Global materials (applied on all SDF objects globally and equally)

- Per-instance materials (applied on individual SDF objects independently)

Global materials can be set on the main RaymarcherRenderer component, which holds a special category in the Material Settings called Global Material Instances.
If this array contains material instances and you hit Register Global Materials, the given material instances will be processed by Raymarcher's material system and dispatched to the shader.
These material instances will be applied to all SDF objects equally.



Per-instance materials are dependent on specific SDF objects.
If your render type is set to Standard or Quality, you can assign a specific material instance to your SDF object.
Each SDF object has a field called Object Material that you can use to assign a material instance in the Unity editor at compile time.
Once the object has a new material instance, Raymarcher will warn you that recompilation is required. After recompilation, you will see that your object has the assigned material instance.



All material instances will pass their data to the shader. This is internally done through compute buffers.

If your target platform is mobile or WebGL, Raymarcher uses a special type of material types that 'unpack' their data into individual arrays without the use of compute buffers.
That's also the reason why materials for mobile/WebGL are simple and contain just a few properties.

Material Data Structure
Materials in Raymarcher have a specific data structure that allows the utilization of textures, shader features, and more.

Each material type consists of:

- Global features: checkboxes enabling/disabling certain features of the material type globally (regardless of the material instance)

- Global settings: a container of material parameters controlling global material settings globally (regardless of the material instance)

Global features & settings of the common material family



- Per-instance settings: fields and properties unique to each material instance.

Per-instance settings of a specific material instance (currently selected)



Global Features are shared based on a common material family type.
For example, if a material has the common family name 'standard,' its features will be shared among other material types with the same family type, such as Lit and PBR.
However, Noise material type, having a different family type, will have its own global features & settings.
It's important to note that enabling more features incurs a higher 'performance cost' to both the material and the renderer itself.

Global Settings are shared based on the common material family type, as well as the global features.
These settings provide more control than simply 'checking/unchecking' certain features.

Per-instance settings are unique to each material instance, with each instance occupying its own memory block.
More material instances result in increased memory usage.
For PC/console targeting, it's generally acceptable to have up to ~20 material instances, as these materials use special memory allocations for dynamic purposes.

Visual representation of the material data structure:



In this example, there are three unique materials.
The sphere and cube are using 'per-instance' materials (simple lit and PBR, respectively), while the capsule has none.
Additionally, there is a global material utilizing only the fresnel effect. This material is applied globally as it is registered in the 'global material instances.'
All three materials share the same family type, and thus, the global features and settings apply to all of them.