OSX build fixes

metadata
Wenzel Jakob 2011-07-08 16:17:11 +02:00
parent f412727cd6
commit 1fe405ec23
16 changed files with 365 additions and 299 deletions

View File

@ -0,0 +1,172 @@
/*
This file is part of Mitsuba, a physically based rendering system.
Copyright (c) 2007-2011 by Wenzel Jakob and others.
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.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(__BASIC_SHADER_H)
#define __BASIC_SHADER_H
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/gpuprogram.h>
MTS_NAMESPACE_BEGIN
/* ============================================================ */
/* Some vary basic texture and shader definitions */
/* These classes are in libhw instead of librender, since */
/* they link to some functions in libhw. */
/* ============================================================ */
/**
* \brief Constant spectrum-valued texture
*
* Includes a \ref Shader implementation for hardware rendering
*/
class MTS_EXPORT_RENDER ConstantSpectrumTexture : public Texture {
public:
inline ConstantSpectrumTexture(const Spectrum &value)
: Texture(Properties()), m_value(value) {
}
ConstantSpectrumTexture(Stream *stream, InstanceManager *manager);
inline Spectrum getValue(const Intersection &its) const {
return m_value;
}
inline Spectrum getAverage() const {
return m_value;
}
inline Spectrum getMaximum() const {
return m_value;
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ConstantSpectrumTexture[value=" << m_value.toString() << "]";
return oss.str();
}
inline bool usesRayDifferentials() const {
return false;
}
Shader *createShader(Renderer *renderer) const;
void serialize(Stream *stream, InstanceManager *manager) const;
MTS_DECLARE_CLASS()
protected:
Spectrum m_value;
};
/**
* \brief Constant float-valued texture
*
* Includes a \ref Shader implementation for hardware rendering
*/
class MTS_EXPORT_RENDER ConstantFloatTexture : public Texture {
public:
inline ConstantFloatTexture(const Float &value)
: Texture(Properties()), m_value(value) {
}
ConstantFloatTexture(Stream *stream, InstanceManager *manager);
inline Spectrum getValue(const Intersection &its) const {
return Spectrum(m_value);
}
inline Spectrum getAverage() const {
return Spectrum(m_value);
}
inline Spectrum getMaximum() const {
return Spectrum(m_value);
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ConstantFloatTexture[value=" << m_value << "]";
return oss.str();
}
inline bool usesRayDifferentials() const {
return false;
}
Shader *createShader(Renderer *renderer) const;
void serialize(Stream *stream, InstanceManager *manager) const;
MTS_DECLARE_CLASS()
protected:
Float m_value;
};
/**
* \brief Scaling passthrough texture
*
* Includes a \ref Shader implementation for hardware rendering
*/
class MTS_EXPORT_RENDER ScaleTexture : public Texture {
public:
inline ScaleTexture(const Texture *nested, const Float &scale)
: Texture(Properties()), m_nested(nested), m_scale(scale) {
}
ScaleTexture(Stream *stream, InstanceManager *manager);
inline Spectrum getValue(const Intersection &its) const {
return m_nested->getValue(its) * m_scale;
}
inline Spectrum getAverage() const {
return m_nested->getAverage() * m_scale;
}
inline Spectrum getMaximum() const {
return m_nested->getMaximum() * m_scale;
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ScaleTexture[" << endl
<< " nested = " << indent(m_nested->toString()) << "," << endl
<< " scale = " << m_scale << endl
<< "]";
return oss.str();
}
inline bool usesRayDifferentials() const {
return m_nested->usesRayDifferentials();
}
Shader *createShader(Renderer *renderer) const;
void serialize(Stream *stream, InstanceManager *manager) const;
MTS_DECLARE_CLASS()
protected:
ref<const Texture> m_nested;
Float m_scale;
};
MTS_NAMESPACE_END
#endif /* __BASIC_SHADER_H */

View File

@ -34,7 +34,6 @@ class BlockListener;
class BSDF;
struct BSDFQueryRecord;
class Camera;
class ConstantSpectrumTexture;
struct EmissionRecord;
class Film;
class GatherPhotonProcess;

View File

@ -86,133 +86,6 @@ protected:
Vector2 m_uvScale;
};
/* ============================================================ */
/* Some vary basic texture definitions */
/* ============================================================ */
class MTS_EXPORT_RENDER ConstantSpectrumTexture : public Texture {
public:
inline ConstantSpectrumTexture(const Spectrum &value)
: Texture(Properties()), m_value(value) {
}
ConstantSpectrumTexture(Stream *stream, InstanceManager *manager);
inline Spectrum getValue(const Intersection &its) const {
return m_value;
}
inline Spectrum getAverage() const {
return m_value;
}
inline Spectrum getMaximum() const {
return m_value;
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ConstantSpectrumTexture[value=" << m_value.toString() << "]";
return oss.str();
}
inline bool usesRayDifferentials() const {
return false;
}
Shader *createShader(Renderer *renderer) const;
void serialize(Stream *stream, InstanceManager *manager) const;
MTS_DECLARE_CLASS()
protected:
Spectrum m_value;
};
class MTS_EXPORT_RENDER ConstantFloatTexture : public Texture {
public:
inline ConstantFloatTexture(const Float &value)
: Texture(Properties()), m_value(value) {
}
ConstantFloatTexture(Stream *stream, InstanceManager *manager);
inline Spectrum getValue(const Intersection &its) const {
return Spectrum(m_value);
}
inline Spectrum getAverage() const {
return Spectrum(m_value);
}
inline Spectrum getMaximum() const {
return Spectrum(m_value);
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ConstantFloatTexture[value=" << m_value << "]";
return oss.str();
}
inline bool usesRayDifferentials() const {
return false;
}
Shader *createShader(Renderer *renderer) const;
void serialize(Stream *stream, InstanceManager *manager) const;
MTS_DECLARE_CLASS()
protected:
Float m_value;
};
class MTS_EXPORT_RENDER ScaleTexture : public Texture {
public:
inline ScaleTexture(const Texture *nested, const Float &scale)
: Texture(Properties()), m_nested(nested), m_scale(scale) {
}
ScaleTexture(Stream *stream, InstanceManager *manager);
inline Spectrum getValue(const Intersection &its) const {
return m_nested->getValue(its) * m_scale;
}
inline Spectrum getAverage() const {
return m_nested->getAverage() * m_scale;
}
inline Spectrum getMaximum() const {
return m_nested->getMaximum() * m_scale;
}
inline std::string toString() const {
std::ostringstream oss;
oss << "ScaleTexture[" << endl
<< " nested = " << indent(m_nested->toString()) << "," << endl
<< " scale = " << m_scale << endl
<< "]";
return oss.str();
}
inline bool usesRayDifferentials() const {
return m_nested->usesRayDifferentials();
}
Shader *createShader(Renderer *renderer) const;
void serialize(Stream *stream, InstanceManager *manager) const;
MTS_DECLARE_CLASS()
protected:
ref<const Texture> m_nested;
Float m_scale;
};
MTS_NAMESPACE_END
#endif /* __TEXTURE_H */

