Reworking VertexData
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import Common;
|
||||
|
||||
struct AABB
|
||||
{
|
||||
float3 min;
|
||||
float3 max;
|
||||
bool insideFrustum(float4x4 transform, Frustum frustum)
|
||||
{
|
||||
float3 corners[8];
|
||||
corners[0] = mul(transform, float4(min.x, min.y, min.z, 1.0f)).xyz;
|
||||
corners[1] = mul(transform, float4(min.x, min.y, max.z, 1.0f)).xyz;
|
||||
corners[2] = mul(transform, float4(min.x, max.y, min.z, 1.0f)).xyz;
|
||||
corners[3] = mul(transform, float4(min.x, max.y, max.z, 1.0f)).xyz;
|
||||
corners[4] = mul(transform, float4(max.x, min.y, min.z, 1.0f)).xyz;
|
||||
corners[5] = mul(transform, float4(max.x, min.y, max.z, 1.0f)).xyz;
|
||||
corners[6] = mul(transform, float4(max.x, max.y, min.z, 1.0f)).xyz;
|
||||
corners[7] = mul(transform, float4(max.x, max.y, max.z, 1.0f)).xyz;
|
||||
for(int i = 0; i < 8; ++i)
|
||||
{
|
||||
if(frustum.pointInside(corners[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,7 @@ struct ViewParameter
|
||||
float4 cameraPos_WS;
|
||||
float2 screenDimensions;
|
||||
}
|
||||
//layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
|
||||
layout(set = INDEX_VIEW_PARAMS)
|
||||
ParameterBlock<ViewParameter> viewParams;
|
||||
|
||||
|
||||
@@ -31,7 +31,24 @@ struct Plane
|
||||
|
||||
struct Frustum
|
||||
{
|
||||
Plane planes[4];
|
||||
Plane sides[4];
|
||||
Plane basePlane;
|
||||
bool pointInside(float3 point)
|
||||
{
|
||||
if (dot(basePlane.n, point) + basePlane.d < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int p = 0; p < 4; ++p)
|
||||
{
|
||||
float result = dot(sides[p].n, point) + sides[p].d;
|
||||
if(result < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Plane computePlane(float3 p0, float3 p1, float3 p2)
|
||||
{
|
||||
|
||||
@@ -8,4 +8,5 @@ interface IMaterial
|
||||
|
||||
};
|
||||
|
||||
layout(set = INDEX_MATERIAL)
|
||||
ParameterBlock<IMaterial> gMaterial;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import AABB;
|
||||
|
||||
struct MeshletDescription
|
||||
{
|
||||
AABB boundingBox;
|
||||
uint32_t vertexCount;
|
||||
uint32_t primitiveCount;
|
||||
uint32_t vertexOffset;
|
||||
@@ -14,8 +17,30 @@ struct MeshletData
|
||||
StructuredBuffer<uint32_t> vertexIndices;
|
||||
};
|
||||
|
||||
struct MeshData
|
||||
{
|
||||
uint numMeshlets;
|
||||
uint meshletOffset;
|
||||
};
|
||||
|
||||
static const uint MAX_VERTICES = 64;
|
||||
static const uint MAX_PRIMITIVES = 126;
|
||||
static const uint GROUP_SIZE = 32;
|
||||
static const uint TASK_GROUP_SIZE = 128;
|
||||
static const uint MESH_GROUP_SIZE = 32;
|
||||
static const uint MAX_MESHLETS_PER_MESH = 512;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 transformMatrix;
|
||||
};
|
||||
|
||||
struct Scene
|
||||
{
|
||||
StructuredBuffer<InstanceData> instances;
|
||||
StructuredBuffer<MeshData> meshData;
|
||||
StructuredBuffer<MeshletData> meshlets;
|
||||
};
|
||||
|
||||
layout(set = INDEX_SCENE_DATA)
|
||||
ParameterBlock<Scene> scene;
|
||||
|
||||
ParameterBlock<MeshletData> meshlets;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 transformMatrix;
|
||||
};
|
||||
|
||||
struct MeshData
|
||||
{
|
||||
uint numMeshlets;
|
||||
uint meshletOffset;
|
||||
uint numInstances;
|
||||
uint instanceOffset;
|
||||
};
|
||||
|
||||
struct Scene
|
||||
{
|
||||
StructuredBuffer<InstanceData> instances;
|
||||
StructuredBuffer<MeshData> meshData;
|
||||
};
|
||||
|
||||
ParameterBlock<Scene> scene;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import VertexData;
|
||||
import Common;
|
||||
import Scene;
|
||||
|
||||
struct SkinnedMeshVertexAttributes : VertexAttributes
|
||||
{
|
||||
float4 clipPosition: SV_Position;
|
||||
float3 worldPosition: POSITION0;
|
||||
float2 texCoords: TEXCOORD0;
|
||||
float3 normal: NORMAL0;
|
||||
float3 tangent: TANGENT0;
|
||||
float3 biTangent: BITANGENT0;
|
||||
float3 getWorldPosition()
|
||||
{
|
||||
return worldPosition;
|
||||
}
|
||||
float2 getTexCoords()
|
||||
{
|
||||
return texCoords;
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
float3 getTangent()
|
||||
{
|
||||
return tangent;
|
||||
}
|
||||
float3 getBiTangent()
|
||||
{
|
||||
return biTangent;
|
||||
}
|
||||
}
|
||||
|
||||
struct SkinnedMeshVertexData : VertexData
|
||||
{
|
||||
SkinnedMeshVertexAttributes getAttributes(uint index, float4x4 transform)
|
||||
{
|
||||
StaticMeshVertexAttributes attr;
|
||||
float4x4 boneTransform = float4x4(1.0f);
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
boneTransform += bones[boneIndices[i]] * boneWeights[i];
|
||||
}
|
||||
float4 localPos = mul(boneTransform, float4(positions[index], 1));
|
||||
float4 worldPos = mul(transform, localPos);
|
||||
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
|
||||
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
|
||||
attr.clipPosition = clipPos;
|
||||
attr.worldPosition = worldPos.xyz;
|
||||
attr.texCoords = texCoords[index];
|
||||
attr.normal = normals[index];
|
||||
attr.tangent = tangents[index];
|
||||
attr.biTangent = biTangents[index];
|
||||
return attr;
|
||||
}
|
||||
StructuredBuffer<float3> positions;
|
||||
StructuredBuffer<float2> texCoords;
|
||||
StructuredBuffer<float3> normals;
|
||||
StructuredBuffer<float3> tangents;
|
||||
StructuredBuffer<float3> biTangents;
|
||||
StructuredBuffer<int4> boneIndices;
|
||||
StructuredBuffer<float4> boneWeights;
|
||||
StructuredBuffer<float4x4> bones;
|
||||
}
|
||||
layout(set = INDEX_VERTEX_DATA)
|
||||
ParameterBlock<SkinnedMeshVertexData> vertexData;
|
||||
@@ -34,11 +34,11 @@ struct StaticMeshVertexAttributes : VertexAttributes
|
||||
|
||||
struct StaticMeshVertexData : VertexData
|
||||
{
|
||||
StaticMeshVertexAttributes getAttributes(uint index, InstanceData inst)
|
||||
StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform)
|
||||
{
|
||||
StaticMeshVertexAttributes attr;
|
||||
float4 localPos = float4(positions[index], 1);
|
||||
float4 worldPos = mul(inst.transformMatrix, localPos);
|
||||
float4 worldPos = mul(transform, localPos);
|
||||
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
|
||||
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
|
||||
attr.clipPosition = clipPos;
|
||||
@@ -55,4 +55,5 @@ struct StaticMeshVertexData : VertexData
|
||||
StructuredBuffer<float3> tangents;
|
||||
StructuredBuffer<float3> biTangents;
|
||||
}
|
||||
layout(set = INDEX_VERTEX_DATA)
|
||||
ParameterBlock<StaticMeshVertexData> vertexData;
|
||||
@@ -11,5 +11,5 @@ interface VertexAttributes
|
||||
|
||||
interface VertexData
|
||||
{
|
||||
VertexAttributes getAttributes(uint index, InstanceData inst);
|
||||
VertexAttributes getAttributes(uint index, float4x4 transform);
|
||||
};
|
||||
Reference in New Issue
Block a user