Skip to content

Commit 548a649

Browse files
author
devsh
committed
emitter Frontend IR test
1 parent d15be7c commit 548a649

File tree

2 files changed

+170
-37
lines changed

2 files changed

+170
-37
lines changed

13_MaterialCompilerTest/CFrontendIR.cpp

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ using namespace nbl::system;
1212

1313
bool CFrontendIR::CEmitter::invalid(const SInvalidCheckArgs& args) const
1414
{
15-
if (const auto* radianceNode=args.pool->deref(radiance); !radianceNode)
16-
{
17-
args.logger.log("Radiance node of correct type must be attached, but is %u of type %s",ELL_ERROR,radiance,args.pool->getTypeName(radiance).data());
18-
return false;
19-
}
2015
// not checking validty of profile because invalid means no emission profile
2116
// check for NaN and non invertible matrix
2217
if (profile && !(hlsl::determinant(profileTransform)>hlsl::numeric_limits<hlsl::float32_t>::min))
@@ -177,37 +172,39 @@ void CFrontendIR::SParameter::printDot(std::ostringstream& sstr, const core::str
177172
sstr << "\n\t" << selfID << " -> _view_" << std::to_string(reinterpret_cast<const uint64_t&>(view));
178173
}
179174

180-
void CFrontendIR::CSpectralVariable::printDot(std::ostringstream& sstr, const core::string& selfID) const
175+
core::string CFrontendIR::CSpectralVariable::getLabelSuffix() const
181176
{
182-
auto pWonky = reinterpret_cast<const SCreationParams<2>*>(this+1);
183-
const auto knotCount = getKnotCount();
184-
// single knot stuff is monochrome
185-
if (knotCount>1)
177+
if (getKnotCount()<2)
178+
return "";
179+
constexpr const char* SemanticNames[] =
186180
{
187-
sstr << "\n\t" << selfID << " -> ";
188-
constexpr const char* semanticNames[] =
189-
{
190-
"Fixed3_SRGB",
191-
"Fixed3_DCI_P3",
192-
"Fixed3_BT2020",
193-
"Fixed3_AdobeRGB",
194-
"Fixed3_AcesCG"
195-
};
196-
sstr << semanticNames[static_cast<uint8_t>(pWonky->getSemantics())] << " [label=\"Semantics\"]";
197-
}
198-
pWonky->knots.printDot(knotCount,sstr,selfID);
181+
"\\nSemantics = Fixed3_SRGB",
182+
"\\nSemantics = Fixed3_DCI_P3",
183+
"\\nSemantics = Fixed3_BT2020",
184+
"\\nSemantics = Fixed3_AdobeRGB",
185+
"\\nSemantics = Fixed3_AcesCG"
186+
};
187+
auto pWonky = reinterpret_cast<const SCreationParams<2>*>(this+1);
188+
return SemanticNames[static_cast<uint8_t>(pWonky->getSemantics())];
189+
}
190+
void CFrontendIR::CSpectralVariable::printDot(std::ostringstream& sstr, const core::string& selfID) const
191+
{
192+
auto pWonky = reinterpret_cast<const SCreationParams<1>*>(this+1);
193+
pWonky->knots.printDot(getKnotCount(),sstr,selfID);
199194
}
200195

201196
void CFrontendIR::CEmitter::printDot(std::ostringstream& sstr, const core::string& selfID) const
202197
{
203198
if (profile)
199+
profile.printDot(sstr,selfID);
200+
if (profile.view)
204201
{
205202
const auto transformNodeID = selfID+"_pTform";
206203
sstr << "\n\t" << transformNodeID << " [label=\"";
207204
printMatrix(sstr,profileTransform);
208205
sstr << "\"]";
209206
// connect up
210-
sstr << "\n\t" << selfID << " -> " << transformNodeID;
207+
sstr << "\n\t" << selfID << " -> " << transformNodeID << "[label=\"Profile Transform\"]";
211208
}
212209
}
213210

