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.
Properties
Attributes
Gets a mapping from vertex attribute names to their OpenGL attribute locations.
public Dictionary<string, int> Attributes { get; }Property Value
Default
Gets the default whose values serve as fallbacks when a material omits a uniform.
public RenderMaterial Default { get; init; }Property Value
IgnoreMaterialData
Gets a value indicating whether material data (textures and params) should be skipped during rendering.
public bool IgnoreMaterialData { 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
MaterialLoader
Gets the used to resolve fallback textures.
protected MaterialLoader MaterialLoader { get; init; }Property Value
Name
Gets the shader name (typically a Source 2 .vfx shader name).
public string Name { get; }Property Value
NameHash
Gets the MurmurHash2 hash of .
public uint NameHash { 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
RenderModes
Gets the set of render mode names supported by this shader.
public required HashSet<string> RenderModes { get; init; }Property Value
ReservedTexturesUsed
Gets the set of reserved texture uniform names that are actively used by this shader.
public HashSet<string> ReservedTexturesUsed { get; }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
EnsureLoaded()
Ensures the shader program has been linked and its uniforms and attributes have been cached.
public bool EnsureLoaded()Returns
true if the shader linked successfully; otherwise false.
GetAllUniformNames()
Enumerates all active uniforms in the program, 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.
GetUniformBlockIndex(string)
Returns the OpenGL index of the named uniform block, querying the driver and caching the result on first access.
public int GetUniformBlockIndex(string name)Parameters
name string
The uniform block name.
Returns
The uniform block index, or -1 if the block does not exist.
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, int)
Sets the uAnimationData uniform used by skinned mesh shaders.
public void SetBoneAnimationData(bool animated, int boneOffset = 0, int boneCount = 0, int weightCount = 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.
weightCount int
Number of bone weights per vertex.
SetMaterialVector4Uniform(string, Vector4)
Sets a vector material uniform, applying sRGB-to-linear conversion if needed and adapting to the actual uniform size.
public void SetMaterialVector4Uniform(string name, Vector4 value)Parameters
name string
value Vector4
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.
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
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 dropping the last 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.
SetUniformMatrix4x3Array(string, int, float[])
Sets an array of 4×3 column-major matrix uniforms on this program.
public void SetUniformMatrix4x3Array(string name, int count, float[] value)Parameters
name string
The uniform array name.
count int
Number of matrices to upload.
value float[]
Flat array of float values (count * 12 elements).
StoreAttributeLocations()
Queries and caches the OpenGL locations of all active vertex attributes.
public void StoreAttributeLocations()Use()
Installs this shader program as part of the current rendering state.
public void Use()
