GlobalUbo

Represents the Global Uniform Buffer Object (UBO) used for global shader data.

Properties

Count

(int): Gets the number of point lights in the UBO.

DirectionalCount

(int): Gets the number of directional light slots in the UBO.

SizeOf

(uint): Gets the size, in bytes, of the UBO.

Public Methods

ClearLights

public void ClearLights()

Turns every light slot off. Call this before filling the UBO from a scene: a default PointLight is white at full intensity sitting on the world origin, so slots left over from a scene with more lights would keep illuminating anything near it.

Update

public void Update(Matrix4x4 projectionMatrix, Matrix4x4 viewMatrix, Vector4 frontVector)

Updates the UBO with new projection, view, and front vector data.

Parameters:

  • projectionMatrix (Matrix4x4): The projection matrix.
  • viewMatrix (Matrix4x4): The view matrix.
  • frontVector (Vector4): The front vector.

SetPointLightPosition

public void SetPointLightPosition(int lightIndex, Vector3 position)

Sets the position of a point light at the specified index.

Parameters:

  • lightIndex (int): The index of the point light.
  • position (Vector3): The position to set.

SetPointLightColor

public void SetPointLightColor(int lightIndex, Vector4 color, float intensity)

Sets the color and intensity of a point light at the specified index.

Parameters:

  • lightIndex (int): The index of the point light.
  • color (Vector4): The color to set.
  • intensity (float): The intensity to set.

SetDirectionalLight

public void SetDirectionalLight(int lightIndex, Vector3 direction, Vector4 color, float intensity)

Sets the direction, color and intensity of a directional light at the specified index.

Parameters:

  • lightIndex (int): The index of the directional light.
  • direction (Vector3): The direction the light travels in world space.
  • color (Vector4): The color to set.
  • intensity (float): The intensity to set.

AsBytes

public byte[] AsBytes()

Converts the UBO data to a byte array.

Returns: byte[]

  • A byte array containing the UBO data.