feat: initial commit

This commit is contained in:
lucasdpt
2026-06-14 01:24:29 +02:00
commit 0d40f88ab2
5815 changed files with 703860 additions and 0 deletions
@@ -0,0 +1,168 @@
// The MIT License
// Copyright © 2024 Benjamin Stott "sixthsurge"
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#if !defined INCLUDE_UTILITY_COLOR
#define INCLUDE_UTILITY_COLOR
const vec3 luminanceWeightsRec709 = vec3(0.2126, 0.7152, 0.0722);
const vec3 luminanceWeightsRec2020 = vec3(0.2627, 0.6780, 0.0593);
const vec3 luminanceWeightsAp1 = vec3(0.2722, 0.6741, 0.0537);
#define luminance_weights luminance_weights_rec2020
const vec3 primaryWavelengthsRec709 = vec3(660.0, 550.0, 440.0);
const vec3 primaryWavelengthsRec2020 = vec3(660.0, 550.0, 440.0);
const vec3 primaryWavelengthsAp1 = vec3(630.0, 530.0, 465.0);
#define primary_wavelengths primary_wavelengths_rec2020
// -----------------------------------
// Color space conversion matrices
// -----------------------------------
#define display_to_working_color rec709_to_rec2020
#define working_to_display_color rec2020_to_rec709
#define rec709_to_working_color rec709_to_rec2020
// Helper macro to convert sRGB colors to working space
#define from_srgb(x) (pow(x, vec3(2.2)) * rec709_to_rec2020)
// Rec. 709 (sRGB primaries)
const mat3 xyzToRec709 = mat3(
3.2406, -1.5372, -0.4986,
-0.9689, 1.8758, 0.0415,
0.0557, -0.2040, 1.0570
);
const mat3 rec709ToXyz = mat3(
0.4124, 0.3576, 0.1805,
0.2126, 0.7152, 0.0722,
0.0193, 0.1192, 0.9505
);
// Rec. 2020 (working color space)
const mat3 xyzToRec2020 = mat3(
1.7166084, -0.3556621, -0.2533601,
-0.6666829, 1.6164776, 0.0157685,
0.0176422, -0.0427763, 0.94222867
);
const mat3 rec2020ToXyz = mat3(
0.6369736, 0.1446172, 0.1688585,
0.2627066, 0.6779996, 0.0592938,
0.0000000, 0.0280728, 1.0608437
);
const mat3 rec709ToRec2020 = rec709ToXyz * xyzToRec2020;
const mat3 rec2020ToRec709 = rec2020ToXyz * xyzToRec709;
// ------------------------------
// Transfer functions (gamma)
// ------------------------------
#define display_eotf srgb_eotf
#define display_eotf_inv srgb_eotf_inv
vec3 srgbEotf(vec3 linear) { // linear -> sRGB
return 1.14374 * (-0.126893 * linear + sqrt(linear)); // from Jodie in #snippets
}
vec3 srgbEotfInv(vec3 srgb) { // sRGB -> linear
return srgb * (srgb * (srgb * 0.305306011 + 0.682171111) + 0.012522878); // https://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
}
// ---------------------------------------------------------------
// Transformations between RGB and other color representations
// ---------------------------------------------------------------
// from https://gist.github.com/983/e170a24ae8eba2cd174f
vec3 rgbToHsl(vec3 c) {
const vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1e-6;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hslToRgb(vec3 c) {
const vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
c.yz = clamp01(c.yz);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp01(p - K.xxx), c.y);
}
// from https://en.wikipedia.org/wiki/YCoCg#Conversion_with_the_RGB_color_model
vec3 rgbToYcocg(vec3 rgb) {
const mat3 cm = mat3(
0.25, 0.5, 0.25,
0.5, 0.0, -0.5,
-0.25, 0.5, -0.25
);
return rgb * cm;
}
vec3 ycocgToRgb(vec3 ycocg) {
float tmp = ycocg.x - ycocg.z;
return vec3(tmp + ycocg.y, ycocg.x + ycocg.z, tmp - ycocg.y);
}
// Original source: https://github.com/Jessie-LC/open-source-utility-code/blob/main/advanced/blackbody.glsl
vec3 blackbody(float temperature) {
const vec3 lambda = primaryWavelengthsAp1;
const vec3 lambda2 = lambda * lambda;
const vec3 lambda5 = lambda2 * lambda2 * lambda;
const float h = 6.63e-16; // Planck constant
const float k = 1.38e-5; // Boltzmann constant
const float c = 3.0e17; // Speed of light
const vec3 a = lambda5 / (2.0 * h * c * c);
const vec3 b = (h * c) / (k * lambda);
vec3 d = exp(b / temperature);
vec3 rgb = a * d - a;
return minOf(rgb) / rgb;
}
// Isolate a range of hues
float isolateHue(vec3 hsl, float center, float width) {
if (hsl.y < 1e-2 || hsl.z < 1e-2) return 0.0; // black/gray colors with no hue
return pulse(hsl.x * 360.0, center, width, 360.0);
}
// OKLab color space conversion
// https://bottosson.github.io/posts/oklab/
// MIT License (MIT) Copyright (c) 2020 Björn Ottosson
const mat3 RGB2OKLAB_A = mat3(
0.2104542553, 1.9779984951, 0.0259040371,
0.7936177850, -2.4285922050, 0.7827717662,
-0.0040720468, 0.4505937099, -0.8086757660);
const mat3 RGB2OKLAB_B = mat3(
0.4122214708, 0.2119034982, 0.0883024619,
0.5363325363, 0.6806995451, 0.2817188376,
0.0514459929, 0.1073969566, 0.6299787005);
const mat3 OKLAB2RGB_A = mat3(
1.0, 1.0, 1.0,
0.3963377774, -0.1055613458, -0.0894841775,
0.2158037573, -0.0638541728, -1.2914855480);
const mat3 OKLAB2RGB_B = mat3(
4.0767416621, -1.2684380046, -0.0041960863,
-3.3077115913, 2.6097574011, -0.7034186147,
0.2309699292, -0.3413193965, 1.7076147010);
vec3 rgb2oklab(vec3 rgb) {
vec3 lms = RGB2OKLAB_B * rgb;
return RGB2OKLAB_A * (sign(lms) * pow(abs(lms), vec3(0.3333333333333)));
}
vec3 oklab2rgb(vec3 oklab) {
vec3 lms = OKLAB2RGB_A * oklab;
return OKLAB2RGB_B * (lms * lms * lms);
}
#endif // INCLUDE_UTILITY_COLOR
@@ -0,0 +1,750 @@
#ifdef VERTEX_SHADER
vec2 GetLightMapCoordinates() {
vec2 lmCoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).xy;
return clamp((lmCoord - 0.03125) * 1.06667, 0.0, 1.0);
}
vec3 GetSunVector() {
const vec2 sunRotationData = vec2(cos(sunPathRotation * 0.01745329251994), -sin(sunPathRotation * 0.01745329251994));
#ifdef OVERWORLD
float ang = fract(timeAngle - 0.25);
ang = (ang + (cos(ang * 3.14159265358979) * -0.5 + 0.5 - ang) / 3.0) * 6.28318530717959;
return normalize((gbufferModelView * vec4(vec3(-sin(ang), cos(ang) * sunRotationData) * 2000.0, 1.0)).xyz);
#elif defined END
float ang = 0.0;
return normalize((gbufferModelView * vec4(vec3(0.0, sunRotationData * 2000.0), 1.0)).xyz);
#else
return vec3(0.0);
#endif
}
#endif
float Noise3D(vec3 p) {
p.z = fract(p.z) * 128.0;
float iz = floor(p.z);
float fz = fract(p.z);
vec2 a_off = vec2(23.0, 29.0) * (iz) / 128.0;
vec2 b_off = vec2(23.0, 29.0) * (iz + 1.0) / 128.0;
float a = texture2DLod(noisetex, p.xy + a_off, 0.0).r;
float b = texture2DLod(noisetex, p.xy + b_off, 0.0).r;
return mix(a, b, fz);
}
float GetSkyLightFactor(vec2 lmCoordM, vec3 shadowMult) {
#ifdef OVERWORLD
#if WORLD_SPACE_REFLECTIONS_INTERNAL == -1
float skyLightFactor = max(lmCoordM.y - 0.7, 0.0) * 3.33333;
skyLightFactor *= skyLightFactor;
#else
float skyLightFactor = lmCoordM.y;
#endif
#if defined GBUFFERS_WATER || defined DH_WATER
#if SHADOW_QUALITY > -1 && WATER_REFLECT_QUALITY >= 2 && WATER_MAT_QUALITY >= 2
skyLightFactor = max(skyLightFactor, dot(shadowMult, shadowMult) * 0.333333);
#endif
#endif
#else
#if WORLD_SPACE_REFLECTIONS_INTERNAL == -1 || MC_VERSION < 12109
float skyLightFactor = dot(shadowMult, shadowMult) * 0.333333;
#else
float skyLightFactor = lmCoordM.y;
#endif
#endif
return skyLightFactor;
}
int min1(int x) {
return min(x, 1);
}
float min1(float x) {
return min(x, 1.0);
}
int max0(int x) {
return max(x, 0);
}
float max0(float x) {
return max(x, 0.0);
}
vec2 max0(vec2 x) {
return max(x, vec2(0.0));
}
vec3 max0(vec3 x) {
return max(x, vec3(0.0));
}
vec4 max0(vec4 x) {
return max(x, vec4(0.0));
}
float maxAll(vec2 x) {
return max(x.x, x.y);
}
float maxAll(vec3 x) {
return max(x.x, max(x.y, x.z));
}
float maxAll(vec4 x) {
return max(x.x, max(x.y, max(x.z, x.w)));
}
int clamp01(int x) {
return clamp(x, 0, 1);
}
float clamp01(float x) {
return clamp(x, 0.0, 1.0);
}
vec2 clamp01(vec2 x) {
return clamp(x, vec2(0.0), vec2(1.0));
}
vec3 clamp01(vec3 x) {
return clamp(x, vec3(0.0), vec3(1.0));
}
vec4 clamp01(vec4 x) {
return clamp(x, vec4(0.0), vec4(1.0));
}
int pow2(int x) {
return x * x;
}
float pow2(float x) {
return x * x;
}
vec2 pow2(vec2 x) {
return x * x;
}
vec3 pow2(vec3 x) {
return x * x;
}
vec4 pow2(vec4 x) {
return x * x;
}
int pow3(int x) {
return pow2(x) * x;
}
float pow3(float x) {
return pow2(x) * x;
}
vec2 pow3(vec2 x) {
return pow2(x) * x;
}
vec3 pow3(vec3 x) {
return pow2(x) * x;
}
vec4 pow3(vec4 x) {
return pow2(x) * x;
}
int pow4(int x) {
return pow2(x) * pow2(x);
}
float pow4(float x) {
return pow2(x) * pow2(x);
}
vec2 pow4(vec2 x) {
return pow2(x) * pow2(x);
}
vec3 pow4(vec3 x) {
return pow2(x) * pow2(x);
}
vec4 pow4(vec4 x) {
return pow2(x) * pow2(x);
}
int pow5(int x) {
return pow3(x) * pow2(x);
}
float pow5(float x) {
return pow3(x) * pow2(x);
}
vec2 pow5(vec2 x) {
return pow3(x) * pow2(x);
}
vec3 pow5(vec3 x) {
return pow3(x) * pow2(x);
}
vec4 pow5(vec4 x) {
return pow3(x) * pow2(x);
}
int pow6(int x) {
return pow3(x) * pow3(x);
}
float pow6(float x) {
return pow3(x) * pow3(x);
}
vec2 pow6(vec2 x) {
return pow3(x) * pow3(x);
}
vec3 pow6(vec3 x) {
return pow3(x) * pow3(x);
}
vec4 pow6(vec4 x) {
return pow3(x) * pow3(x);
}
float pow1_5(float x) { // Faster pow(x, 1.5) approximation (that isn't accurate at all) if x is between 0 and 1
return x - x * pow2(1.0 - x); // Thanks to SixthSurge
}
vec2 pow1_5(vec2 x) {
return x - x * pow2(1.0 - x);
}
vec3 pow1_5(vec3 x) {
return x - x * pow2(1.0 - x);
}
vec4 pow1_5(vec4 x) {
return x - x * pow2(1.0 - x);
}
float sqrt1(float x) { // Faster sqrt() approximation (that isn't accurate at all) if x is between 0 and 1
return x * (2.0 - x); // Thanks to Builderb0y
}
vec2 sqrt1(vec2 x) {
return x * (2.0 - x);
}
vec3 sqrt1(vec3 x) {
return x * (2.0 - x);
}
vec4 sqrt1(vec4 x) {
return x * (2.0 - x);
}
float sqrt2(float x) {
x = 1.0 - x;
x *= x;
x *= x;
return 1.0 - x;
}
vec2 sqrt2(vec2 x) {
x = 1.0 - x;
x *= x;
x *= x;
return 1.0 - x;
}
vec3 sqrt2(vec3 x) {
x = 1.0 - x;
x *= x;
x *= x;
return 1.0 - x;
}
vec4 sqrt2(vec4 x) {
x = 1.0 - x;
x *= x;
x *= x;
return 1.0 - x;
}
float sqrt3(float x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec2 sqrt3(vec2 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec3 sqrt3(vec3 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec4 sqrt3(vec4 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
float sqrt4(float x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec2 sqrt4(vec2 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec3 sqrt4(vec3 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec4 sqrt4(vec4 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
float smoothstep1(float x) {
return x * x * (3.0 - 2.0 * x);
}
vec2 smoothstep1(vec2 x) {
return x * x * (3.0 - 2.0 * x);
}
vec3 smoothstep1(vec3 x) {
return x * x * (3.0 - 2.0 * x);
}
vec4 smoothstep1(vec4 x) {
return x * x * (3.0 - 2.0 * x);
}
float dot3(vec3 x) {
return dot(x, x);
}
#define rcp(x) (1.0 / (x))
float maxOf(vec2 v) { return max(v.x, v.y); }
float maxOf(vec3 v) { return max(v.x, max(v.y, v.z)); }
float maxOf(vec4 v) { return max(v.x, max(v.y, max(v.z, v.w))); }
float minOf(vec2 v) { return min(v.x, v.y); }
float minOf(vec3 v) { return min(v.x, min(v.y, v.z)); }
float minOf(vec4 v) { return min(v.x, min(v.y, min(v.z, v.w))); }
// Smoothing function used by smoothstep
// Zero derivative at zero and one
float cubic_smooth(float x) {
return pow2(x) * (3.0 - 2.0 * x);
}
// Remaps center +/- 0.5 * width to zero and center to 1, with the same smoothing function as
// smoothstep
float pulse(float x, float center, float width) {
x = abs(x - center) / width;
return x > 1.0 ? 0.0 : 1.0 - cubic_smooth(x);
}
float pulse(float x, float center, float width, const float period) {
x = (x - center + 0.5 * period) / period;
x = fract(x) * period - (0.5 * period);
return pulse(x, 0.0, width);
}
float GetLuminance(vec3 color) {
return dot(color, vec3(0.299, 0.587, 0.114));
}
vec3 DoLuminanceCorrection(vec3 color) {
return color / GetLuminance(color);
}
float GetBiasFactor(float NdotLM) {
float NdotLM2 = NdotLM * NdotLM;
return 1.25 * (1.0 - NdotLM2 * NdotLM2) / NdotLM;
}
float GetHorizonFactor(float XdotU) {
#ifdef SUN_MOON_HORIZON
float horizon = clamp((XdotU + 0.1) * 10.0, 0.0, 1.0);
horizon *= horizon;
return horizon * horizon * (3.0 - 2.0 * horizon);
#else
#ifdef CELESTIAL_BOTH_HEMISPHERES
return 1.0;
#endif
float horizon = min(XdotU + 1.0, 1.0);
horizon *= horizon;
horizon *= horizon;
return horizon * horizon;
#endif
}
bool CheckForColor(vec3 albedo, vec3 check) { // Thanks to Builderb0y
vec3 dif = albedo - check * 0.003921568;
return dif == clamp(dif, vec3(-0.001), vec3(0.001));
}
bool CheckForStick(vec3 albedo) {
return CheckForColor(albedo, vec3(40, 30, 11)) ||
CheckForColor(albedo, vec3(73, 54, 21)) ||
CheckForColor(albedo, vec3(104, 78, 30)) ||
CheckForColor(albedo, vec3(137, 103, 39));
}
float GetMaxColorDif(vec3 color) {
vec3 dif = abs(vec3(color.r - color.g, color.g - color.b, color.r - color.b));
return max(dif.r, max(dif.g, dif.b));
}
vec3 RgbFrom256(int r, int g, int b) {
return vec3(float(r)/256.0 ,float(g)/256.0 ,float(b)/256.0);
}
// Inspired by Inigo Quilez
// https://iquilezles.org/articles/palettes/
vec3 getRainbowColor(vec2 coord, float speed) {
const vec3 rainbowColor = vec3(0.0, pi * 0.67, pi * 1.33);
float t = frameTimeCounter * speed;
t += sin(t) * (coord.x) + cos(t) * coord.y;
return vec3(0.5) + vec3(0.5) * sin(rainbowColor + t);
}
vec3 saturateColors(vec3 col, float saturationMult) {
if (saturationMult == 1.0) return col;
float brightness = maxAll(col);
return (col - brightness) * saturationMult + brightness;
}
float fuzzyOr(float a, float b) {
return clamp01(a + b - (a * b));
}
float getBloodMoon(float sunVisibility) {
float visibility = 0.0;
#if BLOOD_MOON == 0
return visibility;
#else
visibility = 1.0 - sunVisibility;
// BLOOD_MOON defines how many nights between blood moons
// 1 = every night, 2 = every other night, 5 = every 5th night, etc.
if ((worldDay % BLOOD_MOON) != 0) visibility = 0.0;
#if BLOOD_MOON > 1
visibility *= float(min(worldDay, 1)); // no blood moon on day 0
if (moonPhase == 4) visibility = 0.0; // no blood moon on new moon
#endif
#endif
return clamp01(visibility);
}
bool isViewMoving() {
if (cameraPosition == previousCameraPosition) {
mat3 previousModelView = mat3(gbufferPreviousModelView);
mat3 currentModelView = mat3(gbufferModelView);
for (int i = 0; i < 3; i++) {
if(!all(lessThan(abs(previousModelView[i] - currentModelView[i]), vec3(0.001)))) return true;
}
return false;
}
return true;
}
vec3 changeColorFunction(vec3 color, float strength, vec3 changeColor, float uniformValue) {
float luminanceColor = GetLuminance(color);
color = mix(color, mix(color, vec3(luminanceColor), 0.88), uniformValue);
return color *= mix(vec3(1.0), changeColor * luminanceColor * strength, uniformValue);
}
float isLightningActive() {
float lightning = 0.0;
#if defined IS_IRIS || defined IS_ANGELICA
lightning = lightningBoltPosition.w;
#else
lightning = lightningFlashOptifine * rainFactor * inRainy;
#endif
return lightning;
}
vec3 getLightningPos(vec3 playerPos, vec3 lightningBoltPosition, bool pointLight) {
vec3 lightningPos = vec3(0.0);
if (pointLight){
lightningPos = lightningBoltPosition - playerPos;
} else {
// i like to offset the y of lightningBoltPosition to be ~100 blocks higher to give the effect of the light coming off the entire bolt, not just the point it hits.
lightningPos = vec3(lightningBoltPosition.x, max(playerPos.y, lightningBoltPosition.y) + 2, lightningBoltPosition.z) - playerPos ;
}
return lightningPos;
}
vec2 lightningFlashEffect(vec3 lightningPos, vec3 normal, float lightDistance, float gradient, int subsurfaceMode) { // Thanks to Xonk!
// point light, max distance is ~500 blocks (the maximum entity render distance), change lightDistance to change the reach
float lightningLight = max(1.0 - length(lightningPos) / lightDistance, 0.0);
// the light above ^^^ is a linear curve. me no likey. here's an exponential one instead.
float lightningLightX = exp((1.0 - lightningLight) * -15.0);
float lightningLightY = lightningLightX;
if (subsurfaceMode == 1) lightningLightX *= exp((1.0 - lightningLightX) * -1.0) * 0.75; // make grass and others not as intense
// good old NdotL
// float NdotL = clamp(dot(lightningPos, -normal), 0.0, 1.0);
float NdotL = clamp01(dot(normalize(lightningPos), normal));
if (gradient > 0.0) NdotL = (NdotL * (1.0 - gradient)) + gradient;
return vec2(lightningLightX * NdotL, lightningLightY);
}
void redstoneIPBR(inout vec3 color, inout float emission) {
#ifdef REDSTONE_IPBR
if (color.r * REDSTONE_IPBR_R > max(color.b * 1.15 * REDSTONE_IPBR_B, color.g * 3.5 * REDSTONE_IPBR_G) * 0.97) {
emission = (4.5 - 2.25 * color.g) * 0.97 * REDSTONE_IPBR_I;
color.rgb *= color.rgb;
}
#endif
}
float getTwinklingStars(vec2 coord, float speed){
return clamp01((texture2DLod(noisetex, coord + frameTimeCounter * 0.0003 * speed, 0.0).r - 0.5) * 10.0 + 0.5);
}
float GetStarNoise(vec2 pos) {
return fract(sin(dot(pos, vec2(12.9898, 4.1414))) * 43758.54953);
}
float getStarEdgeFactor(vec2 fractPart, float starShape, float softness) {
vec2 squareToCircle = fractPart - 0.5;
float distFromCenter = length(squareToCircle);
float maxComponent = max(abs(squareToCircle.x), abs(squareToCircle.y));
// Interpolate between square and circle
float shapeFactor = mix(maxComponent, distFromCenter, starShape);
// Adjust the edge transition
float edgeWidth = 0.05 + softness * 0.5;
return smoothstep(0.5, 0.5 - edgeWidth, shapeFactor);
}
vec3 GetStarColor(vec2 starCoord, vec3 baseColor, vec3 starColor1, vec3 starColor2, vec3 starColor3, float starColorVariation) {
if (starColorVariation > 0.0) {
int starColorDecider = int(mod((starCoord.x + starCoord.y) * 1000.0, 3.0));
vec3 chosenColor = (starColorDecider == 0) ? starColor1 :
(starColorDecider == 1) ? starColor2 : starColor3;
baseColor = mix(chosenColor, vec3(GetStarNoise(starCoord)), (1.0 - starColorVariation) * 0.5);
}
return baseColor;
}
vec3 movingCheckerboard(vec2 texCoord, float gridSize, float lineWidth, vec2 moveSpeed, vec3 lineColor) {
vec2 checkerPixel = fract((texCoord + frameTimeCounter * moveSpeed) * viewSize / gridSize);
vec2 lineThreshold = vec2(lineWidth / gridSize);
if (any(lessThan(checkerPixel, lineThreshold)) || any(greaterThan(checkerPixel, 1.0 - lineThreshold))) {
return lineColor;
}
return vec3(0.0);
}
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
vec3 hex2rgb(uint hex) {
return vec3(
float((hex >> 16) & 0xFFu) / 255.0,
float((hex >> 8) & 0xFFu) / 255.0,
float(hex & 0xFFu) / 255.0
);
}
mat2 rotate(float angle)
{
float s = sin(angle), c = cos(angle);
return mat2(c, -s, s, c);
}
float DoAutomaticEmission(inout bool noSmoothLighting, inout bool noDirectionalShading, vec3 color, float lmCoord, int blockLightEmission, float minEmission){
noSmoothLighting = true, noDirectionalShading = true;
float lightLevel = max(float(lmCoord > 0.99), blockLightEmission / 15.0);
float baseEmission = pow3(GetLuminance(color)) * pow1_5(lightLevel);
return max(minEmission, (baseEmission - 0.1) * 2.5);
}
float getDHFadeFactor(vec3 playerPosition) {
float horizontalDistance = length(playerPosition.xz);
float verticalDistance = abs(playerPosition.y);
float fadeTransitionLength = (far - near) * RENDER_EDGE_FADE_TRANSITION_PERCENT;
fadeTransitionLength = max(fadeTransitionLength, 1.0);
float fadeStartPoint = far - fadeTransitionLength;
fadeStartPoint = max(near + 0.01 * (far - near), fadeStartPoint);
if (fadeStartPoint >= far) {
fadeStartPoint = far - max(0.001 * (far - near), 0.1);
}
float horizontalFade = smoothstep(far, fadeStartPoint, horizontalDistance);
float verticalFade = smoothstep(far, fadeStartPoint, verticalDistance);
return min(horizontalFade, verticalFade);
}
vec2 causticOffsetDist(float x, int s) {
float n = fract(x * 2.427) * 3.1415;
return vec2(cos(n), sin(n)) * 2.0 * x / float(s) / 256.0;
}
float hash1(uint n) {
// The MIT License
// Copyright © 2017 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// integer hash copied from Hugo Elias
n = (n << 13U) ^ n;
n = n * (n * n * 15731U + 789221U) + 1376312589U;
return float( n & uint(0x7fffffffU))/float(0x7fffffff);
}
float hash1(const in int p) {return hash1(uint(p));}
float hash11Modified(float a, float s)
{
return fract(53.156*sin(a*45.45 + s))-.5;
}
#define UI0 1597334673U
#define UI1 3812015801U
#define UI3 uvec3(UI0, UI1, 2798796415U)
#define UIF (1.0 / float(0xffffffffU))
vec3 hash33(const in uvec3 p) {
uvec3 q = p * UI3;
q = (q.x ^ q.y ^ q.z) * UI3;
return -1.0 + 2.0 * vec3(q) * UIF;
}
vec3 hash33(const in vec3 p) {return hash33(uvec3(p));}
// Hash Without Sine from https://www.shadertoy.com/view/4djSRW
// The MIT License
// Copyright (c)2014 David Hoskins.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// 1 out, 1 in...
float hash11(float p)
{
p = fract(p * .1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
// 1 out, 4 in
float hash14(vec4 p4)
{
p4 = fract(p4 * vec4(.1031, .1030, .0973, .1099));
p4 += dot(p4, p4.wzxy+33.33);
return fract((p4.x + p4.y) * (p4.z + p4.w));
}
// 2 out, 2 in...
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx+33.33);
return fract((p3.xx+p3.yz)*p3.zy);
}
// 1 out, 2 in...
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
// 1 out, 3 in...
float hash13(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
// 2 out, 1 in...
vec2 hash21(float p) {
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx+p3.yz)*p3.zy);
}
// 3 out, 1 in...
vec3 hash31(float p) {
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx+33.33);
return fract((p3.xxy+p3.yzz)*p3.zyx);
}
// 3 out, 2 in...
vec3 hash32(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yxz+33.33);
return fract((p3.xxy+p3.yzz)*p3.zyx);
}
// by David Hoskins
// https://www.shadertoy.com/view/XdGfRR
// CC-BY-SA 4.0 license:
// https://creativecommons.org/licenses/by-sa/4.0/
// 2 out, 3 in
vec2 hash23(vec3 p) {
uvec3 q = uvec3(ivec3(p)) * uvec3(1597334673u, 3812015801u, 2798796415u);
uvec2 n = (q.x ^ q.y ^ q.z) * uvec2(1597334673u, 3812015801u);
return vec2(n) / float(0xffffffffu);
}
// 1 out, 2 in... Simplex noise functions are (C) Ashima Arts and Stefan Gustavson
float smoothHash12(vec2 x) {
vec2 p = floor(x);
vec2 f = fract(x);
f = f * f * (3.0 - 2.0 * f);
vec2 a = vec2(1.0, 0.0);
return mix(mix(hash12(p + a.yy), hash12(p + a.xy), f.x), mix(hash12(p + a.yx), hash12(p + a.xx), f.x), f.y);
}
float getThunderstormCloudHighlights(vec3 tracePos, vec2 cameraPos, float lTracePos, float minPlaneDistance, float maxPlaneDistance, float distanceFalloff) {
if (thunderFactor == 0.0) return 0.0;
float eventTime = frameTimeCounter * 3;
float eventPeriod = 8.0; // seconds between possible events
float eventPhase = mod(eventTime, eventPeriod);
float eventSeed = floor(eventTime / eventPeriod);
float eventTrigger = hash11(eventSeed);
bool highlightActive = (eventPhase < 6.5) && (eventTrigger > 0.77);
if (!highlightActive) return 0.0;
float highlightBoost = 0.0;
float positionTime = floor(frameTimeCounter * 2.0) * 0.5;
for (int h = 0; h < 4; h++) {
float posSeed = float(h) * 24.0 + positionTime * 0.007;
vec2 highlightOffset = (hash21(posSeed) - 0.5) * 1600.0;
vec2 highlightPos = cameraPos + highlightOffset * 1.2;
float dist = length(tracePos.xz - highlightPos);
float flickerSeed = frameTimeCounter * 28.0 + float(h) * 2.5;
float flickerNoise = hash11(flickerSeed * 0.1) * 0.6 + 0.55; // add subtle randomness
float fade = smoothstep(0.0, 1.0, sin(flickerSeed) * 0.5 + 0.5) * flickerNoise;
float falloff = exp(-dist * distanceFalloff) * fade;
float shadowMix = mix(1.0, (lTracePos - minPlaneDistance) / (maxPlaneDistance - minPlaneDistance), 0.85);
highlightBoost += falloff * shadowMix * 0.5 * thunderFactor;
}
return highlightBoost;
}
@@ -0,0 +1,6 @@
#ifndef INCLUDE_DFDX_DFDY
#define INCLUDE_DFDX_DFDY
vec2 dcdx = dFdx(texCoord.xy);
vec2 dcdy = dFdy(texCoord.xy);
#endif
@@ -0,0 +1,13 @@
#ifndef INCLUDE_DITHER
#define INCLUDE_DITHER
// Thanks to Jessie for dithering
float Bayer2 (vec2 c) { c = 0.5 * floor(c); return fract(1.5 * fract(c.y) + c.x); }
float Bayer4 (vec2 c) { return 0.25 * Bayer2 (0.5 * c) + Bayer2(c); }
float Bayer8 (vec2 c) { return 0.25 * Bayer4 (0.5 * c) + Bayer2(c); }
float Bayer16 (vec2 c) { return 0.25 * Bayer8 (0.5 * c) + Bayer2(c); }
float Bayer32 (vec2 c) { return 0.25 * Bayer16 (0.5 * c) + Bayer2(c); }
float Bayer64 (vec2 c) { return 0.25 * Bayer32 (0.5 * c) + Bayer2(c); }
float Bayer128(vec2 c) { return 0.25 * Bayer64 (0.5 * c) + Bayer2(c); }
float Bayer256(vec2 c) { return 0.25 * Bayer128(0.5 * c) + Bayer2(c); }
#endif
@@ -0,0 +1,15 @@
vec2 midCoordPos = absMidCoordPos * signMidCoordPos;
#include "/lib/util/dFdxdFdy.glsl"
vec2 mipx = dcdx / absMidCoordPos * 8.0;
vec2 mipy = dcdy / absMidCoordPos * 8.0;
float mipDelta = max(dot(mipx, mipx), dot(mipy, mipy));
float miplevel = max(0.5 * log2(mipDelta), 0.0);
#if !defined GBUFFERS_ENTITIES && !defined GBUFFERS_HAND
vec2 atlasSizeM = atlasSize;
#else
vec2 atlasSizeM = atlasSize.x + atlasSize.y > 0.5 ? atlasSize : textureSize(tex, 0);
#endif
@@ -0,0 +1,47 @@
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 ScreenToView(vec3 pos) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x,
gbufferProjectionInverse[1].y,
gbufferProjectionInverse[2].zw);
vec3 p3 = pos * 2.0 - 1.0;
vec4 viewPos = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return viewPos.xyz / viewPos.w;
}
vec3 ViewToPlayer(vec3 pos) {
return mat3(gbufferModelViewInverse) * pos + gbufferModelViewInverse[3].xyz;
}
vec3 PlayerToShadow(vec3 pos) {
vec3 shadowpos = mat3(shadowModelView) * pos + shadowModelView[3].xyz;
return projMAD(shadowProjection, shadowpos);
}
vec3 ShadowClipToShadowView(vec3 pos) {
return mat3(shadowProjectionInverse) * pos;
}
vec3 ShadowViewToPlayer(vec3 pos) {
return mat3(shadowModelViewInverse) * pos;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
#ifdef DISTANT_HORIZONS
vec3 ScreenToViewDH(vec3 pos) {
vec4 iProjDiag = vec4(dhProjectionInverse[0].x,
dhProjectionInverse[1].y,
dhProjectionInverse[2].zw);
vec3 p3 = pos * 2.0 - 1.0;
vec4 viewPos = iProjDiag * p3.xyzz + dhProjectionInverse[3];
return viewPos.xyz / viewPos.w;
}
#endif