Raymarcher Technical & APi Documentation
RMSdfObjectBase
Namespace: Raymarcher.Objects
The RMSdfObjectBase class serves as a foundational class for scripts defining 'objects' within the Raymarcher renderer.
These objects are specific types of Signed Distance Functions (SDFs) that leverage mathematical formulas to approximate the shape of the desired SDF object.
RMSdfObjectBase contains an interface implementation of ISDFEntity, defining 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 within the Raymarcher renderer.

Once you create a gameObject in Unity with a mono class inheriting from RMSdfObjectBase, the Raymarcher will automatically integrate the object into the Object Buffer.
If the Object Buffer detects changes, the converter will prompt for Raymarcher's recompilation.
It is required to accurately define the properties that the RMSdfObjectBase class expects to be overridden.

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

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

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

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

// Specify an optional method extension for this SDF. 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 iteration index
public abstract void PushSdfEntityToShader(in Material raymarcherSessionMaterial, in string iterationIndex);
Each Raymarcher SDF object shares common values, although some of these values are active and visible only in specific Raymarcher Render Types.
For example, when the render type is set to Performant, the object's material won't be utilized, as the Performant render type supports global materials only.

List of public fields and properties shared among all Raymarcher SDF objects:
// Built-in Raymarcher's compiler define macros that the developer can use to define custom sdf
protected const string VARCONST_RESULT = "result"; // read/write 'result' - result of the sdf formula
protected const string VARCONST_POSITION = "p"; // readonly 'p'
protected const string VARCONST_COLOR = "color"; // read/write 'color'

// Does the object have some sdf modifiers?
public bool HasModifiers { get; }
// Currently cached sdf object modifiers
public IReadOnlyList<RMObjectModifierBase> Modifiers { get; }
// Reference shortcut to the current render master
public RMRenderMaster RenderMaster { get; }
// Reference shortcut to the current object buffer
public RMCoreRenderMasterMapping MappingMaster { get; }

// Current material instance on the object
public RMMaterialBase ObjectMaterial { get; }

// Current hue shift on the object (not active when the render type is set to Quality)
public float HueShift { get; set; }

// Current quality render data on the object
public SdfQualityRenderData QualityRenderData { get; }
// Quality render data is used if the Render Type is set to Quality only!
// QualityRenderData content:
public Color objectColor;
public Texture2D objectTexture; // Object texture can be set at compile time only (if not cached in the Raymarcher resources)
public float textureTiling;
public float textureScaleX;
public float textureScaleY;
public float textureScaleZ;
public float textureOpacity;
//----------------------------------------