diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class3')
11 files changed, 366 insertions, 208 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl index 7b82aa1a0d..487db0a6ae 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/hazeF.glsl @@ -64,8 +64,6 @@ void main() calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); - vec3 sunlit_linear = srgb_to_linear(sunlit); - // mask off atmospherics below water (when camera is under water) bool do_atmospherics = false; diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 5ee9aea09d..f8803f1a29 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -36,6 +36,7 @@ uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 otherwise uniform int sun_up_factor; +uniform int classic_mode; vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); vec3 scaleSoftClipFragLinear(vec3 l); @@ -51,6 +52,7 @@ uniform mat3 normal_matrix; in vec3 vary_position; void mirrorClip(vec3 pos); +vec4 encodeNormal(vec3 n, float env, float gbuffer_flag); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -136,9 +138,9 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float lit = 0.0f; float amb_da = ambiance; - if (da >= 0) + if (da >= 0.0) { - lit = max(da * dist_atten, 0.0); + lit = clamp(da * dist_atten, 0.0, 1.0); col = lit * light_col * diffuse; amb_da += (da*0.5 + 0.5) * ambiance; } @@ -157,10 +159,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float nv = dot(n, npos); float vh = dot(npos, h); float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; + float fres = pow(1.0 - dot(h, npos), 5.0)*0.4 + 0.5; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + float gtdenom = 2.0 * nh; + float gt = max(0.0, min(gtdenom * nv / vh, gtdenom * da / vh)); if (nh > 0.0) { @@ -176,8 +178,10 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } } } - - return max(col, vec3(0.0, 0.0, 0.0)); + float final_scale = 1.0; + if (classic_mode > 0) + final_scale = 0.9; + return max(col * final_scale, vec3(0.0, 0.0, 0.0)); } #else @@ -221,7 +225,7 @@ vec3 getNormal(inout float glossiness) #ifdef HAS_NORMAL_MAP vec4 vNt = texture(bumpMap, vary_texcoord1.xy); glossiness *= vNt.a; - vNt.xyz = vNt.xyz * 2 - 1; + vNt.xyz = vNt.xyz * 2.0 - 1.0; float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -327,11 +331,12 @@ void main() vec3 additive; vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); - - vec3 sunlit_linear = srgb_to_linear(sunlit); + if (classic_mode > 0) + sunlit *= 1.35; + vec3 sunlit_linear = sunlit; vec3 amblit_linear = amblit; - vec3 ambenv; + vec3 ambenv = amblit; vec3 glossenv; vec3 legacyenv; sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env, true, amblit_linear); @@ -339,8 +344,20 @@ void main() color = ambenv; float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - vec3 sun_contrib = min(da, shadow) * sunlit_linear; - color.rgb += sun_contrib; + if (classic_mode > 0) + { + da = pow(da,1.2); + vec3 sun_contrib = vec3(min(da, shadow)); + + color.rgb = srgb_to_linear(color.rgb * 0.9 + linear_to_srgb(sun_contrib) * sunlit_linear * 0.7); + sunlit_linear = srgb_to_linear(sunlit_linear); + } + else + { + vec3 sun_contrib = min(da, shadow) * sunlit_linear; + color.rgb += sun_contrib; + } + color *= diffcol.rgb; vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -360,9 +377,9 @@ void main() float lit = min(nl*6.0, 1.0); float sa = nh; - float fres = pow(1 - vh, 5) * 0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + float fres = pow(1.0 - vh, 5.0) * 0.4+0.5; + float gtdenom = 2.0 * nh; + float gt = max(0.0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); float scol = shadow*fres*texture(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl); color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; @@ -379,7 +396,7 @@ void main() applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, env); float cur_glare = max(max(legacyenv.r, legacyenv.g), legacyenv.b); - cur_glare = clamp(cur_glare, 0, 1); + cur_glare = clamp(cur_glare, 0.0, 1.0); cur_glare *= env; glare += cur_glare; } @@ -404,8 +421,10 @@ void main() glare *= 1.0-emissive; glare = min(glare, 1.0); float al = max(diffcol.a, glare) * vertex_color.a; - - frag_color = max(vec4(color, al), vec4(0)); + float final_scale = 1; + if (classic_mode > 0) + final_scale = 1.1; + frag_color = max(vec4(color * final_scale, al), vec4(0)); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl @@ -414,8 +433,11 @@ void main() frag_data[0] = max(vec4(diffcol.rgb, emissive), vec4(0)); // gbuffer is sRGB for legacy materials frag_data[1] = max(vec4(spec.rgb, glossiness), vec4(0)); // XYZ = Specular color. W = Specular exponent. - frag_data[2] = vec4(norm, flag); // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) - frag_data[3] = vec4(env, 0, 0, 0); + frag_data[2] = encodeNormal(norm, env, flag); // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) + +#if defined(HAS_EMISSIVE) + frag_data[3] = vec4(0, 0, 0, 0); +#endif #endif } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 4ed778371f..b11c2644aa 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,9 +27,6 @@ out vec4 frag_color; -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D lightFunc; uniform vec3 env_mat[3]; @@ -41,6 +38,7 @@ uniform vec4 light_col[LIGHT_COUNT]; // .a = falloff uniform vec2 screen_res; uniform float far_z; uniform mat4 inv_proj; +uniform int classic_mode; in vec4 vary_fragcoord; @@ -55,13 +53,17 @@ vec3 srgb_to_linear(vec3 c); // Util vec3 hue_to_rgb(float hue); -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, // surface point to light + out float nl, + out vec3 diff, + out vec3 spec); +GBufferInfo getGBuffer(vec2 screenpos); void main() { @@ -73,18 +75,19 @@ void main() discard; } - vec4 norm = getNorm(tc); // need `norm.w` for GET_GBUFFER_FLAG() - vec3 n = norm.xyz; + GBufferInfo gb = getGBuffer(tc); - vec4 spec = texture(specularRect, tc); - vec3 diffuse = texture(diffuseRect, tc).rgb; + vec3 n = gb.normal; + + vec4 spec = gb.specular; + vec3 diffuse = gb.albedo.rgb; vec3 h, l, v = -normalize(pos); float nh, nv, vh, lightDist; - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + if (GET_GBUFFER_FLAG(gb.gbufferFlag, GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture(emissiveRect, tc).rgb; + vec3 colorEmissive = gb.emissive.rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -113,8 +116,11 @@ void main() float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); vec3 intensity = dist_atten * lightColor * 3.25; - - final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); + float nl = 0; + vec3 diff = vec3(0); + vec3 specPunc = vec3(0); + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv, nl, diff, specPunc); + final_color += intensity * clamp(nl * (diff + specPunc), vec3(0), vec3(10)); } } } @@ -147,10 +153,10 @@ void main() if (spec.a > 0.0) { lit = min(nl * 6.0, 1.0) * dist_atten; - float fres = pow(1 - vh, 5) * 0.4 + 0.5; + float fres = pow(1.0 - vh, 5.0) * 0.4 + 0.5; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); + float gtdenom = 2.0 * nh; + float gt = max(0.0, min(gtdenom * nv / vh, gtdenom * nl / vh)); if (nh > 0.0) { @@ -164,8 +170,10 @@ void main() } } } - - frag_color.rgb = max(final_color, vec3(0)); + float final_scale = 1.0; + if (classic_mode > 0) + final_scale = 0.9; + frag_color.rgb = max(final_color * final_scale, vec3(0)); frag_color.a = 0.0; #ifdef IS_AMD_CARD diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 6c13757149..6a248f25bc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -27,9 +27,6 @@ out vec4 frag_color; -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D lightFunc; uniform vec3 env_mat[3]; @@ -47,6 +44,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; +uniform int classic_mode; void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); float calcLegacyDistanceAttenuation(float distance, float falloff); @@ -57,24 +55,29 @@ vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); float getDepth(vec2 tc); -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, // surface point to light + out float nl, + out vec3 diff, + out vec3 spec); + +GBufferInfo getGBuffer(vec2 screenpos); void main() { vec3 final_color = vec3(0); vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; + GBufferInfo gb = getGBuffer(tc); - vec4 norm = getNorm(tc); // need `norm.w` for GET_GBUFFER_FLAG() - vec3 n = norm.xyz; + vec3 n = gb.normal; - vec3 diffuse = texture(diffuseRect, tc).rgb; - vec4 spec = texture(specularRect, tc); + vec3 diffuse = gb.albedo.rgb; + vec4 spec = gb.specular; // Common half vectors calcs vec3 lv = trans_center.xyz-pos; @@ -89,9 +92,9 @@ void main() float dist = lightDist / size; float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + if (GET_GBUFFER_FLAG(gb.gbufferFlag, GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture(emissiveRect, tc).rgb; + vec3 colorEmissive = gb.emissive.rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -104,7 +107,14 @@ void main() vec3 specularColor = mix(f0, baseColor.rgb, metallic); vec3 intensity = dist_atten * color * 3.25; // Legacy attenuation, magic number to balance with legacy materials - final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); + + float nl = 0; + vec3 diffPunc = vec3(0); + vec3 specPunc = vec3(0); + + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv), nl, diffPunc, specPunc); + + final_color += intensity* clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)); } else { @@ -124,9 +134,9 @@ void main() lit = min(nl*6.0, 1.0) * dist_atten; float sa = nh; - float fres = pow(1 - vh, 5) * 0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + float fres = pow(1.0 - vh, 5.0) * 0.4+0.5; + float gtdenom = 2.0 * nh; + float gt = max(0.0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); if (nh > 0.0) { @@ -140,7 +150,9 @@ void main() discard; } } - - frag_color.rgb = max(final_color, vec3(0)); + float final_scale = 1.0; + if (classic_mode > 0) + final_scale = 0.9; + frag_color.rgb = max(final_color * final_scale, vec3(0)); frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 4bae7b6deb..2f577f8459 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -38,6 +38,8 @@ uniform float max_probe_lod; uniform bool transparent_surface; +uniform int classic_mode; + #define MAX_REFMAP_COUNT 256 // must match LL_MAX_REFLECTION_PROBE_COUNT layout (std140) uniform ReflectionProbes @@ -739,7 +741,10 @@ void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm, amblit); + ambenv = amblit; + + if (classic_mode == 0) + ambenv = sampleProbeAmbient(pos, norm, amblit); float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod); @@ -784,9 +789,6 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, probeIndex[probeInfluences++] = 0; doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, false, amblit); - - // fudge factor to get PBR water at a similar luminance ot legacy water - glossenv *= 0.4; } void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) @@ -845,7 +847,10 @@ void sampleReflectionProbesLegacy(out vec3 ambenv, out vec3 glossenv, out vec3 l vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm, amblit); + ambenv = amblit; + + if (classic_mode == 0) + ambenv = sampleProbeAmbient(pos, norm, amblit); if (glossiness > 0.0) { diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index 9ac389f926..5eda28bd8a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -66,7 +66,7 @@ void main() vec4 fcol = texture(diffuseMap, tc); - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + if (GET_GBUFFER_FLAG(norm.w, GBUFFER_FLAG_HAS_PBR)) { vec3 orm = specCol.rgb; float perceptualRoughness = orm.g; @@ -81,7 +81,7 @@ void main() vec4 collectedColor = vec4(0); - float w = tapScreenSpaceReflection(4, tc, pos, norm.xyz, collectedColor, diffuseMap, 0); + float w = tapScreenSpaceReflection(4, tc, pos, norm.xyz, collectedColor, diffuseMap, 0.f); collectedColor.rgb *= specCol.rgb; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 4231d8580e..6cec65ad83 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,14 +23,12 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #define FLT_MAX 3.402823466e+38 out vec4 frag_color; -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl - const float M_PI = 3.14159265; #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) @@ -54,6 +52,8 @@ uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; uniform int sun_up_factor; +uniform int classic_mode; + in vec2 vary_fragcoord; uniform mat4 inv_proj; @@ -103,13 +103,8 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 additive, vec3 atten); -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, - float metallic, - vec3 n, // normal - vec3 v, // surface point to camera - vec3 l); //surface point to light - +GBufferInfo getGBuffer(vec2 screenpos); +vec3 clampHDRRange(vec3 color); void adjustIrradiance(inout vec3 irradiance, float ambocc) { @@ -126,13 +121,15 @@ void main() vec2 tc = vary_fragcoord.xy; float depth = getDepth(tc.xy); vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = getNorm(tc); - vec3 colorEmissive = texture(emissiveRect, tc).rgb; - float envIntensity = colorEmissive.r; + + GBufferInfo gb = getGBuffer(tc); + + vec3 colorEmissive = gb.emissive.rgb; + float envIntensity = gb.envIntensity; vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - vec4 baseColor = texture(diffuseRect, tc); - vec4 spec = texture(specularRect, tc); // NOTE: PBR linear Emissive + vec4 baseColor = gb.albedo; + vec4 spec = gb.specular; // NOTE: PBR linear Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) vec2 scol_ambocc = texture(lightMap, vary_fragcoord.xy).rg; @@ -157,26 +154,29 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); + calcAtmosphericVarsLinear(pos.xyz, gb.normal, light_dir, sunlit, amblit, additive, atten); - vec3 sunlit_linear = srgb_to_linear(sunlit); + if (classic_mode > 0) + sunlit *= 1.35; + + vec3 sunlit_linear = sunlit; vec3 amblit_linear = amblit; - vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + if (GET_GBUFFER_FLAG(gb.gbufferFlag, GBUFFER_FLAG_HAS_PBR)) { vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; float ao = orm.r; + vec3 irradiance = amblit_linear; // PBR IBL float gloss = 1.0 - perceptualRoughness; - sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false, amblit_linear); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, gb.normal, gloss, false, amblit_linear); adjustIrradiance(irradiance, ambocc); @@ -185,17 +185,21 @@ void main() calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); - color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, gb.normal, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); } - else if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI)) + else if (GET_GBUFFER_FLAG(gb.gbufferFlag, GBUFFER_FLAG_HAS_HDRI)) { // actual HDRI sky, just copy color value color = colorEmissive.rgb; } - else if (GET_GBUFFER_FLAG(GBUFFER_FLAG_SKIP_ATMOS)) + else if (GET_GBUFFER_FLAG(gb.gbufferFlag, GBUFFER_FLAG_SKIP_ATMOS)) { //should only be true of WL sky, port over base color value and scale for fake HDR +#if defined(HAS_EMISSIVE) color = colorEmissive.rgb; +#else + color = baseColor.rgb; +#endif color = srgb_to_linear(color); color *= sky_hdr_scale; } @@ -206,31 +210,43 @@ void main() spec.rgb = srgb_to_linear(spec.rgb); - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); + float da = clamp(dot(gb.normal, light_dir.xyz), 0.0, 1.0); - vec3 irradiance = vec3(0); + vec3 irradiance = amblit; vec3 glossenv = vec3(0); vec3 legacyenv = vec3(0); - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity, false, amblit_linear); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, gb.normal, spec.a, envIntensity, false, amblit_linear); adjustIrradiance(irradiance, ambocc); // apply lambertian IBL only (see pbrIbl) color.rgb = irradiance; - vec3 sun_contrib = min(da, scol) * sunlit_linear; - color.rgb += sun_contrib; + if (classic_mode > 0) + { + da = pow(da,1.2); + vec3 sun_contrib = vec3(min(da, scol)); + + color.rgb = srgb_to_linear(color.rgb * 0.9 + (linear_to_srgb(sun_contrib) * sunlit_linear * 0.7)); + sunlit_linear = srgb_to_linear(sunlit_linear); + } + else + { + vec3 sun_contrib = min(da, scol) * sunlit_linear; + color.rgb += sun_contrib; + } + color.rgb *= baseColor.rgb; - vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + vec3 refnormpersp = reflect(pos.xyz, gb.normal); if (spec.a > 0.0) { vec3 lv = light_dir.xyz; vec3 h, l, v = -normalize(pos.xyz); float nh, nl, nv, vh, lightDist; - vec3 n = norm.xyz; + vec3 n = gb.normal; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); if (nl > 0.0 && nh > 0.0) @@ -247,7 +263,7 @@ void main() } // add radiance map - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + applyGlossEnv(color, glossenv, spec, pos.xyz, gb.normal); } @@ -255,10 +271,15 @@ void main() if (envIntensity > 0.0) { // add environment map - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + applyLegacyEnv(color, legacyenv, spec, pos.xyz, gb.normal, envIntensity); } } - frag_color.rgb = max(color.rgb, vec3(0)); //output linear since local lights will be added to this shader's results + //color.r = classic_mode > 0 ? 1.0 : 0.0; + float final_scale = 1; + if (classic_mode > 0) + final_scale = 1.1; + + frag_color.rgb = clampHDRRange(color.rgb * final_scale); //output linear since local lights will be added to this shader's results frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index bc4d36d10d..017f8bc844 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -27,9 +27,6 @@ out vec4 frag_color; -uniform sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; uniform sampler2D lightMap; uniform sampler2D lightFunc; @@ -50,6 +47,7 @@ uniform vec3 proj_origin; //origin of projection to be used for angular attenuat uniform float sun_wash; uniform int proj_shadow_idx; uniform float shadow_fade; +uniform int classic_mode; // Light params #if defined(MULTI_SPOTLIGHT) @@ -80,12 +78,17 @@ vec4 getPosition(vec2 pos_screen); const float M_PI = 3.14159265; -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, // surface point to light + out float nl, + out vec3 diff, + out vec3 spec); + +GBufferInfo getGBuffer(vec2 screenpos); void main() { @@ -118,8 +121,9 @@ void main() shadow = clamp(shadow, 0.0, 1.0); } - vec4 norm = getNorm(tc); - vec3 n = norm.xyz; + GBufferInfo gb = getGBuffer(tc); + + vec3 n = gb.normal; float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); if (dist_atten <= 0.0) @@ -132,14 +136,14 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - vec3 diffuse = texture(diffuseRect, tc).rgb; - vec4 spec = texture(specularRect, tc); + vec3 diffuse = gb.albedo.rgb; + vec4 spec = gb.specular; vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); vec3 amb_rgb = vec3(0); - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + if (GET_GBUFFER_FLAG(gb.gbufferFlag, GBUFFER_FLAG_HAS_PBR)) { vec3 orm = spec.rgb; float perceptualRoughness = orm.g; @@ -151,6 +155,8 @@ void main() diffuseColor *= 1.0 - metallic; vec3 specularColor = mix(f0, baseColor.rgb, metallic); + vec3 diffPunc = vec3(0); + vec3 specPunc = vec3(0); // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied if (proj_tc.x > 0.0 && proj_tc.x < 1.0 @@ -168,16 +174,21 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); vec3 intensity = dist_atten * dlit * 3.25 * shadow; // Legacy attenuation, magic number to balance with legacy materials - final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); + + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv), nl, diffPunc, specPunc); + + final_color += intensity * clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)); } amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ) * 3.25; //magic number to balance with legacy ambiance - final_color += amb_rgb * pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, -lv); + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv), nl, diffPunc, specPunc); + + final_color += amb_rgb * clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)); } } else { - float envIntensity = texture(emissiveRect, tc).r; + float envIntensity = gb.envIntensity; diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); @@ -188,7 +199,7 @@ void main() proj_tc.x > 0.0 && proj_tc.y > 0.0) { - float amb_da = 0; + float amb_da = 0.0; float lit = 0.0; if (nl > 0.0) @@ -211,10 +222,10 @@ void main() { dlit *= min(nl*6.0, 1.0) * dist_atten; - float fres = pow(1 - vh, 5)*0.4+0.5; + float fres = pow(1.0 - vh, 5.0)*0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); + float gtdenom = 2.0 * nh; + float gt = max(0.0, min(gtdenom * nv / vh, gtdenom * nl / vh)); if (nh > 0.0) { @@ -248,7 +259,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - final_color += color.rgb * texture2DLodSpecular(stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + final_color += color.rgb * texture2DLodSpecular(stc.xy, (1.0 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; } } } @@ -257,8 +268,10 @@ void main() //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); - + float final_scale = 1.0; + if (classic_mode > 0) + final_scale = 0.9; //output linear - frag_color.rgb = final_color; + frag_color.rgb = final_color * final_scale; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl index 2bf785e773..091c25d15e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/waterHazeF.glsl @@ -35,13 +35,25 @@ vec4 getWaterFogView(vec3 pos); uniform int above_water; +uniform sampler2D exclusionTex; + void main() { vec2 tc = vary_fragcoord.xy/vary_fragcoord.w*0.5+0.5; float depth = getDepth(tc.xy); + float mask = texture(exclusionTex, tc.xy).r; if (above_water > 0) { + // Just discard if we're in the exclusion mask. + // The previous invisiprim hack we're replacing would also crank up water fog desntiy. + // But doing that makes exclusion surfaces very slow as we'd need to render even more into the mask. + // - Geenz 2025-02-06 + if (mask < 1) + { + discard; + } + // we want to depth test when the camera is above water, but some GPUs have a hard time // with depth testing against render targets that are bound for sampling in the same shader // so we do it manually here @@ -51,11 +63,13 @@ void main() { discard; } + } vec4 pos = getPositionWithDepth(tc, depth); vec4 fogged = getWaterFogView(pos.xyz); + fogged.a = max(pow(fogged.a, 1.7), 0); frag_color = max(fogged, vec4(0)); //output linear since local lights will be added to this shader's results diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index 1c02dc764d..fa410e9f11 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -26,6 +26,7 @@ out vec4 frag_color; uniform sampler2D bumpMap; +uniform sampler2D exclusionTex; #ifdef TRANSPARENT_WATER uniform sampler2D screenTex; @@ -59,6 +60,9 @@ void mirrorClip(vec3 position); void main() { mirrorClip(vary_position); + vec2 screen_tc = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + float water_mask = texture(exclusionTex, screen_tc).r; + vec4 color; //get detail normals @@ -68,8 +72,8 @@ void main() vec3 wavef = normalize(wave1+wave2+wave3); //figure out distortion vector (ripply) - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - distort = distort+wavef.xy*refScale; + vec2 distort = screen_tc; + distort = mix(distort, distort+wavef.xy*refScale, water_mask); #ifdef TRANSPARENT_WATER vec4 fb = texture(screenTex, distort); diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 03da5b020f..b9de4edc67 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -25,6 +25,8 @@ // class3/environment/waterF.glsl +#define WATER_MINIMAL 1 + out vec4 frag_color; #ifdef HAS_SUN_SHADOW @@ -42,20 +44,25 @@ vec2 BRDF(float NoV, float roughness); void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); -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 perceptualRoughness); - -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, - float metallic, - vec3 n, // normal - vec3 v, // surface point to camera - vec3 l); //surface point to light + out vec3 diffuse, + out vec3 specular); + +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 + out float nl, + out vec3 diff, + out vec3 spec); vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, @@ -81,23 +88,17 @@ uniform sampler2D screenTex; uniform sampler2D depthMap; #endif -uniform sampler2D refTex; +uniform sampler2D exclusionTex; -uniform float sunAngle; -uniform float sunAngle2; +uniform int classic_mode; uniform vec3 lightDir; uniform vec3 specular; -uniform float lightExp; +uniform float blurMultiplier; uniform float refScale; uniform float kd; -uniform vec2 screenRes; uniform vec3 normScale; uniform float fresnelScale; uniform float fresnelOffset; -uniform float blurMultiplier; -uniform vec4 waterFogColor; -uniform vec3 waterFogColorLinear; - //bigWave is (refCoord.w, view.w); in vec4 refCoord; @@ -117,6 +118,10 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) vec3 srgb_to_linear(vec3 col); vec3 linear_to_srgb(vec3 col); +vec3 atmosLighting(vec3 light); +vec3 scaleSoftClip(vec3 light); +vec3 toneMapNoExposure(vec3 color); + vec3 vN, vT, vB; vec3 transform_normal(vec3 vNt) @@ -127,59 +132,109 @@ vec3 transform_normal(vec3 vNt) void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, vec3 amblit_linear); +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); + +/* +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit); +*/ + + vec3 getPositionWithNDC(vec3 ndc); +void generateWaveNormals(out vec3 wave1, out vec3 wave2, out vec3 wave3) +{ + // Generate all of our wave normals. + // We layer these back and forth. + + vec2 bigwave = vec2(refCoord.w, view.w); + + vec3 wave1_a = texture(bumpMap, bigwave).xyz * 2.0 - 1.0; + vec3 wave2_a = texture(bumpMap, littleWave.xy).xyz * 2.0 - 1.0; + vec3 wave3_a = texture(bumpMap, littleWave.zw).xyz * 2.0 - 1.0; + + vec3 wave1_b = texture(bumpMap2, bigwave).xyz * 2.0 - 1.0; + vec3 wave2_b = texture(bumpMap2, littleWave.xy).xyz * 2.0 - 1.0; + vec3 wave3_b = texture(bumpMap2, littleWave.zw).xyz * 2.0 - 1.0; + + wave1 = BlendNormal(wave1_a, wave1_b); + wave2 = BlendNormal(wave2_a, wave2_b); + wave3 = BlendNormal(wave3_a, wave3_b); +} + +void calculateFresnelFactors(out vec3 df3, out vec2 df2, vec3 viewVec, vec3 wave1, vec3 wave2, vec3 wave3, vec3 wavef) +{ + // We calculate the fresnel here. + // We do this by getting the dot product for each sets of waves, and applying scale and offset. + + df3 = max(vec3(0), vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset); + + df3 *= df3; + + df2 = max(vec2(0), vec2( + df3.x + df3.y + df3.z, + dot(viewVec, wavef) * fresnelScale + fresnelOffset + )); +} + void main() { mirrorClip(vary_position); + vN = vary_normal; vT = vary_tangent; vB = cross(vN, vT); vec3 pos = vary_position.xyz; + float linear_depth = 1.0 / -pos.z; float dist = length(pos.xyz); //normalize view vector vec3 viewVec = normalize(pos.xyz); - //get wave normals - vec2 bigwave = vec2(refCoord.w, view.w); - vec3 wave1_a = texture(bumpMap, bigwave, -2.0 ).xyz*2.0-1.0; - vec3 wave2_a = texture(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_a = texture(bumpMap, littleWave.zw).xyz*2.0-1.0; - - vec3 wave1_b = texture(bumpMap2, bigwave ).xyz*2.0-1.0; - vec3 wave2_b = texture(bumpMap2, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_b = texture(bumpMap2, littleWave.zw).xyz*2.0-1.0; + // Setup our waves. - //wave1_a = wave2_a = wave3_a = wave1_b = wave2_b = wave3_b = vec3(0,0,1); + vec3 wave1 = vec3(0, 0, 1); + vec3 wave2 = vec3(0, 0, 1); + vec3 wave3 = vec3(0, 0, 1); - vec3 wave1 = BlendNormal(wave1_a, wave1_b); - vec3 wave2 = BlendNormal(wave2_a, wave2_b); - vec3 wave3 = BlendNormal(wave3_a, wave3_b); + generateWaveNormals(wave1, wave2, wave3); + float dmod = sqrt(dist); vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - //wave1 = transform_normal(wave1); - //wave2 = transform_normal(wave2); - //wave3 = transform_normal(wave3); - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + vec3 df3 = vec3(0); + vec2 df2 = vec2(0); + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + + calculateFresnelFactors(df3, df2, normalize(view.xyz), wave1, wave2, wave3, wavef); + vec3 waver = wavef*3.0; vec3 up = transform_normal(vec3(0,0,1)); float vdu = -dot(viewVec, up)*2.0; - vec3 wave_ibl = wavef; + vec3 wave_ibl = wavef * normScale; wave_ibl.z *= 2.0; wave_ibl = transform_normal(normalize(wave_ibl)); vec3 norm = transform_normal(normalize(wavef)); vdu = clamp(vdu, 0.0, 1.0); - wavef.z *= max(vdu*vdu*vdu, 0.1); + //wavef.z *= max(vdu*vdu*vdu, 0.1); wavef = normalize(wavef); @@ -189,62 +244,71 @@ void main() float dist2 = dist; dist = max(dist, 5.0); - float dmod = sqrt(dist); - //figure out distortion vector (ripply) - vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0); + vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0) * 2.0; distort2 = clamp(distort2, vec2(0), vec2(0.999)); - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - float shadow = 1.0f; + float water_mask = texture(exclusionTex, distort).r; + #ifdef HAS_SUN_SHADOW shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, distort); #endif - calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = sunlit; + float fade = 1.0; +#ifdef TRANSPARENT_WATER + float depth = texture(depthMap, distort).r; - vec3 sunlit_linear = srgb_to_linear(sunlit); + vec3 refPos = getPositionWithNDC(vec3(distort*2.0-vec2(1.0), depth*2.0-1.0)); -#ifdef TRANSPARENT_WATER - vec4 fb = texture(screenTex, distort2); - float depth = texture(depthMap, distort2).r; - vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0)); + // Calculate some distance fade in the water to better assist with refraction blending and reducing the refraction texture's "disconnect". +#ifdef SHORELINE_FADE + fade = max(0.0,min(1.0, (pos.z - refPos.z) / 10.0)); +#else + fade = 1.0; +#endif + fade *= water_mask; + distort2 = mix(distort, distort2, min(1.0, fade * 10.0)); + depth = texture(depthMap, distort2).r; - if (refPos.z > pos.z-0.05) + refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); + + if (pos.z < refPos.z - 0.05) { - //we sampled an above water sample, don't distort distort2 = distort; - fb = texture(screenTex, distort2); - depth = texture(depthMap, distort2).r; - refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); } + vec4 fb = texture(screenTex, distort2); + #else vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0)); -#endif - // fudge sample on other side of water to be a tad darker - fb.rgb *= 0.75; + if (water_mask < 1.0) + discard; +#endif - float metallic = 0.0; - float perceptualRoughness = 0.05; + float metallic = 1.0; + float perceptualRoughness = blurMultiplier; float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss, amblit); + vec3 legacyenv = vec3(0); - irradiance = vec3(0); + // TODO: Make this an option. +#ifdef WATER_MINIMAL + sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss, amblit); +#elif WATER_MINIMAL_PLUS + sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss, false, amblit); +#endif vec3 diffuseColor = vec3(0); vec3 specularColor = vec3(0); - calcDiffuseSpecular(vec3(1), metallic, diffuseColor, specularColor); + vec3 specular_linear = srgb_to_linear(specular); + calcDiffuseSpecular(specular_linear, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); @@ -252,39 +316,36 @@ void main() float ao = 1.0; vec3 light_dir = transform_normal(lightDir); - perceptualRoughness = 0.0; - metallic = 1.0; - float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); - vec3 punctual = pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir)); - - vec3 color = punctual * sunlit_linear * 2.75 * shadow; - - vec3 ibl = pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0); + float nl = 0.0; + vec3 diffPunc = vec3(0); + vec3 specPunc = vec3(0); - color += ibl; + pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir), nl, diffPunc, specPunc); - float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - vec2 brdf = BRDF(clamp(nv, 0.0, 1.0), 1.0); - float f = 1.0-brdf.y; //1.0 - (brdf.x+brdf.y); - f *= 0.9; - f *= f; + vec3 punctual = clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)) * sunlit_linear * shadow * atten; + radiance *= df2.y; + //radiance = toneMapNoExposure(radiance); + vec3 color = vec3(0); + color = mix(fb.rgb, radiance, min(1.0, df2.x)) + punctual.rgb; - // incoming scale is [0, 1] with 0.5 being default - // shift to 0.5 to 1.5 - f *= (fresnelScale - 0.5)+1.0; + float water_haze_scale = 4.0; - // incoming offset is [0, 1] with 0.5 being default - // shift from -1 to 1 - f += (fresnelOffset - 0.5) * 2.0; + if (classic_mode > 0) + water_haze_scale = 1.0; - f = clamp(f, 0.0, 1.0); + // This looks super janky, but we do this to restore water haze in the distance. + // These values were finagled in to try and bring back some of the distant brightening on legacy water. Also works reasonably well on PBR skies such as PBR midday. + // color = mix(color, additive * water_haze_scale, (1 - atten)); - color = ((1.0 - f) * color) + fb.rgb; + // We shorten the fade here at the shoreline so it doesn't appear too soft from a distance. + fade *= 60.0; + fade = min(1.0, fade); + color = mix(fb.rgb, color, fade); - float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); + float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.0); - frag_color = max(vec4(color, spec), vec4(0)); + frag_color = min(vec4(1),max(vec4(color.rgb, spec * water_mask), vec4(0))); } |