Skip to content

Commit 92029c5

Browse files
Detect reflective material
1 parent f4e5bff commit 92029c5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

attachments/38_ray_tracing.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct UniformBufferObject {
9191

9292
struct PushConstant {
9393
uint32_t materialIndex;
94+
uint32_t reflective;
9495
};
9596

9697
class HelloTriangleApplication {
@@ -180,6 +181,7 @@ class HelloTriangleApplication {
180181
uint32_t firstVertex;
181182
uint32_t maxVertex;
182183
bool alphaCut;
184+
bool reflective;
183185
};
184186
std::vector<SubMesh> submeshes;
185187
std::vector<tinyobj::material_t> materials;
@@ -913,14 +915,16 @@ class HelloTriangleApplication {
913915

914916
// Note that this is only valid for this particular MODEL_PATH
915917
bool alphaCut = (shape.name.find("nettle_plant") != std::string::npos);
918+
bool reflective = (shape.name.find("table") != std::string::npos);
916919

917920
submeshes.push_back({
918921
.indexOffset = startOffset,
919922
.indexCount = indexCount,
920923
.materialID = globalMaterialID,
921924
.firstVertex = 0u,
922925
.maxVertex = localMaxV + 1,
923-
.alphaCut = alphaCut
926+
.alphaCut = alphaCut,
927+
.reflective = reflective
924928
});
925929
}
926930

@@ -1652,7 +1656,7 @@ class HelloTriangleApplication {
16521656

16531657
for (auto& sub : submeshes) {
16541658
uint32_t idx = sub.materialID < 0 ? 0u : static_cast<uint32_t>(sub.materialID);
1655-
commandBuffers[currentFrame].pushConstants<PushConstant>(pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, PushConstant{ .materialIndex = idx });
1659+
commandBuffers[currentFrame].pushConstants<PushConstant>(pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, PushConstant{ .materialIndex = idx, .reflective = sub.reflective });
16561660
commandBuffers[currentFrame].drawIndexed(sub.indexCount, 1, sub.indexOffset, 0, 0);
16571661
}
16581662

attachments/38_ray_tracing.slang

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Texture2D<float4> textures[];
5757

5858
struct PushConstant {
5959
uint materialIndex;
60+
uint reflective;
6061
};
6162
[push_constant]
6263
PushConstant pc;
@@ -134,6 +135,10 @@ float4 fragMain(VSOutput vertIn) : SV_TARGET {
134135
// Alpha test
135136
if (baseColor.a < 0.5) discard;
136137

138+
if (pc.reflective > 0) {
139+
baseColor.rgb = float3(1.0, 0.0, 0.0);
140+
}
141+
137142
bool inShadow = in_shadow(vertIn.worldPos);
138143

139144
// Darken if in shadow

0 commit comments

Comments
 (0)