summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-08-04 08:11:00 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-08-08 21:23:36 +0000
commit04a8dd84be40deab6ab6ae2958db79925e03cbb9 (patch)
tree61d5a7dd177fd38ac0dea55fbe3787552bb4c164
parentc3e3f8ccf6f5a2f4439b0d083cf38df8423425bf (diff)
Set the viewProjection and its inverse as uniforms if used
These are useful for performing ray marching in the fragment shader and for mapping from screenspace or NDC to world space in general. Change-Id: I1f273f16c85cdf6c46c03a63f80a6202305c7eaa Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/render/backend/renderview.cpp15
-rw-r--r--src/render/backend/renderview_p.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index 8d40f2882..0c45366c4 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -114,12 +114,14 @@ RenderView::StandardUniformsPFuncsHash RenderView::initializeStandardUniformSett
setters.insert(StringToInt::lookupId(QLatin1String("viewMatrix")), &RenderView::viewMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("projectionMatrix")), &RenderView::projectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("modelView")), &RenderView::modelViewMatrix);
+ setters.insert(StringToInt::lookupId(QLatin1String("viewProjectionMatrix")), &RenderView::viewProjectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("modelViewProjection")), &RenderView::modelViewProjectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("mvp")), &RenderView::modelViewProjectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("inverseModelMatrix")), &RenderView::inverseModelMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("inverseViewMatrix")), &RenderView::inverseViewMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("inverseProjectionMatrix")), &RenderView::inverseProjectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("inverseModelView")), &RenderView::inverseModelViewMatrix);
+ setters.insert(StringToInt::lookupId(QLatin1String("inverseViewProjectionMatrix")), &RenderView::inverseViewProjectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("inverseModelViewProjection")), &RenderView::inverseModelViewProjectionMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("modelNormalMatrix")), &RenderView::modelNormalMatrix);
setters.insert(StringToInt::lookupId(QLatin1String("modelViewNormal")), &RenderView::modelViewNormalMatrix);
@@ -151,6 +153,12 @@ QUniformValue RenderView::modelViewMatrix(const QMatrix4x4 &model) const
return QUniformValue(QVariant::fromValue(m_data.m_viewMatrix * model));
}
+QUniformValue RenderView::viewProjectionMatrix(const QMatrix4x4 &model) const
+{
+ Q_UNUSED(model);
+ return QUniformValue(QVariant::fromValue(m_data.m_renderCameraLens->projection() * m_data.m_viewMatrix));
+}
+
QUniformValue RenderView::modelViewProjectionMatrix(const QMatrix4x4 &model) const
{
return QUniformValue(QVariant::fromValue(m_data.m_viewProjectionMatrix * model));
@@ -179,6 +187,13 @@ QUniformValue RenderView::inverseModelViewMatrix(const QMatrix4x4 &model) const
return QUniformValue(QVariant::fromValue((m_data.m_viewMatrix * model).inverted()));
}
+QUniformValue RenderView::inverseViewProjectionMatrix(const QMatrix4x4 &model) const
+{
+ Q_UNUSED(model);
+ const auto viewProjectionMatrix = m_data.m_renderCameraLens->projection() * m_data.m_viewMatrix;
+ return QUniformValue(QVariant::fromValue(viewProjectionMatrix.inverted()));
+}
+
QUniformValue RenderView::inverseModelViewProjectionMatrix(const QMatrix4x4 &model) const
{
return QUniformValue(QVariant::fromValue((m_data.m_viewProjectionMatrix * model).inverted(0)));
diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h
index 0b01744e9..1e943a80b 100644
--- a/src/render/backend/renderview_p.h
+++ b/src/render/backend/renderview_p.h
@@ -282,11 +282,13 @@ private:
QUniformValue viewMatrix(const QMatrix4x4&) const;
QUniformValue projectionMatrix(const QMatrix4x4 &) const;
QUniformValue modelViewMatrix(const QMatrix4x4 &model) const;
+ QUniformValue viewProjectionMatrix(const QMatrix4x4 &model) const;
QUniformValue modelViewProjectionMatrix(const QMatrix4x4 &model) const;
QUniformValue inverseModelMatrix(const QMatrix4x4 &model) const;
QUniformValue inverseViewMatrix(const QMatrix4x4 &) const;
QUniformValue inverseProjectionMatrix(const QMatrix4x4 &) const;
QUniformValue inverseModelViewMatrix(const QMatrix4x4 &model) const;
+ QUniformValue inverseViewProjectionMatrix(const QMatrix4x4 &model) const;
QUniformValue inverseModelViewProjectionMatrix(const QMatrix4x4 &model) const;
QUniformValue modelNormalMatrix(const QMatrix4x4 &model) const;
QUniformValue modelViewNormalMatrix(const QMatrix4x4 &model) const;