View File

@ -17,9 +17,8 @@
*/
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/core/fresolver.h>
#include <mitsuba/hw/gpuprogram.h>
#include <mitsuba/hw/basicshader.h>
MTS_NAMESPACE_BEGIN

View File

@ -17,7 +17,7 @@
*/
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/basicshader.h>
#include "ior.h"
MTS_NAMESPACE_BEGIN

View File

@ -18,7 +18,7 @@
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/renderer.h>
#include <mitsuba/hw/basicshader.h>
MTS_NAMESPACE_BEGIN

View File

@ -18,7 +18,7 @@
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/renderer.h>
#include <mitsuba/hw/basicshader.h>
MTS_NAMESPACE_BEGIN

View File

@ -17,7 +17,7 @@
*/
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/basicshader.h>
#include "ior.h"
MTS_NAMESPACE_BEGIN

View File

@ -19,8 +19,7 @@
#include <mitsuba/core/fresolver.h>
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/sampler.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/gpuprogram.h>
#include <mitsuba/hw/basicshader.h>
#include "microfacet.h"
MTS_NAMESPACE_BEGIN

View File

@ -18,7 +18,7 @@
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/sampler.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/basicshader.h>
#include "microfacet.h"
#include "ior.h"

View File

@ -17,8 +17,7 @@
*/
#include <mitsuba/render/bsdf.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/renderer.h>
#include <mitsuba/hw/basicshader.h>
MTS_NAMESPACE_BEGIN

