Class RenderMaterial
Namespace: ValveResourceFormat.Renderer.Materials
Assembly: Renderer.dll
Material with shader, textures, and render state for GPU rendering.
public class RenderMaterialInheritance
Constructors
RenderMaterial(Material, RendererContext, Dictionary<string, byte>?)
Initializes a new instance of the class from a parsed material resource, loading its shader and applying render state.
[SetsRequiredMembers]
public RenderMaterial(Material material, RendererContext rendererContext, Dictionary<string, byte>? shaderArguments)Parameters
material Material
The parsed Source 2 material data.
rendererContext RendererContext
The renderer context used to load shaders and textures.
shaderArguments Dictionary<string, byte>?
Optional caller-supplied static combo values used as a base; the material's own shader arguments are merged in afterward and take precedence on conflicting keys.
RenderMaterial(Shader)
Initializes a new instance of the class wrapping an existing shader with an empty material.
[SetsRequiredMembers]
public RenderMaterial(Shader shader)Parameters
shader Shader
The shader to use for rendering.
Fields
PerShaderSortIdRange
The sort ID range allocated per unique shader program, used to group draw calls by shader while preserving random ordering within a group.
public const int PerShaderSortIdRange = 10000Field Value
TextureUnitStart
First non-reserved texture unit. Material (per-draw) textures bind here and above so the globally bound textures stay intact.
public const int TextureUnitStart = 19Field Value
Properties
CanPrimeDepth
Gets whether this material can perform early depth priming and then shade with Equal comparison.
public bool CanPrimeDepth { get; }Property Value
DoNotCastShadows
Gets a value indicating whether geometry using this material should be excluded from shadow passes.
public bool DoNotCastShadows { get; }Property Value
FloatParams
Gets the float parameters, seeded from and writable per instance.
public MaterialInputs<float> FloatParams { get; }Property Value
IntParams
Gets the integer parameters, seeded from and writable per instance.
public MaterialInputs<long> IntParams { get; }Property Value
IsAlphaTest
Gets a value indicating whether this material uses alpha-to-coverage alpha testing.
public bool IsAlphaTest { get; }Property Value
IsCs2Water
Gets a value indicating whether this material uses the CS2 water rendering path.
public bool IsCs2Water { get; }Property Value
IsOverlay
Gets or sets a value indicating whether this material is rendered as a screen-space or world-space overlay (polygon-offset, no depth write).
public bool IsOverlay { get; set; }Property Value
IsToolsMaterial
Gets a value indicating whether this is a tools-only material that should not appear in normal rendering.
public bool IsToolsMaterial { get; }Property Value
IsTranslucent
Gets a value indicating whether this material uses any blending mode that requires back-to-front ordering.
public bool IsTranslucent { get; }Property Value
Material
Gets the underlying parsed data, as read from the file.
public Material Material { get; }Property Value
Matrices
Gets the map of matrix uniform names to their current values for this material.
public MaterialInputs<Matrix4x4> Matrices { get; }Property Value
ReadsSceneColor
Gets a value indicating whether this material's shader samples the scene color texture, and therefore has to be drawn after the framebuffer grab in or . Queried live rather than cached: shaders are compiled without blocking, so this only becomes true once the program has been linked and reflected, which is one frame after the material is first collected.
public bool ReadsSceneColor { get; }Property Value
Shader
Gets the used to render this material.
public required Shader Shader { get; init; }Property Value
ShaderName
Gets the shader name of the material, normalized to the .vfx extension the renderer resolves shaders by.
public string ShaderName { get; }Property Value
SortId
Gets a value used to bucket this material into draw-call sort bins; derived from the shader program handle and a random offset.
public int SortId { get; }Property Value
Textures
Gets the map of texture uniform names to the bound objects for this material.
public MaterialInputs<RenderTexture> Textures { get; }Property Value
VectorParams
Gets the vector parameters, seeded from and writable per instance.
public MaterialInputs<Vector4> VectorParams { get; }Property Value
VertexAnimation
Gets a value indicating whether this material drives vertex animation (foliage or morph-based).
public bool VertexAnimation { get; }Property Value
Methods
ComposeRenderState(in RenderState)
Composes this material's render state over the given pass baseline.
public RenderState ComposeRenderState(in RenderState passState)Parameters
passState RenderState
The baseline state of the enclosing pass.
Returns
The state this material draws with.
Delete()
Releases the GPU resources this material owns. Safe to call more than once.
public void Delete()LoadRenderState()
Load or reload render state from material data.
public void LoadRenderState()PostRender()
Unbinds the samplers that were bound for this material's draw call.
public void PostRender()Render(Shader?, bool)
Binds textures, sets material uniforms, and applies blend/depth render state for this material.
public void Render(Shader? shader = null, bool depthPass = false)Parameters
shader Shader?
The shader to use for this draw call, or null to use .
depthPass bool
Whether the draw only lays down depth, which a shared depth shader still rasterizes this material's way.
SetUniform(string, float)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, float value)Parameters
name string
value float
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.
SetUniform(string, long)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, long value)Parameters
name string
value long
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.
SetUniform(string, bool)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, bool value)Parameters
name string
value bool
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.
SetUniform(string, Vector4)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, Vector4 value)Parameters
name string
value Vector4
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.
SetUniform(string, Vector3)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, Vector3 value)Parameters
name string
value Vector3
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.
SetUniform(string, Vector2)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, Vector2 value)Parameters
name string
value Vector2
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.
SetUniform(string, Matrix4x4)
Sets a packed global uniform in this material's constant buffer.
public void SetUniform(string name, Matrix4x4 value)Parameters
name string
value Matrix4x4
Remarks
The value survives until the buffer is refilled, which only happens when one of the inputs it is built from changes, or a shader reload replaces the layout.

