custommods

This commit is contained in:
samsonsin
2025-05-29 23:31:29 +02:00
committed by samsonsin
parent 29b5acd552
commit cec1be0c4f
799 changed files with 19536 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
float waterH(vec3 pos) {
float noise = 0;
vec2 wind = vec2(frametime) * 0.25 * WATER_SPEED;
float yFactor = 0.5;
noise+= texture2D(noisetex,(pos.xz + wind - pos.y * yFactor) / 1024.0 * 1.1).r * 1.0;
noise+= texture2D(noisetex,(pos.xz - wind - pos.y * yFactor) / 1024.0 * 1.5).r * 0.8;
noise-= texture2D(noisetex,(pos.xz + wind + pos.y * yFactor) / 1024.0 * 2.5).r * 0.6;
noise+= texture2D(noisetex,(pos.xz - wind - pos.y * yFactor) / 1024.0 * 5.0).r * 0.4;
noise-= texture2D(noisetex,(pos.xz + wind + pos.y * yFactor) / 1024.0 * 8.0).r * 0.2;
return noise;
}
float getCausticWaves(vec3 pos) {
float deltaPos = 0.1;
float caustic_h0 = waterH(pos);
float caustic_h1 = waterH(pos + vec3( deltaPos, 0.0, 0.0));
float caustic_h2 = waterH(pos + vec3(-deltaPos, 0.0, 0.0));
float caustic_h3 = waterH(pos + vec3( 0.0, 0.0, deltaPos));
float caustic_h4 = waterH(pos + vec3( 0.0, 0.0, -deltaPos));
float caustic = max((1.0-abs(0.5-caustic_h0))*(1.0-(abs(caustic_h1-caustic_h2)+abs(caustic_h3-caustic_h4))),0.0);
caustic = max(pow(caustic,3.5),0.0)*2.0;
return caustic;
}

View File

@@ -0,0 +1,442 @@
#if defined SHADOWS && ((defined PROJECTED_CAUSTICS && !defined GBUFFERS_WATER) || defined COLORED_SHADOWS) && defined OVERWORLD
uniform sampler2DShadow shadowtex1;
#endif
#if (defined OVERWORLD || defined END || defined SEVEN) && defined SHADOWS
#include "/lib/lighting/shadows.glsl"
vec3 DistortShadow(inout vec3 worldPos, float distortFactor) {
worldPos.xy /= distortFactor;
worldPos.z *= 0.2;
return worldPos * 0.5 + 0.5;
}
#endif
#if defined WATER_CAUSTICS && defined OVERWORLD
#include "/lib/lighting/caustics.glsl"
#endif
float GetFakeShadow(float skyLight) {
float fakeShadow = 0.0;
#ifndef END
if (isEyeInWater == 0) skyLight = pow(skyLight, 30.0);
fakeShadow = skyLight;
#else
#ifdef SHADOWS
fakeShadow = 1.0;
#else
fakeShadow = 0.0;
#endif
#endif
return fakeShadow;
}
void GetLighting(inout vec3 albedo, inout vec3 shadow, inout vec3 lightAlbedo, vec3 viewPos, float lViewPos, vec3 worldPos,
vec2 lightmap, float smoothLighting, float NdotL, float quarterNdotU,
float parallaxShadow, float emissive, float subsurface, float leaves, float materialAO) {
vec3 fullShadow = vec3(0.0);
float fullShadow1 = 0.0;
float fakeShadow = 0.0;
float shadowMult = 1.0;
float shadowTime = 1.0;
float water = 0.0;
#if PIXEL_SHADOWS > 0 && !defined GBUFFERS_HAND
worldPos = floor((worldPos + cameraPosition) * PIXEL_SHADOWS + 0.001) / PIXEL_SHADOWS - cameraPosition + 0.5 / PIXEL_SHADOWS;
#endif
#if defined OVERWORLD || defined END || defined SEVEN
#ifdef SHADOWS
shadow = vec3(1.0);
if ((NdotL > 0.0 || subsurface > 0.001)) {
float shadowLength = shadowDistance * 0.9166667 - length(vec4(worldPos.x, worldPos.y, worldPos.y, worldPos.z));
//shadowDistance * 0.9166667 is shadowDistance - shadowDistance / 12.0
#if (defined OVERWORLD || defined SEVEN) && defined LIGHT_LEAK_FIX
if (isEyeInWater == 0) shadowLength *= float(lightmap.y > 0.001);
#endif
#ifdef TEST_12312
vec3 shadowPos = WorldToShadow(worldPos);
float distb = sqrt(shadowPos.x * shadowPos.x + shadowPos.y * shadowPos.y);
float distortFactor = distb * shadowMapBias + (1.0 - shadowMapBias);
shadowPos = DistortShadow(shadowPos, distortFactor);
bool doShadow = min2(shadowPos.xy) > 0.0
&& max2(shadowPos.xy) < 1.0;
if (!doShadow || shadowLength < 0.000001) albedo.rgb = vec3(1.0, 0.0, 1.0);
shadowLength = 999999.0;
#endif
if (shadowLength > 0.000001) {
#ifndef TEST_12312
vec3 shadowPos = WorldToShadow(worldPos);
float distb = sqrt(shadowPos.x * shadowPos.x + shadowPos.y * shadowPos.y);
float distortFactor = distb * shadowMapBias + (1.0 - shadowMapBias);
shadowPos = DistortShadow(shadowPos, distortFactor);
#endif
#ifdef NORMAL_MAPPING
float NdotLm = clamp(dot(normal, lightVec) * 1.01 - 0.01, 0.0, 1.0) * 0.99 + 0.01;
NdotL = min(NdotL, NdotLm);
#else
float NdotLm = NdotL * 0.99 + 0.01;
#endif
float dotWorldPos = dot(worldPos.xyz, worldPos.xyz);
float biasFactor = sqrt(1.0 - NdotLm * NdotLm) / NdotLm;
float distortBias = distortFactor * shadowDistance / 256.0;
distortBias *= 8.0 * distortBias;
float bias = (distortBias * biasFactor + dotWorldPos * 0.000005 + 0.05) / shadowMapResolution;
float offset = 1.0 / shadowMapResolution;
int doSubsurface = 0;
if (subsurface > 0.001) {
if (leaves < 0.5) {
float UdotLm = clamp(dot(upVec, lightVec) * 1.01 - 0.01, 0.0, 1.0) * 0.99 + 0.01;
float biasFactorF = sqrt(1.0 - UdotLm * UdotLm) / UdotLm;
bias = (distortBias * biasFactorF + 0.05) / shadowMapResolution * 1.3;
} else bias = 0.0002;
offset = 0.002;
#if SHADOW_SUBSURFACE > 2
doSubsurface = 14;
#endif
}
if (isEyeInWater == 1) offset *= 5.0;
#if PIXEL_SHADOWS > 0 && !defined GBUFFERS_HAND
bias += 0.0025 / PIXEL_SHADOWS * (1.0 + subsurface);
#endif
shadowPos.z -= bias;
shadow = GetShadow(shadowPos, offset, water, doSubsurface);
float extraSideLight = 1.0;
shadow *= (1.0 + extraSideLight) - extraSideLight * quarterNdotU;
#if defined PROJECTED_CAUSTICS && defined WATER_CAUSTICS && defined OVERWORLD && !defined GBUFFERS_WATER
if (isEyeInWater == 0) {
water = float(water > 0.99);
water *= sqrt2(NdotL);
float shadowSum = (shadow.r + shadow.g + shadow.b) / 3.0;
water *= pow2(1.0 - shadowSum);
}
#ifdef GBUFFERS_ENTITIES
if (entityId == 1089) { // Boats
water = 0.0;
}
#endif
#endif
}
float shadowSmooth = 16.0;
if (shadowLength < shadowSmooth) {
float shadowLengthDecider = max(shadowLength / shadowSmooth, 0.0);
float skyLightShadow = GetFakeShadow(lightmap.y);
shadow = mix(vec3(skyLightShadow), shadow, shadowLengthDecider);
subsurface *= mix(subsurface * 0.5, subsurface, shadowLengthDecider);
fakeShadow = mix(1.0, fakeShadow, shadowLengthDecider);
fakeShadow = 1.0 - fakeShadow;
fakeShadow *= fakeShadow;
fakeShadow = 1.0 - fakeShadow;
}
#ifdef TEST_12312
if (shadow.r < 0.1 && albedo.r + albedo.b < 1.9) {
float timeThing1 = abs(fract(frameTimeCounter * 1.35) - 0.5) * 2.0;
float timeThing2 = abs(fract(frameTimeCounter * 1.15) - 0.5) * 2.0;
float timeThing3 = abs(fract(frameTimeCounter * 1.55) - 0.5) * 2.0;
albedo.rgb = 3.0 * pow(vec3(timeThing1, timeThing2, timeThing3), vec3(3.2));
}
#endif
}
#else
shadow = vec3(GetFakeShadow(lightmap.y));
#endif
#if defined CLOUD_SHADOW && defined OVERWORLD
float cloudSize = 0.000025;
vec2 wind = vec2(frametime, 0.0) * CLOUD_SPEED * 6.0;
float cloudShadow = texture2D(noisetex, cloudSize * (wind + (worldPos.xz + cameraPosition.xz))).r;
cloudShadow += texture2D(noisetex, cloudSize * (vec2(1000.0) + wind + (worldPos.xz + cameraPosition.xz))).r;
cloudShadow = clamp(cloudShadow, 0.0, 1.0);
cloudShadow *= cloudShadow;
cloudShadow *= cloudShadow;
shadow *= cloudShadow;
#endif
#ifdef ADV_MAT
#ifdef SELF_SHADOW
float shadowNdotL = min(NdotL + 0.5, 1.0);
shadowNdotL *= shadowNdotL;
shadow *= mix(1.0, parallaxShadow, shadowNdotL);
#endif
#endif
fullShadow = shadow * max(NdotL, subsurface * (1.0 - max(rainStrengthS, (1.0 - sunVisibility)) * 0.40));
fullShadow1 = (fullShadow.r + fullShadow.g + fullShadow.b) / 3.0;
#ifdef ADV_MAT
shadow *= float(fullShadow1 > 0.01);
#endif
#if defined OVERWORLD && !defined TWO
shadowMult = 1.0 * (1.0 - 0.95 * rainStrengthS);
shadowTime = abs(sunVisibility - 0.5) * 2.0;
shadowTime *= shadowTime;
shadowMult *= shadowTime * shadowTime;
#ifndef LIGHT_LEAK_FIX
ambientCol *= pow(lightmap.y, 2.5);
#else
if (isEyeInWater == 1) ambientCol *= pow(lightmap.y, 2.5);
#endif
vec3 lightingCol = pow(lightCol, vec3(1.0 + sunVisibility * 1.5 - 0.5 * timeBrightness));
#ifdef SHADOWS
lightingCol *= (1.0 + 0.5 * leaves);
#else
lightingCol *= (1.0 + 0.4 * leaves);
#endif
vec3 shadowDecider = fullShadow * shadowMult;
if (isEyeInWater == 1) shadowDecider *= pow(min(lightmap.y * 1.03, 1.0), 200.0);
ambientCol *= AMBIENT_GROUND;
lightingCol *= LIGHT_GROUND;
vec3 sceneLighting = mix(ambientCol, lightingCol, shadowDecider);
#ifdef LIGHT_LEAK_FIX
if (isEyeInWater == 0) sceneLighting *= pow(lightmap.y, 2.5);
#endif
#endif
#ifdef END
vec3 ambientEnd = endCol * 0.07;
vec3 lightEnd = endCol * 0.17;
vec3 shadowDecider = fullShadow;
vec3 sceneLighting = mix(ambientEnd, lightEnd, shadowDecider);
sceneLighting *= END_I * (0.7 + 0.4 * vsBrightness);
#endif
#ifdef TWO
#ifndef ABYSS
vec3 sceneLighting = vec3(0.0003, 0.0004, 0.002) * 10.0;
#else
vec3 sceneLighting = pow(fogColor, vec3(0.2)) * 0.125;
#endif
#endif
#if defined SEVEN && !defined SEVEN_2
sceneLighting = vec3(0.005, 0.006, 0.018) * 133 * (0.3 * fullShadow + 0.025);
#endif
#ifdef SEVEN_2
vec3 sceneLighting = vec3(0.005, 0.006, 0.018) * 33 * (1.0 * fullShadow + 0.025);
#endif
#if defined SEVEN || defined SEVEN_2
sceneLighting *= lightmap.y * lightmap.y;
#endif
#if defined SHADOWS && defined OVERWORLD
if (subsurface > 0.001) {
float VdotL = clamp(dot(normalize(viewPos.xyz), lightVec), 0.0, 1.0);
vec3 subsurfaceGlow = (5.5 + 8.0 * leaves) * (1.0 - fakeShadow) * shadowTime * fullShadow * pow(VdotL, 10.0);
subsurfaceGlow *= 1.0 - rainStrengthS * 0.68;
albedo.rgb += max(albedo.g * normalize(sqrt((albedo.rgb + vec3(0.001)) * lightCol)) * subsurfaceGlow, vec3(0.0));
}
#endif
#else
#ifdef NETHER
#if MC_VERSION >= 11600
if (quarterNdotU < 0.5625) quarterNdotU = 0.5625 + (0.4 - quarterNdotU * 0.7111111111111111);
#endif
#if MC_VERSION >= 11600
vec3 sceneLighting = normalize(sqrt(max(fogColor, vec3(0.001)))) * 0.0385 * NETHER_I * (vsBrightness*0.5 + 0.6);
#else
vec3 sceneLighting = normalize(netherCol) * 0.0385 * NETHER_I * (vsBrightness*0.5 + 0.6);
#endif
#else
vec3 sceneLighting = vec3(0.0);
#endif
#endif
#ifdef DYNAMIC_SHADER_LIGHT
float handLight = min(float(heldBlockLightValue2 + heldBlockLightValue), 15.0) / 15.0;
float handLightFactor = 1.0 - min(DYNAMIC_LIGHT_DISTANCE * handLight, lViewPos) / (DYNAMIC_LIGHT_DISTANCE * handLight);
#ifdef GBUFFERS_WATER
if (mat > 0.05) handLight *= 0.9;
#endif
#ifdef GBUFFERS_HAND
handLight = min(handLight, 0.95);
#endif
float finalHandLight = handLight * handLightFactor;
lightmap.x = max(finalHandLight * 0.95, lightmap.x);
#endif
float lightmapX2 = lightmap.x * lightmap.x;
float lightmapXM1 = pow2(pow2(lightmapX2)) * lightmapX2;
float lightmapXM2 = max((lightmap.x - 0.05) * 0.925, 0.0);
float newLightmap = mix(lightmapXM1 * 5.0 + lightmapXM2, lightmapXM1 * 4.0 + lightmapXM2 * 1.5, vsBrightness);
#ifdef BLOCKLIGHT_FLICKER
float frametimeM = frametime * 0.5;
float lightFlicker = min(((1 - clamp(sin(fract(frametimeM*2.7) + frametimeM*3.7) - 0.75, 0.0, 0.25) * BLOCKLIGHT_FLICKER_STRENGTH)
* max(fract(frametimeM*1.4), (1 - BLOCKLIGHT_FLICKER_STRENGTH * 0.25))) / (1.0 - BLOCKLIGHT_FLICKER_STRENGTH * 0.2)
, 0.8) * 1.25
* 0.8 + 0.2 * clamp((cos(fract(frametimeM*0.47) * fract(frametimeM*1.17) + fract(frametimeM*2.17))) * 1.5, 1.0 - BLOCKLIGHT_FLICKER_STRENGTH * 0.25, 1.0);
newLightmap *= lightFlicker;
#endif
#ifdef RANDOM_BLOCKLIGHT
float CLr = texture2D(noisetex, 0.00006 * (worldPos.xz + cameraPosition.xz)).r;
float CLg = texture2D(noisetex, 0.00009 * (worldPos.xz + cameraPosition.xz)).r;
float CLb = texture2D(noisetex, 0.00014 * (worldPos.xz + cameraPosition.xz)).r;
blocklightCol = vec3(CLr, CLg, CLb);
blocklightCol *= blocklightCol * BLOCKLIGHT_I * 2.22;
#endif
#ifdef COLORED_LIGHT
#ifdef GBUFFERS_TERRAIN
if (lightVarying > 0.5) {
if (lightVarying < 1.5) {
lightAlbedo = albedo;
}
else if (lightVarying < 2.5) {
#ifdef COMPBR
lightAlbedo = float(eyeBrightness.x < 144) * emissive * albedo;
#else
lightAlbedo = float(eyeBrightness.x < 144) * albedo;
#endif
}
else if (lightVarying < 3.5) {
lightAlbedo = vec3(0.7, 0.5, 0.2);
}
else if (lightVarying < 4.5) { // Sea Lantern, Beacon, End Rod
lightAlbedo = albedo * vec3(0.6, 0.85, 1.0);
}
else if (lightVarying < 5.5) { // Sea Pickles
lightAlbedo = vec3(0.2, 0.9, 1.0);
}
}
//if (lViewPos > 16.0) lightAlbedo = vec3(0.0);
#endif
vec3 blocklightComplex = texture2D(colortex9, texCoord).rgb;
blocklightComplex *= 0.75 + 2.0 * blocklightComplex.b;
blocklightCol = mix(blocklightCol, blocklightComplex, 0.7);
#ifdef DYNAMIC_SHADER_LIGHT
#include "/lib/ifchecks/heldColoredLighting.glsl"
#endif
#endif
vec3 blockLighting = blocklightCol * newLightmap * newLightmap;
vec3 minLighting = vec3(0.000000000001 + (MIN_LIGHT * 0.0035 * (vsBrightness*0.0775 + 0.0125)));
#ifndef MIN_LIGHT_EVERYWHERE
minLighting *= (1.0 - eBS);
#endif
#ifdef GBUFFERS_WATER
minLighting *= 2.0;
#endif
float shade = pow(quarterNdotU, SHADING_STRENGTH);
vec3 emissiveLighting = albedo.rgb * emissive * 20.0 / shade * EMISSIVE_MULTIPLIER;
float nightVisionLighting = nightVision * 0.25;
if (smoothLighting > 0.01) {
smoothLighting = clamp(smoothLighting, 0.0, 1.0);
#if VAO_STRENGTH == 10
smoothLighting *= smoothLighting;
#else
smoothLighting = pow(smoothLighting, 0.2 * VAO_STRENGTH);
#endif
} else smoothLighting = 1.0;
if (materialAO < 1.0) {
smoothLighting *= pow(materialAO, max(1.0 - shadowTime * length(shadow) * NdotL - lmCoord.x, 0.0));
}
albedo *= sceneLighting + blockLighting + emissiveLighting + nightVisionLighting + minLighting;
albedo *= shade;
albedo *= smoothLighting;
#if defined WATER_CAUSTICS && defined OVERWORLD
#if defined PROJECTED_CAUSTICS && !defined GBUFFERS_WATER
if (water > 0.0 || isEyeInWater == 1) {
#else
if ((isEyeInWater != 0 && isEyeInWater != 2 && isEyeInWater != 3)) {
// Not just doing (isEyeInWater == 1) to fix caustics appearing in shadows on AMD Mesa with Iris
#endif
vec3 albedoCaustic = albedo;
float skyLightMap = lightmap.y * lightmap.y * (3.0 - 2.0 * lightmap.y);
float skyLightMapA = pow2(pow2((1.0 - skyLightMap)));
float skyLightMapB = skyLightMap > 0.98 ? (1.0 - skyLightMap) * 50.0 : 1.0;
float causticfactor = 1.0 - lightmap.x * 0.8;
vec3 causticpos = worldPos.xyz + cameraPosition.xyz;
float caustic = getCausticWaves(causticpos);
vec3 causticcol = underwaterColor.rgb / UNDERWATER_I;
#if defined PROJECTED_CAUSTICS && !defined GBUFFERS_WATER
if (isEyeInWater == 0) {
causticfactor *= 1.0 - skyLightMapA;
causticfactor *= 10.0;
causticcol = sqrt(normalize(waterColor.rgb + vec3(0.01)) * 0.32 * sqrt(UNDERWATER_I));
#ifndef WATER_ABSORPTION
albedoCaustic = albedo.rgb * causticcol * 3.0;
causticcol *= 0.53;
#else
albedoCaustic = albedo.rgb * water * 1.74;
causticcol = sqrt(causticcol) * 0.2;
#endif
} else {
#endif
causticfactor *= shadow.g * sqrt2(NdotL) * (1.0 - rainStrengthS);
causticfactor *= 0.25 - 0.15 * skyLightMapA;
causticfactor *= skyLightMapB;
albedoCaustic = (albedo.rgb + albedo.rgb * underwaterColor.rgb * 16.0) * 0.225;
#ifdef WATER_ABSORPTION
albedoCaustic *= 1.5;
#endif
albedoCaustic += albedo.rgb * underwaterColor.rgb * caustic * sqrt1(lightmap.x) * 4.0 * skyLightMapB;
causticcol = sqrt(causticcol) * 30.0;
#if defined PROJECTED_CAUSTICS && !defined GBUFFERS_WATER
}
#endif
vec3 lightcaustic = caustic * causticfactor * causticcol * UNDERWATER_I;
albedoCaustic *= 1.0 + lightcaustic;
#if defined PROJECTED_CAUSTICS && !defined GBUFFERS_WATER
if (isEyeInWater == 0) albedo = mix(albedo, albedoCaustic, max(water - rainStrengthS, 0.0));
else albedo = albedoCaustic;
#else
albedo = albedoCaustic;
#endif
}
#endif
#if defined GBUFFERS_HAND && defined HAND_BLOOM_REDUCTION
float albedoStrength = (albedo.r + albedo.g + albedo.b) / 10.0;
if (albedoStrength > 1.0) albedo.rgb = albedo.rgb * max(2.0 - albedoStrength, 0.34);
#endif
#if MC_VERSION >= 11900
albedo *= 1.0 - clamp(darknessLightFactor * (2.0 - emissive * 10000.0), 0.0, 1.0);
#endif
}

View File

@@ -0,0 +1,161 @@
//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 SchlickGGX(float NoL, float NoV, float roughness) {
float k = roughness * 0.5;
float smithL = 0.5 / (NoL * (1.0 - k) + k);
float smithV = 0.5 / (NoV * (1.0 - k) + k);
return smithL * smithV;
}
float GGX(vec3 normal, vec3 viewPos, vec3 lightVec, float smoothness, float f0, float sunSize) {
float roughness = 1.0 - smoothness;
if (roughness < 0.05) roughness = 0.05;
float roughnessP = roughness;
roughness *= roughness; roughness *= roughness;
vec3 halfVec = normalize(lightVec - viewPos);
float dotLH = clamp(dot(halfVec, lightVec), 0.0, 1.0);
float dotNL = clamp(dot(normal, lightVec), 0.0, 1.0);
float dotNV = dot(normal, -viewPos);
float dotNH = GetNoHSquared(sunSize, dotNL, dotNV, dot(-viewPos, lightVec));
float denom = dotNH * roughness - dotNH + 1.0;
float D = roughness / (3.141592653589793 * denom * denom);
float F = exp2((-5.55473 * dotLH - 6.98316) * dotLH) * (1.0 - f0) + f0;
float k2 = roughness * 0.5;
float specular = max(dotNL * dotNL * D * F / (dotLH * dotLH * (1.0 - k2) + k2), 0.0);
specular = max(specular, 0.0);
specular = specular / (0.125 * specular + 1.0);
float schlick = SchlickGGX(dotNL, dotNV, roughness);
schlick = pow(schlick * 0.5, roughnessP);
specular *= clamp(schlick, 0.0, 1.25);
if (sunVisibility == 0.0) specular *= float(moonPhase == 0) * 0.35 + 0.65 - float(moonPhase == 4) * 0.65;
else specular *= 1.5;
return specular * (1.0 - isEyeInWater*0.75);
}
float stylisedGGX(vec3 normal, vec3 oldNormal, vec3 nViewPos, vec3 lightVec, float f0) {
vec3 halfVec = normalize(lightVec - nViewPos);
float dotLH = clamp(dot(halfVec, lightVec), 0.0, 1.0);
float dotOldL = clamp(dot(oldNormal, lightVec), 0.0, 1.0);
float dotNmOL = clamp(dot(normal - oldNormal, lightVec), 0.0, 1.0);
float sunSize = 0.037;
float dotNH = GetNoHSquared(sunSize, dotOldL, dot(oldNormal, -nViewPos), dot(-nViewPos, lightVec));
dotOldL *= dotOldL;
float roughness = 0.05;
float denom = dotNH * roughness - dotNH + 1.0;
float D = roughness / (3.141592653589793 * denom * denom);
float F = exp2((-5.55473 * dotLH - 6.98316) * dotLH) * (1.0 - f0) + f0;
float k2 = roughness * 0.25;
float specular = max(dotOldL * D * F / (dotLH * dotLH * (1.0 - k2) + k2), 0.0);
specular = max(specular, 0.0);
specular = specular / (0.125 * specular + 1.0);
dotNmOL *= dotNH * dotNH;
dotNmOL *= dotNmOL * 350.0 * SUN_MOON_WATER_REF;
dotNmOL *= dotNmOL;
dotNmOL = max(dotNmOL * 0.25, sunVisibility * pow2(dotNmOL * dotNmOL));
specular *= 0.075 + 9.0 * min(dotNmOL * 6.0, 50.0);
specular *= 0.4 + 1.71 * dotOldL;
if (sunVisibility == 0.0) {
specular *= 0.25 * MOON_WATER_REF;
specular *= float(moonPhase == 0) * 0.35 + 0.65 - float(moonPhase == 4) * 0.65;
}
return max(specular * (1.0 - isEyeInWater*0.75), 0.0);
}
vec3 GetMetalCol(float f0) {
int metalidx = int(f0 * 255.0);
if (metalidx == 230) return vec3(0.24867, 0.22965, 0.21366);
if (metalidx == 231) return vec3(0.88140, 0.57256, 0.11450);
if (metalidx == 232) return vec3(0.81715, 0.82021, 0.83177);
if (metalidx == 233) return vec3(0.27446, 0.27330, 0.27357);
if (metalidx == 234) return vec3(0.84430, 0.48677, 0.22164);
if (metalidx == 235) return vec3(0.36501, 0.35675, 0.37653);
if (metalidx == 236) return vec3(0.42648, 0.37772, 0.31138);
if (metalidx == 237) return vec3(0.91830, 0.89219, 0.83662);
return vec3(1.0);
}
vec3 GetSpecularHighlight(float smoothness, float metalness, float f0, vec3 specularColor,
vec3 rawAlbedo, vec3 shadow, vec3 normal, vec3 viewPos) {
if (dot(shadow, shadow) < 0.001) return vec3(0.0);
#ifdef END
smoothness *= 0.0;
#endif
float specular = GGX(normal, normalize(viewPos), lightVec, smoothness, f0,
0.01 * sunVisibility + 0.06);
specular *= sqrt1inv(rainStrengthS);
#ifdef SHADOWS
specular *= shadowFade;
#endif
specularColor = pow(specularColor, vec3(1.0 - 0.5 * metalness));
#ifdef COMPBR
specularColor *= pow(rawAlbedo, vec3(metalness * 0.8));
#else
#if RP_SUPPORT == 3
if (metalness > 0.5) {
if (f0 < 1.0) specularColor *= GetMetalCol(f0);
else specularColor *= rawAlbedo;
}
#else
specularColor *= pow(rawAlbedo, vec3(metalness));
#endif
#endif
return specular * specularColor * shadow;
}

