Skip to content

LightStorage

tobspr edited this page Dec 25, 2015 · 22 revisions

Light Storage

Each Light is stored in the LightBuffer with 4 vec4's = 16 floats

The data layout is:

[V0.x] +0: Light Type
[V0.y] +1: IES Profile Index (or -1 for no profile)
[V0.z] +2: First Shadow Source index (or -1 for no shadows)
[V0.w] +3: Position.x
[V1.x] +4: Position.y
[V1.y] +5: Position.z
[V1.z] +6: Color.r
[V1.w] +7: Color.g
[V2.x] +8: Color.b
       +9-15: [Any additional properties depending on the light type]

NullLights

Null lights have a light type of 0, to indicate there is no light at that slot. They don't have any additional properties, too.

PointLights

       +0-8: [see above]
[V2.y] +9:  Radius
[V2.z] +10: Inner Radius (For area PointLights)
       +11-15: [unused]

SpotLights

       +0-8: [see above]
[V2.y] +9:   Radius
[V2.z] +10:  FOV
[V2.w] +11:  Direction.x
[V3.x] +12:  Direction.y
[V3.y] +13:  Direction.z
       +14-15: [unused]

Shadow Source Storage

Each Shadow source is stored in the SourceBuffer with 5 vec4's = 20 floats

The data layout is:

[V0.x - V3.w] +0-16: View-Projection Matrix
[V4.x] +17: uv-coordinate x
[V4.y] +18: uv-coordinate y
[V4.z] +19: uv-coordinate width
[V4.w] +20: uv-coordinate height

GPU Commands:

Commands have the layout:

+0:    [Command ID]
+1-31: [Command Data]

There are several command types:

CMD_INVALID

Does nothing, gets just skipped

CMD_STORE_LIGHT

Stores a new light into the light data, command layout:

+0:    [Command ID]
+1:    [Light ID]
+2-31: [Light Data, see above]

The light id is used to figure where to write the light into the global lights storage buffer. This command basically just takes the Light Data, and writes it to the specified location.

CMD_REMOVE_LIGHT

This command just sets all of the light data to zeroes, so that the light gets a NullLight, and ignored. +0 [Command ID] +1: [Light ID] +2-31: [unused]

CMD_STORE_SOURCE

Stores a new shadow source into the shadow source data, command layout:

+0:    [Command ID]
+1:    [Light ID]
+2-31: [Source Data, see above]

CMD_REMOVE_SOURCE

This command sets all of the source data to zeroes, to indicate its not further used.

+0:    [Command ID]
+1:    [Source ID]
+2-31: [unused]