summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl86
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl78
-rw-r--r--indra/newview/llface.cpp6
-rw-r--r--indra/newview/llmodelpreview.cpp20
4 files changed, 48 insertions, 142 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
index 69019667de..f0f5208f52 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
@@ -25,61 +25,34 @@
/*[EXTRA_CODE_HERE]*/
-#define DEBUG_PBR_LIGHT_TYPE 0 // Output Diffuse=0.75, Emissive=0, ORM=0,0,0
-
-#define DEBUG_BASIC 0
-#define DEBUG_VERTEX 0
-#define DEBUG_NORMAL_MAP 0 // Output packed normal map "as is" to diffuse
-#define DEBUG_NORMAL_OUT 0 // Output unpacked normal to diffuse
-#define DEBUG_ORM 0 // Output Occlusion Roughness Metal "as is" to diffuse
-#define DEBUG_POSITION 0
-
uniform sampler2D diffuseMap; //always in sRGB space
uniform float metallicFactor;
uniform float roughnessFactor;
uniform vec3 emissiveColor;
+uniform sampler2D bumpMap;
+uniform sampler2D emissiveMap;
+uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness
-#ifdef HAS_NORMAL_MAP
- uniform sampler2D bumpMap;
- VARYING vec3 vary_tangent;
- flat in float vary_sign;
-#endif
-
-#ifdef HAS_EMISSIVE_MAP
- uniform sampler2D emissiveMap;
-#endif
-
-#ifdef HAS_SPECULAR_MAP
- uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness
-#endif
-
-uniform samplerCube environmentMap;
-uniform mat3 env_mat;
-
-#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_data[4];
-#else
-#define frag_data gl_FragData
-#endif
VARYING vec3 vary_position;
VARYING vec4 vertex_color;
-VARYING vec2 vary_texcoord0;
-#ifdef HAS_NORMAL_MAP
VARYING vec3 vary_normal;
-VARYING vec2 vary_texcoord1;
-#endif
+VARYING vec3 vary_tangent;
+flat in float vary_sign;
-#ifdef HAS_SPECULAR_MAP
- VARYING vec2 vary_texcoord2;
-#endif
+VARYING vec2 vary_texcoord0;
+VARYING vec2 vary_texcoord1;
+VARYING vec2 vary_texcoord2;
uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff()
vec2 encode_normal(vec3 n);
vec3 linear_to_srgb(vec3 c);
+uniform mat3 normal_matrix;
+
void main()
{
// IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
@@ -94,11 +67,11 @@ void main()
vec3 col = vertex_color.rgb * albedo.rgb;
// from mikktspace.com
- vec4 vNt = texture2D(bumpMap, vary_texcoord1.xy)*2.0-1.0;
+ vec3 vNt = texture2D(bumpMap, vary_texcoord1.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 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
@@ -107,49 +80,22 @@ void main()
// occlusion 1.0
// roughness 0.0
// metal 0.0
-#ifdef HAS_SPECULAR_MAP
vec3 spec = texture2D(specularMap, vary_texcoord2.xy).rgb;
-#else
- vec3 spec = vec3(1,0,0);
-#endif
spec.g *= roughnessFactor;
spec.b *= metallicFactor;
vec3 emissive = emissiveColor;
-#ifdef HAS_EMISSIVE_MAP
emissive *= texture2D(emissiveMap, vary_texcoord0.xy).rgb;
-#endif
-
-#if DEBUG_PBR_LIGHT_TYPE
- col.rgb = vec3(0.75);
- emissive = vec3(0);
- spec.rgb = vec3(0);
-#endif
-#if DEBUG_BASIC
- col.rgb = vec3( 1, 0, 1 );
-#endif
-#if DEBUG_VERTEX
- col.rgb = vertex_color.rgb;
-#endif
-#if DEBUG_NORMAL_MAP
- col.rgb = texture2D(bumpMap, vary_texcoord1.xy).rgb;
-#endif
-#if DEBUG_NORMAL_OUT
- col.rgb = vary_normal;
-#endif
-#if DEBUG_ORM
- col.rgb = linear_to_srgb(spec);
-#endif
-#if DEBUG_POSITION
- col.rgb = vary_position.xyz;
-#endif
tnorm *= gl_FrontFacing ? 1.0 : -1.0;
+ //spec.rgb = vec3(1,1,0);
//col = vec3(0,0,0);
//emissive = vary_tangent.xyz*0.5+0.5;
- //emissive = vec3(vary_sign*0.5+0.5);
+ //emissive = vec3(sign*0.5+0.5);
+ //emissive = vNt * 0.5 + 0.5;
+ //emissive = tnorm*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 e17d91af38..5573c02a60 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
@@ -37,41 +37,24 @@ uniform mat3 normal_matrix;
uniform mat4 modelview_projection_matrix;
#endif
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
-
-#if !defined(HAS_SKIN)
-uniform mat4 modelview_matrix;
-#endif
-
-VARYING vec3 vary_position;
-
-#endif
-
uniform mat4 texture_matrix0;
ATTRIBUTE vec3 position;
ATTRIBUTE vec4 diffuse_color;
ATTRIBUTE vec3 normal;
-ATTRIBUTE vec2 texcoord0;
-
-
-#ifdef HAS_NORMAL_MAP
ATTRIBUTE vec4 tangent;
+ATTRIBUTE vec2 texcoord0;
ATTRIBUTE vec2 texcoord1;
+ATTRIBUTE vec2 texcoord2;
+VARYING vec2 vary_texcoord0;
VARYING vec2 vary_texcoord1;
-#endif
-
-#ifdef HAS_SPECULAR_MAP
-ATTRIBUTE vec2 texcoord2;
VARYING vec2 vary_texcoord2;
-#endif
VARYING vec4 vertex_color;
-VARYING vec2 vary_texcoord0;
+
VARYING vec3 vary_tangent;
flat out float vary_sign;
-
VARYING vec3 vary_normal;
void main()
@@ -83,64 +66,27 @@ void main()
vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
- vary_position = pos;
-#endif
-
gl_Position = projection_matrix*vec4(pos,1.0);
#else
//transform vertex
gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
-
#endif
vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
-
-#ifdef HAS_NORMAL_MAP
vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy;
-#endif
-
-#ifdef HAS_SPECULAR_MAP
vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy;
-#endif
-
#ifdef HAS_SKIN
- vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz);
-#ifdef HAS_NORMAL_MAP
- 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);
-#else //HAS_NORMAL_MAP
-vary_normal = n;
-#endif //HAS_NORMAL_MAP
+ 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 = normalize(normal_matrix * normal);
-#ifdef HAS_NORMAL_MAP
- vec3 t = normalize(normal_matrix * tangent.xyz);
- vary_tangent = t;
- vary_sign = tangent.w;
- vary_normal = n;
+ vec3 n = normal_matrix * normal;
+ vec3 t = normal_matrix * tangent.xyz;
+#endif
- //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);
-#else //HAS_NORMAL_MAP
- vary_normal = n;
-#endif //HAS_NORMAL_MAP
-#endif //HAS_SKIN
+ vary_tangent = normalize(t);
+ vary_sign = tangent.w;
+ vary_normal = normalize(n);
vertex_color = diffuse_color;
-
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
-#if !defined(HAS_SKIN)
- vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
-#endif
-#endif
}
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 33d6a205e7..3f69815e38 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -2177,6 +2177,11 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
mask.setElement<3>();
LLVector4a* tbuff = mikktspace ? vf.mMikktSpaceTangents : vf.mTangents;
+ if (tbuff == nullptr)
+ { // non-mesh prims will not have mikktspace tangents
+ tbuff = vf.mTangents;
+ }
+
LLVector4a* src = tbuff;
LLVector4a* end = tbuff+num_vertices;
@@ -2184,7 +2189,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
{
LLVector4a tangent_out;
mat_normal.rotate(*src, tangent_out);
- tangent_out.normalize3fast();
tangent_out.setSelectWithMask(mask, *src, tangent_out);
tangent_out.store4a(tangents);
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index c3fbada9db..2c0f0ae443 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -1308,9 +1308,10 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe
// extra space for normals and text coords
S32 tc_bytes_size = ((size_vertices * sizeof(LLVector2)) + 0xF) & ~0xF;
- LLVector4a* combined_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 2 * size_vertices + tc_bytes_size);
+ LLVector4a* combined_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 3 * size_vertices + tc_bytes_size);
LLVector4a* combined_normals = combined_positions + size_vertices;
- LLVector2* combined_tex_coords = (LLVector2*)(combined_normals + size_vertices);
+ LLVector4a* combined_tangents = combined_normals + size_vertices;
+ LLVector2* combined_tex_coords = (LLVector2*)(combined_tangents + size_vertices);
// copy indices and vertices into new buffers
S32 combined_positions_shift = 0;
@@ -1320,6 +1321,9 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe
{
const LLVolumeFace &face = base_model->getVolumeFace(face_idx);
+ // ensure tangents have been generated or loaded
+ llassert(face.mMikktSpaceTangents);
+
// Vertices
S32 copy_bytes = face.mNumVertices * sizeof(LLVector4a);
LLVector4a::memcpyNonAliased16((F32*)(combined_positions + combined_positions_shift), (F32*)face.mPositions, copy_bytes);
@@ -1327,6 +1331,9 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe
// Normals
LLVector4a::memcpyNonAliased16((F32*)(combined_normals + combined_positions_shift), (F32*)face.mNormals, copy_bytes);
+ // Tangents
+ LLVector4a::memcpyNonAliased16((F32*)(combined_tangents + combined_positions_shift), (F32*)face.mMikktSpaceTangents, copy_bytes);
+
// Tex coords
copy_bytes = face.mNumVertices * sizeof(LLVector2);
memcpy((void*)(combined_tex_coords + combined_positions_shift), (void*)face.mTexCoords, copy_bytes);
@@ -1428,9 +1435,10 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe
// IV. Repack back into individual faces
- LLVector4a* buffer_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 2 * size_vertices + tc_bytes_size);
+ LLVector4a* buffer_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 3 * size_vertices + tc_bytes_size);
LLVector4a* buffer_normals = buffer_positions + size_vertices;
- LLVector2* buffer_tex_coords = (LLVector2*)(buffer_normals + size_vertices);
+ LLVector4a* buffer_tangents = buffer_normals + size_vertices;
+ LLVector2* buffer_tex_coords = (LLVector2*)(buffer_tangents + size_vertices);
S32 buffer_idx_size = (size_indices * sizeof(U16) + 0xF) & ~0xF;
U16* buffer_indices = (U16*)ll_aligned_malloc_16(buffer_idx_size);
S32* old_to_new_positions_map = new S32[size_vertices];
@@ -1511,6 +1519,7 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe
// Copy vertice, normals, tcs
buffer_positions[buf_positions_copied] = combined_positions[idx];
buffer_normals[buf_positions_copied] = combined_normals[idx];
+ buffer_tangents[buf_positions_copied] = combined_tangents[idx];
buffer_tex_coords[buf_positions_copied] = combined_tex_coords[idx];
old_to_new_positions_map[idx] = buf_positions_copied;
@@ -1549,12 +1558,13 @@ F32 LLModelPreview::genMeshOptimizerPerModel(LLModel *base_model, LLModel *targe
{
new_face.resizeIndices(buf_indices_copied);
new_face.resizeVertices(buf_positions_copied);
-
+ new_face.allocateTangents(buf_positions_copied, true);
S32 idx_size = (buf_indices_copied * sizeof(U16) + 0xF) & ~0xF;
LLVector4a::memcpyNonAliased16((F32*)new_face.mIndices, (F32*)buffer_indices, idx_size);
LLVector4a::memcpyNonAliased16((F32*)new_face.mPositions, (F32*)buffer_positions, buf_positions_copied * sizeof(LLVector4a));
LLVector4a::memcpyNonAliased16((F32*)new_face.mNormals, (F32*)buffer_normals, buf_positions_copied * sizeof(LLVector4a));
+ LLVector4a::memcpyNonAliased16((F32*)new_face.mMikktSpaceTangents, (F32*)buffer_tangents, buf_positions_copied * sizeof(LLVector4a));
U32 tex_size = (buf_positions_copied * sizeof(LLVector2) + 0xF)&~0xF;
LLVector4a::memcpyNonAliased16((F32*)new_face.mTexCoords, (F32*)buffer_tex_coords, tex_size);