redid underwater visuals. more gameplay friendly and looks better.

This commit is contained in:
Xonk 2023-07-23 00:07:10 -04:00
parent 15c7613892
commit 74fc47d4e2
5 changed files with 177 additions and 96 deletions

View File

@ -254,20 +254,23 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
float maxZ = min(rayLength,12.0)/(1e-8+rayLength); float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ; dV *= maxZ;
rayLength *= maxZ; rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ; estEndDepth *= maxZ;
estSunDepth *= maxZ; estSunDepth *= maxZ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float phase = phaseg(VdotL,0.7) * 1.5 + 0.1;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
// float phase = (phaseg(VdotL,0.5) + phaseg(VdotL,0.8)) ;
float phase = (phaseg(VdotL,0.6) + phaseg(VdotL,0.8)) * 0.5;
// float phase = phaseg(VdotL, 0.7);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0; float expFactor = 11.0;
for (int i=0;i<spCount;i++) { for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
@ -289,12 +292,13 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
sh *= GetCloudShadow_VLFOG(progressW,WsunVec); sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
#endif #endif
vec3 sunMul = exp(-max(estSunDepth * d,0.0) * waterCoefs) * 5.0;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs ) * 1.5; vec3 Directlight = (lightSource * phase * sunMul) * sh;
vec3 sunMul = exp(-max(estSunDepth * d,0.0) * waterCoefs); vec3 Indirectlight = ambientMul*ambient;
vec3 light = (sh * lightSource * phase * sunMul + (ambientMul*ambient) )*scatterCoef; vec3 light = (Directlight + Indirectlight) * scatterCoef;
// vec3 light = sh * vec3(1);
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance; vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs); absorbance *= exp(-dd * rayLength * waterCoefs);
@ -847,7 +851,8 @@ void main() {
vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.)); vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.));
vec3 DirectLightColor = lightCol.rgb/80.0; vec3 DirectLightColor = lightCol.rgb/80.0;
// DirectLightColor *= clamp(abs(WsunVec.y)*2,0.,1.); vec3 Direct_SSS = vec3(0.0);
#ifdef ambientLight_only #ifdef ambientLight_only
DirectLightColor = vec3(0.0); DirectLightColor = vec3(0.0);
#endif #endif
@ -859,6 +864,7 @@ void main() {
#endif #endif
vec3 AmbientLightColor = averageSkyCol_Clouds; vec3 AmbientLightColor = averageSkyCol_Clouds;
vec3 Indirect_SSS = vec3(0.0);
@ -882,7 +888,7 @@ void main() {
vec3 background = vec3(0.0); vec3 background = vec3(0.0);
vec3 orbitstar = vec3(np3.x,abs(np3.y),np3.z); vec3 orbitstar = vec3(np3.x,abs(np3.y),np3.z);
orbitstar.x -= WsunVec.x*0.2; orbitstar.x -= WsunVec.x*0.2;
background += stars(orbitstar) * 5.0 ; background += stars(orbitstar) * 10.0 ;
#ifndef ambientLight_only #ifndef ambientLight_only
background += Moon(np3, -WsunVec, DirectLightColor*20, background); // moon background += Moon(np3, -WsunVec, DirectLightColor*20, background); // moon
@ -968,7 +974,6 @@ void main() {
//////////////////////////////// SUN SSS //////////////////////////////// //////////////////////////////// SUN SSS ////////////////////////////////
vec3 SSS = vec3(0.0);
#if SSS_TYPE != 0 #if SSS_TYPE != 0
#ifndef Variable_Penumbra_Shadows #ifndef Variable_Penumbra_Shadows
@ -986,10 +991,9 @@ void main() {
#endif #endif
SSS = SubsurfaceScattering_sun(albedo, SHADOWBLOCKERDEPTBH, sunSSS_density, clamp(dot(np3, WsunVec),0.0,1.0)) ; Direct_SSS = SubsurfaceScattering_sun(albedo, SHADOWBLOCKERDEPTBH, sunSSS_density, clamp(dot(np3, WsunVec),0.0,1.0)) ;
SSS *= DirectLightColor;
if (isEyeInWater == 0) SSS *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix if (isEyeInWater == 0) Direct_SSS *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
#endif #endif
if (!hand){ if (!hand){
@ -1000,23 +1004,23 @@ void main() {
Shadows = min(screenShadow, Shadows); Shadows = min(screenShadow, Shadows);
if (outsideShadowMap) SSS *= Shadows; if (outsideShadowMap) Direct_SSS *= Shadows;
#else #else
if (outsideShadowMap) SSS = vec3(0.0); if (outsideShadowMap) Direct_SSS = vec3(0.0);
#endif #endif
} }
#if SSS_TYPE != 0 #if SSS_TYPE != 0
SSS *= 1.0-clamp(NdotL*Shadows,0,1); Direct_SSS *= 1.0-clamp(NdotL*Shadows,0,1);
#endif #endif
#ifdef VOLUMETRIC_CLOUDS #ifdef VOLUMETRIC_CLOUDS
#ifdef CLOUDS_SHADOWS #ifdef CLOUDS_SHADOWS
cloudShadow = GetCloudShadow(p3); cloudShadow = GetCloudShadow(p3);
Shadows *= cloudShadow; Shadows *= cloudShadow;
SSS *= cloudShadow; Direct_SSS *= cloudShadow;
#endif #endif
#endif #endif
@ -1040,7 +1044,7 @@ void main() {
// do this to make underwater shading easier. // do this to make underwater shading easier.
vec2 newLightmap = lightmap.xy; vec2 newLightmap = lightmap.xy;
if((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)) newLightmap.y = clamp(newLightmap.y,0,1); // if(isEyeInWater == 1 && !iswater) newLightmap.y = max(newLightmap.y, 0.5);
#ifndef ambientSSS_view #ifndef ambientSSS_view
Indirect_lighting = DoAmbientLighting(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), newLightmap.xy, skylight); Indirect_lighting = DoAmbientLighting(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), newLightmap.xy, skylight);
@ -1105,7 +1109,7 @@ void main() {
SSS_forSky *= uplimit; SSS_forSky *= uplimit;
// Combine with the other SSS // Combine with the other SSS
SSS += SSS_forSky; Indirect_SSS += SSS_forSky;
SSS_forSky = vec3((1.0 - SkySSS) * LabSSS); SSS_forSky = vec3((1.0 - SkySSS) * LabSSS);
SSS_forSky *= ambientColor; SSS_forSky *= ambientColor;
@ -1139,22 +1143,18 @@ void main() {
vec3 Absorbtion = exp2(-totEpsilon*estimatedDepth); vec3 Absorbtion = exp2(-totEpsilon*estimatedDepth);
// caustics... // caustics...
float Direct_caustics = waterCaustics(mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition, WsunVec); float Direct_caustics = waterCaustics(p3 + cameraPosition, WsunVec) * cloudShadow;
float Ambient_Caustics = waterCaustics(mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition, vec3(0.5, 1.0, 0.5)); // float Ambient_Caustics = waterCaustics(p3 + cameraPosition, vec3(0.5, 1, 0.5));
// apply caustics to the lightting // apply caustics to the lighting
DirectLightColor *= 0.5 + max(pow(Direct_caustics*2,2),0.0); DirectLightColor *= 1.0 + max(pow(Direct_caustics * 3.0, 2.0),0.0);
// Indirect_lighting *= 0.5 + max(pow(Ambient_Caustics,2),0.0); // Indirect_lighting *= 0.5 + max(pow(Ambient_Caustics, 2.0),0.0);
// directLightCol *= Direct_caustics;
// Indirect_lighting *= Ambient_Caustics*0.5+0.5;
// apply water absorbtion to the lighting
// waterabsorb_speculars.rgb *= Absorbtion;
DirectLightColor *= Absorbtion; DirectLightColor *= Absorbtion;
// Indirect_lighting *= Absorbtion; Indirect_lighting = (Indirect_lighting/exp2(-estimatedDepth*0.5)) * Absorbtion;
if(isEyeInWater == 0) DirectLightColor *= (max(eyeBrightnessSmooth.y,0)/240.);
if(isEyeInWater == 0) DirectLightColor *= max(eyeBrightnessSmooth.y/240., 0.0);
DirectLightColor *= cloudShadow;
} }
@ -1187,10 +1187,10 @@ void main() {
#endif #endif
#endif #endif
Direct_lighting = DoDirectLighting(DirectLightColor, Shadows, NdotL, 0.0); Direct_lighting = DoDirectLighting(DirectLightColor, Shadows, NdotL, 0.0);
Direct_SSS *= DirectLightColor; // do this here so it gets underwater absorbtion.
vec3 FINAL_COLOR = Indirect_lighting + Direct_lighting + SSS; vec3 FINAL_COLOR = Indirect_lighting + Indirect_SSS + Direct_lighting + Direct_SSS ;
#ifndef ambientSSS_view #ifndef ambientSSS_view
FINAL_COLOR *= albedo; FINAL_COLOR *= albedo;
@ -1212,7 +1212,7 @@ void main() {
//////////////////////////////// UNDERWATER FOG //////////////////////////////// //////////////////////////////// UNDERWATER FOG ////////////////////////////////
//////////////////////////////// //////////////////////////////// //////////////////////////////// ////////////////////////////////
if (iswater){ if (iswater){
vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
float Vdiff = distance(fragpos,fragpos0); float Vdiff = distance(fragpos,fragpos0);
float VdotU = np3.y; float VdotU = np3.y;
@ -1221,12 +1221,11 @@ void main() {
float custom_lightmap_T = clamp(pow(texture2D(colortex14, texcoord).a,3.0),0.0,1.0); float custom_lightmap_T = clamp(pow(texture2D(colortex14, texcoord).a,3.0),0.0,1.0);
vec3 lightColVol = lightCol.rgb / 80.;
// if(shadowmapindicator < 1) lightColVol *= clamp((custom_lightmap_T-0.8) * 15,0,1)
vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.); vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 ambientColVol = max((averageSkyCol_Clouds / 30.) * custom_lightmap_T, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)) + lightningColor; vec3 ambientColVol = max((averageSkyCol_Clouds / 30.0) * custom_lightmap_T, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)) + lightningColor;
vec3 lightColVol = DirectLightColor;
if(shadowmapindicator < 1) lightColVol *= clamp((custom_lightmap_T-0.8) * 15,0,1);
if (isEyeInWater == 0) waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(np3, WsunVec)); if (isEyeInWater == 0) waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(np3, WsunVec));
} }

View File

@ -120,76 +120,147 @@ float waterCaustics(vec3 wPos, vec3 lightSource) { // water waves
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = 8; int spCount = 8;
vec3 start = toShadowSpaceProjected(rayStart); vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd); vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start); vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error //limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway //you can't see above this anyway
float maxZ = min(rayLength,48.0)/(1e-8+rayLength); float maxZ = min(rayLength,32.0)/(1e-8+rayLength);
dV *= maxZ; dV *= maxZ;
vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
rayLength *= maxZ; rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
// dVWorld *= maxZ vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 progressW = (gbufferModelViewInverse[3].xyz+cameraPosition);
vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a;
// vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; float phase = (phaseg(VdotL,0.6) + phaseg(VdotL,0.8)) * 0.5;
// vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0); vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0); vec3 vL = vec3(0.0);
float phase = phaseg(VdotL,0.5) * 1.5 + 0.1;
lightSource *= clamp(abs(WsunVec.y)*5,0.,1.);
float cloudShadow = 1;
float expFactor = 11.0; float expFactor = 11.0;
for (int i=0;i<spCount;i++) { for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1) float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative) float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
vec3 spPos = start.xyz + dV*d; vec3 spPos = start.xyz + dV*d;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld; progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
// vec3 progressW = start.xyz+cameraPosition+dVWorld;
//project into biased shadowmap space //project into biased shadowmap space
float distortFactor = calcDistort(spPos.xy); float distortFactor = calcDistort(spPos.xy);
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z); vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0; float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){ if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5; pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x; sh = shadow2D( shadow, pos).x;
} }
// #ifdef VL_CLOUDS_SHADOWS #ifdef CLOUDS_SHADOWS
// sh *= GetCloudShadow_VLFOG(progressW); sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
// #endif #endif
vec3 p3 = mat3(gbufferModelViewInverse) * rayEnd; vec3 sunMul = exp(-max((estSunDepth - dY * d) ,0.0)/abs(refractedSunVec.y) * waterCoefs);
vec3 np3 = normVec(p3); vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs) * 2.0 ;
float ambfogfade = clamp(exp(np3.y*1.5 - 1.5),0.0,1.0) ;
vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs) + ambfogfade*0.5 * clamp(eyeBrightnessSmooth.y/240.0,0.1,1.0);
vec3 sunMul = exp(-max((estEyeDepth - dY * d) ,0.0)/abs(refractedSunVec.y) * waterCoefs)*cloudShadow;
float sunCaustics = waterCaustics(progressW, WsunVec);
sunCaustics = max(pow(sunCaustics*3,2),0.5);
vec3 light = (sh * lightSource * phase * sunMul * sunCaustics + (ambient*ambientMul))*scatterCoef; float np3_Y = normVec(mat3(gbufferModelViewInverse) * rayEnd).y;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance; float ambfogfade = clamp(exp(np3_Y*1.5 - 1.5),0.0,1.0) ;
float sunCaustics = clamp(pow(waterCaustics(progressW, WsunVec)+1,5) * 2.0, phase*0.8+0.2, 1.0);
// make it such that the volume is brighter farther away from the camera.
float bubbleOfClearness = max(pow(length(d*dVWorld)/16,5)*100.0,0.0) + 1;
float bubbleOfClearness2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
vec3 Directlight = (lightSource * sunCaustics * phase * (sunMul+0.5)) * sh * pow(abs(WsunVec.y),2) * bubbleOfClearness;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.6,0.6,1.0) * exp(-waterCoefs) * bubbleOfClearness2) * ambfogfade ;
vec3 light = (Directlight + Indirectlight) * scatterCoef ;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs); absorbance *= exp(-dd * rayLength * waterCoefs);
} }
inColor += vL; inColor += vL;
} }
// void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
// int spCount = 16;
// vec3 start = toShadowSpaceProjected(rayStart);
// vec3 end = toShadowSpaceProjected(rayEnd);
// vec3 dV = (end-start);
// //limit ray length at 32 blocks for performance and reducing integration error
// //you can't see above this anyway
// float maxZ = min(rayLength,32.0)/(1e-8+rayLength);
// dV *= maxZ;
// vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
// rayLength *= maxZ;
// float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
// vec3 progressW = (gbufferModelViewInverse[3].xyz+cameraPosition);
// vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a;
// // float phase = phaseg(VdotL,0.5) * 1.5 + 0.1;
// float phase = (phaseg(VdotL,0.5) + phaseg(VdotL,0.8)) ;
// // lightSource *= clamp(abs(WsunVec.y)*5,0.,1.);
// vec3 absorbance = vec3(1.0);
// vec3 vL = vec3(0.0);
// float expFactor = 11.0;
// for (int i=0;i<spCount;i++) {
// float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
// float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
// vec3 spPos = start.xyz + dV*d;
// progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
// // vec3 progressW = start.xyz+cameraPosition+dVWorld;
// //project into biased shadowmap space
// float distortFactor = calcDistort(spPos.xy);
// vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
// float sh = 1.0;
// if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
// pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
// sh = shadow2D( shadow, pos).x;
// }
// // #ifdef VL_CLOUDS_SHADOWS
// // sh *= GetCloudShadow_VLFOG(progressW);
// // #endif
// vec3 p3 = mat3(gbufferModelViewInverse) * rayEnd;
// vec3 np3 = normVec(p3);
// float ambfogfade = clamp(exp(np3.y*1.5 - 1.5),0.0,1.0) ;
// // vec3 sunMul = exp(-max((estEyeDepth - dY * d) ,0.0)/abs(refractedSunVec.y) * waterCoefs);
// vec3 sunMul = exp(-max(estSunDepth * d,0.0) * waterCoefs) / 5.0;
// vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs) / 2.0;
// ambientMul = max(ambientMul, ambfogfade * 0.01);
// float sunCaustics = waterCaustics(progressW, WsunVec);
// // sunCaustics = clamp(sunCaustics+1.0,0.0,1.0);
// sunCaustics = max(pow(sunCaustics*3,2),0.5);
// vec3 Directlight = (lightSource * phase * sunMul * sunCaustics) * sh;
// vec3 Indirectlight = ambientMul*ambient;
// vec3 light = ( Indirectlight) * scatterCoef;
// vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance;
// absorbance *= exp(-dd * rayLength * waterCoefs);
// }
// inColor += vL;
// }
vec4 RainRays(vec3 rayStart, vec3 rayEnd, float rayLength, float dither, vec3 ambient, vec3 lightSource, float VdotL){ vec4 RainRays(vec3 rayStart, vec3 rayEnd, float rayLength, float dither, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = 8; int spCount = 8;
@ -318,17 +389,20 @@ void main() {
vec3 fragpos = toScreenSpace(vec3(tc/RENDER_SCALE,z)); vec3 fragpos = toScreenSpace(vec3(tc/RENDER_SCALE,z));
float noise = blueNoise(); float noise = blueNoise();
vec3 vl = vec3(0.0);
float estEyeDepth = clamp((14.0-eyeBrightnessSmooth.y/255.0*16.0)/14.0,0.,1.0); float estEyeDepth = 1.0-clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
estEyeDepth *= estEyeDepth*estEyeDepth*34.0; estEyeDepth = pow(estEyeDepth,3.0) * 32.0;
vec3 lightColVol = lightCol.rgb / 80.;
vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.); vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 ambientColVol = (averageSkyCol_Clouds/30.0) + lightningColor; vec3 ambientColVol = (averageSkyCol_Clouds/30.0);
vec3 lightColVol = (lightCol.rgb / 80.);
estEyeDepth = max(Water_Top_Layer - cameraPosition.y,0.0);
// estEyeDepth = max(Water_Top_Layer - cameraPosition.y,0.0);
vec3 vl = vec3(0.0);
waterVolumetrics(vl, vec3(0.0), fragpos, estEyeDepth, estEyeDepth, length(fragpos), noise, totEpsilon, scatterCoef, ambientColVol, lightColVol*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)) , dot(normalize(fragpos), normalize(sunVec) )); waterVolumetrics(vl, vec3(0.0), fragpos, estEyeDepth, estEyeDepth, length(fragpos), noise, totEpsilon, scatterCoef, ambientColVol, lightColVol*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)) , dot(normalize(fragpos), normalize(sunVec) ));
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.); gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
} }
} }

