Skip to content

Commit 33826a7

Browse files
set up for new MIS random variable usage
1 parent ea7214f commit 33826a7

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

examples_tests/42.FragmentShaderPathTracer/common.glsl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,17 @@ layout (constant_id = 1) const int MAX_SAMPLES_LOG2 = 0;
462462

463463
#include <nbl/builtin/glsl/random/xoroshiro.glsl>
464464

465-
vec3 rand3d(in uint protoDimension, in uint _sample, inout nbl_glsl_xoroshiro64star_state_t scramble_state)
465+
mat2x3 rand3d(in uint protoDimension, in uint _sample, inout nbl_glsl_xoroshiro64star_state_t scramble_state)
466466
{
467+
mat2x3 retval;
467468
uint address = bitfieldInsert(protoDimension,_sample,MAX_DEPTH_LOG2,MAX_SAMPLES_LOG2);
468-
uvec3 seqVal = texelFetch(sampleSequence,int(address)).xyz;
469-
seqVal ^= uvec3(nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state));
470-
return vec3(seqVal)*uintBitsToFloat(0x2f800004u);
469+
for (int i=0; i<2u; i++)
470+
{
471+
uvec3 seqVal = texelFetch(sampleSequence,int(address)+i).xyz;
472+
seqVal ^= uvec3(nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state),nbl_glsl_xoroshiro64star(scramble_state));
473+
retval[i] = vec3(seqVal)*uintBitsToFloat(0x2f800004u);
474+
}
475+
return retval;
471476
}
472477

473478
bool traceRay(in ImmutableRay_t _immutable);
@@ -511,7 +516,7 @@ void main()
511516
// apply stochastic reconstruction filter
512517
const float gaussianFilterCutoff = 2.5;
513518
const float truncation = exp(-0.5*gaussianFilterCutoff*gaussianFilterCutoff);
514-
vec2 remappedRand = rand3d(0u,i,scramble_state).xy;
519+
vec2 remappedRand = rand3d(0u,i,scramble_state)[0].xy;
515520
remappedRand.x *= 1.0-truncation;
516521
remappedRand.x += truncation;
517522
tmp.xy += pixOffsetParam*nbl_glsl_BoxMullerTransform(remappedRand,1.5);

examples_tests/42.FragmentShaderPathTracer/litByRectangle.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
287287
rayStack[stackPtr]._immutable.origin = intersection+_sample.L*(doNEE ? maxT:1.0/*kSceneSize*/)*getStartTolerance(depth);
288288
rayStack[stackPtr]._immutable.maxT = maxT;
289289
rayStack[stackPtr]._immutable.direction = _sample.L;
290-
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+1,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
290+
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+2,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
291291
rayStack[stackPtr]._immutable.normalAtOrigin = interaction.isotropic.N;
292292
rayStack[stackPtr]._immutable.wasBSDFAtOrigin = isBSDF;
293293
stackPtr++;

examples_tests/42.FragmentShaderPathTracer/litBySphere.frag

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
155155

156156

157157
const float bsdfGeneratorProbability = BSDFNode_getMISWeight(bsdf);
158-
vec3 epsilon = rand3d(depth,sampleIx,scramble_state);
158+
mat2x3 epsilon = rand3d(depth,sampleIx,scramble_state);
159159

160160
float rcpChoiceProb;
161-
const bool doNEE = nbl_glsl_partitionRandVariable(bsdfGeneratorProbability,epsilon.z,rcpChoiceProb);
161+
const bool doNEE = nbl_glsl_partitionRandVariable(bsdfGeneratorProbability,epsilon[0].z,rcpChoiceProb);
162162

163163

164164
float maxT;
@@ -171,7 +171,7 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
171171
vec3 lightRemainder;
172172
_sample = nbl_glsl_light_generate_and_remainder_and_pdf(
173173
lightRemainder,lightPdf,maxT,
174-
intersection,interaction,epsilon,
174+
intersection,interaction,epsilon[0],
175175
depth
176176
);
177177
throughput *= lightRemainder;
@@ -190,7 +190,7 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
190190
else
191191
{
192192
maxT = FLT_MAX;
193-
_sample = nbl_glsl_bsdf_cos_generate(interaction,epsilon,bsdf,monochromeEta,_cache);
193+
_sample = nbl_glsl_bsdf_cos_generate(interaction,epsilon[0],bsdf,monochromeEta,_cache);
194194
}
195195

196196
// do a cool trick and always compute the bsdf parts this way! (no divergence)
@@ -219,7 +219,7 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
219219
rayStack[stackPtr]._immutable.origin = intersection+_sample.L*(doNEE ? maxT:1.0/*kSceneSize*/)*getStartTolerance(depth);
220220
rayStack[stackPtr]._immutable.maxT = maxT;
221221
rayStack[stackPtr]._immutable.direction = _sample.L;
222-
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+1,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
222+
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+2,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
223223
stackPtr++;
224224
}
225225
}

examples_tests/42.FragmentShaderPathTracer/litByTriangle.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void closestHitProgram(in ImmutableRay_t _immutable, inout nbl_glsl_xoroshiro64s
293293
rayStack[stackPtr]._immutable.origin = intersection+_sample.L*(doNEE ? maxT:1.0/*kSceneSize*/)*getStartTolerance(depth);
294294
rayStack[stackPtr]._immutable.maxT = maxT;
295295
rayStack[stackPtr]._immutable.direction = _sample.L;
296-
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+1,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
296+
rayStack[stackPtr]._immutable.typeDepthSampleIx = bitfieldInsert(sampleIx,depth+2,DEPTH_BITS_OFFSET,DEPTH_BITS_COUNT)|(doNEE ? ANY_HIT_FLAG:0);
297297
rayStack[stackPtr]._immutable.normalAtOrigin = interaction.isotropic.N;
298298
rayStack[stackPtr]._immutable.wasBSDFAtOrigin = isBSDF;
299299
stackPtr++;

examples_tests/42.FragmentShaderPathTracer/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void APIENTRY openGLCBFunc(GLenum source, GLenum type, GLuint id, GLenum severit
146146

147147
struct ShaderParameters
148148
{
149-
const uint32_t MaxDepthLog2 = 3; //5
149+
const uint32_t MaxDepthLog2 = 4; //5
150150
const uint32_t MaxSamplesLog2 = 10; //18
151151
} kShaderParameters;
152152

@@ -261,7 +261,7 @@ int main()
261261
return { gpuPipeline, gpuMeshBuffer };
262262
};
263263

264-
E_LIGHT_GEOMETRY lightGeom = ELG_RECTANGLE;
264+
E_LIGHT_GEOMETRY lightGeom = ELG_SPHERE;
265265
constexpr const char* shaderPaths[] = {"../litBySphere.frag","../litByTriangle.frag","../litByRectangle.frag"};
266266
auto gpuEnvmapResources = createGpuResources(shaderPaths[lightGeom]);
267267
auto gpuEnvmapPipeline = gpuEnvmapResources.first;

0 commit comments

Comments
 (0)