BSDFs now flag spatially varying components

metadata
Wenzel Jakob 2011-07-13 17:40:26 +02:00
parent a92aa6b29a
commit ce9ad8515d
27 changed files with 176 additions and 71 deletions

View File

@ -6,6 +6,8 @@
<bsdf type="coating">
<float name="intIOR" value="1.5"/>
<float name="extIOR" value="1"/>
<rgb name="sigmaA" value="0.1 0.2 0.3"/>
<float name="thickness" value="2"/>
<bsdf type="diffuse"/>
</bsdf>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 KiB

After

Width:  |  Height:  |  Size: 150 KiB

View File

@ -55,6 +55,10 @@ public:
return m_value;
}
inline bool isConstant() const {
return true;
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ConstantSpectrumTexture[value=" << m_value.toString() << "]";
@ -99,6 +103,10 @@ public:
return Spectrum(m_value);
}
inline bool isConstant() const {
return true;
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ConstantFloatTexture[value=" << m_value << "]";

View File

@ -225,10 +225,12 @@ public:
// =============================================================
/// The lobe is not invariant to rotation around the normal
EAnisotropic = 0x01000,
/// The BSDF depends on the UV coordinates
ESpatiallyVarying = 0x02000,
/// Supports interactions on the front-facing side
EFrontSide = 0x02000,
EFrontSide = 0x04000,
/// Supports interactions on the back-facing side
EBackSide = 0x04000,
EBackSide = 0x08000,
/// Can use an extra sampler instance to improve the sampling method
ECanUseSampler = 0x10000
//! @}

View File

@ -43,6 +43,9 @@ public:
/// Return the resolution in pixels, if applicable
virtual Vector3i getResolution() const;
/// Return whether the texture takes on a single constant value
virtual bool isConstant() const = 0;
/**
* \brief Does this texture do pre-filtering when ray
* differentials are available?

View File

@ -30,37 +30,44 @@ MTS_NAMESPACE_BEGIN
* numerically or using a known material name. \default{\texttt{bk7} / 1.5046}}
* \parameter{extIOR}{\Float\Or\String}{Exterior index of refraction specified
* numerically or using a known material name. \default{\texttt{air} / 1.000277}}
* \parameter{sigmaA}{\Spectrum\Or\Texture}{Absorption coefficient within the layer. \default{0}}
* \parameter{thickness}{\Float}{Thickness of the absorbing layer (given in inverse units of \code{sigmaA})\default{1}}
* \parameter{thickness}{\Float}{Denotes the thickness of the absorbing layer (given in inverse units of \code{sigmaA})\default{1}}
* \parameter{sigmaA}{\Spectrum\Or\Texture}{The absorption coefficient of the coating layer. \default{0, i.e. there is no absorption}}
* }
*
* \renderings{
* \rendering{Coated rough copper (lower exposure, \lstref{coating-roughcopper})}
* \rendering{Rough copper}
* {bsdf_roughconductor_copper}
* \rendering{The same material coated with a single layer of clear varnish (see \lstref{coating-roughcopper})}
* {bsdf_coating_roughconductor}
* \rendering{Coated rough plastic}
* {bsdf_coating_roughplastic}
* }
*
* This plugin implements a smooth dielectric coating in the style of the
* paper ``Arbitrarily Layered Micro-Facet Surfaces'' by Weidlich and
* Wilkie \cite{Weidlich2007Arbitrarily}. Any non-transmissive model can
* be coated, and multiple layers can be applied in sequence. This allows
* designing custom materials like car paint.
* This plugin implements a smooth dielectric coating (e.g. a layer of varnish)
* in the style of the paper ``Arbitrarily Layered Micro-Facet Surfaces'' by
* Weidlich and Wilkie \cite{Weidlich2007Arbitrarily}. Any non-transmissive
* BSDF in Mitsuba can be coated using this plugin, and multiple coating layers
* can be applied in sequence. This allows designing interesting custom materials
* like car paint or glazed metal foil. The coating layer can optionally be
* tinted (i.e. filled with an absorbing medium), in which case this model also
* accounts for the directionally dependent absorption within the layer.
*
* The coating layer can optionally be filled with an absorbing medium,
* in which case this model also accounts for the directionally dependent
* extinction within the layer.
* Note that the plugin discards illumination that undergoes internal
* reflection within the coating. This can lead to a noticeable energy
* loss for materials that reflect much of their energy near or below the critical
* angle (i.e. diffuse or very rough materials).
* Therefore, users are discouraged to use this plugin to coat smooth
* diffuse materials, since there is a separately available plugin
* named \pluginref{smoothplastic}, which covers the same case and does not
* suffer from energy loss.
*
* Evaluating the internal component of this model entails refracting the
* incident and exitant rays through the dielectric interface, followed by
* querying the nested material with this modified direction pair. The result
* is attenuated by the two Fresnel transmittances. Note that this model does
* not attempt to handle illumination that is reflected by the interior of the
* coating---this energy is essentially lost.
* is attenuated by the two Fresnel transmittances and the absorption, if any.
*
* \vspace{4mm}
*
* \begin{xml}[caption=Rough copper coated with a transparent layer of lacquer, label=lst:coating-roughcopper]
* \begin{xml}[caption=Rough copper coated with a transparent layer of
* varnish, label=lst:coating-roughcopper]
* <bsdf type="coating">
* <float name="intIOR" value="1.7"/>
* <bsdf type="roughconductor">
@ -80,12 +87,12 @@ public:
/* Specifies the external index of refraction at the interface */
m_extIOR = lookupIOR(props, "extIOR", "air");
/* Specifies the layer's thickness using the inverse units of sigmaA */
m_thickness = props.getFloat("thickness", 1);
/* Specifies the absorption within the layer */
m_sigmaA = new ConstantSpectrumTexture(
props.getSpectrum("sigmaA", Spectrum(0.0f)));
/* Specifies the layer's thickness using the inverse units of sigmaA */
m_thickness = props.getFloat("thickness", 1);
}
SmoothCoating(Stream *stream, InstanceManager *manager)
@ -105,9 +112,24 @@ public:
Log(EError, "Tried to put a smooth coating layer on top of a BSDF "
"with a transmission component -- this is currently not allowed!");
#if COMPENSATE
if (m_nested->getClass()->getName() == "SmoothDiffuse") {
/* For an ideally diffuse material, it is known how much
energy will be lost to total internal reflection */
m_compensation = (m_intIOR*m_intIOR) / (m_extIOR * m_extIOR);
} else {
/* Otherwise, give up (for now) */
m_compensation = 1.0f;
}
#endif
unsigned int extraFlags = 0;
if (!m_sigmaA->isConstant())
extraFlags |= ESpatiallyVarying;
m_components.clear();
for (int i=0; i<m_nested->getComponentCount(); ++i)
m_components.push_back(m_nested->getType(i));
m_components.push_back(m_nested->getType(i) | extraFlags);
m_components.push_back(EDeltaReflection | EFrontSide);
m_usesRayDifferentials = m_nested->usesRayDifferentials()
@ -206,8 +228,9 @@ public:
if (R12 == 1 || R21 == 1) /* Total internal reflection */
return Spectrum(0.0f);
Float eta = m_extIOR / m_intIOR;
Spectrum result = m_nested->eval(bRec2, measure)
* ((1-R12) * (1-R21));
* ((1-R12) * (1-R21) * eta * eta);
Spectrum sigmaA = m_sigmaA->getValue(bRec.its) * m_thickness;
if (!sigmaA.isZero())
@ -216,10 +239,12 @@ public:
1/std::abs(Frame::cosTheta(bRec2.wo)))).exp();
if (measure == ESolidAngle)
result *= Frame::cosTheta(bRec2.wo);
result *= Frame::cosTheta(bRec.wo)
/ Frame::cosTheta(bRec2.wo);
Float eta = m_extIOR / m_intIOR;
result *= eta * eta;
#ifdef COMPENSATE
result *= m_compensation;
#endif
return result;
}
@ -250,8 +275,10 @@ public:
if (R12 == 1 || R21 == 1) /* Total internal reflection */
return 0.0f;
Float pdf = m_nested->pdf(bRec2, measure)
* Frame::cosTheta(bRec.wo)
Float pdf = m_nested->pdf(bRec2, measure);
if (measure == ESolidAngle)
pdf *= Frame::cosTheta(bRec.wo)
/ Frame::cosTheta(bRec2.wo);
Float eta = m_extIOR / m_intIOR;
@ -324,11 +351,16 @@ public:
if (R21 == 1.0f) /* Total internal reflection */
return Spectrum(0.0f);
bool sampledSA = (BSDF::getMeasure(bRec.sampledType) == ESolidAngle);
Float cosRatio = Frame::cosTheta(bRec.wo) / cosThetaWoPrime,
commonTerms = (sampledSA ? cosRatio : 1.0f)* eta * eta;
pdf *= (sampleSpecular ? (1 - R12) : 1.0f) * eta * eta *
Frame::cosTheta(bRec.wo) / cosThetaWoPrime;
pdf *= (sampleSpecular ? (1 - R12) : 1.0f) * commonTerms;
result *= (1 - R12) * (1 - R21) * commonTerms;
result *= (1 - R12) * (1 - R21) * cosThetaWoPrime * eta * eta;
#ifdef COMPENSATE
result *= m_compensation;
#endif
return result;
}
@ -358,11 +390,14 @@ public:
}
MTS_DECLARE_CLASS()
private:
protected:
Float m_intIOR, m_extIOR;
ref<Texture> m_sigmaA;
ref<BSDF> m_nested;
Float m_thickness;
#ifdef COMPENSATE
Float m_compensation;
#endif
};
MTS_IMPLEMENT_CLASS_S(SmoothCoating, false, BSDF)

