summaryrefslogtreecommitdiffstats
path: root/src/plugins/renderers/rhi/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/renderers/rhi/renderer')
-rw-r--r--src/plugins/renderers/rhi/renderer/renderview.cpp16
-rw-r--r--src/plugins/renderers/rhi/renderer/renderview_p.h8
2 files changed, 11 insertions, 13 deletions
diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp
index 073c7fb04..bed1ef641 100644
--- a/src/plugins/renderers/rhi/renderer/renderview.cpp
+++ b/src/plugins/renderers/rhi/renderer/renderview.cpp
@@ -142,18 +142,11 @@ static QRectF resolveViewport(const QRectF &fractionalViewport, const QSize &sur
fractionalViewport.height() * surfaceSize.height());
}
-static Matrix4x4 getProjectionMatrix(const CameraLens *lens, bool yIsUp)
+static Matrix4x4 getProjectionMatrix(const CameraLens *lens)
{
Matrix4x4 m;
if (lens)
m = lens->projection();
- if (!yIsUp) {
- const Matrix4x4 rev { 1, 0, 0, 0,
- 0, -1, 0, 0,
- 0, 0, 0.5, 0.5,
- 0, 0, 0, 1 };
- return rev * m;
- }
return m;
}
@@ -1083,7 +1076,10 @@ void RenderView::updateRenderCommand(const EntityRenderCommandDataSubView &subVi
{
// Update RenderViewUBO (Qt3D standard uniforms)
const bool yIsUp = m_renderer->submissionContext()->rhi()->isYUpInNDC();
- const Matrix4x4 projectionMatrix = getProjectionMatrix(m_renderCameraLens, yIsUp);
+
+ const Matrix4x4 clipCorrectionMatrix = Matrix4x4(m_renderer->submissionContext()->rhi()->clipSpaceCorrMatrix());
+ const Matrix4x4 unCorrectedProjectionMatrix = getProjectionMatrix(m_renderCameraLens);
+ const Matrix4x4 projectionMatrix = clipCorrectionMatrix * unCorrectedProjectionMatrix;
const Matrix4x4 inverseViewMatrix = m_viewMatrix.inverted();
const Matrix4x4 inversedProjectionMatrix = projectionMatrix.inverted();
const Matrix4x4 viewProjectionMatrix = (projectionMatrix * m_viewMatrix);
@@ -1091,6 +1087,8 @@ void RenderView::updateRenderCommand(const EntityRenderCommandDataSubView &subVi
{
memcpy(&m_renderViewUBO.viewMatrix, &m_viewMatrix, sizeof(Matrix4x4));
memcpy(&m_renderViewUBO.projectionMatrix, &projectionMatrix, sizeof(Matrix4x4));
+ memcpy(&m_renderViewUBO.clipCorrectionMatrix, &clipCorrectionMatrix, sizeof(Matrix4x4));
+ memcpy(&m_renderViewUBO.uncorrectedProjectionMatrix, &unCorrectedProjectionMatrix, sizeof(Matrix4x4));
memcpy(&m_renderViewUBO.viewProjectionMatrix, &viewProjectionMatrix, sizeof(Matrix4x4));
memcpy(&m_renderViewUBO.inverseViewMatrix, &inverseViewMatrix, sizeof(Matrix4x4));
memcpy(&m_renderViewUBO.inverseProjectionMatrix, &inversedProjectionMatrix,
diff --git a/src/plugins/renderers/rhi/renderer/renderview_p.h b/src/plugins/renderers/rhi/renderer/renderview_p.h
index df5fe0438..dad66d2d5 100644
--- a/src/plugins/renderers/rhi/renderer/renderview_p.h
+++ b/src/plugins/renderers/rhi/renderer/renderview_p.h
@@ -125,13 +125,12 @@ struct Q_AUTOTEST_EXPORT BlitFramebufferInfo
QBlitFramebuffer::InterpolationMethod interpolationMethod;
};
-// This class is kind of analogous to RenderBin but I want to avoid trampling
-// on that until we get this working
-
struct RenderViewUBO
{
float viewMatrix[16];
float projectionMatrix[16];
+ float uncorrectedProjectionMatrix[16];
+ float clipCorrectionMatrix[16];
float viewProjectionMatrix[16];
float inverseViewMatrix[16];
float inverseProjectionMatrix[16];
@@ -147,7 +146,7 @@ struct RenderViewUBO
float yUpInNDC;
float yUpInFBO;
};
-static_assert(sizeof(RenderViewUBO) == sizeof(float) * (8 * 16 + 1 * 4 + 1 * 3 + 6 * 1),
+static_assert(sizeof(RenderViewUBO) == sizeof(float) * (10 * 16 + 1 * 4 + 1 * 3 + 6 * 1),
"UBO doesn't match std140");
class Q_AUTOTEST_EXPORT RenderView
@@ -348,6 +347,7 @@ private:
Qt3DCore::QNodeIdVector m_layerFilterIds;
Matrix4x4 m_viewMatrix;
Matrix4x4 m_viewProjectionMatrix;
+ Matrix4x4 m_clipCorrectionMatrix;
Vector3D m_eyePos;
Vector3D m_eyeViewDir;