More mesh shading changes
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import Common;
|
||||
import BRDF;
|
||||
import Meshlet;
|
||||
import Scene;
|
||||
import VertexData;
|
||||
import MaterialParameter;
|
||||
|
||||
struct MeshPayload
|
||||
{
|
||||
@@ -47,14 +47,17 @@ void taskMain(
|
||||
MeshData mesh = pScene.meshData[groupID];
|
||||
for(uint i = threadID; i < MAX_MESHLETS_PER_MESH; i += TASK_GROUP_SIZE)
|
||||
{
|
||||
uint m = mesh.meshletOffset + min(mesh.numMeshlets, i);
|
||||
MeshletDescription meshlet = pScene.meshlets.meshletInfos[m];
|
||||
//if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
|
||||
if(i < mesh.numMeshlets)
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(head, 1, index);
|
||||
p.meshletId[index] = m;
|
||||
p.instanceId[index] = groupID;
|
||||
uint m = mesh.meshletOffset + i;
|
||||
MeshletDescription meshlet = pScene.meshletInfos[m];
|
||||
//if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(head, 1, index);
|
||||
p.meshletId[index] = m;
|
||||
p.instanceId[index] = groupID;
|
||||
}
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
@@ -71,6 +74,12 @@ struct PrimitiveAttributes
|
||||
uint cull: SV_CullPrimitive;
|
||||
};
|
||||
|
||||
struct MeshOutput
|
||||
{
|
||||
FragmentParameter parameter : PARAMETER;
|
||||
float4 position_CS : SV_Position;
|
||||
};
|
||||
|
||||
[numthreads(MESH_GROUP_SIZE, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
[shader("mesh")]
|
||||
@@ -78,7 +87,7 @@ void meshMain(
|
||||
in uint threadID: SV_GroupIndex,
|
||||
in uint groupID: SV_GroupID,
|
||||
in payload MeshPayload meshPayload,
|
||||
out Vertices<VertexAttributes, MAX_VERTICES> vertices,
|
||||
out Vertices<MeshOutput, MAX_VERTICES> vertices,
|
||||
out Indices<uint3, MAX_PRIMITIVES> indices
|
||||
){
|
||||
InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]];
|
||||
@@ -92,10 +101,10 @@ void meshMain(
|
||||
InterlockedMax(gs_numVertices, v + 1);
|
||||
{
|
||||
int vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
|
||||
gs_vertices[v] = pVertexData.getAttributes(md.indexOffset + vertexIndex, inst);
|
||||
gs_vertices[v] = pVertexData.getAttributes(md.indicesOffset + vertexIndex, inst.transformMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
const uint primitiveLoops = (MAX_PRIMITIVES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
|
||||
for(uint loop = 0; loop < primitiveLoops; ++loop)
|
||||
{
|
||||
@@ -103,15 +112,12 @@ void meshMain(
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
InterlockedMax(gs_numPrimitives, p + 1);
|
||||
{
|
||||
uint8_t local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||
uint8_t local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||
uint8_t local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||
uint32_t idx0 = pScene.vertexIndices[m.vertexOffset + local_idx0];
|
||||
uint32_t idx1 = pScene.vertexIndices[m.vertexOffset + local_idx1];
|
||||
uint32_t idx2 = pScene.vertexIndices[m.vertexOffset + local_idx2];
|
||||
gs_indices[p * 3 + 0] = idx0;
|
||||
gs_indices[p * 3 + 1] = idx1;
|
||||
gs_indices[p * 3 + 2] = idx2;
|
||||
uint32_t local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||
uint32_t local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||
uint32_t local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||
gs_indices[p].x = local_idx0;
|
||||
gs_indices[p].y = local_idx1;
|
||||
gs_indices[p].z = local_idx2;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
@@ -120,12 +126,16 @@ void meshMain(
|
||||
|
||||
uint v = threadID;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
vertices[v] = gs_vertices[v];
|
||||
FragmentParameter parameter = gs_vertices[v].getParameter(inst.transformMatrix);
|
||||
vertices[v].parameter = parameter;
|
||||
vertices[v].position_CS = parameter.position_CS;
|
||||
if(vertexLoops >= 1)
|
||||
{
|
||||
uint v = threadID + MESH_GROUP_SIZE;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
vertices[v] = gs_vertices[v];
|
||||
FragmentParameter parameter = gs_vertices[v].getParameter(inst.transformMatrix);
|
||||
vertices[v].parameter = parameter;
|
||||
vertices[v].position_CS = parameter.position_CS;
|
||||
}
|
||||
|
||||
uint p = threadID;
|
||||
@@ -134,19 +144,19 @@ void meshMain(
|
||||
|
||||
if(primitiveLoops >= 1)
|
||||
{
|
||||
uint p = threadID + MESH_GROUP_SIZE;
|
||||
p += MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
if(primitiveLoops >= 2)
|
||||
{
|
||||
uint p = threadID + 2 * MESH_GROUP_SIZE;
|
||||
p += MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
if(primitiveLoops >= 3)
|
||||
{
|
||||
uint p = threadID + 3 * MESH_GROUP_SIZE;
|
||||
p += MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
|
||||
@@ -20,15 +20,15 @@ struct LightingParameter
|
||||
// data passed to fragment shader
|
||||
struct FragmentParameter
|
||||
{
|
||||
float3 position_TS;
|
||||
float3 viewDir_TS;
|
||||
float3 normal_WS;
|
||||
float3 tangent_WS;
|
||||
float3 biTangent_WS;
|
||||
float3 position_WS;
|
||||
float4 position_CS;
|
||||
float2 texCoords;
|
||||
float3 vertexColor;
|
||||
float4 position_CS : SV_Position;
|
||||
float3 position_TS : POSITION0;
|
||||
float3 viewDir_TS : POSITION1;
|
||||
float3 normal_WS : NORMAL0;
|
||||
float3 tangent_WS : TANGENT0;
|
||||
float3 biTangent_WS : TANGENT1;
|
||||
float3 position_WS : POSITION2;
|
||||
float2 texCoords : TEXCOORD0;
|
||||
float3 vertexColor : COLOR0;
|
||||
MaterialParameter getMaterialParameter()
|
||||
{
|
||||
MaterialParameter result;
|
||||
|
||||
Reference in New Issue
Block a user