From abc9048c6806083673b44a6bcf1176bfaadb4335 Mon Sep 17 00:00:00 2001 From: Jere Tuliniemi Date: Mon, 2 Mar 2020 14:39:42 +0200 Subject: Add depth function customization for custom materials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example usage: Task-number: QT3DS-3821 Change-Id: I8cf347026ad51ec80837e7ca87fcd836115c0d74 Reviewed-by: Miikka Heikkinen Reviewed-by: Mahmoud Badri Reviewed-by: Tomi Korpipää --- src/dm/systems/Qt3DSDMMetaData.cpp | 15 +++++++++++++++ .../Qt3DSRenderCustomMaterialSystem.cpp | 12 ++++++++++++ .../Qt3DSRenderDynamicObjectSystem.cpp | 5 +++++ .../Qt3DSRenderDynamicObjectSystemCommands.h | 21 +++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/src/dm/systems/Qt3DSDMMetaData.cpp b/src/dm/systems/Qt3DSDMMetaData.cpp index 6cae7f8..0db75da 100644 --- a/src/dm/systems/Qt3DSDMMetaData.cpp +++ b/src/dm/systems/Qt3DSDMMetaData.cpp @@ -4045,6 +4045,21 @@ public: theDstBlendFuc)); // if we have blending we have transparency theMaterial.m_HasTransparency = true; + } else if (AreEqual("Depth", inStream.GetNarrowElementName())) { + const char8_t *depthFuncStr = ""; + const char8_t *depthMaskStr = ""; + inStream.Att("func", depthFuncStr); + inStream.Att("mask", depthMaskStr); + + qt3ds::render::NVRenderBoolOp::Enum depthFunc + = ParseBoolOp(depthFuncStr); + bool depthMask = true; + + if (AreEqual("false", depthMaskStr)) + depthMask = false; + + theMaterial.m_CustomerMaterialCommands.push_back( + new SApplyDepth(depthFunc, depthMask)); } else if (AreEqual("RenderState", inStream.GetNarrowElementName())) { const char8_t *name = ""; diff --git a/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp b/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp index 496d783..593687b 100644 --- a/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp +++ b/src/runtimerender/Qt3DSRenderCustomMaterialSystem.cpp @@ -1381,6 +1381,13 @@ struct SMaterialSystem : public ICustomMaterialSystem } } + void ApplyDepth(const SApplyDepth &inCommand) + { + NVRenderContext &theContext(m_Context->GetRenderContext()); + theContext.SetDepthFunction(inCommand.m_depthFunc); + theContext.SetDepthWriteEnabled(inCommand.m_depthMask); + } + void ApplyBlending(const SApplyBlending &inCommand) { NVRenderContext &theContext(m_Context->GetRenderContext()); @@ -1847,6 +1854,9 @@ struct SMaterialSystem : public ICustomMaterialSystem case CommandTypes::ApplyBlending: ApplyBlending(static_cast(theCommand)); break; + case CommandTypes::ApplyDepth: + ApplyDepth(static_cast(theCommand)); + break; case CommandTypes::ApplyBufferValue: if (theCurrentShader) ApplyBufferValue(inMaterial, *theCurrentShader->m_Shader, @@ -1870,6 +1880,8 @@ struct SMaterialSystem : public ICustomMaterialSystem theContext.CreateRasterizerState(0.0, 0.0, qt3ds::render::NVRenderFaces::Back); theContext.SetRasterizerState(state); theContext.SetCullingEnabled(true); + theContext.SetDepthFunction(NVRenderBoolOp::LessThanOrEqual); + theContext.SetDepthWriteEnabled(true); // Release any per-frame buffers for (QT3DSU32 idx = 0; idx < m_AllocatedBuffers.size(); ++idx) { diff --git a/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp b/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp index a836989..6553ee9 100644 --- a/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp +++ b/src/runtimerender/Qt3DSRenderDynamicObjectSystem.cpp @@ -90,6 +90,8 @@ namespace render { return sizeof(SApplyDepthValue); case CommandTypes::ApplyInstanceValue: return sizeof(SApplyInstanceValue); + case CommandTypes::ApplyDepth: + return sizeof(SApplyDepth); case CommandTypes::ApplyBlending: return sizeof(SApplyBlending); case CommandTypes::ApplyRenderState: @@ -155,6 +157,9 @@ namespace render { case CommandTypes::ApplyInstanceValue: CopyConstructCommandT(inDataBuffer, inCommand, inStrTable); break; + case CommandTypes::ApplyDepth: + CopyConstructCommandT(inDataBuffer, inCommand, inStrTable); + break; case CommandTypes::ApplyBlending: CopyConstructCommandT(inDataBuffer, inCommand, inStrTable); break; diff --git a/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h b/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h index d42507b..0628d8d 100644 --- a/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h +++ b/src/runtimerender/Qt3DSRenderDynamicObjectSystemCommands.h @@ -54,6 +54,7 @@ namespace render { // Apply the depth buffer as an input texture. ApplyDepthValue, Render, // Render to current FBO + ApplyDepth, ApplyBlending, ApplyRenderState, // apply a render state ApplyBlitFramebuffer, @@ -490,6 +491,26 @@ namespace render { } }; + struct SApplyDepth : public SCommand + { + NVRenderBoolOp::Enum m_depthFunc; + bool m_depthMask; + + SApplyDepth(NVRenderBoolOp::Enum depthFunc, bool depthMask) + : SCommand(CommandTypes::ApplyDepth) + , m_depthFunc(depthFunc) + , m_depthMask(depthMask) + { + } + + SApplyDepth(const SApplyDepth &other, IStringTable &) + : SCommand(CommandTypes::ApplyDepth) + , m_depthFunc(other.m_depthFunc) + , m_depthMask(other.m_depthMask) + { + } + }; + struct SApplyBlending : public SCommand { NVRenderSrcBlendFunc::Enum m_SrcBlendFunc; -- cgit v1.2.3