Class ShaderLoader
Namespace: ValveResourceFormat.Renderer.Shaders
Assembly: Renderer.dll
Compiles and caches OpenGL shader programs from source files.
public class ShaderLoader : IDisposableInheritance
Implements
Constructors
ShaderLoader(RendererContext)
Initializes a new instance of the 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
SlangExtension
The file extension for Slang shader source files (.slang).
public const string SlangExtension = ".slang"Field Value
VfxExtension
The file extension of Source 2 shader names (.vfx).
public const string VfxExtension = ".vfx"Field Value
Properties
DeclaredReservedTextures
Gets every reserved texture sampler declared by the shaders loaded so far. Read off the shader source, so unlike a shader's own it is known before the program links, and it includes samplers behind a combo the linker went on to drop. Grow only, so a renderer can pick up what was added since it last looked; see .
public HashSet<string> DeclaredReservedTextures { get; }Property Value
ShaderCount
Gets the number of compiled shader variants currently held in the cache.
public int ShaderCount { get; }Property Value
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 .
GetShaderFileByName(string)
Resolves a shader name to the renderer shader file that draws it. Mappings registered in
take priority over the built-in ones.public static string GetShaderFileByName(string shaderName)Parameters
shaderName string
A Source 2 shader name ending in .vfx, which is mapped to the renderer shader that best matches it and falls back to complex when it is unknown. Any other name is the renderer shader file to load directly, and must exist.
Returns
The renderer shader name without stage or extension (e.g. complex).
LinkLoadedShaders()
Collects the link status of every shader loaded so far, which materials load without waiting 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 .
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 = true)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 .
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
The shader name without directory or extension (e.g. complex).

