@@ -35,11 +35,11 @@ layout(set = 2, binding = 1) uniform sampler2D envMap;
35
35
layout(set = 2, binding = 2) uniform usamplerBuffer sampleSequence;
36
36
layout(set = 2, binding = 3) uniform usampler2D scramblebuf;
37
37
38
- vec2 rand2d (in uint _sample, inout irr_glsl_xoroshiro64star_state_t scramble_state)
38
+ vec3 rand3d (in uint _sample, inout irr_glsl_xoroshiro64star_state_t scramble_state)
39
39
{
40
- uvec2 seqVal = texelFetch(sampleSequence,int(_sample)).xy ;
41
- seqVal ^= uvec2( irr_glsl_xoroshiro64star(scramble_state),irr_glsl_xoroshiro64star(scramble_state));
42
- return vec2 (seqVal)*uintBitsToFloat(0x2f800004u);
40
+ uvec3 seqVal = texelFetch(sampleSequence,int(_sample)).xyz ;
41
+ seqVal ^= uvec3(irr_glsl_xoroshiro64star(scramble_state), irr_glsl_xoroshiro64star(scramble_state),irr_glsl_xoroshiro64star(scramble_state));
42
+ return vec3 (seqVal)*uintBitsToFloat(0x2f800004u);
43
43
}
44
44
45
45
vec2 SampleSphericalMap(in vec3 v)
@@ -50,7 +50,7 @@ vec2 SampleSphericalMap(in vec3 v)
50
50
return uv;
51
51
}
52
52
53
- vec3 irr_computeLighting(inout irr_glsl_IsotropicViewSurfaceInteraction out_interaction, in mat2 dUV)
53
+ vec3 irr_computeLighting(inout irr_glsl_IsotropicViewSurfaceInteraction out_interaction, in mat2 dUV, in MC_precomputed_t precomp )
54
54
{
55
55
irr_glsl_xoroshiro64star_state_t scramble_start_state = textureLod(scramblebuf,gl_FragCoord.xy/VIEWPORT_SZ,0).rg;
56
56
@@ -59,32 +59,30 @@ vec3 irr_computeLighting(inout irr_glsl_IsotropicViewSurfaceInteraction out_inte
59
59
vec3 color = vec3(0.0);
60
60
61
61
#ifdef USE_ENVMAP
62
- instr_stream_t gcs = getGenChoiceStream();
62
+ instr_stream_t gcs = getGenChoiceStream(precomp);
63
+ instr_stream_t rnps = getRemAndPdfStream(precomp);
63
64
for (int i = 0; i < SAMPLE_COUNT; ++i)
64
65
{
65
66
irr_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
66
67
67
- instr_stream_t gcs = getGenChoiceStream();
68
- instr_stream_t rnps = getRemAndPdfStream();
69
-
70
- vec2 rand = rand2d(i,scramble_state);//TODO has to be 3d
68
+ vec3 rand = rand3d(i,scramble_state);
71
69
float pdf;
72
- runGenerateAndRemainderStream(gcs, rnps, rand, pdf);
70
+ irr_glsl_LightSample s;
71
+ vec3 rem = runGenerateAndRemainderStream(precomp, gcs, rnps, rand, pdf, s);
73
72
74
- vec2 uv = SampleSphericalMap(L);
73
+ vec2 uv = SampleSphericalMap(s. L);
75
74
color += rem*textureLod(envMap, uv, 0.0).xyz;
76
75
}
77
76
color /= float(SAMPLE_COUNT);
78
77
#endif
79
78
80
- irr_glsl_BSDFIsotropicParams params;
81
79
for (int i = 0; i < LIGHT_COUNT; ++i)
82
80
{
83
81
SLight l = lights[i];
84
82
vec3 L = l.position-WorldPos;
85
- params.L = L;
83
+ // params.L = L;
86
84
const float intensityScale = LIGHT_INTENSITY_SCALE;//ehh might want to render to hdr fbo and do tonemapping
87
- color += irr_bsdf_cos_eval(params , out_interaction, dUV)*l.intensity*intensityScale / dot(L,L);
85
+ color += irr_bsdf_cos_eval(precomp, normalize(L) , out_interaction, dUV)*l.intensity*intensityScale / dot(L,L);
88
86
}
89
87
90
88
return color+emissive;
@@ -344,7 +342,7 @@ int main()
344
342
meshmetas.push_back (static_cast <const ext::MitsubaLoader::IMeshMetadata*>(cpumesh->getMetadata ()));
345
343
const auto & instances = meshmetas.back ()->getInstances ();
346
344
347
- auto computeAreaAndAvgPos = [](asset::ICPUMeshBuffer* mb, const core::matrix3x4SIMD& tform, core::vectorSIMDf& _outAvgPos) {
345
+ auto computeAreaAndAvgPos = [](const asset::ICPUMeshBuffer* mb, const core::matrix3x4SIMD& tform, core::vectorSIMDf& _outAvgPos) {
348
346
uint32_t triCount = 0u ;
349
347
asset::IMeshManipulator::getPolyCount (triCount, mb);
350
348
assert (triCount>0u );
@@ -392,7 +390,7 @@ int main()
392
390
}
393
391
}
394
392
395
- constexpr uint32_t ENVMAP_SAMPLE_COUNT = 64u ;
393
+ constexpr uint32_t ENVMAP_SAMPLE_COUNT = 16u ;
396
394
constexpr float LIGHT_INTENSITY_SCALE = 0 .01f ;
397
395
398
396
core::unordered_set<const asset::ICPURenderpassIndependentPipeline*> modifiedPipelines;
@@ -440,18 +438,8 @@ int main()
440
438
}
441
439
}
442
440
443
- auto gpuVT = core::make_smart_refctd_ptr<video::IGPUVirtualTexture>(driver, globalMeta->VT .get ());
441
+ // auto gpuVT = core::make_smart_refctd_ptr<video::IGPUVirtualTexture>(driver, globalMeta->VT.get());
444
442
auto gpuds0 = driver->getGPUObjectsFromAssets (&cpuds0.get (), &cpuds0.get ()+1 )->front ();
445
- {
446
- auto count = gpuVT->getDescriptorSetWrites (nullptr , nullptr , nullptr );
447
-
448
- auto writes = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<video::IGPUDescriptorSet::SWriteDescriptorSet>>(count.first );
449
- auto info = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<video::IGPUDescriptorSet::SDescriptorInfo>>(count.second );
450
-
451
- gpuVT->getDescriptorSetWrites (writes->data (), info->data (), gpuds0.get ());
452
-
453
- driver->updateDescriptorSets (writes->size (), writes->data (), 0u , nullptr );
454
- }
455
443
456
444
auto gpuds1layout = driver->getGPUObjectsFromAssets (&ds1layout, &ds1layout+1 )->front ();
457
445
@@ -477,18 +465,20 @@ int main()
477
465
smart_refctd_ptr<video::IGPUBufferView> gpuSequenceBufferView;
478
466
{
479
467
constexpr uint32_t MaxSamples = ENVMAP_SAMPLE_COUNT;
468
+ constexpr uint32_t Channels = 3u ;
480
469
481
- auto sampleSequence = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (uint32_t ) * MaxSamples*2u );
470
+ auto sampleSequence = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (uint32_t ) * MaxSamples*Channels );
482
471
483
- core::OwenSampler sampler (1u , 0xdeadbeefu );
472
+ core::OwenSampler sampler (Channels , 0xdeadbeefu );
484
473
485
474
auto out = reinterpret_cast <uint32_t *>(sampleSequence->getPointer ());
486
- for (uint32_t i = 0 ; i < MaxSamples*2u ; i++)
475
+ for (uint32_t c = 0 ; c < Channels; ++c)
476
+ for (uint32_t i = 0 ; i < MaxSamples; i++)
487
477
{
488
- out[i ] = sampler.sample (i& 1u , i>> 1 );
478
+ out[Channels*i + c ] = sampler.sample (c , i);
489
479
}
490
480
auto gpuSequenceBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem (sampleSequence->getSize (), sampleSequence->getPointer ());
491
- gpuSequenceBufferView = driver->createGPUBufferView (gpuSequenceBuffer.get (), asset::EF_R32G32_UINT );
481
+ gpuSequenceBufferView = driver->createGPUBufferView (gpuSequenceBuffer.get (), asset::EF_R32G32B32_UINT );
492
482
}
493
483
494
484
smart_refctd_ptr<video::IGPUImageView> gpuScrambleImageView;
0 commit comments