Skip to content

Commit 4383458

Browse files
Merge pull request #52 from Devsh-Graphics-Programming/raytracing
Make sure we get all the raytracing goodies before we work on MitsubaLoader again
2 parents 3c57de5 + 3e64869 commit 4383458

File tree

9 files changed

+420
-331
lines changed

9 files changed

+420
-331
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,19 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
305305

306306
m_sceneBound.addInternalBox(core::transformBoxEx(aabbOriginal,instance.tform));
307307

308-
if (instance.emitter.type != ext::MitsubaLoader::CElementEmitter::Type::INVALID)
308+
auto emitter = instance.emitter.front;
309+
if (emitter.type != ext::MitsubaLoader::CElementEmitter::Type::INVALID)
309310
{
310-
assert(instance.emitter.type == ext::MitsubaLoader::CElementEmitter::Type::AREA);
311+
assert(emitter.type == ext::MitsubaLoader::CElementEmitter::Type::AREA);
311312

312313
SLight newLight(cpumesh->getBoundingBox(), instance.tform);
313314

314-
const float weight = newLight.computeFluxBound(instance.emitter.area.radiance) * instance.emitter.area.samplingWeight;
315+
const float weight = newLight.computeFluxBound(emitter.area.radiance) * emitter.area.samplingWeight;
315316
if (weight <= FLT_MIN)
316317
continue;
317318

318319
retval.lights.emplace_back(std::move(newLight));
319-
retval.lightRadiances.push_back(instance.emitter.area.radiance);
320+
retval.lightRadiances.push_back(emitter.area.radiance);
320321
retval.lightPDF.push_back(weight);
321322
}
322323
}
@@ -789,9 +790,10 @@ void Renderer::init(const SAssetBundle& meshes,
789790
}
790791
// set up m_raygenDS
791792
{
792-
auto scrambleTexture = createScreenSizedTexture(EF_R32_UINT);
793+
auto scrambleTexture = createScreenSizedTexture(EF_R32G32_UINT);
793794
{
794-
core::vector<uint32_t> random(renderPixelCount);
795+
constexpr auto ScrambleStateChannels = 2u;
796+
core::vector<uint32_t> random(renderPixelCount*ScrambleStateChannels);
795797
// generate
796798
{
797799
core::RandomSampler rng(0xbadc0ffeu);

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void main()
217217
const bool validRay = any(greaterThan(throughput.rgb,vec3(FLT_MIN)));
218218
if (validRay)
219219
{
220-
const float err = 1.0/256.0; // TODO: improve ray offsets
220+
const float err = 1.0/64.0; // TODO: improve ray offsets
221221
rays[realOutputID].origin = worldPosition+direction*err;
222222
rays[realOutputID].maxT = max(maxT-err,0.0);
223223
rays[realOutputID].direction = direction;

examples_tests/42.FragmentShaderPathTracer/common.glsl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -576,26 +576,12 @@ void main()
576576
577577
Now:
578578
- Always MIS (path correlated reuse)
579-
- Proper Universal&Robust Materials
580579
- Test MIS alpha (roughness) scheme
581580
582-
Quality:
583-
-* Reweighting Noise Removal
584-
-* Covariance Rendering
585-
-* Geometry Specular AA (Curvature adjusted roughness)
586-
587-
When proper scheduling is available:
588-
- Russian Roulette
589-
- Divergence Optimization
590-
- Adaptive Sampling
591-
592-
When finally texturing:
593-
- Covariance Rendering
594-
- CLEAR/LEAN/Toksvig for simult roughness + bumpmap filtering
595-
596581
Many Lights:
597582
- Path Guiding
598583
- Light Importance Lists/Classification
584+
- Spatio-Temporal Reservoir Sampling
599585
600586
Indirect Light:
601587
- Bidirectional Path Tracing

include/nbl/ext/MitsubaLoader/CElementEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class CElementEmitter : public IElement
104104
CElementEmitter(const char* id) : IElement(id), type(Type::INVALID), /*toWorldType(IElement::Type::TRANSFORM),*/ transform()
105105
{
106106
}
107+
CElementEmitter() : CElementEmitter("") {}
107108
CElementEmitter(const CElementEmitter& other) : IElement(""), transform()
108109
{
109110
operator=(other);

include/nbl/ext/MitsubaLoader/SContext.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,24 @@ namespace MitsubaLoader
138138

139139
struct SInstanceData
140140
{
141-
SInstanceData(core::matrix3x4SIMD _tform, SContext::bsdf_type _bsdf, const std::string& _id, const CElementEmitter& _emitter) :
141+
SInstanceData(core::matrix3x4SIMD _tform, SContext::bsdf_type _bsdf, const std::string& _id, const CElementEmitter& _emitterFront, const CElementEmitter& _emitterBack) :
142142
tform(_tform), bsdf(_bsdf),
143143
#if defined(_NBL_DEBUG) || defined(_NBL_RELWITHDEBINFO)
144144
bsdf_id(_id),
145145
#endif
146-
emitter(_emitter)
146+
emitter{_emitterFront, _emitterBack}
147147
{}
148148

149149
core::matrix3x4SIMD tform;
150150
SContext::bsdf_type bsdf;
151151
#if defined(_NBL_DEBUG) || defined(_NBL_RELWITHDEBINFO)
152152
std::string bsdf_id;
153153
#endif
154-
CElementEmitter emitter; // type is invalid if not used
154+
struct {
155+
// type is invalid if not used
156+
CElementEmitter front;
157+
CElementEmitter back;
158+
} emitter;
155159
};
156160
core::unordered_multimap<const shape_ass_type::pointee*, SInstanceData> mapMesh2instanceData;
157161

source/Nabla/COpenGLDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler
453453
default:
454454
{
455455
GLint res = GL_FALSE;
456-
extGlGetInternalformativ(GL_TEXTURE_2D, getSizedOpenGLFormatFromOurFormat(_fmt), GL_COLOR_RENDERABLE, sizeof(res), &res);
456+
extGlGetInternalformativ(GL_TEXTURE_2D, getSizedOpenGLFormatFromOurFormat(_fmt), GL_COLOR_RENDERABLE, 1, &res);
457457
return res==GL_TRUE;
458458
}
459459
}

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
865865
assert(shape->bsdf);
866866
auto bsdf = getBSDFtreeTraversal(ctx, shape->bsdf);
867867
core::matrix3x4SIMD tform = core::concatenateBFollowedByA(relTform, shape->getAbsoluteTransform());
868-
SContext::SInstanceData instance(tform, bsdf, shape->bsdf->id, shape->obtainEmitter());
868+
SContext::SInstanceData instance(tform, bsdf, shape->bsdf->id, shape->obtainEmitter(), CElementEmitter{});
869869
ctx.mapMesh2instanceData.insert({ mesh.get(), instance });
870870
};
871871

@@ -1616,8 +1616,10 @@ inline core::smart_refctd_ptr<asset::ICPUDescriptorSet> CMitsubaLoader::createDS
16161616
mb->setBaseInstance(instanceData.size());
16171617
}
16181618
for (const auto& inst : meta->getInstances()) {
1619-
// @Crisspl IIRC lights in mitsuba have "sides" , TODO
1620-
emissive = inst.emitter.type==CElementEmitter::AREA ? inst.emitter.area.radiance : core::vectorSIMDf(0.f);
1619+
// @Crisspl IIRC lights in mitsuba have "sides"
1620+
//
1621+
// i think it's just that backside of an area emitter does not emit, docs doesnt say anything about this
1622+
emissive = inst.emitter.front.type==CElementEmitter::AREA ? inst.emitter.front.area.radiance : core::vectorSIMDf(0.f);
16211623

16221624
nbl_glsl_ext_Mitsuba_Loader_instance_data_t instData;
16231625

src/nbl/ext/RadeonRays/RadeonRays.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ void Manager::makeInstance( NblInstanceRRInstanceCache& instanceCache, MockScene
124124
if (!gpumeshbuffer)
125125
continue;
126126
::RadeonRays::Shape* shape = cpuAssociation.second;
127-
auto successAndLocation = gpuCache.emplace(gpumeshbuffer,shape);
128-
if (gpumeshbuffer==mb)
129-
found = successAndLocation.first;
127+
gpuCache.emplace(gpumeshbuffer,shape);
130128
}
131129
notRefreshedAlready = false;
130+
131+
found = gpuCache.find(mb);
132132
}
133133
if (found==gpuCache.end())
134134
continue;

0 commit comments

Comments
 (0)