diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1')
28 files changed, 291 insertions, 95 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 32b768cc63..cc4cd8366c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -36,7 +36,7 @@ in vec2 vary_texcoord0; in vec3 vary_position; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -52,7 +52,10 @@ void main() frag_data[0] = vec4(diff.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = encodeNormal(nvn.xyz, 0, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 79c1b392e9..a2341a80ab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -40,7 +40,7 @@ in vec2 vary_texcoord0; in vec3 vary_position; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -52,18 +52,21 @@ void main() { discard; } - col *= vertex_color; + col *= vertex_color; - vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; + vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; - vec3 tnorm = vec3(dot(norm,vary_mat0), - dot(norm,vary_mat1), - dot(norm,vary_mat2)); + vec3 tnorm = vec3(dot(norm,vary_mat0), + dot(norm,vary_mat1), + dot(norm,vary_mat2)); - frag_data[0] = vec4(col.rgb, 0.0); - frag_data[1] = vertex_color.aaaa; // spec - //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested - vec3 nvn = normalize(tnorm); - frag_data[2] = encodeNormal(nvn, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(vertex_color.a, 0, 0, 0); + frag_data[0] = vec4(col.rgb, 0.0); + frag_data[1] = vertex_color.aaaa; // spec + //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested + vec3 nvn = normalize(tnorm); + frag_data[2] = encodeNormal(nvn, vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) + frag_data[3] = vec4(0, 0, 0, 0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 450d4c4c4a..8c51b4a36b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -114,9 +114,15 @@ void main() color.rgb *= 2.0; /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(0); + frag_data[1] = vec4(0.0,0.0,0.0,0.0); frag_data[2] = vec4(0,0,0,GBUFFER_FLAG_SKIP_ATMOS); + +#if defined(HAS_EMISSIVE) + frag_data[0] = vec4(0); frag_data[3] = vec4(color.rgb, alpha1); +#else + frag_data[0] = vec4(color.rgb, alpha1); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 5a83e19b37..b47fae73af 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -48,8 +48,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -uniform sampler2D normalMap; -uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D depthMap; uniform sampler2D projectionMap; // rgba uniform sampler2D brdfLut; @@ -62,6 +62,8 @@ uniform float proj_lod ; // (number of mips in proj map) uniform float proj_range; // range between near clip and far clip plane of projection uniform float proj_ambiance; +uniform int classic_mode; + // light params uniform vec3 color; // light_color uniform float size; // light_size @@ -73,11 +75,11 @@ const float M_PI = 3.14159265; const float ONE_OVER_PI = 0.3183098861; vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cs); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); vec4 decodeNormal(vec4 norm); - float calcLegacyDistanceAttenuation(float distance, float falloff) { float dist_atten = 1.0 - clamp((distance + falloff)/(1.0 + falloff), 0.0, 1.0); @@ -152,6 +154,12 @@ vec4 getNorm(vec2 screenpos) return norm; } +vec4 getNormRaw(vec2 screenpos) +{ + vec4 norm = texture(normalMap, screenpos.xy); + return norm; +} + // get linear depth value given a depth buffer sample d and znear and zfar values float linearDepth(float d, float znear, float zfar) { @@ -352,13 +360,15 @@ vec2 BRDF(float NoV, float roughness) } // set colorDiffuse and colorSpec to the results of GLTF PBR style IBL -vec3 pbrIbl(vec3 diffuseColor, +void pbrIbl(vec3 diffuseColor, vec3 specularColor, vec3 radiance, // radiance map sample vec3 irradiance, // irradiance map sample float ao, // ambient occlusion factor float nv, // normal dot view vector - float perceptualRough) + float perceptualRough, + out vec3 diffuseOut, + out vec3 specularOut) { // retrieve a scale and bias to F0. See [1], Figure 3 vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); @@ -368,7 +378,8 @@ vec3 pbrIbl(vec3 diffuseColor, vec3 diffuse = diffuseLight * diffuseColor; vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); - return (diffuse + specular) * ao; + diffuseOut = diffuse * ao; + specularOut = specular * ao; } @@ -431,12 +442,15 @@ float microfacetDistribution(PBRInfo pbrInputs) return roughnessSq / (M_PI * f * f); } -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, +void pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera - vec3 l) //surface point to light + vec3 l, + out float nl, + out vec3 diff, + out vec3 spec) //surface point to light { // make sure specular highlights from punctual lights don't fall off of polished surfaces perceptualRoughness = max(perceptualRoughness, 8.0/255.0); @@ -485,10 +499,11 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, // Calculation of analytical lighting contribution vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV); - // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) - vec3 color = NdotL * (diffuseContrib + specContrib); - return clamp(color, vec3(0), vec3(10)); + nl = NdotL; + + diff = diffuseContrib; + spec = specContrib; } vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, @@ -522,7 +537,12 @@ vec3 pbrCalcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, vec3 intensity = spot_atten * dist_atten * lightColor * 3.0; //magic number to balance with legacy materials - color = intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); + float nl = 0; + vec3 diffPunc = vec3(0); + vec3 specPunc = vec3(0); + + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, nl, diffPunc, specPunc); + color = intensity * clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)); } return color; @@ -541,10 +561,44 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 color = vec3(0); float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); + vec3 iblDiff = vec3(0); + vec3 iblSpec = vec3(0); + pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness, iblDiff, iblSpec); + + color += iblDiff; + + // For classic mode, we use a special version of pbrPunctual that basically gives us a deconstructed form of the lighting. + float nl = 0; + vec3 diffPunc = vec3(0); + vec3 specPunc = vec3(0); + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir), nl, diffPunc, specPunc); - color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); + // Depending on the sky, we combine these differently. + if (classic_mode > 0) + { + // Reconstruct the diffuse lighting that we do for blinn-phong materials here. + // A special note about why we do some really janky stuff for classic mode. + // Since adding classic mode, we've moved the lambertian diffuse multiply out from pbrPunctual and instead handle it in the different light type calcs. + // For classic mode, this baiscally introduces a double multiplication that we need to somehow avoid + // Using one of the old mobile gamma correction tricks (val * val to "linearize", sqrt(val) to bring back into sRGB), we can _mostly_ avert this + // This will never be 100% correct, but at the very least we can make it look mostly correct with legacy skies and classic mode. + + float da = pow(sqrt(nl), 1.2); + + vec3 sun_contrib = vec3(min(da, scol)); + + // Multiply by PI to account for lambertian diffuse colors. Otherwise things will be too dark when lit by the sun on legacy skies. + sun_contrib = srgb_to_linear(color.rgb * 0.9 + linear_to_srgb(sun_contrib) * sunlit * 0.7) * M_PI; + + // Manually recombine everything here. We have to separate the shading to ensure that lighting is able to more closely match blinn-phong. + color.rgb = srgb_to_linear(iblDiff) + clamp(sun_contrib * (da * (diffPunc.rgb + specPunc.rgb) * scol), vec3(0), vec3(10)); + } + else + { + color += clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)) * sunlit * 3.0 * scol; + } - color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 3.0 * scol; //magic number to balance with legacy materials + color.rgb += iblSpec.rgb; color += colorEmissive; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index fadf06d592..1307ee3bcc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -39,7 +39,7 @@ in vec2 vary_texcoord0; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -55,7 +55,10 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = encodeNormal(nvn.xyz, 0, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 10d06da416..5415ee80d0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -36,7 +36,7 @@ in vec4 vertex_color; in vec2 vary_texcoord0; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -52,6 +52,9 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = encodeNormal(nvn.xyz, 0, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index f7c8fc9596..d2ef7888a3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -33,7 +33,7 @@ uniform sampler2D diffuseMap; in vec3 vary_normal; in vec2 vary_texcoord0; -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -47,7 +47,10 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = encodeNormal(nvn.xyz, 0, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index d83f5a3145..85573d3baf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -35,7 +35,7 @@ in vec2 vary_texcoord0; in vec3 vary_position; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -44,7 +44,10 @@ void main() frag_data[0] = vec4(col, 0.0); frag_data[1] = vertex_color.aaaa; // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(vertex_color.a, 0, 0, 0); + frag_data[2] = encodeNormal(nvn.xyz, vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) + frag_data[3] = vec4(0, 0, 0, 0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 6d8943e7ae..ad4efc863b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -33,7 +33,7 @@ in vec2 vary_texcoord0; in vec3 vary_position; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); vec3 linear_to_srgb(vec3 c); @@ -48,6 +48,9 @@ void main() frag_data[0] = vec4(col, 0.0); frag_data[1] = vec4(spec, vertex_color.a); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(vertex_color.a, 0, 0, 0); + frag_data[2] = encodeNormal(nvn.xyz, vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) + frag_data[3] = vec4(0, 0, 0, 0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl index 67890032df..e4d89827f1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl @@ -35,7 +35,8 @@ uniform sampler2D exposureMap; uniform float dt; uniform vec2 noiseVec; -uniform vec3 dynamic_exposure_params; +uniform vec4 dynamic_exposure_params; +uniform vec4 dynamic_exposure_params2; float lum(vec3 col) { @@ -53,11 +54,11 @@ void main() L /= max_L; L = pow(L, 2.0); float s = mix(dynamic_exposure_params.z, dynamic_exposure_params.y, L); - #ifdef USE_LAST_EXPOSURE float prev = texture(exposureMap, vec2(0.5,0.5)).r; - s = mix(prev, s, min(dt*2.0*abs(prev-s), 0.04)); + float speed = -log(dynamic_exposure_params.w) / dynamic_exposure_params2.w; + s = mix(prev, s, 1 - exp(-speed * dt)); #endif frag_color = max(vec4(s, s, s, dt), vec4(0.0)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/gbufferUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/gbufferUtil.glsl new file mode 100644 index 0000000000..1ccc6e9fbc --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/gbufferUtil.glsl @@ -0,0 +1,59 @@ +/** + * @file class1/deferred/gbufferUtil.glsl + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; + +#if defined(HAS_EMISSIVE) +uniform sampler2D emissiveRect; +#endif + +vec4 getNormRaw(vec2 screenpos); +vec4 decodeNormal(vec4 norm); + +GBufferInfo getGBuffer(vec2 screenpos) +{ + GBufferInfo ret; + vec4 diffInfo = vec4(0); + vec4 specInfo = vec4(0); + vec4 emissInfo = vec4(0); + + diffInfo = texture(diffuseRect, screenpos.xy); + specInfo = texture(specularRect, screenpos.xy); + vec4 normInfo = getNormRaw(screenpos); + +#if defined(HAS_EMISSIVE) + emissInfo = texture(emissiveRect, screenpos.xy); +#endif + + ret.albedo = diffInfo; + ret.normal = decodeNormal(normInfo).xyz; + ret.specular = specInfo; + ret.envIntensity = normInfo.b; + ret.gbufferFlag = normInfo.w; + ret.emissive = emissInfo; + + return ret; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl index 2aac333543..2ed4ba3163 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl @@ -43,15 +43,19 @@ void mirrorClip(vec3 pos) } } -vec4 encodeNormal(vec3 norm, float gbuffer_flag) +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag) { - return vec4(norm * 0.5 + 0.5, gbuffer_flag); + float f = sqrt(8 * n.z + 8); + return vec4(n.xy / f + 0.5, env, gbuffer_flag); } vec4 decodeNormal(vec4 norm) { - norm.xyz = norm.xyz * 2.0 - 1.0; - return norm; + vec2 fenc = norm.xy*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec4 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; } - - diff --git a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl index 5c09950712..ca8c4caf16 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl @@ -35,5 +35,8 @@ void main() frag_data[0] = color*texture(diffuseMap, vary_texcoord0.xy); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index a6bca68cb0..9493afcc5e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -38,7 +38,7 @@ in vec2 vary_texcoord0; vec3 linear_to_srgb(vec3 c); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -55,5 +55,8 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = spec; frag_data[2] = vec4(norm.xyz, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index 3432bf07ef..4acab159cb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -51,8 +51,8 @@ void main() vec4 norm = texture(normalMap, tc); - if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI) && - !GET_GBUFFER_FLAG(GBUFFER_FLAG_SKIP_ATMOS)) + if (!GET_GBUFFER_FLAG(norm.w, GBUFFER_FLAG_HAS_HDRI) && + !GET_GBUFFER_FLAG(norm.w, GBUFFER_FLAG_SKIP_ATMOS)) { // Apply the diffuse luminance scale to objects but not the sky // Prevents underexposing when looking at bright environments diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c23729ef30..855fe69693 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -44,7 +44,9 @@ void main() frag_data[0] = vec4(0.5, 0, 1, 0); // gbuffer is sRGB for legacy materials frag_data[1] = vec4(0); // XYZ = Specular color. W = Specular exponent. frag_data[2] = vec4(0); // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); #endif +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 585de99e1d..29b4aafc03 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -56,7 +56,13 @@ void main() frag_data[0] = vec4(0); frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); + +#if defined(HAS_EMISSIVE) + frag_data[0] = vec4(0); frag_data[3] = vec4(c.rgb, c.a); +#else + frag_data[0] = vec4(c.rgb, c.a); +#endif // Added and commented out for a ground truth. Do not uncomment - Geenz //gl_FragDepth = 0.999985f; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index c0d4c387af..dd9e883fdf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -61,7 +61,7 @@ uniform vec4 clipPlane; uniform float clipSign; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); uniform mat3 normal_matrix; @@ -114,8 +114,11 @@ void main() // See: C++: addDeferredAttachments(), GLSL: softenLightF frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb,0.0), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = encodeNormal(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags + frag_data[2] = encodeNormal(tnorm, 0, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags + +#if defined(HAS_EMISSIVE) frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive +#endif } #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index b434479511..1b90cf9fde 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -162,7 +162,7 @@ in vec4[2] vary_coords; #endif void mirrorClip(vec3 position); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); float terrain_mix(TerrainMix tm, vec4 tms4); @@ -430,7 +430,10 @@ void main() #endif frag_data[0] = max(vec4(pbr_mix.col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(mix_orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = encodeNormal(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, flags + frag_data[2] = encodeNormal(tnorm, 0, GBUFFER_FLAG_HAS_PBR); // normal, flags + +#if defined(HAS_EMISSIVE) frag_data[3] = max(vec4(mix_emissive,0), vec4(0)); // PBR sRGB Emissive +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 41e42b5173..7639a5e6fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -117,8 +117,13 @@ void main() frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); } - frag_data[0] = vec4(0); frag_data[1] = vec4(0); + +#if defined(HAS_EMISSIVE) + frag_data[0] = vec4(0); frag_data[3] = vec4(color.rgb, 1.0); +#else + frag_data[0] = vec4(color.rgb, 1.0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index 6f45adc68d..dac272c686 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -58,9 +58,14 @@ void main() col.a = (col.a * factor) * 32.0f; col.a *= twinkle(); - frag_data[0] = vec4(0); frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); + +#if defined(HAS_EMISSIVE) + frag_data[0] = vec4(0); frag_data[3] = col; +#else + frag_data[0] = col; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index e3441add35..6dce67d2c5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -48,6 +48,11 @@ void main() frag_data[0] = vec4(0); frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); +#if defined(HAS_EMISSIVE) + frag_data[0] = vec4(0); frag_data[3] = c; +#else + frag_data[0] = c; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 5ff84b5937..ff6f1c0ba3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -39,7 +39,7 @@ in vec4 vary_texcoord0; in vec4 vary_texcoord1; void mirrorClip(vec3 position); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -61,7 +61,10 @@ void main() frag_data[0] = max(outColor, vec4(0)); frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = encodeNormal(nvn.xyz, 0, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 0894eff660..a96c8bada5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -37,7 +37,7 @@ in vec3 vary_position; uniform float minimum_alpha; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); void main() { @@ -51,6 +51,9 @@ void main() frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = encodeNormal(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = encodeNormal(nvn.xyz, 0, GBUFFER_FLAG_HAS_ATMOS); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl index 1d8a92bac7..daab7c1911 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl @@ -64,7 +64,7 @@ in vec2 base_color_uv; in vec2 emissive_uv; void mirrorClip(vec3 pos); -vec4 encodeNormal(vec3 norm, float gbuffer_flag); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -243,8 +243,11 @@ void main() #else frag_data[0] = max(vec4(basecolor.rgb, 0.0), vec4(0)); frag_data[1] = max(vec4(orm.rgb,0.0), vec4(0)); - frag_data[2] = encodeNormal(norm, GBUFFER_FLAG_HAS_PBR); + frag_data[2] = encodeNormal(norm, 0, GBUFFER_FLAG_HAS_PBR); + +//#if defined(HAS_EMISSIVE) frag_data[3] = max(vec4(emissive,0), vec4(0)); +//#endif #endif #endif diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl index 6a628bc852..f55b83d056 100644 --- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl +++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl @@ -197,7 +197,7 @@ out vec3 vary_fragcoord; layout (std140) uniform GLTFJoints { - mat3x4 gltf_joints[MAX_NODES_PER_GLTF_OBJECT]; + vec4 gltf_joints[MAX_NODES_PER_GLTF_OBJECT]; }; @@ -210,27 +210,22 @@ mat4 getGLTFTransform() vec4 w = weight4; - uint i1 = joint.x; - uint i2 = joint.y; - uint i3 = joint.z; - uint i4 = joint.w; + uint i1 = joint.x*3u; + uint i2 = joint.y*3u; + uint i3 = joint.z*3u; + uint i4 = joint.w*3u; - mat3 mat = mat3(gltf_joints[i1])*w.x; - mat += mat3(gltf_joints[i2])*w.y; - mat += mat3(gltf_joints[i3])*w.z; - mat += mat3(gltf_joints[i4])*w.w; - - vec3 trans = vec3(gltf_joints[i1][0].w,gltf_joints[i1][1].w,gltf_joints[i1][2].w)*w.x; - trans += vec3(gltf_joints[i2][0].w,gltf_joints[i2][1].w,gltf_joints[i2][2].w)*w.y; - trans += vec3(gltf_joints[i3][0].w,gltf_joints[i3][1].w,gltf_joints[i3][2].w)*w.z; - trans += vec3(gltf_joints[i4][0].w,gltf_joints[i4][1].w,gltf_joints[i4][2].w)*w.w; + // lerp the joints + vec4 v0 = gltf_joints[i1+0u] * w.x + gltf_joints[i2+0u] * w.y + gltf_joints[i3+0u] * w.z + gltf_joints[i4+0u] * w.w; + vec4 v1 = gltf_joints[i1+1u] * w.x + gltf_joints[i2+1u] * w.y + gltf_joints[i3+1u] * w.z + gltf_joints[i4+1u] * w.w; + vec4 v2 = gltf_joints[i1+2u] * w.x + gltf_joints[i2+2u] * w.y + gltf_joints[i3+2u] * w.z + gltf_joints[i4+2u] * w.w; + //unpack into return matrix mat4 ret; - - ret[0] = vec4(mat[0], 0); - ret[1] = vec4(mat[1], 0); - ret[2] = vec4(mat[2], 0); - ret[3] = vec4(trans, 1.0); + ret[0] = vec4(v0.xyz, 0); + ret[1] = vec4(v1.xyz, 0); + ret[2] = vec4(v2.xyz, 0); + ret[3] = vec4(v0.w, v1.w, v2.w, 1.0); return ret; } @@ -239,7 +234,7 @@ mat4 getGLTFTransform() layout (std140) uniform GLTFNodes { - mat3x4 gltf_nodes[MAX_NODES_PER_GLTF_OBJECT]; + vec4 gltf_nodes[MAX_NODES_PER_GLTF_OBJECT]; }; uniform int gltf_node_id = 0; @@ -247,13 +242,17 @@ uniform int gltf_node_id = 0; mat4 getGLTFTransform() { mat4 ret; - mat3x4 src = gltf_nodes[gltf_node_id]; + int idx = gltf_node_id*3; + + vec4 src0 = gltf_nodes[idx+0]; + vec4 src1 = gltf_nodes[idx+1]; + vec4 src2 = gltf_nodes[idx+2]; - ret[0] = vec4(src[0].xyz, 0); - ret[1] = vec4(src[1].xyz, 0); - ret[2] = vec4(src[2].xyz, 0); + ret[0] = vec4(src0.xyz, 0); + ret[1] = vec4(src1.xyz, 0); + ret[2] = vec4(src2.xyz, 0); - ret[3] = vec4(src[0].w, src[1].w, src[2].w, 1); + ret[3] = vec4(src0.w, src1.w, src2.w, 1); return ret; } diff --git a/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl b/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl index ee821d3884..b63dba3cc9 100644 --- a/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl @@ -31,5 +31,8 @@ void main() frag_data[0] = vec4(0, 0, 0, 0); frag_data[1] = vec4(0, 0, 0, 0); frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR); + +#if defined(HAS_EMISSIVE) frag_data[3] = vec4(1, 0, 0, 0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index 359bfe8253..205d4bff6d 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -41,6 +41,7 @@ uniform float scene_light_strength; uniform float sun_moon_glow_factor; uniform float sky_sunlight_scale; uniform float sky_ambient_scale; +uniform int classic_mode; float getAmbientClamp() { return 1.0f; } @@ -121,7 +122,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou // brightness of surface both sunlight and ambient sunlit = sunlight.rgb; - amblit = tmpAmbient; + amblit = pow(tmpAmbient.rgb, vec3(0.9)) * 0.57; additive *= vec3(1.0 - combined_haze); @@ -142,18 +143,22 @@ float ambientLighting(vec3 norm, vec3 light_dir) return ambient; } - // return lit amblit in linear space, leave sunlit and additive in sRGB space void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten) { calcAtmosphericVars(inPositionEye, light_dir, 1.0, sunlit, amblit, additive, atten); + amblit *= ambientLighting(norm, light_dir); + + if (classic_mode < 1) + { + amblit = srgb_to_linear(amblit); + sunlit = srgb_to_linear(sunlit); + } + // multiply to get similar colors as when the "scaleSoftClip" implementation was doubling color values // (allows for mixing of light sources other than sunlight e.g. reflection probes) sunlit *= sky_sunlight_scale; amblit *= sky_ambient_scale; - - amblit = srgb_to_linear(amblit); - amblit *= ambientLighting(norm, light_dir); } |