Skip to content

Commit cc84091

Browse files
author
kevyuu
committed
Optimize ray tracing demo occlusion tracing
1 parent 4d1dca4 commit cc84091

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

71_RayTracingPipeline/app_resources/raytrace.rgen.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void main()
8989
rayDesc.TMin = 0.01;
9090
rayDesc.TMax = cLight.outLightDistance;
9191

92-
uint32_t shadowRayFlags = RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_FORCE_NON_OPAQUE | RAY_FLAG_SKIP_CLOSEST_HIT_SHADER;
92+
uint32_t shadowRayFlags = RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH;
9393
OcclusionPayload occlusionPayload;
9494
occlusionPayload.attenuation = 1;
9595
TraceRay(topLevelAS, shadowRayFlags, 0xFF, ERT_OCCLUSION, 0, EMT_OCCLUSION, rayDesc, occlusionPayload);

71_RayTracingPipeline/app_resources/raytrace_shadow.rahit.hlsl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ void main(inout OcclusionPayload payload, in BuiltInTriangleIntersectionAttribut
99
const STriangleGeomInfo geom = vk::RawBufferLoad < STriangleGeomInfo > (pc.triangleGeomInfoBuffer + instID * sizeof(STriangleGeomInfo));
1010
const Material material = unpackMaterial(geom.material);
1111

12-
if (material.isTransparent())
13-
{
14-
payload.attenuation = material.alpha * payload.attenuation;
15-
IgnoreHit();
16-
}
17-
else
18-
{
19-
payload.attenuation = 0;
20-
AcceptHitAndEndSearch();
21-
}
22-
12+
payload.attenuation = material.alpha * payload.attenuation;
13+
IgnoreHit();
2314
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "common.hlsl"
2+
3+
[shader("closesthit")]
4+
void main(inout OcclusionPayload payload, in BuiltInTriangleIntersectionAttributes attribs)
5+
{
6+
payload.attenuation = 0;
7+
}

71_RayTracingPipeline/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
164164
const auto anyHitShaderShadowPayload = loadCompileAndCreateShader("app_resources/raytrace_shadow.rahit.hlsl");
165165
const auto missShader = loadCompileAndCreateShader("app_resources/raytrace.rmiss.hlsl");
166166
const auto shadowMissShader = loadCompileAndCreateShader("app_resources/raytrace_shadow.rmiss.hlsl");
167+
const auto shadowClosestHitShader = loadCompileAndCreateShader("app_resources/raytrace_shadow_triangle.rchit.hlsl");
167168
const auto directionalLightCallShader = loadCompileAndCreateShader("app_resources/light_directional.rcall.hlsl");
168169
const auto pointLightCallShader = loadCompileAndCreateShader("app_resources/light_point.rcall.hlsl");
169170
const auto spotLightCallShader = loadCompileAndCreateShader("app_resources/light_spot.rcall.hlsl");
@@ -324,6 +325,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
324325
RTDS_RAYGEN,
325326
RTDS_MISS,
326327
RTDS_SHADOW_MISS,
328+
RTDS_CLOSEST_HIT_SHADOW,
327329
RTDS_CLOSEST_HIT,
328330
RTDS_SPHERE_CLOSEST_HIT,
329331
RTDS_ANYHIT_PRIMARY,
@@ -339,6 +341,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
339341
shaders[RTDS_RAYGEN] = {.shader = raygenShader.get()};
340342
shaders[RTDS_MISS] = {.shader = missShader.get()};
341343
shaders[RTDS_SHADOW_MISS] = {.shader = shadowMissShader.get()};
344+
shaders[RTDS_CLOSEST_HIT_SHADOW] = { .shader = shadowClosestHitShader.get() };
342345
shaders[RTDS_CLOSEST_HIT] = {.shader = closestHitShader.get()};
343346
shaders[RTDS_SPHERE_CLOSEST_HIT] = {.shader = proceduralClosestHitShader.get()};
344347
shaders[RTDS_ANYHIT_PRIMARY] = {.shader = anyHitShaderColorPayload.get()};
@@ -350,14 +353,15 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
350353

351354
params.layout = pipelineLayout.get();
352355
params.shaders = std::span(shaders);
356+
params.flags = IGPURayTracingPipeline::SCreationParams::FLAGS::NO_NULL_INTERSECTION_SHADERS;
353357

354358
auto& shaderGroups = params.shaderGroups;
355359

356360
shaderGroups.raygen = { .index = RTDS_RAYGEN };
357361

358362
IRayTracingPipelineBase::SGeneralShaderGroup missGroups[EMT_COUNT];
359363
missGroups[EMT_PRIMARY] = { .index = RTDS_MISS };
360-
missGroups[EMT_OCCLUSION] = { .index = RTDS_SHADOW_MISS };
364+
missGroups[EMT_OCCLUSION] = { .index = IGPURayTracingPipeline::SGeneralShaderGroup::Unused };
361365
shaderGroups.misses = missGroups;
362366

363367
auto getHitGroupIndex = [](E_GEOM_TYPE geomType, E_RAY_TYPE rayType)
@@ -370,6 +374,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
370374
.anyHit = RTDS_ANYHIT_PRIMARY,
371375
};
372376
hitGroups[getHitGroupIndex(EGT_TRIANGLES, ERT_OCCLUSION)] = {
377+
.closestHit = RTDS_CLOSEST_HIT_SHADOW,
373378
.anyHit = RTDS_ANYHIT_SHADOW,
374379
};
375380
hitGroups[getHitGroupIndex(EGT_PROCEDURAL, ERT_PRIMARY)] = {
@@ -378,6 +383,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
378383
.intersectionShader = RTDS_INTERSECTION,
379384
};
380385
hitGroups[getHitGroupIndex(EGT_PROCEDURAL, ERT_OCCLUSION)] = {
386+
.closestHit = RTDS_CLOSEST_HIT_SHADOW,
381387
.anyHit = RTDS_ANYHIT_SHADOW,
382388
.intersectionShader = RTDS_INTERSECTION,
383389
};

0 commit comments

Comments
 (0)