Skip to content

Commit

Permalink
minor extension
Browse files Browse the repository at this point in the history
  • Loading branch information
feiy committed Feb 9, 2024
1 parent 83d26b4 commit 6b19b58
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ThreeEngine/lights/EnvironmentMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ThreeEngine/lights/EnvironmentMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class EnvironmentMap : public IndirectLight
~EnvironmentMap();

glm::vec4 shCoefficients[9];
float intensity = 1.0f;

GLBuffer m_constant;
void updateConstant();
Expand Down
5 changes: 3 additions & 2 deletions ThreeEngine/renderers/bvh_routines/BVHRoutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ThreeEngine/renderers/bvh_routines/CompDrawFog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ThreeEngine/renderers/routines/DrawFog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions ThreeEngine/renderers/routines/SimpleRoutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions ThreeEngine/renderers/routines/StandardRoutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ThreeEngine/volume/routines/DrawIsosurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 6b19b58

Please sign in to comment.