From d8f3adf1b81fa449179a48e053c2f3ed7df0a57a Mon Sep 17 00:00:00 2001 From: iaomw Date: Fri, 5 Jan 2024 21:53:54 +0800 Subject: [PATCH] Improve occlusion for light --- zenovis/xinxinoptix/Light.cu | 5 +++++ zenovis/xinxinoptix/Light.h | 6 ++++++ zenovis/xinxinoptix/TraceStuff.h | 2 ++ 3 files changed, 13 insertions(+) diff --git a/zenovis/xinxinoptix/Light.cu b/zenovis/xinxinoptix/Light.cu index 8a60742dcb..a2e705cf69 100644 --- a/zenovis/xinxinoptix/Light.cu +++ b/zenovis/xinxinoptix/Light.cu @@ -262,6 +262,11 @@ extern "C" __global__ void __anyhit__shadow_cutout() light_index = rect_idx + params.firstRectLightIdx; } + if (light_index == prd->lightIdx) { + //printf("maxDistance = %f tmax = %f \n", prd->maxDistance, optixGetRayTmax()); + ignore = true; + } + if (ignore) { optixIgnoreIntersection(); return; diff --git a/zenovis/xinxinoptix/Light.h b/zenovis/xinxinoptix/Light.h index 6df2d8a766..029af843e5 100644 --- a/zenovis/xinxinoptix/Light.h +++ b/zenovis/xinxinoptix/Light.h @@ -386,6 +386,10 @@ void DirectLighting(RadiancePRD *prd, ShadowPRD& shadowPRD, const float3& shadin } } + lsr.p -= params.cam.eye; + //lsr.p = rtgems::offset_ray(lsr.p, lsr.n); + lsr.dist = length(lsr.p - shadowPRD.origin); + if (!cihouMaxDistanceContinue(lsr, light)) { return; } float3 emission = cihouLightEmission(lsr, light, prd->depth); @@ -402,7 +406,9 @@ void DirectLighting(RadiancePRD *prd, ShadowPRD& shadowPRD, const float3& shadin if (lsr.NoL > _FLT_EPL_ && lsr.PDF > _FLT_EPL_) { + shadowPRD.lightIdx = lighIdx; shadowPRD.maxDistance = lsr.dist; + traceOcclusion(params.handle, shadowPRD.origin, lsr.dir, 0, lsr.dist, &shadowPRD); light_attenuation = shadowPRD.attanuation; diff --git a/zenovis/xinxinoptix/TraceStuff.h b/zenovis/xinxinoptix/TraceStuff.h index 2ef6b098f9..034a2c7d62 100644 --- a/zenovis/xinxinoptix/TraceStuff.h +++ b/zenovis/xinxinoptix/TraceStuff.h @@ -54,6 +54,8 @@ struct VolumePRD { struct ShadowPRD { bool test_distance; float maxDistance; + uint32_t lightIdx = UINT_MAX; + float3 origin; uint32_t seed; float3 attanuation;