View File

@ -181,7 +181,8 @@ public:
m_specularReflectance->usesRayDifferentials();
m_components.clear();
m_components.push_back(EDeltaReflection | EFrontSide);
m_components.push_back(EDeltaReflection | EFrontSide
| (m_specularReflectance->isConstant() ? 0 : ESpatiallyVarying));
BSDF::configure();
}

View File

@ -176,8 +176,10 @@ public:
m_specularTransmittance, "specularTransmittance", 1.0f);
m_components.clear();
m_components.push_back(EDeltaReflection | EFrontSide | EBackSide);
m_components.push_back(EDeltaTransmission | EFrontSide | EBackSide);
m_components.push_back(EDeltaReflection | EFrontSide | EBackSide
| (m_specularReflectance->isConstant() ? 0 : ESpatiallyVarying));
m_components.push_back(EDeltaTransmission | EFrontSide | EBackSide
| (m_specularTransmittance->isConstant() ? 0 : ESpatiallyVarying));
m_usesRayDifferentials =
m_specularReflectance->usesRayDifferentials() ||

View File

@ -64,7 +64,8 @@ public:
m_transmittance = ensureEnergyConservation(m_transmittance, "transmittance", 1.0f);
m_components.clear();
m_components.push_back(EDiffuseTransmission | EFrontSide | EBackSide);
m_components.push_back(EDiffuseTransmission | EFrontSide | EBackSide
| (m_transmittance->isConstant() ? 0 : ESpatiallyVarying));
BSDF::configure();
}

