Add instanced rendering for toping bevels: dedicated shaders (voxelTopingVS/PS), PSO, GPU buffers (t4 vertices, t5 instances), per-group DrawInstanced in a separate render pass with LoadOp::LOAD. Fix inverted face winding (emitTri auto-winding condition flipped for CW front-facing), slope normals (use inward direction not outward), and PS lighting (negate sunDirection like voxelPS). Update CLAUDE.md with Phase 4.1/4.2 documentation.
53 lines
1.6 KiB
HLSL
53 lines
1.6 KiB
HLSL
// BVLE Voxels - Toping Vertex Shader (Phase 4.2)
|
|
// Instanced vertex pulling: reads mesh vertices from t4, instance positions from t5.
|
|
// Push constants carry per-draw-group offsets.
|
|
|
|
#include "voxelCommon.hlsli"
|
|
|
|
// Toping mesh vertex (must match C++ TopingVertex, 24 bytes)
|
|
struct TopingVtx {
|
|
float3 position; // local to voxel [0,1]^3
|
|
float3 normal;
|
|
};
|
|
|
|
// Toping instance (just the world position, 12 bytes)
|
|
struct TopingInst {
|
|
float3 worldPos;
|
|
};
|
|
|
|
StructuredBuffer<TopingVtx> topingVertices : register(t4);
|
|
StructuredBuffer<TopingInst> topingInstances : register(t5);
|
|
|
|
// Push constants — repurposed fields for toping draws:
|
|
// chunkIndex → vertexOffset (into t4)
|
|
// quadOffset → instanceOffset (into t5)
|
|
// flags → materialID
|
|
struct TopingPush {
|
|
uint vertexOffset;
|
|
uint instanceOffset;
|
|
uint materialID;
|
|
uint pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8;
|
|
};
|
|
[[vk::push_constant]] ConstantBuffer<TopingPush> push : register(b999);
|
|
|
|
struct VSOutput {
|
|
float4 position : SV_POSITION;
|
|
float3 worldPos : WORLDPOS;
|
|
float3 normal : NORMAL;
|
|
nointerpolation uint materialID : MATERIALID;
|
|
};
|
|
|
|
[RootSignature(VOXEL_ROOTSIG)]
|
|
VSOutput main(uint vertexID : SV_VertexID, uint instanceID : SV_InstanceID) {
|
|
TopingVtx vtx = topingVertices[push.vertexOffset + vertexID];
|
|
TopingInst inst = topingInstances[push.instanceOffset + instanceID];
|
|
|
|
float3 worldPos = inst.worldPos + vtx.position;
|
|
|
|
VSOutput output;
|
|
output.position = mul(viewProjection, float4(worldPos, 1.0));
|
|
output.worldPos = worldPos;
|
|
output.normal = vtx.normal;
|
|
output.materialID = push.materialID;
|
|
return output;
|
|
}
|