Skip to content

Game.Rendering.RenderingUtils

Assembly:
(unspecified — likely Assembly-CSharp or game runtime assembly)
Namespace: Game.Rendering

Type: static class

Base: System.Object

Summary:
Utility helper methods used by the renderer and various rendering-related systems. Provides conversions between math types (Colossal/Unity.Mathematics) and Unity types, LOD and distance calculations, rendering size estimators (including shadow variants), safe bounds helpers, bone lookup for prefabs, and helpers to convert character blend weight containers. Most methods are pure/stateless math helpers; a few perform lookups and can mutate ref parameters (see FindBoneIndex).


Fields

  • This type declares no instance or static fields.
    The class is a purely static utility container.

Properties

  • This type declares no properties.

Constructors

  • This static class has no public constructors.
    There is no explicit static constructor defined.

Methods

  • public static Matrix4x4 ToMatrix4x4(float4x4 matrix)
    Converts a Colossal.Mathematics/Unity.Mathematics float4x4 into a UnityEngine.Matrix4x4 by setting columns.

  • public static Color ToColor(float4 vector)
    Converts a float4 (rgba) to a UnityEngine.Color.

  • public static float4 Lerp(float4 c0, float4 c0_5, float4 c1, float t)
    Performs a two-segment linear interpolation across three control points: if t <= 0.5 lerps between c0 and c0_5, otherwise lerps between c0_5 and c1. Useful for piecewise interpolations.

  • public static Bounds ToBounds(Bounds3 bounds)
    Converts a Bounds3 (game math struct) to a UnityEngine.Bounds using MathUtils.Center and MathUtils.Size.

  • public static float4 CalculateLodParameters(float lodFactor, BatchCullingContext cullingContext)
    Overload that extracts LODParameters from a BatchCullingContext and forwards to the LODParameters overload.

  • public static float4 CalculateLodParameters(float lodFactor, LODParameters lodParameters)
    Computes LOD parameter vector from a lodFactor and camera LODParameters (uses fieldOfView). Returned float4 contains packed values used by other LOD/distance helpers.

  • public static float CalculateMinDistance(Bounds3 bounds, float3 cameraPosition, float3 cameraDirection, float4 lodParameters)
    Computes the minimum effective distance of a bounds from the camera along a direction, using the lodParameters (z/w entries are used). Useful for LOD culling / selection.

  • public static float CalculateMaxDistance(Bounds3 bounds, float3 cameraPosition, float3 cameraDirection, float4 lodParameters)
    Computes the maximum effective distance of a bounds from the camera along a direction; counterpart to CalculateMinDistance.

  • public static int CalculateLodLimit(float metersPerPixel, float bias)
    Adjusts metersPerPixel by bias and delegates to the metersPerPixel-only overload to compute an 8-bit LOD limit.

  • public static int CalculateLodLimit(float metersPerPixel)
    Computes an 8-bit LOD limit from metersPerPixel using a packed math expression: returns a value in [0,255].

  • public static int CalculateLod(float distanceSq, float4 lodParameters)
    Computes an 8-bit LOD index from squared distance and lodParameters. Uses a fast integer-as-float bit trick and clamps into byte range.

  • public static float CalculateDistanceFactor(int lod)
    Returns a distance scaling factor for a given 8-bit lod value: pow(2, (128 - lod)/6).

  • public static float CalculateDistance(int lod, float4 lodParameters)
    Returns an estimated distance for the given lod by multiplying the distance factor with lodParameters.x.

  • public static Bounds3 SafeBounds(Bounds3 bounds)
    Shrinks bounds slightly to ensure non-zero size (subtracts up to 0.01 from each axis size), returns adjusted Bounds3.

  • public static float GetRenderingSize(float3 size)
    Returns a simple average-size metric: sum(size) / 3.

  • public static float GetRenderingSize(float3 size, float indexCount)
    Returns a rendering size adjusted by index count using a heuristic: sum(size) * 0.57735026 * rsqrt(indexCount).

  • public static float GetRenderingSize(float2 size)
    Creates a float3 from size and a heuristic third component (max(size.x8, size.y4)) and returns GetRenderingSize(float3).

  • public static float GetShadowRenderingSize(float2 size)
    Variant used for shadows: uses a different heuristic third component (max(size * (2,2))) and returns GetRenderingSize(float3).

  • public static float GetRenderingSize(float2 size, float indexFactor)
    Combines indexFactor with a heuristic multiplier on size then delegates to GetRenderingSize(float3, indexCount).

  • public static float GetRenderingSize(float3 boundsSize, StackDirection stackDirection)
    Switch-based helper that adapts boundsSize depending on stacking direction (Right/Up/Forward/Default) and returns an appropriate rendering size.

  • public static float GetShadowRenderingSize(float3 boundsSize, StackDirection stackDirection)
    Similar to GetRenderingSize but intended for shadow-size heuristics. Note: default case falls back to GetRenderingSize(boundsSize).

  • public static float GetRenderingSize(float3 boundsSize, float3 meshSize, float indexCount, StackDirection stackDirection)
    More detailed variant that considers mesh size and index count, dividing by the appropriate mesh dimension depending on stackDirection, and delegates to other overloads.

  • public static int2 FindBoneIndex(Entity prefab, ref float3 position, ref quaternion rotation, int boneID, ref BufferLookup<SubMesh> subMeshBuffers, ref BufferLookup<ProceduralBone> proceduralBoneBuffers)
    Searches the prefab's submeshes and procedural bones for a connection matching boneID. If found:

  • May adjust the passed-in position and rotation (applies bone bind-pose and transform).
  • Returns an int2 where x is the flat bone-index within procedural bones and y is the submesh index (or -1 if transform not present).
  • If not found, returns -1 (as int2; effectively both components -1). Notes: This routine reads buffers via BufferLookup and can mutate ref parameters; intended for runtime prefab bone binding.

  • public static BlendWeight GetBlendWeight(CharacterGroup.IndexWeight indexWeight)
    Converts a CharacterGroup.IndexWeight to a BlendWeight (maps index and weight).

  • public static BlendWeights GetBlendWeights(CharacterGroup.IndexWeight8 indexWeight8)
    Converts an 8-weight index struct to a BlendWeights container by converting each IndexWeight via GetBlendWeight.

Usage Example

// Convert a float4x4 to Unity Matrix4x4 and compute LOD parameters:
float4x4 worldToLocal = ...;
Matrix4x4 unityMatrix = RenderingUtils.ToMatrix4x4(worldToLocal);

float lodFactor = 1.0f;
LODParameters lodParams = /* obtained from camera/rendering context */;
float4 lodVector = RenderingUtils.CalculateLodParameters(lodFactor, lodParams);

// Estimate rendering size for a mesh bounds:
float3 boundsSize = new float3(2.0f, 1.0f, 0.5f);
float renderSize = RenderingUtils.GetRenderingSize(boundsSize);

Notes and remarks: - This class depends on Colossal.Mathematics, Unity.Mathematics, UnityEngine, UnityEngine.Rendering, Game.Prefabs, and Unity.Entities types. - Most helpers are stateless and safe to call from any thread that has access to the math structures, but methods that use BufferLookup (FindBoneIndex) must be used in appropriate ECS/Job contexts and respect the BufferLookup threading rules.