View File

@ -93,7 +93,8 @@ public:
m_reflectance = ensureEnergyConservation(m_reflectance, "reflectance", 1.0f);
m_components.clear();
m_components.push_back(EDiffuseReflection | EFrontSide);
m_components.push_back(EDiffuseReflection | EFrontSide
| (m_reflectance->isConstant() ? 0 : ESpatiallyVarying));
m_usesRayDifferentials = m_reflectance->usesRayDifferentials();
BSDF::configure();

View File

@ -122,8 +122,10 @@ public:
void configure() {
m_components.clear();
m_components.push_back(EGlossyReflection | EAnisotropic | EFrontSide);
m_components.push_back(EDiffuseReflection | EFrontSide);
m_components.push_back(EGlossyReflection | EFrontSide
| EAnisotropic | ESpatiallyVarying);
m_components.push_back(EDiffuseReflection | EFrontSide
| ESpatiallyVarying);
BSDF::configure();
}

View File

@ -83,10 +83,17 @@ public:
void configure() {
if (!m_nestedBSDF)
Log(EError, "A child BSDF is required");
unsigned int extraFlags = 0;
if (!m_opacity->isConstant())
extraFlags |= ESpatiallyVarying;
m_components.clear();
for (int i=0; i<m_nestedBSDF->getComponentCount(); ++i)
m_components.push_back(m_nestedBSDF->getType(i));
m_components.push_back(EDeltaTransmission | EFrontSide | EBackSide);
m_components.push_back(m_nestedBSDF->getType(i) | extraFlags);
m_components.push_back(EDeltaTransmission | EFrontSide
| EBackSide | extraFlags);
m_usesRayDifferentials = m_nestedBSDF->usesRayDifferentials();
m_opacity = ensureEnergyConservation(m_opacity, "opacity", 1.0f);
BSDF::configure();

View File

@ -28,8 +28,8 @@ MTS_NAMESPACE_BEGIN
* \parameter{weights}{\String}{A comma-separated list of BSDF weights}
* }
* \renderings{
* \rendering{An exemplary combination of BSDFs
* (\lstref{mixture-example})}{bsdf_mixture_test}
* \rendering{An admittedly not particularly realistic linear combination of
* diffuse and specular BSDFs (\lstref{mixture-example})}{bsdf_mixture_test}
* }
*
* This plugin implements a ``mixture'' material, which represents

