Skip to content

Commit 11ecec3

Browse files
Add transparency to reflections
1 parent 078c30d commit 11ecec3

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

attachments/38_ray_tracing.slang

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,30 @@ void apply_reflection(float3 P, float3 N, inout float4 baseColor) {
141141
reflectionRayDesc.TMax = 1e4;
142142

143143
// Initialize a ray-query for reflections
144-
RayQuery<RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES |
145-
RAY_FLAG_FORCE_OPAQUE> rq;
146-
let rayFlags = RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES |
147-
RAY_FLAG_FORCE_OPAQUE;
144+
RayQuery<RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES> rq;
145+
let rayFlags = RAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES;
148146

149147
rq.TraceRayInline(accelerationStructure, rayFlags, 0xFF, reflectionRayDesc);
150148

151-
rq.Proceed();
149+
while (rq.Proceed())
150+
{
151+
uint instanceID = rq.CandidateInstanceID();
152+
uint primIndex = rq.CandidatePrimitiveIndex();
153+
154+
float2 uv = intersection_uv(instanceID, primIndex, rq.CandidateTriangleBarycentrics());
155+
156+
uint materialID = instanceLUTBuffer[instanceID].materialID;
157+
float4 intersection_color = textures[materialID].Sample(textureSampler, uv);
158+
159+
if (intersection_color.a < 0.5) {
160+
// If the triangle is transparent, we continue to trace
161+
// to find the next opaque triangle.
162+
} else {
163+
// If we hit an opaque triangle, we stop tracing.
164+
rq.CommitNonOpaqueTriangleHit();
165+
}
166+
167+
}
152168

153169
bool hit = (rq.CommittedStatus() == COMMITTED_TRIANGLE_HIT);
154170

0 commit comments

Comments
 (0)