diff options
| author | Dave Parks <davep@lindenlab.com> | 2022-09-13 18:41:24 -0500 | 
|---|---|---|
| committer | Dave Parks <davep@lindenlab.com> | 2022-09-13 18:41:24 -0500 | 
| commit | 2a5219b23f5f91a2415a51324bb5c160a0139663 (patch) | |
| tree | 11d4e508d604c31d70da9c7f0641725763a0ef6b | |
| parent | 5a10b11b0d306334cd80f52f267ca8c525672062 (diff) | |
SL-17701 WIP -- Correct color space management for base color and emissive color factors and textures.  Support for double sided alpha blended PBR materials.
4 files changed, 14 insertions, 7 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl index d91cd63953..bb0c07915b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl @@ -202,7 +202,7 @@ void main()      }  #endif -    vec3 base = srgb_to_linear(vertex_color.rgb) * albedo.rgb; +    vec3 base = vertex_color.rgb * albedo.rgb;      vec4 norm = texture2D(bumpMap, vary_texcoord1.xy);      norm.xyz = normalize(norm.xyz * 2 - 1); @@ -212,6 +212,8 @@ void main()                        dot(norm.xyz,vary_mat2));      tnorm = normalize(tnorm.xyz); + +    tnorm *= gl_FrontFacing ? 1.0 : -1.0;      norm.xyz = tnorm.xyz;  #ifdef HAS_SHADOW @@ -230,7 +232,9 @@ void main()      packedORM.g *= roughnessFactor;      packedORM.b *= metallicFactor; -    vec3 colorEmissive = srgb_to_linear(emissiveColor); +    // emissiveColor is the emissive color factor from GLTF and is already in linear space +    vec3 colorEmissive = emissiveColor; +    // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear      colorEmissive *= srgb_to_linear(texture2D(emissiveMap, vary_texcoord0.xy).rgb);      vec3 colorDiffuse     = vec3(0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index f0f5208f52..ea28cca0cb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -50,6 +50,7 @@ uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlpha  vec2 encode_normal(vec3 n);  vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c);  uniform mat3 normal_matrix; @@ -64,7 +65,7 @@ void main()          discard;      } -    vec3 col = vertex_color.rgb * albedo.rgb; +    vec3 col = vertex_color.rgb * srgb_to_linear(albedo.rgb);      // from mikktspace.com      vec3 vNt = texture2D(bumpMap, vary_texcoord1.xy).xyz*2.0-1.0; @@ -86,7 +87,7 @@ void main()      spec.b *= metallicFactor;      vec3 emissive = emissiveColor; -    emissive *= texture2D(emissiveMap, vary_texcoord0.xy).rgb; +    emissive *= srgb_to_linear(texture2D(emissiveMap, vary_texcoord0.xy).rgb);      tnorm *= gl_FrontFacing ? 1.0 : -1.0; @@ -97,8 +98,8 @@ void main()      //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 +    frag_data[0] = vec4(linear_to_srgb(col), 0.0);                                                   // Diffuse +    frag_data[1] = vec4(linear_to_srgb(emissive), vertex_color.a);                                   // PBR sRGB Emissive      frag_data[2] = vec4(encode_normal(tnorm), vertex_color.a, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags      frag_data[3] = vec4(spec.rgb,0);                                                 // PBR linear packed Occlusion, Roughness, Metal.  } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 50aa93fea6..1a7e11a1cd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -131,7 +131,7 @@ void main()      float light_gamma = 1.0 / 1.3;      vec4 diffuse     = texture2DRect(diffuseRect, tc); -    vec4 spec        = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR sRGB Emissive +    vec4 spec        = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive  #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO)      vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index b992ab0394..90cf596345 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -615,6 +615,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)                  LLGLTFMaterial *gltf_mat = params.mGLTFMaterial; // Also see: LLPipeline::getPoolTypeFromTE()                  bool is_pbr = LLPipeline::sRenderPBR && gltf_mat; +                LLGLDisable cull_face(is_pbr && gltf_mat->mDoubleSided ? GL_CULL_FACE : 0); +                  if (is_pbr && gltf_mat->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_BLEND)                  {                      target_shader = &gDeferredPBRAlphaProgram; | 
