mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-23 01:02:33 +08:00
Add the whole ass shader
it has begun
This commit is contained in:
382
shaders/world1/lib/ACES.glsl
Normal file
382
shaders/world1/lib/ACES.glsl
Normal file
@ -0,0 +1,382 @@
|
||||
#define log10(x) log(x) / log(10.0)
|
||||
|
||||
struct ColorCorrection {
|
||||
float saturation;
|
||||
float vibrance;
|
||||
vec3 lum;
|
||||
float contrast;
|
||||
float contrastMidpoint;
|
||||
|
||||
vec3 gain;
|
||||
vec3 lift;
|
||||
vec3 InvGamma;
|
||||
} m;
|
||||
|
||||
|
||||
float sigmoid_shaper(float x) { // Sigmoid function in the range 0 to 1 spanning -2 to +2.
|
||||
float t = max(1.0 - abs(0.5 * x), 0.0);
|
||||
float y = 1.0 + sign(x) * (1.0 - t * t);
|
||||
|
||||
return 0.5 * y;
|
||||
}
|
||||
|
||||
float rgb_2_saturation(vec3 rgb) {
|
||||
float minrgb = min(min(rgb.r, rgb.g), rgb.b);
|
||||
float maxrgb = max(max(rgb.r, rgb.g), rgb.b);
|
||||
|
||||
return (max(maxrgb, 1e-10) - max(minrgb, 1e-10)) / max(maxrgb, 1e-2);
|
||||
}
|
||||
|
||||
float rgb_2_yc(vec3 rgb) { // Converts RGB to a luminance proxy, here called YC. YC is ~ Y + K * Chroma.
|
||||
float ycRadiusWeight = 1.75;
|
||||
float r = rgb[0]; float g = rgb[1]; float b = rgb[2];
|
||||
float chroma = sqrt(b * (b - g) + g * (g - r) + r * (r - b));
|
||||
|
||||
return (b + g + r + ycRadiusWeight * chroma) / 3.0;
|
||||
}
|
||||
|
||||
float glow_fwd(float ycIn, float glowGainIn, float glowMid) {
|
||||
float glowGainOut;
|
||||
|
||||
if (ycIn <= 2.0 / 3.0 * glowMid) {
|
||||
glowGainOut = glowGainIn;
|
||||
} else if ( ycIn >= 2.0 * glowMid) {
|
||||
glowGainOut = 0;
|
||||
} else {
|
||||
glowGainOut = glowGainIn * (glowMid / ycIn - 0.5);
|
||||
}
|
||||
|
||||
return glowGainOut;
|
||||
}
|
||||
|
||||
float rgb_2_hue(vec3 rgb) { // Returns a geometric hue angle in degrees (0-360) based on RGB values.
|
||||
float hue;
|
||||
if (rgb[0] == rgb[1] && rgb[1] == rgb[2]) { // For neutral colors, hue is undefined and the function will return a quiet NaN value.
|
||||
hue = 0;
|
||||
} else {
|
||||
hue = (180.0 / 3.1415) * atan(2.0 * rgb[0] - rgb[1] - rgb[2], sqrt(3.0) * (rgb[1] - rgb[2])); // flip due to opengl spec compared to hlsl
|
||||
}
|
||||
|
||||
if (hue < 0.0)
|
||||
hue = hue + 360.0;
|
||||
|
||||
return clamp(hue, 0.0, 360.0);
|
||||
}
|
||||
|
||||
float center_hue(float hue, float centerH) {
|
||||
float hueCentered = hue - centerH;
|
||||
|
||||
if (hueCentered < -180.0) {
|
||||
hueCentered += 360.0;
|
||||
} else if (hueCentered > 180.0) {
|
||||
hueCentered -= 360.0;
|
||||
}
|
||||
|
||||
return hueCentered;
|
||||
}
|
||||
|
||||
// Transformations between CIE XYZ tristimulus values and CIE x,y
|
||||
// chromaticity coordinates
|
||||
vec3 XYZ_2_xyY( vec3 XYZ ) {
|
||||
float divisor = max(XYZ[0] + XYZ[1] + XYZ[2], 1e-10);
|
||||
|
||||
vec3 xyY = XYZ.xyy;
|
||||
xyY.rg = XYZ.rg / divisor;
|
||||
|
||||
return xyY;
|
||||
}
|
||||
|
||||
vec3 xyY_2_XYZ(vec3 xyY) {
|
||||
vec3 XYZ = vec3(0.0);
|
||||
XYZ.r = xyY.r * xyY.b / max(xyY.g, 1e-10);
|
||||
XYZ.g = xyY.b;
|
||||
XYZ.b = (1.0 - xyY.r - xyY.g) * xyY.b / max(xyY.g, 1e-10);
|
||||
|
||||
return XYZ;
|
||||
}
|
||||
|
||||
mat3 ChromaticAdaptation( vec2 src_xy, vec2 dst_xy ) {
|
||||
// Von Kries chromatic adaptation
|
||||
|
||||
// Bradford
|
||||
const mat3 ConeResponse = mat3(
|
||||
vec3(0.8951, 0.2664, -0.1614),
|
||||
vec3(-0.7502, 1.7135, 0.0367),
|
||||
vec3(0.0389, -0.0685, 1.0296)
|
||||
);
|
||||
const mat3 InvConeResponse = mat3(
|
||||
vec3(0.9869929, -0.1470543, 0.1599627),
|
||||
vec3(0.4323053, 0.5183603, 0.0492912),
|
||||
vec3(-0.0085287, 0.0400428, 0.9684867)
|
||||
);
|
||||
|
||||
vec3 src_XYZ = xyY_2_XYZ( vec3( src_xy, 1 ) );
|
||||
vec3 dst_XYZ = xyY_2_XYZ( vec3( dst_xy, 1 ) );
|
||||
|
||||
vec3 src_coneResp = src_XYZ * ConeResponse;
|
||||
vec3 dst_coneResp = dst_XYZ * ConeResponse;
|
||||
|
||||
mat3 VonKriesMat = mat3(
|
||||
vec3(dst_coneResp[0] / src_coneResp[0], 0.0, 0.0),
|
||||
vec3(0.0, dst_coneResp[1] / src_coneResp[1], 0.0),
|
||||
vec3(0.0, 0.0, dst_coneResp[2] / src_coneResp[2])
|
||||
);
|
||||
|
||||
return (ConeResponse * VonKriesMat) * InvConeResponse;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
- Color CorrectionUE4 Style
|
||||
******************************************************************************/
|
||||
|
||||
// Accurate for 1000K < Temp < 15000K
|
||||
// [Krystek 1985, "An algorithm to calculate correlated colour temperature"]
|
||||
vec2 PlanckianLocusChromaticity(float Temp) {
|
||||
float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp );
|
||||
float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp );
|
||||
|
||||
float x = 3.0*u / ( 2.0*u - 8.0*v + 4.0 );
|
||||
float y = 2.0*v / ( 2.0*u - 8.0*v + 4.0 );
|
||||
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
vec2 D_IlluminantChromaticity(float Temp) {
|
||||
// Accurate for 4000K < Temp < 25000K
|
||||
// in: correlated color temperature
|
||||
// out: CIE 1931 chromaticity
|
||||
// Correct for revision of Plank's law
|
||||
// This makes 6500 == D65
|
||||
Temp *= 1.4388 / 1.438;
|
||||
|
||||
float x = Temp <= 7000 ?
|
||||
0.244063 + ( 0.09911e3 + ( 2.9678e6 - 4.6070e9 / Temp ) / Temp ) / Temp :
|
||||
0.237040 + ( 0.24748e3 + ( 1.9018e6 - 2.0064e9 / Temp ) / Temp ) / Temp;
|
||||
|
||||
float y = -3 * x*x + 2.87 * x - 0.275;
|
||||
|
||||
return vec2(x,y);
|
||||
}
|
||||
|
||||
vec2 PlanckianIsothermal( float Temp, float Tint ) {
|
||||
float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp );
|
||||
float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp );
|
||||
|
||||
float ud = ( -1.13758118e9f - 1.91615621e6f * Temp - 1.53177f * Temp*Temp ) / pow( 1.41213984e6f + 1189.62f * Temp + Temp*Temp, 2.0 );
|
||||
float vd = ( 1.97471536e9f - 705674.0f * Temp - 308.607f * Temp*Temp ) / pow( 6.19363586e6f - 179.456f * Temp + Temp*Temp , 2.0); //don't pow2 this
|
||||
|
||||
vec2 uvd = normalize( vec2( u, v ) );
|
||||
|
||||
// Correlated color temperature is meaningful within +/- 0.05
|
||||
u += -uvd.y * Tint * 0.05;
|
||||
v += uvd.x * Tint * 0.05;
|
||||
|
||||
float x = 3*u / ( 2*u - 8*v + 4 );
|
||||
float y = 2*v / ( 2*u - 8*v + 4 );
|
||||
|
||||
return vec2(x,y);
|
||||
}
|
||||
|
||||
vec3 WhiteBalance(vec3 LinearColor) {
|
||||
const float WhiteTemp = float(WHITE_BALANCE);
|
||||
const float WhiteTint = 0.0;
|
||||
vec2 SrcWhiteDaylight = D_IlluminantChromaticity( WhiteTemp );
|
||||
vec2 SrcWhitePlankian = PlanckianLocusChromaticity( WhiteTemp );
|
||||
|
||||
vec2 SrcWhite = WhiteTemp < 4000 ? SrcWhitePlankian : SrcWhiteDaylight;
|
||||
const vec2 D65White = vec2(0.31270, 0.32900);
|
||||
|
||||
// Offset along isotherm
|
||||
vec2 Isothermal = PlanckianIsothermal( WhiteTemp, WhiteTint ) - SrcWhitePlankian;
|
||||
SrcWhite += Isothermal;
|
||||
|
||||
mat3x3 WhiteBalanceMat = ChromaticAdaptation( SrcWhite, D65White );
|
||||
WhiteBalanceMat = (sRGB_2_XYZ_MAT * WhiteBalanceMat) * XYZ_2_sRGB_MAT;
|
||||
|
||||
return LinearColor * WhiteBalanceMat * 1.0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
- ACES Fimic Curve Approx.
|
||||
******************************************************************************/
|
||||
|
||||
// ACES settings
|
||||
const float FilmSlope = Film_Slope; //0.90
|
||||
const float FilmToe = Film_Toe; //0.55
|
||||
const float FilmShoulder = Film_Shoulder; //0.25
|
||||
const float FilmBlackClip = Black_Clip;
|
||||
const float FilmWhiteClip = White_Clip;
|
||||
const float BlueCorrection = Blue_Correction;
|
||||
const float ExpandGamut = Gamut_Expansion;
|
||||
|
||||
vec3 FilmToneMap(vec3 LinearColor) {
|
||||
const mat3 AP0_2_sRGB = (AP0_2_XYZ_MAT * D60_2_D65_CAT) * XYZ_2_sRGB_MAT;
|
||||
const mat3 AP1_2_sRGB = (AP1_2_XYZ_MAT * D60_2_D65_CAT) * XYZ_2_sRGB_MAT;
|
||||
|
||||
const mat3 AP0_2_AP1 = AP0_2_XYZ_MAT * XYZ_2_AP1_MAT;
|
||||
const mat3 AP1_2_AP0 = AP1_2_XYZ_MAT * XYZ_2_AP0_MAT;
|
||||
|
||||
vec3 ColorAP1 = LinearColor * AP0_2_AP1;
|
||||
float LumaAP1 = dot( ColorAP1, AP1_RGB2Y );
|
||||
|
||||
vec3 ChromaAP1 = ColorAP1 / LumaAP1;
|
||||
|
||||
float ChromaDistSqr = dot( ChromaAP1 - 1, ChromaAP1 - 1 );
|
||||
float ExpandAmount = ( 1 - exp2( -4 * ChromaDistSqr ) ) * ( 1 - exp2( -4 * ExpandGamut * LumaAP1*LumaAP1 ) );
|
||||
|
||||
const mat3 Wide_2_XYZ_MAT = mat3(
|
||||
vec3(0.5441691, 0.2395926, 0.1666943),
|
||||
vec3(0.2394656, 0.7021530, 0.0583814),
|
||||
vec3(-0.0023439, 0.0361834, 1.0552183)
|
||||
);
|
||||
|
||||
const mat3 Wide_2_AP1 = Wide_2_XYZ_MAT * XYZ_2_AP1_MAT;
|
||||
const mat3 ExpandMat = AP1_2_sRGB * Wide_2_AP1;
|
||||
|
||||
vec3 ColorExpand = ColorAP1 * ExpandMat;
|
||||
ColorAP1 = mix(ColorAP1, ColorExpand, ExpandAmount);
|
||||
|
||||
const mat3 BlueCorrect = mat3(
|
||||
vec3(0.9404372683, -0.0183068787, 0.0778696104),
|
||||
vec3(0.0083786969, 0.8286599939, 0.1629613092),
|
||||
vec3(0.0005471261, -0.0008833746, 1.0003362486)
|
||||
);
|
||||
const mat3 BlueCorrectInv = mat3(
|
||||
vec3(1.06318, 0.0233956, -0.0865726),
|
||||
vec3(-0.0106337, 1.20632, -0.19569),
|
||||
vec3(-0.000590887, 0.00105248, 0.999538)
|
||||
);
|
||||
|
||||
const mat3 BlueCorrectAP1 = (AP1_2_AP0 * BlueCorrect) * AP0_2_AP1;
|
||||
const mat3 BlueCorrectInvAP1 = (AP1_2_AP0 * BlueCorrectInv) * AP0_2_AP1;
|
||||
|
||||
// Blue correction
|
||||
ColorAP1 = mix(ColorAP1, ColorAP1 * BlueCorrectAP1, BlueCorrection);
|
||||
|
||||
vec3 ColorAP0 = LinearColor * AP1_2_AP0;
|
||||
|
||||
// "Glow" module constants
|
||||
const float RRT_GLOW_GAIN = 0.05;
|
||||
const float RRT_GLOW_MID = 0.08;
|
||||
|
||||
float saturation = rgb_2_saturation(ColorAP0);
|
||||
float ycIn = rgb_2_yc(ColorAP0);
|
||||
float s = sigmoid_shaper((saturation - 0.4) * 5.0);
|
||||
float addedGlow = 1.0 + glow_fwd(ycIn, RRT_GLOW_GAIN * s, RRT_GLOW_MID) * 3;
|
||||
ColorAP0 *= addedGlow;
|
||||
|
||||
// --- Red modifier --- //
|
||||
const float RRT_RED_SCALE = 0.99;
|
||||
const float RRT_RED_PIVOT = 0.22;
|
||||
const float RRT_RED_HUE = 0.15;
|
||||
const float RRT_RED_WIDTH = 135.0;
|
||||
float hue = rgb_2_hue(ColorAP0);
|
||||
float centeredHue = center_hue(hue, RRT_RED_HUE);
|
||||
float hueWeight = pow(smoothstep(0.0, 1.0, 1.0 - abs(2.0 * centeredHue / RRT_RED_WIDTH)), 2.0);
|
||||
|
||||
ColorAP0.r += hueWeight * saturation * (RRT_RED_PIVOT - ColorAP0.r) * (1.0 - RRT_RED_SCALE);
|
||||
|
||||
// Use ACEScg primaries as working space
|
||||
vec3 WorkingColor = ColorAP0 * AP0_2_AP1_MAT * 1.2;
|
||||
WorkingColor = max(vec3(0.0), WorkingColor) * 1.1;
|
||||
WorkingColor = mix(vec3(dot(WorkingColor, AP1_RGB2Y)), WorkingColor, 0.96); // Pre desaturate
|
||||
|
||||
const float ToeScale = 1.0 + FilmBlackClip - FilmToe;
|
||||
const float ShoulderScale = 1.0 + FilmWhiteClip - FilmShoulder;
|
||||
|
||||
const float InMatch = in_Match;
|
||||
const float OutMatch = Out_Match;
|
||||
|
||||
float ToeMatch = 0.0;
|
||||
if(FilmToe > 0.8) {
|
||||
// 0.18 will be on straight segment
|
||||
ToeMatch = (1.0 - FilmToe - OutMatch) / FilmSlope + log10(InMatch);
|
||||
} else {
|
||||
// 0.18 will be on toe segment
|
||||
// Solve for ToeMatch such that input of InMatch gives output of OutMatch.
|
||||
const float bt = (OutMatch + FilmBlackClip) / ToeScale - 1.0;
|
||||
ToeMatch = log10(InMatch) - 0.5 * log((1.0 + bt) / (1.0 - bt)) * (ToeScale / FilmSlope);
|
||||
}
|
||||
|
||||
float StraightMatch = (1.0 - FilmToe) / FilmSlope - ToeMatch;
|
||||
float ShoulderMatch = FilmShoulder / FilmSlope - StraightMatch;
|
||||
|
||||
vec3 LogColor = log10(WorkingColor);
|
||||
vec3 StraightColor = FilmSlope * (LogColor + StraightMatch);
|
||||
|
||||
vec3 ToeColor = (-FilmBlackClip) + (2.0 * ToeScale) / (1.0 + exp((-2.0 * FilmSlope / ToeScale) * (LogColor - ToeMatch)));
|
||||
vec3 ShoulderColor = (1.0 + FilmWhiteClip) - (2.0 * ShoulderScale) / (1.0 + exp(( 2.0 * FilmSlope / ShoulderScale) * (LogColor - ShoulderMatch)));
|
||||
|
||||
for(int i = 0; i < 1; ++i) {
|
||||
ToeColor[i] = LogColor[i] < ToeMatch ? ToeColor[i] : StraightColor[i];
|
||||
ShoulderColor[i] = LogColor[i] > ShoulderMatch ? ShoulderColor[i] : StraightColor[i];
|
||||
}
|
||||
|
||||
vec3 t = clamp((LogColor - ToeMatch) / (ShoulderMatch - ToeMatch), 0.0, 1.0);
|
||||
t = ShoulderMatch < ToeMatch ? 1.0 - t : t;
|
||||
t = (3.0 - 2.0 * t) * t * t;
|
||||
|
||||
vec3 ToneColor = mix(ToeColor, ShoulderColor, t);
|
||||
ToneColor = mix(vec3(dot(ToneColor, AP1_RGB2Y)), ToneColor, 0.93); // Post desaturate
|
||||
|
||||
ToneColor = mix(ToneColor, ToneColor * BlueCorrectInvAP1, BlueCorrection);
|
||||
|
||||
// Returning positive AP1 values
|
||||
return max(vec3(0.0), ToneColor * AP1_2_sRGB);
|
||||
}
|
||||
|
||||
vec3 Saturation(vec3 color, ColorCorrection m) {
|
||||
float grey = dot(color, m.lum);
|
||||
return grey + m.saturation * (color - grey);
|
||||
}
|
||||
|
||||
vec3 Vibrance(vec3 color, ColorCorrection m) {
|
||||
float maxColor = max(color.r, max(color.g, color.b));
|
||||
float minColor = min(color.r, min(color.g, color.b));
|
||||
|
||||
float colorSaturation = maxColor - minColor;
|
||||
|
||||
float grey = dot(color, m.lum);
|
||||
color = mix(vec3(grey), color, 1.0 + m.vibrance * (1.0 - sign(m.vibrance) * colorSaturation));
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 LiftGammaGain(vec3 v, ColorCorrection m) {
|
||||
vec3 lerpV = clamp(pow(v, m.InvGamma), 0.0, 1.0);
|
||||
return m.gain * lerpV + m.lift * (1.0 - lerpV);
|
||||
}
|
||||
|
||||
float LogContrast(float x, const float eps, float logMidpoint, float contrast) {
|
||||
float logX = log2(x + eps);
|
||||
float adjX = (logX - logMidpoint) / contrast + logMidpoint;
|
||||
|
||||
return max(exp2(adjX) - eps, 0.0);
|
||||
}
|
||||
|
||||
vec3 Contrast(vec3 color, ColorCorrection m) {
|
||||
const float contrastEpsilon = 1e-5;
|
||||
|
||||
vec3 ret;
|
||||
ret.x = LogContrast(color.x, contrastEpsilon, log2(0.18), m.contrast);
|
||||
ret.y = LogContrast(color.y, contrastEpsilon, log2(0.18), m.contrast);
|
||||
ret.z = LogContrast(color.z, contrastEpsilon, log2(0.18), m.contrast);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
vec3 srgbToLinear(vec3 srgb) {
|
||||
return mix(
|
||||
srgb * 0.07739938080495356, // 1.0 / 12.92 = ~0.07739938080495356
|
||||
pow(0.947867 * srgb + 0.0521327, vec3(2.4)),
|
||||
step(0.04045, srgb)
|
||||
);
|
||||
}
|
||||
|
||||
vec3 linearToSrgb(vec3 linear) {
|
||||
return mix(
|
||||
linear * 12.92,
|
||||
pow(linear, vec3(0.416666666667)) * 1.055 - 0.055, // 1.0 / 2.4 = ~0.416666666667
|
||||
step(0.0031308, linear)
|
||||
);
|
||||
}
|
115
shaders/world1/lib/ACESSPL.glsl
Normal file
115
shaders/world1/lib/ACESSPL.glsl
Normal file
@ -0,0 +1,115 @@
|
||||
#define log10(x) log(x) / log(10.0)
|
||||
|
||||
|
||||
struct SegmentedSplineParams_c5 {
|
||||
float coefsLow[6]; // coefs for B-spline between minPoint and midPoint (units of log luminance)
|
||||
float coefsHigh[6]; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
|
||||
vec2 minPoint; // {luminance, luminance} linear extension below this
|
||||
vec2 midPoint; // {luminance, luminance}
|
||||
vec2 maxPoint; // {luminance, luminance} linear extension above this
|
||||
float slopeLow; // log-log slope of low linear extension
|
||||
float slopeHigh; // log-log slope of high linear extension
|
||||
};
|
||||
|
||||
struct SegmentedSplineParams_c9 {
|
||||
float coefsLow[10]; // coefs for B-spline between minPoint and midPoint (units of log luminance)
|
||||
float coefsHigh[10]; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
|
||||
float slopeLow; // log-log slope of low linear extension
|
||||
float slopeHigh; // log-log slope of high linear extension
|
||||
};
|
||||
|
||||
const mat3 M = mat3(
|
||||
0.5, -1.0, 0.5,
|
||||
-1.0, 1.0, 0.5,
|
||||
0.5, 0.0, 0.0
|
||||
);
|
||||
|
||||
float segmented_spline_c5_fwd(float x) {
|
||||
const SegmentedSplineParams_c5 C = SegmentedSplineParams_c5(
|
||||
float[6] ( -4.0000000000, -4.0000000000, -3.1573765773, -0.4852499958, 1.8477324706, 1.8477324706 ),
|
||||
float[6] ( -0.7185482425, 2.0810307172, 3.6681241237, 4.0000000000, 4.0000000000, 4.0000000000 ),
|
||||
vec2(0.18*exp2(-15.0), 0.0001),
|
||||
vec2(0.18, 4.8),
|
||||
vec2(0.18*exp2(18.0), 10000.),
|
||||
0.0,
|
||||
0.0
|
||||
);
|
||||
|
||||
const int N_KNOTS_LOW = 4;
|
||||
const int N_KNOTS_HIGH = 4;
|
||||
|
||||
// Check for negatives or zero before taking the log. If negative or zero,
|
||||
// set to ACESMIN.1
|
||||
float xCheck = x <= 0 ? exp2(-14.0) : x;
|
||||
|
||||
float logx = log10( xCheck);
|
||||
float logy;
|
||||
|
||||
if (logx <= log10(C.minPoint.x)) {
|
||||
logy = logx * C.slopeLow + (log10(C.minPoint.y) - C.slopeLow * log10(C.minPoint.x));
|
||||
} else if ((logx > log10(C.minPoint.x)) && (logx < log10(C.midPoint.x))) {
|
||||
float knot_coord = (N_KNOTS_LOW-1) * (logx-log10(C.minPoint.x))/(log10(C.midPoint.x)-log10(C.minPoint.x));
|
||||
int j = int(knot_coord);
|
||||
float t = knot_coord - float(j);
|
||||
|
||||
vec3 cf = vec3( C.coefsLow[ j], C.coefsLow[ j + 1], C.coefsLow[ j + 2]);
|
||||
|
||||
vec3 monomials = vec3(t * t, t, 1.0);
|
||||
logy = dot( monomials, M * cf);
|
||||
} else if ((logx >= log10(C.midPoint.x)) && (logx < log10(C.maxPoint.x))) {
|
||||
float knot_coord = (N_KNOTS_HIGH - 1) * (logx - log10(C.midPoint.x)) / (log10(C.maxPoint.x) - log10(C.midPoint.x));
|
||||
int j = int(knot_coord);
|
||||
float t = knot_coord - float(j);
|
||||
|
||||
vec3 cf = vec3(C.coefsHigh[j], C.coefsHigh[j + 1], C.coefsHigh[j + 2]);
|
||||
vec3 monomials = vec3(t * t, t, 1.0);
|
||||
|
||||
logy = dot(monomials, M * cf);
|
||||
} else {
|
||||
logy = logx * C.slopeHigh + (log10(C.maxPoint.y) - C.slopeHigh * log10(C.maxPoint.x));
|
||||
}
|
||||
|
||||
return pow(10.0, logy);
|
||||
}
|
||||
|
||||
float segmented_spline_c9_fwd( float x, const SegmentedSplineParams_c9 C, const mat3x2 toningPoints) {
|
||||
const int N_KNOTS_LOW = 8;
|
||||
const int N_KNOTS_HIGH = 8;
|
||||
|
||||
// Check for negatives or zero before taking the log. If negative or zero,
|
||||
// set to OCESMIN.
|
||||
float xCheck = x <= 0 ? 1e-4 : x;
|
||||
|
||||
vec2 minPoint = toningPoints[0];
|
||||
vec2 midPoint = toningPoints[1];
|
||||
vec2 maxPoint = toningPoints[2];
|
||||
|
||||
float logx = log10(xCheck);
|
||||
float logy;
|
||||
|
||||
if (logx <= log10(minPoint.x)) {
|
||||
logy = logx * C.slopeLow + (log10(minPoint.y) - C.slopeLow * log10(minPoint.x));
|
||||
} else if ((logx > log10(minPoint.x)) && (logx < log10(midPoint.x))) {
|
||||
float knot_coord = (N_KNOTS_LOW - 1) * (logx - log10(minPoint.x)) / (log10(midPoint.x) - log10(minPoint.x));
|
||||
int j = int(knot_coord);
|
||||
float t = knot_coord - float(j);
|
||||
|
||||
vec3 cf = vec3(C.coefsLow[j], C.coefsLow[j + 1], C.coefsLow[j + 2]);
|
||||
vec3 monomials = vec3(t * t, t, 1.0);
|
||||
|
||||
logy = dot(monomials, M * cf);
|
||||
} else if ((logx >= log10(midPoint.x)) && (logx < log10(maxPoint.x))) {
|
||||
float knot_coord = (N_KNOTS_HIGH - 1) * (logx - log10(midPoint.x)) / (log10(maxPoint.x) - log10(midPoint.x));
|
||||
int j = int(knot_coord);
|
||||
float t = knot_coord - float(j);
|
||||
|
||||
vec3 cf = vec3(C.coefsHigh[j], C.coefsHigh[j + 1], C.coefsHigh[j + 2]);
|
||||
vec3 monomials = vec3(t * t, t, 1.0);
|
||||
|
||||
logy = dot(monomials, M * cf);
|
||||
} else {
|
||||
logy = logx * C.slopeHigh + (log10(maxPoint.y) - C.slopeHigh * log10(maxPoint.x));
|
||||
}
|
||||
|
||||
return pow(10.0, logy);
|
||||
}
|
63
shaders/world1/lib/ACEST.glsl
Normal file
63
shaders/world1/lib/ACEST.glsl
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
const mat3 sRGB_2_XYZ_MAT = mat3( // Linear sRGB to XYZ color space
|
||||
vec3(0.4124564, 0.3575761, 0.1804375),
|
||||
vec3(0.2126729, 0.7151522, 0.0721750),
|
||||
vec3(0.0193339, 0.1191920, 0.9503041)
|
||||
);
|
||||
|
||||
const mat3 XYZ_2_sRGB_MAT = mat3( //XYZ to linear sRGB Color Space
|
||||
vec3(3.2409699419, -1.5373831776, -0.4986107603),
|
||||
vec3(-0.9692436363, 1.8759675015, 0.0415550574),
|
||||
vec3(0.0556300797, -0.2039769589, 1.0569715142)
|
||||
);
|
||||
|
||||
const mat3 D65_2_D60_CAT = mat3( // D65 to D60 White Point
|
||||
vec3(1.01303, 0.00610531, -0.014971),
|
||||
vec3(0.00769823, 0.998165, -0.00503203),
|
||||
vec3(-0.00284131, 0.00468516, 0.924507)
|
||||
);
|
||||
|
||||
const mat3 D60_2_D65_CAT = mat3( //D60 to D65 White Point
|
||||
vec3(0.987224, -0.00611327, 0.0159533),
|
||||
vec3(-0.00759836, 1.00186, 0.00533002),
|
||||
vec3(0.00307257, -0.00509595, 1.08168)
|
||||
);
|
||||
|
||||
const mat3 XYZ_2_AP0_MAT = mat3( // XYZ to ACEScg Color Space
|
||||
vec3(1.0498110175, 0.0000000000,-0.0000974845),
|
||||
vec3(-0.4959030231, 1.3733130458, 0.0982400361),
|
||||
vec3(0.0000000000, 0.0000000000, 0.9912520182)
|
||||
);
|
||||
|
||||
const mat3 AP0_2_XYZ_MAT = mat3( // ACEScg to XYZ Color Space
|
||||
vec3(0.9525523959, 0.0000000000, 0.0000936786),
|
||||
vec3(0.3439664498, 0.7281660966,-0.0721325464),
|
||||
vec3(0.0000000000, 0.0000000000, 1.0088251844)
|
||||
);
|
||||
|
||||
const mat3 XYZ_2_AP1_MAT = mat3( // XYZ to ACEStoning Color Space
|
||||
vec3(1.6410233797, -0.3248032942, -0.2364246952),
|
||||
vec3(-0.6636628587, 1.6153315917, 0.0167563477),
|
||||
vec3(0.0117218943, -0.0082844420, 0.9883948585)
|
||||
);
|
||||
|
||||
const mat3 AP1_2_XYZ_MAT = mat3( // ACEStoning to XYZ Color Space
|
||||
vec3(0.6624541811, 0.1340042065, 0.1561876870),
|
||||
vec3(0.2722287168, 0.6740817658, 0.0536895174),
|
||||
vec3(-0.0055746495, 0.0040607335, 1.0103391003)
|
||||
);
|
||||
|
||||
const mat3 AP0_2_AP1_MAT = mat3( // ACEScg to ACEStoneing Color Space
|
||||
vec3(1.4514393161, -0.2365107469, -0.2149285693),
|
||||
vec3(-0.0765537734, 1.1762296998, -0.0996759264),
|
||||
vec3(0.0083161484, -0.0060324498, 0.9977163014)
|
||||
);
|
||||
|
||||
const mat3 AP1_2_AP0_MAT = mat3( // ACEStoning to ACEScg Color Space
|
||||
vec3(0.6954522414, 0.1406786965, 0.1638690622),
|
||||
vec3(0.0447945634, 0.8596711185, 0.0955343182),
|
||||
vec3(-0.0055258826, 0.0040252103, 1.0015006723)
|
||||
);
|
||||
|
||||
const vec3 AP1_RGB2Y = vec3(0.2722287168, 0.6740817658, 0.0536895174); // Desaturation Coeff
|
||||
const mat3 sRGB_2_AP0 = (sRGB_2_XYZ_MAT * D65_2_D60_CAT) * XYZ_2_AP0_MAT;
|
157
shaders/world1/lib/ROBOBO_sky.glsl
Normal file
157
shaders/world1/lib/ROBOBO_sky.glsl
Normal file
@ -0,0 +1,157 @@
|
||||
const float sunAngularSize = 0.533333;
|
||||
const float moonAngularSize = 0.516667;
|
||||
|
||||
//Sky coefficients and heights
|
||||
|
||||
#define airNumberDensity 2.5035422e25
|
||||
#define ozoneConcentrationPeak 8e-6
|
||||
const float ozoneNumberDensity = airNumberDensity * ozoneConcentrationPeak;
|
||||
#define ozoneCrossSection vec3(4.51103766177301e-21, 3.2854797958699e-21, 1.96774621921165e-22)
|
||||
|
||||
#define sky_planetRadius 6731e3
|
||||
|
||||
#define sky_atmosphereHeight 110e3
|
||||
#define sky_scaleHeights vec2(8.0e3, 1.2e3)
|
||||
|
||||
#define sky_mieg 0.80 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
#define sky_coefficientRayleighR 5.8 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
|
||||
#define sky_coefficientRayleighG 1.35 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
|
||||
#define sky_coefficientRayleighB 3.31 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
|
||||
|
||||
#define sky_coefficientRayleigh vec3(sky_coefficientRayleighR*1e-6, sky_coefficientRayleighG*1e-5, sky_coefficientRayleighB*1e-5)
|
||||
|
||||
|
||||
#define sky_coefficientMieR 3.0 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
|
||||
#define sky_coefficientMieG 3.0 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
|
||||
#define sky_coefficientMieB 3.0 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
|
||||
|
||||
#define sky_coefficientMie vec3(sky_coefficientMieR*1e-6, sky_coefficientMieG*1e-6, sky_coefficientMieB*1e-6) // Should be >= 2e-6
|
||||
const vec3 sky_coefficientOzone = (ozoneCrossSection * (ozoneNumberDensity * 1.e-6)); // ozone cross section * (ozone number density * (cm ^ 3))
|
||||
|
||||
const vec2 sky_inverseScaleHeights = 1.0 / sky_scaleHeights;
|
||||
const vec2 sky_scaledPlanetRadius = sky_planetRadius * sky_inverseScaleHeights;
|
||||
const float sky_atmosphereRadius = sky_planetRadius + sky_atmosphereHeight;
|
||||
const float sky_atmosphereRadiusSquared = sky_atmosphereRadius * sky_atmosphereRadius;
|
||||
|
||||
#define sky_coefficientsScattering mat2x3(sky_coefficientRayleigh, sky_coefficientMie)
|
||||
const mat3 sky_coefficientsAttenuation = mat3(sky_coefficientRayleigh, sky_coefficientMie * 1.11, sky_coefficientOzone); // commonly called the extinction coefficient
|
||||
|
||||
#define sun_illuminance 128000.0 //[10000.0 20000.0 30000.0 40000.0 50000.0 60000.0 70000.0 80000.0 90000.0 100000.0 110000.0 120000.0 130000.0 140000.0 160000.0]
|
||||
#define moon_illuminance 60.0 //[0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 1000.0 10000.0 100000.0]
|
||||
|
||||
#define sunColorR 1.0 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
#define sunColorG 0.9 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
#define sunColorB 0.81 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
|
||||
#define sunColorBase (vec3(sunColorR,sunColorG,sunColorB) * sun_illuminance)
|
||||
//#define sunColorBase blackbody(5778) * sun_illuminance
|
||||
#define moonColorR 1.0 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
#define moonColorG 0.9 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
#define moonColorB 0.81 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
|
||||
#define moonColorBase (vec3(moonColorR, moonColorG, moonColorB) * moon_illuminance ) //Fake Purkinje effect
|
||||
|
||||
float sky_rayleighPhase(float cosTheta) {
|
||||
const vec2 mul_add = vec2(0.1, 0.28) * rPI;
|
||||
return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation
|
||||
}
|
||||
|
||||
float sky_miePhase(float cosTheta, const float g) {
|
||||
float gg = g * g;
|
||||
return (gg * -0.25 + 0.25) * rPI * pow(-(2.0 * g) * cosTheta + (gg + 1.0), -1.5);
|
||||
}
|
||||
|
||||
vec2 sky_phase(float cosTheta, const float g) {
|
||||
return vec2(sky_rayleighPhase(cosTheta), sky_miePhase(cosTheta, g));
|
||||
}
|
||||
|
||||
vec3 sky_density(float centerDistance) {
|
||||
vec2 rayleighMie = exp(centerDistance * -sky_inverseScaleHeights + sky_scaledPlanetRadius);
|
||||
|
||||
// Ozone distribution curve by Sergeant Sarcasm - https://www.desmos.com/calculator/j0wozszdwa
|
||||
float ozone = exp(-max(0.0, (35000.0 - centerDistance) - sky_planetRadius) * (1.0 / 5000.0))
|
||||
* exp(-max(0.0, (centerDistance - 35000.0) - sky_planetRadius) * (1.0 / 15000.0));
|
||||
return vec3(rayleighMie, ozone);
|
||||
}
|
||||
|
||||
vec3 sky_airmass(vec3 position, vec3 direction, float rayLength, const float steps) {
|
||||
float stepSize = rayLength * (1.0 / steps);
|
||||
vec3 increment = direction * stepSize;
|
||||
position += increment * 0.5;
|
||||
|
||||
vec3 airmass = vec3(0.0);
|
||||
for (int i = 0; i < steps; ++i, position += increment) {
|
||||
airmass += sky_density(length(position));
|
||||
}
|
||||
|
||||
return airmass * stepSize;
|
||||
}
|
||||
vec3 sky_airmass(vec3 position, vec3 direction, const float steps) {
|
||||
float rayLength = dot(position, direction);
|
||||
rayLength = rayLength * rayLength + sky_atmosphereRadiusSquared - dot(position, position);
|
||||
if (rayLength < 0.0) return vec3(0.0);
|
||||
rayLength = sqrt(rayLength) - dot(position, direction);
|
||||
|
||||
return sky_airmass(position, direction, rayLength, steps);
|
||||
}
|
||||
|
||||
vec3 sky_opticalDepth(vec3 position, vec3 direction, float rayLength, const float steps) {
|
||||
return sky_coefficientsAttenuation * sky_airmass(position, direction, rayLength, steps);
|
||||
}
|
||||
vec3 sky_opticalDepth(vec3 position, vec3 direction, const float steps) {
|
||||
return sky_coefficientsAttenuation * sky_airmass(position, direction, steps);
|
||||
}
|
||||
|
||||
vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
|
||||
return exp2(-sky_opticalDepth(position, direction, steps) * rLOG2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) {
|
||||
const int jSteps = 4;
|
||||
|
||||
vec3 viewPosition = (sky_planetRadius + eyeAltitude) * upVector;
|
||||
|
||||
vec2 aid = rsi(viewPosition, viewVector, sky_atmosphereRadius);
|
||||
if (aid.y < 0.0) {transmittance = vec3(1.0); return vec3(0.0);}
|
||||
|
||||
pid = rsi(viewPosition, viewVector, sky_planetRadius * 0.998);
|
||||
bool planetIntersected = pid.y >= 0.0;
|
||||
|
||||
vec2 sd = vec2((planetIntersected && pid.x < 0.0) ? pid.y : max(aid.x, 0.0), (planetIntersected && pid.x > 0.0) ? pid.x : aid.y);
|
||||
|
||||
float stepSize = (sd.y - sd.x) * (1.0 / iSteps);
|
||||
vec3 increment = viewVector * stepSize;
|
||||
vec3 position = viewVector * sd.x + viewPosition;
|
||||
position += increment * (0.34*noise);
|
||||
vec2 phaseSun = sky_phase(dot(viewVector, sunVector ), sky_mieg);
|
||||
vec2 phaseMoon = sky_phase(dot(viewVector, moonVector), sky_mieg);
|
||||
|
||||
vec3 scatteringSun = vec3(0.0);
|
||||
vec3 scatteringMoon = vec3(0.0);
|
||||
vec3 scatteringAmbient = vec3(0.0);
|
||||
transmittance = vec3(1.0);
|
||||
|
||||
for (int i = 0; i < iSteps; ++i, position += increment) {
|
||||
vec3 density = sky_density(length(position));
|
||||
if (density.y > 1e35) break;
|
||||
vec3 stepAirmass = density * stepSize;
|
||||
vec3 stepOpticalDepth = sky_coefficientsAttenuation * stepAirmass;
|
||||
|
||||
vec3 stepTransmittance = exp2(-stepOpticalDepth * rLOG2);
|
||||
vec3 stepTransmittedFraction = clamp01((stepTransmittance - 1.0) / -stepOpticalDepth);
|
||||
vec3 stepScatteringVisible = transmittance * stepTransmittedFraction;
|
||||
|
||||
scatteringSun += sky_coefficientsScattering * (stepAirmass.xy * phaseSun ) * stepScatteringVisible * sky_transmittance(position, sunVector, jSteps);
|
||||
scatteringMoon += sky_coefficientsScattering * (stepAirmass.xy * phaseMoon) * stepScatteringVisible * sky_transmittance(position, moonVector, jSteps);
|
||||
// Nice way to fake multiple scattering.
|
||||
scatteringAmbient += sky_coefficientsScattering * stepAirmass.xy * stepScatteringVisible;
|
||||
|
||||
transmittance *= stepTransmittance;
|
||||
}
|
||||
|
||||
vec3 scattering = scatteringSun * sunColorBase + scatteringAmbient * background + scatteringMoon*moonColorBase;
|
||||
|
||||
return scattering;
|
||||
}
|
22
shaders/world1/lib/Shadow_Params.glsl
Normal file
22
shaders/world1/lib/Shadow_Params.glsl
Normal file
@ -0,0 +1,22 @@
|
||||
const float ambientOcclusionLevel = 0.3; //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
|
||||
const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 -78 -77 -76 -75 -74 -73 -72 -71 -70 -69 -68 -67 -66 -65 -64 -63 -62 -61 -60 -59 -58 -57 -56 -55 -54 -53 -52 -51 -50 -49 -48 -47 -46 -45 -44 -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33 -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 ]
|
||||
|
||||
const int shadowMapResolution = 3172; //Will probably crash at 16 384 [512 768 1024 1536 2048 3172 4096 8192 16384]
|
||||
const float shadowDistance = 150; //[32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 ] Not linear at all when shadowDistanceRenderMul is set to -1.0, 175.0 is enough for 40 render distance
|
||||
const float shadowDistanceRenderMul = -1.0; //[-1.0 1.0] Can help to increase shadow draw distance when set to -1.0, at the cost of performance
|
||||
|
||||
|
||||
const float k = 1.8;
|
||||
const float d0 = 0.04;
|
||||
const float d1 = 0.61;
|
||||
float a = exp(d0);
|
||||
float b = (exp(d1)-a)*shadowDistance/128.0;
|
||||
|
||||
vec4 BiasShadowProjection(in vec4 projectedShadowSpacePosition) {
|
||||
float distortFactor = log(length(projectedShadowSpacePosition.xy)*b+a)*k;
|
||||
projectedShadowSpacePosition.xy /= distortFactor;
|
||||
return projectedShadowSpacePosition;
|
||||
}
|
||||
float calcDistort(vec2 worldpos){
|
||||
return 1.0/(log(length(worldpos)*b+a)*k);
|
||||
}
|
16
shaders/world1/lib/clouds.glsl
Normal file
16
shaders/world1/lib/clouds.glsl
Normal file
@ -0,0 +1,16 @@
|
||||
vec3 cloud2D(vec3 fragpos,vec3 col){
|
||||
vec3 wpos = fragpos;
|
||||
float wind = frameTimeCounter/200.;
|
||||
vec2 intersection = ((2000.0-cameraPosition.y)*wpos.xz*inversesqrt(wpos.y+cameraPosition.y/512.-50./512.) + cameraPosition.xz+wind)/40000.;
|
||||
|
||||
|
||||
float phase = pow(clamp(dot(fragpos,sunVec),0.,1.),2.)*0.5+0.5;
|
||||
|
||||
float fbm = clamp((texture2D(noisetex,intersection*vec2(1.,1.5)).a + texture2D(noisetex,intersection*vec2(2.,7.)+wind*0.4).a/2.)-0.5*(1.0-rainStrength),0.,1.) ;
|
||||
|
||||
|
||||
|
||||
|
||||
return mix(col,6.*(vec3(0.9,1.2,1.5)*skyIntensityNight*0.02*(1.0-rainStrength*0.9)+17.*phase*nsunColor*skyIntensity*0.7*(1.0-rainStrength*0.9)),0.0*(fbm*fbm)*(fbm*fbm)*(fbm*clamp(wpos.y*0.9,0.,1.)));
|
||||
|
||||
}
|
46
shaders/world1/lib/color_dither.glsl
Normal file
46
shaders/world1/lib/color_dither.glsl
Normal file
@ -0,0 +1,46 @@
|
||||
//using white noise for color dithering : gives a somewhat more "filmic" look when noise is visible
|
||||
float nrand( vec2 n )
|
||||
{
|
||||
return fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
|
||||
}
|
||||
|
||||
float triangWhiteNoise( vec2 n )
|
||||
{
|
||||
|
||||
float t = fract( frameTimeCounter );
|
||||
float rnd = nrand( n + 0.07*t );
|
||||
|
||||
float center = rnd*2.0-1.0;
|
||||
rnd = center*inversesqrt(abs(center));
|
||||
rnd = max(-1.0,rnd);
|
||||
return rnd-sign(center);
|
||||
}
|
||||
|
||||
vec3 fp10Dither(vec3 color,vec2 tc01){
|
||||
float dither = triangWhiteNoise(tc01);
|
||||
const vec3 mantissaBits = vec3(6.,6.,5.);
|
||||
vec3 exponent = floor(log2(color));
|
||||
return color + dither*exp2(-mantissaBits)*exp2(exponent);
|
||||
}
|
||||
|
||||
vec3 fp16Dither(vec3 color,vec2 tc01){
|
||||
float dither = triangWhiteNoise(tc01);
|
||||
const vec3 mantissaBits = vec3(10.);
|
||||
vec3 exponent = floor(log2(color));
|
||||
return color + dither*exp2(-mantissaBits)*exp2(exponent);
|
||||
}
|
||||
|
||||
vec3 int8Dither(vec3 color,vec2 tc01){
|
||||
float dither = triangWhiteNoise(tc01);
|
||||
return color + dither*exp2(-8.0);
|
||||
}
|
||||
|
||||
vec3 int10Dither(vec3 color,vec2 tc01){
|
||||
float dither = triangWhiteNoise(tc01);
|
||||
return color + dither*exp2(-10.0);
|
||||
}
|
||||
|
||||
vec3 int16Dither(vec3 color,vec2 tc01){
|
||||
float dither = triangWhiteNoise(tc01);
|
||||
return color + dither*exp2(-16.0);
|
||||
}
|
131
shaders/world1/lib/color_transforms.glsl
Normal file
131
shaders/world1/lib/color_transforms.glsl
Normal file
@ -0,0 +1,131 @@
|
||||
//faster and actually more precise than pow 2.2
|
||||
vec3 toLinear(vec3 sRGB){
|
||||
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
|
||||
}
|
||||
|
||||
float luma(vec3 color) {
|
||||
return dot(color,vec3(0.299, 0.587, 0.114));
|
||||
}
|
||||
vec3 ToneMap_Hejl2015(in vec3 hdr)
|
||||
{
|
||||
vec4 vh = vec4(hdr*0.85, 3.0); //0
|
||||
vec4 va = (1.75 * vh) + 0.05; //0.05
|
||||
vec4 vf = ((vh * va + 0.004f) / ((vh * (va + 0.55f) + 0.0491f))) - 0.0821f+0.000633604888; //((0+0.004)/((0*(0.05+0.55)+0.0491)))-0.0821
|
||||
return vf.xyz / vf.www;
|
||||
}
|
||||
const mat3 ACESInputMat =
|
||||
mat3(0.59719, 0.35458, 0.04823,
|
||||
0.07600, 0.90834, 0.01566,
|
||||
0.02840, 0.13383, 0.83777
|
||||
);
|
||||
|
||||
// ODT_SAT => XYZ => D60_2_D65 => sRGB
|
||||
const mat3 ACESOutputMat =
|
||||
mat3( 1.60475, -0.53108, -0.07367,
|
||||
-0.10208, 1.10813, -0.00605,
|
||||
-0.00327, -0.07276, 1.07602
|
||||
);
|
||||
vec3 LinearTosRGB(in vec3 color)
|
||||
{
|
||||
vec3 x = color * 12.92f;
|
||||
vec3 y = 1.055f * pow(clamp(color,0.0,1.0), vec3(1.0f / 2.4f)) - 0.055f;
|
||||
|
||||
vec3 clr = color;
|
||||
clr.r = color.r < 0.0031308f ? x.r : y.r;
|
||||
clr.g = color.g < 0.0031308f ? x.g : y.g;
|
||||
clr.b = color.b < 0.0031308f ? x.b : y.b;
|
||||
|
||||
return clr;
|
||||
}
|
||||
vec3 HableTonemap(vec3 linearColor) {
|
||||
// A = shoulder strength
|
||||
const float A = 0.22;
|
||||
// B = linear strength
|
||||
const float B = 0.3;
|
||||
// C = linear angle
|
||||
const float C = 0.1;
|
||||
// D = toe strength
|
||||
const float D = 0.4;
|
||||
// E = toe numerator
|
||||
const float E = 0.025;
|
||||
// F = toe denominator
|
||||
const float F = 0.30;
|
||||
// Note: E / F = toe angle
|
||||
// linearWhite = linear white point value
|
||||
|
||||
vec3 x = linearColor*2.8;
|
||||
vec3 color = ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
|
||||
|
||||
const float W = 11.2;
|
||||
const float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F;
|
||||
|
||||
return color / white;
|
||||
}
|
||||
|
||||
vec3 reinhard(vec3 x){
|
||||
x *= 1.66;
|
||||
return x/(1.0+x);
|
||||
}
|
||||
vec3 ACESFilm( vec3 x )
|
||||
{
|
||||
x *= 0.23/0.267;
|
||||
float a = 2.51f;
|
||||
float b = 0.03f;
|
||||
float c = 2.43f;
|
||||
float d = 0.59f;
|
||||
float e = 0.14f;
|
||||
return (x*(a*x+b))/(x*(c*x+d)+e);
|
||||
}
|
||||
|
||||
// From https://www.shadertoy.com/view/WdjSW3
|
||||
vec3 Tonemap_Lottes(vec3 x) {
|
||||
// Lottes 2016, "Advanced Techniques and Optimization of HDR Color Pipelines"
|
||||
const float a = 1.7;
|
||||
const float d = 0.92;
|
||||
const float hdrMax = 3.0;
|
||||
const float midIn = 0.2475;
|
||||
const float midOut = 0.267;
|
||||
|
||||
// Can be precomputed
|
||||
const float b =
|
||||
(-pow(midIn, a) + pow(hdrMax, a) * midOut) /
|
||||
((pow(hdrMax, a * d) - pow(midIn, a * d)) * midOut);
|
||||
const float c =
|
||||
(pow(hdrMax, a * d) * pow(midIn, a) - pow(hdrMax, a) * pow(midIn, a * d) * midOut) /
|
||||
((pow(hdrMax, a * d) - pow(midIn, a * d)) * midOut);
|
||||
|
||||
return pow(x,vec3(a)) / (pow(x, vec3(a * d)) * b + c);
|
||||
}
|
||||
// From https://www.shadertoy.com/view/WdjSW3
|
||||
vec3 Tonemap_Uchimura(vec3 x, float P, float a, float m, float l, float c, float b) {
|
||||
// Uchimura 2017, "HDR theory and practice"
|
||||
// Math: https://www.desmos.com/calculator/gslcdxvipg
|
||||
// Source: https://www.slideshare.net/nikuque/hdr-theory-and-practicce-jp
|
||||
float l0 = ((P - m) * l) / a;
|
||||
float L0 = m - m / a;
|
||||
float L1 = m + (1.0 - m) / a;
|
||||
float S0 = m + l0;
|
||||
float S1 = m + a * l0;
|
||||
float C2 = (a * P) / (P - S1);
|
||||
float CP = -C2 / P;
|
||||
|
||||
vec3 w0 = 1.0 - smoothstep(0.0, m, x);
|
||||
vec3 w2 = step(m + l0, x);
|
||||
vec3 w1 = 1.0 - w0 - w2;
|
||||
|
||||
vec3 T = m * pow(x / m, vec3(c)) + b;
|
||||
vec3 S = P - (P - S1) * exp(CP * (x - S0));
|
||||
vec3 L = m + a * (x - m);
|
||||
|
||||
return T * w0 + L * w1 + S * w2;
|
||||
}
|
||||
|
||||
vec3 Tonemap_Uchimura(vec3 x) {
|
||||
const float P = 1.0; // max display brightness
|
||||
const float a = 1.0; // contrast
|
||||
const float m = 0.22; // linear section start
|
||||
const float l = 0.4; // linear section length
|
||||
const float c = 1.33; // black
|
||||
const float b = 0.0; // pedestal
|
||||
return Tonemap_Uchimura(x, P, a, m, l, c, b);
|
||||
}
|
78
shaders/world1/lib/composite3.fsh
Normal file
78
shaders/world1/lib/composite3.fsh
Normal file
@ -0,0 +1,78 @@
|
||||
#version 120
|
||||
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
|
||||
#extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec3 zMults;
|
||||
uniform sampler2D depthtex0;
|
||||
uniform sampler2D colortex3;
|
||||
uniform sampler2D colortex2;
|
||||
uniform sampler2D colortex0;
|
||||
|
||||
uniform int frameCounter;
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
uniform int isEyeInWater;
|
||||
|
||||
uniform vec2 texelSize;
|
||||
float ld(float depth) {
|
||||
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
|
||||
}
|
||||
|
||||
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){
|
||||
vec4 vl = vec4(0.0);
|
||||
float sum = 0.0;
|
||||
mat3x3 weights;
|
||||
ivec2 posD = ivec2(coord/2.0)*2;
|
||||
ivec2 posVl = ivec2(coord/2.0);
|
||||
float dz = zMults.x;
|
||||
ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 3 );
|
||||
//pos = ivec2(1,-1);
|
||||
|
||||
ivec2 tcDepth = posD + ivec2(-2,-2) + pos*2;
|
||||
float dsample = ld(texelFetch2D(depth,tcDepth,0).r);
|
||||
float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
|
||||
vl += texelFetch2D(tex,posVl+ivec2(-1)+pos,0)*w;
|
||||
sum += w;
|
||||
|
||||
tcDepth = posD + ivec2(-2,0) + pos*2;
|
||||
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
|
||||
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
|
||||
vl += texelFetch2D(tex,posVl+ivec2(-1,0)+pos,0)*w;
|
||||
sum += w;
|
||||
|
||||
tcDepth = posD + ivec2(0) + pos*2;
|
||||
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
|
||||
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
|
||||
vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w;
|
||||
sum += w;
|
||||
|
||||
tcDepth = posD + ivec2(0,-2) + pos*2;
|
||||
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
|
||||
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
|
||||
vl += texelFetch2D(tex,posVl+ivec2(0,-1)+pos,0)*w;
|
||||
sum += w;
|
||||
|
||||
return vl/sum;
|
||||
}
|
||||
|
||||
void main() {
|
||||
/* DRAWBUFFERS:0 */
|
||||
|
||||
//3x3 bilateral upscale from half resolution
|
||||
float frDepth = ld(texture2D(depthtex0,texcoord).x);
|
||||
vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
|
||||
|
||||
vec3 color = texture2D(colortex3,texcoord).rgb;
|
||||
vec4 transparencies = texture2D(colortex2,texcoord);
|
||||
color = color*(1.0-transparencies.a)+transparencies.rgb*10.;
|
||||
|
||||
color *= vl.a;
|
||||
color += vl.rgb;
|
||||
|
||||
gl_FragData[0].rgb = clamp(color,6.11*1e-5,65000.0);
|
||||
|
||||
gl_FragData[0].a = vl.a;
|
||||
}
|
19
shaders/world1/lib/composite3.vsh
Normal file
19
shaders/world1/lib/composite3.vsh
Normal file
@ -0,0 +1,19 @@
|
||||
#version 120
|
||||
#extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
varying vec2 texcoord;
|
||||
flat varying vec3 zMults;
|
||||
uniform float far;
|
||||
uniform float near;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
void main() {
|
||||
zMults = vec3(1.0/(far * near),far+near,far-near);
|
||||
gl_Position = ftransform();
|
||||
texcoord = gl_MultiTexCoord0.xy;
|
||||
|
||||
}
|
55
shaders/world1/lib/projections.glsl
Normal file
55
shaders/world1/lib/projections.glsl
Normal file
@ -0,0 +1,55 @@
|
||||
uniform mat4 gbufferProjection;
|
||||
uniform mat4 gbufferProjectionInverse;
|
||||
uniform mat4 gbufferPreviousProjection;
|
||||
uniform mat4 gbufferModelViewInverse;
|
||||
uniform mat4 gbufferModelView;
|
||||
uniform mat4 shadowModelView;
|
||||
uniform mat4 shadowProjection;
|
||||
|
||||
uniform vec3 cameraPosition;
|
||||
|
||||
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
|
||||
vec3 toClipSpace3(vec3 viewSpacePosition) {
|
||||
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 toScreenSpace(vec3 p) {
|
||||
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
||||
vec3 p3 = p * 2. - 1.;
|
||||
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
|
||||
return fragposition.xyz / fragposition.w;
|
||||
}
|
||||
|
||||
vec3 toScreenSpaceVector(vec3 p) {
|
||||
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
|
||||
vec3 p3 = p * 2. - 1.;
|
||||
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
|
||||
return normalize(fragposition.xyz);
|
||||
}
|
||||
|
||||
vec3 toWorldSpace(vec3 p3){
|
||||
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
||||
return p3;
|
||||
}
|
||||
|
||||
vec3 toWorldSpaceCamera(vec3 p3){
|
||||
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
||||
return p3 + cameraPosition;
|
||||
}
|
||||
|
||||
vec3 toShadowSpace(vec3 p3){
|
||||
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
||||
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
|
||||
return p3;
|
||||
}
|
||||
|
||||
vec3 toShadowSpaceProjected(vec3 p3){
|
||||
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
|
||||
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
|
||||
p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz;
|
||||
|
||||
return p3;
|
||||
}
|
84
shaders/world1/lib/sky_gradient.glsl
Normal file
84
shaders/world1/lib/sky_gradient.glsl
Normal file
@ -0,0 +1,84 @@
|
||||
#define DRAW_SUN //if not using custom sky
|
||||
#define SKY_BRIGHTNESS_DAY 1.0 //[0.0 0.5 0.75 1. 1.2 1.4 1.6 1.8 2.0]
|
||||
#define SKY_BRIGHTNESS_NIGHT 1.0 //[0.0 0.5 0.75 1. 1.2 1.4 1.6 1.8 2.0]
|
||||
#define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0)
|
||||
vec3 drawSun(float cosY, float sunInt,vec3 nsunlight,vec3 inColor){
|
||||
return inColor+nsunlight/0.0008821203*pow(smoothstep(cos(0.0093084168595*3.2),cos(0.0093084168595*1.8),cosY),3.)*0.62;
|
||||
}
|
||||
const float pi = 3.141592653589793238462643383279502884197169;
|
||||
vec2 sphereToCarte(vec3 dir) {
|
||||
float lonlat = atan(-dir.x, -dir.z);
|
||||
return vec2(lonlat * (0.5/pi) +0.5,0.5*dir.y+0.5);
|
||||
}
|
||||
vec3 skyFromTex(vec3 pos,sampler2D sampler){
|
||||
vec2 p = sphereToCarte(pos);
|
||||
return texture2D(sampler,p*texelSize*256.+vec2(18.5,1.5)*texelSize).rgb;
|
||||
}
|
||||
float w0(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*(a*(-a + 3.0) - 3.0) + 1.0);
|
||||
}
|
||||
|
||||
float w1(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*a*(3.0*a - 6.0) + 4.0);
|
||||
}
|
||||
|
||||
float w2(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*(a*(-3.0*a + 3.0) + 3.0) + 1.0);
|
||||
}
|
||||
|
||||
float w3(float a)
|
||||
{
|
||||
return (1.0/6.0)*(a*a*a);
|
||||
}
|
||||
|
||||
float g0(float a)
|
||||
{
|
||||
return w0(a) + w1(a);
|
||||
}
|
||||
|
||||
float g1(float a)
|
||||
{
|
||||
return w2(a) + w3(a);
|
||||
}
|
||||
|
||||
float h0(float a)
|
||||
{
|
||||
return -1.0 + w1(a) / (w0(a) + w1(a));
|
||||
}
|
||||
|
||||
float h1(float a)
|
||||
{
|
||||
return 1.0 + w3(a) / (w2(a) + w3(a));
|
||||
}
|
||||
|
||||
vec4 texture2D_bicubic(sampler2D tex, vec2 uv)
|
||||
{
|
||||
vec4 texelSize = vec4(texelSize,1.0/texelSize);
|
||||
uv = uv*texelSize.zw;
|
||||
vec2 iuv = floor( uv );
|
||||
vec2 fuv = fract( uv );
|
||||
|
||||
float g0x = g0(fuv.x);
|
||||
float g1x = g1(fuv.x);
|
||||
float h0x = h0(fuv.x);
|
||||
float h1x = h1(fuv.x);
|
||||
float h0y = h0(fuv.y);
|
||||
float h1y = h1(fuv.y);
|
||||
|
||||
vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texelSize.xy;
|
||||
vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texelSize.xy;
|
||||
vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texelSize.xy;
|
||||
vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texelSize.xy;
|
||||
|
||||
return g0(fuv.y) * (g0x * texture2D(tex, p0) +
|
||||
g1x * texture2D(tex, p1)) +
|
||||
g1(fuv.y) * (g0x * texture2D(tex, p2) +
|
||||
g1x * texture2D(tex, p3));
|
||||
}
|
||||
vec4 skyCloudsFromTex(vec3 pos,sampler2D sampler){
|
||||
vec2 p = sphereToCarte(pos);
|
||||
return texture2D(sampler,p*texelSize*256.+vec2(18.5+257.,1.5)*texelSize);
|
||||
}
|
334
shaders/world1/lib/specular.glsl
Normal file
334
shaders/world1/lib/specular.glsl
Normal file
@ -0,0 +1,334 @@
|
||||
//#define Specular_Reflections // reflections on blocks. REQUIRES A PBR RESOURCEPACK.
|
||||
#define Screen_Space_Reflections // toggle screenspace reflections. if you want normal performance but still want a bit of shiny, the sun reflection stays on when this is turned off.
|
||||
#define Sky_reflection // just in case you dont want it i guess
|
||||
// #define Rough_reflections // turns the roughness GGXVNDF ON. sizable performance impact, and introduces alot of noise.
|
||||
|
||||
#define Sun_specular_Strength 3 // increase for more sparkles [1 2 3 4 5 6 7 8 9 10]
|
||||
#define reflection_quality 30 // adjust the quality of the screenspace reflections. [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 ]
|
||||
#define Roughness_Threshold 1.5 // using a curve on the roughness, make the reflections more or less visible on rough surfaces. good for hiding noise on rough materials [1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
|
||||
|
||||
// #define SCREENSHOT_MODE // go render mode and accumulate frames for as long as you want for max image quality.
|
||||
|
||||
uniform sampler2D gaux1;
|
||||
uniform int framemod8;
|
||||
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
vec2(5.0,1.)/8.,
|
||||
vec2(-3,-5.)/8.,
|
||||
vec2(-5.,5.)/8.,
|
||||
vec2(-7.,-1.)/8.,
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
|
||||
|
||||
// sun specular stuff
|
||||
float square(float x){
|
||||
return x*x;
|
||||
}
|
||||
float g(float NdotL, float roughness){
|
||||
float alpha = square(max(roughness, 0.02));
|
||||
return 2.0 * NdotL / (NdotL + sqrt(square(alpha) + (1.0 - square(alpha)) * square(NdotL)));
|
||||
}
|
||||
float gSimple(float dp, float roughness){
|
||||
float k = roughness + 1;
|
||||
k *= k/8.0;
|
||||
return dp / (dp * (1.0-k) + k);
|
||||
}
|
||||
vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
|
||||
float roughness = r; // when roughness is zero it fucks up
|
||||
|
||||
float alpha = square(roughness) + 1e-4;
|
||||
|
||||
|
||||
vec3 h = normalize(l + v);
|
||||
|
||||
float dotLH = clamp(dot(h,l),0.,1.);
|
||||
float dotNH = clamp(dot(h,n),0.,1.);
|
||||
float dotNL = clamp(dot(n,l),0.,1.);
|
||||
float dotNV = clamp(dot(n,v),0.,1.);
|
||||
float dotVH = clamp(dot(h,v),0.,1.);
|
||||
|
||||
|
||||
float D = alpha / (3.141592653589793*square(square(dotNH) * (alpha - 1.0) + 1.0));
|
||||
float G = gSimple(dotNV, roughness) * gSimple(dotNL, roughness);
|
||||
vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH);
|
||||
|
||||
return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7));
|
||||
}
|
||||
|
||||
|
||||
// other shit
|
||||
float invLinZ (float lindepth){
|
||||
return -((2.0*near/lindepth)-far-near)/(far-near);
|
||||
}
|
||||
vec3 toClipSpace3(vec3 viewSpacePosition) {
|
||||
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
|
||||
}
|
||||
float linZ(float depth) {
|
||||
return (2.0 * near) / (far + near - depth * (far - near));
|
||||
// l = (2*n)/(f+n-d(f-n))
|
||||
// f+n-d(f-n) = 2n/l
|
||||
// -d(f-n) = ((2n/l)-f-n)
|
||||
// d = -((2n/l)-f-n)/(f-n)
|
||||
|
||||
}
|
||||
void frisvad(in vec3 n, out vec3 f, out vec3 r){
|
||||
if(n.z < -0.9) {
|
||||
f = vec3(0.,-1,0);
|
||||
r = vec3(-1, 0, 0);
|
||||
} else {
|
||||
float a = 1./(1.+n.z);
|
||||
float b = -n.x*n.y*a;
|
||||
f = vec3(1. - n.x*n.x*a, b, -n.x) ;
|
||||
r = vec3(b, 1. - n.y*n.y*a , -n.y);
|
||||
}
|
||||
}
|
||||
mat3 CoordBase(vec3 n){
|
||||
vec3 x,y;
|
||||
frisvad(n,x,y);
|
||||
return mat3(x,y,n);
|
||||
}
|
||||
float unpackRoughness(float x){
|
||||
float r = 1.0 - x;
|
||||
return clamp(r*r,0,1);
|
||||
}
|
||||
vec2 R2_samples_spec(int n){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha * n);
|
||||
}
|
||||
|
||||
vec3 sampleGGXVNDF(vec3 V_, float alpha_x, float alpha_y, float U1, float U2, bool ishand){
|
||||
// stretch view
|
||||
vec3 V = normalize(vec3(alpha_x * V_.x, alpha_y * V_.y, V_.z));
|
||||
// orthonormal basis
|
||||
vec3 T1 = (V.z < 0.9999) ? normalize(cross(V, vec3(0,0,1))) : vec3(1,0,0);
|
||||
vec3 T2 = cross(T1, V);
|
||||
// sample point with polar coordinates (r, phi)
|
||||
float a = 1.0 / (1.0 + V.z);
|
||||
float r = sqrt(U1);
|
||||
float phi = (U2<a) ? U2/a * 3.141592653589793 : 3.141592653589793 + (U2-a)/(1.0-a) * 3.141592653589793;
|
||||
float P1 = r*cos(phi);
|
||||
float P2 = r*sin(phi)*((U2<a) ? 1.0 : V.z);
|
||||
// compute normal
|
||||
vec3 N = P1*T1 + P2*T2 + sqrt(max(0.0, 1.0 - P1*P1 - P2*P2))*V;
|
||||
// unstretch
|
||||
N = normalize(vec3(alpha_x*N.x, alpha_y*N.y, max(0.0, N.z)));
|
||||
return N;
|
||||
}
|
||||
|
||||
// idk where this is from
|
||||
vec3 generateUnitVector_spec(vec2 xy, float r) {
|
||||
float roughness = 1.0 / (r + 0.0001);
|
||||
|
||||
const float TAU = 2.0*3.14159265; //
|
||||
xy.x *= TAU; xy.y = xy.y * 2.0 - 1.0 ;
|
||||
|
||||
|
||||
return vec3( max(vec2(sin(xy.x), cos(xy.x)) * sqrt(1.0 - xy.y*xy.y) ,-1.0 + (1.0-r)), roughness);
|
||||
}
|
||||
vec3 generateCosineVector_spec(vec3 normal, vec2 xy, float r) {
|
||||
return normalize(normal + generateUnitVector_spec(xy, r));
|
||||
}
|
||||
|
||||
vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool hand, float fres){
|
||||
|
||||
vec3 clipPosition = toClipSpace3(position);
|
||||
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
|
||||
(-near -position.z) / dir.z : far*sqrt(3.);
|
||||
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
|
||||
direction.xy = normalize(direction.xy);
|
||||
|
||||
//get at which length the ray intersects with the edge of the screen
|
||||
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
|
||||
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
|
||||
|
||||
vec3 stepv = direction * mult / quality*vec3(1,1,1.0);
|
||||
// if(hand) dither *= 0.1 ;
|
||||
vec3 spos = clipPosition*vec3(1,1,1.0) + stepv*dither;
|
||||
|
||||
float minZ = spos.z+stepv.z;
|
||||
float maxZ = spos.z+stepv.z;
|
||||
|
||||
spos.xy += TAA_Offset*texelSize*0.5/1;
|
||||
|
||||
// for (int i = 0; i <= int(quality); i++) {
|
||||
|
||||
// // decode depth buffer
|
||||
// vec2 testthing = hand ? spos.xy*texelSize : spos.xy/texelSize/4.0; // fix for ssr on hand
|
||||
|
||||
// float sp = sqrt(texelFetch2D(gaux1,ivec2(spos.xy/texelSize/4.0),0).w/65000.0);
|
||||
|
||||
// sp = invLinZ(sp);
|
||||
|
||||
// if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/1,sp);
|
||||
|
||||
// spos += stepv;
|
||||
|
||||
// //small bias
|
||||
// float biasamount = 0.00015;
|
||||
// if(hand) biasamount = 0.01;
|
||||
// // minZ = maxZ-clamp(fres*0.0004 ,0.00004,0.0004) / ld(spos.z);
|
||||
// minZ = maxZ-biasamount / ld(spos.z);
|
||||
|
||||
// maxZ += stepv.z;
|
||||
|
||||
// }
|
||||
for (int i = 0; i < int(quality+1); i++) {
|
||||
|
||||
vec2 testthing = hand ? spos.xy : spos.xy/texelSize; // fix for ssr on hand
|
||||
float sp=texelFetch2D(depthtex1,ivec2(testthing),0).x;
|
||||
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)){
|
||||
return vec3(spos.xy,sp);
|
||||
|
||||
}
|
||||
spos += stepv;
|
||||
//small bias
|
||||
float biasamount = 0.00015;
|
||||
if(hand) biasamount = 0.01;
|
||||
// minZ = maxZ-clamp(fres*0.0004 ,0.00004,0.0004) / ld(spos.z);
|
||||
minZ = maxZ-biasamount / ld(spos.z);
|
||||
maxZ += stepv.z;
|
||||
}
|
||||
|
||||
return vec3(1.1);
|
||||
}
|
||||
|
||||
vec3 mix_vec3(vec3 X, vec3 Y, float A){
|
||||
return X * (1.0 - A) + Y * A;
|
||||
}
|
||||
float mix_float(float X, float Y, float A){
|
||||
return X * (1.0 - A) + Y * A;
|
||||
}
|
||||
|
||||
|
||||
// vec3 gaussblur( vec4 colorout, vec2 texcoord )
|
||||
// {
|
||||
// float Pi = 6.28318530718; // Pi*2
|
||||
|
||||
// // GAUSSIAN BLUR SETTINGS {{{
|
||||
// float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
|
||||
// float Quality = 3.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
|
||||
// float Size = 50.0; // BLUR SIZE (Radius)
|
||||
// // GAUSSIAN BLUR SETTINGS }}}
|
||||
|
||||
// vec2 Radius = Size/vec2(1920,1080);
|
||||
|
||||
// // Normalized pixel coordinates (from 0 to 1)
|
||||
// vec2 uv = texcoord/vec2(1920,1080);
|
||||
// // Pixel colour
|
||||
// vec4 Color = texture2D(colortex3, texcoord);
|
||||
|
||||
// // Blur calculations
|
||||
// for( float d=0.0; d<Pi; d+=Pi/Directions)
|
||||
// {
|
||||
// for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality)
|
||||
// {
|
||||
// Color += texture2D( colortex3, texcoord+vec2(cos(d),sin(d))*Radius*i);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Output to screen
|
||||
// Color /= Quality * Directions - 15.0;
|
||||
// colorout = Color;
|
||||
// return colorout.rgb;
|
||||
// }
|
||||
|
||||
|
||||
// pain
|
||||
void MaterialReflections(
|
||||
inout vec3 Output,
|
||||
float roughness,
|
||||
vec3 f0,
|
||||
vec3 albedo,
|
||||
vec3 sunPos,
|
||||
vec3 sunCol,
|
||||
float diffuse,
|
||||
float lightmap,
|
||||
vec3 normal,
|
||||
vec3 np3,
|
||||
vec3 fragpos,
|
||||
vec3 noise,
|
||||
bool hand
|
||||
){
|
||||
vec3 Reflections_Final = Output;
|
||||
|
||||
float Outdoors = 0.0;
|
||||
// float Outdoors = clamp((lightmap-0.5) * , 0.0,1.0);
|
||||
|
||||
roughness = unpackRoughness(roughness);
|
||||
f0 = f0.y == 0.0 ? vec3(0.04) : f0;
|
||||
|
||||
|
||||
mat3 basis = CoordBase(normal);
|
||||
vec3 normSpaceView = -np3*basis ;
|
||||
|
||||
// roughness stuff
|
||||
#ifdef Rough_reflections
|
||||
int seed = (frameCounter%40000);
|
||||
vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ;
|
||||
|
||||
vec3 H = sampleGGXVNDF(normSpaceView, roughness, ij.x, ij.y);
|
||||
if(hand) H = normalize(vec3(0.0,0.0,1.0));
|
||||
#else
|
||||
vec3 H = normalize(vec3(0.0,0.0,1.0));
|
||||
#endif
|
||||
|
||||
vec3 Ln = reflect(-normSpaceView, clamp(H,-1.0,1.0));
|
||||
vec3 L = basis * Ln;
|
||||
|
||||
// fresnel stuff
|
||||
float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0);
|
||||
// vec3 F = f0 + (1.0 - f0) * fresnel;
|
||||
|
||||
vec3 F = mix(f0, vec3(1.0), fresnel);
|
||||
vec3 rayContrib = F;
|
||||
|
||||
|
||||
float NdotV = clamp(normalize(dot(np3, normal))*10000.,0.,1.);
|
||||
bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) > 0.01;
|
||||
|
||||
if (Roughness_Threshold == 1.0){ hasReflections = roughness > -1; NdotV = -1.0;}
|
||||
|
||||
|
||||
vec3 SunReflection = diffuse * GGX2(normal, -np3, sunPos, roughness, f0) * sunCol;
|
||||
|
||||
vec4 Reflections = vec4(0.0);
|
||||
#ifdef Screen_Space_Reflections
|
||||
if ( hasReflections && NdotV <= 0.0) { // Skip SSR if ray contribution is low
|
||||
#ifdef SCREENSHOT_MODE
|
||||
float rayQuality = reflection_quality;
|
||||
#else
|
||||
float rayQuality = mix_float(reflection_quality,0.0,sqrt(roughness)); // Scale quality with ray contribution
|
||||
#endif
|
||||
vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, rayQuality, hand, fresnel);
|
||||
if (rtPos.z < 1. ){ // Reproject on previous frame
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
|
||||
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
|
||||
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
|
||||
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
|
||||
Reflections.a = 1.0;
|
||||
Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// check if the f0 is within the metal ranges, then tint by albedo if it's true.
|
||||
vec3 Metals = f0.y > 229.5/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0);
|
||||
Reflections.rgb *= Metals;
|
||||
|
||||
// apply all reflections to the lighting
|
||||
Reflections_Final += Reflections.rgb * luma(rayContrib);
|
||||
|
||||
// interpolate between the albedos and reflections using the roughness value instead of the sampling.
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0.y) * -4),0,1);
|
||||
#ifdef Rough_reflections
|
||||
Output = hand ? mix_vec3(Output, Reflections_Final, visibilityFactor) : Reflections_Final;
|
||||
#else
|
||||
Output = mix_vec3(Output, Reflections_Final, visibilityFactor);
|
||||
#endif
|
||||
Output += SunReflection;
|
||||
}
|
48
shaders/world1/lib/stars.glsl
Normal file
48
shaders/world1/lib/stars.glsl
Normal file
@ -0,0 +1,48 @@
|
||||
//Original star code : https://www.shadertoy.com/view/Md2SR3 , optimised
|
||||
|
||||
|
||||
|
||||
// Return random noise in the range [0.0, 1.0], as a function of x.
|
||||
float hash12(vec2 p)
|
||||
{
|
||||
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
|
||||
p3 += dot(p3, p3.yzx + 19.19);
|
||||
return fract((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
// Convert Noise2d() into a "star field" by stomping everthing below fThreshhold to zero.
|
||||
float NoisyStarField( in vec2 vSamplePos, float fThreshhold )
|
||||
{
|
||||
float StarVal = hash12( vSamplePos );
|
||||
StarVal = clamp(StarVal/(1.0 - fThreshhold) - fThreshhold/(1.0 - fThreshhold),0.0,1.0);
|
||||
|
||||
return StarVal;
|
||||
}
|
||||
|
||||
// Stabilize NoisyStarField() by only sampling at integer values.
|
||||
float StableStarField( in vec2 vSamplePos, float fThreshhold )
|
||||
{
|
||||
// Linear interpolation between four samples.
|
||||
// Note: This approach has some visual artifacts.
|
||||
// There must be a better way to "anti alias" the star field.
|
||||
float fractX = fract( vSamplePos.x );
|
||||
float fractY = fract( vSamplePos.y );
|
||||
vec2 floorSample = floor( vSamplePos );
|
||||
float v1 = NoisyStarField( floorSample, fThreshhold );
|
||||
float v2 = NoisyStarField( floorSample + vec2( 0.0, 1.0 ), fThreshhold );
|
||||
float v3 = NoisyStarField( floorSample + vec2( 1.0, 0.0 ), fThreshhold );
|
||||
float v4 = NoisyStarField( floorSample + vec2( 1.0, 1.0 ), fThreshhold );
|
||||
|
||||
float StarVal = v1 * ( 1.0 - fractX ) * ( 1.0 - fractY )
|
||||
+ v2 * ( 1.0 - fractX ) * fractY
|
||||
+ v3 * fractX * ( 1.0 - fractY )
|
||||
+ v4 * fractX * fractY;
|
||||
return StarVal;
|
||||
}
|
||||
|
||||
float stars(vec3 fragpos){
|
||||
|
||||
float elevation = clamp(fragpos.y,0.,1.);
|
||||
vec2 uv = fragpos.xz/(1.+elevation);
|
||||
|
||||
return StableStarField(uv*700.,0.999)/4.*(0.3-0.3*rainStrength);
|
||||
}
|
19
shaders/world1/lib/texFiltering.glsl
Normal file
19
shaders/world1/lib/texFiltering.glsl
Normal file
@ -0,0 +1,19 @@
|
||||
vec4 smoothfilter(in sampler2D tex, in vec2 uv, in vec2 textureResolution)
|
||||
{
|
||||
uv = uv*textureResolution + 0.5;
|
||||
vec2 iuv = floor( uv );
|
||||
vec2 fuv = fract( uv );
|
||||
uv = iuv + (fuv*fuv)*(3.0-2.0*fuv);
|
||||
uv = uv/textureResolution - 0.5/textureResolution;
|
||||
return texture2D( tex, uv);
|
||||
}
|
||||
|
||||
float shadowsmoothfilter(in sampler2DShadow tex, in vec3 uv,in float textureResolution)
|
||||
{
|
||||
uv.xy = uv.xy*textureResolution + 0.5;
|
||||
vec2 iuv = floor( uv.xy );
|
||||
vec2 fuv = fract( uv.xy );
|
||||
uv.xy = iuv + (fuv*fuv)*(3.0-2.0*fuv);
|
||||
uv.xy = uv.xy/textureResolution - 0.5/textureResolution;
|
||||
return shadow2D( tex, uv).x;
|
||||
}
|
196
shaders/world1/lib/util.glsl
Normal file
196
shaders/world1/lib/util.glsl
Normal file
@ -0,0 +1,196 @@
|
||||
#define TIME_MULT 1.0
|
||||
#define TIME (frameTimeCounter * TIME_MULT)
|
||||
|
||||
const float PI = acos(-1.0);
|
||||
const float TAU = PI * 2.0;
|
||||
const float hPI = PI * 0.5;
|
||||
const float rPI = 1.0 / PI;
|
||||
const float rTAU = 1.0 / TAU;
|
||||
|
||||
const float PHI = sqrt(5.0) * 0.5 + 0.5;
|
||||
const float rLOG2 = 1.0 / log(2.0);
|
||||
|
||||
const float goldenAngle = TAU / PHI / PHI;
|
||||
|
||||
#define clamp01(x) clamp(x, 0.0, 1.0)
|
||||
#define max0(x) max(x, 0.0)
|
||||
#define min0(x) min(x, 0.0)
|
||||
#define max3(a) max(max(a.x, a.y), a.z)
|
||||
#define min3(a) min(min(a.x, a.y), a.z)
|
||||
#define max4(a, b, c, d) max(max(a, b), max(c, d))
|
||||
#define min4(a, b, c, d) min(min(a, b), min(c, d))
|
||||
|
||||
#define fsign(x) (clamp01(x * 1e35) * 2.0 - 1.0)
|
||||
#define fstep(x,y) clamp01((y - x) * 1e35)
|
||||
|
||||
#define diagonal2(m) vec2((m)[0].x, (m)[1].y)
|
||||
#define diagonal3(m) vec3(diagonal2(m), m[2].z)
|
||||
#define diagonal4(m) vec4(diagonal3(m), m[2].w)
|
||||
|
||||
#define transMAD(mat, v) (mat3(mat) * (v) + (mat)[3].xyz)
|
||||
#define projMAD(mat, v) (diagonal3(mat) * (v) + (mat)[3].xyz)
|
||||
|
||||
#define encodeColor(x) (x * 0.00005)
|
||||
#define decodeColor(x) (x * 20000.0)
|
||||
|
||||
#define cubeSmooth(x) (x * x * (3.0 - 2.0 * x))
|
||||
|
||||
#define lumCoeff vec3(0.2125, 0.7154, 0.0721)
|
||||
|
||||
float facos(const float sx){
|
||||
float x = clamp(abs( sx ),0.,1.);
|
||||
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
|
||||
return sx > 0. ? a : PI - a;
|
||||
//float c = clamp(-sx * 1e35, 0., 1.);
|
||||
//return c * pi + a * -(c * 2. - 1.); //no conditional version
|
||||
}
|
||||
|
||||
|
||||
vec2 sincos(float x){
|
||||
return vec2(sin(x), cos(x));
|
||||
}
|
||||
|
||||
vec2 circlemap(float i, float n){
|
||||
return sincos(i * n * goldenAngle) * sqrt(i);
|
||||
}
|
||||
|
||||
vec3 circlemapL(float i, float n){
|
||||
return vec3(sincos(i * n * goldenAngle), sqrt(i));
|
||||
}
|
||||
|
||||
vec3 calculateRoughSpecular(const float i, const float alpha2, const int steps) {
|
||||
|
||||
float x = (alpha2 * i) / (1.0 - i);
|
||||
float y = i * float(steps) * 64.0 * 64.0 * goldenAngle;
|
||||
|
||||
float c = inversesqrt(x + 1.0);
|
||||
float s = sqrt(x) * c;
|
||||
|
||||
return vec3(cos(y) * s, sin(y) * s, c);
|
||||
}
|
||||
|
||||
vec3 clampNormal(vec3 n, vec3 v){
|
||||
float NoV = clamp( dot(n, -v), 0., 1. );
|
||||
return normalize( NoV * v + n );
|
||||
}
|
||||
|
||||
vec3 srgbToLinear(vec3 srgb){
|
||||
return mix(
|
||||
srgb / 12.92,
|
||||
pow(.947867 * srgb + .0521327, vec3(2.4) ),
|
||||
step( .04045, srgb )
|
||||
);
|
||||
}
|
||||
|
||||
vec3 linearToSRGB(vec3 linear){
|
||||
return mix(
|
||||
linear * 12.92,
|
||||
pow(linear, vec3(1./2.4) ) * 1.055 - .055,
|
||||
step( .0031308, linear )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3 blackbody(float Temp)
|
||||
{
|
||||
float t = pow(Temp, -1.5);
|
||||
float lt = log(Temp);
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
col.x = 220000.0 * t + 0.58039215686;
|
||||
col.y = 0.39231372549 * lt - 2.44549019608;
|
||||
col.y = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : col.y;
|
||||
col.z = 0.76078431372 * lt - 5.68078431373;
|
||||
col = clamp01(col);
|
||||
col = Temp < 1000. ? col * Temp * 0.001 : col;
|
||||
|
||||
return srgbToLinear(col);
|
||||
}
|
||||
|
||||
float calculateHardShadows(float shadowDepth, vec3 shadowPosition, float bias) {
|
||||
if(shadowPosition.z >= 1.0) return 1.0;
|
||||
|
||||
return 1.0 - fstep(shadowDepth, shadowPosition.z - bias);
|
||||
}
|
||||
|
||||
vec3 genUnitVector(vec2 xy) {
|
||||
xy.x *= TAU; xy.y = xy.y * 2.0 - 1.0;
|
||||
return vec3(sincos(xy.x) * sqrt(1.0 - xy.y * xy.y), xy.y);
|
||||
}
|
||||
|
||||
vec2 rotate(vec2 x, float r){
|
||||
vec2 sc = sincos(r);
|
||||
return mat2(sc.x, -sc.y, sc.y, sc.x) * x;
|
||||
}
|
||||
|
||||
vec3 cartToSphere(vec2 coord) {
|
||||
coord *= vec2(TAU, PI);
|
||||
vec2 lon = sincos(coord.x) * sin(coord.y);
|
||||
return vec3(lon.x, 2.0/PI*coord.y-1.0, lon.y);
|
||||
}
|
||||
|
||||
vec2 sphereToCart(vec3 dir) {
|
||||
float lonlat = atan(-dir.x, -dir.z);
|
||||
return vec2(lonlat * rTAU +0.5,0.5*dir.y+0.5);
|
||||
}
|
||||
|
||||
mat3 getRotMat(vec3 x,vec3 y){
|
||||
float d = dot(x,y);
|
||||
vec3 cr = cross(y,x);
|
||||
|
||||
float s = length(cr);
|
||||
|
||||
float id = 1.-d;
|
||||
|
||||
vec3 m = cr/s;
|
||||
|
||||
vec3 m2 = m*m*id+d;
|
||||
vec3 sm = s*m;
|
||||
|
||||
vec3 w = (m.xy*id).xxy*m.yzz;
|
||||
|
||||
return mat3(
|
||||
m2.x, w.x-sm.z, w.y+sm.y,
|
||||
w.x+sm.z, m2.y, w.z-sm.x,
|
||||
w.y-sm.y, w.z+sm.x, m2.z
|
||||
);
|
||||
}
|
||||
|
||||
// No intersection if returned y component is < 0.0
|
||||
vec2 rsi(vec3 position, vec3 direction, float radius) {
|
||||
float PoD = dot(position, direction);
|
||||
float radiusSquared = radius * radius;
|
||||
|
||||
float delta = PoD * PoD + radiusSquared - dot(position, position);
|
||||
if (delta < 0.0) return vec2(-1.0);
|
||||
delta = sqrt(delta);
|
||||
|
||||
return -PoD + vec2(-delta, delta);
|
||||
}
|
||||
float HaltonSeq3(int index)
|
||||
{
|
||||
float r = 0.;
|
||||
float f = 1.;
|
||||
int i = index;
|
||||
while (i > 0)
|
||||
{
|
||||
f /= 3.0;
|
||||
r += f * (i % 3);
|
||||
i = int(i / 3.0);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
float HaltonSeq2(int index)
|
||||
{
|
||||
float r = 0.;
|
||||
float f = 1.;
|
||||
int i = index;
|
||||
while (i > 0)
|
||||
{
|
||||
f /= 2.0;
|
||||
r += f * (i % 2);
|
||||
i = int(i / 2.0);
|
||||
}
|
||||
return r;
|
||||
}
|
342
shaders/world1/lib/volumetricClouds.glsl
Normal file
342
shaders/world1/lib/volumetricClouds.glsl
Normal file
@ -0,0 +1,342 @@
|
||||
#define VOLUMETRIC_CLOUDS// if you don't like the noise on the default cloud settings, turn up the cloud samples. if that hurts performance too much, turn down the clouds quality.
|
||||
|
||||
#define cloud_LevelOfDetail 1 // Number of fbm noise iterations for on-screen clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
|
||||
#define cloud_ShadowLevelOfDetail 0 // Number of fbm noise iterations for the shadowing of on-screen clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
|
||||
#define cloud_LevelOfDetailLQ 1 // Number of fbm noise iterations for reflected clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
|
||||
#define cloud_ShadowLevelOfDetailLQ 0 // Number of fbm noise iterations for the shadowing of reflected clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
|
||||
#define minRayMarchSteps 20 // Number of ray march steps towards zenith for on-screen clouds [20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
|
||||
#define maxRayMarchSteps 30 // Number of ray march steps towards horizon for on-screen clouds [5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
|
||||
#define minRayMarchStepsLQ 10 // Number of ray march steps towards zenith for reflected clouds [5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100]
|
||||
#define maxRayMarchStepsLQ 30 // Number of ray march steps towards horizon for reflected clouds [ 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100]
|
||||
#define cloudMieG 0.5 // Values close to 1 will create a strong peak of luminance around the sun and weak elsewhere, values close to 0 means uniform fog. [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
#define cloudMieG2 0.9 // Multiple scattering approximation. Values close to 1 will create a strong peak of luminance around the sun and weak elsewhere, values close to 0 means uniform fog. [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
#define cloudMie2Multiplier 0.7 // Multiplier for multiple scattering approximation [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
|
||||
#define Cloud_top_cutoff 1.0 // the cutoff point on the top part of the cloud. [ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.5 3.0 4 5 6 7 8 9]
|
||||
#define Cloud_base_cutoff 5.0 // the cutoff point on the base of the cloud. [0.1 1 2 4 6 8 10 12 14 16 18 20]
|
||||
|
||||
|
||||
#ifdef HQ_CLOUDS
|
||||
int maxIT_clouds = minRayMarchSteps;
|
||||
int maxIT = maxRayMarchSteps;
|
||||
#else
|
||||
int maxIT_clouds = minRayMarchStepsLQ;
|
||||
int maxIT = maxRayMarchStepsLQ;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
uniform vec3 sunPosition;
|
||||
|
||||
|
||||
#define cloudCoverage 0.4 // Cloud coverage [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]
|
||||
// #define Rain_coverage 0.8 // how much the coverage of the clouds change during rain [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 3.0 4.0 5.0]
|
||||
|
||||
/////// shape
|
||||
#define cloudDensity 0.0514 // Cloud Density, 0.04-0.06 is around irl values [0.0010 0.0011 0.0013 0.0015 0.0017 0.0020 0.0023 0.0026 0.0030 0.0034 0.0039 0.0045 0.0051 0.0058 0.0067 0.0077 0.0088 0.0101 0.0115 0.0132 0.0151 0.0173 0.0199 0.0228 0.0261 0.0299 0.0342 0.0392 0.0449 0.0514 0.0589 0.0675 0.0773 0.0885 0.1014 0.1162 0.1331 0.1524 0.1746 0.2000 0.3 0.35 0.4 0.45 0.5 0.6 0.7 0.8 0.9 1.0]
|
||||
#define fbmAmount2 1 // Amount of noise added to the cloud shape [0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00]
|
||||
#define fbmPower1 3.00 // Higher values increases high frequency details of the cloud shape [1.0 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 3.02 3.04 3.06 3.08 3.10 3.12 3.14 3.16 3.18 3.20 3.22 3.24 3.26 3.28 3.30 3.32 3.34 3.36 3.38 3.40 3.42 3.44 3.46 3.48 3.50 3.52 3.54 3.56 3.58 3.60 3.62 3.64 3.66 3.68 3.70 3.72 3.74 3.76 3.78 3.80 3.82 3.84 3.86 3.88 3.90 3.92 3.94 3.96 3.98 4.00 5. 6. 7. 8. 9. 10.]
|
||||
#define fbmPower2 1.50 // Lower values increases high frequency details of the cloud shape [1.00 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 3.02 3.04 3.06 3.08 3.10 3.12 3.14 3.16 3.18 3.20 3.22 3.24 3.26 3.28 3.30 3.32 3.34 3.36 3.38 3.40 3.42 3.44 3.46 3.48 3.50 3.52 3.54 3.56 3.58 3.60 3.62 3.64 3.66 3.68 3.70 3.72 3.74 3.76 3.78 3.80 3.82 3.84 3.86 3.88 3.90 3.92 3.94 3.96 3.98 4.00 5. 6. 7. 8. 9. 10.]
|
||||
|
||||
/////// lighting
|
||||
#define Shadow_brightness 0.5 // how dark / bright you want the shadowed part of the clouds to be. low values can look weird. [ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 3.0 4.0 5.0 6.0]
|
||||
#define self_shadow_samples 3.0 // amount of interations for cloud self shadows. longer/shorter cloud self shadows. [ 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0]
|
||||
|
||||
#define Cloud_Size 35 // [1 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100]
|
||||
#define Cloud_Height 319 // [-300 -290 -280 -270 -260 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319 320]
|
||||
|
||||
// #define Dynamic_weather // a
|
||||
|
||||
#define Dynamic_sky_day -1 // -1 MEANS THIS IS OFF. select which day of the 8 to the clouds should take shape in [0 1 2 3 4 5 6 7 ]
|
||||
|
||||
#define Dynamic_Sky // day 1: partly cloudy. day 2: really cloudy, misty. day 3: mostly clear. day 4: cloudy. day 5: cloudy again. day 6: scattered clouds. day 7: partly cloudy. day 8: clear
|
||||
#define High_Altitude_Clouds // a layer of clouds way up yonder
|
||||
|
||||
/////// other
|
||||
#define Puddle_size 5 // size of puddles [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191 20 21 22 23 24 25]
|
||||
#define Puddle_Coverage 0.7 // the amount of cround the puddles cover [ 0.50 0.49 0.48 0.47 0.46 0.45 0.44 0.44 0.43 0.42 0.41 0.40 0.39 0.38 0.37 0.36 0.35 0.34 0.33 0.32 0.31 0.30 0.29 0.28 0.27 0.26 0.25 0.24 0.23 0.22 0.21 0.20 0.19 0.18 0.17 0.16 0.15 0.14 0.13 0.12 0.11 0.10 0.09 0.08 0.07 0.06 0.05 0.04 0.03 0.02 0.01 0.0]
|
||||
#define flip_the_clouds 1 // what was once above is now below [1 -1]
|
||||
#define cloud_speed 1 // how [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2.0 3.0 5.0 10.0 25.0 50.0 100.0 200.0]
|
||||
|
||||
|
||||
#ifdef HQ_CLOUDS
|
||||
const int cloudLoD = cloud_LevelOfDetail;
|
||||
const int cloudShadowLoD = cloud_ShadowLevelOfDetail;
|
||||
#else
|
||||
const int cloudLoD = cloud_LevelOfDetailLQ;
|
||||
const int cloudShadowLoD = cloud_ShadowLevelOfDetailLQ;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
uniform sampler2D colortex4;//Skybox
|
||||
|
||||
uniform float wetness;
|
||||
|
||||
uniform vec4 Moon_Weather_properties;
|
||||
|
||||
|
||||
|
||||
// David Hoskins' Hash without Sine https://www.shadertoy.com/view/4djSRW
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
float speed = floor(frameTimeCounter);
|
||||
vec3 rand_pos = hash31(speed) * 6.28;
|
||||
|
||||
vec3 lighting_pos = vec3(sin(1.57 + rand_pos.x), sin(rand_pos.y), sin(rand_pos.z));
|
||||
// vec3 lighting_pos = vec3(1,3 , 1);
|
||||
|
||||
vec3 lightSource = normalize(lighting_pos);
|
||||
vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
|
||||
vec3 WsunVec = normalize(mat3(gbufferModelViewInverse) * viewspace_sunvec);
|
||||
|
||||
|
||||
float timing = dot(lighting_pos, vec3(1.0));
|
||||
float flash = max(sin(frameTimeCounter*5) * timing,0.0);
|
||||
|
||||
vec3 srgbToLinear(vec3 srgb){
|
||||
return mix(
|
||||
srgb / 12.92,
|
||||
pow(.947867 * srgb + .0521327, vec3(2.4) ),
|
||||
step( .04045, srgb )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
vec3 blackbody(float Temp)
|
||||
{
|
||||
float t = pow(Temp, -1.5);
|
||||
float lt = log(Temp);
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
col.x = 220000.0 * t + 0.58039215686;
|
||||
col.y = 0.39231372549 * lt - 2.44549019608;
|
||||
col.y = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : col.y;
|
||||
col.z = 0.76078431372 * lt - 5.68078431373;
|
||||
col = clamp(col,0,1);
|
||||
col = Temp < 1000. ? col * Temp * 0.001 : col;
|
||||
|
||||
return srgbToLinear(col);
|
||||
}
|
||||
// vec3 SunCol = vec3(1 ,0.3 ,0.8) ;
|
||||
vec3 SunCol = vec3(0.25 ,0.5 ,1.0)*flash * blackbody( rand_pos.y* 2000);
|
||||
// vec3 SunCol = vec3(0.0);
|
||||
|
||||
|
||||
|
||||
|
||||
float cloud_height = 1500.;
|
||||
float maxHeight = 4000.;
|
||||
|
||||
//3D noise from 2d texture
|
||||
float densityAtPos(in vec3 pos){
|
||||
pos /= 18.;
|
||||
pos.xz *= 0.5;
|
||||
vec3 p = floor(pos);
|
||||
vec3 f = fract(pos);
|
||||
vec2 uv = p.xz + f.xz + p.y * vec2(0.0,193.0);
|
||||
vec2 coord = uv / 512.0;
|
||||
|
||||
//Te y channel has an offset to avoid using two textures fetches
|
||||
vec2 xy = texture2D(noisetex, coord).yx;
|
||||
|
||||
return mix(xy.r,xy.g, f.y);
|
||||
}
|
||||
|
||||
float CloudLarge = 1.0;
|
||||
float CloudSmall = 1.0;
|
||||
float coverage = 1.0;
|
||||
float cloudshape = 0;
|
||||
|
||||
// vec2 cloud_movement = vec2( sin(frameTimeCounter/2000)*2 ,-cos(frameTimeCounter/2000)*2) * MOVEMENT;
|
||||
vec3 cloud_movement1 = vec3(frameTimeCounter)*0.1 ;
|
||||
|
||||
//Cloud without 3D noise, is used to exit early lighting calculations if there is no cloud
|
||||
float cloudCov(in vec3 pos,vec3 samplePos){
|
||||
|
||||
CloudLarge = texture2D(noisetex, samplePos.xz/22500 + frameTimeCounter/500. ).b*2.0;
|
||||
|
||||
coverage = CloudLarge +0.5;
|
||||
float mult = max( (4000.0-pos.y) / 1000, 0);
|
||||
|
||||
cloudshape = coverage - mult ;
|
||||
|
||||
return cloudshape;
|
||||
}
|
||||
|
||||
|
||||
//Erode cloud with 3d Perlin-worley noise, actual cloud value
|
||||
float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD){
|
||||
float noise = 0.0 ;
|
||||
float totalWeights = 0.0;
|
||||
float pw = log(fbmPower1);
|
||||
float pw2 = log(fbmPower2);
|
||||
|
||||
float swirl = (1-texture2D(noisetex, samplePos.xz/5000 ).b)*8;
|
||||
|
||||
for (int i = 0; i <= LoD; i++){
|
||||
float weight = exp(-i*pw2);
|
||||
|
||||
noise += weight - densityAtPos(samplePos *(8. )* exp(i*pw) )*weight ;
|
||||
totalWeights += weight ;
|
||||
}
|
||||
|
||||
noise /= totalWeights;
|
||||
noise = noise*noise;
|
||||
noise *= clamp(1.0 - cloudshape,0.0,1.0);
|
||||
float cloud = max(cov-noise*noise*(1.)*fbmAmount2,0.0);
|
||||
|
||||
return cloud;
|
||||
}
|
||||
|
||||
float getCloudDensity(in vec3 pos, in int LoD){
|
||||
vec3 samplePos = pos*vec3(1.0,1./48.,1.0)/4 - frameTimeCounter/2;
|
||||
float coverageSP = cloudCov(pos,samplePos);
|
||||
if (coverageSP > 0.001) {
|
||||
if (LoD < 0) return max(coverageSP - 0.27*fbmAmount2,0.0);
|
||||
return cloudVol(pos,samplePos,coverageSP, LoD);
|
||||
} else return 0.0;
|
||||
}
|
||||
//Mie phase function
|
||||
float phaseg(float x, float g){
|
||||
float gg = g * g;
|
||||
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) /3.14;
|
||||
}
|
||||
|
||||
|
||||
vec3 startOffset = vec3(0);
|
||||
vec4 renderClouds(vec3 fragpositi, vec3 color,float dither,vec3 sunColor,vec3 moonColor,vec3 avgAmbient,float dither2) {
|
||||
|
||||
|
||||
#ifndef VOLUMETRIC_CLOUDS
|
||||
return vec4(0.0,0.0,0.0,1.0);
|
||||
#endif
|
||||
|
||||
//project pixel position into projected shadowmap space
|
||||
vec4 fragposition = gbufferModelViewInverse*vec4(fragpositi,1.0);
|
||||
|
||||
vec3 worldV = normalize(fragposition.rgb);
|
||||
float VdotU = worldV.y;
|
||||
|
||||
// worldV.y += 0.1 ;
|
||||
|
||||
|
||||
//project view origin into projected shadowmap space
|
||||
vec4 start = (gbufferModelViewInverse*vec4(0.0,0.0,0.,1.));
|
||||
vec3 dV_view = worldV;
|
||||
|
||||
vec3 progress_view = dV_view*dither+cameraPosition;
|
||||
|
||||
float testdither = dither ;
|
||||
float vL = 0.0;
|
||||
float total_extinction = 1.0;
|
||||
|
||||
maxIT_clouds = int(clamp( maxIT_clouds /sqrt(exp2(VdotU)),0.0, maxIT*1.0));
|
||||
float distW = length(worldV);
|
||||
worldV = normalize(worldV)*100000. + cameraPosition; //makes max cloud distance not dependant of render distance
|
||||
dV_view = normalize(dV_view);
|
||||
// maxHeight = maxHeight * (1+testCloudheight_variation);
|
||||
|
||||
int Flip_clouds = 1;
|
||||
if (worldV.y < cloud_height) Flip_clouds = -1;
|
||||
//setup ray to start at the start of the cloud plane and end at the end of the cloud plane
|
||||
dV_view *= max(maxHeight - cloud_height, 0.0)/dV_view.y/(maxIT_clouds);
|
||||
startOffset = dV_view*testdither;
|
||||
|
||||
vec3 camPos = Flip_clouds*(cameraPosition);
|
||||
|
||||
progress_view = (startOffset) + camPos + dV_view*((cloud_height)-camPos.y)/dV_view.y ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
float shadowStep = 240.;
|
||||
vec3 dV_Sun = Flip_clouds * normalize( mat3(gbufferModelViewInverse) * viewspace_sunvec ) * shadowStep;
|
||||
|
||||
|
||||
float mult = length(dV_view);
|
||||
|
||||
|
||||
color = vec3(0.0);
|
||||
|
||||
total_extinction = 1.0;
|
||||
float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpositi));
|
||||
|
||||
float mieDay = phaseg(SdotV, 0.8);
|
||||
float mie2 = phaseg(SdotV, 0.5);
|
||||
|
||||
|
||||
// vec3 SunCol = vec3(1.0,0.5,0.5) * flashing ;
|
||||
|
||||
vec3 sunContribution = mieDay*SunCol*3.14;
|
||||
|
||||
|
||||
// float darkness = texture2D(noisetex, progress_view.xz/120500).b;
|
||||
// vec3 skyCol0 = (avgAmbient*4.0*3.1415*8/3.0 ) ;
|
||||
vec3 skyCol0 = gl_Fog.color.rgb * 0.01;
|
||||
|
||||
for(int i=0;i<maxIT_clouds;i++) {
|
||||
|
||||
float cloud = getCloudDensity(progress_view, cloudLoD);
|
||||
float densityofclouds = max(cloudDensity,0.) ;
|
||||
|
||||
|
||||
if(cloud > 0.0001){
|
||||
float muS = cloud*densityofclouds;
|
||||
float muE = cloud*densityofclouds;
|
||||
|
||||
float muEshD = 0.0;
|
||||
if (sunContribution.g > 1e-5){
|
||||
for (int j=0; j < 3; j++){
|
||||
|
||||
vec3 shadowSamplePos = progress_view + dV_Sun * ((j+0.5) + (j *2)) ;
|
||||
// get the cloud density and apply it
|
||||
if (shadowSamplePos.y < maxHeight){
|
||||
float cloudS = getCloudDensity(shadowSamplePos, cloudShadowLoD);
|
||||
muEshD += cloudS*densityofclouds*shadowStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float powder = muE * 100; // powder....
|
||||
|
||||
float sunShadow = exp(-muEshD*0.25); // this simulates the direct light, and the scattering of it
|
||||
|
||||
float front_lit = sunShadow;
|
||||
float back_lit = pow(muS*(cloud+muE), max(1-cloud*2,0.0)*2);
|
||||
|
||||
float innerSeams = mix(front_lit, back_lit*0.5, clamp(mie2,0.,1.) ) ;
|
||||
|
||||
vec3 SunCloud_lighting = sunContribution * innerSeams * mie2;
|
||||
vec3 AmbientCloud_Lighting = skyCol0 * powder ;
|
||||
|
||||
|
||||
|
||||
vec3 S = SunCloud_lighting + AmbientCloud_Lighting ; // combine all the combined
|
||||
|
||||
vec3 Sint= (S - S * exp(-mult*muE)) / muE;
|
||||
color += max(muS*Sint*total_extinction,0.0);
|
||||
total_extinction *= max(exp(-muE*mult),0);
|
||||
|
||||
if (total_extinction < 1e-5) break;
|
||||
}
|
||||
progress_view += dV_view;
|
||||
}
|
||||
|
||||
// vec3 normView = normalize(dV_view);
|
||||
// // Assume fog color = sky gradient at long distance
|
||||
// vec3 fogColor = skyFromTex(normView, colortex4)/150.;
|
||||
// float dist = (cloud_height - cameraPosition.y)/normalize(dV_view).y;
|
||||
// float fog = exp(-dist/15000.0*(1.0+rainCloudwetness*8.));
|
||||
|
||||
float cosY = normalize(dV_view).y;
|
||||
return mix(vec4(color,clamp(total_extinction*(1.0+1/250.)-1/250.,0.0,1.0)),vec4(0.0,0.0,0.0,1.0), 1-smoothstep(0.02,0.15,cosY));
|
||||
}
|
118
shaders/world1/lib/volumetricFog.glsl
Normal file
118
shaders/world1/lib/volumetricFog.glsl
Normal file
@ -0,0 +1,118 @@
|
||||
#define VL_SAMPLES2 6 //[4 6 8 10 12 14 16 20 24 30 40 50]
|
||||
#define Ambient_Mult 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0 5.0 6.0 10.0]
|
||||
#define SEA_LEVEL 70 //[0 10 20 30 40 50 60 70 80 90 100 110 120 130 150 170 190] //The volumetric light uses an altitude-based fog density, this is where fog density is the highest, adjust this value according to your world.
|
||||
#define ATMOSPHERIC_DENSITY 1.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 4.0 5.0 7.5 10.0 12.5 15.0 20.]
|
||||
#define fog_mieg1 0.40 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
|
||||
#define fog_mieg2 0.10 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
|
||||
#define fog_coefficientRayleighR 5.8 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
|
||||
#define fog_coefficientRayleighG 1.35 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
|
||||
#define fog_coefficientRayleighB 3.31 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
|
||||
|
||||
#define fog_coefficientMieR 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
|
||||
#define fog_coefficientMieG 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
|
||||
#define fog_coefficientMieB 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
|
||||
|
||||
#define Underwater_Fog_Density 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0]
|
||||
|
||||
float phaseRayleigh(float cosTheta) {
|
||||
const vec2 mul_add = vec2(0.1, 0.28) /acos(-1.0);
|
||||
return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation
|
||||
}
|
||||
float cloudVol2(in vec3 pos){
|
||||
|
||||
vec3 samplePos = pos*vec3(1.0,1./16.,1.0)+frameTimeCounter*vec3(0.5,0.,0.5)*5.;
|
||||
float coverage = mix(exp2(-(pos.y-SEA_LEVEL)*(pos.y-SEA_LEVEL)/10000.),1.0,rainStrength*0.5);
|
||||
float noise = densityAtPos(samplePos*12.);
|
||||
float unifCov = exp2(-max(pos.y-SEA_LEVEL,0.0)/50.);
|
||||
|
||||
float cloud = pow(clamp(coverage-noise-0.76,0.0,1.0),2.)*1200./0.23/(coverage+0.01)*VFAmount*600+unifCov*60.*fogAmount;
|
||||
|
||||
return cloud;
|
||||
}
|
||||
|
||||
mat2x3 getVolumetricRays(float dither,vec3 fragpos) {
|
||||
|
||||
//project pixel position into projected shadowmap space
|
||||
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
|
||||
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
|
||||
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
|
||||
|
||||
|
||||
|
||||
//project view origin into projected shadowmap space
|
||||
vec3 start = toShadowSpaceProjected(vec3(0.));
|
||||
|
||||
|
||||
//rayvector into projected shadow map space
|
||||
//we can use a projected vector because its orthographic projection
|
||||
//however we still have to send it to curved shadow map space every step
|
||||
vec3 dV = (fragposition-start);
|
||||
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
|
||||
|
||||
float maxLength = min(length(dVWorld),256.0)/length(dVWorld);
|
||||
dV *= maxLength;
|
||||
dVWorld *= maxLength;
|
||||
|
||||
//apply dither
|
||||
vec3 progress = start.xyz;
|
||||
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
|
||||
vec3 vL = vec3(0.);
|
||||
|
||||
float SdotV = dot(sunVec,normalize(fragpos))*lightCol.a;
|
||||
float dL = length(dVWorld);
|
||||
//Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx)
|
||||
float mie = max(phaseg(SdotV,fog_mieg1),1.0/13.0);
|
||||
float rayL = phaseRayleigh(SdotV);
|
||||
// wpos.y = clamp(wpos.y,0.0,1.0);
|
||||
|
||||
vec3 ambientCoefs = dVWorld/dot(abs(dVWorld),vec3(1.));
|
||||
|
||||
vec3 ambientLight = ambientUp*clamp(ambientCoefs.y,0.,1.);
|
||||
ambientLight += ambientDown*clamp(-ambientCoefs.y,0.,1.);
|
||||
ambientLight += ambientRight*clamp(ambientCoefs.x,0.,1.);
|
||||
ambientLight += ambientLeft*clamp(-ambientCoefs.x,0.,1.);
|
||||
ambientLight += ambientB*clamp(ambientCoefs.z,0.,1.);
|
||||
ambientLight += ambientF*clamp(-ambientCoefs.z,0.,1.);
|
||||
|
||||
vec3 skyCol0 = ambientLight*2.*eyeBrightnessSmooth.y/vec3(240.)*Ambient_Mult*2.0/PI;
|
||||
vec3 sunColor = lightCol.rgb;
|
||||
|
||||
vec3 rC = vec3(fog_coefficientRayleighR*1e-6, fog_coefficientRayleighG*1e-5, fog_coefficientRayleighB*1e-5);
|
||||
vec3 mC = vec3(fog_coefficientMieR*1e-6, fog_coefficientMieG*1e-6, fog_coefficientMieB*1e-6);
|
||||
|
||||
|
||||
float mu = 1.0;
|
||||
float muS = 1.0*mu;
|
||||
vec3 absorbance = vec3(1.0);
|
||||
float expFactor = 11.0;
|
||||
for (int i=0;i<VL_SAMPLES2;i++) {
|
||||
float d = (pow(expFactor, float(i+dither)/float(VL_SAMPLES2))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
||||
float dd = pow(expFactor, float(i+dither)/float(VL_SAMPLES2)) * log(expFactor) / float(VL_SAMPLES2)/(expFactor-1.0);
|
||||
progress = start.xyz + d*dV;
|
||||
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
|
||||
//project into biased shadowmap space
|
||||
float distortFactor = calcDistort(progress.xy);
|
||||
vec3 pos = vec3(progress.xy*distortFactor, progress.z);
|
||||
float densityVol = cloudVol2(progressW);
|
||||
float sh = 1.0;
|
||||
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
|
||||
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
|
||||
sh = shadow2D( shadow, pos).x;
|
||||
}
|
||||
//Water droplets(fog)
|
||||
float density = densityVol*ATMOSPHERIC_DENSITY*mu*200.;
|
||||
//Just air
|
||||
vec2 airCoef = exp2(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0))*6.0;
|
||||
|
||||
//Pbr for air, yolo mix between mie and rayleigh for water droplets
|
||||
vec3 rL = rC*(airCoef.x+density*0.15);
|
||||
vec3 m = (airCoef.y+density*1.85)*mC;
|
||||
vec3 vL0 = sunColor*sh*(rayL*rL+m*mie) + skyCol0*(rL+m);
|
||||
vL += (vL0 - vL0 * exp(-dot(rL+m, vec3(0.22,0.71,0.07))*dd*dL)) / (dot(rL+m, vec3(0.22,0.71,0.07))+0.00000001)*absorbance;
|
||||
absorbance *= clamp(exp(-dot(rL+m, vec3(0.22,0.71,0.07))*dd*dL),0.0,1.0);
|
||||
}
|
||||
return mat2x3(vL,absorbance);
|
||||
|
||||
|
||||
|
||||
}
|
38
shaders/world1/lib/waterBump.glsl
Normal file
38
shaders/world1/lib/waterBump.glsl
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
float getWaterHeightmap(vec2 posxz, float waveM, float waveZ, float iswater) {
|
||||
vec2 pos = posxz*4.0;
|
||||
float moving = clamp(iswater*2.-1.0,0.0,1.0);
|
||||
vec2 movement = vec2(-0.02*frameTimeCounter*moving);
|
||||
float caustic = 0.0;
|
||||
float weightSum = 0.0;
|
||||
float radiance = 2.39996;
|
||||
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
|
||||
for (int i = 0; i < 4; i++){
|
||||
vec2 displ = texture2D(noisetex, pos/32.0/1.74/1.74 + movement).bb*2.0-1.0;
|
||||
pos = rotationMatrix * pos;
|
||||
caustic += sin(dot((pos+vec2(moving*frameTimeCounter))/1.74/1.74 * exp2(0.8*i) + displ*2.0,vec2(0.5)))*exp2(-0.8*i);
|
||||
weightSum += exp2(-i);
|
||||
}
|
||||
return caustic * weightSum / 300.;
|
||||
}
|
||||
vec3 getWaveHeight(vec2 posxz, float iswater){
|
||||
|
||||
vec2 coord = posxz;
|
||||
|
||||
float deltaPos = 0.25;
|
||||
|
||||
float waveZ = mix(20.0,0.25,iswater);
|
||||
float waveM = mix(0.0,4.0,iswater);
|
||||
|
||||
float h0 = getWaterHeightmap(coord, waveM, waveZ, iswater);
|
||||
float h1 = getWaterHeightmap(coord + vec2(deltaPos,0.0), waveM, waveZ, iswater);
|
||||
float h3 = getWaterHeightmap(coord + vec2(0.0,deltaPos), waveM, waveZ, iswater);
|
||||
|
||||
|
||||
float xDelta = ((h1-h0))/deltaPos*2.;
|
||||
float yDelta = ((h3-h0))/deltaPos*2.;
|
||||
|
||||
vec3 wave = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0)));
|
||||
|
||||
return wave;
|
||||
}
|
21
shaders/world1/lib/waterOptions.glsl
Normal file
21
shaders/world1/lib/waterOptions.glsl
Normal file
@ -0,0 +1,21 @@
|
||||
#define Dirt_Amount 0.14 //How much dirt there is in water [0.0 0.04 0.08 0.12 0.16 0.2 0.24 0.28 0.32 0.36 0.4 0.44 0.48 0.52 0.56 0.6 0.64 0.68 0.72 0.76 0.8 0.84 0.88 0.92 0.96 1.0 1.04 1.08 1.12 1.16 1.2 1.24 1.28 1.32 1.36 1.4 1.44 1.48 1.52 1.56 1.6 1.64 1.68 1.72 1.76 1.8 1.84 1.88 1.92 1.96 2.0 ]
|
||||
|
||||
#define Dirt_Scatter_R 0.6 //How much dirt diffuses red [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
#define Dirt_Scatter_G 0.6 //How much dirt diffuses green [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
#define Dirt_Scatter_B 0.6 //How much dirt diffuses blue [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
|
||||
#define Dirt_Absorb_R 1.65 //How much dirt absorbs red [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
|
||||
#define Dirt_Absorb_G 1.85 //How much dirt absorbs green [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
|
||||
#define Dirt_Absorb_B 2.05 //How much dirt absorbs blue [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
|
||||
|
||||
#define Water_Absorb_R 0.2629 //How much water absorbs red [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
|
||||
#define Water_Absorb_G 0.0565 //How much water absorbs green [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
|
||||
#define Water_Absorb_B 0.01011 //How much water absorbs blue [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
|
||||
|
||||
#define Dirt_Mie_Phase 0.4 //Values close to 1 will create a strong peak around the sun and weak elsewhere, values close to 0 means uniform fog. [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
|
||||
|
||||
#define rayMarchSampleCount 2 //Number of samples used for the volumetric underwater fog [1 2 3 4 6 8 12 16 32 64]
|
||||
|
||||
#define Water_Top_Layer 62.90 // When under water and when lightMapDepthEstimate is turned off. Assumes the top layer of the water is at this height (minecraft y position) for underwater lighting calculations. If not set correctly, underwater will look incorrect.[0.90 1.90 2.90 3.90 4.90 5.90 6.90 7.90 8.90 9.90 10.90 11.90 12.90 13.90 14.90 15.90 16.90 17.90 18.90 19.90 20.90 21.90 22.90 23.90 24.90 25.90 26.90 27.90 28.90 29.90 30.90 31.90 32.90 33.90 34.90 35.90 36.90 37.90 38.90 39.90 40.90 41.90 42.90 43.90 44.90 45.90 46.90 47.90 48.90 49.90 50.90 51.90 52.90 53.90 54.90 55.90 56.90 57.90 58.90 59.90 60.90 61.90 62.90 63.90 64.90 65.90 66.90 67.90 68.90 69.90 70.90 71.90 72.90 73.90 74.90 75.90 76.90 77.90 78.90 79.90 80.90 81.90 82.90 83.90 84.90 85.90 86.90 87.90 88.90 89.90 90.90 91.90 92.90 93.90 94.90 95.90 96.90 97.90 98.90 99.90 100.90 101.90 102.90 103.90 104.90 105.90 106.90 107.90 108.90 109.90 110.90 111.90 112.90 113.90 114.90 115.90 116.90 117.90 118.90 119.90 120.90 121.90 122.90 123.90 124.90 125.90 126.90 127.90 128.90 129.90 130.90 131.90 132.90 133.90 134.90 135.90 136.90 137.90 138.90 139.90 140.90 141.90 142.90 143.90 144.90 145.90 146.90 147.90 148.90 149.90 150.90 151.90 152.90 153.90 154.90 155.90 156.90 157.90 158.90 159.90 160.90 161.90 162.90 163.90 164.90 165.90 166.90 167.90 168.90 169.90 170.90 171.90 172.90 173.90 174.90 175.90 176.90 177.90 178.90 179.90 180.90 181.90 182.90 183.90 184.90 185.90 186.90 187.90 188.90 189.90 190.90 191.90 192.90 193.90 194.90 195.90 196.90 197.90 198.90 199.90]
|
||||
|
||||
//#define lightMapDepthEstimation // If turned off, will use the player eye position and the Water_Top_Layer option to determine how deep the player is in water. It can look wrong in a lot of cases, and using minecraft light levels instead improves this but will look worse in oceans, lakes and rivers.
|
Reference in New Issue
Block a user