first commit
This commit is contained in:
commit
0f859671ea
308 files changed
+18617
No files matched your search
@@ -0,0 +1,47 @@
|
||||
vec3 GetN(int idx) {
|
||||
if (idx == 230) return vec3(2.9114, 2.9497, 2.5845);
|
||||
if (idx == 231) return vec3(0.18299, 0.42108, 1.3734);
|
||||
if (idx == 232) return vec3(1.3456, 0.96521, 0.61722);
|
||||
if (idx == 233) return vec3(3.1071, 3.1812, 2.3230);
|
||||
if (idx == 234) return vec3(0.27105, 0.67693, 1.3164);
|
||||
if (idx == 235) return vec3(1.9100, 1.8300, 1.4400);
|
||||
if (idx == 236) return vec3(2.3757, 2.0847, 1.8453);
|
||||
if (idx == 237) return vec3(0.15943, 0.14512, 0.13547);
|
||||
return vec3(0.0);
|
||||
}
|
||||
|
||||
vec3 GetK(int idx) {
|
||||
if (idx == 230) return vec3(3.0893, 2.9318, 2.7670);
|
||||
if (idx == 231) return vec3(3.4242, 2.3459, 1.7704);
|
||||
if (idx == 232) return vec3(7.4746, 6.3995, 5.3031);
|
||||
if (idx == 233) return vec3(3.3314, 3.3291, 3.1350);
|
||||
if (idx == 234) return vec3(3.6092, 2.6248, 2.2921);
|
||||
if (idx == 235) return vec3(3.5100, 3.4000, 3.1800);
|
||||
if (idx == 236) return vec3(4.2655, 3.7153, 3.1365);
|
||||
if (idx == 237) return vec3(3.9291, 3.1900, 2.3808);
|
||||
return vec3(1.0);
|
||||
}
|
||||
|
||||
vec3 ComplexFresnel(float fresnel, float f0) {
|
||||
int metalidx = int(f0 * 255.0);
|
||||
vec3 k = GetK(metalidx);
|
||||
vec3 n = GetN(metalidx);
|
||||
float f = 1.0 - fresnel;
|
||||
|
||||
vec3 k2 = k * k;
|
||||
vec3 n2 = n * n;
|
||||
float f2 = f * f;
|
||||
|
||||
vec3 rs_num = n2 + k2 - 2 * n * f + f2;
|
||||
vec3 rs_den = n2 + k2 + 2 * n * f + f2;
|
||||
vec3 rs = rs_num / rs_den;
|
||||
|
||||
vec3 rp_num = (n2 + k2) * f2 - 2 * n * f + 1;
|
||||
vec3 rp_den = (n2 + k2) * f2 + 2 * n * f + 1;
|
||||
vec3 rp = rp_num / rp_den;
|
||||
|
||||
vec3 fresnel3 = clamp(0.5 * (rs + rp), vec3(0.0), vec3(1.0));
|
||||
fresnel3 *= fresnel3;
|
||||
|
||||
return fresnel3;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
float GetPuddles(vec3 worldPos, vec2 coord, float skylight, float NoU, float wetness) {
|
||||
if (wetness < 0.001) return 0.0;
|
||||
|
||||
worldPos = (worldPos + cameraPosition) * 0.005;
|
||||
|
||||
float height = texture2DGradARB(normals, coord, dcdx, dcdy).a;
|
||||
height = mix(1.0, height, PARALLAX_DEPTH);
|
||||
height = smoothstep(1.0, 0.95, height) * 0.1 - 0.05;
|
||||
float noise = texture2D(noisetex, worldPos.xz * 0.5 ).r * 0.375;
|
||||
noise+= texture2D(noisetex, worldPos.xz * 0.125).r * 0.625;
|
||||
noise = noise + height + (wetness * REFLECTION_RAIN_AMOUNT - 0.5);
|
||||
|
||||
float puddles = smoothstep(0.4, 0.6, noise);
|
||||
|
||||
#ifdef WEATHER_PERBIOME
|
||||
float weatherWeight = isCold + isDesert + isMesa + isSavanna;
|
||||
puddles *= 1.0 - weatherWeight;
|
||||
#endif
|
||||
|
||||
puddles *= clamp(skylight * 32.0 - 31.0, 0.0, 1.0) * clamp(NoU, 0.0, 1.0);
|
||||
|
||||
return puddles;
|
||||
}
|
||||
|
||||
float rand(vec2 worldPos){
|
||||
return fract(sin(dot(worldPos, vec2(12.9898, 4.1414))) * 43758.5453);
|
||||
}
|
||||
|
||||
vec2 getpos(vec2 i){
|
||||
return vec2(rand(i), rand(i + 1.0)) * 0.5 + 0.25;
|
||||
}
|
||||
|
||||
float GetRipple(vec3 worldPos, vec2 offset) {
|
||||
vec2 ppos = worldPos.xz + offset * 0.1 + frametime * 0.01;
|
||||
ppos = vec2(ppos.x * 0.7 + ppos.y * 0.7, ppos.x * -0.7 + ppos.y * 0.7) * 0.8;
|
||||
vec2 ppossh = ppos + vec2(fract(0.618 * floor(ppos.y)) * sin(frametime * 0.05), 0.0);
|
||||
vec2 pposfr = fract(ppossh);
|
||||
vec2 pposfl = floor(ppossh);
|
||||
|
||||
float val = texture2D(noisetex, ppos / 64.0 + frametime * 0.007).r * 0.125;
|
||||
val += texture2D(noisetex, ppos / 64.0 - frametime * 0.005).r * 0.125;
|
||||
|
||||
float seed = rand(pposfl);
|
||||
float rippleTime = frametime * 1.7 + fract(seed * 1.618);
|
||||
float rippleSeed = seed + floor(rippleTime) * 1.618;
|
||||
vec2 ripplePos = getpos(pposfl + rippleSeed);
|
||||
float ripple = clamp(1.0 - 4.0 * length(pposfr - ripplePos), 0.0, 1.0);
|
||||
ripple = clamp(ripple + fract(rippleTime) - 1.0, 0.0, 1.0);
|
||||
ripple = sin(min(ripple * 6.0 * 3.1415, 3.0 * 3.1415)) * pow(1.0 - fract(rippleTime), 2.0);
|
||||
val += ripple * 0.3;
|
||||
|
||||
//if(pposfr.x < 0.01 || pposfr.y < 0.01) val += 0.85;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
vec3 GetPuddleNormal(vec3 worldPos, vec3 viewPos, mat3 tbn) {
|
||||
vec3 puddlePos = worldPos + cameraPosition;
|
||||
float normalOffset = 0.1;
|
||||
|
||||
float fresnel = pow(clamp(1.0 + dot(normalize(normal), normalize(viewPos)), 0.0, 1.0), 7.5);
|
||||
float normalStrength = 0.35 * (1.0 - fresnel);
|
||||
|
||||
float h1 = GetRipple(puddlePos, vec2( normalOffset, 0.0));
|
||||
float h2 = GetRipple(puddlePos, vec2(-normalOffset, 0.0));
|
||||
float h3 = GetRipple(puddlePos, vec2(0.0, normalOffset));
|
||||
float h4 = GetRipple(puddlePos, vec2(0.0, -normalOffset));
|
||||
|
||||
float xDelta = (h2 - h1) / normalOffset;
|
||||
float yDelta = (h4 - h3) / normalOffset;
|
||||
|
||||
vec3 normalMap = vec3(xDelta, yDelta, 1.0 - (xDelta * xDelta + yDelta * yDelta));
|
||||
normalMap = normalMap * normalStrength + vec3(0.0, 0.0, 1.0 - normalStrength);
|
||||
|
||||
return clamp(normalize(normalMap * tbn), vec3(-1.0), vec3(1.0));
|
||||
}
|
||||
|
||||
void ApplyPuddleToMaterial(float puddles, inout vec4 albedo, inout float smoothness, inout float f0, float porosity) {
|
||||
float puddleSmoothness = sqrt(1.0 - 0.75 * porosity);
|
||||
float puddleDarkening = (0.5 * porosity + 0.15);
|
||||
|
||||
smoothness = mix(smoothness, 1.0, puddles * puddleSmoothness);
|
||||
f0 = max(f0, puddles * 0.02);
|
||||
|
||||
albedo.rgb *= 1.0 - (puddles * puddleDarkening);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
vec3 nvec3(vec4 pos) {
|
||||
return pos.xyz/pos.w;
|
||||
}
|
||||
|
||||
vec4 nvec4(vec3 pos) {
|
||||
return vec4(pos.xyz, 1.0);
|
||||
}
|
||||
|
||||
float cdist(vec2 coord) {
|
||||
return max(abs(coord.x - 0.5), abs(coord.y - 0.5)) * 1.85;
|
||||
}
|
||||
|
||||
#if REFLECTION_MODE == 0
|
||||
float errMult = 1.0;
|
||||
#elif REFLECTION_MODE == 1
|
||||
float errMult = 1.3;
|
||||
#else
|
||||
float errMult = 1.6;
|
||||
#endif
|
||||
|
||||
vec4 Raytrace(sampler2D depthtex, vec3 viewPos, vec3 normal, float dither, out float border,
|
||||
int maxf, float stp, float ref, float inc) {
|
||||
vec3 pos = vec3(0.0);
|
||||
float dist = 0.0;
|
||||
|
||||
#ifdef TAA
|
||||
#if TAA_MODE == 0
|
||||
dither = fract(dither + frameCounter * 0.618);
|
||||
#else
|
||||
dither = fract(dither + frameCounter * 0.5);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec3 start = viewPos + normal * 0.075;
|
||||
|
||||
vec3 vector = stp * reflect(normalize(viewPos), normalize(normal));
|
||||
viewPos += vector;
|
||||
vec3 tvector = vector;
|
||||
|
||||
int sr = 0;
|
||||
|
||||
for(int i = 0; i < 30; i++) {
|
||||
pos = nvec3(gbufferProjection * nvec4(viewPos)) * 0.5 + 0.5;
|
||||
if (pos.x < -0.05 || pos.x > 1.05 || pos.y < -0.05 || pos.y > 1.05) break;
|
||||
|
||||
vec3 rfragpos = vec3(pos.xy, texture2D(depthtex,pos.xy).r);
|
||||
rfragpos = nvec3(gbufferProjectionInverse * nvec4(rfragpos * 2.0 - 1.0));
|
||||
dist = abs(dot(normalize(start - rfragpos), normal));
|
||||
|
||||
float err = length(viewPos - rfragpos);
|
||||
float lVector = length(vector) * pow(length(tvector), 0.1) * errMult;
|
||||
if (err < lVector) {
|
||||
sr++;
|
||||
if (sr >= maxf) break;
|
||||
tvector -= vector;
|
||||
vector *= ref;
|
||||
}
|
||||
vector *= inc;
|
||||
tvector += vector;
|
||||
viewPos = start + tvector * (0.025 * dither + 0.975);
|
||||
}
|
||||
|
||||
border = cdist(pos.st);
|
||||
|
||||
#ifdef REFLECTION_PREVIOUS
|
||||
//Previous frame reprojection from Chocapic13
|
||||
vec4 viewPosPrev = gbufferProjectionInverse * vec4(pos * 2.0 - 1.0, 1.0);
|
||||
viewPosPrev /= viewPosPrev.w;
|
||||
|
||||
viewPosPrev = gbufferModelViewInverse * viewPosPrev;
|
||||
|
||||
vec4 previousPosition = viewPosPrev + vec4(cameraPosition - previousCameraPosition, 0.0);
|
||||
previousPosition = gbufferPreviousModelView * previousPosition;
|
||||
previousPosition = gbufferPreviousProjection * previousPosition;
|
||||
pos.xy = previousPosition.xy / previousPosition.w * 0.5 + 0.5;
|
||||
#endif
|
||||
|
||||
return vec4(pos, dist);
|
||||
}
|
||||
|
||||
vec4 BasicReflect(vec3 viewPos, vec3 normal, out float border) {
|
||||
vec3 reflectedViewPos = reflect(viewPos, normal) + normal * dot(viewPos, normal) * 0.5;
|
||||
|
||||
vec3 pos = nvec3(gbufferProjection * nvec4(reflectedViewPos)) * 0.5 + 0.5;
|
||||
|
||||
border = cdist(pos.st);
|
||||
|
||||
return vec4(pos, 0.0);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifdef REFLECTION_PREVIOUS
|
||||
#define colortexR colortex5
|
||||
#else
|
||||
#define colortexR colortex0
|
||||
#endif
|
||||
|
||||
vec4 RoughReflection(vec3 viewPos, vec3 normal, float dither, float smoothness) {
|
||||
vec4 color = vec4(0.0);
|
||||
float border = 0.0;
|
||||
|
||||
vec4 pos = Raytrace(depthtex0, viewPos, normal, dither, border, 6, 0.5, 0.1, 1.8);
|
||||
border = clamp(13.333 * (1.0 - border) * (0.9 * smoothness + 0.1), 0.0, 1.0);
|
||||
|
||||
float fovScale = gbufferProjection[1][1] / 1.37;
|
||||
|
||||
if (pos.z < 1.0 - 1e-5) {
|
||||
#ifdef REFLECTION_ROUGH
|
||||
float dist = 0.03125 * pow(1.0 - smoothness, 2.0) * pos.a * fovScale;
|
||||
float lod = log2(viewHeight * dist);
|
||||
#else
|
||||
float lod = 0.0;
|
||||
#endif
|
||||
|
||||
if (lod < 1.0) {
|
||||
color.a = texture2DLod(colortex6, pos.st, 1.0).b;
|
||||
if (color.a > 0.001) color.rgb = texture2DLod(colortexR, pos.st, 1.0).rgb;
|
||||
#ifdef REFLECTION_PREVIOUS
|
||||
color.rgb = pow(color.rgb * 2.0, vec3(8.0));
|
||||
#else
|
||||
#if ALPHA_BLEND == 0
|
||||
color.rgb = pow(color.rgb, vec3(2.2));
|
||||
#endif
|
||||
#endif
|
||||
}else{
|
||||
for(int i = -2; i <= 2; i++) {
|
||||
for(int j = -2; j <= 2; j++) {
|
||||
vec2 refOffset = vec2(i, j) * exp2(lod - 1.0) / vec2(viewWidth, viewHeight);
|
||||
vec2 refCoord = pos.st + refOffset;
|
||||
float alpha = texture2DLod(colortex6, refCoord, lod).b;
|
||||
if (alpha > 0.001) {
|
||||
vec3 ssrSample = texture2DLod(colortexR, refCoord, max(lod - 1.0, 0.0)).rgb;
|
||||
|
||||
#ifdef REFLECTION_PREVIOUS
|
||||
ssrSample = pow(ssrSample * 2.0, vec3(8.0));
|
||||
#else
|
||||
#if ALPHA_BLEND == 0
|
||||
ssrSample = pow(ssrSample, vec3(2.2));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
color.rgb += ssrSample;
|
||||
color.a += alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
color /= 25.0;
|
||||
}
|
||||
|
||||
//Fog(color.rgb, (gbufferProjectionInverse * pos).xyz);
|
||||
|
||||
color *= color.a;
|
||||
color.a = clamp(color.a * 2.0 - 1.0, 0.0, 1.0) * border;
|
||||
// color.a = pos.a * float(border > 0.0);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
vec4 SimpleReflection(vec3 viewPos, vec3 normal, float dither, out float reflectionMask) {
|
||||
vec4 color = vec4(0.0);
|
||||
float border = 0.0;
|
||||
reflectionMask = 0.0;
|
||||
|
||||
vec4 pos = Raytrace(depthtex1, viewPos, normal, dither, border, 4, 1.0, 0.1, 2.0);
|
||||
border = clamp(13.333 * (1.0 - border), 0.0, 1.0);
|
||||
|
||||
#ifdef REFLECTION_SKYBOX
|
||||
float zThreshold = 1.0 + 1e-5;
|
||||
#else
|
||||
float zThreshold = 1.0;
|
||||
#endif
|
||||
|
||||
if (pos.z < zThreshold) {
|
||||
#if MC_VERSION > 10800
|
||||
color = texture2D(gaux2, pos.st);
|
||||
#else
|
||||
color = texture2DLod(gaux2, pos.st, 0);
|
||||
#endif
|
||||
reflectionMask = color.a;
|
||||
|
||||
#ifdef REFLECTION_SKYBOX
|
||||
color.a = 1.0;
|
||||
#endif
|
||||
|
||||
color.a *= border;
|
||||
reflectionMask *= border;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 DHReflection(vec3 viewPos, vec3 normal, float dither, out float reflectionMask) {
|
||||
vec4 color = vec4(0.0);
|
||||
float border = 0.0;
|
||||
reflectionMask = 0.0;
|
||||
|
||||
vec4 pos = BasicReflect(viewPos, normal, border);
|
||||
border = clamp(13.333 * (1.0 - border), 0.0, 1.0);
|
||||
|
||||
#ifdef REFLECTION_SKYBOX
|
||||
float zThreshold = 1.0 + 1e-5;
|
||||
#else
|
||||
float zThreshold = 1.0;
|
||||
#endif
|
||||
|
||||
if (pos.z < zThreshold) {
|
||||
#if MC_VERSION > 10800
|
||||
color = texture2D(gaux2, pos.st);
|
||||
#else
|
||||
color = texture2DLod(gaux2, pos.st, 0);
|
||||
#endif
|
||||
reflectionMask = color.a;
|
||||
|
||||
#ifdef REFLECTION_SKYBOX
|
||||
color.a = 1.0;
|
||||
#endif
|
||||
|
||||
color.a *= border;
|
||||
reflectionMask *= border;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
Reference in new issue
Block a user