Files
com.misaki.ao-volume/Runtime/Shader/Includes/GeometryData.cs
Misaki c25ff0dd61 Added H-z culling;
Changed the name of enum FrustumGPU to GPUFrustum;
2025-02-20 18:01:12 +09:00

74 lines
2.0 KiB
C#

using UnityEngine;
using UnityEngine.Rendering;
namespace Misaki.AoVolume
{
[GenerateHLSL(PackingRules.Exact, false)]
internal struct GPUFrustum
{
// The data of the 6 planes of the frustum
public Vector3 normal0;
public float dist0;
public Vector3 normal1;
public float dist1;
public Vector3 normal2;
public float dist2;
public Vector3 normal3;
public float dist3;
public Vector3 normal4;
public float dist4;
public Vector3 normal5;
public float dist5;
// The data of the 8 corners of the frustum
public Vector4 corner0;
public Vector4 corner1;
public Vector4 corner2;
public Vector4 corner3;
public Vector4 corner4;
public Vector4 corner5;
public Vector4 corner6;
public Vector4 corner7;
}
[GenerateHLSL(PackingRules.Exact, false)]
internal struct OrientedBoundingBox
{
// 4 x float3 = 48 bytes.
// TODO: pack the axes into 16-bit UNORM per channel, and consider a quaternionic representation.
public Vector3 center;
public Vector3 right;
public Vector3 up;
public Vector3 extent;
//public ushort quatX;
//public ushort quatY;
//public ushort quatZ;
//public ushort quatW;
public readonly Vector3 Forward => Vector3.Cross(up, right);
public OrientedBoundingBox(Matrix4x4 trs)
{
var vecX = (Vector3)trs.GetColumn(0);
var vecY = (Vector3)trs.GetColumn(1);
var vecZ = (Vector3)trs.GetColumn(2);
center = trs.GetColumn(3);
right = vecX * (1.0f / vecX.magnitude);
up = vecY * (1.0f / vecY.magnitude);
extent.x = 0.5f * vecX.magnitude;
extent.y = 0.5f * vecY.magnitude;
extent.z = 0.5f * vecZ.magnitude;
}
}
[GenerateHLSL(PackingRules.Exact, false)]
internal struct CullingData
{
public float fadeStart;
public float fadeEnd;
}
}