Skip to content

Commit c5ba0f1

Browse files
authored
Add files via upload
1 parent a4d18d8 commit c5ba0f1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __TANGENT_UTILS_MODULE__
2+
#define __TANGENT_UTILS_MODULE__
3+
4+
//used for calculating tangents in-shader
5+
6+
7+
//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)
8+
vec3 calculateTangentsAndApplyToNormals(in vec3 normalIn, in vec3 worldNorm){
9+
vec3 returnNorm = normalize((normalIn.xyz * vec3(2.0) - vec3(1.0)));
10+
11+
vec3 baseNorm = worldNorm.rgb + vec3(0, 0, 1);
12+
returnNorm *= vec3(-1, -1, 1);
13+
returnNorm = baseNorm.rgb*dot(baseNorm.rgb, returnNorm.rgb)/baseNorm.z - returnNorm.rgb;
14+
15+
returnNorm = normalize(returnNorm);
16+
17+
18+
return returnNorm;
19+
}
20+
21+
#endif
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef __TRIPLANAR_UTILS_MODULE__
2+
#define __TRIPLANAR_UTILS_MODULE__
3+
4+
vec3 triBlending;
5+
6+
void TriPlanarUtils_calculateBlending(vec3 geometryNormal){
7+
triBlending = abs( geometryNormal );
8+
triBlending = (triBlending -0.2) * 0.7;
9+
triBlending = normalize(max(triBlending, 0.00001)); // Force weights to sum to 1.0 (very important!)
10+
float b = (triBlending.x + triBlending.y + triBlending.z);
11+
triBlending /= vec3(b, b, b);
12+
}
13+
14+
vec4 getTriPlanarBlend(in vec4 coords, in sampler2D map, in float scale) {
15+
vec4 col1 = texture2D( map, coords.yz * scale);
16+
vec4 col2 = texture2D( map, coords.xz * scale);
17+
vec4 col3 = texture2D( map, coords.xy * scale);
18+
// blend the results of the 3 planar projections.
19+
vec4 tex = col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z;
20+
21+
return tex;
22+
}
23+
24+
vec4 getTriPlanarBlendFromTexArray(in vec4 coords, in int idInTexArray, in float scale, in sampler2DArray texArray) {
25+
vec4 col1 = texture2DArray( texArray, vec3((coords.yz * scale), idInTexArray ) );
26+
vec4 col2 = texture2DArray( texArray, vec3((coords.xz * scale), idInTexArray ) );
27+
vec4 col3 = texture2DArray( texArray, vec3((coords.xy * scale), idInTexArray ) );
28+
// blend the results of the 3 planar projections.
29+
vec4 tex = col1 * triBlending.x + col2 * triBlending.y + col3 * triBlending.z;
30+
31+
return tex;
32+
}
33+
34+
#endif

0 commit comments

Comments
 (0)