Explorar el Código

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
Ryan McDonough hace 1 año
padre
commit
d71feba8d3

+ 18 - 3
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

+ 5 - 0
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
         }
     }