Skip to Content
DocumentationScripting APIGenesis Material API

GenesisMaterial

Namespace: Genesis.Runtime · Assembly: Genesis.Runtime.dll · Inherits: System.Object · Implements IDisposable

GenesisMaterial is the C# wrapper around any Material that uses a Genesis shader. It exposes typed accessors for every shader property, keyword-aware feature toggles, and an internal MaterialPropertyBlock path that preserves SRP Batcher compatibility when you drive properties per-renderer.

using Genesis.Runtime; // Wrap a renderer so writes route through a MaterialPropertyBlock var gm = new GenesisMaterial(GetComponent<Renderer>()); gm.EnableFeature(GenesisFeature.Dissolve); gm.SetFloat("_DissolveAmount", 0.5f); gm.Apply();

Construct from a Renderer whenever possible. Writes are buffered into a MaterialPropertyBlock, so the shared material is never instanced and the SRP Batcher keeps batching the renderer with its peers.

Constructors

GenesisMaterial(Material)
method
public GenesisMaterial(Material material)

Wraps an existing material asset. Property writes are applied directly to the material, which affects every renderer that shares it.

Parameters

NameTypeDescription
materialMaterialA material using any Genesis shader. Throws ArgumentException if the shader is not recognised.
GenesisMaterial(Renderer, int)
method
public GenesisMaterial(Renderer renderer, int submeshIndex = 0)

Wraps a renderer. All writes go through a pooled MaterialPropertyBlock and are committed on Apply(), leaving the shared material untouched.

Parameters

NameTypeDescription
rendererRendererThe renderer to drive. Its sharedMaterial must use a Genesis shader.
submeshIndexintMaterial slot to target on multi-material renderers. Defaults to 0.

Properties

Material
property
public Material Material { get; }

The wrapped material asset. Read-only.

Returns Material

Renderer
property
public Renderer Renderer { get; }

The bound renderer, or null when wrapping a raw material. When set, all property writes are buffered into a MaterialPropertyBlock.

Returns Renderer

RenderingMode
property
public GenesisRenderingMode RenderingMode { get; set; }

The active rendering model — Lit, Unlit, or Toon. Setting it swaps the underlying shader keyword and reconfigures the inspector. See Render Modes Explained.

Returns GenesisRenderingMode

Methods

SetFloat(string, float)
method
public void SetFloat(string name, float value)

Sets a float shader property. When a renderer is bound, the write is buffered until Apply(). Prefer this over Material.SetFloat so batching is preserved.

Parameters

NameTypeDescription
namestringShader property ID, e.g. "_DissolveAmount". Underscore-prefixed PascalCase.
valuefloatThe value to assign.
SetColor(string, Color)
method
public void SetColor(string name, Color value)

Sets a color property. HDR colors are accepted for emission and glow properties.

Parameters

NameTypeDescription
namestringShader property ID, e.g. "_EmissionColor".
valueColorLinear-space color. Use Color with intensity > 1 for HDR.
EnableFeature(GenesisFeature)
method
public void EnableFeature(GenesisFeature feature)

Turns a feature on by enabling its shader keyword and flipping the matching inspector toggle. No-op if already enabled.

Parameters

NameTypeDescription
featureGenesisFeatureThe feature flag, e.g. GenesisFeature.Dissolve or GenesisFeature.RimLighting.
DisableFeature(GenesisFeature)
method
public void DisableFeature(GenesisFeature feature)

Turns a feature off and clears its keyword, stripping the associated shader variant from this material.

Parameters

NameTypeDescription
featureGenesisFeatureThe feature to disable.
IsFeatureEnabled(GenesisFeature)
method
public bool IsFeatureEnabled(GenesisFeature feature)

Returns whether the given feature’s keyword is currently enabled on the material.

Parameters

NameTypeDescription
featureGenesisFeatureThe feature to query.

Returns bool

Apply
method
public void Apply()

Flushes pending MaterialPropertyBlock writes to the bound renderer. No-op when wrapping a raw material. Call once per frame after a batch of setters, not after every write.

Dispose
method
public void Dispose()

Releases the internal MaterialPropertyBlock back to the pool. Call from the owning component’s OnDestroy. Safe to omit for short-lived editor tooling.

Sub-APIs

GenesisMaterial exposes grouped helpers that wrap related properties with discoverable, typed methods:

PropertyTypeCovers
LightingGenesisLightingCel, rim, specular, MatCap, Gooch.
StylizationGenesisStylizationHue shift, posterize, color adjustments.
EffectsGenesisEffectsDissolve, hologram, hit flash, intersection glow.
AnimationGenesisAnimationVertex and UV animation.
MapsGenesisMapsAlbedo, normal, detail, layer textures and UV.

Examples

Color-flash a hit on a per-instance material

using Genesis.Runtime; using UnityEngine; public class HitFlash : MonoBehaviour { [SerializeField] Renderer target; GenesisMaterial gm; void Awake() => gm = new GenesisMaterial(target); void OnDestroy() => gm.Dispose(); public void Flash(Color tint, float seconds = 0.15f) => gm.Effects.PlayHitFlash(tint, seconds); }

Fade dissolve over one second

public IEnumerator DissolveOut(GenesisMaterial gm, float duration = 1f) { gm.EnableFeature(GenesisFeature.Dissolve); for (float t = 0f; t < duration; t += Time.deltaTime) { gm.SetFloat("_DissolveAmount", Mathf.Clamp01(t / duration)); gm.Apply(); yield return null; } gm.SetFloat("_DissolveAmount", 1f); gm.Apply(); }

Reading renderer.material anywhere instantiates the material and breaks batching for that renderer. GenesisMaterial avoids this — but watch other scripts on the same GameObject that may touch .material.

See also

Last updated on