checkerboard bugfix
parent
fd68671dbc
commit
e1fb65b170
|
@ -29,29 +29,29 @@ MTS_NAMESPACE_BEGIN
|
|||
class Checkerboard : public Texture2D {
|
||||
public:
|
||||
Checkerboard(const Properties &props) : Texture2D(props) {
|
||||
m_brightColor.g = props.getSpectrum("brightReflectance", Spectrum(.4f));
|
||||
m_darkColor.g = props.getSpectrum("darkReflectance", Spectrum(.2f));
|
||||
m_brightColor = props.getSpectrum("brightColor", Spectrum(.4f));
|
||||
m_darkColor = props.getSpectrum("darkColor", Spectrum(.2f));
|
||||
}
|
||||
|
||||
Checkerboard(Stream *stream, InstanceManager *manager)
|
||||
: Texture2D(stream, manager) {
|
||||
m_brightColor.g = Spectrum(stream);
|
||||
m_darkColor.g = Spectrum(stream);
|
||||
m_brightColor = Spectrum(stream);
|
||||
m_darkColor = Spectrum(stream);
|
||||
}
|
||||
|
||||
void serialize(Stream *stream, InstanceManager *manager) const {
|
||||
Texture2D::serialize(stream, manager);
|
||||
m_brightColor.g.serialize(stream);
|
||||
m_darkColor.g.serialize(stream);
|
||||
m_brightColor.serialize(stream);
|
||||
m_darkColor.serialize(stream);
|
||||
}
|
||||
|
||||
inline Spectrum getValue(const Point2 &uv) const {
|
||||
int x = 2*(((int) uv.x) % 2) - 1, y = 2*(((int) uv.y) % 2) - 1;
|
||||
int x = 2*(((int) (uv.x * 2)) % 2) - 1, y = 2*(((int) (uv.y * 2)) % 2) - 1;
|
||||
|
||||
if (x*y == 1)
|
||||
return m_brightColor.g;
|
||||
return m_brightColor;
|
||||
else
|
||||
return m_darkColor.g;
|
||||
return m_darkColor;
|
||||
}
|
||||
|
||||
Spectrum getValue(const Point2 &uv, Float dudx, Float dudy, Float dvdx, Float dvdy) const {
|
||||
|
@ -63,11 +63,11 @@ public:
|
|||
}
|
||||
|
||||
Spectrum getAverage() const {
|
||||
return m_darkColor.g * .5f;
|
||||
return m_darkColor * .5f;
|
||||
}
|
||||
|
||||
Spectrum getMaximum() const {
|
||||
return m_brightColor.g;
|
||||
return m_brightColor;
|
||||
}
|
||||
|
||||
std::string toString() const {
|
||||
|
@ -78,26 +78,26 @@ public:
|
|||
|
||||
MTS_DECLARE_CLASS()
|
||||
protected:
|
||||
Spectrum m_darkColor.g;
|
||||
Spectrum m_brightColor.g;
|
||||
Spectrum m_darkColor;
|
||||
Spectrum m_brightColor;
|
||||
};
|
||||
|
||||
// ================ Hardware shader implementation ================
|
||||
|
||||
class CheckerboardShader : public Shader {
|
||||
public:
|
||||
CheckerboardShader(Renderer *renderer, const Spectrum &brightColor.g,
|
||||
const Spectrum &darkColor.g, const Point2 &uvOffset,
|
||||
CheckerboardShader(Renderer *renderer, const Spectrum &brightColor,
|
||||
const Spectrum &darkColor, const Point2 &uvOffset,
|
||||
const Vector2 &uvScale) : Shader(renderer, ETextureShader),
|
||||
m_brightColor.g(brightReflectance), m_darkReflectance(darkReflectance),
|
||||
m_brightColor(brightColor), m_darkColor(darkColor),
|
||||
m_uvOffset(uvOffset), m_uvScale(uvScale) {
|
||||
}
|
||||
|
||||
void generateCode(std::ostringstream &oss,
|
||||
const std::string &evalName,
|
||||
const std::vector<std::string> &depNames) const {
|
||||
oss << "uniform vec3 " << evalName << "_brightColor.g;" << endl
|
||||
<< "uniform vec3 " << evalName << "_darkColor.g;" << endl
|
||||
oss << "uniform vec3 " << evalName << "_brightColor;" << endl
|
||||
<< "uniform vec3 " << evalName << "_darkColor;" << endl
|
||||
<< "uniform vec2 " << evalName << "_uvOffset;" << endl
|
||||
<< "uniform vec2 " << evalName << "_uvScale;" << endl
|
||||
<< endl
|
||||
|
@ -105,39 +105,39 @@ public:
|
|||
<< " uv = vec2(" << endl
|
||||
<< " uv.x * " << evalName << "_uvScale.x + " << evalName << "_uvOffset.x," << endl
|
||||
<< " uv.y * " << evalName << "_uvScale.y + " << evalName << "_uvOffset.y);" << endl
|
||||
<< " float x = 2*(mod(int(uv.x), 2)) - 1, y = 2*(mod(int(uv.y), 2)) - 1;" << endl
|
||||
<< " float x = 2*(mod(int(uv.x*2), 2)) - 1, y = 2*(mod(int(uv.y*2), 2)) - 1;" << endl
|
||||
<< " if (x*y == 1)" << endl
|
||||
<< " return " << evalName << "_brightColor.g;" << endl
|
||||
<< " return " << evalName << "_brightColor;" << endl
|
||||
<< " else" << endl
|
||||
<< " return " << evalName << "_darkColor.g;" << endl
|
||||
<< " return " << evalName << "_darkColor;" << endl
|
||||
<< "}" << endl;
|
||||
}
|
||||
|
||||
void resolve(const GPUProgram *program, const std::string &evalName, std::vector<int> ¶meterIDs) const {
|
||||
parameterIDs.push_back(program->getParameterID(evalName + "_brightColor.g", false));
|
||||
parameterIDs.push_back(program->getParameterID(evalName + "_darkColor.g", false));
|
||||
parameterIDs.push_back(program->getParameterID(evalName + "_brightColor", false));
|
||||
parameterIDs.push_back(program->getParameterID(evalName + "_darkColor", false));
|
||||
parameterIDs.push_back(program->getParameterID(evalName + "_uvOffset", false));
|
||||
parameterIDs.push_back(program->getParameterID(evalName + "_uvScale", false));
|
||||
}
|
||||
|
||||
void bind(GPUProgram *program, const std::vector<int> ¶meterIDs,
|
||||
int &textureUnitOffset) const {
|
||||
program->setParameter(parameterIDs[0], m_brightColor.g);
|
||||
program->setParameter(parameterIDs[1], m_darkColor.g);
|
||||
program->setParameter(parameterIDs[0], m_brightColor);
|
||||
program->setParameter(parameterIDs[1], m_darkColor);
|
||||
program->setParameter(parameterIDs[2], m_uvOffset);
|
||||
program->setParameter(parameterIDs[3], m_uvScale);
|
||||
}
|
||||
|
||||
MTS_DECLARE_CLASS()
|
||||
private:
|
||||
Spectrum m_brightColor.g;
|
||||
Spectrum m_darkColor.g;
|
||||
Spectrum m_brightColor;
|
||||
Spectrum m_darkColor;
|
||||
Point2 m_uvOffset;
|
||||
Vector2 m_uvScale;
|
||||
};
|
||||
|
||||
Shader *Checkerboard::createShader(Renderer *renderer) const {
|
||||
return new CheckerboardShader(renderer, m_brightColor.g, m_darkReflectance,
|
||||
return new CheckerboardShader(renderer, m_brightColor, m_darkColor,
|
||||
m_uvOffset, m_uvScale);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue