This commit is contained in:
lucasdpt
2026-06-14 02:07:47 +02:00
parent 398e1e6ddf
commit 0129d81bd4
2475 changed files with 553889 additions and 553884 deletions
@@ -1,86 +1,86 @@
#ifndef INCLUDE_CLOUD_SHADOWS
#define INCLUDE_CLOUD_SHADOWS
#include "/lib/shaderSettings/cloudsAndLighting.glsl"
#ifdef CLOUDS_REIMAGINED
#include "/lib/atmospherics/clouds/cloudCoord.glsl"
#endif
float GetCloudShadow(vec3 playerPos) {
#ifndef OVERWORLD
return 1.0;
#endif
float cloudShadow = 1.0;
vec3 worldPos = playerPos + cameraPosition;
#if defined DO_PIXELATION_EFFECTS && defined PIXELATED_SHADOWS
//worldPos = playerPosPixelated + cameraPosition; // Disabled for now because cloud shadows are too soft to notice pixelation
#endif
#ifdef CLOUDS_REIMAGINED
float EdotL = dot(eastVec, lightVec);
float EdotLM = tan(acos(EdotL));
#if SUN_ANGLE != 0
float NVdotLM = tan(acos(dot(northVec, lightVec)));
#endif
float distToCloudLayer1 = cloudAlt1i - worldPos.y;
vec3 cloudOffset1 = vec3(distToCloudLayer1 / EdotLM, 0.0, 0.0);
#if SUN_ANGLE != 0
cloudOffset1.z += distToCloudLayer1 / NVdotLM;
#endif
vec2 cloudPos1 = GetRoundedCloudCoord(ModifyTracePos(worldPos + cloudOffset1, cloudAlt1i).xz, CLOUD_SHADOW_ROUNDNESS);
#ifndef COMPOSITE
float cloudSample = texture2D(gaux4, cloudPos1).b;
#else
float cloudSample = texture2D(cloudWaterTex, cloudPos1).b;
#endif
cloudSample *= clamp(distToCloudLayer1 * 0.1, 0.0, 1.0);
#ifdef DOUBLE_REIM_CLOUDS
float distToCloudLayer2 = cloudAlt2i - worldPos.y;
vec3 cloudOffset2 = vec3(distToCloudLayer2 / EdotLM, 0.0, 0.0);
#if SUN_ANGLE != 0
cloudOffset2.z += distToCloudLayer2 / NVdotLM;
#endif
vec2 cloudPos2 = GetRoundedCloudCoord(ModifyTracePos(worldPos + cloudOffset2, cloudAlt2i).xz, CLOUD_SHADOW_ROUNDNESS);
float cloudSample2 = texture2D(gaux4, cloudPos2).b;
cloudSample2 *= clamp(distToCloudLayer2 * 0.1, 0.0, 1.0);
cloudSample = 1.0 - (1.0 - cloudSample) * (1.0 - cloudSample2);
#endif
cloudSample *= sqrt3(1.0 - abs(EdotL));
cloudShadow = 1.0 - 0.85 * cloudSample;
#else
vec2 csPos = worldPos.xz + worldPos.y * 0.25;
csPos.x += syncedTime;
csPos *= 0.000002 * CLOUD_UNBOUND_SIZE_MULT * CLOUD_SHADOW_UNBOUND_SIZE;
vec2 shadowoffsets[8] = vec2[8](
vec2( 0.0 , 1.0 ),
vec2( 0.7071, 0.7071),
vec2( 1.0 , 0.0 ),
vec2( 0.7071,-0.7071),
vec2( 0.0 ,-1.0 ),
vec2(-0.7071,-0.7071),
vec2(-1.0 , 0.0 ),
vec2(-0.7071, 0.7071));
float cloudSample = 0.0;
for (int i = 0; i < 8; i++) {
cloudSample += texture2DLod(noisetex, csPos + 0.005 * shadowoffsets[i], 0.0).b;
}
cloudShadow = smoothstep1(pow2(min1(cloudSample * 0.2)));
#endif
cloudShadow = mix(1.0, mix(cloudShadow, 1.0, NIGHT_CLOUD_UNBOUND_REMOVE * (1.0 - sunVisibility)), CLOUD_TRANSPARENCY);
return cloudShadow;
}
#endif
#ifndef INCLUDE_CLOUD_SHADOWS
#define INCLUDE_CLOUD_SHADOWS
#include "/lib/shaderSettings/cloudsAndLighting.glsl"
#ifdef CLOUDS_REIMAGINED
#include "/lib/atmospherics/clouds/cloudCoord.glsl"
#endif
float GetCloudShadow(vec3 playerPos) {
#ifndef OVERWORLD
return 1.0;
#endif
float cloudShadow = 1.0;
vec3 worldPos = playerPos + cameraPosition;
#if defined DO_PIXELATION_EFFECTS && defined PIXELATED_SHADOWS
//worldPos = playerPosPixelated + cameraPosition; // Disabled for now because cloud shadows are too soft to notice pixelation
#endif
#ifdef CLOUDS_REIMAGINED
float EdotL = dot(eastVec, lightVec);
float EdotLM = tan(acos(EdotL));
#if SUN_ANGLE != 0
float NVdotLM = tan(acos(dot(northVec, lightVec)));
#endif
float distToCloudLayer1 = cloudAlt1i - worldPos.y;
vec3 cloudOffset1 = vec3(distToCloudLayer1 / EdotLM, 0.0, 0.0);
#if SUN_ANGLE != 0
cloudOffset1.z += distToCloudLayer1 / NVdotLM;
#endif
vec2 cloudPos1 = GetRoundedCloudCoord(ModifyTracePos(worldPos + cloudOffset1, cloudAlt1i).xz, CLOUD_SHADOW_ROUNDNESS);
#ifndef COMPOSITE
float cloudSample = texture2D(gaux4, cloudPos1).b;
#else
float cloudSample = texture2D(cloudWaterTex, cloudPos1).b;
#endif
cloudSample *= clamp(distToCloudLayer1 * 0.1, 0.0, 1.0);
#ifdef DOUBLE_REIM_CLOUDS
float distToCloudLayer2 = cloudAlt2i - worldPos.y;
vec3 cloudOffset2 = vec3(distToCloudLayer2 / EdotLM, 0.0, 0.0);
#if SUN_ANGLE != 0
cloudOffset2.z += distToCloudLayer2 / NVdotLM;
#endif
vec2 cloudPos2 = GetRoundedCloudCoord(ModifyTracePos(worldPos + cloudOffset2, cloudAlt2i).xz, CLOUD_SHADOW_ROUNDNESS);
float cloudSample2 = texture2D(gaux4, cloudPos2).b;
cloudSample2 *= clamp(distToCloudLayer2 * 0.1, 0.0, 1.0);
cloudSample = 1.0 - (1.0 - cloudSample) * (1.0 - cloudSample2);
#endif
cloudSample *= sqrt3(1.0 - abs(EdotL));
cloudShadow = 1.0 - 0.85 * cloudSample;
#else
vec2 csPos = worldPos.xz + worldPos.y * 0.25;
csPos.x += syncedTime;
csPos *= 0.000002 * CLOUD_UNBOUND_SIZE_MULT * CLOUD_SHADOW_UNBOUND_SIZE;
vec2 shadowoffsets[8] = vec2[8](
vec2( 0.0 , 1.0 ),
vec2( 0.7071, 0.7071),
vec2( 1.0 , 0.0 ),
vec2( 0.7071,-0.7071),
vec2( 0.0 ,-1.0 ),
vec2(-0.7071,-0.7071),
vec2(-1.0 , 0.0 ),
vec2(-0.7071, 0.7071));
float cloudSample = 0.0;
for (int i = 0; i < 8; i++) {
cloudSample += texture2DLod(noisetex, csPos + 0.005 * shadowoffsets[i], 0.0).b;
}
cloudShadow = smoothstep1(pow2(min1(cloudSample * 0.2)));
#endif
cloudShadow = mix(1.0, mix(cloudShadow, 1.0, NIGHT_CLOUD_UNBOUND_REMOVE * (1.0 - sunVisibility)), CLOUD_TRANSPARENCY);
return cloudShadow;
}
#endif
@@ -1,88 +1,88 @@
#include "/lib/misc/reprojection.glsl"
vec3 linearRGB_to_Oklab(vec3 c) {
// Linear RGB to XYZ
float l = 0.4122214708 * c.r + 0.5363325363 * c.g + 0.0514459929 * c.b;
float m = 0.2119034982 * c.r + 0.6806995451 * c.g + 0.1073969566 * c.b;
float s = 0.0883024619 * c.r + 0.2817188376 * c.g + 0.6299787005 * c.b;
// XYZ to Oklab
float l_ = pow(l, 1.0/3.0);
float m_ = pow(m, 1.0/3.0);
float s_ = pow(s, 1.0/3.0);
return vec3(
0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_,
1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_,
0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_
);
}
vec3 Oklab_to_linearRGB(vec3 lab) {
// Oklab to XYZ
float l_ = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;
float m_ = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;
float s_ = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;
float l = l_*l_*l_;
float m = m_*m_*m_;
float s = s_*s_*s_;
// XYZ to linear RGB
return vec3(
+4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
);
}
vec3 saturateMCBL(vec3 color) {
vec3 oklab = linearRGB_to_Oklab(color);
float L = oklab.x;
vec2 ab = oklab.yz;
float chroma = length(ab);
float maxChroma = 0.11;
float targetChroma = min(chroma * 1.7, maxChroma);
float chromaFactor = (chroma > 0.0001) ? min(targetChroma / chroma, 2.0) : 1.0;
ab *= chromaFactor;
return Oklab_to_linearRGB(vec3(L, ab.xy));
}
vec3 ApplyMultiColoredBlocklight(vec3 blocklightCol, vec3 screenPos, vec3 playerPos, float lmCoord) {
float ACTDecider = 1.0;
vec4 coloredLight = texture2D(colortex10, screenPos.xy);
float lmCoordStep = step(0.1, lmCoord);
float entityMask = 0.0;
#if MCBL_MAIN_DEFINE == 3
entityMask = step(0.5, sqrt3(coloredLight.a)) * lmCoordStep;
#endif
#if MCBL_MAIN_DEFINE == 2 && COLORED_LIGHTING_INTERNAL != 0
vec3 absPlayerPos = abs(playerPos);
float maxPlayerPos = max(absPlayerPos.x, max(absPlayerPos.y * 2.0, absPlayerPos.z));
ACTDecider = pow2(min1(maxPlayerPos / min(effectiveACTdistance, far) * 2.0)); // this is to make the effect fade at the edge of ACT range
if (entityMask < 0.5 && ACTDecider < 0.5) return blocklightCol;
#endif
vec3 cameraOffset = cameraPosition - previousCameraPosition;
cameraOffset *= float(screenPos.z * 2.0 - 1.0 > 0.56);
if (screenPos.z > 0.56) {
screenPos.xy = Reprojection(screenPos, cameraOffset);
}
coloredLight.rgb = saturateMCBL(coloredLight.rgb); // make colors pop!
vec3 coloredLightNormalized = normalize(coloredLight.rgb + 0.00001);
// do luminance correction for a seamless transition from the default blocklight color
coloredLightNormalized *= GetLuminance(blocklightCol) / GetLuminance(coloredLightNormalized);
float coloredLightMix = min1((coloredLight.r + coloredLight.g + coloredLight.b) * 2048);
coloredLightMix = mix(0, coloredLightMix, mix(ACTDecider, 1.0, entityMask));
// coloredLightNormalized = vec3(2,0,0);
return mix(blocklightCol, coloredLightNormalized, coloredLightMix * clamp01(MCBL_INFLUENCE) * (1.0 - float(isnan(coloredLightNormalized))) * max(sign(lmCoord), 0.0));
}
#include "/lib/misc/reprojection.glsl"
vec3 linearRGB_to_Oklab(vec3 c) {
// Linear RGB to XYZ
float l = 0.4122214708 * c.r + 0.5363325363 * c.g + 0.0514459929 * c.b;
float m = 0.2119034982 * c.r + 0.6806995451 * c.g + 0.1073969566 * c.b;
float s = 0.0883024619 * c.r + 0.2817188376 * c.g + 0.6299787005 * c.b;
// XYZ to Oklab
float l_ = pow(l, 1.0/3.0);
float m_ = pow(m, 1.0/3.0);
float s_ = pow(s, 1.0/3.0);
return vec3(
0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_,
1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_,
0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_
);
}
vec3 Oklab_to_linearRGB(vec3 lab) {
// Oklab to XYZ
float l_ = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;
float m_ = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;
float s_ = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;
float l = l_*l_*l_;
float m = m_*m_*m_;
float s = s_*s_*s_;
// XYZ to linear RGB
return vec3(
+4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
);
}
vec3 saturateMCBL(vec3 color) {
vec3 oklab = linearRGB_to_Oklab(color);
float L = oklab.x;
vec2 ab = oklab.yz;
float chroma = length(ab);
float maxChroma = 0.11;
float targetChroma = min(chroma * 1.7, maxChroma);
float chromaFactor = (chroma > 0.0001) ? min(targetChroma / chroma, 2.0) : 1.0;
ab *= chromaFactor;
return Oklab_to_linearRGB(vec3(L, ab.xy));
}
vec3 ApplyMultiColoredBlocklight(vec3 blocklightCol, vec3 screenPos, vec3 playerPos, float lmCoord) {
float ACTDecider = 1.0;
vec4 coloredLight = texture2D(colortex10, screenPos.xy);
float lmCoordStep = step(0.1, lmCoord);
float entityMask = 0.0;
#if MCBL_MAIN_DEFINE == 3
entityMask = step(0.5, sqrt3(coloredLight.a)) * lmCoordStep;
#endif
#if MCBL_MAIN_DEFINE == 2 && COLORED_LIGHTING_INTERNAL != 0
vec3 absPlayerPos = abs(playerPos);
float maxPlayerPos = max(absPlayerPos.x, max(absPlayerPos.y * 2.0, absPlayerPos.z));
ACTDecider = pow2(min1(maxPlayerPos / min(effectiveACTdistance, far) * 2.0)); // this is to make the effect fade at the edge of ACT range
if (entityMask < 0.5 && ACTDecider < 0.5) return blocklightCol;
#endif
vec3 cameraOffset = cameraPosition - previousCameraPosition;
cameraOffset *= float(screenPos.z * 2.0 - 1.0 > 0.56);
if (screenPos.z > 0.56) {
screenPos.xy = Reprojection(screenPos, cameraOffset);
}
coloredLight.rgb = saturateMCBL(coloredLight.rgb); // make colors pop!
vec3 coloredLightNormalized = normalize(coloredLight.rgb + 0.00001);
// do luminance correction for a seamless transition from the default blocklight color
coloredLightNormalized *= GetLuminance(blocklightCol) / GetLuminance(coloredLightNormalized);
float coloredLightMix = min1((coloredLight.r + coloredLight.g + coloredLight.b) * 2048);
coloredLightMix = mix(0, coloredLightMix, mix(ACTDecider, 1.0, entityMask));
// coloredLightNormalized = vec3(2,0,0);
return mix(blocklightCol, coloredLightNormalized, coloredLightMix * clamp01(MCBL_INFLUENCE) * (1.0 - float(isnan(coloredLightNormalized))) * max(sign(lmCoord), 0.0));
}
@@ -1,60 +1,60 @@
// GGX area light approximation from Horizon Zero Dawn
float GetNoHSquared(float radiusTan, float NoL, float NoV, float VoL) {
float radiusCos = 1.0 / sqrt(1.0 + radiusTan * radiusTan);
float RoL = 2.0 * NoL * NoV - VoL;
if (RoL >= radiusCos)
return 1.0;
float rOverLengthT = radiusCos * radiusTan / sqrt(1.0 - RoL * RoL);
float NoTr = rOverLengthT * (NoV - RoL * NoL);
float VoTr = rOverLengthT * (2.0 * NoV * NoV - 1.0 - RoL * VoL);
float triple = sqrt(clamp(1.0 - NoL * NoL - NoV * NoV - VoL * VoL + 2.0 * NoL * NoV * VoL, 0.0, 1.0));
float NoBr = rOverLengthT * triple, VoBr = rOverLengthT * (2.0 * triple * NoV);
float NoLVTr = NoL * radiusCos + NoV + NoTr, VoLVTr = VoL * radiusCos + 1.0 + VoTr;
float p = NoBr * VoLVTr, q = NoLVTr * VoLVTr, s = VoBr * NoLVTr;
float xNum = q * (-0.5 * p + 0.25 * VoBr * NoLVTr);
float xDenom = p * p + s * ((s - 2.0 * p)) + NoLVTr * ((NoL * radiusCos + NoV) * VoLVTr * VoLVTr +
q * (-0.5 * (VoLVTr + VoL * radiusCos) - 0.5));
float twoX1 = 2.0 * xNum / (xDenom * xDenom + xNum * xNum);
float sinTheta = twoX1 * xDenom;
float cosTheta = 1.0 - twoX1 * xNum;
NoTr = cosTheta * NoTr + sinTheta * NoBr;
VoTr = cosTheta * VoTr + sinTheta * VoBr;
float newNoL = NoL * radiusCos + NoTr;
float newVoL = VoL * radiusCos + VoTr;
float NoH = NoV + newNoL;
float HoH = 2.0 * newVoL + 2.0;
return clamp(NoH * NoH / HoH, 0.0, 1.0);
}
float GGX(vec3 normalM, vec3 viewPos, vec3 lightVec, float NdotLmax0, float smoothnessG) {
smoothnessG = sqrt1(smoothnessG * 0.9 + 0.1);
float roughnessP = (1.35 - smoothnessG);
float roughness = pow2(pow2(roughnessP));
vec3 halfVec = normalize(lightVec - viewPos);
float dotLH = clamp(dot(halfVec, lightVec), 0.0, 1.0);
float dotNV = dot(normalM, -viewPos);
#if WATER_REFLECT_QUALITY >= 2
float dotNH = GetNoHSquared(0.01, NdotLmax0, dotNV, dot(-viewPos, lightVec));
#else
float dotNH = pow2(min1(2.0 * NdotLmax0 * dotNV * length(halfVec) - dot(-viewPos, lightVec)));
#endif
float denom = dotNH * roughness - dotNH + 1.0;
float D = roughness / (3.141592653589793 * pow2(denom));
float f0 = 0.05;
float F = exp2((-5.55473 * dotLH - 6.98316) * dotLH) * (1.0 - f0) + f0;
float NdotLmax0M = sqrt3(NdotLmax0 * max0(dot(normal, lightVec)));
float specular = max0(NdotLmax0M * D * F / pow2(dotLH));
specular = specular / (0.125 * specular + 1.0);
return specular;
}
// GGX area light approximation from Horizon Zero Dawn
float GetNoHSquared(float radiusTan, float NoL, float NoV, float VoL) {
float radiusCos = 1.0 / sqrt(1.0 + radiusTan * radiusTan);
float RoL = 2.0 * NoL * NoV - VoL;
if (RoL >= radiusCos)
return 1.0;
float rOverLengthT = radiusCos * radiusTan / sqrt(1.0 - RoL * RoL);
float NoTr = rOverLengthT * (NoV - RoL * NoL);
float VoTr = rOverLengthT * (2.0 * NoV * NoV - 1.0 - RoL * VoL);
float triple = sqrt(clamp(1.0 - NoL * NoL - NoV * NoV - VoL * VoL + 2.0 * NoL * NoV * VoL, 0.0, 1.0));
float NoBr = rOverLengthT * triple, VoBr = rOverLengthT * (2.0 * triple * NoV);
float NoLVTr = NoL * radiusCos + NoV + NoTr, VoLVTr = VoL * radiusCos + 1.0 + VoTr;
float p = NoBr * VoLVTr, q = NoLVTr * VoLVTr, s = VoBr * NoLVTr;
float xNum = q * (-0.5 * p + 0.25 * VoBr * NoLVTr);
float xDenom = p * p + s * ((s - 2.0 * p)) + NoLVTr * ((NoL * radiusCos + NoV) * VoLVTr * VoLVTr +
q * (-0.5 * (VoLVTr + VoL * radiusCos) - 0.5));
float twoX1 = 2.0 * xNum / (xDenom * xDenom + xNum * xNum);
float sinTheta = twoX1 * xDenom;
float cosTheta = 1.0 - twoX1 * xNum;
NoTr = cosTheta * NoTr + sinTheta * NoBr;
VoTr = cosTheta * VoTr + sinTheta * VoBr;
float newNoL = NoL * radiusCos + NoTr;
float newVoL = VoL * radiusCos + VoTr;
float NoH = NoV + newNoL;
float HoH = 2.0 * newVoL + 2.0;
return clamp(NoH * NoH / HoH, 0.0, 1.0);
}
float GGX(vec3 normalM, vec3 viewPos, vec3 lightVec, float NdotLmax0, float smoothnessG) {
smoothnessG = sqrt1(smoothnessG * 0.9 + 0.1);
float roughnessP = (1.35 - smoothnessG);
float roughness = pow2(pow2(roughnessP));
vec3 halfVec = normalize(lightVec - viewPos);
float dotLH = clamp(dot(halfVec, lightVec), 0.0, 1.0);
float dotNV = dot(normalM, -viewPos);
#if WATER_REFLECT_QUALITY >= 2
float dotNH = GetNoHSquared(0.01, NdotLmax0, dotNV, dot(-viewPos, lightVec));
#else
float dotNH = pow2(min1(2.0 * NdotLmax0 * dotNV * length(halfVec) - dot(-viewPos, lightVec)));
#endif
float denom = dotNH * roughness - dotNH + 1.0;
float D = roughness / (3.141592653589793 * pow2(denom));
float f0 = 0.05;
float F = exp2((-5.55473 * dotLH - 6.98316) * dotLH) * (1.0 - f0) + f0;
float NdotLmax0M = sqrt3(NdotLmax0 * max0(dot(normal, lightVec)));
float specular = max0(NdotLmax0M * D * F / pow2(dotLH));
specular = specular / (0.125 * specular + 1.0);
return specular;
}
@@ -1,82 +1,82 @@
vec3 GetHeldLighting(vec3 playerPos, vec3 color, inout float emission, vec3 worldGeoNormal, vec3 normalM, vec3 viewPos) {
float heldLight = heldBlockLightValue; float heldLight2 = heldBlockLightValue2;
#ifndef IS_IRIS
if (heldLight > 15.1) heldLight = 0.0;
if (heldLight2 > 15.1) heldLight2 = 0.0;
#endif
#if COLORED_LIGHTING_INTERNAL == 0
vec3 heldLightCol = blocklightCol; vec3 heldLightCol2 = blocklightCol;
if (heldItemId == 45032) heldLight = 15; if (heldItemId2 == 45032) heldLight2 = 15; // Lava Bucket
#else
vec3 heldLightCol = GetSpecialBlocklightColor(heldItemId - 44000).rgb;
vec3 heldLightCol2 = GetSpecialBlocklightColor(heldItemId2 - 44000).rgb;
if (heldItemId == 45032) { heldLightCol = lavaSpecialLightColor.rgb; heldLight = 15; } // Lava Bucket
if (heldItemId2 == 45032) { heldLightCol2 = lavaSpecialLightColor.rgb; heldLight2 = 15; }
#if COLORED_LIGHT_SATURATION != 100
heldLightCol = mix(blocklightCol, heldLightCol, COLORED_LIGHT_SATURATION * 0.01);
heldLightCol2 = mix(blocklightCol, heldLightCol2, COLORED_LIGHT_SATURATION * 0.01);
#endif
#endif
vec3 playerPosLightM = playerPos + relativeEyePosition;
playerPosLightM.y += 0.7;
float lViewPosL = length(playerPosLightM) + 6.0;
#if HELD_LIGHTING_MODE == 1
lViewPosL *= 1.5;
#endif
#ifdef SPACEAGLE17
if (heldLight == 0 && heldLight2 == 0 && !firstPersonCamera && entityId != 50017 && !is_invisible && currentPlayerArmor < 0.4 && isOnGround) {
float powVal = 1.0 + 1.0 * (cos(frameTimeCounter * 1.5) * 0.5 + 0.5);
float anim = 2.8 * max(pow(0.8, powVal), 0.12);
heldLight = anim;
heldLight2 = anim;
heldLightCol = vec3(0.2392, 0.8235, 0.8667);
heldLightCol2 = vec3(0.2392, 0.8235, 0.8667);
playerPosLightM.y += 0.8;
lViewPosL = length(playerPosLightM) + 6.0;
lViewPosL = sqrt2(lViewPosL * 0.35) * 1.2;
}
#endif
#ifdef DIRECTIONAL_LIGHTMAP_NORMALS
vec3 cameraHeldLightPos = (gbufferModelView * vec4(-relativeEyePosition, 1.0)).xyz;
vec3 worldGeoNormalView = (gbufferModelView * vec4(worldGeoNormal, 1.0)).xyz;
cameraHeldLightPos.x += 0.66 * (float(heldLight > 0) - float(heldLight2 > 0)); // Held light position offset
float dirHandLightmap = clamp01(dot(normalize(cameraHeldLightPos - viewPos), normalM)) + 1.0;
float differenceDir = dirHandLightmap - (clamp01(dot(normalize(cameraHeldLightPos - viewPos), worldGeoNormalView)) + 1.0); // Difference between normal and geo normal
dirHandLightmap = mix(1.0, dirHandLightmap, differenceDir * DIRECTIONAL_LIGHTMAP_NORMALS_HANDHELD_STRENGTH);
heldLight *= dirHandLightmap;
heldLight2 *= dirHandLightmap;
#endif
heldLight = pow2(pow2(heldLight * 0.47 / lViewPosL));
heldLight2 = pow2(pow2(heldLight2 * 0.47 / lViewPosL));
vec3 heldLighting = pow2(heldLight * DoLuminanceCorrection(heldLightCol + 0.001))
+ pow2(heldLight2 * DoLuminanceCorrection(heldLightCol2 + 0.001));
#if COLORED_LIGHTING_INTERNAL > 0
AddSpecialLightDetail(heldLighting, color.rgb, emission);
#endif
#if HAND_BLOCKLIGHT_FLICKERING > 0
vec2 flickerNoiseHand = texture2DLod(noisetex, vec2(frameTimeCounter * 0.06), 0.0).rb;
float flickerMix = mix(1.0, min1(max(flickerNoiseHand.r, flickerNoiseHand.g) * 1.7), pow2(HAND_BLOCKLIGHT_FLICKERING * 0.1));
heldLighting *= flickerMix;
#ifdef GBUFFERS_HAND
emission *= mix(1.0, flickerMix, heldLight + heldLight2);
#endif
#endif
return heldLighting;
}
vec3 GetHeldLighting(vec3 playerPos, vec3 color, inout float emission, vec3 worldGeoNormal, vec3 normalM, vec3 viewPos) {
float heldLight = heldBlockLightValue; float heldLight2 = heldBlockLightValue2;
#ifndef IS_IRIS
if (heldLight > 15.1) heldLight = 0.0;
if (heldLight2 > 15.1) heldLight2 = 0.0;
#endif
#if COLORED_LIGHTING_INTERNAL == 0
vec3 heldLightCol = blocklightCol; vec3 heldLightCol2 = blocklightCol;
if (heldItemId == 45032) heldLight = 15; if (heldItemId2 == 45032) heldLight2 = 15; // Lava Bucket
#else
vec3 heldLightCol = GetSpecialBlocklightColor(heldItemId - 44000).rgb;
vec3 heldLightCol2 = GetSpecialBlocklightColor(heldItemId2 - 44000).rgb;
if (heldItemId == 45032) { heldLightCol = lavaSpecialLightColor.rgb; heldLight = 15; } // Lava Bucket
if (heldItemId2 == 45032) { heldLightCol2 = lavaSpecialLightColor.rgb; heldLight2 = 15; }
#if COLORED_LIGHT_SATURATION != 100
heldLightCol = mix(blocklightCol, heldLightCol, COLORED_LIGHT_SATURATION * 0.01);
heldLightCol2 = mix(blocklightCol, heldLightCol2, COLORED_LIGHT_SATURATION * 0.01);
#endif
#endif
vec3 playerPosLightM = playerPos + relativeEyePosition;
playerPosLightM.y += 0.7;
float lViewPosL = length(playerPosLightM) + 6.0;
#if HELD_LIGHTING_MODE == 1
lViewPosL *= 1.5;
#endif
#ifdef SPACEAGLE17
if (heldLight == 0 && heldLight2 == 0 && !firstPersonCamera && entityId != 50017 && !is_invisible && currentPlayerArmor < 0.4 && isOnGround) {
float powVal = 1.0 + 1.0 * (cos(frameTimeCounter * 1.5) * 0.5 + 0.5);
float anim = 2.8 * max(pow(0.8, powVal), 0.12);
heldLight = anim;
heldLight2 = anim;
heldLightCol = vec3(0.2392, 0.8235, 0.8667);
heldLightCol2 = vec3(0.2392, 0.8235, 0.8667);
playerPosLightM.y += 0.8;
lViewPosL = length(playerPosLightM) + 6.0;
lViewPosL = sqrt2(lViewPosL * 0.35) * 1.2;
}
#endif
#ifdef DIRECTIONAL_LIGHTMAP_NORMALS
vec3 cameraHeldLightPos = (gbufferModelView * vec4(-relativeEyePosition, 1.0)).xyz;
vec3 worldGeoNormalView = (gbufferModelView * vec4(worldGeoNormal, 1.0)).xyz;
cameraHeldLightPos.x += 0.66 * (float(heldLight > 0) - float(heldLight2 > 0)); // Held light position offset
float dirHandLightmap = clamp01(dot(normalize(cameraHeldLightPos - viewPos), normalM)) + 1.0;
float differenceDir = dirHandLightmap - (clamp01(dot(normalize(cameraHeldLightPos - viewPos), worldGeoNormalView)) + 1.0); // Difference between normal and geo normal
dirHandLightmap = mix(1.0, dirHandLightmap, differenceDir * DIRECTIONAL_LIGHTMAP_NORMALS_HANDHELD_STRENGTH);
heldLight *= dirHandLightmap;
heldLight2 *= dirHandLightmap;
#endif
heldLight = pow2(pow2(heldLight * 0.47 / lViewPosL));
heldLight2 = pow2(pow2(heldLight2 * 0.47 / lViewPosL));
vec3 heldLighting = pow2(heldLight * DoLuminanceCorrection(heldLightCol + 0.001))
+ pow2(heldLight2 * DoLuminanceCorrection(heldLightCol2 + 0.001));
#if COLORED_LIGHTING_INTERNAL > 0
AddSpecialLightDetail(heldLighting, color.rgb, emission);
#endif
#if HAND_BLOCKLIGHT_FLICKERING > 0
vec2 flickerNoiseHand = texture2DLod(noisetex, vec2(frameTimeCounter * 0.06), 0.0).rb;
float flickerMix = mix(1.0, min1(max(flickerNoiseHand.r, flickerNoiseHand.g) * 1.7), pow2(HAND_BLOCKLIGHT_FLICKERING * 0.1));
heldLighting *= flickerMix;
#ifdef GBUFFERS_HAND
emission *= mix(1.0, flickerMix, heldLight + heldLight2);
#endif
#endif
return heldLighting;
}
@@ -1,25 +1,25 @@
vec3 GetMinimumLighting(float lightmapYM, vec3 playerPos) {
float fadeMinLightDistance = 1.0;
#if DISTANCE_MIN_LIGHT > 0
float blockMinLightFadeDistance = 250;
float distMinLightIntensity = DISTANCE_MIN_LIGHT * 0.1;
fadeMinLightDistance = max(1.0 - length(playerPos) / blockMinLightFadeDistance, 0.0);
fadeMinLightDistance = exp((1.0 - fadeMinLightDistance) * -15.0 * distMinLightIntensity) * (1.0 - nightVision) + nightVision;
#endif
#if !defined END && CAVE_LIGHTING > 0
vec3 minLighting = vec3(0.005625 + vsBrightness * 0.043) * fadeMinLightDistance;
#if CAVE_LIGHTING != 100
#define CAVE_LIGHTING_M CAVE_LIGHTING * 0.01
minLighting *= CAVE_LIGHTING_M;
#endif
minLighting *= vec3(0.45, 0.475, 0.6);
minLighting *= 1.0 - lightmapYM;
#else
vec3 minLighting = vec3(0.0);
#endif
minLighting += nightVision * vec3(0.5, 0.5, 0.75);
return minLighting;
}
vec3 GetMinimumLighting(float lightmapYM, vec3 playerPos) {
float fadeMinLightDistance = 1.0;
#if DISTANCE_MIN_LIGHT > 0
float blockMinLightFadeDistance = 250;
float distMinLightIntensity = DISTANCE_MIN_LIGHT * 0.1;
fadeMinLightDistance = max(1.0 - length(playerPos) / blockMinLightFadeDistance, 0.0);
fadeMinLightDistance = exp((1.0 - fadeMinLightDistance) * -15.0 * distMinLightIntensity) * (1.0 - nightVision) + nightVision;
#endif
#if !defined END && CAVE_LIGHTING > 0
vec3 minLighting = vec3(0.005625 + vsBrightness * 0.043) * fadeMinLightDistance;
#if CAVE_LIGHTING != 100
#define CAVE_LIGHTING_M CAVE_LIGHTING * 0.01
minLighting *= CAVE_LIGHTING_M;
#endif
minLighting *= vec3(0.45, 0.475, 0.6);
minLighting *= 1.0 - lightmapYM;
#else
vec3 minLighting = vec3(0.0);
#endif
minLighting += nightVision * vec3(0.5, 0.5, 0.75);
return minLighting;
}
@@ -1,110 +1,110 @@
vec3 GetShadowPos(vec3 playerPos) {
vec3 shadowPos = PlayerToShadow(playerPos);
float distb = sqrt(shadowPos.x * shadowPos.x + shadowPos.y * shadowPos.y);
float distortFactor = distb * shadowMapBias + (1.0 - shadowMapBias);
shadowPos.xy /= distortFactor;
shadowPos.z *= 0.2;
return shadowPos * 0.5 + 0.5;
}
vec3 SampleShadow(vec3 shadowPos, float colorMult, float colorPow) {
float shadow0 = shadow2D(shadowtex0, vec3(shadowPos.st, shadowPos.z)).x;
vec3 shadowcol = vec3(0.0);
if (shadow0 < 1.0) {
float shadow1 = shadow2D(shadowtex1, vec3(shadowPos.st, shadowPos.z)).x;
if (shadow1 > 0.9999) {
shadowcol = texture2D(shadowcolor0, shadowPos.st).rgb * shadow1;
shadowcol *= colorMult;
shadowcol = pow(shadowcol, vec3(colorPow));
}
}
return shadowcol * (1.0 - shadow0) + shadow0;
}
float InterleavedGradientNoiseForShadows() {
float n = 52.9829189 * fract(0.06711056 * gl_FragCoord.x + 0.00583715 * gl_FragCoord.y);
#if !defined GBUFFERS_ENTITIES && !defined GBUFFERS_HAND && !defined GBUFFERS_TEXTURED && defined TAA
return fract(n + goldenRatio * mod(float(frameCounter), 3600.0));
#else
return fract(n);
#endif
}
vec2 offsetDist(float x, int s) {
float n = fract(x * 2.427) * 3.1415;
return vec2(cos(n), sin(n)) * 1.4 * x / s;
}
vec3 SampleTAAFilteredShadow(vec3 shadowPos, float offset, int shadowSamples, bool leaves, float colorMult, float colorPow) {
vec3 shadow = vec3(0.0);
float gradientNoise = InterleavedGradientNoiseForShadows();
#if !defined GBUFFERS_ENTITIES && !defined GBUFFERS_HAND && !defined GBUFFERS_TEXTURED
offset *= 1.3875;
#else
shadowSamples *= 2;
offset *= 0.69375;
#endif
float shadowPosZM = shadowPos.z;
for (int i = 0; i < shadowSamples; i++) {
vec2 offset2 = offsetDist(gradientNoise + i, shadowSamples) * offset;
if (leaves) shadowPosZM = shadowPos.z - 0.12 * offset * (gradientNoise + i) / shadowSamples;
shadow += SampleShadow(vec3(shadowPos.st + offset2, shadowPosZM), colorMult, colorPow);
shadow += SampleShadow(vec3(shadowPos.st - offset2, shadowPosZM), colorMult, colorPow);
}
shadow /= shadowSamples * 2.0;
return shadow;
}
vec2 shadowOffsets[4] = vec2[4](
vec2( 1.0, 0.0),
vec2( 0.0, 1.0),
vec2(-1.0, 0.0),
vec2( 0.0,-1.0));
vec3 SampleBasicFilteredShadow(vec3 shadowPos, float offset) {
float shadow = 0.0;
for (int i = 0; i < 4; i++) {
shadow += shadow2D(shadowtex0, vec3(offset * shadowOffsets[i] + shadowPos.st, shadowPos.z)).x;
}
return vec3(shadow * 0.25);
}
vec3 GetShadow(vec3 shadowPos, float lightmapY, float offset, int shadowSamples, bool leaves) {
#if SHADOW_QUALITY > 0
#if ENTITY_SHADOW <= 1 && defined GBUFFERS_BLOCK
offset *= 4.0;
#else
#ifdef OVERWORLD
offset *= 1.0 + rainFactor2
#ifdef SUN_MOON_DURING_RAIN
* 2.0
#else
* 4.0
#endif
;
#else
offset *= 3.0;
#endif
#endif
#endif
float colorMult = 2.5 + 5.5 * pow1_5(lightmapY) + 2.0 * pow2(lightmapY); // 423HDSS: Shadow color strength is stored 10 times lower to allow for water shadows going above 1.0
float colorPow = mix(1.5 + 0.5 * float(isEyeInWater == 0), 0.5, pow2(pow2(lightmapY)));
#if SHADOW_QUALITY >= 1
vec3 shadow = SampleTAAFilteredShadow(shadowPos, offset, shadowSamples, leaves, colorMult, colorPow);
#else
vec3 shadow = SampleBasicFilteredShadow(shadowPos, offset);
#endif
return shadow;
}
vec3 GetShadowPos(vec3 playerPos) {
vec3 shadowPos = PlayerToShadow(playerPos);
float distb = sqrt(shadowPos.x * shadowPos.x + shadowPos.y * shadowPos.y);
float distortFactor = distb * shadowMapBias + (1.0 - shadowMapBias);
shadowPos.xy /= distortFactor;
shadowPos.z *= 0.2;
return shadowPos * 0.5 + 0.5;
}
vec3 SampleShadow(vec3 shadowPos, float colorMult, float colorPow) {
float shadow0 = shadow2D(shadowtex0, vec3(shadowPos.st, shadowPos.z)).x;
vec3 shadowcol = vec3(0.0);
if (shadow0 < 1.0) {
float shadow1 = shadow2D(shadowtex1, vec3(shadowPos.st, shadowPos.z)).x;
if (shadow1 > 0.9999) {
shadowcol = texture2D(shadowcolor0, shadowPos.st).rgb * shadow1;
shadowcol *= colorMult;
shadowcol = pow(shadowcol, vec3(colorPow));
}
}
return shadowcol * (1.0 - shadow0) + shadow0;
}
float InterleavedGradientNoiseForShadows() {
float n = 52.9829189 * fract(0.06711056 * gl_FragCoord.x + 0.00583715 * gl_FragCoord.y);
#if !defined GBUFFERS_ENTITIES && !defined GBUFFERS_HAND && !defined GBUFFERS_TEXTURED && defined TAA
return fract(n + goldenRatio * mod(float(frameCounter), 3600.0));
#else
return fract(n);
#endif
}
vec2 offsetDist(float x, int s) {
float n = fract(x * 2.427) * 3.1415;
return vec2(cos(n), sin(n)) * 1.4 * x / s;
}
vec3 SampleTAAFilteredShadow(vec3 shadowPos, float offset, int shadowSamples, bool leaves, float colorMult, float colorPow) {
vec3 shadow = vec3(0.0);
float gradientNoise = InterleavedGradientNoiseForShadows();
#if !defined GBUFFERS_ENTITIES && !defined GBUFFERS_HAND && !defined GBUFFERS_TEXTURED
offset *= 1.3875;
#else
shadowSamples *= 2;
offset *= 0.69375;
#endif
float shadowPosZM = shadowPos.z;
for (int i = 0; i < shadowSamples; i++) {
vec2 offset2 = offsetDist(gradientNoise + i, shadowSamples) * offset;
if (leaves) shadowPosZM = shadowPos.z - 0.12 * offset * (gradientNoise + i) / shadowSamples;
shadow += SampleShadow(vec3(shadowPos.st + offset2, shadowPosZM), colorMult, colorPow);
shadow += SampleShadow(vec3(shadowPos.st - offset2, shadowPosZM), colorMult, colorPow);
}
shadow /= shadowSamples * 2.0;
return shadow;
}
vec2 shadowOffsets[4] = vec2[4](
vec2( 1.0, 0.0),
vec2( 0.0, 1.0),
vec2(-1.0, 0.0),
vec2( 0.0,-1.0));
vec3 SampleBasicFilteredShadow(vec3 shadowPos, float offset) {
float shadow = 0.0;
for (int i = 0; i < 4; i++) {
shadow += shadow2D(shadowtex0, vec3(offset * shadowOffsets[i] + shadowPos.st, shadowPos.z)).x;
}
return vec3(shadow * 0.25);
}
vec3 GetShadow(vec3 shadowPos, float lightmapY, float offset, int shadowSamples, bool leaves) {
#if SHADOW_QUALITY > 0
#if ENTITY_SHADOW <= 1 && defined GBUFFERS_BLOCK
offset *= 4.0;
#else
#ifdef OVERWORLD
offset *= 1.0 + rainFactor2
#ifdef SUN_MOON_DURING_RAIN
* 2.0
#else
* 4.0
#endif
;
#else
offset *= 3.0;
#endif
#endif
#endif
float colorMult = 2.5 + 5.5 * pow1_5(lightmapY) + 2.0 * pow2(lightmapY); // 423HDSS: Shadow color strength is stored 10 times lower to allow for water shadows going above 1.0
float colorPow = mix(1.5 + 0.5 * float(isEyeInWater == 0), 0.5, pow2(pow2(lightmapY)));
#if SHADOW_QUALITY >= 1
vec3 shadow = SampleTAAFilteredShadow(shadowPos, offset, shadowSamples, leaves, colorMult, colorPow);
#else
vec3 shadow = SampleBasicFilteredShadow(shadowPos, offset);
#endif
return shadow;
}