diff options
author | Määttä Antti <antti.maatta@qt.io> | 2018-05-31 14:56:38 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-06-01 04:08:54 +0000 |
commit | 8fc0026450fbd9c4591561874578001483cabacb (patch) | |
tree | b27c5e2b53b5d4a6b4df26e57cb6a43fdf8dc5ce /src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl | |
parent | a465515bcd856d355f92255d4c0034e0d2aeda24 (diff) |
Fix lighting with custom material and shadows
There are two problems with the shadows.
1. The shader cache key for default materials is not properly initialized,
which causes invalid shader being used for the material.
2. Custom material shadow cubes and maps uniforms are not set correctly.
Only first element in those sampler arrays were set, so when custom material
lighting had more then 1 light and shadows, only one light affected the
rendered result.
Fixed the default material key and implemented proper setters for sampler
uniforms.
Task-number: QT3DS-1824
Change-Id: I0b97a4642410f37011392adf1020bc1d2bd21bb3
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl')
2 files changed, 30 insertions, 29 deletions
diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp index 52423df3..51bff7f4 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderData.cpp @@ -693,6 +693,9 @@ namespace render { | qt3ds::render::NVRenderClearValues::Color); for (QT3DSU32 i = 0; i < m_Lights.size(); i++) { + // don't render shadows when not casting + if (m_Lights[i]->m_CastShadow == false) + continue; SShadowMapEntry *pEntry = m_ShadowMapManager->GetShadowMapEntry(i); if (pEntry && pEntry->m_DepthMap && pEntry->m_DepthCopy && pEntry->m_DepthRender) { SCamera theCamera; diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderPreparationData.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderPreparationData.cpp index 3275d889..aa1606d6 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderPreparationData.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplLayerRenderPreparationData.cpp @@ -319,13 +319,14 @@ namespace render { SLayerRenderPreparationData::GenerateLightingKey(DefaultMaterialLighting::Enum inLightingType) { SShaderDefaultMaterialKey theGeneratedKey(GetShaderFeatureSetHash()); - if (inLightingType != DefaultMaterialLighting::NoLighting) { - m_Renderer.DefaultMaterialShaderKeyProperties().m_HasLighting.SetValue(theGeneratedKey, - true); - - if (m_Layer.m_LightProbe && m_Layer.m_LightProbe->m_TextureData.m_Texture) - m_Renderer.DefaultMaterialShaderKeyProperties().m_HasIbl.SetValue(theGeneratedKey, - true); + const bool lighting = inLightingType != DefaultMaterialLighting::NoLighting; + m_Renderer.DefaultMaterialShaderKeyProperties().m_HasLighting.SetValue(theGeneratedKey, + lighting); + if (lighting) { + const bool lightProbe = m_Layer.m_LightProbe + && m_Layer.m_LightProbe->m_TextureData.m_Texture; + m_Renderer.DefaultMaterialShaderKeyProperties().m_HasIbl.SetValue(theGeneratedKey, + lightProbe); QT3DSU32 numLights = (QT3DSU32)m_Lights.size(); if (numLights > SShaderDefaultMaterialKeyProperties::LightCount @@ -338,19 +339,20 @@ namespace render { m_Renderer.DefaultMaterialShaderKeyProperties().m_LightCount.SetValue(theGeneratedKey, numLights); - for (QT3DSU32 lightIdx = 0, lightEnd = m_Lights.size(); lightIdx < lightEnd; ++lightIdx) { + for (QT3DSU32 lightIdx = 0, lightEnd = m_Lights.size(); + lightIdx < lightEnd; ++lightIdx) { SLight *theLight(m_Lights[lightIdx]); - if (theLight->m_LightType != RenderLightTypes::Directional) - m_Renderer.DefaultMaterialShaderKeyProperties().m_LightFlags[lightIdx].SetValue( - theGeneratedKey, true); - if (theLight->m_LightType == RenderLightTypes::Area) - m_Renderer.DefaultMaterialShaderKeyProperties() - .m_LightAreaFlags[lightIdx] - .SetValue(theGeneratedKey, true); - if ((theLight->m_LightType != RenderLightTypes::Point) && (theLight->m_CastShadow)) - m_Renderer.DefaultMaterialShaderKeyProperties() - .m_LightShadowFlags[lightIdx] - .SetValue(theGeneratedKey, true); + const bool isDirectional = theLight->m_LightType == RenderLightTypes::Directional; + const bool isArea = theLight->m_LightType == RenderLightTypes::Area; + const bool castShadowsArea = (theLight->m_LightType != RenderLightTypes::Area) + && (theLight->m_CastShadow); + + m_Renderer.DefaultMaterialShaderKeyProperties().m_LightFlags[lightIdx] + .SetValue(theGeneratedKey, !isDirectional); + m_Renderer.DefaultMaterialShaderKeyProperties().m_LightAreaFlags[lightIdx] + .SetValue(theGeneratedKey, isArea); + m_Renderer.DefaultMaterialShaderKeyProperties().m_LightShadowFlags[lightIdx] + .SetValue(theGeneratedKey, castShadowsArea); } } return theGeneratedKey; @@ -682,22 +684,18 @@ namespace render { } bool specularEnabled = theMaterial->IsSpecularEnabled(); + m_Renderer.DefaultMaterialShaderKeyProperties().m_SpecularEnabled.SetValue( + theGeneratedKey, specularEnabled); if (specularEnabled) { - m_Renderer.DefaultMaterialShaderKeyProperties().m_SpecularEnabled.SetValue( - theGeneratedKey, true); m_Renderer.DefaultMaterialShaderKeyProperties().m_SpecularModel.SetSpecularModel( theGeneratedKey, theMaterial->m_SpecularModel); } - if (theMaterial->IsFresnelEnabled()) { - m_Renderer.DefaultMaterialShaderKeyProperties().m_FresnelEnabled.SetValue( - theGeneratedKey, true); - } + m_Renderer.DefaultMaterialShaderKeyProperties().m_FresnelEnabled.SetValue( + theGeneratedKey, theMaterial->IsFresnelEnabled()); - if (theMaterial->IsVertexColorsEnabled()) { - m_Renderer.DefaultMaterialShaderKeyProperties().m_VertexColorsEnabled.SetValue( - theGeneratedKey, true); - } + m_Renderer.DefaultMaterialShaderKeyProperties().m_VertexColorsEnabled.SetValue( + theGeneratedKey, theMaterial->IsVertexColorsEnabled()); // Run through the material's images and prepare them for render. // this may in fact set pickable on the renderable flags if one of the images |