Skip to content

Game.Rendering.VTTextureParamBlockExtension

Assembly: Assembly-CSharp (in-game)
Namespace: Game.Rendering

Type: static class

Base: System.Object

Summary:
This static extension class provides a small helper to write a VT (virtual texturing) parameter block into a Unity MaterialPropertyBlock. It maps the two Vector4 fields from a VTTextureParamBlock into shader property IDs supplied as a tuple. This is a convenience wrapper used when applying virtual texturing parameters to materials without creating new Material instances.


Fields

  • This type defines no fields.
    This is a stateless static extension class; it only provides a helper method and stores no instance or static state.

Properties

  • This type defines no properties.
    There are no properties because the class is static and only exposes extension methods.

Constructors

  • This static class has no constructors.
    Static classes cannot be instantiated. The class only contains static methods and therefore does not expose any constructors.

Methods

  • public static void SetTextureParamBlock(this MaterialPropertyBlock material, (int transform, int textureInfo) nameId, VTTextureParamBlock block)
    Writes the contents of a VTTextureParamBlock into the given MaterialPropertyBlock using the provided shader property IDs.

  • material: The MaterialPropertyBlock to modify. Typically applied to a Renderer via Renderer.SetPropertyBlock.

  • nameId: A tuple of two integer shader property IDs: nameId.transform identifies the shader property that will receive the transform Vector4, and nameId.textureInfo identifies the property that will receive the textureInfo Vector4. These IDs are commonly obtained via Shader.PropertyToID.
  • block: The VTTextureParamBlock instance containing at least two Vector4 properties named transform and textureInfo (from Colossal.IO.AssetDatabase.VirtualTexturing). The method calls MaterialPropertyBlock.SetVector for each field.

Notes: - This method assumes block.transform and block.textureInfo are compatible with MaterialPropertyBlock.SetVector (typically UnityEngine.Vector4). - MaterialPropertyBlock operations should be performed on the main thread. After setting values, remember to apply the block to the appropriate Renderer.

Usage Example

using UnityEngine;
using Colossal.IO.AssetDatabase.VirtualTexturing; // for VTTextureParamBlock

// Example usage inside a MonoBehaviour
void ApplyVTParams(Renderer renderer, VTTextureParamBlock vtBlock)
{
    var mpb = new MaterialPropertyBlock();

    // Precompute shader property IDs (preferably once and cached)
    int transformId = Shader.PropertyToID("_VT_Transform");
    int textureInfoId = Shader.PropertyToID("_VT_TextureInfo");

    // Call the extension method; pass IDs as a tuple
    mpb.SetTextureParamBlock((transformId, textureInfoId), vtBlock);

    // Apply the property block to the renderer
    renderer.SetPropertyBlock(mpb);
}

Additional tips: - Cache shader property IDs using Shader.PropertyToID to avoid runtime string lookups. - Ensure the shader you target defines matching Vector properties for the provided IDs. - This extension is primarily a convenience to keep code that sets virtual texturing parameters concise and consistent.