first commit

This commit is contained in:
Rbanh committed 2024-06-22 15:15:55 -04:00
commit 0f859671ea
308 files changed
+18617

No files matched your search

+385
View File
@@ -0,0 +1,385 @@
#ifdef OVERWORLD
float CloudSampleBase(vec2 coord, vec2 wind, float cloudGradient, float sunCoverage, float dither, float multiplier) {
coord.xy *= 0.004;
#if CLOUD_BASE == 0
float noiseBase = texture2D(noisetex, coord * 0.25 + wind).r;
#else
float noiseBase = texture2D(noisetex, coord * 0.5 + wind).g;
noiseBase = pow(1.0 - noiseBase, 2.0) * 0.5 + 0.25;
#endif
float detailZ = floor(cloudGradient * float(CLOUD_THICKNESS)) * 0.04;
float noiseDetailLow = texture2D(noisetex, coord.xy * 0.5 - wind * 2.0 + detailZ).b;
float noiseDetailHigh = texture2D(noisetex, coord.xy * 0.5 - wind * 2.0 + detailZ + 0.04).b;
float noiseDetail = mix(noiseDetailLow, noiseDetailHigh, fract(cloudGradient * float(CLOUD_THICKNESS)));
float noiseCoverage = abs(cloudGradient - 0.125);
noiseCoverage *= cloudGradient > 0.125 ? (2.14 - CLOUD_AMOUNT * 0.1) : 8.0;
noiseCoverage = noiseCoverage * noiseCoverage * 4.0;
float noise = mix(noiseBase, noiseDetail, 0.0476 * CLOUD_DETAIL) * 21.0 - noiseCoverage;
noise = mix(noise, 21.0 - noiseCoverage * 2.5, 0.33 * rainStrength);
noise = max(noise - (sunCoverage * 3.0 + CLOUD_AMOUNT), 0.0);
noise *= CLOUD_DENSITY * multiplier;
noise *= (1.0 - 0.75 * rainStrength);
noise = noise / sqrt(noise * noise + 0.5);
return noise;
}
float CloudSampleSkybox(vec2 coord, vec2 wind, float cloudGradient, float sunCoverage, float dither) {
return CloudSampleBase(coord, wind, cloudGradient, sunCoverage, dither, 0.125);
}
float CloudSampleVolumetric(vec2 coord, vec2 wind, float cloudGradient, float sunCoverage, float dither) {
coord.xy /= CLOUD_VOLUMETRIC_SCALE;
return CloudSampleBase(coord, wind, cloudGradient, sunCoverage, dither, 0.125);
}
float InvLerp(float v, float l, float h) {
return clamp((v - l) / (h - l), 0.0, 1.0);
}
vec4 DrawCloudSkybox(vec3 viewPos, float z, float dither, vec3 lightCol, vec3 ambientCol, bool fadeFaster) {
if (z < 1.0) return vec4(0.0);
#ifdef TAA
#if TAA_MODE == 0
dither = fract(dither + frameCounter * 0.618);
#else
dither = fract(dither + frameCounter * 0.5);
#endif
#endif
int samples = CLOUD_THICKNESS * 2;
float cloud = 0.0, cloudLighting = 0.0;
float sampleStep = 1.0 / samples;
float currentStep = dither * sampleStep;
vec3 nViewPos = normalize(viewPos);
float VoU = dot(nViewPos, upVec);
float VoL = dot(nViewPos, lightVec);
float sunCoverage = mix(abs(VoL), max(VoL, 0.0), shadowFade);
sunCoverage = pow(clamp(sunCoverage * 2.0 - 1.0, 0.0, 1.0), 12.0) * (1.0 - rainStrength);
vec2 wind = vec2(
frametime * CLOUD_SPEED * 0.0005,
sin(frametime * CLOUD_SPEED * 0.001) * 0.005
) * CLOUD_HEIGHT / 15.0;
vec3 cloudColor = vec3(0.0);
if (VoU > 0.025) {
vec3 wpos = normalize((gbufferModelViewInverse * vec4(viewPos, 1.0)).xyz);
float halfVoL = mix(abs(VoL) * 0.8, VoL, shadowFade) * 0.5 + 0.5;
float halfVoLSqr = halfVoL * halfVoL;
float scattering = pow(halfVoL, 6.0);
float noiseLightFactor = (2.0 - 1.5 * VoL * shadowFade) * CLOUD_DENSITY * 0.5;
for(int i = 0; i < samples; i++) {
if (cloud > 0.99) break;
vec3 planeCoord = wpos * ((CLOUD_HEIGHT + currentStep * CLOUD_THICKNESS) / wpos.y);
vec2 coord = cameraPosition.xz * 0.0625 * 16.0 / CLOUD_VOLUMETRIC_SCALE + planeCoord.xz;
float noise = CloudSampleSkybox(coord, wind, currentStep, sunCoverage, dither);
float sampleLighting = pow(currentStep, 1.125 * halfVoLSqr + 0.875) * 0.8 + 0.2;
sampleLighting *= 1.0 - pow(noise, noiseLightFactor);
cloudLighting = mix(cloudLighting, sampleLighting, noise * (1.0 - cloud * cloud));
cloud = mix(cloud, 1.0, noise);
currentStep += sampleStep;
}
cloudLighting = mix(cloudLighting, 1.0, (1.0 - cloud * cloud) * scattering * 0.5);
cloudLighting *= (1.0 - 0.9 * rainStrength);
cloudColor = mix(
ambientCol * (0.3 * sunVisibility + 0.5),
lightCol * (0.85 + 1.15 * scattering),
cloudLighting
);
cloudColor *= 1.0 - 0.4 * rainStrength;
cloud *= clamp(1.0 - exp(-16.0 / max(fogDensity, 0.5) * VoU + 0.5), 0.0, 1.0);
if (fadeFaster) {
cloud *= 1.0 - pow(1.0 - VoU, 4.0);
}
}
cloudColor *= CLOUD_BRIGHTNESS * (0.5 - 0.25 * (1.0 - sunVisibility) * (1.0 - rainStrength));
// cloudColor *= voidFade;
#if MC_VERSION >= 11800
cloudColor *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
cloudColor *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
#ifdef UNDERGROUND_SKY
cloud *= mix(clamp((cameraPosition.y - 48.0) / 16.0, 0.0, 1.0), 1.0, eBS);
#endif
return vec4(cloudColor, cloud * cloud * CLOUD_OPACITY);
}
vec3 GetReflectedCameraPos(vec3 worldPos, vec3 normal) {
vec4 worldNormal = gbufferModelViewInverse * vec4(normal, 1.0);
worldNormal.xyz /= worldNormal.w;
vec3 cameraPos = cameraPosition + 2.0 * worldNormal.xyz * dot(worldPos, worldNormal.xyz);
cameraPos = cameraPos + reflect(worldPos, worldNormal.xyz); //bobbing stabilizer, works like magic
return cameraPos;
}
vec4 DrawCloudVolumetric(vec3 viewPos, vec3 cameraPos, float z, float dither, vec3 lightCol, vec3 ambientCol, inout float cloudViewLength, bool fadeFaster) {
#ifdef TAA
#if TAA_MODE == 0
dither = fract(dither + frameCounter * 0.618);
#else
dither = fract(dither + frameCounter * 0.5);
#endif
#endif
vec3 nViewPos = normalize(viewPos);
vec3 worldPos = (gbufferModelViewInverse * vec4(viewPos, 1.0)).xyz;
vec3 nWorldPos = normalize(worldPos);
float viewLength = length(viewPos);
float cloudHeight = CLOUD_HEIGHT * CLOUD_VOLUMETRIC_SCALE + 70;
// float cloudHeight = CLOUD_HEIGHT * CLOUD_VOLUMETRIC_SCALE + cameraPosition.y;
// float cloudHeight = 63;
float lowerY = cloudHeight;
float upperY = cloudHeight + CLOUD_THICKNESS * CLOUD_VOLUMETRIC_SCALE;
float lowerPlane = (lowerY - cameraPos.y) / nWorldPos.y;
float upperPlane = (upperY - cameraPos.y) / nWorldPos.y;
float nearestPlane = max(min(lowerPlane, upperPlane), 0.0);
float furthestPlane = max(lowerPlane, upperPlane);
float maxcloudViewLength = cloudViewLength;
if (furthestPlane < 0) return vec4(0.0);
float planeDifference = furthestPlane - nearestPlane;
vec3 startPos = cameraPos + nearestPlane * nWorldPos;
float scaling = abs(cameraPosition.y - (upperY + lowerY) * 0.5) / ((upperY - lowerY) * 0.5);
scaling = clamp((scaling - 1.0) * CLOUD_THICKNESS * 0.125, 0.0, 1.0);
float sampleLength = CLOUD_THICKNESS * CLOUD_VOLUMETRIC_SCALE / 2.0;
sampleLength /= (4.0 * nWorldPos.y * nWorldPos.y) * scaling + 1.0;
vec3 sampleStep = nWorldPos * sampleLength;
int samples = int(min(planeDifference / sampleLength, 32) + 1);
vec3 samplePos = startPos + sampleStep * dither;
float sampleTotalLength = nearestPlane + sampleLength * dither;
vec2 wind = vec2(
frametime * CLOUD_SPEED * 0.0005,
sin(frametime * CLOUD_SPEED * 0.001) * 0.005
) * CLOUD_HEIGHT / 15.0;
float cloud = 0.0;
float cloudFaded = 0.0;
float cloudLighting = 0.0;
float VoU = dot(nViewPos, upVec);
float VoL = dot(nViewPos, lightVec);
float sunCoverage = mix(abs(VoL), max(VoL, 0.0), shadowFade);
sunCoverage = pow(clamp(sunCoverage * 2.0 - 1.0, 0.0, 1.0), 12.0) * (1.0 - rainStrength);
float halfVoL = mix(abs(VoL) * 0.8, VoL, shadowFade) * 0.5 + 0.5;
float halfVoLSqr = halfVoL * halfVoL;
float scattering = pow(halfVoL, 6.0);
float noiseLightFactor = (2.0 - 1.5 * VoL * shadowFade) * CLOUD_DENSITY * 0.5;
float viewLengthSoftMin = viewLength - sampleLength * 0.5;
float viewLengthSoftMax = viewLength + sampleLength * 0.5;
float fade = 1.0;
float fadeStart = 32.0 / max(fogDensity, 0.5);
float fadeEnd = (fadeFaster ? 80.0 : 240.0) / max(fogDensity, 0.5);
for (int i = 0; i < samples; i++) {
if (cloud > 0.99) break;
if (sampleTotalLength > viewLengthSoftMax && z < 1.0) break;
float cloudGradient = InvLerp(samplePos.y, lowerY, upperY);
float xzNormalizedDistance = length(samplePos.xz - cameraPos.xz) / CLOUD_VOLUMETRIC_SCALE;
float noise = CloudSampleVolumetric(samplePos.xz, wind, cloudGradient, sunCoverage, dither);
noise *= step(lowerY, samplePos.y) * step(samplePos.y, upperY);
float sampleLighting = pow(cloudGradient, 1.125 * halfVoLSqr + 0.875) * 0.8 + 0.2;
sampleLighting *= 1.0 - pow(noise, noiseLightFactor);
float sampleFade = InvLerp(xzNormalizedDistance, fadeEnd, fadeStart);
fade *= mix(1.0, sampleFade, noise * (1.0 - cloud));
noise *= step(xzNormalizedDistance, fadeEnd);
cloudLighting = mix(cloudLighting, sampleLighting, noise * (1.0 - cloud * cloud));
if (z < 1.0) {
noise *= InvLerp(sampleTotalLength, viewLengthSoftMax, viewLengthSoftMin);
}
cloud = mix(cloud, 1.0, noise);
if (cloudViewLength == maxcloudViewLength && cloud > 0.5) {
cloudViewLength = sampleTotalLength;
}
samplePos += sampleStep;
sampleTotalLength += sampleLength;
}
cloudFaded = cloud * fade;
cloudLighting = mix(cloudLighting, 1.0, (1.0 - cloud * cloud) * scattering * 0.5);
cloudLighting *= (1.0 - 0.9 * rainStrength);
vec3 cloudColor = mix(
ambientCol * (0.3 * sunVisibility + 0.5),
lightCol * (0.85 + 1.15 * scattering),
cloudLighting
);
cloudColor *= 1.0 - 0.4 * rainStrength;
cloudColor *= CLOUD_BRIGHTNESS * (0.5 - 0.25 * (1.0 - sunVisibility) * (1.0 - rainStrength));
cloudFaded *= cloudFaded * CLOUD_OPACITY;
if (cloudFaded < dither) {
cloudViewLength = maxcloudViewLength;
}
return vec4(cloudColor, cloudFaded);
}
float GetNoise(vec2 pos) {
return fract(sin(dot(pos, vec2(12.9898, 4.1414))) * 43758.5453);
}
void DrawStars(inout vec3 color, vec3 viewPos) {
vec3 wpos = vec3(gbufferModelViewInverse * vec4(viewPos * 100.0, 1.0));
vec3 planeCoord = wpos / (wpos.y + length(wpos.xz));
vec2 wind = vec2(frametime, 0.0);
vec2 coord = planeCoord.xz * 0.4 + cameraPosition.xz * 0.0001 + wind * 0.00125;
coord = floor(coord * 1024.0) / 1024.0;
float VoU = clamp(dot(normalize(viewPos), upVec), 0.0, 1.0);
float VoL = dot(normalize(viewPos), sunVec);
float multiplier = sqrt(sqrt(VoU)) * 5.0 * (1.0 - rainStrength) * moonVisibility;
float star = 1.0;
if (VoU > 0.0) {
star *= GetNoise(coord.xy);
star *= GetNoise(coord.xy + 0.10);
star *= GetNoise(coord.xy + 0.23);
}
star = clamp(star - 0.8125, 0.0, 1.0) * multiplier;
//star *= voidFade;
#if MC_VERSION >= 11800
star *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
star *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
#ifdef UNDERGROUND_SKY
star *= mix(clamp((cameraPosition.y - 48.0) / 16.0, 0.0, 1.0), 1.0, eBS);
#endif
float moonFade = smoothstep(-0.997,-0.992, VoL);
star *= moonFade;
color += star * pow(lightNight, vec3(0.8));
}
#ifdef AURORA
#include "/lib/color/auroraColor.glsl"
float AuroraSample(vec2 coord, vec2 wind, float VoU) {
float noise = texture2D(noisetex, coord * 0.0625 + wind * 0.25).b * 3.0;
noise+= texture2D(noisetex, coord * 0.03125 + wind * 0.15).b * 3.0;
noise = max(1.0 - 4.0 * (0.5 * VoU + 0.5) * abs(noise - 3.0), 0.0);
return noise;
}
vec3 DrawAurora(vec3 viewPos, float dither, int samples) {
#ifdef TAA
#if TAA_MODE == 0
dither = fract(dither + frameCounter * 0.618);
#else
dither = fract(dither + frameCounter * 0.5);
#endif
#endif
float sampleStep = 1.0 / samples;
float currentStep = dither * sampleStep;
float VoU = dot(normalize(viewPos), upVec);
float visibility = moonVisibility * (1.0 - rainStrength) * (1.0 - rainStrength);
#ifdef WEATHER_PERBIOME
visibility *= isCold * isCold;
#endif
vec2 wind = vec2(
frametime * CLOUD_SPEED * 0.000125,
sin(frametime * CLOUD_SPEED * 0.05) * 0.00025
);
vec3 aurora = vec3(0.0);
if (VoU > 0.0 && visibility > 0.0) {
vec3 wpos = normalize((gbufferModelViewInverse * vec4(viewPos, 1.0)).xyz);
for(int i = 0; i < samples; i++) {
vec3 planeCoord = wpos * ((8.0 + currentStep * 7.0) / wpos.y) * 0.004;
vec2 coord = cameraPosition.xz * 0.00004 + planeCoord.xz;
coord += vec2(coord.y, -coord.x) * 0.3;
float noise = AuroraSample(coord, wind, VoU);
if (noise > 0.0) {
noise *= texture2D(noisetex, coord * 0.125 + wind * 0.25).b;
noise *= 0.5 * texture2D(noisetex, coord + wind * 16.0).b + 0.75;
noise = noise * noise * 3.0 * sampleStep;
noise *= max(sqrt(1.0 - length(planeCoord.xz) * 3.75), 0.0);
vec3 auroraColor = mix(auroraLowCol, auroraHighCol, pow(currentStep, 0.4));
aurora += noise * auroraColor * exp2(-6.0 * i * sampleStep);
}
currentStep += sampleStep;
}
}
// visibility *= voidFade;
#if MC_VERSION >= 11800
visibility *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
visibility *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
#ifdef UNDERGROUND_SKY
visibility *= mix(clamp((cameraPosition.y - 48.0) / 16.0, 0.0, 1.0), 1.0, eBS);
#endif
return aurora * visibility;
}
#endif
#endif
+190
View File
@@ -0,0 +1,190 @@
#ifdef OVERWORLD
vec3 GetFogColor(vec3 viewPos) {
vec3 nViewPos = normalize(viewPos);
float lViewPos = length(viewPos) / 64.0;
lViewPos = 1.0 - exp(-lViewPos * lViewPos);
float VoU = clamp(dot(nViewPos, upVec), -1.0, 1.0);
float VoL = clamp(dot(nViewPos, sunVec), -1.0, 1.0);
float density = 0.4;
float nightDensity = 1.0;
float weatherDensity = 1.5;
float groundDensity = 0.08 * (4.0 - 3.0 * sunVisibility) *
(10.0 * rainStrength * rainStrength + 1.0);
float exposure = exp2(timeBrightness * 0.75 - 0.75);
float nightExposure = exp2(-3.5);
float baseGradient = exp(-(VoU * 0.5 + 0.5) * 0.5 / density);
float groundVoU = clamp(-VoU * 0.5 + 0.5, 0.0, 1.0);
float ground = 1.0 - exp(-groundDensity / groundVoU);
vec3 fog = fogCol * baseGradient / (SKY_I * SKY_I);
fog = fog / sqrt(fog * fog + 1.0) * exposure * sunVisibility * (SKY_I * SKY_I);
float sunMix = (VoL * 0.5 + 0.5) * pow(clamp(1.0 - VoU, 0.0, 1.0), 2.0 - sunVisibility) *
pow(1.0 - timeBrightness * 0.6, 3.0);
float horizonMix = pow(1.0 - abs(VoU), 2.5) * 0.125;
float lightMix = (1.0 - (1.0 - sunMix) * (1.0 - horizonMix)) * lViewPos;
vec3 lightFog = pow(lightSun, vec3(4.0 - sunVisibility)) * baseGradient;
lightFog = lightFog / (1.0 + lightFog * rainStrength);
fog = mix(
sqrt(fog * (1.0 - lightMix)),
sqrt(lightFog),
lightMix
);
fog *= fog;
float nightGradient = exp(-(VoU * 0.5 + 0.5) * 0.35 / nightDensity);
vec3 nightFog = lightNight * lightNight * nightGradient * nightExposure;
fog = mix(nightFog, fog, sunVisibility * sunVisibility);
float rainGradient = exp(-(VoU * 0.5 + 0.5) * 0.125 / weatherDensity);
vec3 weatherFog = weatherCol.rgb * weatherCol.rgb;
weatherFog *= GetLuminance(ambientCol / (weatherFog)) * (0.2 * sunVisibility + 0.2);
fog = mix(fog, weatherFog * rainGradient, rainStrength);
fog = mix(minLightCol * 0.5, fog * eBS, eBS);
//fog *= voidFade;
#if MC_VERSION >= 11800
fog *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
fog *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
return fog;
}
#endif
void NormalFog(inout vec3 color, vec3 viewPos) {
float viewLength = length(viewPos);
vec4 worldPos = gbufferModelViewInverse * vec4(viewPos, 1.0);
worldPos.xyz /= worldPos.w;
#if FAR_VANILLA_FOG > 0
#if FAR_VANILLA_FOG_STYLE == 0
float fogFactor = viewLength;
#else
float fogFactor = length(worldPos.xz);
#endif
#endif
#ifdef OVERWORLD
float fog = viewLength * fogDensity / 1024.0;
float clearDay = sunVisibility * (1.0 - rainStrength);
#ifdef DISTANT_HORIZONS
fog *= FOG_DENSITY_DH;
#endif
fog *= mix(FOG_DENSITY_INDOOR, mix(1.0, FOG_DENSITY_WEATHER, rainStrength) / mix(1.0 / FOG_DENSITY_NIGHT, 1.0, clearDay) * eBS, eBS);
fog = min(fog, (fog - 0.8) * 0.25 + 0.8);
#ifdef FOG_HEIGHT
fog *= exp2(-max(worldPos.y + cameraPosition.y - FOG_HEIGHT_Y, 0.0) / exp2(FOG_HEIGHT_FALLOFF));
#endif
fog = 1.0 - exp(-2.0 * pow(fog, 0.35 * clearDay * eBS + 1.25));
vec3 fogColor = GetFogColor(viewPos);
#if FAR_VANILLA_FOG == 1 || FAR_VANILLA_FOG == 3
if(isEyeInWater == 0.0){
#if MC_VERSION >= 11800
float fogOffset = 0.0;
#else
float fogOffset = 12.0;
#endif
float fogFar = far;
float vanillaDensity = 0.2;
#ifdef DISTANT_HORIZONS
fogFar = dhFarPlane * 0.5;
vanillaDensity = 0.4;
#endif
float vanillaFog = 1.0 - (fogFar - (fogFactor + fogOffset)) / (vanillaDensity * fogFar * FOG_DENSITY_VANILLA);
vanillaFog = clamp(vanillaFog, 0.0, 1.0);
if(vanillaFog > 0.0){
vec3 vanillaFogColor = GetSkyColor(viewPos, false);
vanillaFogColor *= 1.0 + nightVision;
#ifdef CLASSIC_EXPOSURE
vanillaFogColor *= 4.0 - 3.0 * eBS;
#endif
fogColor *= fog;
fog = mix(fog, 1.0, vanillaFog);
if(fog > 0.0) fogColor = mix(fogColor, vanillaFogColor, vanillaFog) / fog;
}
}
#endif
#endif
#ifdef NETHER
float fog = 2.0 * pow(viewLength * fogDensity / 256.0, 1.5);
#if FAR_VANILLA_FOG == 2 || FAR_VANILLA_FOG == 3
#ifndef DISTANT_HORIZONS
fog += 6.0 * pow(fogFactor * 1.5 / far, 4.0);
#else
fog += 6.0 * pow(fogFactor * 3.0 / dhFarPlane, 4.0);
#endif
#endif
fog = 1.0 - exp(-fog);
vec3 fogColor = netherCol.rgb * 0.0425;
#endif
#ifdef END
float fog = viewLength * fogDensity / 512.0;
#if FAR_VANILLA_FOG == 2 || FAR_VANILLA_FOG == 3
#ifndef DISTANT_HORIZONS
fog += 2.0 * pow(fogFactor * 1.5 / far, 4.0);
#else
fog += 2.0 * pow(fogFactor * 3.0 / dhFarPlane, 4.0);
#endif
#endif
fog = 1.0 - exp(-fog);
vec3 fogColor = endCol.rgb * 0.003;
#ifndef LIGHT_SHAFT
fogColor *= 4.0;
#endif
#endif
color = mix(color, fogColor, fog);
}
void BlindFog(inout vec3 color, vec3 viewPos) {
float fog = length(viewPos) * max(blindFactor * 0.2, darknessFactor * 0.075);
fog = (1.0 - exp(-6.0 * fog * fog * fog)) * max(blindFactor, darknessFactor);
color = mix(color, vec3(0.0), fog);
}
vec3 denseFogColor[2] = vec3[2](
vec3(1.0, 0.3, 0.01),
vec3(0.1, 0.16, 0.2)
);
void DenseFog(inout vec3 color, vec3 viewPos) {
float fog = length(viewPos) * 0.5;
fog = (1.0 - exp(-4.0 * fog * fog * fog));
color = mix(color, denseFogColor[isEyeInWater - 2], fog);
}
void Fog(inout vec3 color, vec3 viewPos) {
NormalFog(color, viewPos);
if (isEyeInWater > 1) DenseFog(color, viewPos);
if (blindFactor > 0.0 || darknessFactor > 0.0) BlindFog(color, viewPos);
}
+77
View File
@@ -0,0 +1,77 @@
#ifdef OVERWORLD
vec3 GetSkyColor(vec3 viewPos, bool isReflection) {
vec3 nViewPos = normalize(viewPos);
float VoU = clamp(dot(nViewPos, upVec), -1.0, 1.0);
float VoL = clamp(dot(nViewPos, sunVec), -1.0, 1.0);
float groundDensity = 0.1 * (4.0 - 3.0 * sunVisibility) *
(10.0 * rainStrength * rainStrength + 1.0);
float exposure = exp2(timeBrightness * 0.75 - 0.75 + SKY_EXPOSURE_D);
float nightExposure = exp2(-3.5 + SKY_EXPOSURE_N);
float weatherExposure = exp2(SKY_EXPOSURE_W);
float gradientCurve = mix(SKY_HORIZON_F, SKY_HORIZON_N, VoL);
float baseGradient = exp(-(1.0 - pow(1.0 - max(VoU, 0.0), gradientCurve)) /
SKY_DENSITY_D);
#if SKY_GROUND > 0
float groundVoU = clamp(-VoU * 1.015 - 0.015, 0.0, 1.0);
float ground = 1.0 - exp(-groundDensity * max(fogDensity, 0.125) / groundVoU);
#if SKY_GROUND == 1
if (!isReflection) ground = 1.0;
#endif
#else
float ground = 1.0;
#endif
vec3 sky = skyCol;
#ifdef SKY_VANILLA
sky = mix(sky, fogCol, pow(1.0 - max(VoU, 0.0), 4.0));
#endif
sky *= baseGradient / (SKY_I * SKY_I);
sky = sky / sqrt(sky * sky + 1.0) * exposure * sunVisibility * (SKY_I * SKY_I);
float sunMix = (VoL * 0.5 + 0.5) * pow(clamp(1.0 - VoU, 0.0, 1.0), 2.0 - sunVisibility) *
pow(1.0 - timeBrightness * 0.6, 3.0);
float horizonMix = pow(1.0 - abs(VoU), 2.5) * 0.125;
float lightMix = (1.0 - (1.0 - sunMix) * (1.0 - horizonMix));
vec3 lightSky = pow(lightSun, vec3(4.0 - sunVisibility)) * baseGradient;
lightSky = lightSky / (1.0 + lightSky * rainStrength);
sky = mix(
sqrt(sky * (1.0 - lightMix)),
sqrt(lightSky),
lightMix
);
sky *= sky;
float nightGradient = exp(-max(VoU, 0.0) / SKY_DENSITY_N);
vec3 nightSky = lightNight * lightNight * nightGradient * nightExposure;
sky = mix(nightSky, sky, sunVisibility * sunVisibility);
float rainGradient = exp(-max(VoU, 0.0) / SKY_DENSITY_W);
vec3 weatherSky = weatherCol.rgb * weatherCol.rgb * weatherExposure;
weatherSky *= GetLuminance(ambientCol / (weatherSky)) * (0.2 * sunVisibility + 0.2);
sky = mix(sky, weatherSky * rainGradient, rainStrength);
sky *= ground;
#ifdef UNDERGROUND_SKY
float ug = mix(clamp((cameraPosition.y - 48.0) / 16.0, 0.0, 1.0), 1.0, eBS);
sky = mix(minLightCol * 0.125, sky, ug);
#endif
// sky *= voidFade;
#if MC_VERSION >= 11800
sky *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
sky *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
return sky;
}
#endif
+85
View File
@@ -0,0 +1,85 @@
void RoundSunMoon(inout vec3 color, vec3 viewPos, vec3 sunColor, vec3 moonColor) {
vec3 nViewPos = normalize(viewPos);
float VoL = dot(nViewPos, sunVec);
float VoU = dot(nViewPos, upVec);
if (VoU < -0.1) {
return;
}
float isMoon = float(VoL < 0.0);
float sunMoonSize = (0.007 - 0.004 * isMoon) * ROUND_SUN_MOON_SIZE;
float sun = pow(smoothstep(1.0 - sunMoonSize, 1.0, abs(VoL)), 3.0);
float miniGlare = pow(abs(VoL), 192.0 + 64.0 * isMoon) * (0.05 - 0.04 * isMoon);
float sunFade = smoothstep(0.0, 1.0, 1.0 - pow(1.0 - max(VoU * 0.98 + 0.02, 0.0), 8.0));
float glareFade = smoothstep(0.0, 1.0, 1.0 - pow(1.0 - max(VoU * 0.93 + 0.07, 0.0), 8.0));
float rainVisibility = 1.0 - sqrt(rainStrength);
vec3 moonNormal = vec3(0.0);
if (sun > 0.0 && isMoon > 0.5 && moonPhase > 0) {
const vec2 sunRotationData = vec2(cos(sunPathRotation * 0.01745329251994), -sin(sunPathRotation * 0.01745329251994));
float ang = fract(timeAngle + 0.0001 - 0.25);
ang = (ang + (cos(ang * 3.14159265358979) * -0.5 + 0.5 - ang) / 3.0) * 6.28318530717959;
vec3 nextSunVec = normalize((gbufferModelView * vec4(vec3(-sin(ang), cos(ang) * sunRotationData) * 2000.0, 1.0)).xyz);
vec3 sunTangent = normalize(nextSunVec - sunVec);
vec3 sunBinormal = -cross(sunVec, sunTangent);
float VoLt = dot(nViewPos, sunTangent);
float VoLb = dot(nViewPos, sunBinormal);
float rad = 0.08 * sqrt(ROUND_SUN_MOON_SIZE);
float moonNormalX = clamp(VoLt / rad, -1.0, 1.0);
float moonNormalY = clamp(VoLb / rad, -1.0, 1.0);
float moonNormalZ = sqrt(1.0 - moonNormalX * moonNormalX - moonNormalY * moonNormalY);
moonNormal = vec3(moonNormalX, moonNormalY, moonNormalZ);
if (sun > 0.0 && (moonNormalX * moonNormalX + moonNormalY * moonNormalY) > 1) color.r += 8.0;
vec3 moonPhaseVec = moonPhaseVecs[moonPhase];
float moonPhase = smoothstep(moonDiffuse[moonPhase].x, moonDiffuse[moonPhase].y, dot(moonNormal, moonPhaseVec));
float glaremoonPhase = (1.0 - moonPhase) * pow(sun,0.25);
sun *= moonPhase;
miniGlare *= 1.0 - glaremoonPhase;
}
sun *= sunFade * rainVisibility;
miniGlare *= glareFade * rainVisibility;
float sunColorPower = pow(1.0 - max(VoU, 0.0), 16.0) * 4.0 * sunVisibility + 1.0;
vec3 sunCol = pow(sunColor, vec3(sunColorPower)) * sunVisibility * SUN_INTENSITY * SUN_INTENSITY;
vec3 moonCol = moonColor * moonVisibility * MOON_INTENSITY * MOON_INTENSITY;
vec3 sunMoonCol = mix(sunCol, moonCol, isMoon);
color += (sun + miniGlare) * sunMoonCol * 4.0;
}
void SunGlare(inout vec3 color, vec3 viewPos, vec3 lightCol) {
float VoL = dot(normalize(viewPos), lightVec);
float visfactor = 0.05 * (-0.8 * timeBrightness + 1.0) * (3.0 * rainStrength + 1.0);
float invvisfactor = 1.0 - visfactor;
float visibility = clamp(VoL * 0.5 + 0.5, 0.0, 1.0);
visibility = visfactor / (1.0 - invvisfactor * visibility) - visfactor;
visibility = clamp(visibility * 1.015 / invvisfactor - 0.015, 0.0, 1.0);
visibility = mix(1.0, visibility, 0.03125 * eBS + 0.96875) * (1.0 - rainStrength * eBS * 0.875);
visibility *= shadowFade * LIGHT_SHAFT_STRENGTH;
//visibility *= voidFade;
#if MC_VERSION >= 11800
visibility *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
visibility *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
#ifdef LIGHT_SHAFT
if (isEyeInWater == 1) color += 0.25 * lightCol * visibility;
#else
color += 0.25 * lightCol * visibility * (1.0 + 0.25 * isEyeInWater);
#endif
}
@@ -0,0 +1,162 @@
float GetLogarithmicDepth(float dist) {
return (far * (dist - near)) / (dist * (far - near));
}
float GetLinearDepth2(float depth) {
return 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
}
vec4 DistortShadow(vec4 shadowpos, float distortFactor) {
shadowpos.xy *= 1.0 / distortFactor;
shadowpos.z = shadowpos.z * 0.2;
shadowpos = shadowpos * 0.5 + 0.5;
return shadowpos;
}
vec4 GetWorldSpace(float shadowdepth, vec2 texCoord) {
vec4 viewPos = gbufferProjectionInverse * (vec4(texCoord, shadowdepth, 1.0) * 2.0 - 1.0);
viewPos /= viewPos.w;
vec4 wpos = gbufferModelViewInverse * viewPos;
wpos /= wpos.w;
return wpos;
}
vec4 GetShadowSpace(vec4 wpos) {
wpos = shadowModelView * wpos;
wpos = shadowProjection * wpos;
wpos /= wpos.w;
float distb = sqrt(wpos.x * wpos.x + wpos.y * wpos.y);
float distortFactor = 1.0 - shadowMapBias + distb * shadowMapBias;
wpos = DistortShadow(wpos,distortFactor);
return wpos;
}
//Light shafts from Robobo1221 (modified)
vec3 GetLightShafts(float pixeldepth0, float pixeldepth1, vec3 color, float dither) {
vec3 vl = vec3(0.0);
#ifdef TAA
#if TAA_MODE == 0
dither = fract(dither + frameCounter * 0.618);
#else
dither = fract(dither + frameCounter * 0.5);
#endif
#endif
vec3 screenPos = vec3(texCoord, pixeldepth0);
vec4 viewPos = gbufferProjectionInverse * (vec4(screenPos, 1.0) * 2.0 - 1.0);
viewPos /= viewPos.w;
vec3 lightVec = sunVec * ((timeAngle < 0.5325 || timeAngle > 0.9675) ? 1.0 : -1.0);
float VoL = dot(normalize(viewPos.xyz), lightVec);
#ifdef OVERWORLD
float visfactor = 0.05 * (-0.8 * timeBrightness + 1.0) * (3.0 * rainStrength + 1.0);
float invvisfactor = 1.0 - visfactor;
float visibility = clamp(VoL * 0.5 + 0.5, 0.0, 1.0);
visibility = visfactor / (1.0 - invvisfactor * visibility) - visfactor;
visibility = clamp(visibility * 1.015 / invvisfactor - 0.015, 0.0, 1.0);
visibility = mix(1.0, visibility, 0.03125 * eBS + 0.96875);
#endif
#ifdef END
VoL = pow(VoL * 0.5 + 0.5, 16.0) * 0.75 + 0.25;
float visibility = VoL;
#endif
visibility *= 0.14285 * float(pixeldepth0 > 0.56);
if (visibility > 0.0) {
float maxDist = 128.0;
float depth0 = GetLinearDepth2(pixeldepth0);
float depth1 = GetLinearDepth2(pixeldepth1);
vec4 worldposition = vec4(0.0);
vec4 shadowposition = vec4(0.0);
vec3 watercol = mix(vec3(1.0),
waterColor.rgb / (waterColor.a * waterColor.a),
pow(waterAlpha, 0.25));
for(int i = 0; i < 7; i++) {
float minDist = exp2(i + dither) - 0.95;
if (minDist >= maxDist) break;
if (depth1 < minDist || (depth0 < minDist && color == vec3(0.0))) {
break;
}
worldposition = GetWorldSpace(GetLogarithmicDepth(minDist), texCoord.st);
shadowposition = GetShadowSpace(worldposition);
shadowposition.z += 0.0512 / shadowMapResolution;
if (length(shadowposition.xy * 2.0 - 1.0) < 1.0) {
float shadow0 = shadow2D(shadowtex0, shadowposition.xyz).z;
vec3 shadowCol = vec3(0.0);
#ifdef SHADOW_COLOR
if (shadow0 < 1.0) {
float shadow1 = shadow2D(shadowtex1, shadowposition.xyz).z;
if (shadow1 > 0.0) {
shadowCol = texture2D(shadowcolor0, shadowposition.xy).rgb;
shadowCol *= shadowCol * shadow1;
#ifdef WATER_CAUSTICS
shadowCol *= 16.0 - 15.0 * (1.0 - (1.0 - shadow0) * (1.0 - shadow0));
#endif
}
}
#endif
shadow0 *= shadow0;
shadowCol *= shadowCol;
vec3 shadow = clamp(shadowCol * (1.0 - shadow0) + shadow0, vec3(0.0), vec3(16.0));
if (depth0 < minDist) shadow *= color;
else if (isEyeInWater == 1.0) {
#ifdef WATER_SHADOW_COLOR
shadow *= 0.125 * (1.0 + eBS);
#else
shadow *= watercol * 0.01 * (1.0 + eBS);
#endif
}
#ifdef END
vec3 npos = worldposition.xyz + cameraPosition.xyz + vec3(frametime * 4.0, 0, 0);
float n3da = texture2D(noisetex, npos.xz / 512.0 + floor(npos.y / 3.0) * 0.35).r;
float n3db = texture2D(noisetex, npos.xz / 512.0 + floor(npos.y / 3.0 + 1.0) * 0.35).r;
float noise = mix(n3da, n3db, fract(npos.y / 3.0));
noise = sin(noise * 28.0 + frametime * 4.0) * 0.25 + 0.5;
shadow *= noise;
#endif
vl += shadow;
}
else{
vl += 1.0;
}
}
//vl *= voidFade;
#if MC_VERSION >= 11800
vl *= clamp((cameraPosition.y + 70.0) / 8.0, 0.0, 1.0);
#else
vl *= clamp((cameraPosition.y + 6.0) / 8.0, 0.0, 1.0);
#endif
#ifdef UNDERGROUND_SKY
vl *= mix(clamp((cameraPosition.y - 48.0) / 16.0, 0.0, 1.0), 1.0, eBS);
#endif
vl = sqrt(vl * visibility);
if(dot(vl, vl) > 0.0) vl += (dither - 0.25) / 128.0;
}
return vl;
}
+28
View File
@@ -0,0 +1,28 @@
#if (WATER_MODE == 1 || WATER_MODE == 3) && !defined SKY_VANILLA && (!defined NETHER || !defined NETHER_VANILLA)
uniform vec3 fogColor;
#endif
vec4 GetWaterFog(vec3 viewPos) {
float fog = length(viewPos) / waterFogRange;
fog = 1.0 - exp(-2.0 * fog);
#if WATER_MODE == 0 || WATER_MODE == 2
vec3 waterFogColor = waterColor.rgb * waterColor.a;
#elif WATER_MODE == 1 || WATER_MODE == 3
vec3 waterFogColor = fogColor * fogColor * 0.125;
#endif
waterFogColor *= WATER_F * WATER_F * (1.0 - max(blindFactor, darknessFactor));
#ifdef OVERWORLD
vec3 waterFogTint = lightCol * eBS * shadowFade * 0.9 + 0.1;
#endif
#ifdef NETHER
vec3 waterFogTint = netherCol.rgb;
#endif
#ifdef END
vec3 waterFogTint = endCol.rgb;
#endif
waterFogTint = sqrt(waterFogTint * length(waterFogTint));
return vec4(waterFogColor * waterFogTint, fog);
}
@@ -0,0 +1,14 @@
#if defined WEATHER_PERBIOME && defined OVERWORLD
float fogDensity = FOG_DENSITY * mix(
1.0,
(
FOG_DENSITY_COLD * isCold +
FOG_DENSITY_DRY * (isDesert + isMesa + isSavanna) +
FOG_DENSITY_DAMP * (isSwamp + isMushroom + isJungle)
) / max(weatherWeight, 0.0001),
weatherWeight
);
#else
float fogDensity = FOG_DENSITY;
#endif