Skip to content

Commit 37fcd32

Browse files
author
devsh
committed
port the named Fresnel list from the Mitsuba XML Loader to the Material Compiler Frontend IR
1 parent 38d17e7 commit 37fcd32

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

examples_tests

include/nbl/asset/material_compiler3/CFrontendIR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ class CFrontendIR : public CNodePool
650650

651651
// To quickly make a matching backface material from a frontface or vice versa
652652
NBL_API TypedHandle<IExprNode> reciprocate(const TypedHandle<const IExprNode> other);
653+
NBL_API TypedHandle<CFresnel> createNamedFresnel(const std::string_view name);
653654

654655
// IMPORTANT: Two BxDFs are not allowed to be multiplied together.
655656
// NOTE: Right now all Spectral Variables are required to be Monochrome or 3 bucket fixed semantics, all the same wavelength.
@@ -687,7 +688,6 @@ class CFrontendIR : public CNodePool
687688
}
688689

689690
core::vector<TypedHandle<const CLayer>> m_rootNodes;
690-
// TODO: named material Fresnels
691691
};
692692

693693
inline bool CFrontendIR::valid(const TypedHandle<const CLayer> rootHandle, system::logger_opt_ptr logger) const

src/nbl/asset/material_compiler3/CFrontendIR.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// For conditions of distribution and use, see copyright notice in nabla.h
44
#include "nbl/asset/material_compiler3/CFrontendIR.h"
55

6+
#include "nbl/builtin/hlsl/complex.hlsl"
7+
#include "nbl/builtin/hlsl/portable/vector_t.hlsl"
8+
69

710
namespace nbl::asset::material_compiler3
811
{
@@ -75,10 +78,113 @@ bool CFrontendIR::CCookTorrance::invalid(const SInvalidCheckArgs& args) const
7578

7679
auto CFrontendIR::reciprocate(const TypedHandle<const IExprNode> other) -> TypedHandle<IExprNode>
7780
{
81+
if (const auto* in=deref<CFresnel>({.untyped=other.untyped}); in)
82+
{
83+
auto fresnelH = _new<CFresnel>();
84+
auto* fresnel = deref(fresnelH);
85+
*fresnel = *in;
86+
fresnel->reciprocateEtas = ~in->reciprocateEtas;
87+
return fresnelH;
88+
}
7889
assert(false); // unimplemented
7990
return {};
8091
}
8192

93+
auto CFrontendIR::createNamedFresnel(const std::string_view name) -> TypedHandle<CFresnel>
94+
{
95+
using complex32_t = hlsl::complex_t<float>;
96+
using spectral_complex_t = hlsl::portable_vector_t<complex32_t,3>;
97+
const static core::map<std::string_view,spectral_complex_t> creationLambdas = {
98+
#define SPECTRUM_MACRO(R,G,B,X,Y,Z) spectral_complex_t(complex32_t(R,X),complex32_t(G,Y),complex32_t(B,Z))
99+
{"a-C", SPECTRUM_MACRO(1.6855f, 1.065f, 1.727f, 0.0f, 0.009f, 0.0263f)}, // there is no "a-C", but "a-C:H; data from palik"
100+
{"Ag", SPECTRUM_MACRO(0.059481f, 0.055090f, 0.046878f, 4.1367f, 3.4574f, 2.8028f)},
101+
{"Al", SPECTRUM_MACRO(1.3404f, 0.95151f, 0.68603f, 7.3509f, 6.4542f, 5.6351f)},
102+
{"AlAs", SPECTRUM_MACRO(3.1451f, 3.2636f, 3.4543f, 0.0012319f, 0.0039041f, 0.012940f)},
103+
{"AlAs_palik", SPECTRUM_MACRO(3.145f, 3.273f, 3.570f, 0.0f, 0.000275f, 1.56f)},
104+
{"Au", SPECTRUM_MACRO(0.21415f, 0.52329f, 1.3319f, 3.2508f, 2.2714f, 1.8693f)},
105+
{"Be", SPECTRUM_MACRO(3.3884f, 3.2860f, 3.1238f, 3.1692f, 3.1301f, 3.1246f)},
106+
{"Be_palik", SPECTRUM_MACRO(3.46f, 3.30f, 3.19f, 3.18f, 3.18f, 3.16f)},
107+
{"Cr", SPECTRUM_MACRO(3.2246f, 2.6791f, 2.1411f, 4.2684f, 4.1664f, 3.9300f)},
108+
{"CsI", SPECTRUM_MACRO(1.7834f, 1.7978f, 1.8182f, 0.0f, 0.0f, 0.0f)},
109+
{"CsI_palik", SPECTRUM_MACRO(1.78006f, 1.79750f, 1.82315, 0.0f, 0.0f, 0.0f)},
110+
{"Cu", SPECTRUM_MACRO(0.32075f,1.09860f,1.2469f, 3.17900f,2.59220f,2.4562)},
111+
{"Cu_palik", SPECTRUM_MACRO(0.32000f, 1.04f, 1.16f, 3.15000f, 2.59f, 2.4f)},
112+
{"Cu20", SPECTRUM_MACRO(2.975f, 3.17f, 3.075f, 0.122f, 0.23f, 0.525f)}, // out of range beyond 2.5 um refractiveindex.info and similar websites, so data applied is same as from palik's data
113+
{"Cu20_palik", SPECTRUM_MACRO(2.975f, 3.17f, 3.075f, 0.122f, 0.23f, 0.525f)},
114+
{"d-C", SPECTRUM_MACRO(2.4123f, 2.4246f, 2.4349f, 0.0f, 0.0f, 0.0f)},
115+
{"d-C_palik", SPECTRUM_MACRO(2.4137f, 2.4272f, 2.4446f, 0.0f, 0.0f, 0.0f)},
116+
{"Hg", SPECTRUM_MACRO(1.8847f, 1.4764f, 1.1306f, 5.1147f, 4.5410f, 3.9896f)},
117+
{"Hg_palik", SPECTRUM_MACRO(1.850f, 1.460f, 1.100f, 5.100f, 4.600f, 3.990f)},
118+
//{"HgTe", SPECTRUM_MACRO(,,, ,,)}, // lack of length wave range for our purpose https://www.researchgate.net/publication/3714159_Dispersion_of_refractive_index_in_degenerate_mercury_cadmium_telluride
119+
//{"HgTe_palik", SPECTRUM_MACRO(,,, ,,)}, // the same in palik (wavelength beyond 2 um)
120+
{"Ir", SPECTRUM_MACRO(2.4200f, 2.0795f, 1.7965f, 5.0665f, 4.6125f, 4.1120f)},
121+
{"Ir_palik", SPECTRUM_MACRO(2.44f, 2.17f, 1.87f, 4.52f, 4.24f, 3.79f)},
122+
{"K", SPECTRUM_MACRO(0.052350f, 0.048270f, 0.042580f, 1.6732f, 1.3919f, 1.1195f)},
123+
{"K_palik", SPECTRUM_MACRO(0.0525f, 0.0483f, 0.0427f, 1.67f, 1.39f, 1.12f)},
124+
{"Li", SPECTRUM_MACRO(0.14872f, 0.14726f, 0.19236f, 2.9594f, 2.5129f, 2.1144f)},
125+
{"Li_palik", SPECTRUM_MACRO(0.218f, 0.2093f, 0.229f, 2.848f, 2.369f, 2.226f)},
126+
{"MgO", SPECTRUM_MACRO(1.7357f, 1.7419f, 1.7501f, 0.0f, 0.0f, 0.0f)},
127+
{"MgO_palik", SPECTRUM_MACRO(1.7355f, 1.7414f, 1.74975f, 0.0f, 0.0f, 1.55f)}, // Handbook of optical constants of solids vol 2 page 951, weird k compoment alone, no measurements and resoults
128+
{"Mo", SPECTRUM_MACRO(0.76709f, 0.57441f, 0.46711f, 8.5005f, 7.2352f, 6.1383f)}, // https://refractiveindex.info/?shelf=main&book=Mo&page=Werner comparing with palik - weird
129+
{"Mo_palik", SPECTRUM_MACRO(3.68f, 3.77f, 3.175f, 3.51f, 3.624f, 3.56f)},
130+
{"Na_palik", SPECTRUM_MACRO(0.0522f, 0.061f, 0.0667f, 2.535f, 2.196f, 1.861f)},
131+
{"Nb", SPECTRUM_MACRO(2.2775f, 2.2225f, 2.0050f, 3.2500f, 3.1325f, 3.0100f)},
132+
{"Nb_palik", SPECTRUM_MACRO(2.869f, 2.9235f, 2.738f, 2.867f, 2.8764f, 2.8983f)},
133+
{"Ni_palik", SPECTRUM_MACRO(1.921f, 1.744f, 1.651f, 3.615f, 3.168f, 2.753f)},
134+
{"Rh", SPECTRUM_MACRO(2.8490f, 2.6410f, 2.4310f, 3.5450f, 3.3150f, 3.1190f)},
135+
{"Rh_palik", SPECTRUM_MACRO(2.092f, 1.934f, 1.8256f, 5.472f, 4.902f, 4.5181f)},
136+
{"Se", SPECTRUM_MACRO(1.4420f, 1.4759f, 1.4501f, 0.018713f, 0.10233f, 0.18418f)},
137+
{"Se_palik", SPECTRUM_MACRO(3.346f, 3.013f, 3.068f, 0.6402f, 0.6711f, 0.553f)},
138+
{"SiC", SPECTRUM_MACRO(2.6398f, 2.6677f, 2.7069f, 0.0f, 0.0f, 0.0f)},
139+
{"SiC_palik", SPECTRUM_MACRO(2.6412f, 2.6684f, 2.7077f, 0.0f, 0.0f, 0.0f)},
140+
{"SnTe", SPECTRUM_MACRO(3.059f, 1.813f, 1.687f, 5.144f, 4.177f, 3.555f)}, // no data except palik's resources, so data same as palik
141+
{"SnTe_palik", SPECTRUM_MACRO(3.059f, 1.813f, 1.687f, 5.144f, 4.177f, 3.555f)},
142+
{"Ta", SPECTRUM_MACRO(1.0683f, 1.1379f, 1.2243f, 5.5047f, 4.7432f, 4.0988f)},
143+
{"Ta_palik", SPECTRUM_MACRO(1.839f, 2.5875f, 2.8211f, 1.997f, 1.8683f, 2.0514f)},
144+
{"Te", SPECTRUM_MACRO(4.1277f, 3.2968f, 2.6239f, 2.5658f, 2.8789f, 2.7673f)},
145+
{"Te_palik", SPECTRUM_MACRO(5.8101f, 4.5213f, 3.3682f, 2.9428f, 3.7289f, 3.6783f)},
146+
{"ThF4", SPECTRUM_MACRO(1.5113f, 1.5152f, 1.5205f, 0.0f, 0.0f, 0.0f)},
147+
{"ThF4_palik", SPECTRUM_MACRO(1.520f, 1.5125f, 1.524f, 0.0f, 0.0f, 0.0f)},
148+
{"TiC", SPECTRUM_MACRO(3.0460f, 2.9815f, 2.8864f, 2.6585f, 2.4714f, 2.3987f)},
149+
{"TiC_palik", SPECTRUM_MACRO(3.0454f, 2.9763, 2.8674f, 2.6589f, 2.4695f, 2.3959f)},
150+
{"TiO2", SPECTRUM_MACRO(2.1362f, 2.1729f, 2.2298f, 0.0f, 0.0f, 0.0f)},
151+
{"TiO2_palik", SPECTRUM_MACRO(2.5925f, 2.676f, 2.78f, 0.0f, 0.0f, 0.0f)},
152+
{"VC", SPECTRUM_MACRO(3.0033f, 2.8936f, 2.8138f, 2.4981f, 2.3046f, 2.1913f)},
153+
{"VC_palik", SPECTRUM_MACRO(3.0038f, 2.8951f, 2.8184f, 2.4923f, 2.3107f, 2.1902f)},
154+
{"V_palik", SPECTRUM_MACRO(3.512f, 3.671f, 3.2178f, 2.9337, 3.069f, 3.3667f)},
155+
{"VN", SPECTRUM_MACRO(2.3429f, 2.2268f, 2.1550f, 2.4506f, 2.1345f, 1.8753f)},
156+
{"VN_palik", SPECTRUM_MACRO(2.3418f, 2.2239f, 2.1539f, 2.4498f, 2.1371f, 1.8776f)},
157+
{"W", SPECTRUM_MACRO(0.96133f, 1.5474f, 2.1930f, 6.2902f, 5.1052f, 5.0325f)},
158+
{"none", SPECTRUM_MACRO(0.f,0.f,0.f, 0.f,0.f,0.f)}
159+
#undef SPECTRUM_MACRO
160+
};
161+
//
162+
const auto found = creationLambdas.find(name);
163+
if (found==creationLambdas.end())
164+
return {};
165+
//
166+
const auto frH = _new<CFrontendIR::CFresnel>();
167+
auto* fr = deref(frH);
168+
fr->debugInfo = _new<CNodePool::CDebugInfo>(found->first);
169+
{
170+
CSpectralVariable::SCreationParams<3> params = {};
171+
params.getSemantics() = CSpectralVariable::Semantics::Fixed3_SRGB;
172+
params.knots.params[0].scale = found->second.x.real();
173+
params.knots.params[1].scale = found->second.y.real();
174+
params.knots.params[2].scale = found->second.z.real();
175+
fr->orientedRealEta = _new<CSpectralVariable>(std::move(params));
176+
}
177+
{
178+
CSpectralVariable::SCreationParams<3> params = {};
179+
params.getSemantics() = CSpectralVariable::Semantics::Fixed3_SRGB;
180+
params.knots.params[0].scale = found->second.x.imag();
181+
params.knots.params[1].scale = found->second.y.imag();
182+
params.knots.params[2].scale = found->second.z.imag();
183+
fr->orientedImagEta = _new<CSpectralVariable>(std::move(params));
184+
}
185+
return frH;
186+
}
187+
82188
void CFrontendIR::printDotGraph(std::ostringstream& str) const
83189
{
84190
str << "digraph {\n";

0 commit comments

Comments
 (0)