|
@@ -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
|