Skip to content

Commit 5103cd2

Browse files
get it to compile again (and try bigger path depths)
1 parent 683b9e4 commit 5103cd2

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ core::smart_refctd_ptr<IGPUImageView> Renderer::createScreenSizedTexture(E_FORMA
651651
return m_driver->createGPUImageView(std::move(viewparams));
652652
}
653653

654-
constexpr uint16_t m_maxDepth = 6u;
654+
constexpr uint16_t m_maxDepth = 8u;
655655
constexpr uint16_t m_UNUSED_russianRouletteDepth = 5u;
656656
bool extractIntegratorInfo(const ext::MitsubaLoader::CElementIntegrator& integrator, uint32_t &bxdfSamples, uint32_t &maxNEESamples)
657657
{

examples_tests/22.RaytracedAO/Renderer.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
4747
return framesDispatched*samplesPerDispatch;
4848
}
4949

50-
50+
//! Brief guideline to good path depth limits
51+
// Want to see stuff with indirect lighting on the other side of a pane of glass
52+
// 5 = glass frontface->glass backface->diffuse surface->diffuse surface->light
53+
// Want to see through a glass box, vase, or office
54+
// 7 = glass frontface->glass backface->glass frontface->glass backface->diffuse surface->diffuse surface->light
55+
// pick higher numbers for better GI and less bias
56+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxPathDepth = 8u;
5157
_NBL_STATIC_INLINE_CONSTEXPR uint32_t RandomDimsPerPathVertex = 3u;
52-
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxDimensions = RandomDimsPerPathVertex*5u;
58+
// one less because the first path vertex is rasterized
59+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t MaxDimensions = RandomDimsPerPathVertex*(MaxPathDepth-1u);
5360
static const float AntiAliasingSequence[4096][2];
5461
protected:
5562
~Renderer();

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool record_emission_common(out vec3 acc, in uvec3 accumulationLocation, vec3 em
8888
emissive -= acc;
8989
emissive *= pc.cummon.rcpFramesDispatched;
9090

91-
const bool anyChange = any(greaterThan(abs(emissive),vec3(FLT_MIN)));
91+
const bool anyChange = any(greaterThan(abs(emissive),vec3(nbl_glsl_FLT_MIN)));
9292
acc += emissive;
9393
return anyChange;
9494
}
@@ -118,6 +118,29 @@ vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
118118
return normalizedN;
119119
}
120120

121+
122+
123+
124+
vec3 nbl_glsl_robust_ray_origin_fastest(in vec3 origin, in vec3 direction, float error, vec3 normal)
125+
{
126+
// flip it in the correct direction
127+
error = uintBitsToFloat(floatBitsToUint(error)^(floatBitsToUint(dot(normal,direction))&0x80000000u));
128+
return origin+normal*error;
129+
}
130+
vec3 nbl_glsl_robust_ray_origin_fast(in vec3 origin, in vec3 direction, in vec3 error, in vec3 normal)
131+
{
132+
// anticipate that the error could have increased from manipulation
133+
return nbl_glsl_robust_ray_origin_fastest(origin,direction,error.x+error.y+error.z,normal);
134+
}
135+
vec3 nbl_glsl_robust_ray_origin(in vec3 origin, in vec3 direction, in vec3 error, in vec3 normal)
136+
{
137+
const float d = dot(abs(normal),error);
138+
// anticipate that the error could have increased from manipulation
139+
return nbl_glsl_robust_ray_origin_fastest(origin,direction,d,normal);
140+
}
141+
142+
143+
121144
#include <nbl/builtin/glsl/barycentric/utils.glsl>
122145
mat2x3 dPdBary;
123146
vec3 load_positions(in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
@@ -128,7 +151,11 @@ vec3 load_positions(in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_da
128151
nbl_glsl_fetchVtxPos(indices[2],batchInstanceData)
129152
);
130153
const mat4x3 tform = batchInstanceData.tform;
131-
positions = mat3(tform)*positions;
154+
mat3 error;
155+
// for when we quantize positions to RGB21_UNORM
156+
//const float quantizationError = nbl_glsl_numeric_limits_float_epsilon(1u);
157+
positions = nbl_glsl_mul_with_bounds(error,mat3(tform),positions/*,positions*quantizationError*/);
158+
//
132159
dPdBary = mat2x3(positions[0]-positions[2],positions[1]-positions[2]);
133160
return positions[2]+tform[3];
134161
}
@@ -160,7 +187,7 @@ void gen_sample_ray(
160187
in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
161188
)
162189
{
163-
maxT = FLT_MAX;
190+
maxT = nbl_glsl_FLT_MAX;
164191

165192
vec3 rand = rand3d(scramble_state,int(sampleID),int(depth));
166193

@@ -254,24 +281,22 @@ for (uint i=1u; i!=vertex_depth; i++)
254281
// if (i==0u)
255282
// imageStore(scramblebuf,ivec3(outPixelLocation,vertex_depth_mod_2_inv),uvec4(scramble_state,0u,0u));
256283
nextThroughput[i] *= prevThroughput;
257-
if (any(greaterThan(nextThroughput[i],vec3(FLT_MIN))))
284+
if (any(greaterThan(nextThroughput[i],vec3(nbl_glsl_FLT_MIN))))
258285
raysToAllocate++;
259286
else
260287
maxT[i] = 0.f;
261288
}
262289
// TODO: investigate workgroup reductions here
263290
const uint baseOutputID = atomicAdd(rayCount[pc.cummon.rayCountWriteIx],raysToAllocate);
264291

265-
// TODO: improve ray offset (maybe using smooth normal wouldn't be a sin)
266-
vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
267-
const vec3 absGeomNormal = abs(geomNormal);
268-
geomNormal /= max(max(absGeomNormal.x,absGeomNormal.y),max(absGeomNormal.z,0.001f))*64.f;
292+
// TODO: improve
293+
const vec3 error = vec3(0.0001f);// abs(origin)* uintBitsToFloat(0x35480005);
269294
uint offset = 0u;
270295
for (uint i=0u; i<maxRaysToGen; i++)
271296
if (maxT[i]!=0.f)
272297
{
273298
nbl_glsl_ext_RadeonRays_ray newRay;
274-
newRay.origin = origin+uintBitsToFloat(floatBitsToUint(geomNormal) ^ floatBitsToUint(dot(geomNormal, direction[i])) & 0x80000000u);
299+
newRay.origin = origin+direction[i]*0.002;// nbl_glsl_robust_ray_origin(origin, direction[i], error, normalizedN);
275300
newRay.maxT = maxT[i];
276301
newRay.direction = direction[i];
277302
newRay.time = packOutPixelLocation(outPixelLocation);

0 commit comments

Comments
 (0)