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
ReservedTextures
Gets the set of texture uniform names that are bound to reserved global texture slots and must not be overridden by materials.
public static readonly HashSet<string> ReservedTexturesField Value
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
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
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 OpenGL format triple appropriate for exporting a rendered image, choosing between 8-bit BGRA and 32-bit float RGBA.
public static (SizedInternalFormat SizedInternalFormat, PixelFormat PixelFormat, PixelType PixelType) GetImageExportFormat(bool hdr)Parameters
hdr bool
Whether to use the HDR (32-bit float) format.
Returns
(SizedInternalFormat SizedInternalFormat, PixelFormat PixelFormat, PixelType PixelType)
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
GetTexture(string, 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)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.
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 isViewerRequest = false)Parameters
textureResource Resource
The loaded texture resource.
srgbRead bool
Whether to use the sRGB internal format when available.
isViewerRequest bool
When true, skips mip-level capping and keeps the resource alive after upload.