@@ -241,16 +238,6 @@ void CFrontendIR::COrenNayar::printDot(std::ostringstream& sstr, const core::str
241238

242239
void CFrontendIR::CCookTorrance::printDot(std::ostringstream& sstr, const core::string& selfID) const
243240
{
244-
sstr << "\n\t" << selfID << " -> ";
245-
switch (ndf)
246-
{
247-
case NDF::GGX:
248-
sstr << "GGX";
249-
break;
250-
case NDF::Beckmann:
251-
sstr << "Beckmann";
252-
break;
253-
}
254241
ndParams.printDot(sstr,selfID);
255242
}
256243

13_MaterialCompilerTest/main.cpp

Lines changed: 150 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
4444

4545
auto logger = m_logger.get();
4646

47-
// dummy monochrome image
48-
smart_refctd_ptr<ICPUImageView> monochromeImageView;
47+
// dummy image views
48+
smart_refctd_ptr<ICPUImageView> monochromeImageView, rgbImageView;
4949
{
5050
constexpr auto format = EF_R16_SFLOAT;
5151
auto image = ICPUImage::create({
@@ -58,6 +58,18 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
5858
});
5959
monochromeImageView = ICPUImageView::create({.image=std::move(image),.viewType=ICPUImageView::ET_2D,.format=format});
6060
}
61+
{
62+
constexpr auto format = EF_R8G8B8A8_SRGB;
63+
auto image = ICPUImage::create({
64+
.type = IImage::E_TYPE::ET_2D,
65+
.samples = IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT,
66+
.format = format,
67+
.extent = {1024,1024,1},
68+
.mipLevels = 11,
69+
.arrayLayers = 72 // fur teh lulz
70+
});
71+
rgbImageView = ICPUImageView::create({.image=std::move(image),.viewType=ICPUImageView::ET_2D_ARRAY,.format=format});
72+
}
6173

6274
// TODO: use std::source_info
6375
#define ASSERT_VALUE(WHAT,VALUE,MSG) if (WHAT!=VALUE) return logFail("%s:%d test doesn't match expected value. %s",__FILE__,__LINE__,MSG)
@@ -159,9 +171,143 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
159171
}
160172
}
161173

