summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl3
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl29
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl38
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl18
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl16
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/globalF.glsl10
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl18
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/moonF.glsl14
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl41
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl12
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl11
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl16
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl7
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl146
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl89
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl170
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl4
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl1
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/skyF.glsl16
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/skyV.glsl4
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl22
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl24
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl87
25 files changed, 565 insertions, 235 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl
index 49470f0e39..ce018623a8 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl
@@ -23,8 +23,7 @@
* $/LicenseInfo$
*/
-uniform sampler2D noiseMap;
-uniform sampler2D normalMap;
+uniform sampler2D noiseMap;
uniform sampler2D depthMap;
uniform float ssao_radius;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl
index 438e1d1b33..37dcbbd328 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl
@@ -27,8 +27,6 @@
out vec4 frag_color;
-uniform sampler2D diffuseMap;
-
void main()
{
frag_color = vec4(1,1,1,1);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
index 8627ab1852..23a3ca4911 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file blurLightF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -27,7 +27,6 @@
out vec4 frag_color;
-uniform sampler2D normalMap;
uniform sampler2D lightMap;
uniform float dist_factor;
@@ -42,16 +41,16 @@ in vec2 vary_fragcoord;
vec4 getPosition(vec2 pos_screen);
vec4 getNorm(vec2 pos_screen);
-void main()
+void main()
{
vec2 tc = vary_fragcoord.xy;
vec4 norm = getNorm(tc);
vec3 pos = getPosition(tc).xyz;
vec4 ccol = texture(lightMap, tc).rgba;
-
+
vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy);
dlt /= max(-pos.z*dist_factor, 1.0);
-
+
vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free'
vec4 col = defined_weight.xyxx * ccol;
@@ -75,15 +74,15 @@ void main()
k[1] = (k[0]+k[2])*0.5f;
k[3] = (k[2]+k[4])*0.5f;
k[5] = (k[4]+k[6])*0.5f;
-
+
for (int i = 1; i < 7; i++)
{
vec2 samptc = tc + k[i].z*dlt*2.0;
samptc /= screen_res;
- vec3 samppos = getPosition(samptc).xyz;
+ vec3 samppos = getPosition(samptc).xyz;
float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
-
+
if (d*d <= pointplanedist_tolerance_pow2)
{
col += texture(lightMap, samptc)*k[i].xyxx;
@@ -95,10 +94,10 @@ void main()
{
vec2 samptc = tc - k[i].z*dlt*2.0;
samptc /= screen_res;
- vec3 samppos = getPosition(samptc).xyz;
+ vec3 samppos = getPosition(samptc).xyz;
float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
-
+
if (d*d <= pointplanedist_tolerance_pow2)
{
col += texture(lightMap, samptc)*k[i].xyxx;
@@ -108,7 +107,7 @@ void main()
col /= defined_weight.xyxx;
//col.y *= col.y;
-
+
frag_color = max(col, vec4(0));
#ifdef IS_AMD_CARD
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
index 01543732d0..ab0e4fd4d8 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
@@ -50,7 +50,6 @@ SOFTWARE.
uniform sampler2D normalMap;
uniform sampler2D depthMap;
-uniform sampler2D emissiveRect;
uniform sampler2D projectionMap; // rgba
uniform sampler2D brdfLut;
@@ -487,6 +486,43 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
return clamp(color, vec3(0), vec3(10));
}
+vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
+ float perceptualRoughness,
+ float metallic,
+ vec3 n, // normal
+ vec3 p, // pixel position
+ vec3 v, // view vector (negative normalized pixel position)
+ vec3 lp, // light position
+ vec3 ld, // light direction (for spotlights)
+ vec3 lightColor,
+ float lightSize, float falloff, float is_pointlight, float ambiance)
+{
+ vec3 color = vec3(0,0,0);
+
+ vec3 lv = lp.xyz - p;
+
+ float lightDist = length(lv);
+
+ float dist = lightDist / lightSize;
+ if (dist <= 1.0)
+ {
+ lv /= lightDist;
+
+ float dist_atten = calcLegacyDistanceAttenuation(dist, falloff);
+
+ // spotlight coefficient.
+ float spot = max(dot(-ld, lv), is_pointlight);
+ // spot*spot => GL_SPOT_EXPONENT=2
+ float spot_atten = spot*spot;
+
+ vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials
+
+ color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv);
+ }
+
+ return color;
+}
+
void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor)
{
vec3 f0 = vec3(0.04);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl
index eff7221ae7..67890032df 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl
@@ -1,28 +1,28 @@
-/**
+/**
* @file exposureF.glsl
*
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
-
+
/*[EXTRA_CODE_HERE]*/
out vec4 frag_color;
@@ -43,7 +43,7 @@ float lum(vec3 col)
return dot(l, col);
}
-void main()
+void main()
{
vec2 tc = vec2(0.5,0.5);
@@ -53,13 +53,13 @@ void main()
L /= max_L;
L = pow(L, 2.0);
float s = mix(dynamic_exposure_params.z, dynamic_exposure_params.y, L);
-
+
#ifdef USE_LAST_EXPOSURE
float prev = texture(exposureMap, vec2(0.5,0.5)).r;
s = mix(prev, s, min(dt*2.0*abs(prev-s), 0.04));
#endif
-
+
frag_color = max(vec4(s, s, s, dt), vec4(0.0));
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
index 52dfed06ae..2b9cc6ae5a 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
@@ -1,28 +1,28 @@
-/**
+/**
* @file deferred/fullbrightF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
-
+
/*[EXTRA_CODE_HERE]*/
out vec4 frag_color;
@@ -52,7 +52,7 @@ vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
void mirrorClip(vec3 pos);
-void main()
+void main()
{
mirrorClip(vary_position);
#ifdef IS_ALPHA
@@ -90,7 +90,7 @@ void main()
calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten);
color.rgb = applySkyAndWaterFog(pos, additive, atten, color).rgb;
-
+
#endif
#endif
diff --git a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl
index 7e3e7d9271..a1b7a4b11f 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file class1/deferred/globalF.glsl
*
* $LicenseInfo:firstyear=2024&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2024, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl
index 95b2f80e06..3432bf07ef 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl
@@ -1,32 +1,32 @@
-/**
+/**
* @file luminanceF.glsl
*
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
-
+
/*[EXTRA_CODE_HERE]*/
-// take a luminance sample of diffuseRect and emissiveRect
+// take a luminance sample of diffuseRect and emissiveRect
out vec4 frag_color;
@@ -43,12 +43,12 @@ float lum(vec3 col)
return dot(l, col);
}
-void main()
+void main()
{
vec2 tc = vary_fragcoord*0.6+0.2;
tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky
vec3 c = texture(diffuseRect, tc).rgb;
-
+
vec4 norm = texture(normalMap, tc);
if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI) &&
diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl
index 6ef556d7e8..585de99e1d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl
@@ -1,28 +1,28 @@
-/**
+/**
* @file class1\deferred\moonF.glsl
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2005, 2020 Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
-
+
/*[EXTRA_CODE_HERE]*/
out vec4 frag_data[4];
@@ -34,7 +34,7 @@ uniform sampler2D diffuseMap;
in vec2 vary_texcoord0;
-void main()
+void main()
{
// Restore Pre-EEP alpha fade moon near horizon
float fade = 1.0;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl b/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl
index 902746366d..607a8c6ef6 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl
@@ -25,24 +25,53 @@
/*[EXTRA_CODE_HERE]*/
+
+
+// generate a normal map using an approximation of the old emboss bump map "brightness/darkness" technique
+// srcMap is a source color image, output should be a normal
+
out vec4 frag_color;
-uniform sampler2D alphaMap;
+uniform sampler2D srcMap;
in vec2 vary_texcoord0;
uniform float stepX;
uniform float stepY;
uniform float norm_scale;
+uniform int bump_code;
+
+#define BE_BRIGHTNESS 1
+#define BE_DARKNESS 2
+
+// get luminance or inverse luminance depending on bump_code
+float getBumpValue(vec2 texcoord)
+{
+ vec3 c = texture(srcMap, texcoord).rgb;
+
+ vec3 WEIGHT = vec3(0.2995, 0.5875, 0.1145);
+
+ float l = dot(c, WEIGHT);
+
+ if (bump_code == BE_DARKNESS)
+ {
+ l = 1.0 - l;
+ }
+
+ return l;
+}
+
void main()
{
- float c = texture(alphaMap, vary_texcoord0).r;
+ float c = getBumpValue(vary_texcoord0);
+
+ float scaler = 512.0;
- vec3 right = vec3(norm_scale, 0, (texture(alphaMap, vary_texcoord0+vec2(stepX, 0)).r-c)*255);
- vec3 left = vec3(-norm_scale, 0, (texture(alphaMap, vary_texcoord0-vec2(stepX, 0)).r-c)*255);
- vec3 up = vec3(0, -norm_scale, (texture(alphaMap, vary_texcoord0-vec2(0, stepY)).r-c)*255);
- vec3 down = vec3(0, norm_scale, (texture(alphaMap, vary_texcoord0+vec2(0, stepY)).r-c)*255);
+ vec3 right = vec3(norm_scale, 0, (getBumpValue(vary_texcoord0+vec2(stepX, 0))-c)*scaler);
+ vec3 left = vec3(-norm_scale, 0, (getBumpValue(vary_texcoord0-vec2(stepX, 0))-c)*scaler);
+ vec3 up = vec3(0, -norm_scale, (getBumpValue(vary_texcoord0-vec2(0, stepY))-c)*scaler);
+ vec3 down = vec3(0, norm_scale, (getBumpValue(vary_texcoord0+vec2(0, stepY))-c)*scaler);
vec3 norm = cross(right, down) + cross(down, left) + cross(left,up) + cross(up, right);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl
index 35b7602569..07a2218db2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file pbrShadowAlphaMaskF.glsl
*
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -33,7 +33,7 @@ in vec4 vertex_color;
in vec2 vary_texcoord0;
uniform float minimum_alpha;
-void main()
+void main()
{
float alpha = texture(diffuseMap,vary_texcoord0.xy).a * vertex_color.a;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl
index d0fc362db9..66adf50fa9 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl
@@ -51,8 +51,6 @@ uniform vec4[2] texture_emissive_transform;
out vec3 vary_fragcoord;
-uniform float near_clip;
-
in vec3 position;
in vec4 diffuse_color;
in vec3 normal;
@@ -71,7 +69,7 @@ flat out float vary_sign;
out vec3 vary_normal;
vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
-vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+vec4 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
void main()
@@ -88,7 +86,7 @@ void main()
#endif
gl_Position = vert;
- vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip);
+ vary_fragcoord.xyz = vert.xyz;
base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0);
normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0);
@@ -105,8 +103,9 @@ void main()
n = normalize(n);
- vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0));
- vary_sign = tangent.w;
+ vec4 transformed_tangent = tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0);
+ vary_tangent = normalize(transformed_tangent.xyz);
+ vary_sign = transformed_tangent.w;
vary_normal = n;
vertex_color = diffuse_color;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
index 380d493636..b521081af9 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file pbropaqueF.glsl
*
* $LicenseInfo:firstyear=2022&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2022, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -28,7 +28,7 @@
#ifndef IS_HUD
-// deferred opaque implementation
+// deferred opaque implementation
uniform sampler2D diffuseMap; //always in sRGB space
@@ -85,7 +85,7 @@ void main()
float sign = vary_sign;
vec3 vN = vary_normal;
vec3 vT = vary_tangent.xyz;
-
+
vec3 vB = sign * cross(vN, vT);
vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
@@ -95,7 +95,7 @@ void main()
// roughness 0.0
// metal 0.0
vec3 spec = texture(specularMap, metallic_roughness_texcoord.xy).rgb;
-
+
spec.g *= roughnessFactor;
spec.b *= metallicFactor;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
index fd020afd57..0ad9bf5e4b 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
@@ -63,7 +63,7 @@ out vec3 vary_normal;
out vec3 vary_position;
vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
-vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+vec4 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
void main()
{
@@ -97,8 +97,9 @@ void main()
n = normalize(n);
- vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0));
- vary_sign = tangent.w;
+ vec4 transformed_tangent = tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0);
+ vary_tangent = normalize(transformed_tangent.xyz);
+ vary_sign = transformed_tangent.w;
vary_normal = n;
vertex_color = diffuse_color;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
index 0de2d348c3..410c447c64 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file class1\deferred\terrainF.glsl
*
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -30,8 +30,11 @@
#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[2]
+#define TerrainCoord vec4[3]
#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
#define TerrainCoord vec2
#endif
@@ -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,36 +141,60 @@ uniform vec3[4] emissiveColors;
#endif
uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff()
-#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
-in vec4[2] vary_coords;
-#endif
in vec3 vary_position;
in vec3 vary_normal;
-in vec3 vary_tangent;
-flat in float vary_sign;
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+in vec3 vary_tangents[4];
+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);
float terrain_mix(TerrainMix tm, vec4 tms4);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+// from mikktspace.com
+vec3 mikktspace(vec3 vNt, vec3 vT, float sign)
+{
+ vec3 vN = vary_normal;
+
+ 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;
+
+ return tnorm;
+}
+#endif
+
void main()
{
// Make sure we clip the terrain if we're in a mirror.
mirrorClip(vary_position);
-#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
- TerrainCoord terrain_texcoord = vary_coords;
-#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
- TerrainCoord terrain_texcoord = vary_texcoord0.xy;
-#endif
-
+ 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
@@ -182,9 +217,19 @@ void main()
PBRMix pbr_mix = init_pbr_mix();
PBRMix mix2;
+ TerrainCoord terrain_texcoord;
switch (tm.type & MIX_X)
{
case MIX_X:
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ terrain_texcoord[0].xy = vary_coords[0].xy;
+ terrain_texcoord[0].zw = vary_coords[0].zw;
+ terrain_texcoord[1].xy = vary_coords[1].xy;
+ terrain_texcoord[1].zw = vary_coords[1].zw;
+ terrain_texcoord[2].xy = vary_coords[2].xy;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+ terrain_texcoord = vary_coords[0].xy;
+#endif
mix2 = terrain_sample_and_multiply_pbr(
terrain_texcoord
, detail_0_base_color
@@ -193,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
@@ -207,6 +255,9 @@ void main()
, emissiveColors[0]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[0], vary_signs[0]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.x);
break;
default:
@@ -215,6 +266,15 @@ void main()
switch (tm.type & MIX_Y)
{
case MIX_Y:
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ terrain_texcoord[0].xy = vary_coords[2].zw;
+ terrain_texcoord[0].zw = vary_coords[3].xy;
+ terrain_texcoord[1].xy = vary_coords[3].zw;
+ terrain_texcoord[1].zw = vary_coords[4].xy;
+ terrain_texcoord[2].xy = vary_coords[4].zw;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+ terrain_texcoord = vary_coords[0].zw;
+#endif
mix2 = terrain_sample_and_multiply_pbr(
terrain_texcoord
, detail_1_base_color
@@ -223,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
@@ -237,6 +300,9 @@ void main()
, emissiveColors[1]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[1], vary_signs[1]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.y);
break;
default:
@@ -245,6 +311,15 @@ void main()
switch (tm.type & MIX_Z)
{
case MIX_Z:
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ terrain_texcoord[0].xy = vary_coords[5].xy;
+ terrain_texcoord[0].zw = vary_coords[5].zw;
+ terrain_texcoord[1].xy = vary_coords[6].xy;
+ terrain_texcoord[1].zw = vary_coords[6].zw;
+ terrain_texcoord[2].xy = vary_coords[7].xy;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+ terrain_texcoord = vary_coords[1].xy;
+#endif
mix2 = terrain_sample_and_multiply_pbr(
terrain_texcoord
, detail_2_base_color
@@ -253,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
@@ -267,6 +345,9 @@ void main()
, emissiveColors[2]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[2], vary_signs[2]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.z);
break;
default:
@@ -275,6 +356,15 @@ void main()
switch (tm.type & MIX_W)
{
case MIX_W:
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ terrain_texcoord[0].xy = vary_coords[7].zw;
+ terrain_texcoord[0].zw = vary_coords[8].xy;
+ terrain_texcoord[1].xy = vary_coords[8].zw;
+ terrain_texcoord[1].zw = vary_coords[9].xy;
+ terrain_texcoord[2].xy = vary_coords[9].zw;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+ terrain_texcoord = vary_coords[1].zw;
+#endif
mix2 = terrain_sample_and_multiply_pbr(
terrain_texcoord
, detail_3_base_color
@@ -283,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
@@ -297,6 +390,9 @@ void main()
, emissiveColors[3]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[3], vary_signs[3]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.w);
break;
default:
@@ -311,20 +407,12 @@ void main()
float base_color_factor_alpha = terrain_mix(tm, vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z));
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
- // from mikktspace.com
- vec3 vNt = pbr_mix.vNt;
- vec3 vN = vary_normal;
- vec3 vT = vary_tangent.xyz;
-
- vec3 vB = vary_sign * cross(vN, vT);
- vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
-
- tnorm *= gl_FrontFacing ? 1.0 : -1.0;
+ vec3 tnorm = normalize(pbr_mix.vNt);
#else
vec3 tnorm = vary_normal;
- tnorm *= gl_FrontFacing ? 1.0 : -1.0;
#endif
-
+ tnorm *= gl_FrontFacing ? 1.0 : -1.0;
+
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
#define mix_emissive pbr_mix.emissive
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
index 935c3f9301..dc43007dca 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file class1\deferred\pbrterrainUtilF.glsl
*
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -51,7 +51,12 @@
#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
in vec3 vary_vertex_normal;
+#endif
vec3 srgb_to_linear(vec3 c);
@@ -202,6 +207,45 @@ TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal)
return tm;
}
+// A paintmap weight applier for 4 swatches. The input saves a channel by not
+// storing swatch 1, and assuming the weights of the 4 swatches add to 1.
+// The components of weight3 should be between 0 and 1
+// The sum of the components of weight3 should be between 0 and 1
+TerrainMix get_terrain_usage_from_weight3(vec3 weight3)
+{
+ // These steps ensure the output weights add to between 0 and 1
+ weight3.xyz = max(vec3(0.0), weight3.xyz);
+ weight3.xyz /= max(1.0, weight3.x + weight3.y + weight3.z);
+
+ TerrainMix tm;
+
+ // Extract the first weight from the other weights
+ tm.weight.x = 1.0 - (weight3.x + weight3.y + weight3.z);
+ tm.weight.yzw = weight3.xyz;
+ ivec4 usage = max(ivec4(0), ivec4(ceil(tm.weight)));
+
+ tm.type = (usage.x * MIX_X) |
+ (usage.y * MIX_Y) |
+ (usage.z * MIX_Z) |
+ (usage.w * MIX_W);
+ return tm;
+}
+
+// Inverse of get_terrain_usage_from_weight3, excluding usage flags
+// The components of weight should be between 0 and 1
+// The sum of the components of weight should be 1
+vec3 get_weight3_from_terrain_weight(vec4 weight)
+{
+ // These steps ensure the input weights add to 1
+ weight = max(vec4(0.0), weight);
+ weight.x += 1.0 - sign(weight.x + weight.y + weight.z + weight.w);
+ weight /= weight.x + weight.y + weight.z + weight.w;
+
+ // Then return the input weights with the first weight truncated
+ return weight.yzw;
+}
+
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
TerrainTriplanar _t_triplanar()
{
float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR;
@@ -219,6 +263,8 @@ TerrainTriplanar _t_triplanar()
((usage.z) * SAMPLE_Z);
return tw;
}
+#endif
+
// Assume weights add to 1
float terrain_mix(TerrainMix tm, vec4 tms4)
@@ -233,17 +279,12 @@ float terrain_mix(TerrainMix tm, vec4 tms4)
// Triplanar mapping
// Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused)
-#define TerrainCoord vec4[2]
+#define TerrainCoord vec4[3]
-vec2 _t_uv(vec2 uv_unflipped, float sign_or_zero)
+// If sign_or_zero is positive, use uv_unflippped, otherwise use uv_flipped
+vec2 _t_uv(vec2 uv_unflipped, vec2 uv_flipped, float sign_or_zero)
{
- // Handle case where sign is 0
- float sign = (2.0*sign_or_zero) + 1.0;
- sign /= abs(sign);
- // If the vertex normal is negative, flip the texture back
- // right-side up.
- vec2 uv = uv_unflipped * vec2(sign, 1);
- return uv;
+ return mix(uv_flipped, uv_unflipped, max(0.0, sign_or_zero));
}
vec3 _t_normal_post_1(vec3 vNt0, float sign_or_zero)
@@ -261,11 +302,12 @@ vec3 _t_normal_post_1(vec3 vNt0, float sign_or_zero)
}
// Triplanar-specific normal texture fixes
-vec3 _t_normal_post_x(vec3 vNt0)
+vec3 _t_normal_post_x(vec3 vNt0, float tangent_sign)
{
vec3 vNt_x = _t_normal_post_1(vNt0, sign(vary_vertex_normal.x));
// *HACK: Transform normals according to orientation of the UVs
vNt_x.xy = vec2(-vNt_x.y, vNt_x.x);
+ vNt_x.xy *= tangent_sign;
return vNt_x;
}
vec3 _t_normal_post_y(vec3 vNt0)
@@ -290,6 +332,7 @@ PBRMix terrain_sample_pbr(
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, sampler2D tex_vNt
+ , float tangent_sign
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, sampler2D tex_emissive
@@ -298,9 +341,9 @@ PBRMix terrain_sample_pbr(
{
PBRMix mix = init_pbr_mix();
-#define get_uv_x() _t_uv(terrain_coord[0].zw, sign(vary_vertex_normal.x))
-#define get_uv_y() _t_uv(terrain_coord[1].xy, sign(vary_vertex_normal.y))
-#define get_uv_z() _t_uv(terrain_coord[0].xy, sign(vary_vertex_normal.z))
+#define get_uv_x() _t_uv(terrain_coord[0].zw, terrain_coord[1].zw, sign(vary_vertex_normal.x))
+#define get_uv_y() _t_uv(terrain_coord[1].xy, terrain_coord[2].xy, sign(vary_vertex_normal.y))
+#define get_uv_z() _t_uv(terrain_coord[0].xy, vec2(0), sign(vary_vertex_normal.z))
switch (tw.type & SAMPLE_X)
{
case SAMPLE_X:
@@ -319,7 +362,7 @@ PBRMix terrain_sample_pbr(
);
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
// Triplanar-specific normal texture fix
- mix_x.vNt = _t_normal_post_x(mix_x.vNt);
+ mix_x.vNt = _t_normal_post_x(mix_x.vNt, tangent_sign);
#endif
mix = mix_pbr(mix, mix_x, tw.weight.x);
break;
@@ -379,7 +422,7 @@ PBRMix terrain_sample_pbr(
default:
break;
}
-
+
return mix;
}
@@ -425,6 +468,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 tangent_sign
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, sampler2D tex_emissive
@@ -451,6 +497,9 @@ PBRMix terrain_sample_and_multiply_pbr(
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
, tex_vNt
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+ , tangent_sign
+#endif
#endif
#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE)
, tex_emissive
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
index ed52297314..6791a22a76 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
@@ -23,35 +23,60 @@
* $/LicenseInfo$
*/
+#define TERRAIN_PBR_DETAIL_EMISSIVE 0
+#define TERRAIN_PBR_DETAIL_OCCLUSION -1
+#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
+
uniform mat3 normal_matrix;
uniform mat4 texture_matrix0;
uniform mat4 modelview_matrix;
uniform mat4 modelview_projection_matrix;
+#if TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_PBR_PAINTMAP
+uniform float region_scale;
+#endif
in vec3 position;
in vec3 normal;
in vec4 tangent;
in vec4 diffuse_color;
+#if TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE
in vec2 texcoord1;
+#endif
+out vec3 vary_position;
+out vec3 vary_normal;
#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
-out vec4[2] vary_coords;
-#endif
out vec3 vary_vertex_normal; // Used by pbrterrainUtilF.glsl
-out vec3 vary_normal;
-out vec3 vary_tangent;
-flat out float vary_sign;
+#endif
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+out vec3 vary_tangents[4];
+flat out 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
out vec4 vary_texcoord0;
out vec4 vary_texcoord1;
-out vec3 vary_position;
+#elif TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_PBR_PAINTMAP
+out vec2 vary_texcoord;
+#endif
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
+out vec4[10] vary_coords;
+#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
+out vec4[2] vary_coords;
+#endif
-// *HACK: tangent_space_transform should use texture_normal_transform, or maybe
-// we shouldn't use tangent_space_transform at all. See the call to
-// tangent_space_transform below.
-uniform vec4[2] texture_base_color_transform;
+// *HACK: Each material uses only one texture transform, but the KHR texture
+// transform spec allows handling texture transforms separately for each
+// individual texture info.
+uniform vec4[5] terrain_texture_transforms;
vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform);
-vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform);
+vec4 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform);
void main()
{
@@ -60,37 +85,120 @@ void main()
vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
vec3 n = normal_matrix * normal;
+#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
vary_vertex_normal = normal;
+#endif
vec3 t = normal_matrix * tangent.xyz;
- vary_tangent = normalize(t);
- // *TODO: Decide if we want this. It may be better to just calculate the
- // tangents on-the-fly in the fragment shader, due to the subtleties of the
- // effect of triplanar mapping on UVs.
- // *HACK: Should be using texture_normal_transform here. The KHR texture
- // transform spec requires handling texture transforms separately for each
- // individual texture.
- vary_tangent = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform));
- vary_sign = tangent.w;
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ {
+ vec4[2] ttt;
+ vec4 transformed_tangent;
+ // material 1
+ ttt[0].xyz = terrain_texture_transforms[0].xyz;
+ ttt[1].x = terrain_texture_transforms[0].w;
+ ttt[1].y = terrain_texture_transforms[1].x;
+ transformed_tangent = terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt);
+ vary_tangents[0] = normalize(transformed_tangent.xyz);
+ vary_signs[0] = transformed_tangent.w;
+ // material 2
+ ttt[0].xyz = terrain_texture_transforms[1].yzw;
+ ttt[1].xy = terrain_texture_transforms[2].xy;
+ transformed_tangent = terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt);
+ vary_tangents[1] = normalize(transformed_tangent.xyz);
+ vary_signs[1] = transformed_tangent.w;
+ // material 3
+ ttt[0].xy = terrain_texture_transforms[2].zw;
+ ttt[0].z = terrain_texture_transforms[3].x;
+ ttt[1].xy = terrain_texture_transforms[3].yz;
+ transformed_tangent = terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt);
+ vary_tangents[2] = normalize(transformed_tangent.xyz);
+ vary_signs[2] = transformed_tangent.w;
+ // material 4
+ ttt[0].x = terrain_texture_transforms[3].w;
+ ttt[0].yz = terrain_texture_transforms[4].xy;
+ ttt[1].xy = terrain_texture_transforms[4].zw;
+ transformed_tangent = terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt);
+ vary_tangents[3] = normalize(transformed_tangent.xyz);
+ vary_signs[3] = transformed_tangent.w;
+ }
+#endif
vary_normal = normalize(n);
// Transform and pass tex coords
- // *HACK: texture_base_color_transform is used for all of these here, but
- // the KHR texture transform spec requires handling texture transforms
- // separately for each individual texture.
+ {
+ vec4[2] ttt;
+#define transform_xy() terrain_texture_transform(position.xy, ttt)
#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
- // xy
- vary_coords[0].xy = terrain_texture_transform(position.xy, texture_base_color_transform);
- // yz
- vary_coords[0].zw = terrain_texture_transform(position.yz, texture_base_color_transform);
- // (-x)z
- vary_coords[1].xy = terrain_texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform);
+// Don't care about upside-down (transform_xy_flipped())
+#define transform_yz() terrain_texture_transform(position.yz, ttt)
+#define transform_negx_z() terrain_texture_transform(position.xz * vec2(-1, 1), ttt)
+#define transform_yz_flipped() terrain_texture_transform(position.yz * vec2(-1, 1), ttt)
+#define transform_negx_z_flipped() terrain_texture_transform(position.xz, ttt)
+ // material 1
+ ttt[0].xyz = terrain_texture_transforms[0].xyz;
+ ttt[1].x = terrain_texture_transforms[0].w;
+ ttt[1].y = terrain_texture_transforms[1].x;
+ vary_coords[0].xy = transform_xy();
+ vary_coords[0].zw = transform_yz();
+ vary_coords[1].xy = transform_negx_z();
+ vary_coords[1].zw = transform_yz_flipped();
+ vary_coords[2].xy = transform_negx_z_flipped();
+ // material 2
+ ttt[0].xyz = terrain_texture_transforms[1].yzw;
+ ttt[1].xy = terrain_texture_transforms[2].xy;
+ vary_coords[2].zw = transform_xy();
+ vary_coords[3].xy = transform_yz();
+ vary_coords[3].zw = transform_negx_z();
+ vary_coords[4].xy = transform_yz_flipped();
+ vary_coords[4].zw = transform_negx_z_flipped();
+ // material 3
+ ttt[0].xy = terrain_texture_transforms[2].zw;
+ ttt[0].z = terrain_texture_transforms[3].x;
+ ttt[1].xy = terrain_texture_transforms[3].yz;
+ vary_coords[5].xy = transform_xy();
+ vary_coords[5].zw = transform_yz();
+ vary_coords[6].xy = transform_negx_z();
+ vary_coords[6].zw = transform_yz_flipped();
+ vary_coords[7].xy = transform_negx_z_flipped();
+ // material 4
+ ttt[0].x = terrain_texture_transforms[3].w;
+ ttt[0].yz = terrain_texture_transforms[4].xy;
+ ttt[1].xy = terrain_texture_transforms[4].zw;
+ vary_coords[7].zw = transform_xy();
+ vary_coords[8].xy = transform_yz();
+ vary_coords[8].zw = transform_negx_z();
+ vary_coords[9].xy = transform_yz_flipped();
+ vary_coords[9].zw = transform_negx_z_flipped();
#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
- vary_texcoord0.xy = terrain_texture_transform(position.xy, texture_base_color_transform);
+ // material 1
+ ttt[0].xyz = terrain_texture_transforms[0].xyz;
+ ttt[1].x = terrain_texture_transforms[0].w;
+ ttt[1].y = terrain_texture_transforms[1].x;
+ vary_coords[0].xy = transform_xy();
+ // material 2
+ ttt[0].xyz = terrain_texture_transforms[1].yzw;
+ ttt[1].xy = terrain_texture_transforms[2].xy;
+ vary_coords[0].zw = transform_xy();
+ // material 3
+ ttt[0].xy = terrain_texture_transforms[2].zw;
+ ttt[0].z = terrain_texture_transforms[3].x;
+ ttt[1].xy = terrain_texture_transforms[3].yz;
+ vary_coords[1].xy = transform_xy();
+ // material 4
+ ttt[0].x = terrain_texture_transforms[3].w;
+ ttt[0].yz = terrain_texture_transforms[4].xy;
+ ttt[1].xy = terrain_texture_transforms[4].zw;
+ vary_coords[1].zw = transform_xy();
#endif
+ }
- vec4 tc = vec4(texcoord1,0,1);
+#if TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_HEIGHTMAP_WITH_NOISE
+ vec2 tc = texcoord1.xy;
vary_texcoord0.zw = tc.xy;
vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0);
vary_texcoord1.zw = tc.xy-vec2(1.0, 0.0);
+#elif TERRAIN_PAINT_TYPE == TERRAIN_PAINT_TYPE_PBR_PAINTMAP
+ vary_texcoord = position.xy / region_scale;
+#endif
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl
index cf0595ee45..e77e972873 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl
@@ -27,11 +27,11 @@
float random (vec2 uv)
{
- return 0;
+ return 0.f;
}
float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness)
{
collectedColor = vec4(0);
- return 0;
+ return 0.f;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl
index 9db8f461dd..f208ac746b 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl
@@ -27,8 +27,6 @@
out vec4 frag_color;
-uniform sampler2D diffuseMap;
-
in vec4 post_pos;
in float target_pos_x;
in vec4 vertex_color;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
index 16cc7cfbbc..6f7bd2bf3c 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
@@ -24,7 +24,6 @@
*/
uniform sampler2D normalMap;
-uniform sampler2D depthMap;
#if defined(SUN_SHADOW)
uniform sampler2DShadow shadowMap0;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl
index 785c748234..41e42b5173 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file class1/deferred/skyF.glsl
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2005, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -99,9 +99,9 @@ void main()
else
#endif
{
- // Potential Fill-rate optimization. Add cloud calculation
- // back in and output alpha of 0 (so that alpha culling kills
- // the fragment) if the sky wouldn't show up because the clouds
+ // Potential Fill-rate optimization. Add cloud calculation
+ // back in and output alpha of 0 (so that alpha culling kills
+ // the fragment) if the sky wouldn't show up because the clouds
// are fully opaque.
color = vary_HazeColor;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
index 24d2db2183..ea00d240df 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl
@@ -102,7 +102,7 @@ void main()
// Initialize temp variables
vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color * 0.7; //magic 0.7 to match legacy color
-
+
// Sunlight attenuation effect (hue and brightness) due to atmosphere
// this is used later for sunlight modulation at various altitudes
vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y);
@@ -152,7 +152,7 @@ void main()
sunlight *= max(0.0, (1. - cloud_shadow));
// Haze color below cloud
- vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient)
+ vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient)
+ (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient));
// Attenuate cloud color by atmosphere
diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl
index 5f598f84a7..1fd31e0546 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl
@@ -1,28 +1,28 @@
-/**
+/**
* @file class1\deferred\terrainF.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
-
+
/*[EXTRA_CODE_HERE]*/
out vec4 frag_data[4];
@@ -44,7 +44,7 @@ void main()
{
mirrorClip(pos);
/// Note: This should duplicate the blending functionality currently used for the terrain rendering.
-
+
vec4 color0 = texture(detail_0, vary_texcoord0.xy);
vec4 color1 = texture(detail_1, vary_texcoord0.xy);
vec4 color2 = texture(detail_2, vary_texcoord0.xy);
@@ -54,10 +54,10 @@ void main()
float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a;
float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a;
vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
-
- outColor.a = 0.0; // yes, downstream atmospherics
-
- frag_data[0] = outColor;
+
+ outColor.a = 0.0; // yes, downstream atmospherics
+
+ frag_data[0] = max(outColor, vec4(0));
frag_data[1] = vec4(0.0,0.0,0.0,-1.0);
vec3 nvn = normalize(vary_normal);
frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
index b4ab7cd169..7fc0e98513 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file class1\environment\terrainV.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2007, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -44,15 +44,15 @@ uniform vec4 object_plane_t;
vec2 texgen_object(vec4 vpos, mat4 mat, vec4 tp0, vec4 tp1)
{
vec4 tcoord;
-
+
tcoord.x = dot(vpos, tp0);
tcoord.y = dot(vpos, tp1);
tcoord.z = 0;
tcoord.w = 1;
- tcoord = mat * tcoord;
-
- return tcoord.xy;
+ tcoord = mat * tcoord;
+
+ return tcoord.xy;
}
void main()
@@ -65,12 +65,12 @@ void main()
pos = (modelview_matrix*pre_pos).xyz;
vary_normal = normalize(normal_matrix * normal);
-
+
// Transform and pass tex coords
vary_texcoord0.xy = texgen_object(vec4(position, 1.0), texture_matrix0, object_plane_s, object_plane_t);
-
+
vec4 t = vec4(texcoord1,0,1);
-
+
vary_texcoord0.zw = t.xy;
vary_texcoord1.xy = t.xy-vec2(2.0, 0.0);
vary_texcoord1.zw = t.xy-vec2(1.0, 0.0);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
index 7c02cb9d4a..c75a0e0d5d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
@@ -1,24 +1,24 @@
-/**
+/**
* @file class1/deferred/textureUtilV.glsl
*
* $LicenseInfo:firstyear=2023&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2023, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -48,6 +48,7 @@ vec2 khr_texture_transform(vec2 texcoord, vec2 scale, float rotation, vec2 offse
return (transform * vec3(texcoord, 1)).xy;
}
+// A texture transform function for PBR materials applied to shape prims/Collada model prims
// vertex_texcoord - The UV texture coordinates sampled from the vertex at
// runtime. Per SL convention, this is in a right-handed UV coordinate
// system. Collada models also have right-handed UVs.
@@ -93,36 +94,48 @@ vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform)
// Take the rotation only from both transforms and apply to the tangent. This
// accounts for the change of the topology of the normal texture when a texture
// rotation is applied to it.
+// In practice, this applies the inverse of the texture transform to the tangent.
+// It is effectively an inverse of the rotation
// *HACK: Assume the imported GLTF model did not have both normal texture
// transforms and tangent vertices. The use of this function is inconsistent
// with the GLTF sample viewer when that is the case. See getNormalInfo in
// https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Viewer/47a191931461a6f2e14de48d6da0f0eb6ec2d147/source/Renderer/shaders/material_info.glsl
// We may want to account for this case during GLTF model import.
// -Cosmic,2023-06-06
-vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform)
+vec4 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform)
{
- vec2 weights = vec2(0, 1);
-
- // Apply texture animation first to avoid shearing and other artifacts (rotation only)
- mat2 sl_rot_scale;
- sl_rot_scale[0][0] = sl_animation_transform[0][0];
- sl_rot_scale[0][1] = sl_animation_transform[0][1];
- sl_rot_scale[1][0] = sl_animation_transform[1][0];
- sl_rot_scale[1][1] = sl_animation_transform[1][1];
- weights = sl_rot_scale * weights;
- // Remove scale
- weights = normalize(weights);
+ // Immediately convert to left-handed coordinate system, but it has no
+ // effect here because y is 0 ((1,0) -> (1,0))
+ vec2 weights = vec2(1, 0);
- // Convert to left-handed coordinate system
- weights.y = -weights.y;
-
- // Apply KHR_texture_transform (rotation only)
- float khr_rotation = khr_gltf_transform[0].z;
+ // Apply inverse KHR_texture_transform (rotation and scale sign only)
+ float khr_rotation = -khr_gltf_transform[0].z;
mat2 khr_rotation_mat = mat2(
cos(khr_rotation),-sin(khr_rotation),
sin(khr_rotation), cos(khr_rotation)
);
weights = khr_rotation_mat * weights;
+ vec2 khr_scale_sign = sign(khr_gltf_transform[0].xy);
+ weights *= khr_scale_sign.xy;
+
+ // *NOTE: Delay conversion to right-handed coordinate system here, to
+ // remove the need for computing the inverse of the SL texture animation
+ // matrix.
+
+ // Apply texture animation last to avoid shearing and other artifacts (rotation only)
+ mat2 inv_sl_rot_scale;
+ inv_sl_rot_scale[0][0] = sl_animation_transform[0][0];
+ inv_sl_rot_scale[0][1] = sl_animation_transform[0][1];
+ inv_sl_rot_scale[1][0] = sl_animation_transform[1][0];
+ inv_sl_rot_scale[1][1] = sl_animation_transform[1][1];
+ weights = inv_sl_rot_scale * weights;
+ // *NOTE: Scale to be removed later
+
+ // Set weights to default if 0 for some reason
+ weights.x += 1.0 - abs(sign(sign(weights.x) + (0.5 * sign(weights.y))));
+
+ // Remove scale from SL texture animation transform
+ weights = normalize(weights);
// Convert back to right-handed coordinate system
weights.y = -weights.y;
@@ -131,27 +144,41 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh
// from the normal and tangent, as seen in the fragment shader
vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz);
- return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz);
+ // An additional sign flip prevents the binormal from being flipped as a
+ // result of a propagation of the tangent sign during the cross product.
+ float sign_flip = khr_scale_sign.x * khr_scale_sign.y;
+ return vec4((weights.x * vertex_tangent.xyz) + (weights.y * vertex_binormal.xyz), vertex_tangent.w * sign_flip);
}
-// Similar to tangent_space_transform but no no texture animation support.
-vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform)
+// Similar to tangent_space_transform but no texture animation support.
+vec4 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform)
{
- // Immediately convert to left-handed coordinate system ((0,1) -> (0, -1))
- vec2 weights = vec2(0, -1);
+ // Immediately convert to left-handed coordinate system, but it has no
+ // effect here because y is 0 ((1,0) -> (1,0))
+ vec2 weights = vec2(1, 0);
- // Apply KHR_texture_transform (rotation only)
- float khr_rotation = khr_gltf_transform[0].z;
+ // Apply inverse KHR_texture_transform (rotation and scale sign only)
+ float khr_rotation = -khr_gltf_transform[0].z;
mat2 khr_rotation_mat = mat2(
cos(khr_rotation),-sin(khr_rotation),
sin(khr_rotation), cos(khr_rotation)
);
weights = khr_rotation_mat * weights;
+ vec2 khr_scale_sign = sign(khr_gltf_transform[0].xy);
+ weights *= khr_scale_sign.xy;
+
+ // Set weights to default if 0 for some reason
+ weights.x += 1.0 - abs(sign(sign(weights.x) + (0.5 * sign(weights.y))));
// Convert back to right-handed coordinate system
weights.y = -weights.y;
+ // Similar to the MikkTSpace-compatible method of extracting the binormal
+ // from the normal and tangent, as seen in the fragment shader
vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz);
- return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz);
+ // An additional sign flip prevents the binormal from being flipped as a
+ // result of a propagation of the tangent sign during the cross product.
+ float sign_flip = khr_scale_sign.x * khr_scale_sign.y;
+ return vec4((weights.x * vertex_tangent.xyz) + (weights.y * vertex_binormal.xyz), vertex_tangent.w * sign_flip);
}