summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2018-12-20 15:25:13 +0000
committerMike Krus <mike.krus@kdab.com>2019-01-09 14:30:14 +0000
commit82eb8b44e0a3d1dc586acc52132be2b05102900c (patch)
tree7bec340b449352c43ae604322c0631dd2b59b426
parent9d61881e4bcaebd6f98e647163f1df6b5082a6a8 (diff)
Fix env-map less rendering
Assign texture units to env map samplers even if they are not used. Remove previous work around from pbr material. Change-Id: I5060bfb61c4658339d2b74df71574c39cddfeb18 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/extras/defaults/qmetalroughmaterial.cpp24
-rw-r--r--src/extras/defaults/qmetalroughmaterial_p.h4
-rw-r--r--src/render/renderers/opengl/renderer/renderview.cpp7
3 files changed, 7 insertions, 28 deletions
diff --git a/src/extras/defaults/qmetalroughmaterial.cpp b/src/extras/defaults/qmetalroughmaterial.cpp
index de21268f1..f52437769 100644
--- a/src/extras/defaults/qmetalroughmaterial.cpp
+++ b/src/extras/defaults/qmetalroughmaterial.cpp
@@ -61,8 +61,6 @@ namespace Qt3DExtras {
QMetalRoughMaterialPrivate::QMetalRoughMaterialPrivate()
: QMaterialPrivate()
- , m_environmentIrradianceTexture(new QTexture2D())
- , m_environmentSpecularTexture(new QTexture2D())
, m_baseColorParameter(new QParameter(QStringLiteral("baseColor"), QColor("grey")))
, m_metalnessParameter(new QParameter(QStringLiteral("metalness"), 0.0f))
, m_roughnessParameter(new QParameter(QStringLiteral("roughness"), 0.0f))
@@ -72,8 +70,6 @@ QMetalRoughMaterialPrivate::QMetalRoughMaterialPrivate()
, m_ambientOcclusionMapParameter(new QParameter(QStringLiteral("ambientOcclusionMap"), QVariant()))
, m_normalMapParameter(new QParameter(QStringLiteral("normalMap"), QVariant()))
, m_textureScaleParameter(new QParameter(QStringLiteral("texCoordScale"), 1.0f))
- , m_environmentIrradianceParameter(new QParameter(QStringLiteral("envLight.irradiance"), m_environmentIrradianceTexture))
- , m_environmentSpecularParameter(new QParameter(QStringLiteral("envLight.specular"), m_environmentSpecularTexture))
, m_metalRoughEffect(new QEffect())
, m_metalRoughGL3Technique(new QTechnique())
, m_metalRoughGL3RenderPass(new QRenderPass())
@@ -85,17 +81,6 @@ QMetalRoughMaterialPrivate::QMetalRoughMaterialPrivate()
, m_metalRoughES3ShaderBuilder(new QShaderProgramBuilder())
, m_filterKey(new QFilterKey)
{
- m_environmentIrradianceTexture->setMagnificationFilter(QAbstractTexture::Linear);
- m_environmentIrradianceTexture->setMinificationFilter(QAbstractTexture::LinearMipMapLinear);
- m_environmentIrradianceTexture->setWrapMode(QTextureWrapMode(QTextureWrapMode::Repeat));
- m_environmentIrradianceTexture->setGenerateMipMaps(true);
- m_environmentIrradianceTexture->setMaximumAnisotropy(16.0f);
-
- m_environmentSpecularTexture->setMagnificationFilter(QAbstractTexture::Linear);
- m_environmentSpecularTexture->setMinificationFilter(QAbstractTexture::LinearMipMapLinear);
- m_environmentSpecularTexture->setWrapMode(QTextureWrapMode(QTextureWrapMode::Repeat));
- m_environmentSpecularTexture->setGenerateMipMaps(true);
- m_environmentSpecularTexture->setMaximumAnisotropy(16.0f);
}
void QMetalRoughMaterialPrivate::init()
@@ -163,15 +148,6 @@ void QMetalRoughMaterialPrivate::init()
m_metalRoughEffect->addParameter(m_roughnessParameter);
m_metalRoughEffect->addParameter(m_textureScaleParameter);
- // Note that even though those parameters are not exposed in the API,
- // they need to be kept around for now due to a bug in some drivers/GPUs
- // (at least Intel) which cause issues with unbound textures even if you
- // don't try to sample from them.
- // Can probably go away once we generate the shaders and deal in this
- // case in a better way.
- m_metalRoughEffect->addParameter(m_environmentIrradianceParameter);
- m_metalRoughEffect->addParameter(m_environmentSpecularParameter);
-
q->setEffect(m_metalRoughEffect);
}
diff --git a/src/extras/defaults/qmetalroughmaterial_p.h b/src/extras/defaults/qmetalroughmaterial_p.h
index e12df1a8b..4d8b68320 100644
--- a/src/extras/defaults/qmetalroughmaterial_p.h
+++ b/src/extras/defaults/qmetalroughmaterial_p.h
@@ -81,8 +81,6 @@ public:
void handleTextureScaleChanged(const QVariant &var);
- Qt3DRender::QAbstractTexture *m_environmentIrradianceTexture;
- Qt3DRender::QAbstractTexture *m_environmentSpecularTexture;
Qt3DRender::QParameter *m_baseColorParameter;
Qt3DRender::QParameter *m_metalnessParameter;
Qt3DRender::QParameter *m_roughnessParameter;
@@ -92,8 +90,6 @@ public:
Qt3DRender::QParameter *m_ambientOcclusionMapParameter;
Qt3DRender::QParameter *m_normalMapParameter;
Qt3DRender::QParameter *m_textureScaleParameter;
- Qt3DRender::QParameter *m_environmentIrradianceParameter;
- Qt3DRender::QParameter *m_environmentSpecularParameter;
Qt3DRender::QEffect *m_metalRoughEffect;
Qt3DRender::QTechnique *m_metalRoughGL3Technique;
Qt3DRender::QRenderPass *m_metalRoughGL3RenderPass;
diff --git a/src/render/renderers/opengl/renderer/renderview.cpp b/src/render/renderers/opengl/renderer/renderview.cpp
index 66299e430..8e0c16938 100644
--- a/src/render/renderers/opengl/renderer/renderview.cpp
+++ b/src/render/renderers/opengl/renderer/renderview.cpp
@@ -1060,6 +1060,13 @@ void RenderView::setShaderAndUniforms(RenderCommand *command,
setDefaultUniformBlockShaderDataValue(command->m_parameterPack, shader, shaderData, QStringLiteral("envLight"));
envLightCount = 1;
}
+ } else {
+ // with some drivers, samplers (like the envbox sampler) need to be bound even though
+ // they may not be actually used, otherwise draw calls can fail
+ static const int irradianceId = StringToInt::lookupId(QLatin1String("envLight.irradiance"));
+ static const int specularId = StringToInt::lookupId(QLatin1String("envLight.specular"));
+ setUniformValue(command->m_parameterPack, irradianceId, m_renderer->submissionContext()->maxTextureUnitsCount());
+ setUniformValue(command->m_parameterPack, specularId, m_renderer->submissionContext()->maxTextureUnitsCount());
}
setUniformValue(command->m_parameterPack, StringToInt::lookupId(QStringLiteral("envLightCount")), envLightCount);
}