View File

@@ -0,0 +1,98 @@
uniform sampler2DShadow shadowtex0;
#if defined COLORED_SHADOWS && defined OVERWORLD
uniform sampler2D shadowcolor1;
#endif
#if defined PROJECTED_CAUSTICS && defined WATER_CAUSTICS && defined OVERWORLD && !defined GBUFFERS_WATER
uniform sampler2D shadowcolor0;
#endif
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));
vec2 offsetDist(float x, float s) {
float n = fract(x * 1.414) * 3.1415;
return vec2(cos(n), sin(n)) * 1.4 * x / s;
}
vec3 SampleBasicShadow(vec3 shadowPos, inout float water) {
float shadow0 = shadow2D(shadowtex0, vec3(shadowPos.st, shadowPos.z)).x;
#if (defined COLORED_SHADOWS || (defined PROJECTED_CAUSTICS && defined WATER_CAUSTICS && !defined GBUFFERS_WATER)) && defined OVERWORLD
vec3 shadowcol = vec3(0.0);
if (shadow0 < 1.0) {
float shadow1 = shadow2D(shadowtex1, vec3(shadowPos.st, shadowPos.z)).x;
if (shadow1 > 0.9999) {
#if defined COLORED_SHADOWS && defined OVERWORLD
shadowcol = texture2D(shadowcolor1, shadowPos.st).rgb * shadow1;
#endif
#if defined PROJECTED_CAUSTICS && defined WATER_CAUSTICS && defined OVERWORLD && !defined GBUFFERS_WATER
water = texture2D(shadowcolor0, shadowPos.st).r * shadow1;
#endif
}
}
return shadowcol * (1.0 - shadow0) + shadow0;
#else
return vec3(shadow0);
#endif
}
vec3 SampleFilteredShadow(vec3 shadowPos, float offset, inout float water) {
vec3 shadow = SampleBasicShadow(vec3(shadowPos.st, shadowPos.z), water) * 2.0;
for(int i = 0; i < 8; i++) {
shadow+= SampleBasicShadow(vec3(offset * 1.2 * shadowoffsets[i] + shadowPos.st, shadowPos.z), water);
}
return shadow * 0.1;
}
float InterleavedGradientNoise() {
float n = 52.9829189 * fract(0.06711056 * gl_FragCoord.x + 0.00583715 * gl_FragCoord.y);
return fract(n + 1.61803398875 * mod(float(frameCounter), 3600.0));
}
vec3 SampleTAAFilteredShadow(vec3 shadowPos, float offset, inout float water, int doSubsurface) {
float noise = InterleavedGradientNoise();
vec3 shadow = vec3(0.0);
offset = offset * (2.0 - 0.5 * (0.85 + 0.25 * (3072.0 / shadowMapResolution)));
if (shadowMapResolution < 400.0) offset *= 30.0;
#if SHADOW_SUBSURFACE < 3
int sampleCount = 2;
#else
int sampleCount = 2 + doSubsurface;
#endif
for(int i = 0; i < sampleCount; i++) {
vec2 offset = offsetDist(noise + i, sampleCount) * offset;
shadow += SampleBasicShadow(vec3(shadowPos.st + offset, shadowPos.z), water);
shadow += SampleBasicShadow(vec3(shadowPos.st - offset, shadowPos.z), water);
}
shadow /= sampleCount * 2;
return shadow;
}
vec3 GetShadow(vec3 shadowPos, float offset, inout float water, int doSubsurface) {
#ifdef SHADOW_FILTER
#if AA > 1
vec3 shadow = SampleTAAFilteredShadow(shadowPos, offset, water, doSubsurface);
#else
vec3 shadow = SampleFilteredShadow(shadowPos, offset, water);
#endif
#else
vec3 shadow = SampleBasicShadow(shadowPos, water);
#endif
return shadow;
}