Skip to content

Commit 1fab76f

Browse files
Merge pull request #43 from Crisspl/spirv-optimizer
Fixes for ex 22
2 parents 64f1ebd + 4cd0ff0 commit 1fab76f

File tree

6 files changed

+289
-198
lines changed

6 files changed

+289
-198
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 5 additions & 4 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
}

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

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ void Manager::makeInstance( NblInstanceRRInstanceCache& instanceCache, MockScene
125125
continue;
126126
::RadeonRays::Shape* shape = cpuAssociation.second;
127127
auto successAndLocation = gpuCache.emplace(gpumeshbuffer,shape);
128-
if (gpumeshbuffer==mb)
128+
if (gpumeshbuffer == mb)
129+
{
129130
found = successAndLocation.first;
131+
break;
132+
}
130133
}
131134
notRefreshedAlready = false;
132135
}

0 commit comments

Comments
 (0)