Class Shader
Namespace: ValveResourceFormat.Renderer.Shaders
Assembly: Renderer.dll
OpenGL shader program with uniform management and material defaults.
public class ShaderInheritance
Constructors
Shader(string, RendererContext)
Initializes a new instance of the class.
public Shader(string name, RendererContext rendererContext)Parameters
name string
The shader name, typically a Source 2 .vfx shader name.
rendererContext RendererContext
The renderer context used to access the material loader.
Fields
AlphaTestCombo
The static combo that turns on alpha testing.
public const string AlphaTestCombo = "F_ALPHA_TEST"Field Value
DepthModeCombo
The static combo that selects a material shader's depth only mode.
public const string DepthModeCombo = "S_MODE_DEPTH"Field Value
OverdrawModeCombo
The static combo that selects the quad overdraw counting mode.
public const string OverdrawModeCombo = "S_MODE_OVERDRAW"Field Value
Properties
Default
Gets the default whose values serve as fallbacks when a material omits a uniform.
public RenderMaterial Default { get; init; }Property Value
Defines
Gets every static combo the source declares, unlike . Shared by every variant.
public required IReadOnlyDictionary<string, byte> Defines { get; init; }Property Value
IReadOnlyDictionary<string, byte>
DepthMode
Gets this shader's depth only mode, or null when it has none.
public Shader? DepthMode { get; }Property Value
GlobalsLayout
Gets the packed layout of this shader's loose global uniforms, derived from the source and shared by every variant.
public GlobalsLayout GlobalsLayout { get; }Property Value
IgnoreMaterialData
Gets a value indicating whether material data (textures and params) should be skipped during rendering.
public bool IgnoreMaterialData { get; }Property Value
IntegerAttributes
Gets those locations declared as an integer type, which need an integer format.
public int IntegerAttributes { get; }Property Value
IsAlphaTestVariant
Gets whether this variant alpha tests, which makes it read the material's color texture.
public bool IsAlphaTestVariant { get; }Property Value
IsLoaded
Gets a value indicating whether the shader link status has been checked.
public bool IsLoaded { get; }Property Value
IsValid
Gets a value indicating whether the shader linked successfully and is ready for use.
public bool IsValid { get; }Property Value
Name
Gets the shader name (typically a Source 2 .vfx shader name).
public string Name { get; }Property Value
NameHash
Gets the hash of .
public uint NameHash { get; }Property Value
OverdrawMode
Gets this shader's quad overdraw counting mode, or null when it has none.
public Shader? OverdrawMode { get; }Property Value
Parameters
Gets the static combo parameter values used to compile this shader variant.
public required IReadOnlyDictionary<string, byte> Parameters { get; init; }Property Value
IReadOnlyDictionary<string, byte>
Program
Gets or sets the OpenGL program object handle.
public int Program { get; set; }Property Value
ReadsSceneColor
Gets whether the program samples g_tSceneColor.
public bool ReadsSceneColor { get; }Property Value
RenderModes
Gets the set of render mode names supported by this shader.
public required HashSet<string> RenderModes { get; init; }Property Value
RequiredAttributes
Gets the locations this program reads, as a mask. Checked in .
public int RequiredAttributes { get; }Property Value
ReservedTexturesUsed
Gets the reserved texture uniforms this shader samples, seeded from the source and trimmed by .
public HashSet<string> ReservedTexturesUsed { get; init; }Property Value
SamplerUserConfigUniforms
Gets the set of sampler uniform names that use material address modes via // Sampler(UserConfig).
public required HashSet<string> SamplerUserConfigUniforms { get; init; }Property Value
ShaderObjects
Gets the compiled OpenGL shader stage object handles.
public required int[] ShaderObjects { get; init; }Property Value
int[]
SrgbUniforms
Gets the set of uniform names that require sRGB-to-linear conversion when setting material values.
public required HashSet<string> SrgbUniforms { get; init; }Property Value
UniformNames
Gets the set of uniform names declared in the shader source.
public required HashSet<string> UniformNames { get; init; }Property Value
Methods
DeclaresCombo(string)
Gets whether the shader source declares combo as a static combo.
public bool DeclaresCombo(string combo)Parameters
combo string
Returns
Delete()
Deletes the program, its default globals buffer, and any stage objects still attached.
public void Delete()DescribeAttributes(int)
Names the attributes this program declares at the given locations.
public string DescribeAttributes(int locationMask)Parameters
locationMask int
Returns
EnsureLoaded()
Ensures the shader program has been linked and its uniforms have been cached.
public bool EnsureLoaded()Returns
true if the shader linked successfully; otherwise false.
GetAllUniformNames()
Enumerates all active non-block uniforms in the program (uniforms belonging to uniform blocks are skipped), populating the internal uniform location cache.
public IEnumerable<(string Name, int Index, ActiveUniformType Type, int Size)> GetAllUniformNames()Returns
IEnumerable<(string Name, int Index, ActiveUniformType Type, int Size)>
A sequence of tuples with each uniform's name, index, type, and array size.
GetRegisterSize(string)
Returns the number of scalar components in the named uniform (1 for scalars, 2-4 for vectors).
public int GetRegisterSize(string name)Parameters
name string
The uniform variable name.
Returns
The component count, defaulting to 4 if the uniform is not found in the cache.
GetUniformLocation(string)
Returns the OpenGL location of the named uniform, querying the driver and caching the result on first access.
public int GetUniformLocation(string name)Parameters
name string
The uniform variable name.
Returns
The uniform location, or -1 if the uniform does not exist in the program.
IsBooleanParameter(string)
Returns a value indicating whether the named uniform has a boolean type.
public bool IsBooleanParameter(string paramName)Parameters
paramName string
The uniform variable name.
Returns
SetBoneAnimationData(bool, int, int)
Sets the uAnimationData uniform used by skinned mesh shaders.
public void SetBoneAnimationData(bool animated, int boneOffset = 0, int boneCount = 0)Parameters
animated bool
Whether skeletal animation is active.
boneOffset int
Offset into the bone transform buffer.
boneCount int
Number of bones influencing this draw call.
SetTexture(int, string, RenderTexture?)
Binds a texture to the given texture unit and sets the named sampler uniform, returning false if the texture or uniform is absent.
public bool SetTexture(int slot, string name, RenderTexture? texture)Parameters
slot int
The texture unit index.
name string
The sampler uniform name.
texture RenderTexture?
The texture to bind.
Returns
true if the texture was successfully bound; otherwise false.
SetTexture(int, int, RenderTexture?)
Binds a texture to the given texture unit and sets the sampler uniform by location.
public void SetTexture(int slot, int uniformLocation, RenderTexture? texture)Parameters
slot int
The texture unit index.
uniformLocation int
The pre-resolved sampler uniform location.
texture RenderTexture?
The texture to bind.
SetUniform(string, float)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, float value)Parameters
name string
value float
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, int)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, int value)Parameters
name string
value int
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, uint)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, uint value)Parameters
name string
value uint
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, bool)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, bool value)Parameters
name string
value bool
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, Vector2)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, Vector2 value)Parameters
name string
value Vector2
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, Vector3)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, Vector3 value)Parameters
name string
value Vector3
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, Vector4)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, Vector4 value)Parameters
name string
value Vector4
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform(string, Matrix4x4)
Sets a packed global uniform in this shader's own constant buffer.
public void SetUniform(string name, Matrix4x4 value)Parameters
name string
value Matrix4x4
Remarks
For shaders drawn without a material. When a material is bound its own constant buffer is what the draw reads, so set the value through instead.
SetUniform1(string, float)
Sets a scalar float uniform on this program.
public void SetUniform1(string name, float value)Parameters
name string
value float
SetUniform1(string, int)
Sets a scalar integer uniform on this program.
public void SetUniform1(string name, int value)Parameters
name string
value int
SetUniform1(string, bool)
Sets a scalar boolean uniform on this program, encoded as 1u or 0u.
public void SetUniform1(string name, bool value)Parameters
name string
value bool
SetUniform1(string, uint)
Sets a scalar unsigned integer uniform on this program.
public void SetUniform1(string name, uint value)Parameters
name string
value uint
SetUniform1AllVariants(string, uint)
Sets a uniform on this shader and on every variant taken from it, which are separate programs and so hold their own copy. Variants can be taken of variants, so the walk recurses.
public void SetUniform1AllVariants(string name, uint value)Parameters
name string
value uint
SetUniform2(string, Vector2)
Sets a two-component float vector uniform on this program.
public void SetUniform2(string name, Vector2 value)Parameters
name string
value Vector2
SetUniform3(string, Vector3)
Sets a three-component float vector uniform on this program.
public void SetUniform3(string name, Vector3 value)Parameters
name string
value Vector3
SetUniform3x4(string, Matrix4x4)
Sets a 3×4 matrix uniform (converted from a by transposing and dropping the last (M14/M24/M34/M44) column).
public void SetUniform3x4(string name, Matrix4x4 value)Parameters
name string
value Matrix4x4
SetUniform4(string, Vector4)
Sets a four-component float vector uniform on this program.
public void SetUniform4(string name, Vector4 value)Parameters
name string
value Vector4
SetUniform4Array(string, int, float[])
Sets an array of four-component float vector uniforms on this program.
public void SetUniform4Array(string name, int count, float[] value)Parameters
name string
The uniform array name.
count int
Number of vec4 elements to upload.
value float[]
Flat array of float values (count * 4 elements).
SetUniform4x4(string, Matrix4x4, bool)
Sets a 4×4 matrix uniform on this program.
public void SetUniform4x4(string name, Matrix4x4 value, bool transpose = false)Parameters
name string
The uniform variable name.
value Matrix4x4
The matrix value.
transpose bool
Whether to transpose the matrix before uploading.
Use()
Installs this program and the constant buffer holding its own global uniforms.
public void Use()WithAlphaTest(bool)
Gets this shader's alpha test variant when it has one and the material alpha tests, and this shader otherwise.
public Shader WithAlphaTest(bool alphaTest)Parameters
alphaTest bool
Returns
WithCombo(string, byte)
Gets this shader with one combo set differently, cached. Chain the calls to move more than one.
public Shader WithCombo(string combo, byte value)Parameters
combo string
value byte
Returns
WithSkinning(MeshSkinning)
Gets this shader built for what a mesh supplies, for passes that replace material shaders.
public Shader WithSkinning(MeshSkinning skinning)Parameters
skinning MeshSkinning

