summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings')
-rw-r--r--indra/newview/app_settings/settings.xml244
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl37
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl4
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl102
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl31
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl131
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl22
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl14
-rw-r--r--indra/newview/app_settings/shaders/class1/environment/srgbF.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl300
-rw-r--r--indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl171
-rw-r--r--indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl32
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/materialF.glsl1
13 files changed, 970 insertions, 121 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 587ae3c7c1..ecfef112a4 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -379,7 +379,7 @@
<key>Value</key>
<integer>0</integer>
</map>
- <key>AutoAcceptNewInventory</key>
+ <key>AutoAcceptNewInventory</key>
<map>
<key>Comment</key>
<string>Automatically accept new notecards/textures/landmarks</string>
@@ -9308,6 +9308,17 @@
<key>Value</key>
<real>8.0</real>
</map>
+ <key>RenderTerrainPBRTransformsEnabled</key>
+ <map>
+ <key>Comment</key>
+ <string>EXPERIMENTAL: Enable PBR Terrain texture transforms.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
<key>RenderTerrainPBRNormalsEnabled</key>
<map>
<key>Comment</key>
@@ -14634,6 +14645,226 @@
<key>Value</key>
<string>00000000-0000-0000-0000-000000000000</string>
</map>
+ <key>LocalTerrainTransform1ScaleU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset1 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform1ScaleV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset1 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform1Rotation</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset1 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform1OffsetU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset1 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform1OffsetV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset1 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform2ScaleU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset2 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform2ScaleV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset2 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform2Rotation</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset2 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform2OffsetU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset2 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform2OffsetV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset2 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform3ScaleU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset3 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform3ScaleV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset3 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform3Rotation</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset3 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform3OffsetU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset3 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform3OffsetV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset3 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform4ScaleU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset4 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform4ScaleV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset4 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>1.0</real>
+ </map>
+ <key>LocalTerrainTransform4Rotation</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset4 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform4OffsetU</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset4 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
+ <key>LocalTerrainTransform4OffsetV</key>
+ <map>
+ <key>Comment</key>
+ <string>KHR texture transform component if LocalTerrainAsset4 is set</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>F32</string>
+ <key>Value</key>
+ <real>0.0</real>
+ </map>
<key>PathfindingRetrieveNeighboringRegion</key>
<map>
<key>Comment</key>
@@ -15518,5 +15749,16 @@
<key>Value</key>
<integer>0</integer>
</map>
+ <key>GLTFEnabled</key>
+ <map>
+ <key>Comment</key>
+ <string>Enable GLTF support. Set to true by simulator if the simulator you are connected to supports GLTF Asset upload. WARNING: Manually setting this to true will enable buttons that can drain your L$ balance by implicitly uploading textures without asking.</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>0</integer>
+ </map>
</map>
</llsd>
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
index 01543732d0..3ea2248bec 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
@@ -487,6 +487,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/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl
index d0fc362db9..ae179d3f37 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;
@@ -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);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
index 71f4a93369..abb899a876 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$
*/
@@ -31,7 +31,7 @@
#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3
#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
@@ -131,12 +131,16 @@ uniform vec3[4] emissiveColors;
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;
-in vec3 vary_tangent;
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+in vec3 vary_tangents[4];
flat in float vary_sign;
+#endif
in vec4 vary_texcoord0;
in vec4 vary_texcoord1;
@@ -144,17 +148,26 @@ 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)
+{
+ vec3 vN = vary_normal;
+
+ 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;
+
+ 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
-
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;
@@ -182,9 +195,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
@@ -207,6 +230,9 @@ void main()
, emissiveColors[0]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[0]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.x);
break;
default:
@@ -215,6 +241,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
@@ -237,6 +272,9 @@ void main()
, emissiveColors[1]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[1]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.y);
break;
default:
@@ -245,6 +283,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
@@ -267,6 +314,9 @@ void main()
, emissiveColors[2]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[2]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.z);
break;
default:
@@ -275,6 +325,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
@@ -297,6 +356,9 @@ void main()
, emissiveColors[3]
#endif
);
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ mix2.vNt = mikktspace(mix2.vNt, vary_tangents[3]);
+#endif
pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.w);
break;
default:
@@ -311,20 +373,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 c44b60b6e5..7a7fd783ec 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$
*/
@@ -233,17 +233,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)
@@ -298,9 +293,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:
@@ -379,7 +374,7 @@ PBRMix terrain_sample_pbr(
default:
break;
}
-
+
return mix;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
index ed52297314..f8e826bbdb 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
@@ -23,6 +23,11 @@
* $/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
+
uniform mat3 normal_matrix;
uniform mat4 texture_matrix0;
uniform mat4 modelview_matrix;
@@ -34,21 +39,25 @@ in vec4 tangent;
in vec4 diffuse_color;
in vec2 texcoord1;
-#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;
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+out vec3 vary_tangents[4];
flat out float vary_sign;
+#endif
out vec4 vary_texcoord0;
out vec4 vary_texcoord1;
+#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
out vec3 vary_position;
-// *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);
@@ -63,31 +72,101 @@ void main()
vary_vertex_normal = normal;
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));
+#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL)
+ {
+ vec4[2] 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_tangents[0] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt));
+ // material 2
+ ttt[0].xyz = terrain_texture_transforms[1].yzw;
+ ttt[1].xy = terrain_texture_transforms[2].xy;
+ vary_tangents[1] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt));
+ // 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_tangents[2] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt));
+ // 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_tangents[3] = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, ttt));
+ }
+
vary_sign = 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;
#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_xy() terrain_texture_transform(position.xy, ttt)
+#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 = terrain_texture_transform(position.xy, ttt);
+ // material 2
+ ttt[0].xyz = terrain_texture_transforms[1].yzw;
+ ttt[1].xy = terrain_texture_transforms[2].xy;
+ vary_coords[0].zw = terrain_texture_transform(position.xy, ttt);
+ // 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 = terrain_texture_transform(position.xy, ttt);
+ // 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 = terrain_texture_transform(position.xy, ttt);
#endif
+ }
vec4 tc = vec4(texcoord1,0,1);
vary_texcoord0.zw = tc.xy;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl
index d6fe211910..5c79fd7315 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/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
index 6ba57f7543..bf5d106dab 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.
@@ -134,7 +135,8 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh
return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz);
}
-// Similar to tangent_space_transform but no no texture animation support.
+// Similar to tangent_space_transform but no offset during coordinate system
+// conversion, and no texture animation support.
vec3 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))
diff --git a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl
index 7e1d906878..d7f6d20547 100644
--- a/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl
+++ b/indra/newview/app_settings/shaders/class1/environment/srgbF.glsl
@@ -23,8 +23,6 @@
* $/LicenseInfo$
*/
- uniform sampler2D exposureMap;
-
vec3 srgb_to_linear(vec3 cs)
{
vec3 low_range = cs / vec3(12.92);
diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
new file mode 100644
index 0000000000..d71a3fad99
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
@@ -0,0 +1,300 @@
+/**
+ * @file pbrmetallicroughnessF.glsl
+ *
+ * $LicenseInfo:firstyear=2024&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$
+ */
+
+/*[EXTRA_CODE_HERE]*/
+
+
+// GLTF pbrMetallicRoughness implementation
+
+
+// ==================================
+// needed by all variants
+// ==================================
+uniform sampler2D diffuseMap; //always in sRGB space
+uniform sampler2D emissiveMap;
+uniform vec3 emissiveColor;
+in vec3 vary_position;
+in vec4 vertex_color;
+in vec2 base_color_texcoord;
+in vec2 emissive_texcoord;
+uniform float minimum_alpha;
+
+void mirrorClip(vec3 pos);
+vec3 linear_to_srgb(vec3 c);
+vec3 srgb_to_linear(vec3 c);
+// ==================================
+
+
+// ==================================
+// needed by all lit variants
+// ==================================
+#ifndef UNLIT
+uniform sampler2D normalMap;
+uniform sampler2D metallicRoughnessMap;
+uniform sampler2D occlusionMap;
+uniform float metallicFactor;
+uniform float roughnessFactor;
+in vec3 vary_normal;
+in vec3 vary_tangent;
+flat in float vary_sign;
+in vec2 normal_texcoord;
+in vec2 metallic_roughness_texcoord;
+#endif
+// ==================================
+
+
+// ==================================
+// needed by all alpha variants
+// ==================================
+#ifdef ALPHA_BLEND
+in vec3 vary_fragcoord;
+uniform vec4 clipPlane;
+uniform float clipSign;
+void waterClip(vec3 pos);
+void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
+vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
+#endif
+// ==================================
+
+
+// ==================================
+// needed by lit alpha
+// ==================================
+#if defined(ALPHA_BLEND) && !defined(UNLIT)
+
+#ifdef HAS_SUN_SHADOW
+uniform sampler2D lightMap;
+uniform vec2 screen_res;
+#endif
+
+// Lights
+// See: LLRender::syncLightState()
+uniform vec4 light_position[8];
+uniform vec3 light_direction[8]; // spot direction
+uniform vec4 light_attenuation[8]; // linear, quadratic, is omni, unused, See: LLPipeline::setupHWLights() and syncLightState()
+uniform vec3 light_diffuse[8];
+uniform vec2 light_deferred_attenuation[8]; // light size and falloff
+
+uniform int sun_up_factor;
+uniform vec3 sun_dir;
+uniform vec3 moon_dir;
+
+void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
+float calcLegacyDistanceAttenuation(float distance, float falloff);
+float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen);
+void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv,
+ vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear);
+
+void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor);
+
+vec3 pbrBaseLight(vec3 diffuseColor,
+ vec3 specularColor,
+ float metallic,
+ vec3 pos,
+ vec3 norm,
+ float perceptualRoughness,
+ vec3 light_dir,
+ vec3 sunlit,
+ float scol,
+ vec3 radiance,
+ vec3 irradiance,
+ vec3 colorEmissive,
+ float ao,
+ vec3 additive,
+ vec3 atten);
+
+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);
+
+#endif
+// ==================================
+
+
+// ==================================
+// output definition
+// ==================================
+#if defined(ALPHA_BLEND) || defined(UNLIT)
+out vec4 frag_color;
+#else
+out vec4 frag_data[4];
+#endif
+// ==================================
+
+
+void main()
+{
+
+// ==================================
+// all variants
+// mirror clip
+// base color
+// masking
+// emissive
+// ==================================
+ vec3 pos = vary_position;
+ mirrorClip(pos);
+
+ vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba;
+ basecolor.rgb = srgb_to_linear(basecolor.rgb);
+ basecolor *= vertex_color;
+
+ if (basecolor.a < minimum_alpha)
+ {
+ discard;
+ }
+
+ vec3 emissive = emissiveColor;
+ emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb);
+// ==================================
+
+// ==================================
+// all lit variants
+// prepare norm
+// prepare orm
+// ==================================
+#ifndef UNLIT
+ // from mikktspace.com
+ vec3 vNt = texture(normalMap, normal_texcoord.xy).xyz*2.0-1.0;
+ float sign = vary_sign;
+ vec3 vN = vary_normal;
+ vec3 vT = vary_tangent.xyz;
+
+ vec3 vB = sign * cross(vN, vT);
+ vec3 norm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
+ norm *= gl_FrontFacing ? 1.0 : -1.0;
+
+ // RGB = Occlusion, Roughness, Metal
+ // default values, see LLViewerTexture::sDefaultPBRORMImagep
+ // occlusion 1.0
+ // roughness 0.0
+ // metal 0.0
+ vec3 orm = texture(metallicRoughnessMap, metallic_roughness_texcoord.xy).rgb;
+ orm.r = texture(occlusionMap, metallic_roughness_texcoord.xy).r;
+ orm.g *= roughnessFactor;
+ orm.b *= metallicFactor;
+#endif
+// ==================================
+
+// ==================================
+// non alpha output
+// ==================================
+#ifndef ALPHA_BLEND
+#ifdef UNLIT
+ vec4 color = basecolor;
+ color.rgb += emissive.rgb;
+ frag_color = color;
+#else
+ frag_data[0] = max(vec4(basecolor.rgb, 0.0), vec4(0));
+ frag_data[1] = max(vec4(orm.rgb,0.0), vec4(0));
+ frag_data[2] = vec4(norm, GBUFFER_FLAG_HAS_PBR);
+ frag_data[3] = max(vec4(emissive,0), vec4(0));
+#endif
+#endif
+
+
+// ==================================
+// alpha implementation
+// ==================================
+#ifdef ALPHA_BLEND
+
+ float scol = 1.0;
+ vec3 sunlit;
+ vec3 amblit;
+ vec3 additive;
+ vec3 atten;
+
+ vec3 light_dir;
+
+#ifdef UNLIT
+ light_dir = vec3(0,0,1);
+ vec3 norm = vec3(0,0,1);
+#else
+ light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
+#endif
+
+ calcAtmosphericVarsLinear(pos.xyz, norm, light_dir, sunlit, amblit, additive, atten);
+
+#ifndef UNLIT
+ vec3 sunlit_linear = srgb_to_linear(sunlit);
+
+ vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
+
+#ifdef HAS_SUN_SHADOW
+ scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag);
+#endif
+
+ float perceptualRoughness = orm.g * roughnessFactor;
+ float metallic = orm.b * metallicFactor;
+
+ // PBR IBL
+ float gloss = 1.0 - perceptualRoughness;
+ vec3 irradiance = vec3(0);
+ vec3 radiance = vec3(0);
+ sampleReflectionProbes(irradiance, radiance, vary_position.xy*0.5+0.5, pos.xyz, norm.xyz, gloss, true, amblit);
+
+ vec3 diffuseColor;
+ vec3 specularColor;
+ calcDiffuseSpecular(basecolor.rgb, metallic, diffuseColor, specularColor);
+
+ vec3 v = -normalize(pos.xyz);
+
+ vec3 color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, emissive, orm.r, additive, atten);
+
+ vec3 light = vec3(0);
+
+ // Punctual lights
+#define LIGHT_LOOP(i) light += pbrCalcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w);
+
+ LIGHT_LOOP(1)
+ LIGHT_LOOP(2)
+ LIGHT_LOOP(3)
+ LIGHT_LOOP(4)
+ LIGHT_LOOP(5)
+ LIGHT_LOOP(6)
+ LIGHT_LOOP(7)
+
+ color.rgb += light.rgb;
+
+ color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb;
+
+ float a = basecolor.a*vertex_color.a;
+
+ frag_color = max(vec4(color.rgb,a), vec4(0));
+#else // UNLIT
+ vec4 color = basecolor;
+ color.rgb += emissive.rgb;
+ frag_color = color;
+#endif
+#endif // ALPHA_BLEND
+}
+
diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
new file mode 100644
index 0000000000..f123c29101
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
@@ -0,0 +1,171 @@
+/**
+ * @file pbrmetallicroughnessV.glsl
+ *
+ * $LicenseInfo:firstyear=2024&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$
+ */
+
+// GLTF pbrMetallicRoughness implementation
+
+uniform mat4 modelview_matrix;
+
+#ifdef HAS_SKIN
+uniform mat4 projection_matrix;
+#else
+uniform mat3 normal_matrix;
+uniform mat4 modelview_projection_matrix;
+#endif
+uniform mat4 texture_matrix0;
+
+uniform vec4[2] texture_base_color_transform;
+uniform vec4[2] texture_normal_transform;
+uniform vec4[2] texture_metallic_roughness_transform;
+uniform vec4[2] texture_emissive_transform;
+
+in vec3 position;
+in vec4 diffuse_color;
+in vec2 texcoord0;
+out vec2 base_color_texcoord;
+out vec2 emissive_texcoord;
+out vec4 vertex_color;
+out vec3 vary_position;
+
+#ifndef UNLIT
+in vec3 normal;
+in vec4 tangent;
+out vec2 normal_texcoord;
+out vec2 metallic_roughness_texcoord;
+out vec3 vary_tangent;
+flat out float vary_sign;
+out vec3 vary_normal;
+vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+#endif
+
+vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+
+
+#ifdef ALPHA_BLEND
+out vec3 vary_fragcoord;
+#endif
+
+#ifdef HAS_SKIN
+in uvec4 joint;
+in vec4 weight4;
+
+layout (std140) uniform GLTFJoints
+{
+ // list of OBBs for user override probes
+ mat3x4 gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT];
+};
+
+mat4 getGLTFSkinTransform()
+{
+ int i;
+
+ vec4 w = weight4;
+
+ uint i1 = joint.x;
+ uint i2 = joint.y;
+ uint i3 = joint.z;
+ uint i4 = joint.w;
+
+ mat3 mat = mat3(gltf_joints[i1])*w.x;
+ mat += mat3(gltf_joints[i2])*w.y;
+ mat += mat3(gltf_joints[i3])*w.z;
+ mat += mat3(gltf_joints[i4])*w.w;
+
+ vec3 trans = vec3(gltf_joints[i1][0].w,gltf_joints[i1][1].w,gltf_joints[i1][2].w)*w.x;
+ trans += vec3(gltf_joints[i2][0].w,gltf_joints[i2][1].w,gltf_joints[i2][2].w)*w.y;
+ trans += vec3(gltf_joints[i3][0].w,gltf_joints[i3][1].w,gltf_joints[i3][2].w)*w.z;
+ trans += vec3(gltf_joints[i4][0].w,gltf_joints[i4][1].w,gltf_joints[i4][2].w)*w.w;
+
+ mat4 ret;
+
+ ret[0] = vec4(mat[0], 0);
+ ret[1] = vec4(mat[1], 0);
+ ret[2] = vec4(mat[2], 0);
+ ret[3] = vec4(trans, 1.0);
+
+ return ret;
+
+#ifdef IS_AMD_CARD
+ // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
+ mat3x4 dummy1 = gltf_joints[0];
+ mat3x4 dummy2 = gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT-1];
+#endif
+
+}
+
+#endif
+
+void main()
+{
+#ifdef HAS_SKIN
+ mat4 mat = getGLTFSkinTransform();
+
+ mat = modelview_matrix * mat;
+
+ vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
+ vary_position = pos;
+
+ vec4 vert = projection_matrix * vec4(pos, 1.0);
+ gl_Position = vert;
+
+#else
+ vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
+ //transform vertex
+ vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0);
+ gl_Position = vert;
+#endif
+
+ base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0);
+ emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0);
+
+#ifndef UNLIT
+ normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0);
+ metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0);
+#endif
+
+
+#ifndef UNLIT
+#ifdef HAS_SKIN
+ vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz;
+ vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz;
+#else //HAS_SKIN
+ vec3 n = normal_matrix * normal;
+ vec3 t = normal_matrix * tangent.xyz;
+#endif
+
+ n = normalize(n);
+ vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0));
+ vary_sign = tangent.w;
+ vary_normal = n;
+#endif
+
+ vertex_color = diffuse_color;
+#ifdef ALPHA_BLEND
+ vary_fragcoord = vert.xyz;
+#endif
+}
+
+
+
+
diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl
index 17774adbf5..f4a8051427 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl
@@ -118,7 +118,7 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
vec3 v, // surface point to camera
vec3 l); //surface point to light
-vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
+vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
float perceptualRoughness,
float metallic,
vec3 n, // normal
@@ -127,33 +127,7 @@ vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor,
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;
-}
+ float lightSize, float falloff, float is_pointlight, float ambiance);
void main()
{
@@ -230,7 +204,7 @@ void main()
vec3 light = vec3(0);
// Punctual lights
-#define LIGHT_LOOP(i) light += calcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w);
+#define LIGHT_LOOP(i) light += pbrCalcPointLightOrSpotLight(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, pos.xyz, v, light_position[i].xyz, light_direction[i].xyz, light_diffuse[i].rgb, light_deferred_attenuation[i].x, light_deferred_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w);
LIGHT_LOOP(1)
LIGHT_LOOP(2)
diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
index d3e19cf4a8..26ab0406f6 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
@@ -77,7 +77,6 @@ uniform float is_mirror;
uniform vec3 sun_dir;
uniform vec3 moon_dir;
-in vec2 vary_fragcoord;
uniform mat4 proj_mat;
uniform mat4 inv_proj;