custommods

This commit is contained in:
samsonsin
2025-05-29 23:31:29 +02:00
parent 90b3575aea
commit 9d577eb52d
800 changed files with 19540 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
void AutoGenerateNormals(inout vec4 normalMap, vec3 albedoP, float delta) {
float packSizeGN = 128.0;
float lOriginalAlbedo = length(albedoP);
float normalMult = max(1.0 - delta, 0.0) * 1.8 * sqrt(NORMAL_MULTIPLIER);
float normalClamp = 0.05;
#ifndef SAFE_GENERATED_NORMALS
vec2 offsetR = 16.0 / atlasSize;
#else
vec2 offsetR = max(vTexCoordAM.z, vTexCoordAM.w) * vec2(float(atlasSize.y) / float(atlasSize.x), 1.0);
#endif
offsetR /= packSizeGN;
vec2 midCoord = texCoord - vTexCoordL / 2.0;
vec2 vTexCoordAM_M = vTexCoordAM.zw * (0.5 - 0.5 / packSizeGN);
if (normalMult > 0.0) {
for(int i = 0; i < 4; i++) {
vec2 offsetCoord;
if (i == 0) {
offsetCoord = texCoord + vec2( 0.0, offsetR.y);
if (offsetCoord.y > midCoord.y + vTexCoordAM_M.y) continue;
} else if (i == 1) {
offsetCoord = texCoord + vec2( offsetR.x, 0.0);
if (offsetCoord.x > midCoord.x + vTexCoordAM_M.x) continue;
} else if (i == 2) {
offsetCoord = texCoord + vec2( 0.0,-offsetR.y);
if (offsetCoord.y < midCoord.y - vTexCoordAM_M.y) continue;
} else if (i == 3) {
offsetCoord = texCoord + vec2(-offsetR.x, 0.0);
if (offsetCoord.x < midCoord.x - vTexCoordAM_M.x) continue;
}
float lNearbyAlbedo = length(texture2D(texture, offsetCoord).rgb);
float dif = lOriginalAlbedo - lNearbyAlbedo;
if (dif > 0.0) dif = max(dif - normalClamp, 0.0);
else dif = min(dif + normalClamp, 0.0);
dif *= normalMult;
if (i == 0)
normalMap.y += dif;
else if (i == 1)
normalMap.x += dif;
else if (i == 2)
normalMap.y -= dif;
else if (i == 3)
normalMap.x -= dif;
}
}
}

View File

@@ -0,0 +1,23 @@
mat3 GetLightmapTBN(vec3 viewPos) {
mat3 lightmapTBN = mat3(normalize(dFdx(viewPos)), normalize(dFdy(viewPos)), vec3(0.0));
lightmapTBN[2] = cross(lightmapTBN[0], lightmapTBN[1]);
return lightmapTBN;
}
float DirectionalLightmap(float lightmap, float lightmapRaw, vec3 normal, mat3 lightmapTBN) {
if (lightmap < 0.001) return lightmap;
vec2 deriv = vec2(dFdx(lightmapRaw), dFdy(lightmapRaw)) * 256.0;
vec3 dir = normalize(vec3(deriv.x * lightmapTBN[0] +
0.0005 * lightmapTBN[2] +
deriv.y * lightmapTBN[1]));
float pwr = clamp(dot(normal, dir), -1.0, 1.0);
if (abs(pwr) > 0.0)
pwr = pow(abs(pwr), 9.0 / DIRECTIONAL_LIGHTMAP_STRENGTH) * sign(pwr) * lightmap;
if (length(deriv) > 0.001)
lightmap = pow(lightmap, 1.0 - pwr);
return lightmap;
}

View File

@@ -0,0 +1,30 @@
void GetMaterials(out float smoothness, out float metalness, out float f0,
out vec3 normal, out vec3 rawAlbedo, vec2 coord) {
vec2 specularData = texture2D(colortex3, coord).rg;
smoothness = specularData.r;
#ifdef COMPBR
if (smoothness < 0.5) {
smoothness /= 0.5;
f0 = 1.0;
}
else {
smoothness = (smoothness - 0.5) / 0.5;
f0 = 4.0;
}
metalness = specularData.g;
#else
#if RP_SUPPORT == 3
f0 = specularData.g;
metalness = f0 >= 0.9 ? 1.0 : 0.0;
#else
metalness = specularData.g;
f0 = 0.78 * metalness + 0.02;
#endif
#endif
normal = DecodeNormal(texture2D(colortex6, coord).xy);
rawAlbedo = texture2D(colortex1, coord).rgb;
}

