Skip to content

Commit 8e45c47

Browse files
geometric normals and position derivatives need redoing
1 parent e488450 commit 8e45c47

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ core::smart_refctd_ptr<IGPUImageView> Renderer::createScreenSizedTexture(E_FORMA
622622
return m_driver->createGPUImageView(std::move(viewparams));
623623
}
624624

625+
constexpr uint16_t m_maxDepth = 2u;
626+
constexpr uint16_t m_UNUSED_russianRouletteDepth = 5u;
625627
bool extractIntegratorInfo(const ext::MitsubaLoader::CElementIntegrator& integrator, uint32_t &bxdfSamples, uint32_t &maxNEESamples)
626628
{
627629
using Enum = ext::MitsubaLoader::CElementIntegrator::Type;
@@ -673,7 +675,8 @@ void Renderer::init(const SAssetBundle& meshes, core::smart_refctd_ptr<ICPUBuffe
673675
core::smart_refctd_ptr<IGPUImageView> depthBuffer,visibilityBuffer;
674676
// set up Descriptor Sets
675677
{
676-
// captures m_globalBackendDataDS, creates m_indirectDrawBuffers, sets up m_mdiDrawCalls ranges, creates m_additionalGlobalDS and m_cullDS, sets m_cullPushConstants and m_cullWorkgroups, creates m_perCameraRasterDS
678+
// captures m_globalBackendDataDS, creates m_indirectDrawBuffers, sets up m_mdiDrawCalls ranges
679+
// creates m_additionalGlobalDS and m_cullDS, sets m_cullPushConstants and m_cullWorkgroups, creates m_perCameraRasterDS
677680
auto initData = initSceneObjects(meshes);
678681
{
679682
initSceneNonAreaLights(initData);
@@ -722,7 +725,7 @@ void Renderer::init(const SAssetBundle& meshes, core::smart_refctd_ptr<ICPUBuffe
722725
// see how much we can bump the sample count per raster pass
723726
{
724727
uint32_t sampleMultiplier = 0u;
725-
const auto maxSSBOSize = core::min(m_driver->getMaxSSBOSize(),1024u<<20);
728+
const auto maxSSBOSize = core::min(m_driver->getMaxSSBOSize(),256u<<20);
726729
while (raygenBufferSize<=maxSSBOSize && intersectionBufferSize<=maxSSBOSize) // for AMD && m_maxRaysPerDispatch*WORKGROUP_SIZE<=64<<10))
727730
setRayBufferSizes(++sampleMultiplier);
728731
if (sampleMultiplier==1u)
@@ -774,6 +777,7 @@ void Renderer::init(const SAssetBundle& meshes, core::smart_refctd_ptr<ICPUBuffe
774777
(std::ofstream("runtime_defines.glsl")
775778
<< "#define _NBL_EXT_MITSUBA_LOADER_VT_STORAGE_VIEW_COUNT " << initData.globalMeta->m_global.getVTStorageViewCount() << "\n"
776779
<< initData.globalMeta->m_global.m_materialCompilerGLSL_declarations
780+
<< "#define MAX_PATH_DEPTH " << m_maxDepth << "\n"
777781
<< "#ifndef MAX_RAYS_GENERATED\n"
778782
<< "# define MAX_RAYS_GENERATED " << m_staticViewData.samplesPerPixelPerDispatch << "\n"
779783
<< "#endif\n"
@@ -1135,8 +1139,6 @@ void Renderer::deinit()
11351139
// one day it will just work like that
11361140
//#include <nbl/builtin/glsl/sampling/box_muller_transform.glsl>
11371141

1138-
constexpr uint16_t m_maxDepth = 2u; // TODO: = 5u
1139-
constexpr uint16_t m_UNUSED_russianRouletteDepth = 5u;
11401142
void Renderer::render(nbl::ITimer* timer)
11411143
{
11421144
if (m_cullPushConstants.maxGlobalInstanceCount==0u)

examples_tests/22.RaytracedAO/closestHit.comp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,22 @@ void main()
6868
const nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(InstData.data[batchInstanceGUID].material,frontfacing);
6969
emissive = nbl_glsl_MC_oriented_material_t_getEmissive(material);
7070

71-
const uint MAX_PATH_DEPTH = 2u; // TODO: move to push constant or UBO
72-
const bool _continue = vertex_depth!=MAX_PATH_DEPTH && ray.maxT==FLT_INF; // last vertex or was a NEE path
71+
const bool _continue = vertex_depth!=MAX_PATH_DEPTH && ray.maxT==FLT_MAX; // last vertex or was a NEE path
7372
if (_continue)
7473
{
7574
// if we ever support spatially varying emissive, we'll need to hoist barycentric computation and UV fetching to the position fetching
7675
const vec2 compactBary = intersection.uvwt.xy;
7776

7877
const mat2 dBarydScreen = mat2(0.0); // TODO: Covariance Rendering
7978
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(
80-
compactBary,indices,batchInstanceGUID,material,dBarydScreen,outPixelLocation,vertex_depth_mod_2
79+
compactBary,indices,batchInstanceGUID,material,dBarydScreen,outPixelLocation,vertex_depth
8180
);
8281

8382
const vec3 hitWorldPos = dPdBary*compactBary.xy+last_vx_pos;
8483

8584
generate_next_rays(
86-
MAX_RAYS_GENERATED,material,frontfacing,vertex_depth_mod_2,
87-
scramble_start_state,sampleID,outPixelLocation,hitWorldPos,normalize(geomNormal),throughput
85+
MAX_RAYS_GENERATED,material,frontfacing,vertex_depth,
86+
scramble_start_state,sampleID,outPixelLocation,hitWorldPos,geomNormal,throughput
8887
);
8988
}
9089
}

examples_tests/22.RaytracedAO/main.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ int main()
213213

214214

215215
auto driver = device->getVideoDriver();
216-
// temporary workaround for Renderdoc v 1.14 bug
217-
device->run();
218-
driver->beginScene(false, false);
219-
driver->endScene();
220-
glFinish();
221216

222217

223218
core::smart_refctd_ptr<Renderer> renderer = core::make_smart_refctd_ptr<Renderer>(driver,device->getAssetManager(),smgr);

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ void main()
7474

7575
// generate rays
7676
const uint sampleID = bitfieldExtract(pc.cummon.samplesComputed_depth,0,16);
77-
const vec3 geomNormal = normalize(cross(dPdBary[0],dPdBary[1]));
77+
const vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
78+
const uint vertex_depth = 1u;
7879
generate_next_rays(
79-
staticViewData.samplesPerPixelPerDispatch,material,frontfacing,vertex_depth_mod_2,
80+
staticViewData.samplesPerPixelPerDispatch,material,frontfacing,vertex_depth,
8081
scramble_start_state,sampleID,outPixelLocation,hitWorldPos,geomNormal,vec3(1.0)
8182
);
8283
}

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,22 @@ mat2 nbl_glsl_perturbNormal_dUVdSomething()
146146
#include <nbl/builtin/glsl/material_compiler/common.glsl>
147147

148148

149-
vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint _sample)
149+
vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in int _sample, in int depth)
150150
{
151-
uvec3 seqVal = texelFetch(sampleSequence,int(_sample)).xyz; // TODO: add depth param!!!
151+
uvec3 seqVal = texelFetch(sampleSequence,int(_sample)+(depth-1)*MAX_ACCUMULATED_SAMPLES).xyz;
152152
seqVal ^= uvec3(nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state));
153153
return vec3(seqVal)*uintBitsToFloat(0x2f800004u);
154154
}
155155

156156
void gen_sample_ray(
157157
out float maxT, out vec3 direction, out vec3 throughput,
158-
inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID,
158+
inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID, in uint depth,
159159
in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
160160
)
161161
{
162162
maxT = FLT_MAX;
163163

164-
vec3 rand = rand3d(scramble_state,sampleID);
164+
vec3 rand = rand3d(scramble_state,int(sampleID),int(depth));
165165

166166
float pdf;
167167
nbl_glsl_LightSample s;
@@ -213,7 +213,7 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
213213
}
214214

215215
void generate_next_rays(
216-
in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth_mod_2,
216+
in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth,
217217
in nbl_glsl_xoroshiro64star_state_t scramble_start_state, in uint sampleID, in uvec2 outPixelLocation,
218218
in vec3 origin, vec3 geomNormal, in vec3 prevThroughput)
219219
{
@@ -228,7 +228,8 @@ void generate_next_rays(
228228
const nbl_glsl_MC_instr_stream_t nps = nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(material);
229229
nbl_glsl_MC_runNormalPrecompStream(nps,precomputed);
230230
#endif
231-
231+
232+
const uint vertex_depth_mod_2 = vertex_depth&0x1u;
232233
const uint vertex_depth_mod_2_inv = vertex_depth_mod_2^0x1u;
233234
// prepare rays
234235
uint raysToAllocate = 0u;
@@ -237,9 +238,10 @@ void generate_next_rays(
237238
{
238239
nbl_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
239240
// TODO: When generating NEE rays, advance the dimension, NOT the sampleID
240-
gen_sample_ray(maxT[i],direction[i],nextThroughput[i],scramble_state,sampleID+i,precomputed,gcs,rnps);
241-
if (i==0u)
242-
imageStore(scramblebuf,ivec3(outPixelLocation,vertex_depth_mod_2_inv),uvec4(scramble_state,0u,0u));
241+
gen_sample_ray(maxT[i],direction[i],nextThroughput[i],scramble_state,sampleID+i,vertex_depth,precomputed,gcs,rnps);
242+
// TODO: bad idea, invent something else
243+
// if (i==0u)
244+
// imageStore(scramblebuf,ivec3(outPixelLocation,vertex_depth_mod_2_inv),uvec4(scramble_state,0u,0u));
243245
nextThroughput[i] *= prevThroughput;
244246
if (any(greaterThan(nextThroughput[i],vec3(FLT_MIN))))
245247
raysToAllocate++;
@@ -256,8 +258,8 @@ void generate_next_rays(
256258
{
257259
nbl_glsl_ext_RadeonRays_ray newRay;
258260
// TODO: improve ray offsets
259-
const float err = frontfacing ? (1.0/96):(-1.0/96);
260-
newRay.origin = origin+geomNormal*err;
261+
const float err = 1.f/96.f;
262+
newRay.origin = origin+/*geomNormal/max(max(geomNormal.x,geomNormal.y),geomNormal.z)*sign(dot(geomNormal,direction[i]))*/direction[i]*err;
261263
newRay.maxT = maxT[i];
262264
newRay.direction = direction[i];
263265
newRay.time = packOutPixelLocation(outPixelLocation);

0 commit comments

Comments
 (0)