175 lines
7.6 KiB
C#
175 lines
7.6 KiB
C#
using UnityEngine;
|
|
|
|
namespace Assets.ThoMagic.Renderer
|
|
{
|
|
public struct InstanceData
|
|
{
|
|
public const int Add = 1;
|
|
public const int Delete = 2;
|
|
public static readonly int Stride = 48;
|
|
public readonly Vector4 Packed1;
|
|
public readonly Vector4 Packed2;
|
|
public readonly uint prefabId;
|
|
//Used to stream out new instances
|
|
public readonly int uploadAction;
|
|
public readonly int uploadId;
|
|
public readonly int padding;
|
|
|
|
public InstanceData(
|
|
int uploadAction,
|
|
int uploadId,
|
|
uint prefabId,
|
|
float x,
|
|
float y,
|
|
float z,
|
|
in Quaternion rotation,
|
|
float scaleXZ,
|
|
float scaleY)
|
|
{
|
|
float num = rotation.w > 0.0 ? 1f : -1f;
|
|
Packed1.x = x;
|
|
Packed1.y = y;
|
|
Packed1.z = z;
|
|
Packed1.w = (rotation.x * num);
|
|
Packed2.x = scaleXZ;
|
|
Packed2.y = scaleY;
|
|
Packed2.z = (rotation.y * num);
|
|
Packed2.w = (rotation.z * num);
|
|
this.prefabId = prefabId;
|
|
this.uploadAction = uploadAction;
|
|
this.uploadId = uploadId;
|
|
padding = 0;
|
|
}
|
|
|
|
public InstanceData(
|
|
int uploadAction,
|
|
int uploadId)
|
|
{
|
|
Packed1.x = 0;
|
|
Packed1.y = 0;
|
|
Packed1.z = 0;
|
|
Packed1.w = 0;
|
|
Packed2.x = 0;
|
|
Packed2.y = 0;
|
|
Packed2.z = 0;
|
|
Packed2.w = 0;
|
|
this.prefabId = 0;
|
|
this.uploadAction = uploadAction;
|
|
this.uploadId = uploadId;
|
|
padding = 0;
|
|
}
|
|
}
|
|
|
|
public struct PrefabData
|
|
{
|
|
public static readonly int Stride = 228;
|
|
public uint batchIndex;
|
|
public uint indexBufferStartOffset;
|
|
public uint maxCount;
|
|
public uint lodCount;
|
|
public uint fadeLods;
|
|
public Vector4 densityInDistance;
|
|
public Vector4 lodData0;
|
|
public Vector4 lodData1;
|
|
public Vector4 lodData2;
|
|
public Vector4 lodData3;
|
|
public Vector4 lodData4;
|
|
public Vector4 lodData5;
|
|
public Vector4 lodData6;
|
|
public Vector4 lodData7;
|
|
public uint indirectArgsOffset0;
|
|
public uint indirectArgsCount0;
|
|
public uint indirectArgsOffset1;
|
|
public uint indirectArgsCount1;
|
|
public uint indirectArgsOffset2;
|
|
public uint indirectArgsCount2;
|
|
public uint indirectArgsOffset3;
|
|
public uint indirectArgsCount3;
|
|
public uint indirectArgsOffset4;
|
|
public uint indirectArgsCount4;
|
|
public uint indirectArgsOffset5;
|
|
public uint indirectArgsCount5;
|
|
public uint indirectArgsOffset6;
|
|
public uint indirectArgsCount6;
|
|
public uint indirectArgsOffset7;
|
|
public uint indirectArgsCount7;
|
|
|
|
public void SetLods(Vector4[] lodData, uint[] indirectArgsPerLodOffset, uint[] indirectArgsPerLodCount)
|
|
{
|
|
this.lodData0 = lodCount > 0 ? lodData[0] : Vector4.zero;
|
|
this.lodData1 = lodCount > 1 ? lodData[1] : Vector4.zero;
|
|
this.lodData2 = lodCount > 2 ? lodData[2] : Vector4.zero;
|
|
this.lodData3 = lodCount > 3 ? lodData[3] : Vector4.zero;
|
|
this.lodData4 = lodCount > 4 ? lodData[4] : Vector4.zero;
|
|
this.lodData5 = lodCount > 5 ? lodData[5] : Vector4.zero;
|
|
this.lodData6 = lodCount > 6 ? lodData[6] : Vector4.zero;
|
|
this.lodData7 = lodCount > 7 ? lodData[7] : Vector4.zero;
|
|
|
|
this.indirectArgsOffset0 = lodCount > 0 ? indirectArgsPerLodOffset[0] : 0;
|
|
this.indirectArgsOffset1 = lodCount > 1 ? indirectArgsPerLodOffset[1] : 0;
|
|
this.indirectArgsOffset2 = lodCount > 2 ? indirectArgsPerLodOffset[2] : 0;
|
|
this.indirectArgsOffset3 = lodCount > 3 ? indirectArgsPerLodOffset[3] : 0;
|
|
this.indirectArgsOffset4 = lodCount > 4 ? indirectArgsPerLodOffset[4] : 0;
|
|
this.indirectArgsOffset5 = lodCount > 5 ? indirectArgsPerLodOffset[5] : 0;
|
|
this.indirectArgsOffset6 = lodCount > 6 ? indirectArgsPerLodOffset[6] : 0;
|
|
this.indirectArgsOffset7 = lodCount > 7 ? indirectArgsPerLodOffset[7] : 0;
|
|
|
|
this.indirectArgsCount0 = lodCount > 0 ? indirectArgsPerLodCount[0] : 0;
|
|
this.indirectArgsCount1 = lodCount > 1 ? indirectArgsPerLodCount[1] : 0;
|
|
this.indirectArgsCount2 = lodCount > 2 ? indirectArgsPerLodCount[2] : 0;
|
|
this.indirectArgsCount3 = lodCount > 3 ? indirectArgsPerLodCount[3] : 0;
|
|
this.indirectArgsCount4 = lodCount > 4 ? indirectArgsPerLodCount[4] : 0;
|
|
this.indirectArgsCount5 = lodCount > 5 ? indirectArgsPerLodCount[5] : 0;
|
|
this.indirectArgsCount6 = lodCount > 6 ? indirectArgsPerLodCount[6] : 0;
|
|
this.indirectArgsCount7 = lodCount > 7 ? indirectArgsPerLodCount[7] : 0;
|
|
}
|
|
|
|
public PrefabData(
|
|
uint batchIndex,
|
|
uint indexBufferStartOffset,
|
|
uint maxCount,
|
|
uint lodCount,
|
|
uint fadeLods,
|
|
Vector4 densityInDistance,
|
|
Vector4[] lodData,
|
|
uint[] indirectArgsPerLodOffset,
|
|
uint[] indirectArgsPerLodCount
|
|
)
|
|
{
|
|
this.batchIndex = batchIndex;
|
|
this.indexBufferStartOffset = indexBufferStartOffset;
|
|
this.maxCount = maxCount;
|
|
this.lodCount = lodCount;
|
|
this.fadeLods = fadeLods;
|
|
this.densityInDistance = densityInDistance;
|
|
|
|
this.lodData0 = lodCount > 0 ? lodData[0] : Vector4.zero;
|
|
this.lodData1 = lodCount > 1 ? lodData[1] : Vector4.zero;
|
|
this.lodData2 = lodCount > 2 ? lodData[2] : Vector4.zero;
|
|
this.lodData3 = lodCount > 3 ? lodData[3] : Vector4.zero;
|
|
this.lodData4 = lodCount > 4 ? lodData[4] : Vector4.zero;
|
|
this.lodData5 = lodCount > 5 ? lodData[5] : Vector4.zero;
|
|
this.lodData6 = lodCount > 6 ? lodData[6] : Vector4.zero;
|
|
this.lodData7 = lodCount > 7 ? lodData[7] : Vector4.zero;
|
|
|
|
this.indirectArgsOffset0 = lodCount > 0 ? indirectArgsPerLodOffset[0] : 0;
|
|
this.indirectArgsOffset1 = lodCount > 1 ? indirectArgsPerLodOffset[1] : 0;
|
|
this.indirectArgsOffset2 = lodCount > 2 ? indirectArgsPerLodOffset[2] : 0;
|
|
this.indirectArgsOffset3 = lodCount > 3 ? indirectArgsPerLodOffset[3] : 0;
|
|
this.indirectArgsOffset4 = lodCount > 4 ? indirectArgsPerLodOffset[4] : 0;
|
|
this.indirectArgsOffset5 = lodCount > 5 ? indirectArgsPerLodOffset[5] : 0;
|
|
this.indirectArgsOffset6 = lodCount > 6 ? indirectArgsPerLodOffset[6] : 0;
|
|
this.indirectArgsOffset7 = lodCount > 7 ? indirectArgsPerLodOffset[7] : 0;
|
|
|
|
this.indirectArgsCount0 = lodCount > 0 ? indirectArgsPerLodCount[0] : 0;
|
|
this.indirectArgsCount1 = lodCount > 1 ? indirectArgsPerLodCount[1] : 0;
|
|
this.indirectArgsCount2 = lodCount > 2 ? indirectArgsPerLodCount[2] : 0;
|
|
this.indirectArgsCount3 = lodCount > 3 ? indirectArgsPerLodCount[3] : 0;
|
|
this.indirectArgsCount4 = lodCount > 4 ? indirectArgsPerLodCount[4] : 0;
|
|
this.indirectArgsCount5 = lodCount > 5 ? indirectArgsPerLodCount[5] : 0;
|
|
this.indirectArgsCount6 = lodCount > 6 ? indirectArgsPerLodCount[6] : 0;
|
|
this.indirectArgsCount7 = lodCount > 7 ? indirectArgsPerLodCount[7] : 0;
|
|
}
|
|
}
|
|
}
|