From 6b19b5816629d35a88e67eccb6d0629ceb857f1f Mon Sep 17 00:00:00 2001 From: feiy Date: Fri, 9 Feb 2024 12:58:14 +0800 Subject: [PATCH] minor extension --- ThreeEngine/lights/EnvironmentMap.cpp | 3 +++ ThreeEngine/lights/EnvironmentMap.h | 1 + ThreeEngine/renderers/bvh_routines/BVHRoutine.cpp | 5 +++-- ThreeEngine/renderers/bvh_routines/CompDrawFog.cpp | 3 ++- ThreeEngine/renderers/routines/DrawFog.cpp | 3 ++- ThreeEngine/renderers/routines/SimpleRoutine.cpp | 5 +++-- ThreeEngine/renderers/routines/StandardRoutine.cpp | 5 +++-- ThreeEngine/volume/routines/DrawIsosurface.cpp | 3 ++- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ThreeEngine/lights/EnvironmentMap.cpp b/ThreeEngine/lights/EnvironmentMap.cpp index b9cdbfcb..41d83705 100644 --- a/ThreeEngine/lights/EnvironmentMap.cpp +++ b/ThreeEngine/lights/EnvironmentMap.cpp @@ -4,12 +4,14 @@ struct EnvironmentMapConst { glm::vec4 shCoefficients[9]; + float intensity; float diffuseThresh; float diffuseHigh; float diffuseLow; float specularThresh; float specularHigh; float specularLow; + float padding; }; EnvironmentMap::EnvironmentMap(): m_constant(sizeof(EnvironmentMapConst), GL_UNIFORM_BUFFER) @@ -27,6 +29,7 @@ void EnvironmentMap::updateConstant() { EnvironmentMapConst c; memcpy(c.shCoefficients, shCoefficients, sizeof(glm::vec4) * 9); + c.intensity = intensity; c.diffuseThresh = diffuse_thresh; c.diffuseHigh = diffuse_high; c.diffuseLow = diffuse_low; diff --git a/ThreeEngine/lights/EnvironmentMap.h b/ThreeEngine/lights/EnvironmentMap.h index 4c27be39..e0757c9b 100644 --- a/ThreeEngine/lights/EnvironmentMap.h +++ b/ThreeEngine/lights/EnvironmentMap.h @@ -11,6 +11,7 @@ class EnvironmentMap : public IndirectLight ~EnvironmentMap(); glm::vec4 shCoefficients[9]; + float intensity = 1.0f; GLBuffer m_constant; void updateConstant(); diff --git a/ThreeEngine/renderers/bvh_routines/BVHRoutine.cpp b/ThreeEngine/renderers/bvh_routines/BVHRoutine.cpp index ca455a98..f428b890 100644 --- a/ThreeEngine/renderers/bvh_routines/BVHRoutine.cpp +++ b/ThreeEngine/renderers/bvh_routines/BVHRoutine.cpp @@ -571,7 +571,7 @@ R"( layout (location = LOCATION_TEX_LIGHTMAP) uniform sampler2D uTexLightmap; #endif -vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ] ) +vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ]) { // normal is assumed to have unit length @@ -599,6 +599,7 @@ vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ] ) layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap { vec4 uSHCoefficients[9]; + float uIntensity; float uDiffuseThresh; float uDiffuseHigh; float uDiffuseLow; @@ -609,7 +610,7 @@ layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap vec3 getIrradiance(in vec3 normal) { - return shGetIrradianceAt(normal, uSHCoefficients); + return shGetIrradianceAt(normal, uSHCoefficients) * uIntensity; } #endif diff --git a/ThreeEngine/renderers/bvh_routines/CompDrawFog.cpp b/ThreeEngine/renderers/bvh_routines/CompDrawFog.cpp index 1afccfa1..9a72cf26 100644 --- a/ThreeEngine/renderers/bvh_routines/CompDrawFog.cpp +++ b/ThreeEngine/renderers/bvh_routines/CompDrawFog.cpp @@ -23,11 +23,12 @@ layout (location = 0) uniform sampler2D uDepthTex; layout (std140, binding = 1) uniform EnvironmentMap { vec4 uSHCoefficients[9]; + float uIntensity; }; vec3 GetIrradiance() { - return uSHCoefficients[0].xyz * 0.886227; + return uSHCoefficients[0].xyz * 0.886227 * uIntensity; } #elif HAS_AMBIENT_LIGHT layout (std140, binding = 1) uniform AmbientLight diff --git a/ThreeEngine/renderers/routines/DrawFog.cpp b/ThreeEngine/renderers/routines/DrawFog.cpp index 37ebb1ad..08f0a7bd 100644 --- a/ThreeEngine/renderers/routines/DrawFog.cpp +++ b/ThreeEngine/renderers/routines/DrawFog.cpp @@ -59,11 +59,12 @@ layout (location = 0) uniform sampler2D uDepthTex; layout (std140, binding = 3) uniform EnvironmentMap { vec4 uSHCoefficients[9]; + float uIntensity; }; vec3 GetIrradiance() { - return uSHCoefficients[0].xyz * 0.886227; + return uSHCoefficients[0].xyz * 0.886227 * uIntensity; } #elif HAS_AMBIENT_LIGHT layout (std140, binding = 3) uniform AmbientLight diff --git a/ThreeEngine/renderers/routines/SimpleRoutine.cpp b/ThreeEngine/renderers/routines/SimpleRoutine.cpp index 2a2e179a..bd727189 100644 --- a/ThreeEngine/renderers/routines/SimpleRoutine.cpp +++ b/ThreeEngine/renderers/routines/SimpleRoutine.cpp @@ -311,7 +311,7 @@ R"( layout (location = LOCATION_TEX_LIGHTMAP) uniform sampler2D uTexLightmap; #endif -vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ] ) +vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ]) { // normal is assumed to have unit length @@ -339,6 +339,7 @@ vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ] ) layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap { vec4 uSHCoefficients[9]; + float uIntensity; float uDiffuseThresh; float uDiffuseHigh; float uDiffuseLow; @@ -349,7 +350,7 @@ layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap vec3 getIrradiance(in vec3 normal) { - return shGetIrradianceAt(normal, uSHCoefficients); + return shGetIrradianceAt(normal, uSHCoefficients) * uIntensity; } #endif diff --git a/ThreeEngine/renderers/routines/StandardRoutine.cpp b/ThreeEngine/renderers/routines/StandardRoutine.cpp index 4084a501..d6fec3e8 100644 --- a/ThreeEngine/renderers/routines/StandardRoutine.cpp +++ b/ThreeEngine/renderers/routines/StandardRoutine.cpp @@ -682,7 +682,7 @@ vec3 getRadiance(in vec3 worldPos, in vec3 viewDir, in vec3 norm, const in vec3 } #endif -vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ] ) +vec3 shGetIrradianceAt( in vec3 normal, in vec4 shCoefficients[ 9 ]) { // normal is assumed to have unit length @@ -783,6 +783,7 @@ vec3 getReflectionDir(in vec3 dir, in vec3 norm) layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap { vec4 uSHCoefficients[9]; + float uIntensity; float uDiffuseThresh; float uDiffuseHigh; float uDiffuseLow; @@ -793,7 +794,7 @@ layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap vec3 getIrradiance(in vec3 normal) { - return shGetIrradianceAt(normal, uSHCoefficients); + return shGetIrradianceAt(normal, uSHCoefficients) * uIntensity; } #endif diff --git a/ThreeEngine/volume/routines/DrawIsosurface.cpp b/ThreeEngine/volume/routines/DrawIsosurface.cpp index 6b37b74c..9bd2cdc5 100644 --- a/ThreeEngine/volume/routines/DrawIsosurface.cpp +++ b/ThreeEngine/volume/routines/DrawIsosurface.cpp @@ -277,6 +277,7 @@ vec3 getReflRadiance(in vec3 reflectVec, float roughness) layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap { vec4 uSHCoefficients[9]; + float uIntensity; float uDiffuseThresh; float uDiffuseHigh; float uDiffuseLow; @@ -287,7 +288,7 @@ layout (std140, binding = BINDING_ENVIRONMEN_MAP) uniform EnvironmentMap vec3 getIrradiance(in vec3 world_pos, in vec3 normal) { - return shGetIrradianceAt(normal, uSHCoefficients); + return shGetIrradianceAt(normal, uSHCoefficients) * uIntensity; } #endif