View File

@@ -0,0 +1,70 @@
void GetMaterials(out float smoothness, out float metalness, out float f0, out float metalData,
inout float emissive, out float materialAO, out vec4 normalMap,
vec2 newCoord, vec2 dcdx, vec2 dcdy) {
#ifdef MC_SPECULAR_MAP
#ifdef WRONG_MIPMAP_FIX
vec4 specularMap = texture2DLod(specular, newCoord, 0);
#else
vec4 specularMap = texture2D(specular, newCoord);
#endif
#else
vec4 specularMap = vec4(0.0, 0.0, 0.0, 1.0);
#endif
#ifdef NORMAL_MAPPING
normalMap = textureGrad(normals, newCoord, dcdx, dcdy).rgba;
normalMap.xyz += vec3(0.5, 0.5, 0.0);
normalMap.xyz = pow(normalMap.xyz, vec3(NORMAL_MULTIPLIER));
normalMap.xyz -= vec3(0.5, 0.5, 0.0);
#endif
#if RP_SUPPORT == 4
smoothness = specularMap.r;
metalness = specularMap.g;
f0 = 0.78 * metalness + 0.02;
metalData = metalness;
materialAO = 1.0;
float materialEmissive = specularMap.b;
#ifdef NORMAL_MAPPING
normalMap.xyz = normalMap.xyz * 2.0 - 1.0;
#endif
#else
smoothness = specularMap.r;
f0 = specularMap.g;
metalness = f0 >= 0.9 ? 1.0 : 0.0;
metalData = f0;
#ifdef NORMAL_MAPPING
materialAO = normalMap.z;
#else
materialAO = texture2D(normals, newCoord).z;
#endif
materialAO *= materialAO;
float materialEmissive = specularMap.a < 1.0 ? specularMap.a : 0.0;
#ifdef NORMAL_MAPPING
normalMap.xyz = normalMap.xyz * 2.0 - 1.0;
float normalCheck = normalMap.x + normalMap.y;
if (normalCheck > -1.999) {
if (length(normalMap.xy) > 1.0) normalMap.xy = normalize(normalMap.xy);
normalMap.z = sqrt(1.0 - dot(normalMap.xy, normalMap.xy));
normalMap.xyz = normalize(clamp(normalMap.xyz, vec3(-1.0), vec3(1.0)));
} else {
normalMap.xyz = vec3(0.0, 0.0, 1.0);
materialAO = 1.0;
}
#endif
#endif
materialEmissive = pow(materialEmissive, 2.5 + 2.0 * materialEmissive);
emissive = mix(materialEmissive, 1.0, emissive);
materialAO = clamp(materialAO, 0.01, 1.0);
}

View File

@@ -0,0 +1,27 @@
void NoiseCoatTextures(inout vec4 albedo, inout float smoothness, inout float emissive, inout float metalness, vec3 worldPos, float miplevel, float noiseVaryingM, float snowFactor) {
float packSizeNT = 64.0;
#ifndef SAFE_GENERATED_NORMALS
vec2 noiseCoord = floor(vTexCoordL.xy / 32.0 * packSizeNT * atlasSize) / packSizeNT / 12.0;
#else
vec2 offsetR = max(vTexCoordAM.z, vTexCoordAM.w) * vec2(float(atlasSize.y) / float(atlasSize.x), 1.0);
vec2 noiseCoord = floor(vTexCoordL.xy / 2.0 * packSizeNT / offsetR) / packSizeNT / 12.0;
#endif
if (noiseVaryingM < 999.0) {
noiseCoord += 0.21 * (floor((worldPos.xz + cameraPosition.xz) + 0.001) + floor((worldPos.y + cameraPosition.y) + 0.001));
} else {
noiseVaryingM -= 1000.0;
}
float noiseTexture = texture2D(noisetex, noiseCoord).r;
noiseTexture = noiseTexture * 0.75 + 0.625;
float colorBrightness = 0.2126 * albedo.r + 0.7152 * albedo.g + 0.0722 * albedo.b;
float noiseFactor = 0.7 * sqrt(1.0 - colorBrightness) * (1.0 - 0.5 * metalness)
* (1.0 - 0.25 * smoothness) * max(1.0 - emissive, 0.0);
#if defined SNOW_MODE && defined OVERWORLD
noiseFactor *= 2.0 * max(0.5 - snowFactor, 0.0);
#endif
noiseFactor *= noiseVaryingM;
noiseFactor *= max(1.0 - miplevel * 0.25, 0.0);
noiseTexture = pow(noiseTexture, noiseFactor);
albedo.rgb *= noiseTexture;
smoothness = min(smoothness * sqrt(2.0 - noiseTexture), 1.0);
}

