diff options
author | Dave Parks <davep@lindenlab.com> | 2022-09-08 10:06:53 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2022-09-08 10:06:53 -0500 |
commit | 8ad7240a3bb626ebaabcc81fb8155a8cbb5adf39 (patch) | |
tree | 6830de5176cf8562b3e50a847496d8fe97bb00f1 /indra/newview/app_settings/shaders/class1 | |
parent | abf788175c451046f82cc9aeaddc894c47863ffa (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/app_settings/shaders/class1')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl | 29 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl | 28 |
2 files changed, 27 insertions, 30 deletions
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 |