summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2022-09-08 10:06:53 -0500
committerDave Parks <davep@lindenlab.com>2022-09-08 10:06:53 -0500
commit8ad7240a3bb626ebaabcc81fb8155a8cbb5adf39 (patch)
tree6830de5176cf8562b3e50a847496d8fe97bb00f1 /indra/newview
parentabf788175c451046f82cc9aeaddc894c47863ffa (diff)
SL-18095 WIP -- Add Mikktspace tangent generation for PBR materials and switch to per-pixel binormal generation. Still bugged with some test content.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/settings.xml11
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl29
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl28
-rw-r--r--indra/newview/llface.cpp11
4 files changed, 46 insertions, 33 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index cd33690075..9508c1dc2d 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -10558,6 +10558,17 @@
<key>Value</key>
<integer>0</integer>
</map>
+ <key>RenderUseMikktSpace</key>
+ <map>
+ <key>Comment</key>
+ <string>Use Mikkt Space tangents on GLTF materials.</string>
+ <key>Persist</key>
+ <integer>1</integer>
+ <key>Type</key>
+ <string>Boolean</string>
+ <key>Value</key>
+ <integer>1</integer>
+ </map>
<key>RenderUseTriStrips</key>
<map>
<key>Comment</key>
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
index f5b5698305..69019667de 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
@@ -42,6 +42,8 @@ uniform vec3 emissiveColor;
#ifdef HAS_NORMAL_MAP
uniform sampler2D bumpMap;
+ VARYING vec3 vary_tangent;
+ flat in float vary_sign;
#endif
#ifdef HAS_EMISSIVE_MAP
@@ -66,9 +68,6 @@ VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
#ifdef HAS_NORMAL_MAP
VARYING vec3 vary_normal;
-VARYING vec3 vary_mat0;
-VARYING vec3 vary_mat1;
-VARYING vec3 vary_mat2;
VARYING vec2 vary_texcoord1;
#endif
@@ -94,21 +93,14 @@ void main()
vec3 col = vertex_color.rgb * albedo.rgb;
-#ifdef HAS_NORMAL_MAP
- vec4 norm = texture2D(bumpMap, vary_texcoord1.xy);
- norm.xyz = normalize(norm.xyz * 2 - 1);
-
- vec3 tnorm = vec3(dot(norm.xyz,vary_mat0),
- dot(norm.xyz,vary_mat1),
- dot(norm.xyz,vary_mat2));
-#else
- vec4 norm = vec4(0,0,0,1.0);
-// vec3 tnorm = vary_normal;
- vec3 tnorm = vec3(0,0,1);
-#endif
+ // from mikktspace.com
+ vec4 vNt = texture2D(bumpMap, vary_texcoord1.xy)*2.0-1.0;
+ float sign = vary_sign;
+ vec3 vN = vary_normal;
+ vec3 vT = vary_tangent.xyz;
- tnorm = normalize(tnorm.xyz);
- norm.xyz = tnorm.xyz;
+ vec3 vB = sign * cross(vN, vT);
+ vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
// RGB = Occlusion, Roughness, Metal
// default values, see LLViewerTexture::sDefaultPBRORMImagep
@@ -155,6 +147,9 @@ void main()
tnorm *= gl_FrontFacing ? 1.0 : -1.0;
+ //col = vec3(0,0,0);
+ //emissive = vary_tangent.xyz*0.5+0.5;
+ //emissive = vec3(vary_sign*0.5+0.5);
// See: C++: addDeferredAttachments(), GLSL: softenLightF
frag_data[0] = vec4(col, 0.0); // Diffuse
frag_data[1] = vec4(emissive, vertex_color.a); // PBR sRGB Emissive
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
index a2606ed771..e17d91af38 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
@@ -59,13 +59,7 @@ ATTRIBUTE vec2 texcoord0;
ATTRIBUTE vec4 tangent;
ATTRIBUTE vec2 texcoord1;
-VARYING vec3 vary_mat0;
-VARYING vec3 vary_mat1;
-VARYING vec3 vary_mat2;
-
VARYING vec2 vary_texcoord1;
-#else
-VARYING vec3 vary_normal;
#endif
#ifdef HAS_SPECULAR_MAP
@@ -75,6 +69,10 @@ VARYING vec2 vary_texcoord2;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
+VARYING vec3 vary_tangent;
+flat out float vary_sign;
+
+VARYING vec3 vary_normal;
void main()
{
@@ -113,9 +111,9 @@ void main()
vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz);
vec3 b = cross(n, t)*tangent.w;
- vary_mat0 = vec3(t.x, b.x, n.x);
- vary_mat1 = vec3(t.y, b.y, n.y);
- vary_mat2 = vec3(t.z, b.z, n.z);
+ //vary_mat0 = vec3(t.x, b.x, n.x);
+ //vary_mat1 = vec3(t.y, b.y, n.y);
+ //vary_mat2 = vec3(t.z, b.z, n.z);
#else //HAS_NORMAL_MAP
vary_normal = n;
#endif //HAS_NORMAL_MAP
@@ -123,12 +121,16 @@ vary_normal = n;
vec3 n = normalize(normal_matrix * normal);
#ifdef HAS_NORMAL_MAP
vec3 t = normalize(normal_matrix * tangent.xyz);
- vec3 b = cross(n,t)*tangent.w;
+ vary_tangent = t;
+ vary_sign = tangent.w;
+ vary_normal = n;
+
+ //vec3 b = cross(n,t)*tangent.w;
//vec3 t = cross(b,n) * binormal.w;
- vary_mat0 = vec3(t.x, b.x, n.x);
- vary_mat1 = vec3(t.y, b.y, n.y);
- vary_mat2 = vec3(t.z, b.z, n.z);
+ //vary_mat0 = vec3(t.x, b.x, n.x);
+ //vary_mat1 = vec3(t.y, b.y, n.y);
+ //vary_mat2 = vec3(t.z, b.z, n.z);
#else //HAS_NORMAL_MAP
vary_normal = n;
#endif //HAS_NORMAL_MAP
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 52aacb607c..f35b4b6d91 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -2166,14 +2166,19 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
mVertexBuffer->getTangentStrider(tangent, mGeomIndex, mGeomCount, map_range);
F32* tangents = (F32*) tangent.get();
- mVObjp->getVolume()->genTangents(f);
+ LLGLTFMaterial* gltf_mat = tep->getGLTFMaterial();
+ static LLCachedControl<bool> use_mikktspace(gSavedSettings, "RenderUseMikktSpace");
+ bool mikktspace = use_mikktspace && gltf_mat != nullptr;
+
+ mVObjp->getVolume()->genTangents(f, mikktspace);
LLVector4Logical mask;
mask.clear();
mask.setElement<3>();
- LLVector4a* src = vf.mTangents;
- LLVector4a* end = vf.mTangents+num_vertices;
+ LLVector4a* tbuff = mikktspace ? vf.mMikktSpaceTangents : vf.mTangents;
+ LLVector4a* src = tbuff;
+ LLVector4a* end = tbuff+num_vertices;
while (src < end)
{