Class ShaderProperties
- Namespace
- Gamelogic.Fx.PostProcessing
- Assembly
- Gamelogic.Fx.dll
Defines a serializable set of properties used to configure a specific post-processing shader.
[Serializable]
public abstract class ShaderProperties
- Inheritance
-
ShaderProperties
- Derived
- Inherited Members
Remarks
A ShaderProperties instance acts as the bridge between inspector-exposed settings and the underlying shader uniforms.
When enabled, this class attempts to load the shader specified by ShaderName and stores a reference to it so the shader is included correctly in builds.
Subclasses typically:
- Provide the shader name via ShaderName.
- Expose serialized fields that represent shader parameters.
- Override SetMaterialProperties(Material) to apply those parameters.
- Override CheckMaterialVersion() if any property change requires material recreation.
Properties
MaterialVersion
A generation counter that increments whenever the owning material must be destroyed and recreated.
public int MaterialVersion { get; }
Property Value
Remarks
Consumers (such as Gamelogic.Fx.BuiltIn.PostProcessing.PostProcess<TShaderProperties> and the Dither Designer preview renderer) each maintain their own "last seen" copy of this value. When their copy differs from MaterialVersion, they destroy their cached material and create a new one before the next render.
Do not increment this directly; call IncMaterialVersion() instead.
See the block comment on the ShaderProperties source file for a full description of
the material version system.
Requirements
Names of optional external packages this property set's shader depends on for one of its
shader_feature keywords (for example "Mixbox").
public virtual IEnumerable<string> Requirements { get; }
Property Value
Remarks
Used by the editor-time shader variant collector (see
EffectShaderVariantCollectionUtils) to know which package-presence keywords
(such as GAMELOGIC_HAS_MIXBOX) to record for this shader, alongside the keywords
from GetActiveShaderFeatureKeywords(). Unlike RequiresDepthTexture
and RequiresNormalsTexture - a small, fixed set read by one runtime
consumer - this covers an open-ended, growing set of optional third-party dependencies,
so new ones are added by overriding this in the relevant subclass rather than by widening
this base class further.
Empty by default. Override to return the relevant requirement name(s) if this shader
declares a shader_feature keyword gated on a package that might not be installed.
RequiresDepthTexture
Indicates whether this shader requires access to the camera depth texture.
public virtual bool RequiresDepthTexture { get; }
Property Value
Remarks
Override and return true if the shader samples depth information.
This is used by higher-level systems to enable the correct camera flags.
RequiresNormalsTexture
Indicates whether this shader requires access to the camera normals texture.
public virtual bool RequiresNormalsTexture { get; }
Property Value
Remarks
Override and return true if the shader samples scene normals.
This is used by higher-level systems to ensure normals are generated when needed.
Shader
Gets the resolved shader instance.
public Shader Shader { get; }
Property Value
ShaderName
Gets the name of the shader used by this property set.
public abstract string ShaderName { get; }
Property Value
Remarks
This name is passed to the internal shader lookup system when the properties are enabled. It should match the full shader path as defined in the shader file.
Methods
CheckMaterialVersion()
Checks whether any condition requires the owning material to be recreated, and calls IncMaterialVersion() if so.
public virtual void CheckMaterialVersion()
Remarks
The owning post-process calls this method at the top of each render, before fetching the effect material. This guarantees that staleness detection and material recreation happen in the same frame, with no visible lag.
Override this in subclasses whose properties can change size independently of normal inspector validation — for example, float arrays, texture arrays, or compute buffers whose element count is driven by user-editable data. Compare the current state against a stored "last seen" snapshot and call IncMaterialVersion() on a mismatch.
See Gamelogic.Fx.Dithering.PostProcessing.Effects.DitherMatrixBiasProperties
for a worked example: it tracks each channel matrix's FloatMatrix.SizeVersion and
increments the material version whenever any matrix is resized.
GetActiveShaderFeatureKeywords()
Gets the shader_feature keywords that are currently active (enabled) on this
property set, given its current serialized values.
public IEnumerable<string> GetActiveShaderFeatureKeywords()
Returns
Remarks
Used by the editor-time shader variant collector (see
EffectShaderVariantCollectionUtils) to work out which keyword combinations
are actually configured across the project, since materials for these effects are
created at runtime and never exist as serialized assets that Unity's normal
shader-feature usage stripping can see.
Discovered by reflection over fields whose type implements IShaderFeatureKeyword (such as BoolKeyword and EnumKeyword<TEnum>) - subclasses don't need to override this. Compiled out of Player builds; always empty outside the editor.
Pipeline keywords (GAMELOGIC_HAS_URP, GAMELOGIC_HAS_URP_RENDER_GRAPH) are not
listed here - they apply to every shader unconditionally and are supplied separately by
PipelineDefiner.GetActivePipelineKeywords.
IncMaterialVersion()
Increments MaterialVersion, signalling all consumers that their cached material is stale and must be recreated before the next render.
public void IncMaterialVersion()
Remarks
Call this from CheckMaterialVersion() when a staleness condition is detected. Do not call it from SetMaterialProperties(Material) — by the time that method runs, the material has already been fetched, so incrementing there would defer recreation to the next frame.
OnEnable()
Called when the owning component or asset is enabled.
public virtual void OnEnable()
Remarks
The default implementation resolves the shader using ShaderName.
Subclasses overriding this method should normally call base.OnEnable().
OnValidate()
Called when serialized values are changed in the inspector.
public virtual void OnValidate()
Remarks
Override this method to clamp values, enforce invariants, or perform lightweight validation in response to inspector edits.
SetMaterialProperties(Material)
Applies all shader-related properties to the given material.
public virtual void SetMaterialProperties(Material material)
Parameters
materialMaterialThe material created for the post process effect, using the shader defined by ShaderName.
Remarks
Subclasses should override this method and set all relevant shader uniforms (for example, floats, vectors, colors, textures, and keywords).
Do not call IncMaterialVersion() here. By the time this method is called the material has already been fetched, so any increment would take effect one frame late. Staleness checks belong in CheckMaterialVersion().