2010-09-03 05:41:20 +08:00
|
|
|
/*
|
2011-07-13 05:16:27 +08:00
|
|
|
This file is part of Mitsuba, a physically based rendering system.
|
2010-09-03 05:41:20 +08:00
|
|
|
|
2011-07-13 05:16:27 +08:00
|
|
|
Copyright (c) 2007-2011 by Wenzel Jakob and others.
|
2010-09-03 05:41:20 +08:00
|
|
|
|
2011-07-13 05:16:27 +08:00
|
|
|
Mitsuba is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License Version 3
|
|
|
|
as published by the Free Software Foundation.
|
2010-09-03 05:41:20 +08:00
|
|
|
|
2011-07-13 05:16:27 +08:00
|
|
|
Mitsuba is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2010-09-03 05:41:20 +08:00
|
|
|
|
2011-07-13 05:16:27 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-09-03 05:41:20 +08:00
|
|
|
*/
|
|
|
|
|
2010-08-10 01:38:37 +08:00
|
|
|
#include <mitsuba/render/bsdf.h>
|
2011-07-12 17:53:36 +08:00
|
|
|
#include <mitsuba/hw/basicshader.h>
|
2010-08-10 01:38:37 +08:00
|
|
|
|
|
|
|
MTS_NAMESPACE_BEGIN
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
/*!\plugin{phong}{Modified Phong BRDF}
|
2011-07-13 05:16:27 +08:00
|
|
|
* \order{10}
|
2011-07-12 17:53:36 +08:00
|
|
|
* \parameters{
|
|
|
|
* \parameter{exponent}{\Float\Or\Texture}{
|
|
|
|
* Specifies the Phong exponent \default{30}.
|
|
|
|
* }
|
2011-07-13 00:36:20 +08:00
|
|
|
* \parameter{specular\showbreak Reflectance}{\Spectrum\Or\Texture}{
|
|
|
|
* Specifies the weight of the specular reflectance component.\default{0.2}}
|
|
|
|
* \parameter{diffuse\showbreak Reflectance}{\Spectrum\Or\Texture}{
|
|
|
|
* Specifies the weight of the diffuse reflectance component\default{0.5}}
|
2011-07-12 17:53:36 +08:00
|
|
|
* }
|
|
|
|
* \renderings{
|
2011-07-13 00:36:20 +08:00
|
|
|
* \rendering{Exponent$\,=60$}{bsdf_phong_60}
|
|
|
|
* \rendering{Exponent$\,=300$}{bsdf_phong_300}
|
2011-07-12 17:53:36 +08:00
|
|
|
* }
|
|
|
|
|
|
|
|
* This plugin implements the modified Phong reflectance model as described in
|
|
|
|
* \cite{Phong1975Illumination} and \cite{Lafortune1994Using}. This empirical
|
2011-07-13 00:36:20 +08:00
|
|
|
* model is mainly included for historical reasons---its use in new scenes is
|
2011-07-12 17:53:36 +08:00
|
|
|
* discouraged, since significantly more realistic models have been developed
|
|
|
|
* since 1975.
|
|
|
|
*
|
|
|
|
* If possible, it is recommended to switch to a BRDF that is based on
|
2011-07-13 00:36:20 +08:00
|
|
|
* microfacet theory and includes knowledge about the material's index of
|
|
|
|
* refraction. In Mitsuba, two good alternatives to \pluginref{phong} are
|
|
|
|
* the plugins \pluginref{roughconductor} and \pluginref{roughplastic}
|
|
|
|
* (depending on the material type).
|
|
|
|
*
|
|
|
|
* When using this plugin, note that the diffuse and specular reflectance
|
|
|
|
* components should add up to a value less than or equal to one (for each
|
2011-07-13 07:56:00 +08:00
|
|
|
* color channel). Otherwise, they will automatically be scaled appropriately
|
|
|
|
* to ensure energy conservation.
|
2010-08-10 01:38:37 +08:00
|
|
|
*/
|
|
|
|
class Phong : public BSDF {
|
|
|
|
public:
|
|
|
|
Phong(const Properties &props)
|
|
|
|
: BSDF(props) {
|
2011-07-01 07:48:33 +08:00
|
|
|
m_diffuseReflectance = new ConstantSpectrumTexture(
|
2010-09-03 21:26:18 +08:00
|
|
|
props.getSpectrum("diffuseReflectance", Spectrum(0.5f)));
|
2011-07-01 07:48:33 +08:00
|
|
|
m_specularReflectance = new ConstantSpectrumTexture(
|
2010-09-03 21:26:18 +08:00
|
|
|
props.getSpectrum("specularReflectance", Spectrum(0.2f)));
|
2011-07-12 17:53:36 +08:00
|
|
|
m_exponent = new ConstantFloatTexture(
|
|
|
|
props.getFloat("exponent", 30.0f));
|
2011-07-17 06:28:28 +08:00
|
|
|
m_specularSamplingWeight = 0.0f;
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Phong(Stream *stream, InstanceManager *manager)
|
|
|
|
: BSDF(stream, manager) {
|
2010-09-03 21:26:18 +08:00
|
|
|
m_diffuseReflectance = static_cast<Texture *>(manager->getInstance(stream));
|
|
|
|
m_specularReflectance = static_cast<Texture *>(manager->getInstance(stream));
|
2011-07-12 17:53:36 +08:00
|
|
|
m_exponent = static_cast<Texture *>(manager->getInstance(stream));
|
|
|
|
|
|
|
|
configure();
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
2010-09-08 03:50:30 +08:00
|
|
|
void configure() {
|
2011-07-12 17:53:36 +08:00
|
|
|
m_components.clear();
|
2011-07-13 23:40:26 +08:00
|
|
|
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));
|
2011-07-12 17:53:36 +08:00
|
|
|
|
|
|
|
/* Verify the input parameters and fix them if necessary */
|
|
|
|
std::pair<Texture *, Texture *> result = ensureEnergyConservation(
|
|
|
|
m_specularReflectance, m_diffuseReflectance,
|
|
|
|
"specularReflectance", "diffuseReflectance", 1.0f);
|
|
|
|
m_specularReflectance = result.first;
|
|
|
|
m_diffuseReflectance = result.second;
|
|
|
|
|
|
|
|
/* Compute weights that steer samples towards
|
|
|
|
the specular or diffuse components */
|
|
|
|
Float dAvg = m_diffuseReflectance->getAverage().getLuminance(),
|
|
|
|
sAvg = m_specularReflectance->getAverage().getLuminance();
|
|
|
|
m_specularSamplingWeight = sAvg / (dAvg + sAvg);
|
2010-09-08 03:50:30 +08:00
|
|
|
|
2011-07-12 19:54:05 +08:00
|
|
|
m_usesRayDifferentials =
|
|
|
|
m_diffuseReflectance->usesRayDifferentials() ||
|
|
|
|
m_specularReflectance->usesRayDifferentials() ||
|
|
|
|
m_exponent->usesRayDifferentials();
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
BSDF::configure();
|
2010-09-08 03:50:30 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
Spectrum getDiffuseReflectance(const Intersection &its) const {
|
|
|
|
return m_diffuseReflectance->getValue(its);
|
|
|
|
}
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
/// Reflection in local coordinates
|
|
|
|
inline Vector reflect(const Vector &wi) const {
|
|
|
|
return Vector(-wi.x, -wi.y, wi.z);
|
|
|
|
}
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 19:54:05 +08:00
|
|
|
Spectrum eval(const BSDFQueryRecord &bRec, EMeasure measure) const {
|
|
|
|
if (Frame::cosTheta(bRec.wi) <= 0 ||
|
|
|
|
Frame::cosTheta(bRec.wo) <= 0 || measure != ESolidAngle)
|
|
|
|
return Spectrum(0.0f);
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
bool hasSpecular = (bRec.typeMask & EGlossyReflection)
|
2010-08-10 01:38:37 +08:00
|
|
|
&& (bRec.component == -1 || bRec.component == 0);
|
2011-07-12 17:53:36 +08:00
|
|
|
bool hasDiffuse = (bRec.typeMask & EDiffuseReflection)
|
2010-08-10 01:38:37 +08:00
|
|
|
&& (bRec.component == -1 || bRec.component == 1);
|
2011-07-12 17:53:36 +08:00
|
|
|
|
|
|
|
Spectrum result(0.0f);
|
|
|
|
if (hasSpecular) {
|
|
|
|
Float alpha = dot(bRec.wo, reflect(bRec.wi)),
|
|
|
|
exponent = m_exponent->getValue(bRec.its).average();
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
if (alpha > 0.0f) {
|
|
|
|
result += m_specularReflectance->getValue(bRec.its) *
|
|
|
|
((exponent + 2) * INV_TWOPI * std::pow(alpha, exponent));
|
|
|
|
}
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasDiffuse)
|
2011-07-12 17:53:36 +08:00
|
|
|
result += m_diffuseReflectance->getValue(bRec.its) * INV_PI;
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
return result * Frame::cosTheta(bRec.wo);
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
Float pdf(const BSDFQueryRecord &bRec, EMeasure measure) const {
|
2011-07-12 19:54:05 +08:00
|
|
|
if (Frame::cosTheta(bRec.wi) <= 0 ||
|
|
|
|
Frame::cosTheta(bRec.wo) <= 0 || measure != ESolidAngle)
|
|
|
|
return 0.0f;
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
bool hasSpecular = (bRec.typeMask & EGlossyReflection)
|
2010-08-10 01:38:37 +08:00
|
|
|
&& (bRec.component == -1 || bRec.component == 0);
|
2011-07-12 17:53:36 +08:00
|
|
|
bool hasDiffuse = (bRec.typeMask & EDiffuseReflection)
|
2010-08-10 01:38:37 +08:00
|
|
|
&& (bRec.component == -1 || bRec.component == 1);
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
Float diffuseProb = 0.0f, specProb = 0.0f;
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
if (hasDiffuse)
|
|
|
|
diffuseProb = Frame::cosTheta(bRec.wo) * INV_PI;
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
if (hasSpecular) {
|
|
|
|
Float alpha = dot(bRec.wo, reflect(bRec.wi)),
|
|
|
|
exponent = m_exponent->getValue(bRec.its).average();
|
|
|
|
if (alpha > 0)
|
|
|
|
specProb = std::pow(alpha, exponent) *
|
|
|
|
(exponent + 1.0f) / (2.0f * M_PI);
|
|
|
|
}
|
2010-08-10 01:38:37 +08:00
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
if (hasDiffuse && hasSpecular)
|
|
|
|
return m_specularSamplingWeight * specProb +
|
|
|
|
(1-m_specularSamplingWeight) * diffuseProb;
|
|
|
|
else if (hasDiffuse)
|
|
|
|
return diffuseProb;
|
|
|
|
else if (hasSpecular)
|
|
|
|
return specProb;
|
2011-07-12 19:54:05 +08:00
|
|
|
else
|
|
|
|
return 0.0f;
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
inline Spectrum sample(BSDFQueryRecord &bRec, Float &_pdf, const Point2 &_sample) const {
|
2011-02-03 16:15:25 +08:00
|
|
|
Point2 sample(_sample);
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
bool hasSpecular = (bRec.typeMask & EGlossyReflection)
|
2010-08-10 01:38:37 +08:00
|
|
|
&& (bRec.component == -1 || bRec.component == 0);
|
2011-07-12 17:53:36 +08:00
|
|
|
bool hasDiffuse = (bRec.typeMask & EDiffuseReflection)
|
2010-08-10 01:38:37 +08:00
|
|
|
&& (bRec.component == -1 || bRec.component == 1);
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
if (!hasSpecular && !hasDiffuse)
|
|
|
|
return Spectrum(0.0f);
|
|
|
|
|
|
|
|
bool choseSpecular = hasSpecular;
|
|
|
|
|
|
|
|
if (hasDiffuse && hasSpecular) {
|
2011-02-03 16:15:25 +08:00
|
|
|
if (sample.x <= m_specularSamplingWeight) {
|
|
|
|
sample.x /= m_specularSamplingWeight;
|
2010-08-10 01:38:37 +08:00
|
|
|
} else {
|
2011-02-03 16:15:25 +08:00
|
|
|
sample.x = (sample.x - m_specularSamplingWeight)
|
2011-07-12 17:53:36 +08:00
|
|
|
/ (1-m_specularSamplingWeight);
|
|
|
|
choseSpecular = false;
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
if (choseSpecular) {
|
|
|
|
Vector R = reflect(bRec.wi);
|
|
|
|
Float exponent = m_exponent->getValue(bRec.its).average();
|
|
|
|
|
|
|
|
/* Sample from a Phong lobe centered around (0, 0, 1) */
|
|
|
|
Float sinAlpha = std::sqrt(1-std::pow(sample.y, 2/(exponent + 1)));
|
|
|
|
Float cosAlpha = std::pow(sample.y, 1/(exponent + 1));
|
|
|
|
Float phi = (2.0f * M_PI) * sample.x;
|
|
|
|
Vector localDir = Vector(
|
|
|
|
sinAlpha * std::cos(phi),
|
|
|
|
sinAlpha * std::sin(phi),
|
|
|
|
cosAlpha
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Rotate into the correct coordinate system */
|
|
|
|
bRec.wo = Frame(R).toWorld(localDir);
|
|
|
|
bRec.sampledComponent = 1;
|
|
|
|
bRec.sampledType = EGlossyReflection;
|
|
|
|
|
|
|
|
if (Frame::cosTheta(bRec.wo) <= 0)
|
|
|
|
return Spectrum(0.0f);
|
|
|
|
} else {
|
|
|
|
bRec.wo = squareToHemispherePSA(sample);
|
|
|
|
bRec.sampledComponent = 0;
|
|
|
|
bRec.sampledType = EDiffuseReflection;
|
|
|
|
}
|
|
|
|
|
|
|
|
_pdf = pdf(bRec, ESolidAngle);
|
|
|
|
|
|
|
|
if (_pdf == 0)
|
|
|
|
return Spectrum(0.0f);
|
|
|
|
else
|
|
|
|
return eval(bRec, ESolidAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
Spectrum sample(BSDFQueryRecord &bRec, const Point2 &sample) const {
|
2011-07-13 23:40:26 +08:00
|
|
|
Float pdf = 0;
|
2011-07-12 17:53:36 +08:00
|
|
|
Spectrum result = Phong::sample(bRec, pdf, sample);
|
|
|
|
|
|
|
|
if (result.isZero())
|
|
|
|
return Spectrum(0.0f);
|
|
|
|
else
|
|
|
|
return result / pdf;
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void addChild(const std::string &name, ConfigurableObject *child) {
|
2011-07-12 19:54:05 +08:00
|
|
|
if (child->getClass()->derivesFrom(MTS_CLASS(Texture))) {
|
|
|
|
if (name == "exponent")
|
|
|
|
m_exponent = static_cast<Texture *>(child);
|
|
|
|
else if (name == "specularReflectance")
|
|
|
|
m_specularReflectance = static_cast<Texture *>(child);
|
|
|
|
else if (name == "diffuseReflectance")
|
|
|
|
m_diffuseReflectance = static_cast<Texture *>(child);
|
|
|
|
else
|
|
|
|
BSDF::addChild(name, child);
|
2010-08-10 01:38:37 +08:00
|
|
|
} else {
|
|
|
|
BSDF::addChild(name, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void serialize(Stream *stream, InstanceManager *manager) const {
|
|
|
|
BSDF::serialize(stream, manager);
|
|
|
|
|
2010-09-03 21:26:18 +08:00
|
|
|
manager->serialize(stream, m_diffuseReflectance.get());
|
|
|
|
manager->serialize(stream, m_specularReflectance.get());
|
2011-07-12 17:53:36 +08:00
|
|
|
manager->serialize(stream, m_exponent.get());
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Shader *createShader(Renderer *renderer) const;
|
|
|
|
|
|
|
|
std::string toString() const {
|
|
|
|
std::ostringstream oss;
|
2010-08-16 23:16:13 +08:00
|
|
|
oss << "Phong[" << endl
|
2011-07-12 17:53:36 +08:00
|
|
|
<< " name = \"" << getName() << "\"," << endl
|
2010-09-08 03:50:30 +08:00
|
|
|
<< " diffuseReflectance = " << indent(m_diffuseReflectance->toString()) << "," << endl
|
|
|
|
<< " specularReflectance = " << indent(m_specularReflectance->toString()) << "," << endl
|
|
|
|
<< " specularSamplingWeight = " << m_specularSamplingWeight << "," << endl
|
2011-07-12 17:53:36 +08:00
|
|
|
<< " diffuseSamplingWeight = " << (1-m_specularSamplingWeight) << "," << endl
|
|
|
|
<< " exponent = " << indent(m_exponent->toString()) << endl
|
2010-08-10 01:38:37 +08:00
|
|
|
<< "]";
|
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
MTS_DECLARE_CLASS()
|
|
|
|
private:
|
2010-09-03 21:26:18 +08:00
|
|
|
ref<Texture> m_diffuseReflectance;
|
|
|
|
ref<Texture> m_specularReflectance;
|
2011-07-12 17:53:36 +08:00
|
|
|
ref<Texture> m_exponent;
|
2010-08-10 01:38:37 +08:00
|
|
|
Float m_specularSamplingWeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ================ Hardware shader implementation ================
|
|
|
|
|
2011-07-12 17:53:36 +08:00
|
|
|
/**
|
|
|
|
* The GLSL implementation clamps the exponent to 30 so that a
|
|
|
|
* VPL renderer will able to handle the material reasonably well.
|
|
|
|
*/
|
2010-08-10 01:38:37 +08:00
|
|
|
class PhongShader : public Shader {
|
|
|
|
public:
|
2011-07-12 17:53:36 +08:00
|
|
|
PhongShader(Renderer *renderer, const Texture *exponent,
|
|
|
|
const Texture *diffuseColor, const Texture *specularColor)
|
|
|
|
: Shader(renderer, EBSDFShader),
|
|
|
|
m_exponent(exponent),
|
2010-09-03 21:26:18 +08:00
|
|
|
m_diffuseReflectance(diffuseColor),
|
2011-07-12 17:53:36 +08:00
|
|
|
m_specularReflectance(specularColor) {
|
|
|
|
m_exponentShader = renderer->registerShaderForResource(m_exponent.get());
|
2010-09-03 21:26:18 +08:00
|
|
|
m_diffuseReflectanceShader = renderer->registerShaderForResource(m_diffuseReflectance.get());
|
|
|
|
m_specularReflectanceShader = renderer->registerShaderForResource(m_specularReflectance.get());
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isComplete() const {
|
2011-07-12 17:53:36 +08:00
|
|
|
return m_exponentShader.get() != NULL &&
|
|
|
|
m_diffuseReflectanceShader.get() != NULL &&
|
2010-09-03 21:26:18 +08:00
|
|
|
m_specularReflectanceShader.get() != NULL;
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void putDependencies(std::vector<Shader *> &deps) {
|
2011-07-12 17:53:36 +08:00
|
|
|
deps.push_back(m_exponentShader.get());
|
2010-09-03 21:26:18 +08:00
|
|
|
deps.push_back(m_diffuseReflectanceShader.get());
|
|
|
|
deps.push_back(m_specularReflectanceShader.get());
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup(Renderer *renderer) {
|
2011-07-12 17:53:36 +08:00
|
|
|
renderer->unregisterShaderForResource(m_exponent.get());
|
2010-09-03 21:26:18 +08:00
|
|
|
renderer->unregisterShaderForResource(m_diffuseReflectance.get());
|
|
|
|
renderer->unregisterShaderForResource(m_specularReflectance.get());
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void generateCode(std::ostringstream &oss,
|
|
|
|
const std::string &evalName,
|
|
|
|
const std::vector<std::string> &depNames) const {
|
2011-07-12 17:53:36 +08:00
|
|
|
oss << "vec3 " << evalName << "(vec2 uv, vec3 wi, vec3 wo) {" << endl
|
|
|
|
<< " if (cosTheta(wi) <= 0.0 || cosTheta(wo) <= 0.0)" << endl
|
2010-08-10 01:38:37 +08:00
|
|
|
<< " return vec3(0.0);" << endl
|
|
|
|
<< " vec3 R = vec3(-wi.x, -wi.y, wi.z);" << endl
|
2010-09-08 04:02:40 +08:00
|
|
|
<< " float specRef = 0.0, alpha = dot(R, wo);" << endl
|
2011-07-12 17:53:36 +08:00
|
|
|
<< " float exponent = min(30.0, " << depNames[0] << "(uv)[0]);" << endl
|
2010-09-08 04:02:40 +08:00
|
|
|
<< " if (alpha > 0.0)" << endl
|
2011-07-12 17:53:36 +08:00
|
|
|
<< " specRef = pow(alpha, exponent) * " << endl
|
|
|
|
<< " (exponent + 2) * 0.15915;" << endl
|
|
|
|
<< " return (" << depNames[1] << "(uv) * 0.31831" << endl
|
|
|
|
<< " + " << depNames[2] << "(uv) * specRef) * cosTheta(wo);" << endl
|
2010-08-29 04:31:14 +08:00
|
|
|
<< "}" << endl
|
|
|
|
<< "vec3 " << evalName << "_diffuse(vec2 uv, vec3 wi, vec3 wo) {" << endl
|
2011-07-13 00:36:20 +08:00
|
|
|
<< " if (wi.z <= 0.0 || wo.z <= 0.0)" << endl
|
2010-08-29 04:31:14 +08:00
|
|
|
<< " return vec3(0.0);" << endl
|
2011-07-12 17:53:36 +08:00
|
|
|
<< " return " << depNames[1] << "(uv) * (0.31831 * cosTheta(wo));" << endl
|
2010-08-10 01:38:37 +08:00
|
|
|
<< "}" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MTS_DECLARE_CLASS()
|
|
|
|
private:
|
2011-07-12 17:53:36 +08:00
|
|
|
ref<const Texture> m_exponent;
|
2010-09-03 21:26:18 +08:00
|
|
|
ref<const Texture> m_diffuseReflectance;
|
|
|
|
ref<const Texture> m_specularReflectance;
|
2011-07-12 17:53:36 +08:00
|
|
|
ref<Shader> m_exponentShader;
|
2010-09-03 21:26:18 +08:00
|
|
|
ref<Shader> m_diffuseReflectanceShader;
|
|
|
|
ref<Shader> m_specularReflectanceShader;
|
2010-08-10 01:38:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Shader *Phong::createShader(Renderer *renderer) const {
|
2011-07-12 17:53:36 +08:00
|
|
|
return new PhongShader(renderer, m_exponent.get(),
|
|
|
|
m_diffuseReflectance.get(), m_specularReflectance.get());
|
2010-08-10 01:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MTS_IMPLEMENT_CLASS(PhongShader, false, Shader)
|
|
|
|
MTS_IMPLEMENT_CLASS_S(Phong, false, BSDF)
|
|
|
|
MTS_EXPORT_PLUGIN(Phong, "Modified Phong BRDF");
|
|
|
|
MTS_NAMESPACE_END
|