View File

@ -77,8 +77,11 @@ public:
void configure() {
m_components.clear();
m_components.push_back(EGlossyReflection | EFrontSide);
m_components.push_back(EDiffuseReflection | EFrontSide);
m_components.push_back(EGlossyReflection | EFrontSide |
((!m_specularReflectance->isConstant()
|| !m_exponent->isConstant()) ? ESpatiallyVarying : 0));
m_components.push_back(EDiffuseReflection | EFrontSide
| (m_diffuseReflectance->isConstant() ? 0 : ESpatiallyVarying));
/* Verify the input parameters and fix them if necessary */
std::pair<Texture *, Texture *> result = ensureEnergyConservation(
@ -230,7 +233,7 @@ public:
}
Spectrum sample(BSDFQueryRecord &bRec, const Point2 &sample) const {
Float pdf;
Float pdf = 0;
Spectrum result = Phong::sample(bRec, pdf, sample);
if (result.isZero())

View File

@ -103,8 +103,10 @@ public:
m_diffuseReflectance->usesRayDifferentials();
m_components.clear();
m_components.push_back(EDeltaReflection | EFrontSide);
m_components.push_back(EDiffuseReflection | EFrontSide);
m_components.push_back(EDeltaReflection | EFrontSide
| (m_specularReflectance->isConstant() ? 0 : ESpatiallyVarying));
m_components.push_back(EDiffuseReflection | EFrontSide
| (m_diffuseReflectance->isConstant() ? 0 : ESpatiallyVarying));
BSDF::configure();
}

View File

@ -205,10 +205,12 @@ public:
"anisotropic Ashikhmin-Shirley microfacet distribution "
"(named \"as\")");
}
if (!m_alphaU->isConstant() || !m_alphaV->isConstant() ||
!m_specularReflectance->isConstant())
extraFlags |= ESpatiallyVarying;
m_components.clear();
m_components.push_back(
EGlossyReflection | EFrontSide | extraFlags);
m_components.push_back(EGlossyReflection | EFrontSide | extraFlags);
/* Verify the input parameters and fix them if necessary */
m_specularReflectance = ensureEnergyConservation(

View File

@ -227,11 +227,16 @@ public:
"(named \"as\")");
}
if (!m_alphaU->isConstant() || !m_alphaV->isConstant())
extraFlags |= ESpatiallyVarying;
m_components.clear();
m_components.push_back(
EGlossyReflection | EFrontSide | EBackSide | ECanUseSampler | extraFlags);
m_components.push_back(
EGlossyTransmission | EFrontSide | EBackSide | ECanUseSampler | extraFlags);
m_components.push_back(EGlossyReflection | EFrontSide
| EBackSide | ECanUseSampler | extraFlags
| (m_specularReflectance->isConstant() ? 0 : ESpatiallyVarying));
m_components.push_back(EGlossyTransmission | EFrontSide
| EBackSide | ECanUseSampler | extraFlags
| (m_specularTransmittance->isConstant() ? 0 : ESpatiallyVarying));
/* Verify the input parameters and fix them if necessary */
m_specularReflectance = ensureEnergyConservation(

View File

@ -109,7 +109,10 @@ public:
m_reflectance = ensureEnergyConservation(m_reflectance, "reflectance", 1.0f);
m_components.clear();
m_components.push_back(EGlossyReflection | EFrontSide);
m_components.push_back(EGlossyReflection | EFrontSide
| ((!m_reflectance->isConstant() || !m_alpha->isConstant())
? ESpatiallyVarying : 0));
m_usesRayDifferentials = m_reflectance->usesRayDifferentials() ||
m_alpha->usesRayDifferentials();

View File

@ -176,8 +176,11 @@ public:
void configure() {
m_components.clear();
m_components.push_back(EGlossyReflection | EFrontSide);
m_components.push_back(EDiffuseReflection | EFrontSide);
m_components.push_back(EGlossyReflection | EFrontSide
| (m_specularReflectance->isConstant() ? 0 : ESpatiallyVarying));
m_components.push_back(EDiffuseReflection | EFrontSide
| (m_diffuseReflectance->isConstant() ? 0 : ESpatiallyVarying));
/* Verify the input parameters and fix them if necessary */
m_specularReflectance = ensureEnergyConservation(
@ -357,7 +360,7 @@ public:
}
Spectrum sample(BSDFQueryRecord &bRec, const Point2 &sample) const {
Float pdf;
Float pdf = 0;
Spectrum result = RoughPlastic::sample(bRec, pdf, sample);
if (result.isZero())

View File

@ -140,8 +140,11 @@ public:
extraFlags |= EAnisotropic;
m_components.clear();
m_components.push_back(EGlossyReflection | EFrontSide | extraFlags);
m_components.push_back(EDiffuseReflection | EFrontSide | extraFlags);
m_components.push_back(EGlossyReflection | EFrontSide | extraFlags
| ((!m_specularReflectance->isConstant() || !m_alphaU->isConstant()
|| !m_alphaV->isConstant()) ? ESpatiallyVarying : 0));
m_components.push_back(EDiffuseReflection | EFrontSide | extraFlags
| (m_diffuseReflectance->isConstant() ? 0 : ESpatiallyVarying));
/* Verify the input parameters and fix them if necessary */
std::pair<Texture *, Texture *> result = ensureEnergyConservation(

View File

@ -256,6 +256,10 @@ public:
return m_maximum;
}
bool isConstant() const {
return false;
}
bool usesRayDifferentials() const {
return true;
}

View File

@ -71,6 +71,10 @@ public:
return m_brightColor;
}
bool isConstant() const {
return false;
}
std::string toString() const {
return "Checkerboard[]";
}

View File

@ -80,6 +80,10 @@ public:
return m_brightColor; // that's not quite right
}
bool isConstant() const {
return false;
}
std::string toString() const {
return "GridTexture[]";
}

View File

@ -68,6 +68,10 @@ public:
return m_nested->getMaximum() * m_scale;
}
bool isConstant() const {
return m_nested->isConstant();
}
std::string toString() const {
std::ostringstream oss;
oss << "ScalingTexture[" << endl

View File

@ -54,6 +54,10 @@ public:
return Spectrum(1.0f);
}
bool isConstant() const {
return false;
}
std::string toString() const {
return "VertexColors[]";
}