Support HDR/LDR Light Sources v3.4.0 (#3951)

* Support HDR/LDR Light Sources

* Fix ClangTidy error

* Fix name style error

* Synchronize naming for HDR

* Fix name style and compiling errors

* Remove fpScale, make deferred and forward uniform

* Fix diffusemap binding error

Co-authored-by: pandamicro <lphuabin@gmail.com>
This commit is contained in:
jk20012001
2021-10-12 10:47:28 +08:00
committed by GitHub
parent 5e734702d0
commit 4c94f2ca56
14 changed files with 91 additions and 58 deletions
@@ -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()) {
+16
View File
@@ -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,
+8
View File
@@ -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<uint>(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<uint>(ModelLocalBindings::SAMPLER_JOINTS);
static const gfx::DescriptorSetLayoutBinding DESCRIPTOR;
@@ -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<size_t>(ModelLocalBindings::COUNT));
localDescriptorSetLayout.blocks[UBOLocalBatched::NAME] = UBOLocalBatched::LAYOUT;
+18 -16
View File
@@ -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::array<fl
}
void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *output, const scene::Camera *camera) {
const auto *const scene = camera->scene;
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;
@@ -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()) {
@@ -151,10 +151,6 @@ gfx::Color RenderPipeline::getClearcolor(scene::Camera *camera) const {
if (camera->clearFlag & static_cast<uint>(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;
}
@@ -110,9 +110,9 @@ bool LightingStage::initialize(const RenderStageInfo &info) {
}
void LightingStage::gatherLights(scene::Camera *camera) {
auto * pipeline = static_cast<DeferredPipeline *>(_pipeline);
auto *const sceneData = _pipeline->getPipelineSceneData();
auto *const sharedData = sceneData->getSharedData();
auto * pipeline = static_cast<DeferredPipeline *>(_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;
@@ -155,10 +155,6 @@ void ForwardStage::render(scene::Camera *camera) {
if (hasFlag(static_cast<gfx::ClearFlags>(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;
+3 -2
View File
@@ -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};
+6 -3
View File
@@ -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;
};
+6 -3
View File
@@ -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;
+6 -3
View File
@@ -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};
+3 -3
View File
@@ -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],