View File

@@ -0,0 +1,77 @@
vec4 ReadNormal(vec2 coord) {
coord = fract(coord) * vTexCoordAM.pq + vTexCoordAM.st;
return textureGrad(normals, coord, dcdx, dcdy);
}
void GetParallaxCoord(float parallaxFade, inout vec2 newCoord, inout float parallaxDepth) {
vec2 coord = vTexCoord.st;
float invParallaxQuality = 1.0 / PARALLAX_QUALITY;
if (parallaxFade < 1.0) {
vec3 normalMap = ReadNormal(vTexCoord.st).xyz * 2.0 - 1.0;
float normalCheck = normalMap.x + normalMap.y;
float minHeight = 1.0 - invParallaxQuality;
if (viewVector.z < 0.0 && ReadNormal(vTexCoord.st).a < minHeight && normalCheck > -1.999) {
float multiplier = 0.25 * (1.0 - parallaxFade) * PARALLAX_DEPTH /
(-viewVector.z * PARALLAX_QUALITY);
vec2 interval = viewVector.xy * multiplier;
#ifdef SELF_SHADOW
float lowSurface = 0.0;
#endif
for(int i = 0; i < PARALLAX_QUALITY; i++) {
float normalA = ReadNormal(coord).a;
if (normalA < 1.0 - float(i) / PARALLAX_QUALITY) {
coord += interval;
#ifdef SELF_SHADOW
parallaxDepth = normalA;
#endif
} else break;
}
newCoord = fract(coord.st) * vTexCoordAM.pq + vTexCoordAM.st;
}
}
}
float GetParallaxShadow(float parallaxFade, vec2 coord, vec3 lightVec, mat3 tbn, float parallaxDepth, float normalDepth) {
float parallaxshadow = 1.0;
float invParallaxQuality = 1.0 / PARALLAX_QUALITY;
float minHeight = 1.0 - invParallaxQuality;
if (dist < PARALLAX_DISTANCE + 32.0) {
#ifdef PARALLAX
float heightCheck = parallaxDepth;
#else
float heightCheck = normalDepth;
#endif
if (heightCheck < minHeight) {
vec3 parallaxdir = tbn * lightVec;
parallaxdir.xy *= 0.2 * SELF_SHADOW_ANGLE * PARALLAX_DEPTH;
vec2 newvTexCoord = (coord - vTexCoordAM.st) / vTexCoordAM.pq;
float step = 1.28 / PARALLAX_QUALITY;
float height = normalDepth;
#ifdef PARALLAX
int parallaxD32 = PARALLAX_QUALITY / 32;
#endif
for(int i = 0; i < PARALLAX_QUALITY / 4; i++) {
float currentHeight = height + parallaxdir.z * step * i;
vec2 parallaxCoord = fract(newvTexCoord + parallaxdir.xy * i * step) *
vTexCoordAM.pq + vTexCoordAM.st;
float offsetHeight = textureGrad(normals, parallaxCoord, dcdx, dcdy).a;
#ifdef PARALLAX
if (i == parallaxD32) height = parallaxDepth;
#endif
parallaxshadow *= clamp(1.0 - (offsetHeight - currentHeight) * 40.0, 0.0, 1.0);
if (parallaxshadow < 0.01) break;
}
parallaxshadow = mix(parallaxshadow, 1.0, parallaxFade);
}
}
return parallaxshadow;
}

View File

@@ -0,0 +1,26 @@
float GetPuddles(vec2 pos) {
float noise = texture2D(noisetex, pos).r;
noise+= texture2D(noisetex, pos * 0.5).r *2.0;
noise+= texture2D(noisetex, pos * 0.25).r *4.0;
noise+= texture2D(noisetex, pos * 0.125).r *8.0;
noise *= REFLECTION_RAIN_COVERAGE * 0.055;
noise = max((noise-15.5) * 0.8 - 1.2 , 0.0);
#ifndef RAIN_REF_FORCED
float wetnessM = wetness;
#else
float wetnessM = 1.0;
#endif
noise *= wetnessM;
noise /= sqrt(noise * noise + 1.0);
#if REFLECTION_RAIN_COVERAGE == 100
noise = mix(noise, 1.0, min(sqrt1(wetnessM) * 2.0, 1.0));
#endif
#ifdef RAIN_REF_BIOME_CHECK
noise *= isRainy;
#endif
noise = clamp((noise - 0.75) * 4.5, 0.0, 1.0);
return noise;
}