Skip to content

Commit 0718b86

Browse files
author
Ali-RS
committed
Added ambient light support in PBR shader
1 parent 9c1452b commit 0718b86

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ varying vec4 Color;
1212

1313
uniform vec4 g_LightData[NB_LIGHTS];
1414
uniform vec3 g_CameraPosition;
15+
uniform vec4 g_AmbientLightColor;
1516

1617
uniform float m_Roughness;
1718
uniform float m_Metallic;
@@ -40,7 +41,7 @@ varying vec3 wPosition;
4041
#endif
4142

4243
#ifdef USE_PACKED_MR
43-
uniform sampler2D m_MetallicRoughnessMap;
44+
uniform sampler2D m_MetallicRoughnessMap;
4445
#else
4546
#ifdef METALLICMAP
4647
uniform sampler2D m_MetallicMap;
@@ -51,10 +52,10 @@ varying vec3 wPosition;
5152
#endif
5253

5354
#ifdef EMISSIVE
54-
uniform vec4 m_Emissive;
55+
uniform vec4 m_Emissive;
5556
#endif
5657
#ifdef EMISSIVEMAP
57-
uniform sampler2D m_EmissiveMap;
58+
uniform sampler2D m_EmissiveMap;
5859
#endif
5960
#if defined(EMISSIVE) || defined(EMISSIVEMAP)
6061
uniform float m_EmissivePower;
@@ -91,7 +92,7 @@ varying vec3 wPosition;
9192
varying vec3 wNormal;
9293

9394
#ifdef DISCARD_ALPHA
94-
uniform float m_AlphaDiscardThreshold;
95+
uniform float m_AlphaDiscardThreshold;
9596
#endif
9697

9798
void main(){
@@ -273,7 +274,7 @@ void main(){
273274
float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
274275
#endif
275276

276-
#if NB_PROBES >= 2
277+
#if NB_PROBES >= 2
277278
float invNdf = max(1.0 - ndf,0.0);
278279
float invNdf2 = max(1.0 - ndf2,0.0);
279280
float sumNdf = ndf + ndf2;
@@ -294,6 +295,12 @@ void main(){
294295
weight2 /= weightSum;
295296
weight3 /= weightSum;
296297
#endif
298+
299+
#ifdef AMBIENT_LIGHT_COLOR
300+
color1.rgb *= g_AmbientLightColor.rgb;
301+
color2.rgb *= g_AmbientLightColor.rgb;
302+
color3.rgb *= g_AmbientLightColor.rgb;
303+
#endif
297304
gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
298305

299306
#endif

jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ MaterialDef PBR Lighting {
5353
// Parallax/height map
5454
Texture2D ParallaxMap -LINEAR
5555

56-
//Set to true is parallax map is stored in the alpha channel of the normal map
56+
//Set to true if parallax map is stored in the alpha channel of the normal map
5757
Boolean PackedNormalParallax
5858

5959
//Sets the relief height for parallax mapping
@@ -111,13 +111,16 @@ MaterialDef PBR Lighting {
111111
Int NumberOfMorphTargets
112112
Int NumberOfTargetsBuffers
113113

114-
//For instancing
114+
// For instancing
115115
Boolean UseInstancing
116116

117-
//For Vertex Color
117+
// For Vertex Color
118118
Boolean UseVertexColor
119119

120120
Boolean BackfaceShadows : false
121+
122+
// Set to true to use AmbientLight
123+
Boolean UseAmbientLightColor
121124
}
122125

123126
Technique {
@@ -161,6 +164,7 @@ MaterialDef PBR Lighting {
161164
NUM_MORPH_TARGETS: NumberOfMorphTargets
162165
NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
163166
HORIZON_FADE: HorizonFade
167+
AMBIENT_LIGHT_COLOR: UseAmbientLightColor
164168
}
165169
}
166170

0 commit comments

Comments
 (0)