Skip to content
Snippets Groups Projects
Commit 2a5219b2 authored by David Parks's avatar David Parks
Browse files

SL-17701 WIP -- Correct color space management for base color and emissive...

SL-17701 WIP -- Correct color space management for base color and emissive color factors and textures.  Support for double sided alpha blended PBR materials.
parent 5a10b11b
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
......@@ -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);
......
......@@ -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.
}
......@@ -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;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment