Skip to content

Commit 8977c55

Browse files
committed
thin infinite scatter correction eval and quotient impls
1 parent 997813e commit 8977c55

1 file changed

Lines changed: 99 additions & 3 deletions

File tree

src/nbl/asset/material_compiler3/CReferenceUnidirectionalPathTracing.cpp

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,54 @@ static quotient_weight_t OrientedMaterial<)===" << hashString << R"===(>::quotie
18391839
sstr << R"===(
18401840
return quotient_weight_t::create(val, 0.0);
18411841
}
1842+
)===";
1843+
break;
1844+
}
1845+
case CTrueIR::INode::EFinalType::CThinInfiniteScatterCorrection:
1846+
{
1847+
const auto* scatter = dynamic_cast<const CTrueIR::CThinInfiniteScatterCorrection*>(node);
1848+
if (!scatter)
1849+
break;
1850+
1851+
const auto hashString = getHashAs4UintsString(node, ir);
1852+
sstr << R"===(
1853+
static quotient_weight_t OrientedMaterial<)===" << hashString << R"===(>::quotientAndWeight(NBL_CONST_REF_ARG(sample_t) _sample, NBL_CONST_REF_ARG(aniso_interaction_t) inter, NBL_REF_ARG(gen_cache<)===" << hashString << R"===(>) cache)
1854+
{
1855+
)===";
1856+
1857+
const auto top = ir->getObjectPool().deref(scatter->reflectanceTop);
1858+
const auto extinction = ir->getObjectPool().deref(scatter->extinction);
1859+
const auto bottom = ir->getObjectPool().deref(scatter->reflectanceBottom);
1860+
1861+
const auto topHash = getHashAs4UintsString(top, ir);
1862+
const auto extinctionHash = getHashAs4UintsString(extinction, ir);
1863+
const auto bottomHash = getHashAs4UintsString(bottom, ir);
1864+
1865+
// TODO verify correctness
1866+
// expecting no pdf value from quotient_weight
1867+
sstr << R"===(
1868+
quotient_weight_t reflectanceTop = OrientedMaterial<)===" << topHash << R"===(>::quotientAndWeight(_sample, inter, cache.child0);
1869+
quotient_weight_t extinction = OrientedMaterial<)===" << extinctionHash << R"===(>::quotientAndWeight(_sample, inter, cache.child1);
1870+
quotient_weight_t reflectanceBottom = OrientedMaterial<)===" << bottomHash << R"===(>::quotientAndWeight(_sample, inter, cache.child2);
1871+
1872+
spectral_t Rt = reflectanceTop.quotient();
1873+
spectral_t E = extinction.quotient();
1874+
spectral_t Rb = reflectanceBottom.quotient();
1875+
)===";
1876+
1877+
if (nodeInfo.isTransmission)
1878+
sstr << R"===(
1879+
spectral_t val = (scalar_t(1.0) - Rt) * (scalar_t(1.0) - Rb) / (scalar_t(1.0) / (E * E) - Rt * Rb);
1880+
)===";
1881+
else
1882+
sstr << R"===(
1883+
spectral_t oneMinusRt = (scalar_t(1.0) - Rt);
1884+
spectral_t val = Rt + (oneMinusRt * oneMinusRt * Rb) / (scalar_t(1.0) / (E * E) - Rt * Rb);
1885+
)===";
1886+
1887+
sstr << R"===(
1888+
return quotient_weight_t::create(val, 0.0);
1889+
}
18421890
)===";
18431891
break;
18441892
}
@@ -2162,7 +2210,7 @@ static value_weight_t OrientedMaterial<)===" << hashString << R"===(>::evalAndWe
21622210
const auto imagEtaHash = getHashAs4UintsString(imagEta, ir);
21632211

21642212
// TODO verify correctness
2165-
// expecting no pdf value from quotient_weight
2213+
// expecting no pdf value from value_weight
21662214
// monochrome eta will take from x component
21672215
// TODO no cache in eval, should be enough to approximate with NdotV?
21682216
sstr << R"===(
@@ -2173,7 +2221,7 @@ static value_weight_t OrientedMaterial<)===" << hashString << R"===(>::evalAndWe
21732221
if (isConductor)
21742222
sstr << R"===(
21752223
using fresnel_t = bxdf::fresnel::Conductor<spectral_t>;
2176-
fresnel_t fresnel = fresnel_t::create(orientedRealEta.quotient(), orientedImagEta.quotient());
2224+
fresnel_t fresnel = fresnel_t::create(orientedRealEta.value(), orientedImagEta.value());
21772225
)===";
21782226
else
21792227
sstr << R"===(
@@ -2185,7 +2233,55 @@ static value_weight_t OrientedMaterial<)===" << hashString << R"===(>::evalAndWe
21852233

21862234
sstr << R"===(
21872235
spectral_t val = fresnel(inter.getNdotV());
2188-
return quotient_weight_t::create(val, 0.0);
2236+
return value_weight_t::create(val, 0.0);
2237+
}
2238+
)===";
2239+
break;
2240+
}
2241+
case CTrueIR::INode::EFinalType::CThinInfiniteScatterCorrection:
2242+
{
2243+
const auto* scatter = dynamic_cast<const CTrueIR::CThinInfiniteScatterCorrection*>(node);
2244+
if (!scatter)
2245+
break;
2246+
2247+
const auto hashString = getHashAs4UintsString(node, ir);
2248+
sstr << R"===(
2249+
static value_weight_t OrientedMaterial<)===" << hashString << R"===(>::evalAndWeight(NBL_CONST_REF_ARG(sample_t) _sample, NBL_CONST_REF_ARG(aniso_interaction_t) inter)
2250+
{
2251+
)===";
2252+
2253+
const auto top = ir->getObjectPool().deref(scatter->reflectanceTop);
2254+
const auto extinction = ir->getObjectPool().deref(scatter->extinction);
2255+
const auto bottom = ir->getObjectPool().deref(scatter->reflectanceBottom);
2256+
2257+
const auto topHash = getHashAs4UintsString(top, ir);
2258+
const auto extinctionHash = getHashAs4UintsString(extinction, ir);
2259+
const auto bottomHash = getHashAs4UintsString(bottom, ir);
2260+
2261+
// TODO verify correctness
2262+
// expecting no pdf value from value_weight
2263+
sstr << R"===(
2264+
value_weight_t reflectanceTop = OrientedMaterial<)===" << topHash << R"===(>::evalAndWeight(_sample, inter);
2265+
value_weight_t extinction = OrientedMaterial<)===" << extinctionHash << R"===(>::evalAndWeight(_sample, inter);
2266+
value_weight_t reflectanceBottom = OrientedMaterial<)===" << bottomHash << R"===(>::evalAndWeight(_sample, inter);
2267+
2268+
spectral_t Rt = reflectanceTop.value();
2269+
spectral_t E = extinction.value();
2270+
spectral_t Rb = reflectanceBottom.value();
2271+
)===";
2272+
2273+
if (nodeInfo.isTransmission)
2274+
sstr << R"===(
2275+
spectral_t val = (hlsl::promote<spectral_t>(1.0) - Rt) * (hlsl::promote<spectral_t>(1.0) - Rb) / (hlsl::promote<spectral_t>(1.0) / (E * E) - Rt * Rb);
2276+
)===";
2277+
else
2278+
sstr << R"===(
2279+
spectral_t oneMinusRt = (hlsl::promote<spectral_t>(1.0) - Rt);
2280+
spectral_t val = Rt + (oneMinusRt * oneMinusRt * Rb) / (hlsl::promote<spectral_t>(1.0) / (E * E) - Rt * Rb);
2281+
)===";
2282+
2283+
sstr << R"===(
2284+
return value_weight_t::create(val, 0.0);
21892285
}
21902286
)===";
21912287
break;

0 commit comments

Comments
 (0)