Raymarcher Technical & APi Documentation
RMObjectModifierBase
Namespace: Raymarcher.Objects.Modifiers
The RMObjectModifierBase class serves as a foundational class for scripts defining 'modifiers' for SDF objects within the Raymarcher renderer.
RMObjectModifierBase contains an interface implementation of ISDFEntity, establishing common parameters for all SDF entities, including modifiers.

For a visual representation of the data structure of Raymarcher objects and modifiers, refer to the image below:



Inherit from this class to define your custom SDF object modifier in the Raymarcher renderer.

After adding a modifier to a gameObject with any SDF object script in Unity, the Raymarcher will automatically integrate the modifier with the target SDF object. The converter will prompt for Raymarcher's recompilation.

It is crucial to accurately define the base modifier's properties that the RMObjectModifierBase class requires to be overridden.
Additionally, note that the order of modifiers in the inspector plays a significant role in the Raymarcher.
Some modifiers may exhibit different behavior if they are affected by 'more-prioritized' modifiers that are compiled first.

List of abstract methods and properties essential for proper modifier definition:
// Invoked when the SdfObjectBuffer is recompiled (optional)
public virtual void SdfBufferRecompiled()

// Specify a method name for this modifier. This method will be called and represent this modifier formula
public abstract string SdfMethodName { get; }

// Specify an array of uniform fields for this modifier. These variables will be used and modified at runtime in the formula
public abstract ISDFEntity.SDFUniformField[] SdfUniformFields { get; }

// Specify a method body for this modifier. This defines the actual behavior of the modifier formula
public abstract string SdfMethodBody { get; }

// Specify an optional method extension for this modifier. Use this to inline all helper and utility methods at the top of the declaration list (optional)
public virtual string SdfMethodExtension { get; }

// Set Float/Vector/Color/Texture values in the raymarcher session material with the given iterationIndex
public abstract void PushSdfEntityToShader(in Material raymarcherSessionMaterial, in string iterationIndex);

// Select the appropriate inline mode for this modifier. Inform the compiler whether the SDF modifier should be inlined to the SDF position, placed below the SDF declaration, or positioned after the object buffer declaration
public virtual InlineMode ModifierInlineMode() => InlineMode.PostSdfInstance;

// If the modifier supports shared containers, create a boxed reference directive to the target shared container type
public virtual object CreateSharedModifierContainer { get; } = null;

// Define whether this modifier supports shared modifier containers
public virtual bool ModifierSupportsSharedContainer { get; } = false;

// Pass modifier data to the shared container object
public virtual void PassModifierDataToSharedContainer()

// Pass shared container object's data to the modifier
public virtual void PassSharedContainerDataToModifier()
List of public fields and properties shared among all Raymarcher modifiers:
// Built-in Raymarcher's compiler define macros that the developer can use to define custom sdf modifier
protected const string VARCONST_POSITION = "p"; // read/write 'p' - currently marched position
protected const string VARCONST_SDF = "sdf"; // read/write 'sdf' - result of the sdf formula to modify
protected const string VARCONST_MATERIAL_INSTANCE = "materialInstance"; // read/write 'materialInstance' - currently calculated object's material instance index (Doesn't apply for Performant render type)
protected const string VARCONST_MATERIAL_TYPE = "materialType"; // read/write 'materialType' - currently calculated object's material type index (Doesn't apply for Performant render type)
protected const string VARCONST_COLOR = "color"; // read/write 'color' - currently calculated object's color (full rgb when Quality render type, hue only when Standard & Performant)

// Target sdf object of this modifier
public RMSdfObjectBase SdfTarget { get; }
// Shared modifier container (if any)
public RMObjectModifierSharedContainer SharedModifierContainer { get; }