diff --git a/native/cocos/renderer/pipeline/ClusterLightCulling.cpp b/native/cocos/renderer/pipeline/ClusterLightCulling.cpp index 83ce541aac..7622c8dcef 100644 --- a/native/cocos/renderer/pipeline/ClusterLightCulling.cpp +++ b/native/cocos/renderer/pipeline/ClusterLightCulling.cpp @@ -157,10 +157,10 @@ void ClusterLightCulling::updateLights() { } } - const auto exposure = _camera->exposure; - const auto validLightCount = _validLights.size(); - auto* const sceneData = _pipeline->getPipelineSceneData(); - auto* const sharedData = sceneData->getSharedData(); + const auto exposure = _camera->exposure; + const auto validLightCount = _validLights.size(); + auto* const sceneData = _pipeline->getPipelineSceneData(); + auto* const sharedData = sceneData->getSharedData(); if (validLightCount > _lightBufferCount) { _lightBufferResized = true; @@ -197,11 +197,12 @@ void ClusterLightCulling::updateLights() { _lightBufferData[index++] = color.z; } - float illuminance = isSpotLight ? spotLight->getIlluminance() : sphereLight->getIlluminance(); + float luminanceHDR = isSpotLight ? spotLight->getLuminanceHDR() : sphereLight->getLuminanceHDR(); + float luminanceLDR = isSpotLight ? spotLight->getLuminanceLDR() : sphereLight->getLuminanceLDR(); if (sharedData->isHDR) { - _lightBufferData[index] = illuminance * sharedData->fpScale * _lightMeterScale; + _lightBufferData[index] = luminanceHDR * exposure * _lightMeterScale; } else { - _lightBufferData[index] = illuminance * exposure * _lightMeterScale; + _lightBufferData[index] = luminanceLDR; } switch (light->getType()) { diff --git a/native/cocos/renderer/pipeline/Define.cpp b/native/cocos/renderer/pipeline/Define.cpp index a73ae50263..ae802aa931 100644 --- a/native/cocos/renderer/pipeline/Define.cpp +++ b/native/cocos/renderer/pipeline/Define.cpp @@ -329,6 +329,22 @@ const gfx::UniformSamplerTexture SPOTLIGHTINGMAP::LAYOUT = { 1, }; +const String DIFFUSEMAP::NAME = "cc_diffuseMap"; +const gfx::DescriptorSetLayoutBinding DIFFUSEMAP::DESCRIPTOR = { + DIFFUSEMAP::BINDING, + gfx::DescriptorType::SAMPLER_TEXTURE, + 1, + gfx::ShaderStageFlagBit::FRAGMENT, + {}, +}; +const gfx::UniformSamplerTexture DIFFUSEMAP::LAYOUT = { + globalSet, + DIFFUSEMAP::BINDING, + DIFFUSEMAP::NAME, + gfx::Type::SAMPLER_CUBE, + 1, +}; + const String JOINTTEXTURE::NAME = "cc_jointTexture"; const gfx::DescriptorSetLayoutBinding JOINTTEXTURE::DESCRIPTOR = { JOINTTEXTURE::BINDING, diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index c7046840cf..bbc00bbea3 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -216,6 +216,7 @@ enum class CC_DLL PipelineGlobalBindings { SAMPLER_SHADOWMAP, SAMPLER_ENVIRONMENT, SAMPLER_SPOT_LIGHTING_MAP, + SAMPLER_DIFFUSEMAP, COUNT, }; @@ -503,6 +504,13 @@ struct CC_DLL SPOTLIGHTINGMAP : public Object { static const String NAME; }; +struct CC_DLL DIFFUSEMAP : public Object { + static constexpr uint BINDING = static_cast(PipelineGlobalBindings::SAMPLER_DIFFUSEMAP); + static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; + static const gfx::UniformSamplerTexture LAYOUT; + static const String NAME; +}; + struct CC_DLL JOINTTEXTURE : public Object { static constexpr uint BINDING = static_cast(ModelLocalBindings::SAMPLER_JOINTS); static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; diff --git a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp index f98eb2a160..a9a4cdaa96 100644 --- a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp +++ b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp @@ -167,6 +167,8 @@ void GlobalDSManager::setDescriptorSetLayout() { globalDescriptorSetLayout.bindings[ENVIRONMENT::BINDING] = ENVIRONMENT::DESCRIPTOR; globalDescriptorSetLayout.samplers[SPOTLIGHTINGMAP::NAME] = SPOTLIGHTINGMAP::LAYOUT; globalDescriptorSetLayout.bindings[SPOTLIGHTINGMAP::BINDING] = SPOTLIGHTINGMAP::DESCRIPTOR; + globalDescriptorSetLayout.samplers[DIFFUSEMAP::NAME] = DIFFUSEMAP::LAYOUT; + globalDescriptorSetLayout.bindings[DIFFUSEMAP::BINDING] = DIFFUSEMAP::DESCRIPTOR; localDescriptorSetLayout.bindings.resize(static_cast(ModelLocalBindings::COUNT)); localDescriptorSetLayout.blocks[UBOLocalBatched::NAME] = UBOLocalBatched::LAYOUT; diff --git a/native/cocos/renderer/pipeline/PipelineUBO.cpp b/native/cocos/renderer/pipeline/PipelineUBO.cpp index 8464799d9f..397867ed8b 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.cpp +++ b/native/cocos/renderer/pipeline/PipelineUBO.cpp @@ -29,6 +29,7 @@ #include "gfx-base/GFXDevice.h" #include "platform/Application.h" #include "scene/RenderScene.h" +#include "forward/ForwardPipeline.h" namespace cc { @@ -71,16 +72,15 @@ void PipelineUBO::updateGlobalUBOView(const scene::Camera *camera, std::arrayscene; - const scene::DirectionalLight *mainLight = scene->getMainLight(); - auto * sceneData = pipeline->getPipelineSceneData(); - auto *const sharedData = sceneData->getSharedData(); - const auto fpScale = sharedData->fpScale; - auto *const descriptorSet = pipeline->getDescriptorSet(); - auto * ambient = sharedData->ambient; - auto * fog = sharedData->fog; - const auto isHDR = sharedData->isHDR; - const auto shadingScale = sharedData->shadingScale; + const auto *const scene = camera->scene; + const scene::DirectionalLight *mainLight = scene->getMainLight(); + auto * sceneData = pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); + auto *const descriptorSet = pipeline->getDescriptorSet(); + auto * ambient = sharedData->ambient; + auto * fog = sharedData->fog; + const auto isHDR = sharedData->isHDR; + const auto shadingScale = sharedData->shadingScale; auto *device = gfx::Device::getInstance(); @@ -96,7 +96,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out output[UBOCamera::EXPOSURE_OFFSET + 0] = exposure; output[UBOCamera::EXPOSURE_OFFSET + 1] = 1.0F / exposure; output[UBOCamera::EXPOSURE_OFFSET + 2] = isHDR ? 1.0F : 0.0F; - output[UBOCamera::EXPOSURE_OFFSET + 3] = fpScale / exposure; + output[UBOCamera::EXPOSURE_OFFSET + 3] = 0.0F; if (mainLight) { TO_VEC3(output, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET) @@ -109,9 +109,10 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out } if (isHDR) { - output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * fpScale; - } else { - output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * exposure; + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminanceHDR() * exposure; + } + else { + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminanceLDR(); } } else { TO_VEC3(output, Vec3::UNIT_Z, UBOCamera::MAIN_LIT_DIR_OFFSET); @@ -120,10 +121,11 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out Vec4 skyColor = ambient->skyColor; if (isHDR) { - skyColor.w = ambient->skyIllum * fpScale; - } else { skyColor.w = ambient->skyIllum * exposure; } + else { + skyColor.w = ambient->skyIllum; + } TO_VEC4(output, skyColor, UBOCamera::AMBIENT_SKY_OFFSET) output[UBOCamera::AMBIENT_GROUND_OFFSET + 0] = ambient->groundAlbedo.x; diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index 903ffab0fc..3cd416b431 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -228,9 +228,10 @@ void RenderAdditiveLightQueue::addRenderQueue(const scene::Pass *pass, const sce } void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::CommandBuffer *cmdBuffer) { - const auto exposure = camera->exposure; - const auto validLightCount = _validLights.size(); - auto *const sceneData = _pipeline->getPipelineSceneData(); + const auto exposure = camera->exposure; + const auto validLightCount = _validLights.size(); + auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); const auto *shadowInfo = sharedData->shadow; size_t offset = 0; @@ -272,11 +273,12 @@ void RenderAdditiveLightQueue::updateUBOs(const scene::Camera *camera, gfx::Comm _lightBufferData[index++] = color.z; } - float illuminance = isSpotLight ? spotLight->getIlluminance() : sphereLight->getIlluminance(); + float luminanceHDR = isSpotLight ? spotLight->getLuminanceHDR() : sphereLight->getLuminanceHDR(); + float luminanceLDR = isSpotLight ? spotLight->getLuminanceLDR() : sphereLight->getLuminanceLDR(); if (sharedData->isHDR) { - _lightBufferData[index] = illuminance * sharedData->fpScale * _lightMeterScale; + _lightBufferData[index] = luminanceHDR * exposure * _lightMeterScale; } else { - _lightBufferData[index] = illuminance * exposure * _lightMeterScale; + _lightBufferData[index] = luminanceLDR; } switch (light->getType()) { diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index e88b672c1b..75bb2d3030 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -151,10 +151,6 @@ gfx::Color RenderPipeline::getClearcolor(scene::Camera *camera) const { if (camera->clearFlag & static_cast(gfx::ClearFlagBit::COLOR)) { if (sharedData->isHDR) { srgbToLinear(&clearColor, camera->clearColor); - const auto scale = sharedData->fpScale / camera->exposure; - clearColor.x *= scale; - clearColor.y *= scale; - clearColor.z *= scale; } else { clearColor = camera->clearColor; } diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index 48c137888a..aded853f2f 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -110,9 +110,9 @@ bool LightingStage::initialize(const RenderStageInfo &info) { } void LightingStage::gatherLights(scene::Camera *camera) { - auto * pipeline = static_cast(_pipeline); - auto *const sceneData = _pipeline->getPipelineSceneData(); - auto *const sharedData = sceneData->getSharedData(); + auto * pipeline = static_cast(_pipeline); + auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); gfx::CommandBuffer *cmdBuf = pipeline->getCommandBuffers()[0]; const auto * scene = camera->scene; @@ -156,9 +156,9 @@ void LightingStage::gatherLights(scene::Camera *camera) { } if (sharedData->isHDR) { - tmpArray.w = light->getIlluminance() * sharedData->fpScale * _lightMeterScale; + tmpArray.w = light->getLuminanceHDR() * exposure * _lightMeterScale; } else { - tmpArray.w = light->getIlluminance() * exposure * _lightMeterScale; + tmpArray.w = light->getLuminanceLDR(); } _lightBufferData[offset + 0] = tmpArray.x; @@ -207,9 +207,9 @@ void LightingStage::gatherLights(scene::Camera *camera) { } if (sharedData->isHDR) { - tmpArray.w = light->getIlluminance() * sharedData->fpScale * _lightMeterScale; + tmpArray.w = light->getLuminanceHDR() * exposure * _lightMeterScale; } else { - tmpArray.w = light->getIlluminance() * exposure * _lightMeterScale; + tmpArray.w = light->getLuminanceLDR(); } _lightBufferData[offset + 0] = tmpArray.x; diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index 2a8429a10e..33d9bf3711 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -155,10 +155,6 @@ void ForwardStage::render(scene::Camera *camera) { if (hasFlag(static_cast(camera->clearFlag), gfx::ClearFlagBit::COLOR)) { if (sharedData->isHDR) { srgbToLinear(&_clearColors[0], camera->clearColor); - auto scale{sharedData->fpScale / camera->exposure}; - _clearColors[0].x *= scale; - _clearColors[0].y *= scale; - _clearColors[0].z *= scale; } else { _clearColors[0].x = camera->clearColor.x; _clearColors[0].y = camera->clearColor.y; diff --git a/native/cocos/scene/Define.h b/native/cocos/scene/Define.h index c4a7f4527d..2c9b8c0df8 100644 --- a/native/cocos/scene/Define.h +++ b/native/cocos/scene/Define.h @@ -94,6 +94,8 @@ struct Skybox { bool enabled{false}; bool isRGBE{false}; bool useIBL{false}; + bool useHDR{true}; + bool useDiffuseMap{false}; Model *model{nullptr}; }; @@ -105,9 +107,8 @@ struct Ambient { }; struct PipelineSharedSceneData { - bool isHDR{false}; + bool isHDR{true}; float shadingScale{0.0F}; - float fpScale{0.0F}; Ambient * ambient{nullptr}; Shadow * shadow{nullptr}; Skybox * skybox{nullptr}; diff --git a/native/cocos/scene/DirectionalLight.h b/native/cocos/scene/DirectionalLight.h index 56966f0853..53ddc5b27d 100644 --- a/native/cocos/scene/DirectionalLight.h +++ b/native/cocos/scene/DirectionalLight.h @@ -43,13 +43,16 @@ public: void update() override; inline void setDirection(const Vec3 &dir) { _dir = dir; } - inline void setIlluminance(float illum) { _illuminance = illum; } + inline void setIlluminanceHDR(float illum) { _illuminanceHDR = illum; } + inline void setIlluminanceLDR(float illum) { _illuminanceLDR = illum; } inline const Vec3 &getDirection() const { return _dir; } - inline float getIlluminance() const { return _illuminance; } + inline float getIlluminanceHDR() const { return _illuminanceHDR; } + inline float getIlluminanceLDR() const { return _illuminanceLDR; } private: - float _illuminance{0.F}; + float _illuminanceHDR{0.F}; + float _illuminanceLDR{0.F}; Vec3 _dir; }; diff --git a/native/cocos/scene/SphereLight.h b/native/cocos/scene/SphereLight.h index 44224f0a47..b0f805a2cd 100644 --- a/native/cocos/scene/SphereLight.h +++ b/native/cocos/scene/SphereLight.h @@ -44,7 +44,8 @@ public: void update() override; inline void setAABB(AABB *aabb) { _aabb = aabb; } - inline void setIlluminance(float illum) { _illuminance = illum; } + inline void setLuminanceHDR(float illum) { _luminanceHDR = illum; } + inline void setLuminanceLDR(float illum) { _luminanceLDR = illum; } inline void setPosition(const Vec3 &pos) { _pos = pos; } inline void setRange(float range) { _range = range; @@ -53,14 +54,16 @@ public: inline void setSize(float size) { _size = size; } inline AABB * getAABB() const { return _aabb; } - inline float getIlluminance() const { return _illuminance; } + inline float getLuminanceHDR() const { return _luminanceHDR; } + inline float getLuminanceLDR() const { return _luminanceLDR; } inline const Vec3 &getPosition() const { return _pos; } inline float getRange() const { return _range; } inline float getSize() const { return _size; } private: bool _needUpdate{false}; - float _illuminance{0.F}; + float _luminanceHDR{0.F}; + float _luminanceLDR{0.F}; float _range{0.F}; float _size{0.F}; Vec3 _pos; diff --git a/native/cocos/scene/SpotLight.h b/native/cocos/scene/SpotLight.h index 6380ad30d4..f7303426d5 100644 --- a/native/cocos/scene/SpotLight.h +++ b/native/cocos/scene/SpotLight.h @@ -55,7 +55,8 @@ public: } inline void setDirection(const Vec3 &dir) { _dir = dir; } inline void setFrustum(Frustum frustum) { _frustum = std::move(frustum); } - inline void setIlluminance(float illu) { _illuminance = illu; } + inline void setLuminanceHDR(float illu) { _luminanceHDR = illu; } + inline void setLuminanceLDR(float illu) { _luminanceLDR = illu; } inline void setNeedUpdate(bool value) { _needUpdate = value; } inline void setRange(float range) { _range = range; @@ -70,7 +71,8 @@ public: inline float getAspect() const { return _aspect; } inline const Vec3 & getDirection() const { return _dir; } inline const Frustum &getFrustum() const { return _frustum; } - inline float getIlluminance() const { return _illuminance; } + inline float getLuminanceHDR() const { return _luminanceHDR; } + inline float getLuminanceLDR() const { return _luminanceLDR; } inline bool getNeedUpdate() const { return _needUpdate; } inline float getRange() const { return _range; } inline const Vec3 & getPosition() const { return _pos; } @@ -78,7 +80,8 @@ public: private: bool _needUpdate{false}; - float _illuminance{0.F}; + float _luminanceHDR{0.F}; + float _luminanceLDR{0.F}; float _range{0.F}; float _size{0.F}; float _angle{0.F}; diff --git a/native/tools/tojs/scene.ini b/native/tools/tojs/scene.ini index 68a9d7deae..04b7682a6f 100644 --- a/native/tools/tojs/scene.ini +++ b/native/tools/tojs/scene.ini @@ -45,9 +45,9 @@ skip = Model::[setInstancedAttrBlock getType getLocalBuffer getModelBounds getWo Light::[getColor getColorTemperatureRGB getNode getType getUseColorTemperature], Node::[getFlagsChanged getDirtyNode getLayer getWorldMatrix getWorldPosition getWorldRotation getWorldScale setFlagsChanged setDirtyFlag setDirtyNode setLayer setWorldMatrix setWorldPosition setWorldRotation invalidateChildren setWorldScale setLocalPosition setLocalRotation setLocalScale getNodeLayout getWorldRT updateWorldTransform updateWorldRTMatrix getDirtyFlag getPosition getScale getRotation getParent], BaseNode::[addChild removeChild getFlagsChanged getDirtyNode getLayer getWorldMatrix getWorldPosition getWorldRotation getWorldScale setFlagsChanged setDirtyFlag setDirtyNode setLayer setWorldMatrix setWorldPosition setWorldRotation invalidateChildren setWorldScale setLocalPosition setLocalRotation setLocalScale getNodeLayout getWorldRT updateWorldTransform updateWorldRTMatrix getDirtyFlag getPosition getScale getRotation getParent], - DirectionalLight::[getDirection getIlluminance], - SpotLight::[getAABB getAngle getAspect getSpotAngle getDirection getFrustum getIlluminance getNeedUpdate getRange getPosition getSize], - SphereLight::[getAABB getIlluminance getPosition getRange getSize], + DirectionalLight::[getDirection getIlluminanceHDR getIlluminanceLDR], + SpotLight::[getAABB getAngle getAspect getSpotAngle getDirection getFrustum getLuminanceHDR getLuminanceLDR getNeedUpdate getRange getPosition getSize], + SphereLight::[getAABB getLuminanceHDR getLuminanceLDR getPosition getRange getSize], Pass::[setRootBufferAndBlock], AABB::[getBoundary aabbAabb aabbFrustum aabbPlan merge transform transformExtentM4 setCenter getCenter getValid setValid setHalfExtents getHalfExtents set fromPoints], SkinningModel::[updateTransform updateUBOs uploadJointData updateWorldMatrix],