Ryan McDonough 7 месяцев назад
Родитель
Сommit
c5ba0f18d3

+ 21 - 0
jme3-core/src/main/resources/Common/ShaderLib/TangentUtils.glsllib

@@ -0,0 +1,21 @@
+#ifndef __TANGENT_UTILS_MODULE__
+    #define __TANGENT_UTILS_MODULE__
+
+    //used for calculating tangents in-shader
+   
+
+    //primarily used for terrains, since jme terrains do not store pre-calculated tangents by default (thus the tbnMat cannot be used for PBR light calculation like it is in jme's stock PBR shader)
+    vec3 calculateTangentsAndApplyToNormals(in vec3 normalIn, in vec3 worldNorm){
+        vec3 returnNorm = normalize((normalIn.xyz * vec3(2.0) - vec3(1.0)));
+
+        vec3 baseNorm = worldNorm.rgb + vec3(0, 0, 1);
+        returnNorm *= vec3(-1, -1, 1);
+        returnNorm = baseNorm.rgb*dot(baseNorm.rgb, returnNorm.rgb)/baseNorm.z - returnNorm.rgb;
+
+        returnNorm = normalize(returnNorm);
+
+
+        return returnNorm;
+    }
+
+#endif

+ 34 - 0
jme3-core/src/main/resources/Common/ShaderLib/TriPlanarUtils.glsllib

@@ -0,0 +1,34 @@
+#ifndef __TRIPLANAR_UTILS_MODULE__
+    #define __TRIPLANAR_UTILS_MODULE__
+    
+    vec3 triBlending;
+    
+    void TriPlanarUtils_calculateBlending(vec3 geometryNormal){
+        triBlending = abs( geometryNormal );
+        triBlending = (triBlending -0.2) * 0.7;
+        triBlending = normalize(max(triBlending, 0.00001));      // Force weights to sum to 1.0 (very important!)
+        float b = (triBlending.x + triBlending.y + triBlending.z);
+        triBlending /= vec3(b, b, b);
+    }    
+
+    vec4 getTriPlanarBlend(in vec4 coords, in sampler2D map, in float scale) {
+        vec4 col1 = texture2D( map, coords.yz * scale);
+        vec4 col2 = texture2D( map, coords.xz * scale);
+        vec4 col3 = texture2D( map, coords.xy * scale); 
+        // blend the results of the 3 planar projections.
+        vec4 tex = col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z;
+
+        return tex;
+    }
+
+    vec4 getTriPlanarBlendFromTexArray(in vec4 coords, in int idInTexArray, in float scale, in sampler2DArray texArray) {
+        vec4 col1 = texture2DArray( texArray, vec3((coords.yz * scale), idInTexArray ) );
+        vec4 col2 = texture2DArray( texArray, vec3((coords.xz * scale), idInTexArray ) );
+        vec4 col3 = texture2DArray( texArray, vec3((coords.xy * scale), idInTexArray ) );
+        // blend the results of the 3 planar projections.
+        vec4 tex = col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z;
+
+        return tex;
+    }
+
+#endif