diff --git a/CMakeLists.txt b/CMakeLists.txt index f100b92a..56e77d07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ include(GNUInstallDirs) # note: we're often tracking the most recent changes from ANARI-SDK # (on branch "next_release") find_package(anari 0.10.0 REQUIRED) -find_package(visionaray 0.3.5 REQUIRED) +find_package(visionaray 0.4.2 REQUIRED) option(ANARI_VISIONARAY_ENABLE_CUDA "Compile the CUDA device" OFF) set(cuda ${ANARI_VISIONARAY_ENABLE_CUDA}) diff --git a/DeviceCopyableObjects.h b/DeviceCopyableObjects.h index 6bc68c57..ceaefc1d 100644 --- a/DeviceCopyableObjects.h +++ b/DeviceCopyableObjects.h @@ -1289,7 +1289,12 @@ inline hit_record> intersect( xfmRay.dir = affineInv * xfmRay.dir; auto hr = intersect(xfmRay,bls.theBVH); - hr.inst_id = hr.hit ? bls.instID : ~0u; + if (hr.hit) { + hr.isect_pos = xfmRay.ori + hr.t * xfmRay.dir; + hr.inst_id = bls.instID; + } else { + hr.inst_id = ~0u; + } return hr; } diff --git a/renderer/DirectLight_impl.cpp b/renderer/DirectLight_impl.cpp index 0449a705..9faac606 100644 --- a/renderer/DirectLight_impl.cpp +++ b/renderer/DirectLight_impl.cpp @@ -159,7 +159,8 @@ bool shade(ScreenSample &ss, Ray &ray, unsigned worldID, viewDir = -ray.dir; - getNormals(geom, hr.prim_id, hitPos, uv, gn, sn); + float3 localHitPos = hr.isect_pos; + getNormals(geom, hr.prim_id, localHitPos, uv, gn, sn); mat3 nxfm = getNormalTransform(inst, ray); gn = nxfm * gn; @@ -167,7 +168,7 @@ bool shade(ScreenSample &ss, Ray &ray, unsigned worldID, sn = faceforward(sn, viewDir, gn); - float4 tng4 = getTangent(geom, hr.prim_id, hitPos, uv); + float4 tng4 = getTangent(geom, hr.prim_id, localHitPos, uv); if (length(sn) > 0.f && length(tng4.xyz()) > 0.f) { tng = tng4.xyz(); btng = cross(sn, tng) * tng4.w; diff --git a/renderer/Raycast_impl.cpp b/renderer/Raycast_impl.cpp index a5e62f08..38d1bdb0 100644 --- a/renderer/Raycast_impl.cpp +++ b/renderer/Raycast_impl.cpp @@ -32,6 +32,7 @@ inline PixelSample renderSample(ScreenSample &ss, Ray ray, unsigned worldID, const auto &mat = onDevice.materials[group.materials[hr.geom_id]]; vec3f hitPos = ray.ori + hr.t * ray.dir; + vec3f localHitPos = hr.isect_pos; vec2f uv{hr.u,hr.v}; vec3f gn, sn; @@ -40,7 +41,7 @@ inline PixelSample renderSample(ScreenSample &ss, Ray ray, unsigned worldID, attribs[i] = getAttribute(geom, (dco::Attribute)i, hr.prim_id, uv); } - getNormals(geom, hr.prim_id, hitPos, uv, gn, sn); + getNormals(geom, hr.prim_id, localHitPos, uv, gn, sn); mat3 nxfm = getNormalTransform(inst, ray); gn = nxfm * gn; @@ -48,7 +49,7 @@ inline PixelSample renderSample(ScreenSample &ss, Ray ray, unsigned worldID, vec3f tng{0.f}; vec3f btng{0.f}; - float4 tng4 = getTangent(geom, hr.prim_id, hitPos, uv); + float4 tng4 = getTangent(geom, hr.prim_id, localHitPos, uv); if (length(sn) > 0.f && length(tng4.xyz()) > 0.f) { tng = tng4.xyz(); btng = cross(sn, tng) * tng4.w;