Class ShaderLoader
Namespace: ValveResourceFormat.Renderer.Shaders
Assembly: Renderer.dll
Compiles and caches OpenGL shader programs from source files.
public class ShaderLoader : IDisposableInheritance
object ← ShaderLoader
Implements
Constructors
ShaderLoader(RendererContext)
Initializes a new instance of the ShaderLoader class.
public ShaderLoader(RendererContext rendererContext)Parameters
rendererContext RendererContext
The renderer context that owns this loader.
Fields
ShaderFileExtension
The file extension used to identify vertex shader entry points (.vert.slang).
public const string ShaderFileExtension = ".vert.slang"Field Value
string
SlangExtension
The file extension for Slang shader source files (.slang).
public const string SlangExtension = ".slang"Field Value
string
VfxExtension
The file extension of Source 2 shader names (.vfx).
public const string VfxExtension = ".vfx"Field Value
string
Properties
DeclaredReservedTextures
Gets every reserved texture sampler declared by the loaded shaders. Read from the source, so it is known before linking. Unlike Shader.ReservedTexturesUsed, it keeps samplers behind dropped combos. Only grows, so a renderer can poll it for additions; see MaterialLoader.ShaderTextures.
public HashSet<string> DeclaredReservedTextures { get; }Property Value
HashSet<string>
ShaderCount
Gets the number of compiled shader variants currently held in the cache.
public int ShaderCount { get; }Property Value
int
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()Dispose(bool)
Releases managed resources held by this loader.
protected virtual void Dispose(bool disposing)Parameters
disposing bool
true when called from ShaderLoader.Dispose().
GetShaderFileByName(string)
Resolves a shader name to the renderer shader file that draws it. Mappings registered in ShaderRegistry take priority over the built-in ones.
public static string GetShaderFileByName(string shaderName)Parameters
shaderName string
A Source 2 shader name ending in .vfx, mapped to the closest renderer shader, or complex if unknown. Any other name is a renderer shader file to load directly, and must exist.
Returns
string
The renderer shader name without stage or extension (e.g. complex).
LinkLoadedShaders()
Collects the link status of every shader loaded so far, which loading does not wait for. Until this runs a shader is linked by the first draw that uses it, and a draw call is queued before that happens: run it before rendering a frame that has to see each shader's final state, such as a pre-warm pass. Must be called on the thread holding the GL context.
public void LinkLoadedShaders()LoadShader(string, params (string ComboName, byte ComboValue)[])
Loads or retrieves a cached shader compiled with the specified static combos.
public Shader LoadShader(string shaderName, params (string ComboName, byte ComboValue)[] combos)Parameters
shaderName string
The Source 2 shader name (e.g. complex.vfx), or a renderer shader file name that must exist (e.g. grid). See ShaderLoader.GetShaderFileByName(string).
combos (string ComboName, byte ComboValue)[]
Static combo name/value pairs to activate.
Returns
LoadShader(string, IReadOnlyDictionary<string, byte>?, bool)
Loads or retrieves a cached shader compiled with the given argument dictionary.
public Shader LoadShader(string shaderName, IReadOnlyDictionary<string, byte>? arguments = null, bool blocking = false)Parameters
shaderName string
The Source 2 shader name (e.g. complex.vfx), or a renderer shader file name that must exist (e.g. grid). See ShaderLoader.GetShaderFileByName(string).
arguments IReadOnlyDictionary<string, byte>?
Static combo parameter overrides, or null for defaults.
blocking bool
When true, waits for linking to complete before returning.
Returns
ShaderNameFromPath(string)
Returns the bare shader name from a full shader file path by stripping the trailing stage extension (.vert.slang, .frag.slang, or .comp.slang).
public static string ShaderNameFromPath(string shaderFilePath)Parameters
shaderFilePath string
The full path or file name of the shader (e.g. /path/complex.vert.slang).
Returns
string
The shader name without directory or extension (e.g. complex).

