Class MaterialLoader
Namespace: ValveResourceFormat.Renderer.Materials
Assembly: Renderer.dll
Loads and caches materials and textures from Source 2 resources.
public class MaterialLoaderInheritance
Constructors
MaterialLoader(RendererContext)
Initializes a new instance of the class.
public MaterialLoader(RendererContext rendererContext)Parameters
rendererContext RendererContext
The renderer context used for file loading and shader access.
Fields
ReservedTextureSlotByName
Gets the texture unit each reserved sampler uniform is bound to.
public static readonly FrozenDictionary<string, ReservedTextureSlots> ReservedTextureSlotByNameField Value
FrozenDictionary<string, ReservedTextureSlots>
ShaderTextures
Material invariant textures, requested by shaders. They become scene-wide textures.
public static readonly List<(ReservedTextureSlots Slot, string Name, string Path)> ShaderTexturesField Value
List<(ReservedTextureSlots Slot, string Name, string Path)>
Properties
MaterialCount
Gets the number of materials currently held in the cache.
public int MaterialCount { get; }Property Value
MaxTextureMaxAnisotropy
Gets or sets the maximum anisotropy level applied to newly loaded textures when anisotropic filtering is enabled.
public static float MaxTextureMaxAnisotropy { get; set; }Property Value
Methods
Clear()
Clears the material cache and disposes any cached textures and samplers.
public void Clear()GenerateGradientTexture(ReadOnlySpan<(float Position, Color32 Color)>)
Builds a one-dimensional colour ramp from a list of gradient stops.
public static RenderTexture GenerateGradientTexture(ReadOnlySpan<(float Position, Color32 Color)> stops)Parameters
stops ReadOnlySpan<(float Position, Color32 Color)>
Gradient stops, each a position in 0-1 and its colour. Need not be sorted.
Returns
GetDefaultColor()
Returns a lazily created 1×1 solid white colour texture, a neutral fallback albedo.
public RenderTexture GetDefaultColor()Returns
GetDefaultMask()
Returns a lazily created 1×1 solid white mask texture.
public RenderTexture GetDefaultMask()Returns
GetDefaultNormal()
Returns a lazily created 1×1 flat normal map texture (127, 127, 255).
public RenderTexture GetDefaultNormal()Returns
GetDefaultTextureArray()
Returns a lazily created 1×1 single layer white array texture.
public RenderTexture GetDefaultTextureArray()Returns
GetDefaultVolume()
Returns a lazily created 1×1×1 white volume texture.
public RenderTexture GetDefaultVolume()Returns
GetErrorTexture()
Returns a lazily created 4×4 checkerboard error texture used as a fallback for missing textures.
public RenderTexture GetErrorTexture()Returns
GetImageExportFormat(bool)
Returns the readback format appropriate for exporting a rendered image: 8-bit BGRA, or 32-bit float RGBA for HDR.
public static ImageFormat GetImageExportFormat(bool hdr)Parameters
hdr bool
Whether to use the HDR (32-bit float) format.
Returns
GetMaterial(string?, Dictionary<string, byte>?)
Returns a cached for the given resource path and shader arguments, loading and caching it on first access.
public RenderMaterial GetMaterial(string? name, Dictionary<string, byte>? shaderArguments)Parameters
name string?
The compiled material resource path, or null to return the error material.
shaderArguments Dictionary<string, byte>?
Optional static combo overrides to pass to the shader.
Returns
GetOrCreateSampler(RsTextureAddressMode, RsTextureAddressMode, bool, bool)
Gets a sampler object for the supplied texture address modes, creating and caching one per .
public int GetOrCreateSampler(RsTextureAddressMode addressModeU, RsTextureAddressMode addressModeV, bool mipmaps = true, bool anisotropicFiltering = true)Parameters
addressModeU RsTextureAddressMode
addressModeV RsTextureAddressMode
mipmaps bool
anisotropicFiltering bool
Returns
GetTexture(string, bool, bool, bool)
Returns a cached for the given path, loading it on first access.
public RenderTexture GetTexture(string name, bool srgbRead = false, bool anisotropicFiltering = false, bool streaming = false)Parameters
name string
The compiled texture resource path.
srgbRead bool
Whether to interpret the texture data in sRGB color space.
anisotropicFiltering bool
Whether to apply anisotropic filtering when is sufficient.
streaming bool
Whether mips may arrive over later frames.
Returns
IsReservedTexture(string)
Returns whether a uniform name is bound to one of the .
public static bool IsReservedTexture(string uniformName)Parameters
uniformName string
Returns
LoadBitmapTexture(SKBitmap)
Uploads an as a 2D texture and returns the resulting .
public static RenderTexture LoadBitmapTexture(SKBitmap bitmap)Parameters
bitmap SKBitmap
The bitmap whose pixels are uploaded to the GPU.
Returns
LoadMaterial(Resource?, Dictionary<string, byte>?)
Creates a from an already-loaded resource, binding textures and resolving aliases.
public RenderMaterial LoadMaterial(Resource? resource, Dictionary<string, byte>? shaderArguments = null)Parameters
resource Resource?
The material resource, or null to return the error material.
shaderArguments Dictionary<string, byte>?
Optional static combo overrides to pass to the shader.
Returns
LoadTexture(Resource, bool, bool)
Uploads a texture resource to the GPU and returns the resulting .
public RenderTexture LoadTexture(Resource textureResource, bool srgbRead = false, bool async = false)Parameters
textureResource Resource
The loaded texture resource.
srgbRead bool
Whether to use the sRGB internal format when available.
async bool
When true, mip data is loaded on background jobs and hooked up later by , smallest mips first.

