summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorCosmic Linden <cosmic@lindenlab.com>2023-10-13 10:39:45 -0700
committerCosmic Linden <cosmic@lindenlab.com>2023-10-13 10:39:45 -0700
commit2895b7bf81c3d076a8ceaa4ce77037e870069365 (patch)
treefb524f680e8decb2540cb623b589fcc933181e4b /indra/newview
parent3e3a3c1c5262e65df3edf27c4e27a6bbc8d49a01 (diff)
DRTVWR-592: Triplanar performance pass
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl63
1 files changed, 58 insertions, 5 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
index a89bc6f211..1b13bc8836 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
@@ -109,14 +109,67 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord)
// *NOTE: Bottom face has not been tested
vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord)
{
- vec3 x = _t_texture_n(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x));
+ float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR;
+ vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness));
+ float threshold = 0.01;
+ vec3 significant = max(vec3(0), sign(weight - threshold));
+ int sample_type = (int(significant.x) << 2) |
+ (int(significant.y) << 1) |
+ (int(significant.z) << 0);
+
+ #define SAMPLE_X 1 << 2
+ #define SAMPLE_Y 1 << 1
+ #define SAMPLE_Z 1 << 0
+ #define terrain_coord_x terrain_coord[0].zw
+ #define terrain_coord_y terrain_coord[1].xy
+ #define terrain_coord_z terrain_coord[0].xy
+ vec3 x;
+ vec3 y;
+ vec3 z;
+ switch (sample_type)
+ {
+ case SAMPLE_X | SAMPLE_Y | SAMPLE_Z:
+ x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x));
+ y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y));
+ z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z));
+ break;
+ case SAMPLE_X | SAMPLE_Y:
+ x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x));
+ y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y));
+ z = vec3(0);
+ break;
+ case SAMPLE_X | SAMPLE_Z:
+ x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x));
+ y = vec3(0);
+ z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z));
+ break;
+ case SAMPLE_Y | SAMPLE_Z:
+ x = vec3(0);
+ y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y));
+ z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z));
+ break;
+ case SAMPLE_X:
+ x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x));
+ y = vec3(0);
+ z = vec3(0);
+ break;
+ case SAMPLE_Y:
+ x = vec3(0);
+ y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y));
+ z = vec3(0);
+ break;
+ case SAMPLE_Z:
+ default:
+ x = vec3(0);
+ y = vec3(0);
+ z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z));
+ break;
+ }
+
+ // *HACK: Transform normals according to orientation of the UVs
x.xy = vec2(-x.y, x.x);
- vec3 y = _t_texture_n(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y));
y.xy = -y.xy;
- vec3 z = _t_texture_n(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z));
- float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR;
- vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness));
return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z);
}
#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1