Skip to content

Commit 0b30462

Browse files
author
kevyuu
committed
Fix example 71 normal computation for more geometry
1 parent 01c2b69 commit 0b30462

File tree

1 file changed

+27
-53
lines changed

1 file changed

+27
-53
lines changed

71_RayTracingPipeline/app_resources/raytrace.rchit.hlsl

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,60 +40,34 @@ float32_t3 fetchVertexNormal(int instID, int primID, STriangleGeomInfo geom, flo
4040
const uint64_t normalVertexBufferAddress = geom.normalBufferAddress;
4141
float3 n0, n1, n2;
4242

43-
// TODO(kevin): Currently this will work correctly both for cubes and rectangle, which are the only triangles geometry that is used in this example. Need to implement other geometry
44-
uint32_t v0 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i0 * 4);
45-
uint32_t v1 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i1 * 4);
46-
uint32_t v2 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i2 * 4);
47-
48-
49-
n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz);
50-
n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz);
51-
n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz);
52-
53-
// switch (objType)
54-
// {
55-
// case OT_CUBE:
56-
// {
57-
// // TODO(kevin): Don't hardcode the normal stride in hlsl
58-
// uint32_t v0 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i0 * 4);
59-
// uint32_t v1 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i1 * 4);
60-
// uint32_t v2 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i2 * 4);
61-
//
62-
// n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz);
63-
// n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz);
64-
// n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz);
65-
// }
66-
// break;
67-
// case OT_SPHERE:
68-
// case OT_CYLINDER:
69-
// case OT_ARROW:
70-
// case OT_CONE:
71-
// {
72-
// // TODO(kevin): Fix this logic. Don't use vertex stride since nomral is separated from position
73-
// uint32_t v0 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i0 * vertexStride);
74-
// uint32_t v1 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i1 * vertexStride);
75-
// uint32_t v2 = vk::RawBufferLoad < uint32_t > (normalVertexBufferAddress + i2 * vertexStride);
76-
//
77-
// n0 = normalize(unpackNormals3x10(v0));
78-
// n1 = normalize(unpackNormals3x10(v1));
79-
// n2 = normalize(unpackNormals3x10(v2));
80-
// }
81-
// break;
82-
// case OT_RECTANGLE:
83-
// case OT_DISK:
84-
// case OT_ICOSPHERE:
85-
// default:
86-
// {
87-
// // TODO(kevin): Don't hardcode the normal stride in hlsl
88-
// n0 = vk::RawBufferLoad < float3 > (normalVertexBufferAddress + i0 * 4);
89-
// n1 = vk::RawBufferLoad < float3 > (normalVertexBufferAddress + i1 * 4);
90-
// n2 = vk::RawBufferLoad < float3 > (normalVertexBufferAddress + i2 * 4);
91-
// }
92-
// }
43+
float3 n0, n1, n2;
44+
switch (objType)
45+
{
46+
case OT_CUBE:
47+
case OT_SPHERE:
48+
case OT_RECTANGLE:
49+
case OT_CYLINDER:
50+
//case OT_ARROW:
51+
case OT_CONE:
52+
{
53+
// TODO: document why the alignment is 2 here and nowhere else? isnt the `vertexStride` aligned to more than 2 anyway?
54+
uint32_t v0 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + i0 * 4);
55+
uint32_t v1 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + i1 * 4);
56+
uint32_t v2 = vk::RawBufferLoad<uint32_t>(normalBufferAddress + i2 * 4);
9357

94-
// n0 = float3(0, 1, 0);
95-
// n1 = float3(0, 1, 0);
96-
// n2 = float3(0, 1, 0);
58+
n0 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v0).xyz);
59+
n1 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v1).xyz);
60+
n2 = normalize(nbl::hlsl::spirv::unpackSnorm4x8(v2).xyz);
61+
}
62+
break;
63+
case OT_ICOSPHERE:
64+
default:
65+
{
66+
n0 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + i0 * 12));
67+
n1 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + i1 * 12));
68+
n2 = normalize(vk::RawBufferLoad<float3>(normalBufferAddress + i2 * 12));
69+
}
70+
}
9771

9872
float3 barycentrics = float3(0.0, bary);
9973
barycentrics.x = 1.0 - barycentrics.y - barycentrics.z;

0 commit comments

Comments
 (0)