Skip to content

Commit

Permalink
Use local hit point to compute normals
Browse files Browse the repository at this point in the history
Requires Visionaray v0.4.2
  • Loading branch information
szellmann committed Jun 30, 2024
1 parent aa3ed4d commit 12dcbcc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 6 additions & 1 deletion DeviceCopyableObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,12 @@ inline hit_record<Ray, primitive<unsigned>> 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;
}

Expand Down
5 changes: 3 additions & 2 deletions renderer/DirectLight_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ 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;
sn = nxfm * sn;

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;
Expand Down
5 changes: 3 additions & 2 deletions renderer/Raycast_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,15 +41,15 @@ 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;
sn = nxfm * sn;

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;
Expand Down

0 comments on commit 12dcbcc

Please sign in to comment.