#3456 Water improvements to get us closer to 6.6.17 (#3490)

* A lot of tweaking for water.

* Get water much closer to 6.6.17.

This won't produce 1:1 results, but it should be much closer to where we once were.
master
Jonathan "Geenz" Goodman 2025-01-30 01:59:45 -05:00 committed by GitHub
parent fd577e3bfc
commit 460e77c47e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 92 additions and 59 deletions

View File

@ -41,6 +41,26 @@ vec3 srgb_to_linear(vec3 cs)
}
vec4 srgb_to_linear4(vec4 cs)
{
vec4 low_range = cs / vec4(12.92);
vec4 high_range = pow((cs+vec4(0.055))/vec4(1.055), vec4(2.4));
bvec4 lte = lessThanEqual(cs,vec4(0.04045));
#ifdef OLD_SELECT
vec4 result;
result.r = lte.r ? low_range.r : high_range.r;
result.g = lte.g ? low_range.g : high_range.g;
result.b = lte.b ? low_range.b : high_range.b;
result.a = lte.a ? low_range.a : high_range.a;
return result;
#else
return mix(high_range, low_range, lte);
#endif
}
vec3 linear_to_srgb(vec3 cl)
{
cl = clamp(cl, vec3(0), vec3(1));

View File

@ -66,11 +66,11 @@ vec4 getWaterFogViewNoClip(vec3 pos)
float t2 = kd + ks * es;
float t3 = pow(F, t2*l) - 1.0;
float L = min(t1/t2*t3, 1.0);
float L = pow(min(t1/t2*t3, 1.0), 1.0/1.7);
float D = pow(0.98, l*kd);
return vec4(srgb_to_linear(kc.rgb*L), D);
return vec4(srgb_to_linear(kc.rgb)*L, D);
}
vec4 getWaterFogView(vec3 pos)

View File

@ -56,7 +56,7 @@ void main()
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
}

View File

@ -132,8 +132,54 @@ 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, -2).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 = vec3(
dot(viewVec, wave1),
dot(viewVec, (wave2 + wave3) * 0.5),
dot(viewVec, wave3)
) * fresnelScale + fresnelOffset;
df3 *= df3;
df2 = vec2(
df3.x + df3.y + df3.z,
dot(viewVec, wavef) * fresnelScale + fresnelOffset
);
}
void main()
{
mirrorClip(vary_position);
@ -148,30 +194,23 @@ void main()
//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 ).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;
// Setup our waves.
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;
vec3 wave1 = vec3(0, 0, 1);
vec3 wave2 = vec3(0, 0, 1);
vec3 wave3 = vec3(0, 0, 1);
//wave1_a = wave2_a = wave3_a = wave1_b = wave2_b = wave3_b = 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);
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);
calculateFresnelFactors(df3, df2, normalize(view.xyz), wave1, wave2, wave3, wavef);
vec3 waver = wavef*3;
vec3 up = transform_normal(vec3(0,0,1));
@ -197,7 +236,7 @@ void main()
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;
distort2 = clamp(distort2, vec2(0), vec2(0.999));
@ -217,8 +256,8 @@ void main()
vec3 sunlit_linear = srgb_to_linear(sunlit);
#ifdef TRANSPARENT_WATER
vec4 fb = texture(screenTex, distort2);
float depth = texture(depthMap, distort2).r;
vec4 fb = texture(screenTex, distort2);
vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0));
if (refPos.z > pos.z-0.05)
@ -234,18 +273,16 @@ void main()
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;
float metallic = 0.0;
float perceptualRoughness = 0.05;
float gloss = 1.0 - perceptualRoughness;
float metallic = 1.0;
float perceptualRoughness = 0.1;
float gloss = 0.95;
vec3 irradiance = vec3(0);
vec3 radiance = vec3(0);
vec3 legacyenv = vec3(0);
sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss, amblit);
irradiance = vec3(0);
//sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, 1, true, amblit);
//sampleReflectionProbesLegacy(irradiance, radiance, legacyenv, distort2, pos.xyz, wave_ibl.xyz, gloss, 1, false, amblit);
vec3 diffuseColor = vec3(0);
vec3 specularColor = vec3(0);
@ -257,46 +294,22 @@ 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);
float nl = 0;
vec3 diffPunc = vec3(0);
vec3 specPunc = vec3(0);
pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir), nl, diffPunc, specPunc);
pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir), nl, diffPunc, specPunc);
vec3 punctual = clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10));
vec3 punctual = clamp(nl * (diffPunc + specPunc), vec3(0), vec3(10)) * sunlit_linear * 2.75 * shadow;
vec3 color = punctual * sunlit_linear * 2.75 * shadow;
vec3 iblDiff;
vec3 iblSpec;
pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0, iblDiff, iblSpec);
vec3 color = vec3(0);
color += iblDiff + iblSpec;
float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0);
vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0);
float f = 1.0-brdf.y; //1.0 - (brdf.x+brdf.y);
f *= 0.9;
f *= f;
// incoming scale is [0, 1] with 0.5 being default
// shift to 0.5 to 1.5
f *= (fresnelScale - 0.5)+1.0;
// incoming offset is [0, 1] with 0.5 being default
// shift from -1 to 1
f += (fresnelOffset - 0.5) * 2.0;
f = clamp(f, 0, 1);
color = ((1.0 - f) * color) + fb.rgb;
color = mix(fb.rgb, radiance * df2.x, df2.x * 0.99999) + punctual.rgb;
float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05);
frag_color = max(vec4(color, spec), vec4(0));
frag_color = max(vec4(color.rgb, spec), vec4(0));
}