162-
// emitter without IES profile
174+
// emitter without IES profile
175+
{
176+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
177+
auto* layer = forest->deref(layerH);
178+
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("Twosided Constant Emitter");
179+
{
180+
const auto mulH = forest->_new<CFrontendIR::CMul>();
181+
auto* mul = forest->deref(mulH);
182+
{
183+
const auto emitterH = forest->_new<CFrontendIR::CEmitter>();
184+
// no profile, unit emission
185+
mul->lhs = emitterH;
186+
}
187+
// we multiply the unit emitter by the value we actually want
188+
{
189+
spectral_var_t::SCreationParams<3> params = {};
190+
params.getSemantics() = spectral_var_t::Semantics::Fixed3_SRGB;
191+
params.knots.params[0].scale = 3.f;
192+
params.knots.params[1].scale = 7.f;
193+
params.knots.params[2].scale = 15.f;
194+
mul->rhs = forest->_new<spectral_var_t>(std::move(params));
195+
}
196+
layer->brdfTop = mulH;
197+
layer->brdfBottom = mulH;
198+
}
199+
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
200+
}
201+
202+
// emitter with IES profile
203+
{
204+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
205+
auto* layer = forest->deref(layerH);
206+
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("IES Profile Emitter");
207+
{
208+
const auto mulH = forest->_new<CFrontendIR::CMul>();
209+
auto* mul = forest->deref(mulH);
210+
{
211+
const auto emitterH = forest->_new<CFrontendIR::CEmitter>();
212+
auto* emitter = forest->deref(emitterH);
213+
// you should use this to normalize the profile to unit emission over the hemisphere
214+
// so the light gets picked "fairly"
215+
emitter->profile.scale = 0.01f;
216+
emitter->profile.viewChannel = 0;
217+
emitter->profile.view = monochromeImageView;
218+
// these are defaults but going to set them
219+
emitter->profile.sampler.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
220+
emitter->profile.sampler.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_REPEAT;
221+
// TODO: set transform after merging the OBB PR
222+
//emitter->profileTransform = ;
223+
mul->lhs = emitterH;
224+
}
225+
// we multiply the unit emitter by the emission color value we actually want
226+
{
227+
spectral_var_t::SCreationParams<3> params = {};
228+
params.getSemantics() = spectral_var_t::Semantics::Fixed3_SRGB;
229+
params.knots.params[0].scale = 60.f;
230+
params.knots.params[1].scale = 90.f;
231+
params.knots.params[2].scale = 45.f;
232+
mul->rhs = forest->_new<spectral_var_t>(std::move(params));
233+
}
234+
layer->brdfTop = mulH;
235+
}
236+
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
237+
}
238+
239+
// onesided emitter with spatially varying emission from the backside
240+
{
241+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
242+
auto* layer = forest->deref(layerH);
243+
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("Spatially Varying Emitter");
244+
{
245+
const auto mulH = forest->_new<CFrontendIR::CMul>();
246+
auto* mul = forest->deref(mulH);
247+
{
248+
const auto emitterH = forest->_new<CFrontendIR::CEmitter>();
249+
// no profile, unit emission
250+
mul->lhs = emitterH;
251+
}
252+
// we multiply the unit emitter by the value we actually want
253+
{
254+
spectral_var_t::SCreationParams<3> params = {};
255+
params.getSemantics() = spectral_var_t::Semantics::Fixed3_SRGB;
256+
for (auto c=0; c<3; c++)
257+
{
258+
params.knots.params[c].scale = 4.9f;
259+
params.knots.params[c].viewChannel = c;
260+
params.knots.params[c].view = rgbImageView;
261+
params.knots.params[c].sampler.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER;
262+
params.knots.params[c].sampler.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER;
263+
params.knots.params[c].sampler.BorderColor = ISampler::E_TEXTURE_BORDER_COLOR::ETBC_FLOAT_OPAQUE_BLACK;
264+
}
265+
mul->rhs = forest->_new<spectral_var_t>(std::move(params));
266+
}
267+
layer->brdfBottom = mulH;
268+
}
269+
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
270+
}
163271

164-
// emitter with IES profile
272+
// spatially varying emission but with a profile (think classroom projector)
273+
{
274+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
275+
auto* layer = forest->deref(layerH);
276+
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("Spatially Varying Emitter with IES profile e.g. Digital Projector");
277+
{
278+
const auto mulH = forest->_new<CFrontendIR::CMul>();
279+
auto* mul = forest->deref(mulH);
280+
{
281+
const auto emitterH = forest->_new<CFrontendIR::CEmitter>();
282+
auto* emitter = forest->deref(emitterH);
283+
emitter->profile.scale = 67.f;
284+
emitter->profile.viewChannel = 0;
285+
emitter->profile.view = monochromeImageView;
286+
// lets try some other samplers
287+
emitter->profile.sampler.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
288+
emitter->profile.sampler.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_EDGE;
289+
// try with default transform
290+
mul->lhs = emitterH;
291+
}
292+
// we multiply the unit emitter by the value we actually want
293+
{
294+
spectral_var_t::SCreationParams<3> params = {};
295+
params.getSemantics() = spectral_var_t::Semantics::Fixed3_SRGB;
296+
for (auto c=0; c<3; c++)
297+
{
298+
params.knots.params[c].scale = 900.f; // super bright cause its probably small
299+
params.knots.params[c].viewChannel = c;
300+
params.knots.params[c].view = rgbImageView;
301+
params.knots.params[c].sampler.TextureWrapU = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER;
302+
params.knots.params[c].sampler.TextureWrapV = ISampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER;
303+
params.knots.params[c].sampler.BorderColor = ISampler::E_TEXTURE_BORDER_COLOR::ETBC_FLOAT_OPAQUE_BLACK;
304+
}
305+
mul->rhs = forest->_new<spectral_var_t>(std::move(params));
306+
}
307+
layer->brdfTop = mulH;
308+
}
309+
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
310+
}
165311

166312
// anisotropic cook torrance GGX with Conductor Fresnel
167313
{

0 commit comments

Comments
 (0)