diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag index f2ca013fc7..8125982303 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag @@ -3,6 +3,10 @@ #import "Common/ShaderLib/Lighting.glsllib" uniform float m_Shininess; +#ifdef SPECULARMAP + uniform sampler2D m_SpecularMap; +#endif + uniform vec4 g_LightDirection; varying vec4 AmbientSum; @@ -634,6 +638,19 @@ void main(){ vec3 normal = vNormal; #endif + //----------------------- + // 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) + //----------------------- + vec4 specularColor = vec4(1.0); + float finalShininessValue = m_Shininess; + #ifdef SPECULARMAP + vec4 specularMapColor = texture2D(m_SpecularMap, texCoord); + #ifdef USE_SPECULARMAP_AS_SHININESS + finalShininessValue = specularMapColor.r; //assumes that specularMap is a gray-scale reflectivity/shininess map) + #else + specularColor = specularMapColor; + #endif + #endif //----------------------- // lighting calculations @@ -641,9 +658,7 @@ void main(){ vec4 lightDir = vLightDir; lightDir.xyz = normalize(lightDir.xyz); - vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,m_Shininess); - - vec4 specularColor = vec4(1.0); + vec2 light = computeLighting(normal, vViewDir.xyz, lightDir.xyz,lightDir.w*spotFallOff,finalShininessValue); //-------------------------- // final color calculations diff --git a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md index 341ef1c683..4eb9c8d7a2 100644 --- a/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md +++ b/jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md @@ -103,6 +103,10 @@ MaterialDef Terrain Lighting { // The glow color of the object Color GlowColor + + // Use diffuse alpha when mixing + Boolean useSpecularMapAsShininess + } Technique { @@ -167,6 +171,7 @@ MaterialDef Terrain Lighting { DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale USE_ALPHA : useDiffuseAlpha + USE_SPECULARMAP_AS_SHININESS : useSpecularMapAsShininess } }