Skip to content

Commit d15be7c

Browse files
author
devsh
committed
correct Oren Nayar DOT printing
1 parent 96db3cc commit d15be7c

File tree

2 files changed

+70
-25
lines changed

2 files changed

+70
-25
lines changed

13_MaterialCompilerTest/CFrontendIR.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ void CFrontendIR::IBxDF::SBasicNDFParams::printDot(std::ostringstream& sstr, con
236236

237237
void CFrontendIR::COrenNayar::printDot(std::ostringstream& sstr, const core::string& selfID) const
238238
{
239-
const auto ndParamsID = selfID + "_ndParams";
240-
sstr << "\n\t" << ndParamsID << " label[\"ND Params\"]";
241-
ndParams.printDot(sstr,ndParamsID);
239+
ndParams.printDot(sstr,selfID);
242240
}
243241

244242
void CFrontendIR::CCookTorrance::printDot(std::ostringstream& sstr, const core::string& selfID) const

13_MaterialCompilerTest/main.cpp

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
4343
auto forest = CFrontendIR::create();
4444

4545
auto logger = m_logger.get();
46+
47+
// dummy monochrome image
48+
smart_refctd_ptr<ICPUImageView> monochromeImageView;
49+
{
50+
constexpr auto format = EF_R16_SFLOAT;
51+
auto image = ICPUImage::create({
52+
.type = IImage::E_TYPE::ET_2D,
53+
.samples = IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT,
54+
.format = format,
55+
.extent = {32,32,1},
56+
.mipLevels = 1,
57+
.arrayLayers = 1
58+
});
59+
monochromeImageView = ICPUImageView::create({.image=std::move(image),.viewType=ICPUImageView::ET_2D,.format=format});
60+
}
61+
4662
// TODO: use std::source_info
4763
#define ASSERT_VALUE(WHAT,VALUE,MSG) if (WHAT!=VALUE) return logFail("%s:%d test doesn't match expected value. %s",__FILE__,__LINE__,MSG)
4864

@@ -51,7 +67,7 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
5167
{
5268
// transmission
5369
{
54-
auto layerH = forest->_new<CFrontendIR::CLayer>();
70+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
5571
auto* layer = forest->deref(layerH);
5672
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("MyWeirdInvisibleMaterial");
5773
layer->btdf = forest->_new<CFrontendIR::CDeltaTransmission>();
@@ -60,28 +76,19 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
6076

6177
// creating a node and changing our mind
6278
{
63-
auto image = ICPUImage::create({
64-
.type = IImage::E_TYPE::ET_2D,
65-
.samples = IImage::E_SAMPLE_COUNT_FLAGS::ESCF_1_BIT,
66-
.format = EF_R16_SFLOAT,
67-
.extent = {32,32,1},
68-
.mipLevels = 1,
69-
.arrayLayers = 1
70-
});
71-
auto view = ICPUImageView::create({.image=image,.viewType=ICPUImageView::ET_2D,.format=EF_R16_SFLOAT});
7279

7380
spectral_var_t::SCreationParams<1> params = {};
7481
params.knots.params[0].scale = 4.5f;
75-
params.knots.params[0].view = view;
82+
params.knots.params[0].view = monochromeImageView;
7683

77-
ASSERT_VALUE(view->getReferenceCount(),2,"initial reference count");
84+
ASSERT_VALUE(monochromeImageView->getReferenceCount(),2,"initial reference count");
7885

79-
auto handle = forest->_new<spectral_var_t>(std::move(params));
80-
ASSERT_VALUE(view->getReferenceCount(),2,"transferred reference count");
86+
const auto handle = forest->_new<spectral_var_t>(std::move(params));
87+
ASSERT_VALUE(monochromeImageView->getReferenceCount(),2,"transferred reference count");
8188

8289
// cleaning it up right away should run the destructor immediately and drop the image view refcount
8390
forest->_delete(handle);
84-
ASSERT_VALUE(view->getReferenceCount(),1,"after deletion reference count");
91+
ASSERT_VALUE(monochromeImageView->getReferenceCount(),1,"after deletion reference count");
8592
}
8693

8794
// delta reflection
@@ -104,16 +111,57 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
104111
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
105112
}
106113

107-
// diffuse
108-
109-
// twosided diffuse
114+
// two-sided diffuse
115+
{
116+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
117+
auto* layer = forest->deref(layerH);
118+
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("Twosided Diffuse");
119+
const auto orenNayarH = forest->_new<CFrontendIR::COrenNayar>();
120+
auto* orenNayar = forest->deref(orenNayarH);
121+
orenNayar->debugInfo = forest->_new<CNodePool::CDebugInfo>("Actually Lambertian");
122+
// TODO: add a derivative map for testing the printing and compilation
123+
layer->brdfTop = orenNayarH;
124+
layer->brdfBottom = orenNayarH;
125+
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
126+
}
110127

111-
// diffuse transmissive
128+
// diffuse isotropic rough transmissive
129+
{
130+
const auto layerH = forest->_new<CFrontendIR::CLayer>();
131+
auto* layer = forest->deref(layerH);
132+
layer->debugInfo = forest->_new<CNodePool::CDebugInfo>("Rough Diffuse Transmitter");
133+
// The material compiler can't handle the BRDF vs. BTDF normalization and energy conservation for you.
134+
// Given a BRDF expression we simply can't tell if the missing energy was supposed
135+
// to be transferred to the BTDF or absorbed by the BRDF itself.
136+
// Hence the BTDF expression must contain the BRDF coating term.
137+
const auto mulH = forest->_new<CFrontendIR::CMul>();
138+
auto* mul = forest->deref(mulH);
139+
// regular BRDF will normalize to 100% over a hemisphere, if we allow a BTDF term we must split it half/half
140+
{
141+
spectral_var_t::SCreationParams<1> params = {};
142+
params.knots.params[0].scale = 0.5f;
143+
mul->rhs = forest->_new<spectral_var_t>(std::move(params));
144+
}
145+
// create the BxDF as we'd do for a single BRDF or BTDF
146+
{
147+
const auto orenNayarH = forest->_new<CFrontendIR::COrenNayar>();
148+
auto* orenNayar = forest->deref(orenNayarH);
149+
orenNayar->debugInfo = forest->_new<CNodePool::CDebugInfo>("BxDF Normalized For Whole Sphere");
150+
auto roughness = orenNayar->ndParams.getRougness();
151+
roughness[1].scale = roughness[0].scale = 0.8f;
152+
mul->lhs = orenNayarH;
153+
}
154+
// TODO: add a derivative map for testing the printing and compilation
155+
layer->brdfTop = mulH;
156+
layer->btdf = mulH;
157+
layer->brdfBottom = mulH;
158+
ASSERT_VALUE(forest->addMaterial(layerH,logger),true,"Add Material");
159+
}
112160
}
113161

114-
// emitter without IES profile
162+
// emitter without IES profile
115163

116-
// emitter with IES profile
164+
// emitter with IES profile
117165

118166
// anisotropic cook torrance GGX with Conductor Fresnel
119167
{
@@ -168,7 +216,6 @@ class MaterialCompilerTest final : public application_templates::MonoDeviceAppli
168216

169217
// thindielectric
170218
// dielectric
171-
// diffuse transmitter
172219

173220
// rough plastic
174221

0 commit comments

Comments
 (0)