summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-08-13 12:47:33 +0200
committerPaul Lemire <paul.lemire@kdab.com>2020-08-13 15:11:03 +0200
commitb807e297beb13532ec09748548e1cfcc5ae6959e (patch)
treec4498c075861a113eb767245407c43572c6c4b03
parentb20d6d35b56c34d87231bc26d789740646984664 (diff)
Add yUpInNDC and yUpInFBO uniforms
This is useful when using RHI as depending on the backend these might have different values and gives a chance to shaders to account for that. Also added to the OpenGL renderer for consistency [ChangeLog] Add yUpInNDC and yUpInFBO default uniforms Change-Id: I76b07906cb2c8e1acb9683428773e27985677df4 Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r--src/plugins/renderers/opengl/renderer/renderview.cpp6
-rw-r--r--src/plugins/renderers/opengl/renderer/renderview_p.h4
-rw-r--r--src/plugins/renderers/rhi/renderer/renderview.cpp5
-rw-r--r--src/plugins/renderers/rhi/renderer/renderview_p.h4
-rw-r--r--src/render/materialsystem/shader.cpp2
-rw-r--r--src/render/materialsystem/shader_p.h2
6 files changed, 21 insertions, 2 deletions
diff --git a/src/plugins/renderers/opengl/renderer/renderview.cpp b/src/plugins/renderers/opengl/renderer/renderview.cpp
index 36d7002b8..66a382742 100644
--- a/src/plugins/renderers/opengl/renderer/renderview.cpp
+++ b/src/plugins/renderers/opengl/renderer/renderview.cpp
@@ -146,6 +146,8 @@ RenderView::StandardUniformsNameToTypeHash RenderView::initializeStandardUniform
setters.insert(Shader::timeNameId, Time);
setters.insert(Shader::eyePositionNameId, EyePosition);
setters.insert(Shader::skinningPaletteNameId, SkinningPalette);
+ setters.insert(Shader::yUpInFBOId, YUpInFBO);
+ setters.insert(Shader::yUpInNDCId, YUpInNDC);
return setters;
}
@@ -233,6 +235,10 @@ UniformValue RenderView::standardUniformValue(RenderView::StandardUniform standa
}
return armature->skinningPaletteUniform();
}
+ case YUpInNDC:
+ return UniformValue(0.0f);
+ case YUpInFBO:
+ return UniformValue(0.0f);
default:
Q_UNREACHABLE();
return UniformValue();
diff --git a/src/plugins/renderers/opengl/renderer/renderview_p.h b/src/plugins/renderers/opengl/renderer/renderview_p.h
index f44d5c3a1..3c1628ba5 100644
--- a/src/plugins/renderers/opengl/renderer/renderview_p.h
+++ b/src/plugins/renderers/opengl/renderer/renderview_p.h
@@ -369,7 +369,9 @@ private:
Exposure,
Gamma,
EyePosition,
- SkinningPalette
+ SkinningPalette,
+ YUpInNDC,
+ YUpInFBO,
};
typedef QHash<int, StandardUniform> StandardUniformsNameToTypeHash;
diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp
index d9adcc9c4..911d38098 100644
--- a/src/plugins/renderers/rhi/renderer/renderview.cpp
+++ b/src/plugins/renderers/rhi/renderer/renderview.cpp
@@ -1104,6 +1104,11 @@ void RenderView::updateRenderCommand(const EntityRenderCommandDataSubView &subVi
memcpy(&m_renderViewUBO.exposure, &exposure, sizeof(float));
const float timeValue = float(m_renderer->time() / 1000000000.0f);
memcpy(&m_renderViewUBO.time, &timeValue, sizeof(float));
+
+ const float yUpNDC = yIsUp ? 1.0f : 0.0f;
+ const float yUpFBO = m_renderer->submissionContext()->rhi()->isYUpInFramebuffer() ? 1.0f : 0.0f;
+ memcpy(&m_renderViewUBO.yUpInNDC, &yUpNDC, sizeof(float));
+ memcpy(&m_renderViewUBO.yUpInFBO, &yUpFBO, sizeof(float));
}
subView.forEach([&] (const Entity *entity,
diff --git a/src/plugins/renderers/rhi/renderer/renderview_p.h b/src/plugins/renderers/rhi/renderer/renderview_p.h
index 7afbcbeec..8600b1591 100644
--- a/src/plugins/renderers/rhi/renderer/renderview_p.h
+++ b/src/plugins/renderers/rhi/renderer/renderview_p.h
@@ -143,8 +143,10 @@ struct RenderViewUBO
float gamma;
float exposure;
float time;
+ float yUpInNDC;
+ float yUpInFBO;
};
-static_assert(sizeof(RenderViewUBO) == sizeof(float) * (8 * 16 + 1 * 4 + 1 * 3 + 4 * 1),
+static_assert(sizeof(RenderViewUBO) == sizeof(float) * (8 * 16 + 1 * 4 + 1 * 3 + 6 * 1),
"UBO doesn't match std140");
class Q_AUTOTEST_EXPORT RenderView
diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp
index 0e777e9aa..e800bcfe5 100644
--- a/src/render/materialsystem/shader.cpp
+++ b/src/render/materialsystem/shader.cpp
@@ -80,6 +80,8 @@ const int Shader::gammaNameId = StringToInt::lookupId(QLatin1String("gamma"));
const int Shader::timeNameId = StringToInt::lookupId(QLatin1String("time"));
const int Shader::eyePositionNameId = StringToInt::lookupId(QLatin1String("eyePosition"));
const int Shader::skinningPaletteNameId = StringToInt::lookupId(QLatin1String("skinningPalette[0]"));
+const int Shader::yUpInFBOId = StringToInt::lookupId(QLatin1String("yUpInFBO"));
+const int Shader::yUpInNDCId = StringToInt::lookupId(QLatin1String("yUpInNDC"));
Shader::Shader()
: BackendNode(ReadWrite)
diff --git a/src/render/materialsystem/shader_p.h b/src/render/materialsystem/shader_p.h
index 94a532d7f..3e1175299 100644
--- a/src/render/materialsystem/shader_p.h
+++ b/src/render/materialsystem/shader_p.h
@@ -92,6 +92,8 @@ public:
static const int timeNameId;
static const int eyePositionNameId;
static const int skinningPaletteNameId;
+ static const int yUpInFBOId;
+ static const int yUpInNDCId;
Shader();
~Shader();