Skip to content

Commit f7ed080

Browse files
fix detection of double-facedness in raytracer
1 parent 8d50d4b commit f7ed080

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

examples_tests/22.RaytracedAO/closestHit.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void main()
6666
// positions
6767
const vec3 last_vx_pos = load_positions(indices,batchInstanceData);
6868
const vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
69-
const bool frontfacing = dot(geomNormal,normalizedV)>0.f;
69+
const bool frontfacing = bool((batchInstanceData.determinantSignBit^floatBitsToUint(dot(geomNormal,normalizedV)))&0x80000000u);
7070

7171
// get material
7272
const nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(batchInstanceData.material,frontfacing);

examples_tests/22.RaytracedAO/fillVisBuffer.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main()
2929
vec2 bary = nbl_glsl_barycentric_frag_get();
3030

3131
const int triangleIDBitcount = findMSB(MAX_TRIANGLES_IN_BATCH-1)+1;
32-
frontFacingTriangleIDDrawID_unorm16Bary_dBarydScreenHalf2x2[0] = bitfieldInsert(gl_PrimitiveID,BackfacingBit_BatchInstanceGUID^(gl_FrontFacing ? 0x0u:0x80000000u),triangleIDBitcount,32-triangleIDBitcount);
32+
frontFacingTriangleIDDrawID_unorm16Bary_dBarydScreenHalf2x2[0] = bitfieldInsert(BackfacingBit_BatchInstanceGUID,gl_PrimitiveID,31-triangleIDBitcount,triangleIDBitcount)^(gl_FrontFacing ? 0x0u:0x80000000u);
3333
frontFacingTriangleIDDrawID_unorm16Bary_dBarydScreenHalf2x2[1] = packUnorm2x16(bary);
3434
frontFacingTriangleIDDrawID_unorm16Bary_dBarydScreenHalf2x2[2] = packHalf2x16(dFdx(bary));
3535
frontFacingTriangleIDDrawID_unorm16Bary_dBarydScreenHalf2x2[3] = packHalf2x16(dFdy(bary));

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void main()
3737
// vis buffer decode
3838
const bool frontfacing = !bool(visBuffer[0]&0x80000000u);
3939
const int triangleIDBitcount = findMSB(MAX_TRIANGLES_IN_BATCH-1)+1;
40-
const uint batchInstanceGUID = bitfieldExtract(visBuffer[0],triangleIDBitcount,31-triangleIDBitcount);
41-
const uint triangleID = bitfieldExtract(visBuffer[0],0,triangleIDBitcount);
40+
const uint triangleID = bitfieldExtract(visBuffer[0],31-triangleIDBitcount,triangleIDBitcount);
41+
const uint batchInstanceGUID = bitfieldExtract(visBuffer[0],0,31-triangleIDBitcount);
4242
const vec2 compactBary = unpackUnorm2x16(visBuffer[1]);
4343
#ifdef TEX_PREFETCH_STREAM
4444
const mat2 dBarydScreen = mat2(unpackHalf2x16(visBuffer[2]),unpackHalf2x16(visBuffer[3]));

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ for (uint i=1u; i!=vertex_depth; i++)
265265
// TODO: improve ray offset (maybe using smooth normal wouldn't be a sin)
266266
vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
267267
const vec3 absGeomNormal = abs(geomNormal);
268-
geomNormal /= max(max(absGeomNormal.x,absGeomNormal.y),max(absGeomNormal.z,0.001f))*96.f;
268+
geomNormal /= max(max(absGeomNormal.x,absGeomNormal.y),max(absGeomNormal.z,0.001f))*32.f;
269269
uint offset = 0u;
270270
for (uint i=0u; i<maxRaysToGen; i++)
271271
if (maxT[i]!=0.f)

0 commit comments

Comments
 (0)