View File

@ -252,7 +252,7 @@ void main() {
#endif #endif
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0)); vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0));
float bloomyFogMult = 1.0;
if (TranslucentShader.a > 0.0){ if (TranslucentShader.a > 0.0){
#ifdef Glass_Tint #ifdef Glass_Tint
@ -296,11 +296,21 @@ void main() {
// underwater fog // underwater fog
if (isEyeInWater == 1){ if (isEyeInWater == 1){
float fogfade = clamp( exp(length(fragpos) / -10) ,0.0,1.0); float dirtAmount = Dirt_Amount;
color.rgb = color.rgb * fogfade ; vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vl.a *= fogfade ; vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
// float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0);
// vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0);
vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0);
fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0);
color.rgb *= fogfade ;
bloomyFogMult *= 0.4;
} }
// apply VL fog to the scene
color *= vl.a; color *= vl.a;
color += vl.rgb; color += vl.rgb;
@ -316,7 +326,7 @@ void main() {
/// powdered snow /// powdered snow
if (isEyeInWater == 3){ if (isEyeInWater == 3){
color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.));
vl.a = 0.0; bloomyFogMult = 0.0;
} }
// blidnesss // blidnesss
@ -331,7 +341,7 @@ void main() {
if(luma(thingy) > 0.0 ) color.rgb = thingy; if(luma(thingy) > 0.0 ) color.rgb = thingy;
#endif #endif
gl_FragData[0].r = vl.a; // pass fog alpha so bloom can do bloomy fog gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0);

View File

@ -324,7 +324,7 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
#ifdef PhysicsMod_support #ifdef PhysicsMod_support
if(physics_iterationsNormal < 1.0){ if(physics_iterationsNormal < 1.0){
#endif #endif
float bumpmult = 1.; float bumpmult = 1.0;
vec3 bump = vec3(0); vec3 bump = vec3(0);
vec3 posxz = p3+cameraPosition; vec3 posxz = p3+cameraPosition;
@ -457,15 +457,12 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
vec3 reflectedVector = reflect(normalize(fragpos), normal); vec3 reflectedVector = reflect(normalize(fragpos), normal);
float normalDotEye = dot(normal, normalize(fragpos)); float normalDotEye = dot(normal, normalize(fragpos));
float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 5.0); float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 5.0);
// float unchangedfresnel = fresnel;
// snells window looking thing // snells window looking thing
if(isEyeInWater == 1 && iswater > 0.99) fresnel = clamp(pow(1.66 + normalDotEye,25),0.02,1.0);
#ifdef PhysicsMod_support #ifdef PhysicsMod_support
if(isEyeInWater == 1 && physics_iterationsNormal > 0.0) fresnel = clamp( 1.0 - (pow( normalDotEye * 1.66 ,25)),0.02,1.0); if(isEyeInWater == 1 && physics_iterationsNormal > 0.0) fresnel = clamp( 1.0 - (pow( normalDotEye * 1.66 ,25)),0.02,1.0);
#else #else
if(isEyeInWater == 1) fresnel = clamp( 1.0 - (pow( normalDotEye * 1.66 ,25)),0.02,1.0); if(isEyeInWater == 1 ) fresnel = pow(clamp(1.66 + normalDotEye,0.0,1.0), 25.0);
#endif #endif
fresnel = mix(f0, 1.0, fresnel); fresnel = mix(f0, 1.0, fresnel);
@ -475,8 +472,9 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
// SSR, Sky, and Sun reflections // SSR, Sky, and Sun reflections
#ifdef WATER_BACKGROUND_SPECULAR #ifdef WATER_BACKGROUND_SPECULAR
SkyReflection = skyCloudsFromTex(wrefl,colortex4).rgb / 30.0; SkyReflection = skyCloudsFromTex(wrefl,colortex4).rgb / 30.0;
// SkyReflection = vec3(CaveFogColor_R,CaveFogColor_G,CaveFogColor_B)/ if(isEyeInWater == 1) SkyReflection = vec3(0.0);
#endif #endif
#ifdef WATER_SUN_SPECULAR #ifdef WATER_SUN_SPECULAR
SunReflection = Direct_lighting * GGX(normal, -normalize(fragpos), lightSign*sunVec, roughness, vec3(f0)); SunReflection = Direct_lighting * GGX(normal, -normalize(fragpos), lightSign*sunVec, roughness, vec3(f0));
#endif #endif

View File

@ -464,7 +464,7 @@ void main() {
#ifdef Specular_Reflections #ifdef Specular_Reflections
MaterialReflections_N(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand); MaterialReflections_N(gl_FragData[0].rgb, SpecularTex.r, vec3(SpecularTex.g), albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand);
#endif #endif
Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); Emission(gl_FragData[0].rgb, albedo, SpecularTex.a);