summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl60
1 files changed, 47 insertions, 13 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
index 2cb7ff196b..410c447c64 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
@@ -30,6 +30,9 @@
#define TERRAIN_PBR_DETAIL_NORMAL -2
#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3
+#define TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE 0
+#define TERRAIN_PAINT_TYPE_PBR_PAINTMAP 1
+
#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
#define TerrainCoord vec4[3]
#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
@@ -48,6 +51,7 @@ struct TerrainMix
};
TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal);
+TerrainMix get_terrain_usage_from_weight3(vec3 weight3);
struct PBRMix
{
@@ -75,6 +79,9 @@ PBRMix terrain_sample_and_multiply_pbr(
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, sampler2D tex_vNt
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , float transform_sign
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, sampler2D tex_emissive
@@ -94,7 +101,11 @@ PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight);
out vec4 frag_data[4];
+#if TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE
uniform sampler2D alpha_ramp;
+#elif TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_PBR_PAINTMAP
+uniform sampler2D paint_map;
+#endif
// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures
uniform sampler2D detail_0_base_color;
@@ -130,19 +141,25 @@ uniform vec3[4] emissiveColors;
#endif
uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff()
-#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
-in vec4[10] vary_coords;
-#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
-in vec4[2] vary_coords;
-#endif
in vec3 vary_position;
in vec3 vary_normal;
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
in vec3 vary_tangents[4];
-flat in float vary_sign;
+flat in float vary_signs[4];
#endif
+
+// vary_texcoord* are used for terrain composition, vary_coords are used for terrain UVs
+#if TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE
in vec4 vary_texcoord0;
in vec4 vary_texcoord1;
+#elif TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_PBR_PAINTMAP
+in vec2 vary_texcoord;
+#endif
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+in vec4[10] vary_coords;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+in vec4[2] vary_coords;
+#endif
void mirrorClip(vec3 position);
@@ -150,11 +167,11 @@ float terrain_mix(TerrainMix tm, vec4 tms4);
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
// from mikktspace.com
-vec3 mikktspace(vec3 vNt, vec3 vT)
+vec3 mikktspace(vec3 vNt, vec3 vT, float sign)
{
vec3 vN = vary_normal;
- vec3 vB = vary_sign * cross(vN, vT);
+ vec3 vB = sign * cross(vN, vT);
vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
tnorm *= gl_FrontFacing ? 1.0 : -1.0;
@@ -168,11 +185,16 @@ void main()
// Make sure we clip the terrain if we're in a mirror.
mirrorClip(vary_position);
+ TerrainMix tm;
+#if TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE
float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a;
float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a;
float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a;
- TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal);
+ tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal);
+#elif TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_PBR_PAINTMAP
+ tm = get_terrain_usage_from_weight3(texture(paint_map, vary_texcoord).xyz);
+#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION)
// RGB = Occlusion, Roughness, Metal
@@ -216,6 +238,9 @@ void main()
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, detail_0_normal
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , vary_signs[0]
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, detail_0_emissive
@@ -231,7 +256,7 @@ void main()
#endif
);
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
- mix2.vNt = mikktspace(mix2.vNt, vary_tangents[0]);
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[0], vary_signs[0]);
#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.x);
break;
@@ -258,6 +283,9 @@ void main()
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, detail_1_normal
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , vary_signs[1]
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, detail_1_emissive
@@ -273,7 +301,7 @@ void main()
#endif
);
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
- mix2.vNt = mikktspace(mix2.vNt, vary_tangents[1]);
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[1], vary_signs[1]);
#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.y);
break;
@@ -300,6 +328,9 @@ void main()
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, detail_2_normal
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , vary_signs[2]
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, detail_2_emissive
@@ -315,7 +346,7 @@ void main()
#endif
);
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
- mix2.vNt = mikktspace(mix2.vNt, vary_tangents[2]);
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[2], vary_signs[2]);
#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.z);
break;
@@ -342,6 +373,9 @@ void main()
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, detail_3_normal
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , vary_signs[3]
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, detail_3_emissive
@@ -357,7 +391,7 @@ void main()
#endif
);
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
- mix2.vNt = mikktspace(mix2.vNt, vary_tangents[3]);
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[3], vary_signs[3]);
#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.w);
break;