minor bugfixes
parent
f1ae7722dd
commit
d7f913de38
|
@ -388,6 +388,8 @@ public:
|
|||
return result / pdf;
|
||||
}
|
||||
|
||||
Shader *createShader(Renderer *renderer) const;
|
||||
|
||||
std::string toString() const {
|
||||
std::ostringstream oss;
|
||||
oss << "SmoothCoating[" << endl
|
||||
|
@ -411,6 +413,51 @@ protected:
|
|||
Float m_thickness;
|
||||
};
|
||||
|
||||
// ================ Hardware shader implementation ================
|
||||
|
||||
/* Crude GLSL approximation -- just forwards to the nested model */
|
||||
class SmoothCoatingShader : public Shader {
|
||||
public:
|
||||
SmoothCoatingShader(Renderer *renderer, const BSDF *nested)
|
||||
: Shader(renderer, EBSDFShader), m_nested(nested) {
|
||||
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 << "vec3 " << evalName << "(vec2 uv, vec3 wi, vec3 wo) {" << endl
|
||||
<< " return " << depNames[0] << "(uv, wi, wo);" << endl
|
||||
<< "}" << endl
|
||||
<< endl
|
||||
<< "vec3 " << evalName << "_diffuse(vec2 uv, vec3 wi, vec3 wo) {" << endl
|
||||
<< " return " << depNames[0] << "_diffuse(uv, wi, wo);" << endl
|
||||
<< "}" << endl;
|
||||
}
|
||||
|
||||
MTS_DECLARE_CLASS()
|
||||
private:
|
||||
ref<const BSDF> m_nested;
|
||||
ref<Shader> m_nestedShader;
|
||||
};
|
||||
|
||||
Shader *SmoothCoating::createShader(Renderer *renderer) const {
|
||||
return new SmoothCoatingShader(renderer, m_nested.get());
|
||||
}
|
||||
|
||||
MTS_IMPLEMENT_CLASS(SmoothCoatingShader, false, Shader)
|
||||
MTS_IMPLEMENT_CLASS_S(SmoothCoating, false, BSDF)
|
||||
MTS_EXPORT_PLUGIN(SmoothCoating, "Smooth dielectric coating");
|
||||
MTS_NAMESPACE_END
|
||||
|
|
|
@ -299,53 +299,63 @@ void VPLShaderManager::setVPL(const VPL &vpl) {
|
|||
m_shadowMap->activateSide(-1);
|
||||
m_shadowMap->clear();
|
||||
m_shadowProgram->bind();
|
||||
for (int i=0; i<6; ++i) {
|
||||
switch (i) {
|
||||
case 0: lightViewTrafo = Transform::lookAt(p, p + Vector(1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 1: lightViewTrafo = Transform::lookAt(p, p + Vector(-1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 2: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 1, 0), Vector(0, 0, -1)).inverse(); break;
|
||||
case 3: lightViewTrafo = Transform::lookAt(p, p + Vector(0, -1, 0), Vector(0, 0, 1)).inverse(); break;
|
||||
case 4: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, 1), Vector(0, 1, 0)).inverse(); break;
|
||||
case 5: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, -1), Vector(0, 1, 0)).inverse(); break;
|
||||
try {
|
||||
for (int i=0; i<6; ++i) {
|
||||
switch (i) {
|
||||
case 0: lightViewTrafo = Transform::lookAt(p, p + Vector(1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 1: lightViewTrafo = Transform::lookAt(p, p + Vector(-1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 2: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 1, 0), Vector(0, 0, -1)).inverse(); break;
|
||||
case 3: lightViewTrafo = Transform::lookAt(p, p + Vector(0, -1, 0), Vector(0, 0, 1)).inverse(); break;
|
||||
case 4: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, 1), Vector(0, 1, 0)).inverse(); break;
|
||||
case 5: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, -1), Vector(0, 1, 0)).inverse(); break;
|
||||
}
|
||||
lightViewTrafo = Transform::scale(Vector(-1, 1, 1)) * lightViewTrafo;
|
||||
const Matrix4x4 &viewMatrix = lightViewTrafo.getMatrix();
|
||||
m_shadowProgram->setParameter(m_shadowProgramParam_cubeMapTransform[i], lightProjTrafo * lightViewTrafo);
|
||||
m_shadowProgram->setParameter(m_shadowProgramParam_depthVec[i], Vector4(
|
||||
-viewMatrix.m[2][0] * m_invClipRange,
|
||||
-viewMatrix.m[2][1] * m_invClipRange,
|
||||
-viewMatrix.m[2][2] * m_invClipRange,
|
||||
(-viewMatrix.m[2][3] - m_nearClip) * m_invClipRange
|
||||
));
|
||||
}
|
||||
lightViewTrafo = Transform::scale(Vector(-1, 1, 1)) * lightViewTrafo;
|
||||
const Matrix4x4 &viewMatrix = lightViewTrafo.getMatrix();
|
||||
m_shadowProgram->setParameter(m_shadowProgramParam_cubeMapTransform[i], lightProjTrafo * lightViewTrafo);
|
||||
m_shadowProgram->setParameter(m_shadowProgramParam_depthVec[i], Vector4(
|
||||
-viewMatrix.m[2][0] * m_invClipRange,
|
||||
-viewMatrix.m[2][1] * m_invClipRange,
|
||||
-viewMatrix.m[2][2] * m_invClipRange,
|
||||
(-viewMatrix.m[2][3] - m_nearClip) * m_invClipRange
|
||||
));
|
||||
m_renderer->drawAll(m_drawList);
|
||||
} catch (const std::exception &ex) {
|
||||
m_shadowProgram->unbind();
|
||||
throw ex;
|
||||
}
|
||||
m_renderer->drawAll(m_drawList);
|
||||
m_shadowProgram->unbind();
|
||||
} else {
|
||||
/* Old-fashioned: render 6 times, once for each cube map face */
|
||||
m_altShadowProgram->bind();
|
||||
for (int i=0; i<6; ++i) {
|
||||
switch (i) {
|
||||
case 0: lightViewTrafo = Transform::lookAt(p, p + Vector(1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 1: lightViewTrafo = Transform::lookAt(p, p + Vector(-1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 2: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 1, 0), Vector(0, 0, -1)).inverse(); break;
|
||||
case 3: lightViewTrafo = Transform::lookAt(p, p + Vector(0, -1, 0), Vector(0, 0, 1)).inverse(); break;
|
||||
case 4: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, 1), Vector(0, 1, 0)).inverse(); break;
|
||||
case 5: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, -1), Vector(0, 1, 0)).inverse(); break;
|
||||
try {
|
||||
for (int i=0; i<6; ++i) {
|
||||
switch (i) {
|
||||
case 0: lightViewTrafo = Transform::lookAt(p, p + Vector(1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 1: lightViewTrafo = Transform::lookAt(p, p + Vector(-1, 0, 0), Vector(0, 1, 0)).inverse(); break;
|
||||
case 2: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 1, 0), Vector(0, 0, -1)).inverse(); break;
|
||||
case 3: lightViewTrafo = Transform::lookAt(p, p + Vector(0, -1, 0), Vector(0, 0, 1)).inverse(); break;
|
||||
case 4: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, 1), Vector(0, 1, 0)).inverse(); break;
|
||||
case 5: lightViewTrafo = Transform::lookAt(p, p + Vector(0, 0, -1), Vector(0, 1, 0)).inverse(); break;
|
||||
}
|
||||
lightViewTrafo = Transform::scale(Vector(-1, 1, 1)) * lightViewTrafo;
|
||||
const Matrix4x4 &viewMatrix = lightViewTrafo.getMatrix();
|
||||
|
||||
m_altShadowProgram->setParameter(m_altShadowProgramParam_cubeMapTransform, lightProjTrafo * lightViewTrafo);
|
||||
m_altShadowProgram->setParameter(m_altShadowProgramParam_depthVec, Vector4(
|
||||
-viewMatrix.m[2][0] * m_invClipRange,
|
||||
-viewMatrix.m[2][1] * m_invClipRange,
|
||||
-viewMatrix.m[2][2] * m_invClipRange,
|
||||
(-viewMatrix.m[2][3] - m_nearClip) * m_invClipRange
|
||||
));
|
||||
|
||||
m_shadowMap->activateSide(i);
|
||||
m_shadowMap->clear();
|
||||
m_renderer->drawAll(m_drawList);
|
||||
}
|
||||
lightViewTrafo = Transform::scale(Vector(-1, 1, 1)) * lightViewTrafo;
|
||||
const Matrix4x4 &viewMatrix = lightViewTrafo.getMatrix();
|
||||
|
||||
m_altShadowProgram->setParameter(m_altShadowProgramParam_cubeMapTransform, lightProjTrafo * lightViewTrafo);
|
||||
m_altShadowProgram->setParameter(m_altShadowProgramParam_depthVec, Vector4(
|
||||
-viewMatrix.m[2][0] * m_invClipRange,
|
||||
-viewMatrix.m[2][1] * m_invClipRange,
|
||||
-viewMatrix.m[2][2] * m_invClipRange,
|
||||
(-viewMatrix.m[2][3] - m_nearClip) * m_invClipRange
|
||||
));
|
||||
|
||||
m_shadowMap->activateSide(i);
|
||||
m_shadowMap->clear();
|
||||
m_renderer->drawAll(m_drawList);
|
||||
} catch (std::exception &ex) {
|
||||
m_altShadowProgram->unbind();
|
||||
throw ex;
|
||||
}
|
||||
|
||||
m_altShadowProgram->unbind();
|
||||
|
|
|
@ -475,7 +475,12 @@ void PreviewThread::oglRenderVPL(PreviewQueueEntry &target, const VPL &vpl) {
|
|||
const std::vector<std::pair<const TriMesh *, Transform> > meshes = m_shaderManager->getMeshes();
|
||||
const std::vector<std::pair<const TriMesh *, Transform> > transpMeshes = m_shaderManager->getTransparentMeshes();
|
||||
|
||||
m_shaderManager->setVPL(vpl);
|
||||
try {
|
||||
m_shaderManager->setVPL(vpl);
|
||||
} catch (std::exception &ex) {
|
||||
/* Fail */
|
||||
return;
|
||||
}
|
||||
|
||||
Point2 jitter(.5f, .5f);
|
||||
if (!m_motion && !m_context->showKDTree && m_accumBuffer != NULL)
|
||||
|
|
|
@ -302,12 +302,6 @@ void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
|
|||
|
||||
QDomElement oldIntegratorNode = findUniqueChild(root, "integrator");
|
||||
QDomElement newIntegratorNode = doc.createElement("integrator");
|
||||
if (oldIntegratorNode.isNull()) {
|
||||
film.appendChild(oldIntegratorNode);
|
||||
} else {
|
||||
film.insertAfter(newIntegratorNode, oldIntegratorNode);
|
||||
film.removeChild(oldIntegratorNode);
|
||||
}
|
||||
|
||||
const Integrator *integrator = ctx->scene->getIntegrator();
|
||||
setProperties(doc, newIntegratorNode, integrator->getProperties());
|
||||
|
@ -321,7 +315,7 @@ void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
|
|||
currentIntegratorNode = childIntegratorNode;
|
||||
}
|
||||
|
||||
root.insertAfter(newIntegratorNode, oldIntegratorNode);
|
||||
root.insertBefore(newIntegratorNode, oldIntegratorNode);
|
||||
root.removeChild(oldIntegratorNode);
|
||||
|
||||
file.setFileName(targetFile);
|
||||
|
@ -337,6 +331,7 @@ void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
|
|||
Beware: the code below is tailored to Qt's
|
||||
output and won't work on arbitrary XML files */
|
||||
QString textContent = doc.toString();
|
||||
cout << qPrintable(textContent) << endl;
|
||||
QTextStream input(&textContent);
|
||||
QTextStream output(&file);
|
||||
QRegExp
|
||||
|
@ -422,6 +417,8 @@ void saveScene(QWidget *parent, SceneContext *ctx, const QString &targetFile) {
|
|||
} else if (line.endsWith(" />")) {
|
||||
line = line.left(line.size()-3) + QString("/>");
|
||||
hasContents = true;
|
||||
} else if (line.endsWith("/>")) {
|
||||
hasContents = true;
|
||||
} else if (line.endsWith(" >")) {
|
||||
line = line.left(line.size()-2) + QString(">");
|
||||
}
|
||||
|
|
|
@ -37,6 +37,10 @@ public:
|
|||
unsigned int p[3];
|
||||
unsigned int n[3];
|
||||
unsigned int uv[3];
|
||||
|
||||
inline OBJTriangle() {
|
||||
memset(this, 0, sizeof(OBJTriangle));
|
||||
}
|
||||
};
|
||||
|
||||
bool fetch_line(std::istream &is, std::string &line) {
|
||||
|
@ -369,12 +373,12 @@ public:
|
|||
else
|
||||
vertex.p = objectToWorld(vertices.at(vertexId));
|
||||
|
||||
if (hasNormals && normals.at(normalId) != Normal(0.0f))
|
||||
if (hasNormals && normalId >= 0 && normals.at(normalId) != Normal(0.0f))
|
||||
vertex.n = normalize(objectToWorld(normals.at(normalId)));
|
||||
else
|
||||
vertex.n = Normal(0.0f);
|
||||
|
||||
if (hasTexcoords)
|
||||
if (hasTexcoords && uvId >= 0)
|
||||
vertex.uv = texcoords.at(uvId);
|
||||
else
|
||||
vertex.uv = Point2(0.0f);
|
||||
|
|
Loading…
Reference in New Issue