Skip to content

Commit d71feba

Browse files
authored
Add reflectivity/shininess support to TerrainLighting.frag (#2306)
* Add reflectivity/shininess support to TerrainLighting.frag Uses the (previously unused) SpecularMap as a gray-scale texture for painting shininess/reflectivity on the whole terrain. * Update TerrainLighting.j3md add USE_SPECULARMAP_AS_SHININESS define to make this PR cleaner, and allow the SpecularMap to be used as regular specularColor if USE_SPECULARMAP_AS_SHININESS is not true/defined * Update TerrainLighting.frag * Update TerrainLighting.frag
1 parent 6709ee8 commit d71feba

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#import "Common/ShaderLib/Lighting.glsllib"
44

55
uniform float m_Shininess;
6+
#ifdef SPECULARMAP
7+
uniform sampler2D m_SpecularMap;
8+
#endif
9+
610
uniform vec4 g_LightDirection;
711

812
varying vec4 AmbientSum;
@@ -634,16 +638,27 @@ void main(){
634638
vec3 normal = vNormal;
635639
#endif
636640

641+
//-----------------------
642+
// read shininess or specularColor from specularMap (possibly want to create a new texture called ShininessMap if there is ever a need to have both a specularMap and reflectivityMap)
643+
//-----------------------
644+
vec4 specularColor = vec4(1.0);
645+
float finalShininessValue = m_Shininess;
646+
#ifdef SPECULARMAP
647+
vec4 specularMapColor = texture2D(m_SpecularMap, texCoord);
648+
#ifdef USE_SPECULARMAP_AS_SHININESS
649+
finalShininessValue = specularMapColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map)
650+
#else
651+
specularColor = specularMapColor;
652+
#endif
653+
#endif
637654

638655
//-----------------------
639656
// lighting calculations
640657
//-----------------------
641658
vec4 lightDir = vLightDir;
642659
lightDir.xyz = normalize(lightDir.xyz);
643660

644-
vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,m_Shininess);
645-
646-
vec4 specularColor = vec4(1.0);
661+
vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,finalShininessValue);
647662

648663
//--------------------------
649664
// final color calculations

jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ MaterialDef Terrain Lighting {
103103

104104
// The glow color of the object
105105
Color GlowColor
106+
107+
// Use diffuse alpha when mixing
108+
Boolean useSpecularMapAsShininess
109+
106110
}
107111

108112
Technique {
@@ -167,6 +171,7 @@ MaterialDef Terrain Lighting {
167171
DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale
168172

169173
USE_ALPHA : useDiffuseAlpha
174+
USE_SPECULARMAP_AS_SHININESS : useSpecularMapAsShininess
170175
}
171176
}
172177

0 commit comments

Comments
 (0)