From 4abc028ccbeef12f94d0588701b44675d01dcdc4 Mon Sep 17 00:00:00 2001 From: cary <39078800+caryliu1999@users.noreply.github.com> Date: Wed, 9 Sep 2020 13:40:32 +0800 Subject: [PATCH] Change skybox and shadow to buffer pool. (#2762) --- .../pipeline/forward/ForwardPipeline.cpp | 2 +- .../pipeline/forward/ForwardPipeline.h | 8 ++--- .../pipeline/forward/SceneCulling.cpp | 3 +- .../renderer/pipeline/helper/SharedMemory.cpp | 8 ++--- .../renderer/pipeline/helper/SharedMemory.h | 35 ++++++++++++------- .../renderer/pipeline/shadow/ShadowFlow.cpp | 4 +-- .../renderer/pipeline/shadow/ShadowStage.cpp | 2 +- native/cocos/scripting/dop/PoolType.h | 8 +++-- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp index 5833ae508d..ad506d6f59 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp @@ -116,7 +116,7 @@ void ForwardPipeline::updateUBOs(RenderView *view) { updateUBO(view); const auto scene = GET_SCENE(view->getCamera()->getSceneID()); const auto mainLight = GET_MAIN_LIGHT(scene->mainLightID); - const auto shadowInfo = _shadowMap; + const auto shadowInfo = _shadows; if (mainLight && shadowInfo->enabled) { const auto node = GET_NODE(mainLight->nodeID); diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.h b/native/cocos/renderer/pipeline/forward/ForwardPipeline.h index 814936f01d..54f18798b1 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.h +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.h @@ -10,8 +10,7 @@ struct UBOShadow; struct Fog; struct Ambient; struct Skybox; -struct PlanarShadow; -struct ShadowMap; +struct Shadows; class CC_DLL ForwardPipeline : public RenderPipeline { public: @@ -39,7 +38,7 @@ public: CC_INLINE float getShadingScale() const { return _shadingScale; } CC_INLINE float getFpScale() const { return _fpScale; } CC_INLINE bool isHDR() const { return _isHDR; } - CC_INLINE const ShadowMap *getShadowMap() const { return _shadowMap; } + CC_INLINE const Shadows *getShadows() const { return _shadows; } void setRenderObjcts(const RenderObjectList &ro) { _renderObjects = std::move(ro); } void setShadowObjects(const RenderObjectList &ro) { _shadowObjects = std::move(ro); } @@ -52,8 +51,7 @@ private: Fog *_fog = nullptr; Ambient *_ambient = nullptr; Skybox *_skybox = nullptr; - PlanarShadow *_planarShadow = nullptr; - ShadowMap *_shadowMap = nullptr; + Shadows *_shadows = nullptr; gfx::Buffer *_lightsUBO = nullptr; LightList _validLights; gfx::BufferList _lightBuffers; diff --git a/native/cocos/renderer/pipeline/forward/SceneCulling.cpp b/native/cocos/renderer/pipeline/forward/SceneCulling.cpp index 983a4261fc..3bf0c4f5d4 100644 --- a/native/cocos/renderer/pipeline/forward/SceneCulling.cpp +++ b/native/cocos/renderer/pipeline/forward/SceneCulling.cpp @@ -27,7 +27,6 @@ void sceneCulling(ForwardPipeline *pipeline, RenderView *view) { RenderObjectList shadowObjects; const auto mainLight = GET_MAIN_LIGHT(scene->mainLightID); - const auto planarShadows = GET_PLANAR_SHADOW(scene->planarShadowID); if (mainLight) { //TODO coulsonwang // if (planarShadows.enabled) { @@ -36,7 +35,7 @@ void sceneCulling(ForwardPipeline *pipeline, RenderView *view) { } if (GET_SKYBOX(scene->skyboxID)->enabled && (camera->getClearFlag() & SKYBOX_FLAG)) { - renderObjects.emplace_back(genRenderObject(GET_SKYBOX(scene->skyboxID), camera)); + renderObjects.emplace_back(genRenderObject(GET_MODEL(GET_SKYBOX(scene->skyboxID)->model), camera)); } const auto stamp = Application::getInstance()->getTotalFrames(); diff --git a/native/cocos/renderer/pipeline/helper/SharedMemory.cpp b/native/cocos/renderer/pipeline/helper/SharedMemory.cpp index 6299ceb472..f670f93e1b 100644 --- a/native/cocos/renderer/pipeline/helper/SharedMemory.cpp +++ b/native/cocos/renderer/pipeline/helper/SharedMemory.cpp @@ -11,8 +11,9 @@ const se::PoolType AABB::type = se::PoolType::AABB; const se::PoolType Frustum::type = se::PoolType::FRUSTUM; const se::PoolType Scene::type = se::PoolType::SCENE; const se::PoolType MainLight::type = se::PoolType::UNKNOWN; -const se::PoolType Ambient::type = se::PoolType::UNKNOWN; -const se::PoolType Fog::type = se::PoolType::UNKNOWN; +const se::PoolType Ambient::type = se::PoolType::AMBIENT; +const se::PoolType Fog::type = se::PoolType::FOG; +const se::PoolType Skybox::type = se::PoolType::SKYBOX; const se::PoolType InstancedAttribute::type = se::PoolType::UNKNOWN; const se::PoolType BufferView::type = se::PoolType::UNKNOWN; const se::PoolType FlatBuffer::type = se::PoolType::UNKNOWN; @@ -20,7 +21,6 @@ const se::PoolType RenderingSubMesh::type = se::PoolType::UNKNOWN; const se::PoolType Node::type = se::PoolType::NODE; const se::PoolType Root::type = se::PoolType::ROOT; const se::PoolType RenderWindow::type = se::PoolType::RENDER_WINDOW; -const se::PoolType ShadowMap::type = se::PoolType::UNKNOWN; -const se::PoolType PlanarShadow::type = se::PoolType::UNKNOWN; +const se::PoolType Shadows::type = se::PoolType::SHADOW; } // namespace pipeline } // namespace cc diff --git a/native/cocos/renderer/pipeline/helper/SharedMemory.h b/native/cocos/renderer/pipeline/helper/SharedMemory.h index c5056df4dd..ca0d84d17d 100644 --- a/native/cocos/renderer/pipeline/helper/SharedMemory.h +++ b/native/cocos/renderer/pipeline/helper/SharedMemory.h @@ -2,6 +2,7 @@ #include "renderer/core/CoreStd.h" #include "math/Vec2.h" #include "math/Vec3.h" +#include "math/Vec4.h" #include "scripting/dop/ArrayPool.h" #include "scripting/dop/BufferPool.h" #include "scripting/dop/ObjectPool.h" @@ -164,6 +165,7 @@ struct CC_DLL MainLight { }; struct CC_DLL Ambient { + float enabled = 0; float skyIllum = 0; cc::Vec4 skyColor; cc::Vec4 groundAlbedo; @@ -173,30 +175,34 @@ struct CC_DLL Ambient { struct CC_DLL Fog { float enabled = 0; + float fogType = 0; + float fogDensity = 0; float fogStart = 0; float fogEnd = 0; - float fogDensity = 0; + float fogAtten = 0; float fogTop = 0; float fogRange = 0; - float fogAtten = 0; cc::Vec4 fogColor; const static se::PoolType type; }; -struct CC_DLL ShadowMap { +struct CC_DLL Shadows { float enabled = 0; + float dirty = 0; + float shadowType = 0; + float distance = 0; + float instancePass = 0; + float planarPass = 0; float nearValue = 0; float farValue = 0; float aspect = 0; + float pcfType = 0; float orthoSize = 0; cc::Vec2 size; - - const static se::PoolType type; -}; - -struct CC_DLL PlanarShadow { - uint32_t enabled = 0; + cc::Vec3 normal; + cc::Vec4 color; + cc::Vec4 sphere; const static se::PoolType type; }; @@ -210,8 +216,13 @@ struct CC_DLL InstancedAttribute { const static se::PoolType type; }; -struct CC_DLL Skybox : public ModelView { +struct CC_DLL Skybox { uint32_t enabled = 0; + uint32_t isRGBE = 0; + uint32_t useIBL = 0; + uint32_t model = 0; + + const static se::PoolType type; }; struct CC_DLL BufferView { @@ -278,7 +289,6 @@ struct CC_DLL RenderWindow { const static se::PoolType type; }; - //Get buffer pool data #define GET_SUBMODEL(index) SharedMemory::getBuffer(index) #define GET_PASS(index) SharedMemory::getBuffer(index) @@ -295,12 +305,11 @@ struct CC_DLL RenderWindow { #define GET_MAIN_LIGHT(index) SharedMemory::getBuffer(index) #define GET_AMBIENT(index) SharedMemory::getBuffer(index) #define GET_FOG(index) SharedMemory::getBuffer(index) -#define GET_PLANAR_SHADOW(index) SharedMemory::getBuffer(index) #define GET_SKYBOX(index) SharedMemory::getBuffer(index) #define GET_FRUSTUM(index) SharedMemory::getBuffer(index) #define GET_AABB(index) SharedMemory::getBuffer(index) #define GET_WINDOW(index) SharedMemory::getBuffer(index) -#define GET_SHADOWMAP(index) SharedMemory::getBuffer(index) +#define GET_SHADOWS(index) SharedMemory::getBuffer(index) //TODO #define GET_NAME(index) (String(0)) diff --git a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp index 9d5e96c4c9..919f76f7b3 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp +++ b/native/cocos/renderer/pipeline/shadow/ShadowFlow.cpp @@ -41,7 +41,7 @@ void ShadowFlow::activate(RenderPipeline *pipeline) { RenderFlow::activate(pipeline); auto device = gfx::Device::getInstance(); - const auto shadowMapSize = static_cast(pipeline)->getShadowMap()->size; + const auto shadowMapSize = static_cast(pipeline)->getShadows()->size; _width = shadowMapSize.x; _height = shadowMapSize.y; @@ -104,7 +104,7 @@ void ShadowFlow::activate(RenderPipeline *pipeline) { void ShadowFlow::render(RenderView *view) { auto pipeline = static_cast(_pipeline); - const auto shadowInfo = pipeline->getShadowMap(); + const auto shadowInfo = pipeline->getShadows(); if (!shadowInfo->enabled) return; const auto shadowMapSize = shadowInfo->size; diff --git a/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp b/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp index 3524815f95..4167f99bd5 100644 --- a/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp +++ b/native/cocos/renderer/pipeline/shadow/ShadowStage.cpp @@ -39,7 +39,7 @@ bool ShadowStage::initialize(const RenderStageInfo &info) { void ShadowStage::render(RenderView *view) { const auto pipeline = static_cast(_pipeline); - const auto shadowInfo = pipeline->getShadowMap(); + const auto shadowInfo = pipeline->getShadows(); _additiveShadowQueue->clear(pipeline->getDescriptorSet()->getBuffer(UBOShadow::BLOCK.binding)); const auto shadowObjects = pipeline->getShadowObjects(); diff --git a/native/cocos/scripting/dop/PoolType.h b/native/cocos/scripting/dop/PoolType.h index a792d9426b..60e7403d61 100644 --- a/native/cocos/scripting/dop/PoolType.h +++ b/native/cocos/scripting/dop/PoolType.h @@ -12,7 +12,7 @@ enum class PoolType { PIPELINE_LAYOUT, FRAMEBUFFER, // buffers - PASS, + PASS = 100, SUB_MODEL, MODEL, SCENE, @@ -22,6 +22,10 @@ enum class PoolType { AABB, RENDER_WINDOW, FRUSTUM, + AMBIENT, + FOG, + SKYBOX, + SHADOW, // INSTANCED_ATTRIBUTE, // MAIN_LIGHT, // AMBIENT, @@ -31,7 +35,7 @@ enum class PoolType { // FLAT_BUFFER, // array - SUB_MODEL_ARRAY, + SUB_MODEL_ARRAY = 200, MODEL_ARRAY, UNKNOWN };