View File

@ -4,7 +4,7 @@ libhw_objects = [
'session.cpp', 'device.cpp', 'gputexture.cpp', 'gpugeometry.cpp',
'gpuprogram.cpp', 'renderer.cpp', 'glrenderer.cpp', 'glprogram.cpp',
'glgeometry.cpp', 'gltexture.cpp', 'gpusync.cpp', 'glsync.cpp',
'vpl.cpp', 'font.cpp', 'viewer.cpp']
'vpl.cpp', 'font.cpp', 'viewer.cpp', 'basicshader.cpp']
if sys.platform == 'win32':
libhw_objects += ['wglsession.cpp',

177
src/libhw/basicshader.cpp Normal file
View File

@ -0,0 +1,177 @@
/*
This file is part of Mitsuba, a physically based rendering system.
Copyright (c) 2007-2011 by Wenzel Jakob and others.
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.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mitsuba/hw/basicshader.h>
MTS_NAMESPACE_BEGIN
ConstantSpectrumTexture::ConstantSpectrumTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) {
m_value = Spectrum(stream);
}
void ConstantSpectrumTexture::serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager);
m_value.serialize(stream);
}
ConstantFloatTexture::ConstantFloatTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) {
m_value = stream->readFloat();
}
void ConstantFloatTexture::serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager);
stream->writeFloat(m_value);
}
ScaleTexture::ScaleTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) {
m_nested = static_cast<Texture *>(manager->getInstance(stream));
m_scale = stream->readFloat();
}
void ScaleTexture::serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager);
manager->serialize(stream, m_nested.get());
stream->writeFloat(m_scale);
}
class ConstantSpectrumTextureShader : public Shader {
public:
ConstantSpectrumTextureShader(Renderer *renderer, const Spectrum &value)
: Shader(renderer, ETextureShader), m_value(value) {
}
void generateCode(std::ostringstream &oss,
const std::string &evalName,
const std::vector<std::string> &depNames) const {
oss << "uniform vec3 " << evalName << "_value;" << endl
<< endl
<< "vec3 " << evalName << "(vec2 uv) {" << endl
<< " return " << evalName << "_value;" << endl
<< "}" << endl;
}
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> &parameterIDs) const {
parameterIDs.push_back(program->getParameterID(evalName + "_value"));
}
void bind(GPUProgram *program, const std::vector<int> &parameterIDs, int &textureUnitOffset) const {
program->setParameter(parameterIDs[0], m_value);
}
MTS_DECLARE_CLASS()
private:
Spectrum m_value;
};
class ConstantFloatTextureShader : public Shader {
public:
ConstantFloatTextureShader(Renderer *renderer, const Float &value)
: Shader(renderer, ETextureShader), m_value(value) {
}
void generateCode(std::ostringstream &oss,
const std::string &evalName,
const std::vector<std::string> &depNames) const {
oss << "uniform float " << evalName << "_value;" << endl
<< endl
<< "vec3 " << evalName << "(vec2 uv) {" << endl
<< " return vec3(" << evalName << "_value);" << endl
<< "}" << endl;
}
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> &parameterIDs) const {
parameterIDs.push_back(program->getParameterID(evalName + "_value"));
}
void bind(GPUProgram *program, const std::vector<int> &parameterIDs, int &textureUnitOffset) const {
program->setParameter(parameterIDs[0], m_value);
}
MTS_DECLARE_CLASS()
private:
Float m_value;
};
class ScaleTextureShader : public Shader {
public:
ScaleTextureShader(Renderer *renderer, const Texture *nested, const Float &scale)
: Shader(renderer, ETextureShader), m_nested(nested), m_scale(scale) {
m_nestedShader = renderer->registerShaderForResource(m_nested.get());
}
bool isComplete() const {
return m_nestedShader.get() != NULL;
}
void cleanup(Renderer *renderer) {
renderer->unregisterShaderForResource(m_nested.get());
}
void putDependencies(std::vector<Shader *> &deps) {
deps.push_back(m_nestedShader.get());
}
void generateCode(std::ostringstream &oss,
const std::string &evalName,
const std::vector<std::string> &depNames) const {
oss << "uniform float " << evalName << "_scale;" << endl
<< endl
<< "vec3 " << evalName << "(vec2 uv) {" << endl
<< " return " << depNames[0] << "(uv) * " << evalName << "_scale;" << endl
<< "}" << endl;
}
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> &parameterIDs) const {
parameterIDs.push_back(program->getParameterID(evalName + "_scale"));
}
void bind(GPUProgram *program, const std::vector<int> &parameterIDs, int &nestedUnitOffset) const {
program->setParameter(parameterIDs[0], m_scale);
}
MTS_DECLARE_CLASS()
private:
ref<const Texture> m_nested;
ref<Shader> m_nestedShader;
Float m_scale;
};
Shader *ConstantSpectrumTexture::createShader(Renderer *renderer) const {
return new ConstantSpectrumTextureShader(renderer, m_value);
}
Shader *ConstantFloatTexture::createShader(Renderer *renderer) const {
return new ConstantFloatTextureShader(renderer, m_value);
}
Shader *ScaleTexture::createShader(Renderer *renderer) const {
return new ScaleTextureShader(renderer, m_nested.get(), m_scale);
}
MTS_IMPLEMENT_CLASS_S(ConstantSpectrumTexture, false, Texture)
MTS_IMPLEMENT_CLASS(ConstantSpectrumTextureShader, false, Shader)
MTS_IMPLEMENT_CLASS_S(ConstantFloatTexture, false, Texture)
MTS_IMPLEMENT_CLASS(ConstantFloatTextureShader, false, Shader)
MTS_IMPLEMENT_CLASS_S(ScaleTexture, false, Texture)
MTS_IMPLEMENT_CLASS(ScaleTextureShader, false, Shader)
MTS_NAMESPACE_END

View File

@ -18,6 +18,7 @@
#include <mitsuba/render/scene.h>
#include <mitsuba/core/frame.h>
#include <mitsuba/core/plugin.h>
MTS_NAMESPACE_BEGIN
@ -81,7 +82,10 @@ Texture *BSDF::ensureEnergyConservation(Texture *texture,
<< "issues. Specify the parameter ensureEnergyConservation=false "
<< "to the BSDF to prevent this from happening.";
Log(EWarn, "%s", oss.str().c_str());
return new ScaleTexture(texture, scale);
Properties props("scale");
props.setFloat("value", scale);
return static_cast<Texture *> (PluginManager::getInstance()->
createObject(MTS_CLASS(Texture), props));
}
return texture;
}

View File

@ -16,8 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/gpuprogram.h>
#include <mitsuba/render/scene.h>
MTS_NAMESPACE_BEGIN
@ -80,160 +79,6 @@ Spectrum Texture2D::getValue(const Intersection &its) const {
return getValue(uv);
}
}
ConstantSpectrumTexture::ConstantSpectrumTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) {
m_value = Spectrum(stream);
}
void ConstantSpectrumTexture::serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager);
m_value.serialize(stream);
}
ConstantFloatTexture::ConstantFloatTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) {
m_value = stream->readFloat();
}
void ConstantFloatTexture::serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager);
stream->writeFloat(m_value);
}
ScaleTexture::ScaleTexture(Stream *stream, InstanceManager *manager)
: Texture(stream, manager) {
m_nested = static_cast<Texture *>(manager->getInstance(stream));
m_scale = stream->readFloat();
}
void ScaleTexture::serialize(Stream *stream, InstanceManager *manager) const {
Texture::serialize(stream, manager);
manager->serialize(stream, m_nested.get());
stream->writeFloat(m_scale);
}
class ConstantSpectrumTextureShader : public Shader {
public:
ConstantSpectrumTextureShader(Renderer *renderer, const Spectrum &value)
: Shader(renderer, ETextureShader), m_value(value) {
}
void generateCode(std::ostringstream &oss,
const std::string &evalName,
const std::vector<std::string> &depNames) const {
oss << "uniform vec3 " << evalName << "_value;" << endl
<< endl
<< "vec3 " << evalName << "(vec2 uv) {" << endl
<< " return " << evalName << "_value;" << endl
<< "}" << endl;
}
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> &parameterIDs) const {
parameterIDs.push_back(program->getParameterID(evalName + "_value"));
}
void bind(GPUProgram *program, const std::vector<int> &parameterIDs, int &textureUnitOffset) const {
program->setParameter(parameterIDs[0], m_value);
}
MTS_DECLARE_CLASS()
private:
Spectrum m_value;
};
class ConstantFloatTextureShader : public Shader {
public:
ConstantFloatTextureShader(Renderer *renderer, const Float &value)
: Shader(renderer, ETextureShader), m_value(value) {
}
void generateCode(std::ostringstream &oss,
const std::string &evalName,
const std::vector<std::string> &depNames) const {
oss << "uniform float " << evalName << "_value;" << endl
<< endl
<< "vec3 " << evalName << "(vec2 uv) {" << endl
<< " return vec3(" << evalName << "_value);" << endl
<< "}" << endl;
}
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> &parameterIDs) const {
parameterIDs.push_back(program->getParameterID(evalName + "_value"));
}
void bind(GPUProgram *program, const std::vector<int> &parameterIDs, int &textureUnitOffset) const {
program->setParameter(parameterIDs[0], m_value);
}
MTS_DECLARE_CLASS()
private:
Float m_value;
};
class ScaleTextureShader : public Shader {
public:
ScaleTextureShader(Renderer *renderer, const Texture *nested, const Float &scale)
: Shader(renderer, ETextureShader), m_nested(nested), m_scale(scale) {
m_nestedShader = renderer->registerShaderForResource(m_nested.get());
}
bool isComplete() const {
return m_nestedShader.get() != NULL;
}
void cleanup(Renderer *renderer) {
renderer->unregisterShaderForResource(m_nested.get());
}
void putDependencies(std::vector<Shader *> &deps) {
deps.push_back(m_nestedShader.get());
}
void generateCode(std::ostringstream &oss,
const std::string &evalName,
const std::vector<std::string> &depNames) const {
oss << "uniform float " << evalName << "_scale;" << endl
<< endl
<< "vec3 " << evalName << "(vec2 uv) {" << endl
<< " return " << depNames[0] << "(uv) * " << evalName << "_scale;" << endl
<< "}" << endl;
}
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> &parameterIDs) const {
parameterIDs.push_back(program->getParameterID(evalName + "_scale"));
}
void bind(GPUProgram *program, const std::vector<int> &parameterIDs, int &nestedUnitOffset) const {
program->setParameter(parameterIDs[0], m_scale);
}
MTS_DECLARE_CLASS()
private:
ref<const Texture> m_nested;
ref<Shader> m_nestedShader;
Float m_scale;
};
Shader *ConstantSpectrumTexture::createShader(Renderer *renderer) const {
return new ConstantSpectrumTextureShader(renderer, m_value);
}
Shader *ConstantFloatTexture::createShader(Renderer *renderer) const {
return new ConstantFloatTextureShader(renderer, m_value);
}
Shader *ScaleTexture::createShader(Renderer *renderer) const {
return new ScaleTextureShader(renderer, m_nested.get(), m_scale);
}
MTS_IMPLEMENT_CLASS(Texture, true, ConfigurableObject)
MTS_IMPLEMENT_CLASS(Texture2D, true, Texture)
MTS_IMPLEMENT_CLASS_S(ConstantSpectrumTexture, false, Texture)
MTS_IMPLEMENT_CLASS(ConstantSpectrumTextureShader, false, Shader)
MTS_IMPLEMENT_CLASS_S(ConstantFloatTexture, false, Texture)
MTS_IMPLEMENT_CLASS(ConstantFloatTextureShader, false, Shader)
MTS_IMPLEMENT_CLASS_S(ScaleTexture, false, Texture)
MTS_IMPLEMENT_CLASS(ScaleTextureShader, false, Shader)
MTS_NAMESPACE_END

View File

@ -17,8 +17,7 @@
*/
#include <mitsuba/render/scene.h>
#include <mitsuba/render/texture.h>
#include <mitsuba/hw/gpuprogram.h>
#include <mitsuba/hw/basicshader.h>
MTS_NAMESPACE_BEGIN