From 73a1cfa040c0ec7a8496cdcd5e52bbd023ac1b55 Mon Sep 17 00:00:00 2001 From: Ali-RS <> Date: Mon, 22 Apr 2019 10:38:46 +0430 Subject: [PATCH 1/2] Added ambient filter in PBRLighting to control the brightness and color of the ambient light. --- .../Common/MatDefs/Light/PBRLighting.frag | 18 ++++++++++++++---- .../Common/MatDefs/Light/PBRLighting.j3md | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index 716d3ff7ab..fa90b78eaf 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -51,10 +51,10 @@ varying vec3 wPosition; #endif #ifdef EMISSIVE - uniform vec4 m_Emissive; + uniform vec4 m_Emissive; #endif #ifdef EMISSIVEMAP - uniform sampler2D m_EmissiveMap; + uniform sampler2D m_EmissiveMap; #endif #if defined(EMISSIVE) || defined(EMISSIVEMAP) uniform float m_EmissivePower; @@ -91,7 +91,11 @@ varying vec3 wPosition; varying vec3 wNormal; #ifdef DISCARD_ALPHA -uniform float m_AlphaDiscardThreshold; + uniform float m_AlphaDiscardThreshold; +#endif + +#ifdef FILTER_COLOR + uniform vec4 m_FilterColor; #endif void main(){ @@ -273,7 +277,7 @@ void main(){ float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3); #endif - #if NB_PROBES >= 2 + #if NB_PROBES >= 2 float invNdf = max(1.0 - ndf,0.0); float invNdf2 = max(1.0 - ndf2,0.0); float sumNdf = ndf + ndf2; @@ -294,6 +298,12 @@ void main(){ weight2 /= weightSum; weight3 /= weightSum; #endif + + #ifdef FILTER_COLOR + color1.rgb *= m_FilterColor.rgb; + color2.rgb *= m_FilterColor.rgb; + color3.rgb *= m_FilterColor.rgb; + #endif gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0); #endif diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md index e300bffdca..29456b25f7 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md @@ -118,6 +118,9 @@ MaterialDef PBR Lighting { Boolean UseVertexColor Boolean BackfaceShadows : false + + //For ambient filter + Color FilterColor } Technique { @@ -161,6 +164,7 @@ MaterialDef PBR Lighting { NUM_MORPH_TARGETS: NumberOfMorphTargets NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers HORIZON_FADE: HorizonFade + FILTER_COLOR : FilterColor } } From 808fc54b774f3db929678a00251b2d96fa2b194a Mon Sep 17 00:00:00 2001 From: Ali-RS <> Date: Mon, 22 Apr 2019 13:51:27 +0430 Subject: [PATCH 2/2] Renamed FilterColor to AmbientColor --- .../resources/Common/MatDefs/Light/PBRLighting.frag | 12 ++++++------ .../resources/Common/MatDefs/Light/PBRLighting.j3md | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index fa90b78eaf..31dbd892d8 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -94,8 +94,8 @@ varying vec3 wNormal; uniform float m_AlphaDiscardThreshold; #endif -#ifdef FILTER_COLOR - uniform vec4 m_FilterColor; +#ifdef AMBIENT_COLOR + uniform vec4 m_AmbientColor; #endif void main(){ @@ -299,10 +299,10 @@ void main(){ weight3 /= weightSum; #endif - #ifdef FILTER_COLOR - color1.rgb *= m_FilterColor.rgb; - color2.rgb *= m_FilterColor.rgb; - color3.rgb *= m_FilterColor.rgb; + #ifdef AMBIENT_COLOR + color1.rgb *= m_AmbientColor.rgb; + color2.rgb *= m_AmbientColor.rgb; + color3.rgb *= m_AmbientColor.rgb; #endif gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0); diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md index 29456b25f7..9f5430c359 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md @@ -119,8 +119,8 @@ MaterialDef PBR Lighting { Boolean BackfaceShadows : false - //For ambient filter - Color FilterColor + //the ambient color + Color AmbientColor } Technique { @@ -164,7 +164,7 @@ MaterialDef PBR Lighting { NUM_MORPH_TARGETS: NumberOfMorphTargets NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers HORIZON_FADE: HorizonFade - FILTER_COLOR : FilterColor + AMBIENT_COLOR : AmbientColor } }