@@ -271,8 +271,17 @@ SAssetBundle CMitsubaLoader::loadAsset(system::IFile* _file, const IAssetLoader:
271271 instances.getInitialTransforms ()[index] = shape->getTransform ();
272272 //
273273 const core::string debugName = shape->id .empty () ? std::format (" 0x{:x}" ,ptrdiff_t (shape)):shape->id ;
274- ctx.getMaterial (shape->bsdf ,shape->obtainEmitter (),debugName,PrintMaterialDot3 ? m_system.get ():nullptr );
275- // TODO: compile the material into the true IR and push it into the instances
274+ const auto astRootH = ctx.getMaterial (shape->bsdf ,shape->obtainEmitter (),debugName,PrintMaterialDot3 ? m_system.get ():nullptr );
275+ // TODO: get the output slot for the material in the ICPUScene from `instances.getMaterialTables()`
276+ material_compiler3::CTrueIR::SMaterialHandle rMaterialHandle = {}; // instances.getMaterialTables()
277+ if (astRootH)
278+ {
279+ // we can't batch because of how the parser works
280+ const auto addedCount = ctx.getMaterialFrontend ()->addMaterials ({.rootNodes ={&astRootH,1 },.ir =ctx.scene ->getMaterialPool (),.result =&rMaterialHandle,.logger =_params.logger });
281+ // we could check `addedCount` but the function above does its own logging
282+ }
283+ else // TODO: make a special Error material
284+ rMaterialHandle = material_compiler3::CTrueIR::BlackholeMaterialHandle;
276285 };
277286
278287 // first go over all actually used shapes which are not shapegroups (regular shapes and instances)
@@ -385,7 +394,8 @@ auto SContext::getMaterial(
385394 }
386395 else
387396 root->brdfTop = foundEmitter->second ._const_cast ();
388- const bool success = frontIR->addMaterial (rootH,inner.params .logger );
397+ //
398+ const bool success = frontIR->valid (rootH,inner.params .logger );
389399
390400 auto logger = inner.params .logger ;
391401 if (!success)
@@ -398,13 +408,14 @@ auto SContext::getMaterial(
398408 const frontend_ir_t ::typed_pointer_type<const frontend_ir_t ::CLayer> constRootH = rootH;
399409 frontend_ir_t ::SDotPrinter printer = {frontIR.get (),{&constRootH,1 }};
400410 writeDot3File (debugFileWriter,DebugDir/" material_frontend" /(debugName+" .dot" ),printer);
411+ debugAllMaterials.push_back (constRootH);
401412 }
402413
403414 return rootH;
404415}
405416
406417
407- using parameter_t = asset::material_compiler3::CFrontendIR ::SParameter;
418+ using parameter_t = asset::material_compiler3::CTrueIR ::SParameter;
408419parameter_t SContext::getTexture (const CElementTexture* const rootTex, hlsl::float32_t2x3* outUvTransform)
409420{
410421 parameter_t retval = {};
@@ -594,22 +605,22 @@ auto SContext::genEmitter(const CElementEmitter* _emitter, system::ISystem* debu
594605 spectral_var_t ::SCreationParams<3 > params = {};
595606 // if you wanted a textured emitter, this would be the place to do it
596607 MitsubaLoader::getParameters<3 >(params.knots .params ,_emitter->area .radiance );
597- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
608+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
598609 mul->rhs = frontPool.emplace <spectral_var_t >(std::move (params));
599610 }
600611
601612 if (debugFileWriter)
602613 {
603614 frontend_ir_t ::SDotPrinter printer = {frontIR.get ()};
604- printer.exprStack .push (handle);
615+ printer.exprStack .push_back (handle);
605616 writeDot3File (debugFileWriter,DebugDir/" material_frontend/emitters" /(debugName+" .dot" ),printer);
606617 }
607618 return handle;
608619}
609620
610- auto SContext::genProfile (const CElementEmissionProfile* profile) -> frontend_ir_t ::SParameter
621+ auto SContext::genProfile (const CElementEmissionProfile* profile) -> true_ir_t ::SParameter
611622{
612- frontend_ir_t ::SParameter retval = {};
623+ true_ir_t ::SParameter retval = {};
613624 // load it!
614625 using namespace nbl ::asset;
615626 const CIESProfileMetadata* iesMeta = nullptr ;
@@ -659,7 +670,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
659670 {
660671 spectral_var_t ::SCreationParams<3 > params = {};
661672 params.knots .uvTransform = getParameters (params.knots .params ,factor);
662- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
673+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
663674 const auto factorH = frontPool.emplace <spectral_var_t >(std::move (params));
664675 frontPool.deref (factorH)->debugInfo = commonDebugNames[uint16_t (debug)]._const_cast ();
665676 return factorH;
@@ -678,7 +689,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
678689 auto * mul = frontPool.deref (mulH);
679690 const auto ctH = frontPool.emplace <frontend_ir_t ::CCookTorrance>();
680691 {
681- using ndf_e = frontend_ir_t ::CCookTorrance::NDF ;
692+ using ndf_e = true_ir_t ::SBasicNDFParams::EDistribution ;
682693 constexpr ndf_e ndfMap[4 ] = {
683694 ndf_e::Beckmann,
684695 ndf_e::GGX,
@@ -690,7 +701,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
690701 if (base)
691702 {
692703 // ct->orientedRealEta gets set in the fresnel part
693- ct->ndf = ndfMap[base->distribution ];
704+ ct->ndParams . getDistribution () = ndfMap[base->distribution ];
694705 // this function sets both roughnesses to same alpha
695706 ct->ndParams .uvTransform = getParameters (roughness,base->alpha );
696707 if (base->alphaV .texture || !hlsl::isnan (base->alphaV .value ))
@@ -819,7 +830,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
819830 {
820831 spectral_var_t ::SCreationParams<3 > params = {};
821832 params.knots .uvTransform = getParameters (params.knots .params ,_bsdf->diffuse .reflectance );
822- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
833+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
823834 const auto albedoH = frontPool.emplace <spectral_var_t >(std::move (params));
824835 frontPool.deref (albedoH)->debugInfo = commonDebugNames[uint16_t (ECommonDebug::Albedo)]._const_cast ();
825836 mul->rhs = albedoH;
@@ -858,14 +869,14 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
858869 spectral_var_t ::SCreationParams<3 > params = {};
859870 const hlsl::float32_t3 eta = _bsdf->conductor .eta .vvalue .xyz ;
860871 MitsubaLoader::getParameters<3 >(params.knots .params ,eta/extEta);
861- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
872+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
862873 fresnel->orientedRealEta = frontPool.emplace <spectral_var_t >(std::move (params));
863874 }
864875 {
865876 spectral_var_t ::SCreationParams<3 > params = {};
866877 const hlsl::float32_t3 k = _bsdf->conductor .k .vvalue .xyz ;
867878 MitsubaLoader::getParameters<3 >(params.knots .params ,k/extEta);
868- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
879+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
869880 fresnel->orientedImagEta = frontPool.emplace <spectral_var_t >(std::move (params));
870881 }
871882 }
@@ -1049,7 +1060,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
10491060 {
10501061 spectral_var_t ::SCreationParams<3 > params = {};
10511062 params.knots .uvTransform = getParameters (params.knots .params ,sigmaA);
1052- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
1063+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
10531064 beer->perpTransmittance = frontPool.emplace <spectral_var_t >(std::move (params));
10541065 }
10551066 fillCoatingLayer (coating,_bsdf->coating ,_bsdf->type ==CElementBSDF::ROUGHCOATING,beerH);
@@ -1172,7 +1183,7 @@ auto SContext::genMaterial(const CElementBSDF* bsdf, system::ISystem* debugFileW
11721183 auto * const root = frontPool.deref (rootH);
11731184 root->debugInfo = frontPool.emplace <frontend_ir_t ::CDebugInfo>(debugName);
11741185
1175- const bool success = frontIR->addMaterial (rootH,inner.params .logger );
1186+ const bool success = frontIR->valid (rootH,inner.params .logger );
11761187 if (!success)
11771188 {
11781189 logger.log (" Failed to add Material for %s" ,LoggerError,debugName.c_str ());
@@ -1281,8 +1292,7 @@ SContext::SContext(
12811292) : inner(_ctx), override_(_override), meta(_metadata)
12821293// ,ir(core::make_smart_refctd_ptr<asset::material_compiler::IR>()), frontend(this)
12831294{
1284- auto materialPool = material_compiler3::CTrueIR::create ({.composed ={.blockSizeKBLog2 =4 }});
1285- scene = ICPUScene::create (core::smart_refctd_ptr (materialPool)); // TODO: feed it max shapes per group
1295+ scene = ICPUScene::create (material_compiler3::CTrueIR::create ({.composed ={.blockSizeKBLog2 =4 }})); // TODO: feed it max shapes per group
12861296 //
12871297 {
12881298 frontIR = frontend_ir_t::create ({.composed ={.blockSizeKBLog2 =4 }});
@@ -1313,7 +1323,7 @@ SContext::SContext(
13131323 mul->lhs = frontPool.emplace <frontend_ir_t ::COrenNayar>();
13141324 spectral_var_t ::SCreationParams<3 > params = {};
13151325 MitsubaLoader::getParameters<3 >(params.knots .params ,{1 .f ,0 .f ,1 .f });
1316- params.getSemantics () = spectral_var_t ::Semantics ::Fixed3_SRGB;
1326+ params.getSemantics () = true_ir_t ::ISpectralVariable::ESemantics ::Fixed3_SRGB;
13171327 mul->rhs = frontPool.emplace <spectral_var_t >(std::move (params));
13181328 }
13191329 errorBRDF = mulH;
0 commit comments