Bladeren bron

Update AdvancedPBRTerrain.frag to work with both MatDefs

Ryan McDonough 7 maanden geleden
bovenliggende
commit
ca07eb42a4
1 gewijzigde bestanden met toevoegingen van 54 en 26 verwijderingen
  1. 54 26
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag

+ 54 - 26
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.frag

@@ -25,7 +25,7 @@ uniform vec3 g_CameraPosition;
 #endif
 
 #ifdef USE_FOG
-    #import "Common/ShaderLib/MaterialFog.glsllib"
+    #import "MatDefs/ShaderLib/MaterialFog.glsllib"
 #endif
 
 void main(){       
@@ -35,6 +35,8 @@ void main(){
     // Create a blank PBRSurface.
     PBRSurface surface = PBRLightingUtils_createPBRSurface(worldViewDir);
     
+    surface.alpha = 1.0;
+    surface.normal = surface.geometryNormal;
     //pre-calculate necessary values for tri-planar blending
     TriPlanarUtils_calculateBlending(surface.geometryNormal);
 
@@ -49,7 +51,7 @@ void main(){
     // read and blend up to 12 texture layers
     #for i=0..12 (#ifdef ALBEDOMAP_$i $0 #endif)
     
-        PBRTerrainTextureLayer terrainTextureLayer_$i = PBRTerrainUtils_createAdvancedPBRTerrainLayer($i);
+        PBRTerrainTextureLayer terrainTextureLayer_$i = PBRTerrainUtils_createAdvancedPBRTerrainLayer($i, surface.geometryNormal);
         
         #ifdef USE_FIRST_LAYER_AS_TRANSPARENCY
             if($i == 0){
@@ -59,29 +61,52 @@ void main(){
             }    
         #endif 
         
+        terrainTextureLayer_$i.roughness = m_Roughness_$i;
+        terrainTextureLayer_$i.metallic = m_Metallic_$i;
         terrainTextureLayer_$i.emission = m_EmissiveColor_$i;
+
+        #ifdef USE_TEXTURE_ARRAYS
+            #if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i)
+              //triplanar for texture arrays:            
+                PBRTerrainUtils_readTriPlanarAlbedoTexArray(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);        
+                #ifdef NORMALMAP_$i
+                    PBRTerrainUtils_readTriPlanarNormalTexArray(m_NormalMap_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
+                #endif
+                #ifdef METALLICROUGHNESSMAP_$i
+                    PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexArray(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
+                #endif
+            #else 
+              //non tri-planar for texture arrays:
+                PBRTerrainUtils_readAlbedoTexArray(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);        
+                #ifdef NORMALMAP_$i
+                    PBRTerrainUtils_readNormalTexArray(m_NormalMap_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
+                #endif
+                #ifdef METALLICROUGHNESSMAP_$i
+                    PBRTerrainUtils_readMetallicRoughnessAoEiTexArray(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
+                #endif       
+            #endif    
+        #else
+            #if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i)
+              //triplanar texture reads:            
+                PBRTerrainUtils_readTriPlanarAlbedoTexture(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);        
+                #ifdef NORMALMAP_$i
+                    PBRTerrainUtils_readTriPlanarNormalTexture(m_NormalMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
+                #endif
+                #ifdef METALLICROUGHNESSMAP_$i
+                    PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexture(m_MetallicRoughnessMap_$i, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
+                #endif
+            #else 
+              //non tri-planar texture reads:
+                PBRTerrainUtils_readAlbedoTexture(m_AlbedoMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);        
+                #ifdef NORMALMAP_$i
+                    PBRTerrainUtils_readNormalTexture(m_NormalMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
+                #endif
+                #ifdef METALLICROUGHNESSMAP_$i
+                    PBRTerrainUtils_readMetallicRoughnessAoEiTexture(m_MetallicRoughnessMap_$i, m_AlbedoMap_$i_scale, terrainTextureLayer_$i);
+                #endif       
+            #endif    
         
-        #if defined(TRI_PLANAR_MAPPING) || defined(TRI_PLANAR_MAPPING_$i)
-          //triplanar:
-            
-            PBRTerrainUtils_readTriPlanarAlbedoTexArray(ALBEDOMAP_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);        
-            #ifdef NORMALMAP_$i
-                PBRTerrainUtils_readTriPlanarNormalTexArray(NORMALMAP_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
-            #endif
-            #ifdef METALLICROUGHNESSMAP_$i
-                PBRTerrainUtils_readTriPlanarMetallicRoughnessAoEiTexArray(METALLICROUGHNESSMAP_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
-            #endif
-        #else 
-          //non tri-planar:
-        
-            PBRTerrainUtils_readAlbedoTexArray(ALBEDOMAP_$i, m_AlbedoMap_$i_scale, m_AlbedoTextureArray, terrainTextureLayer_$i);        
-            #ifdef NORMALMAP_$i
-                PBRTerrainUtils_readNormalTexArray(NORMALMAP_$i, m_AlbedoMap_$i_scale, m_NormalParallaxTextureArray, terrainTextureLayer_$i);
-            #endif
-            #ifdef METALLICROUGHNESSMAP_$i
-                PBRTerrainUtils_readMetallicRoughnessAoEiTexArray(METALLICROUGHNESSMAP_$i, m_AlbedoMap_$i_scale, m_MetallicRoughnessAoEiTextureArray, terrainTextureLayer_$i);
-            #endif       
-        #endif    
+        #endif
         
         //CUSTOM LIB EXAMPLE: uses a custom alpha map to desaturate albedo color for a color-removal effect
         #ifdef AFFLICTIONTEXTURE
@@ -91,7 +116,8 @@ void main(){
 
         //blends this layer
         PBRTerrainUtils_blendPBRTerrainLayer(surface, terrainTextureLayer_$i);
-    #endfor                     
+    #endfor  
+                   
     
     #ifdef DISCARD_ALPHA
         if(surface.alpha < m_AlphaDiscardThreshold){
@@ -129,7 +155,8 @@ void main(){
     gl_FragColor.rgb += surface.directLightContribution;
     gl_FragColor.rgb += surface.envLightContribution;
     gl_FragColor.rgb += surface.emission;
-    gl_FragColor.a = surface.alpha;      
+    gl_FragColor.a = surface.alpha;    
+  
   
     #ifdef USE_FOG
         gl_FragColor = MaterialFog_calculateFogColor(vec4(gl_FragColor));
@@ -138,5 +165,6 @@ void main(){
    //outputs the final value of the selected layer as a color for debug purposes. 
     #ifdef DEBUG_VALUES_MODE
         gl_FragColor = PBRLightingUtils_getColorOutputForDebugMode(m_DebugValuesMode, vec4(gl_FragColor.rgba), surface);
-    #endif
+    #endif      
+
 }