Skip to content

Commit becdf50

Browse files
authored
Merge pull request jMonkeyEngine#2364 from jMonkeyEngine/yaRnMcDonuts-patch-6
Fix Fog in Lighting.frag
2 parents b2f9e68 + 8df8441 commit becdf50

File tree

2 files changed

+7
-34
lines changed

2 files changed

+7
-34
lines changed

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

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,9 @@
66
#import "Common/ShaderLib/Lighting.glsllib"
77
#endif
88

9-
// fog - jayfella
109
#ifdef USE_FOG
11-
#import "Common/ShaderLib/MaterialFog.glsllib"
12-
varying float fog_distance;
13-
uniform vec4 m_FogColor;
14-
15-
#ifdef FOG_LINEAR
16-
uniform vec2 m_LinearFog;
17-
#endif
18-
19-
#ifdef FOG_EXP
20-
uniform float m_ExpFog;
21-
#endif
22-
23-
#ifdef FOG_EXPSQ
24-
uniform float m_ExpSqFog;
25-
#endif
26-
27-
#endif // end fog
10+
#import "Common/ShaderLib/MaterialFog.glsllib"
11+
#endif
2812

2913
varying vec2 texCoord;
3014
#ifdef SEPARATE_TEXCOORD
@@ -231,21 +215,11 @@ void main(){
231215
SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
232216
#endif
233217

234-
235218
// add fog after the lighting because shadows will cause the fog to darken
236219
// which just results in the geometry looking like it's changed color
237220
#ifdef USE_FOG
238-
#ifdef FOG_LINEAR
239-
gl_FragColor = getFogLinear(gl_FragColor, m_FogColor, m_LinearFog.x, m_LinearFog.y, fog_distance);
240-
#endif
241-
#ifdef FOG_EXP
242-
gl_FragColor = getFogExp(gl_FragColor, m_FogColor, m_ExpFog, fog_distance);
243-
#endif
244-
#ifdef FOG_EXPSQ
245-
gl_FragColor = getFogExpSquare(gl_FragColor, m_FogColor, m_ExpSqFog, fog_distance);
246-
#endif
247-
#endif // end fog
248-
221+
gl_FragColor = MaterialFog_calculateFogColor(vec4(gl_FragColor));
222+
#endif
249223

250224
gl_FragColor.a = alpha;
251225
}

jme3-core/src/main/resources/Common/ShaderLib/MaterialFog.glsllib

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
//author @jayfella
12
#ifndef __MATERIAL_FOG_UTIL__
23
#define __MATERIAL_FOG_UTIL__
34

4-
55
vec4 getFogLinear(in vec4 diffuseColor, in vec4 fogColor, in float start, in float end, in float distance) {
66

77
float fogFactor = (end - distance) / (end - start);
@@ -39,8 +39,7 @@
3939

4040
#ifdef FOG_EXPSQ
4141
uniform float m_ExpSqFog;
42-
#endif
43-
42+
#endif
4443

4544
vec4 MaterialFog_calculateFogColor(in vec4 fragColor){
4645
#ifdef FOG_LINEAR
@@ -54,7 +53,7 @@
5453
#endif
5554

5655
return fragColor;
57-
}
56+
}
5857

5958
#endif
6059
#endif

0 commit comments

Comments
 (0)