add floodfill light propagation in vl fog. fix up nether and end shaders. tweaked shadows some. improved filtering for shadows/ssao, and VL fog. improved the "clouds intersect terrain" setting

This commit is contained in:
Xonk
2024-06-19 21:44:21 -04:00
parent afe1a2f30e
commit 56ad3b059d
33 changed files with 843 additions and 771 deletions

View File

@ -118,7 +118,7 @@ void main() {
vec2 PackLightmaps = lightmapCoords;
// PackLightmaps.y *= 1.05;
// PackLightmaps = min(max(PackLightmaps - 0.001*blueNoise(),0.0)*1.002,1.0);
PackLightmaps = min(max(PackLightmaps,0.0)*1.05,1.0);
vec4 data1 = clamp( encode(normals.xyz, PackLightmaps), 0.0, 1.0);

View File

@ -168,7 +168,7 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater){
float quality = mix(15,SSR_STEPS,fresnel);
float quality = mix(5,SSR_STEPS,fresnel);
vec3 clipPosition = DH_toClipSpace3(position);
float rayLength = ((position.z + dir.z * dhFarPlane*sqrt(3.)) > -dhNearPlane) ?
(-dhNearPlane - position.z) / dir.z : dhFarPlane*sqrt(3.);

View File

@ -432,6 +432,14 @@ void main() {
#endif
#endif
#ifdef NETHER_SHADER
AmbientLightColor = skyCloudsFromTexLOD2(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 30.0;
#endif
#ifdef END_SHADER
AmbientLightColor = vec3(0.3,0.6,1.0) * 0.5;
#endif
#ifdef IS_LPV_ENABLED
vec3 lpvPos = GetLpvPosition(feetPlayerPos);

View File

@ -436,65 +436,6 @@ void Emission(
if( Emission < 254.5/255.0) Lighting = mix(Lighting, Albedo * Emissive_Brightness * autoBrightnessAdjust * 0.1, pow(Emission, Emissive_Curve)); // old method.... idk why
}
/*
uniform float viewWidth;
uniform float viewHeight;
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);
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
float fma(float a,float b,float c){
return a * b + c;
}
//// thank you Zombye | the paper: https://ggx-research.github.io/publication/2023/06/09/publication-ggx.html
vec3 SampleVNDFGGX(
vec3 viewerDirection, // Direction pointing towards the viewer, oriented such that +Z corresponds to the surface normal
vec2 alpha, // Roughness parameter along X and Y of the distribution
float xy // Pair of uniformly distributed numbers in [0, 1)
) {
// alpha *= alpha;
// Transform viewer direction to the hemisphere configuration
viewerDirection = normalize(vec3(alpha * viewerDirection.xy, viewerDirection.z));
// Sample a reflection direction off the hemisphere
const float tau = 6.2831853; // 2 * pi
float phi = tau * xy;
float cosTheta = fma(1.0 - xy, 1.0 + viewerDirection.z, -viewerDirection.z) ;
float sinTheta = sqrt(clamp(1.0 - cosTheta * cosTheta, 0.0, 1.0));
// xonk note, i dont know what im doing but this kinda does what i want so whatever
float attemptTailClamp = clamp(sinTheta,max(cosTheta-0.25,0), cosTheta);
float attemptTailClamp2 = clamp(cosTheta,max(sinTheta-0.25,0), sinTheta);
vec3 reflected = vec3(vec2(cos(phi), sin(phi)) * attemptTailClamp2, attemptTailClamp);
// vec3 reflected = vec3(vec2(cos(phi), sin(phi)) * sinTheta, cosTheta);
// Evaluate halfway direction
// This gives the normal on the hemisphere
vec3 halfway = reflected + viewerDirection;
// Transform the halfway direction back to hemiellispoid configuation
// This gives the final sampled normal
return normalize(vec3(alpha * halfway.xy, halfway.z));
}
*/
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -717,8 +658,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
vec3 AmbientLightColor = vec3(0.5,0.75,1.0) * 0.9 + 0.1;
AmbientLightColor *= clamp(1.5 + dot(worldSpaceNormal, normalize(feetPlayerPos))*0.5,0,2);
// vec3 AmbientLightColor = vec3(0.5,0.75,1.0) * 0.9 + 0.1;
// AmbientLightColor *= clamp(1.5 + dot(worldSpaceNormal, normalize(feetPlayerPos))*0.5,0,2);
vec3 AmbientLightColor = vec3(0.3,0.6,1.0) * 0.5;
AmbientLightColor = AmbientLightColor + 0.7 * AmbientLightColor * dot(worldSpaceNormal, normalize(feetPlayerPos));
#endif
#ifdef IS_LPV_ENABLED

View File

@ -476,6 +476,10 @@ vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float refer
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
// ivec2(-1,-1),
// ivec2( 1, 1),
// ivec2(-1, 1),
// ivec2( 1,-1)
);
#ifdef DISTANT_HORIZONS
@ -487,9 +491,11 @@ vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float refer
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
RESULT += texelFetch2D(tex, posColor + pos, 0);
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
ivec2 radius = getRadius[i] ;
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
@ -515,10 +521,10 @@ void BilateralUpscale_REUSE_Z(sampler2D tex1, sampler2D tex2, sampler2D depth, v
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[4] = ivec2[](
ivec2(-1,-1),
ivec2(-1, 0),
ivec2( 0, 0),
ivec2( 0,-1)
ivec2(-1,-1),
ivec2( 1,-1),
ivec2( 1, 1),
ivec2(-1, 1)
);
#ifdef DISTANT_HORIZONS
@ -529,7 +535,65 @@ void BilateralUpscale_REUSE_Z(sampler2D tex1, sampler2D tex2, sampler2D depth, v
vec3 shadow_RESULT = vec3(0.0);
vec2 ssao_RESULT = vec2(0.0);
vec4 fog_RESULT = vec4(0.0);
float SUM = 1.0;
#ifdef LIGHTING_EFFECTS_BLUR_FILTER
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
#ifdef Variable_Penumbra_Shadows
shadow_RESULT += texelFetch2D(tex1, posColor + radius + pos, 0).rgb * EDGES;
#endif
#if indirect_effect == 1
ssao_RESULT += texelFetch2D(tex2, posColor + radius + pos, 0).rg * EDGES;
#endif
SUM += EDGES;
}
#endif
#ifdef Variable_Penumbra_Shadows
shadow_RESULT += texture2D(tex1, gl_FragCoord.xy*texelSize).rgb;
filteredShadow = shadow_RESULT/SUM;
#endif
#if indirect_effect == 1
ssao_RESULT += texture2D(tex2, gl_FragCoord.xy*texelSize).rg;
ambientEffects = ssao_RESULT/SUM;
#endif
}
vec4 BilateralUpscale_VLFOG(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[5] = ivec2[](
ivec2(-1,-1),
ivec2( 1, 1),
ivec2(-1, 1),
ivec2( 1,-1),
ivec2( 0, 0)
);
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.01;
#else
float diffThreshold = zMults.x;
#endif
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 4; i++) {
@ -543,22 +607,13 @@ void BilateralUpscale_REUSE_Z(sampler2D tex1, sampler2D tex2, sampler2D depth, v
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
// #ifdef Variable_Penumbra_Shadows
shadow_RESULT += texelFetch2D(tex1, posColor + radius + pos, 0).rgb * EDGES;
// #endif
#if indirect_effect == 1
ssao_RESULT += texelFetch2D(tex2, posColor + radius + pos, 0).rg * EDGES;
#endif
SUM += EDGES;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
SUM += EDGES;
}
// #ifdef Variable_Penumbra_Shadows
filteredShadow = shadow_RESULT/SUM;
// #endif
#if indirect_effect == 1
ambientEffects = ssao_RESULT/SUM;
#endif
return RESULT / SUM;
}
#ifdef OVERWORLD_SHADER
@ -617,8 +672,8 @@ float ComputeShadowMap(in vec3 projectedShadowPosition, float distortFactor, flo
#endif
// return maxDistFade;
return mix(1.0, shadowmap / samples, maxDistFade);
return shadowmap / samples;
// return mix(1.0, shadowmap / samples, maxDistFade);
}
#endif
@ -632,7 +687,7 @@ float CustomPhase(float LightPos){
return Final;
}
vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, float lightPos, float shadows, bool distantSSS){
vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, float lightPos, float shadows, float distantSSS){
Scattering *= sss_density_multiplier;
@ -641,7 +696,7 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa
float scatterDepth = max(1.0 - Scattering/density,0.0);
scatterDepth = exp((1.0-scatterDepth) * -7.0);
if(distantSSS) scatterDepth = exp(Scattering * -10.0);
scatterDepth = mix(exp(Scattering * -10.0), scatterDepth, distantSSS);
// this is for SSS when there is no shadow blocker depth
#if defined BASIC_SHADOW_FILTER && defined Variable_Penumbra_Shadows
@ -851,9 +906,9 @@ void main() {
vec2 SSAO_SSS = vec2(1.0);
#if defined DISTANT_HORIZONS && defined DH_AMBIENT_OCCLUSION
BilateralUpscale_REUSE_Z(colortex3, colortex14, colortex12, gl_FragCoord.xy, DH_mixedLinearZ, SSAO_SSS, filteredShadow, hand);
BilateralUpscale_REUSE_Z(colortex3, colortex14, colortex12, gl_FragCoord.xy-1.5, DH_mixedLinearZ, SSAO_SSS, filteredShadow, hand);
#else
BilateralUpscale_REUSE_Z(colortex3, colortex14, depthtex0, gl_FragCoord.xy, ld(z0), SSAO_SSS, filteredShadow, hand);
BilateralUpscale_REUSE_Z(colortex3, colortex14, depthtex0, gl_FragCoord.xy-1.5, ld(z0), SSAO_SSS, filteredShadow, hand);
#endif
float ShadowBlockerDepth = filteredShadow.y;
@ -936,8 +991,10 @@ void main() {
projectedShadowPosition = diagonal3_old(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
#if OPTIMIZED_SHADOW_DISTANCE > 0
float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / (shadowDistance+16),0.0)*5.0,1.0));
float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / (shadowDistance+16.0),0.0)*5.0,1.0));
float shadowMapFalloff2 = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / shadowDistance,0.0)*5.0,1.0));
#else
vec3 shadowEdgePos = projectedShadowPosition * vec3(0.4,0.4,0.5/6.0) + vec3(0.5,0.5,0.12);
float fadeLength = max((shadowDistance/256)*30,10.0);
@ -964,7 +1021,8 @@ void main() {
float ShadowAlpha = 0.0; // this is for subsurface scattering later.
Shadows = ComputeShadowMap(projectedShadowPosition, distortFactor, noise_2, filteredShadow.x, flatNormNdotL, shadowMapFalloff, DirectLightColor, ShadowAlpha, LabSSS > 0.0);
if(!isWater) Shadows *= mix(LM_shadowMapFallback, 1.0, shadowMapFalloff2);
// transition to fallback lightmap shadow mask.
Shadows = mix(isWater ? 1.0 : LM_shadowMapFallback, Shadows, shadowMapFalloff);
#ifdef OLD_LIGHTLEAK_FIX
if (isEyeInWater == 0) Shadows *= lightLeakFix; // light leak fix
@ -1022,6 +1080,8 @@ void main() {
/////////////////////////////////////////////////////////////////////////////////
#if defined OVERWORLD_SHADER && (indirect_effect == 0 || indirect_effect == 1)
Indirect_lighting = AmbientLightColor;
float allDirections = dot(abs(slopednormal),vec3(1.0));
vec3 ambientcoefs = slopednormal / allDirections;
float SkylightDir = ambientcoefs.y*1.5;
@ -1034,26 +1094,20 @@ void main() {
skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) ));
#endif
Indirect_lighting = AmbientLightColor * skylight;
Indirect_lighting *= skylight;
#endif
#ifdef NETHER_SHADER
// Indirect_lighting = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 15.0;
// vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb/ 30.0;
// vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb/ 30.0;
// up *= pow( max( slopednormal.y, 0), 2);
// down *= pow( max(-slopednormal.y, 0), 2);
// Indirect_lighting += up + down;
Indirect_lighting = vec3(0.05);
Indirect_lighting = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 30.0;
vec3 up = skyCloudsFromTexLOD2(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 30.0;
Indirect_lighting = mix(up, Indirect_lighting, clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0));
#endif
#ifdef END_SHADER
Indirect_lighting += (vec3(0.5,0.75,1.0) * 0.9 + 0.1) * 0.1;
Indirect_lighting *= clamp(1.5 + dot(normal, feetPlayerPos_normalized)*0.5,0,2);
Indirect_lighting = vec3(0.3,0.6,1.0) * 0.5;
Indirect_lighting = Indirect_lighting + 0.7*mix(-Indirect_lighting, Indirect_lighting * dot(slopednormal, feetPlayerPos_normalized), clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0));
#endif
#ifdef IS_LPV_ENABLED
@ -1165,7 +1219,6 @@ void main() {
if(entities) sunSSS_density = 0.0;
#endif
#ifdef SCREENSPACE_CONTACT_SHADOWS
vec2 SS_directLight = SSRT_Shadows(toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth1), isDHrange, normalize(WsunVec*mat3(gbufferModelViewInverse)), interleaved_gradientNoise(), sunSSS_density > 0.0 && shadowMapFalloff2 < 1.0, hand);
@ -1174,12 +1227,12 @@ void main() {
// combine shadowmap blocker depth with a minumum determined by the screenspace shadows, starting after the shadowmap ends
ShadowBlockerDepth = mix(SS_directLight.g, ShadowBlockerDepth, shadowMapFalloff2);
// ShadowBlockerDepth = SS_directLight.g;
#endif
Direct_SSS = SubsurfaceScattering_sun(albedo, ShadowBlockerDepth, sunSSS_density, clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), SSS_shadow, shadowMapFalloff2 < 1.0);
Direct_SSS *= mix(LM_shadowMapFallback, 1.0, shadowMapFalloff2);
Direct_SSS = SubsurfaceScattering_sun(albedo, ShadowBlockerDepth, sunSSS_density, clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), SSS_shadow, shadowMapFalloff2);
// Direct_SSS = vec3(1.0);
if (isEyeInWater == 0) Direct_SSS *= lightLeakFix;
#ifndef SCREENSPACE_CONTACT_SHADOWS
@ -1206,7 +1259,7 @@ void main() {
#ifdef OVERWORLD_SHADER
Direct_lighting = max(DirectLightColor * NdotL * Shadows, DirectLightColor * Direct_SSS);
// Direct_lighting = 0.5 + DirectLightColor * exp(-7*SS_directLight.g);
// Direct_lighting = DirectLightColor * Direct_SSS;
#endif
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo;
@ -1222,35 +1275,21 @@ void main() {
gl_FragData[0].rgb *= Absorbtion;
}
if(translucentMasks > 0.0){
#ifdef DISTANT_HORIZONS
vec4 vlBehingTranslucents = BilateralUpscale_DH(colortex13, colortex12, gl_FragCoord.xy, sqrt(texture2D(colortex12,texcoord).a/65000.0));
vec4 vlBehingTranslucents = BilateralUpscale_VLFOG(colortex13, colortex12, gl_FragCoord.xy - 1.5, sqrt(texture2D(colortex12,texcoord).a/65000.0));
#else
vec4 vlBehingTranslucents = BilateralUpscale(colortex13, depthtex1, gl_FragCoord.xy, ld(z));
vec4 vlBehingTranslucents = BilateralUpscale_VLFOG(colortex13, depthtex1, gl_FragCoord.xy - 1.5, ld(z));
#endif
gl_FragData[0].rgb = gl_FragData[0].rgb * vlBehingTranslucents.a + vlBehingTranslucents.rgb;
}
// #if defined VOLUMETRIC_CLOUDS && defined CLOUDS_INTERSECT_TERRAIN
// vec4 Clouds = texture2D_bicubic_offset(colortex0, ((gl_FragCoord.xy + 0.5)*texelSize)*CLOUDS_QUALITY, noise, RENDER_SCALE.x);
// // vec4 Clouds = BilateralUpscale_REUSE_Z_clouds(colortex0, colortex12, DH_mixedLinearZ, gl_FragCoord.xy*CLOUDS_QUALITY, texcoord*CLOUDS_QUALITY);
// gl_FragData[1] = texture2D(colortex2, texcoord);
// gl_FragData[0].rgb = gl_FragData[0].rgb * Clouds.a + Clouds.rgb;
// gl_FragData[1].a = gl_FragData[1].a * pow(Clouds.a,5.0);
// #endif
// gl_FragData[0].rgb = vec3(1.0) * clamp(1.0 - filteredShadow.y/1,0,1);
// if(hideGUI > 0) gl_FragData[0].rgb = vec3(1.0) * Shadows;
////// DEBUG VIEW STUFF
// #if DEBUG_VIEW == debug_SHADOWMAP
// vec3 OutsideShadowMap_and_DH_shadow = (shadowMapFalloff > 0.0 && z >= 1.0) ? vec3(0.25,1.0,0.25) : vec3(1.0,0.25,0.25);
// vec3 Normal_Shadowmap = z < 1.0 ? vec3(1.0,1.0,1.0) : OutsideShadowMap_and_DH_shadow;
// gl_FragData[0].rgb = mix(vec3(0.1) * (normal.y * 0.1 +0.9), Normal_Shadowmap, shadowMap) * 30.0;
// #endif
#if DEBUG_VIEW == debug_SHADOWMAP
gl_FragData[0].rgb = vec3(0.5) + vec3(1.0) * Shadows * 30.0;
#endif
#if DEBUG_VIEW == debug_NORMALS
if(swappedDepth >= 1.0) Direct_lighting = vec3(1.0);
gl_FragData[0].rgb = normalize(worldToView(normal));
@ -1271,11 +1310,11 @@ void main() {
gl_FragData[0].rgb = viewPos * 0.001;
#endif
#if DEBUG_VIEW == debug_FILTERED_STUFF
if(hideGUI == 1) gl_FragData[0].rgb = vec3(1) * (1.0 - SSAO_SSS.y);
if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * (1.0 - SSAO_SSS.x);
// if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * filteredShadow.z;//exp(-7*(1-clamp(1.0 - filteredShadow.x,0.0,1.0)));
// if(hideGUI == 1) gl_FragData[0].rgb = vec3(1) * (1.0 - SSAO_SSS.y);
// if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * (1.0 - SSAO_SSS.x);
if(hideGUI == 0) gl_FragData[0].rgb = vec3(1) * exp(-10*filteredShadow.y);//exp(-7*(1-clamp(1.0 - filteredShadow.x,0.0,1.0)));
#endif
// gl_FragData[0].rgb = vec3(1) * lightmap.y;
// gl_FragData[0].rgb = vec3(1) * Shadows;
// if(swappedDepth >= 1.0) gl_FragData[0].rgb = vec3(0.1);
// gl_FragData[0].rgb = vec3(1) * ld(texture2D(depthtex1, texcoord).r);
// if(texcoord.x > 0.5 )gl_FragData[0].rgb = vec3(1) * ld(texture2D(depthtex0, texcoord).r);

View File

@ -1,32 +1,26 @@
#include "/lib/settings.glsl"
varying vec2 texcoord;
uniform vec2 texelSize;
uniform sampler2D colortex7;
uniform sampler2D colortex14;
uniform sampler2D depthtex0;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform sampler2D noisetex;
uniform float viewHeight;
uniform float viewWidth;
uniform float aspectRatio;
uniform sampler2D shadow;
uniform sampler2D shadowcolor0;
uniform sampler2D shadowcolor1;
uniform sampler2D shadowtex0;
uniform sampler2D shadowtex1;
uniform sampler2D noisetex;
uniform float frameTimeCounter;
uniform vec3 previousCameraPosition;
uniform vec3 cameraPosition;
uniform int hideGUI;
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/res_params.glsl"
uniform int hideGUI;
/*
vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
@ -76,21 +70,19 @@ vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize )
return result;
}
/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595
void applyContrast(inout vec3 color, float contrast){
color = (color - 0.5) * contrast + 0.5;
}
*/
float lowerCurve(float x) {
float y = 16 * x * (0.5 - x) * 0.1;
return clamp(y, 0.0, 1.0);
}
float upperCurve(float x) {
float y = 16 * (0.5 - x) * (x - 1.0) * 0.1;
return clamp(y, 0.0, 1.0);
}
vec3 toneCurve(vec3 color){
vec3 luminanceCurve(vec3 color){
color.r += LOWER_CURVE * lowerCurve(color.r) + UPPER_CURVE * upperCurve(color.r);
color.g += LOWER_CURVE * lowerCurve(color.g) + UPPER_CURVE * upperCurve(color.g);
color.b += LOWER_CURVE * lowerCurve(color.b) + UPPER_CURVE * upperCurve(color.b);
@ -110,49 +102,57 @@ vec3 colorGrading(vec3 color) {
return saturate(graded_shadows * shadows_amount + graded_mids * mids_amount + graded_highlights * highlights_amount);
}
vec3 contrastAdaptiveSharpening(vec3 color, vec2 texcoord){
//Weights : 1 in the center, 0.5 middle, 0.25 corners
vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 m1 = -0.5/3.5*color + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5;
vec3 std = abs(color - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) +
abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1);
float contrast = 1.0 - luma(std)/5.0;
color = color*(1.0+(SHARPENING+UPSCALING_SHARPNENING)*contrast) -
(SHARPENING+UPSCALING_SHARPNENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*color);
return color;
}
vec3 saturationAndCrosstalk(vec3 color){
float luminance = luma(color);
vec3 lumaColDiff = color - luminance;
color = color + lumaColDiff*(-luminance*CROSSTALK + SATURATION);
return color;
}
void main() {
/* DRAWBUFFERS:7 */
#ifdef BICUBIC_UPSCALING
vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb;
#else
vec3 col = texture2D(colortex7,texcoord).rgb;
#endif
vec3 color = texture2D(colortex7,texcoord).rgb;
#ifdef CONTRAST_ADAPTATIVE_SHARPENING
//Weights : 1 in the center, 0.5 middle, 0.25 corners
vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb;
vec3 m1 = -0.5/3.5*col + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5;
vec3 std = abs(col - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) +
abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1);
float contrast = 1.0 - luma(std)/5.0;
col = col*(1.0+(SHARPENING+UPSCALING_SHARPNENING)*contrast)
- (SHARPENING+UPSCALING_SHARPNENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*col);
color = contrastAdaptiveSharpening(color, texcoord);
#endif
float lum = luma(col);
vec3 diff = col-lum;
col = col + diff*(-lum*CROSSTALK + SATURATION);
vec3 FINAL_COLOR = clamp(int8Dither(col,texcoord),0.0,1.0);
#ifdef TONE_CURVE
FINAL_COLOR = toneCurve(FINAL_COLOR);
color = saturationAndCrosstalk(color);
#ifdef LUMINANCE_CURVE
color = luminanceCurve(color);
#endif
#ifdef COLOR_GRADING_ENABLED
FINAL_COLOR = colorGrading(FINAL_COLOR);
color = colorGrading(color);
#endif
applyContrast(FINAL_COLOR, CONTRAST); // for fun
gl_FragData[0].rgb = FINAL_COLOR;
gl_FragData[0].rgb = clamp(int8Dither(color, texcoord),0.0,1.0);
}

View File

@ -1,9 +1,12 @@
#include "/lib/settings.glsl"
#define EXCLUDE_WRITE_TO_LUT
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
@ -41,6 +44,7 @@ uniform ivec2 eyeBrightnessSmooth;
uniform float eyeAltitude;
uniform float caveDetection;
// uniform int dhRenderDistance;
#define DHVLFOG
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
@ -66,6 +70,60 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
return (near * far) / (depth * (near - far) + far);
}
#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED
flat varying float exposure;
#ifdef IS_LPV_ENABLED
#extension GL_ARB_shader_image_load_store: enable
#extension GL_ARB_shading_language_packing: enable
#endif
#ifdef IS_LPV_ENABLED
uniform usampler1D texBlockData;
uniform sampler3D texLpv1;
uniform sampler3D texLpv2;
#endif
// #ifdef IS_LPV_ENABLED
// uniform int heldItemId;
// uniform int heldItemId2;
// #endif
#ifdef IS_LPV_ENABLED
#include "/lib/hsv.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_render.glsl"
#endif
vec3 LPV_FOG_ILLUMINATION(in vec3 playerPos, float dd, float dL){
vec3 color = vec3(0.0);
vec3 lpvPos = GetLpvPosition(playerPos);
float fadeLength = 10.0; // in blocks
vec3 cubicRadius = clamp( min(((LpvSize3-1.0) - lpvPos)/fadeLength, lpvPos/fadeLength) ,0.0,1.0);
float LpvFadeF = cubicRadius.x*cubicRadius.y*cubicRadius.z;
if(LpvFadeF > 0.0){
vec4 lpvSample = SampleLpvLinear(lpvPos);
if(length(lpvSample.xyz) > 1e-5){
vec3 LpvTorchLight = GetLpvBlockLight(lpvSample);
vec3 lighting = LpvTorchLight;
float density = exp(-5.0 * clamp( 1.0 - length(lpvSample.xyz) / 16.0,0.0,1.0)) * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS/100) * LpvFadeF;
color = lighting - lighting * exp(-density*dd*dL);
}
}
return color;
}
#endif
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
@ -77,12 +135,11 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
#endif
flat varying vec3 refractedSunVec;
// uniform int dhRenderDistance;
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
#include "/lib/volumetricClouds.glsl"
// #define CLOUDS_INTERSECT_TERRAIN
#include "/lib/volumetricClouds.glsl"
#include "/lib/overworld_fog.glsl"
#endif
#ifdef NETHER_SHADER
@ -105,12 +162,10 @@ float interleaved_gradientNoise(){
return noise;
}
// float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter);
// }
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter );
}
float R2_dither(){
#ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
@ -166,75 +221,6 @@ void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEn
}
// #ifdef OVERWORLD_SHADER
// vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
// int spCount = rayMarchSampleCount;
// vec3 start = toShadowSpaceProjected(rayStart);
// vec3 end = toShadowSpaceProjected(rayEnd);
// vec3 dV = (end-start);
// //limit ray length at 32 blocks for performance and reducing integration error
// //you can't see above this anyway
// float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
// dV *= maxZ;
// rayLength *= maxZ;
// estEndDepth *= maxZ;
// estSunDepth *= maxZ;
// vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
// vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
// vec3 newabsorbance = exp(-rayLength * waterCoefs); // No need to take the integrated value
// float phase = fogPhase(VdotL) * 5.0;
// vec3 absorbance = vec3(1.0);
// vec3 vL = vec3(0.0);
// float expFactor = 11.0;
// for (int i=0;i<spCount;i++) {
// float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
// float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
// vec3 spPos = start.xyz + dV*d;
// vec3 progressW = start.xyz+cameraPosition+dVWorld;
// //project into biased shadowmap space
// #ifdef DISTORT_SHADOWMAP
// float distortFactor = calcDistort(spPos.xy);
// #else
// float distortFactor = 1.0;
// #endif
// vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
// 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;
// }
// #ifdef VL_CLOUDS_SHADOWS
// sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
// #endif
// vec3 sunMul = exp(-estSunDepth * d * waterCoefs * 1.1);
// vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
// vec3 Directlight = (lightSource * phase * sunMul) * sh;
// // vec3 Indirectlight = ambient * ambientMul;
// vec3 Indirectlight = max(ambient * ambientMul, vec3(0.01,0.2,0.4) * ambientMul * 0.1) ;
// vec3 light = (Indirectlight + Directlight) * scatterCoef;
// vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
// absorbance *= exp(-waterCoefs * dd * rayLength);
// }
// // inColor += vL;
// return vec4( vL, dot(newabsorbance,vec3(0.335)));
// }
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = 8;
@ -324,6 +310,11 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-waterCoefs * dd * rayLength);
#if defined LPV_VL_FOG_ILLUMINATION && defined EXCLUDE_WRITE_TO_LUT
vL += LPV_FOG_ILLUMINATION(progressW-cameraPosition, dd, 1.0);
#endif
}
inColor += vL;
}
@ -346,6 +337,15 @@ float fogPhase2(float lightPoint){
return exponential;
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -355,17 +355,20 @@ float fogPhase2(float lightPoint){
void main() {
/* RENDERTARGETS:0 */
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
/* RENDERTARGETS:0,14 */
#else
/* RENDERTARGETS:0 */
#endif
float noise_1 = max(1.0 - R2_dither(),0.0015);
float noise_2 = blueNoise();
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
bool iswater = texture2D(colortex7,tc).a > 0.99;
float z0 = texture2D(depthtex0,tc).x;
float z0 = texture2D(depthtex0, tc).x;
#ifdef DISTANT_HORIZONS
float DH_z0 = texture2D(dhDepthTex,tc).x;
@ -373,22 +376,8 @@ void main() {
float DH_z0 = 0.0;
#endif
float z = texture2D(depthtex1,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex1,tc).x;
#else
float DH_z = 0.0;
#endif
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
@ -399,24 +388,28 @@ void main() {
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
vec3 cloudDepth = vec3(0.0);
vec3 fogDepth = vec3(0.0);
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
vec4 VolumetricClouds = renderClouds(viewPos0, vec2(noise_1,noise_2), directLightColor, indirectLightColor, cloudDepth);
#endif
#ifdef OVERWORLD_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos0, vec2(noise_1,noise_2), directLightColor, indirectLightColor, averageSkyCol_Clouds/30.0);
vec4 VolumetricFog = GetVolumetricFog(viewPos0, vec2(noise_2,noise_1), directLightColor, indirectLightColor, averageSkyCol_Clouds/30.0, cloudDepth);
#endif
#if defined NETHER_SHADER || defined END_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos0, noise_1, noise_2);
#endif
#if defined VOLUMETRIC_CLOUDS && defined CLOUDS_INTERSECT_TERRAIN
vec4 Clouds = texture2D(colortex0, (gl_FragCoord.xy*texelSize) / (VL_RENDER_RESOLUTION/CLOUDS_QUALITY));
VolumetricFog.rgb = Clouds.rgb * VolumetricFog.a + VolumetricFog.rgb;
VolumetricFog.a = VolumetricFog.a*Clouds.a;
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a);
#endif
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
if (isEyeInWater == 1){
float estEyeDepth = clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
@ -432,4 +425,7 @@ void main() {
}
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
gl_FragData[1] = vec4(VolumetricClouds.a,0.0,0.0,0.0);
#endif
}

View File

@ -6,6 +6,10 @@ flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED
flat varying float exposure;
#endif
#if defined Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
@ -26,6 +30,16 @@ uniform mat4 gbufferModelViewInverse;
uniform int frameCounter;
flat varying vec2 TAA_Offset;
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.);
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -40,15 +54,8 @@ uniform float frameTimeCounter;
void main() {
gl_Position = ftransform();
// gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0;
// #ifdef TAA
// tempOffsets = HaltonSeq2(frameCounter%10000);
// #else
// tempOffsets = 0.0;
// #endif
#ifdef OVERWORLD_SHADER
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
@ -79,6 +86,16 @@ void main() {
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
#endif
#ifdef TAA
TAA_Offset = offsets[framemod8];
#else
TAA_Offset = vec2(0.0);
#endif
}

View File

@ -31,6 +31,7 @@ uniform sampler2D colortex10;
uniform sampler2D colortex11;
uniform sampler2D colortex12;
uniform sampler2D colortex13;
uniform sampler2D colortex14;
uniform sampler2D colortex15;
uniform vec2 texelSize;
@ -71,7 +72,7 @@ uniform float caveDetection;
#include "/lib/sky_gradient.glsl"
#include "/lib/lightning_stuff.glsl"
#include "/lib/climate_settings.glsl"
//#define CLOUDS_INTERSECT_TERRAIN
// #define CLOUDSHADOWSONLY
// #include "/lib/volumetricClouds.glsl"
#endif
@ -99,78 +100,6 @@ vec3 toScreenSpace(vec3 p) {
#include "/lib/DistantHorizons_projections.glsl"
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
}
float DH_inv_ld (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
}
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
vec4 BilateralUpscale(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.01;
#else
float diffThreshold = zMults.x;
#endif
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
SUM += EDGES;
}
// return vec4(1) * SUM;
return RESULT / SUM;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn;
return clamp(normalize(n.xyz),-1.0,1.0);
}
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
@ -186,6 +115,87 @@ float interleaved_gradientNoise(){
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
}
float DH_inv_ld (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
}
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
vec4 BilateralUpscale(sampler2D tex, sampler2D tex2, sampler2D depth, vec2 coord, float referenceDepth, inout float CLOUDALPHA){
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[5] = ivec2[](
ivec2(-1,-1),
ivec2( 1, 1),
ivec2(-1, 1),
ivec2( 1,-1),
ivec2( 0, 0)
);
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.01;
#else
float diffThreshold = zMults.x;
#endif
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 5; i++) {
ivec2 radius = getRadius[i];
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
CLOUDALPHA += texelFetch2D(tex2, posColor + radius + pos, 0).x * EDGES;
#endif
SUM += EDGES;
}
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
CLOUDALPHA = CLOUDALPHA / SUM;
#endif
return RESULT / SUM;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn;
return clamp(normalize(n.xyz),-1.0,1.0);
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
@ -293,14 +303,18 @@ void main() {
bool isEntity = abs(translucentMasks - 0.9) < 0.01 || isReflectiveEntity;
////// --------------- get volumetrics
#ifdef TOGGLE_VL_FOG
#ifdef DISTANT_HORIZONS
vec4 vl = BilateralUpscale(colortex0, colortex12, gl_FragCoord.xy - 1.5, sqrt(texture2D(colortex12,texcoord).a/65000.0));
#else
vec4 vl = BilateralUpscale(colortex0, depthtex0, gl_FragCoord.xy - 1.5, frDepth);
#endif
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
float cloudAlpha = 0.0;
#else
vec4 vl = vec4(0,0,0,1);
float cloudAlpha = 1.0;
#endif
#ifdef DISTANT_HORIZONS
vec4 vl = BilateralUpscale(colortex0, colortex14, colortex12, gl_FragCoord.xy - 1.5, sqrt(texture2D(colortex12,texcoord).a/65000.0), cloudAlpha);
#else
vec4 vl = BilateralUpscale(colortex0, colortex14, depthtex0, gl_FragCoord.xy - 1.5, frDepth,cloudAlpha);
#endif
float bloomyFogMult = 1.0;
@ -330,11 +344,9 @@ void main() {
fog *= exp(-10.0 * pow(clamp(np3.y,0.0,1.0)*4.0,2.0));
fog *= caveDetection;
fog *= (1.0-caveDetection);
if(swappedDepth >= 1.0 || isEyeInWater != 0) fog = 0.0;
#ifdef SKY_GROUND
vec3 borderFogColor = skyGroundColor;
@ -366,32 +378,33 @@ void main() {
#if defined OVERWORLD_SHADER && defined CAVE_FOG
if (isEyeInWater == 0 && eyeAltitude < 1500){
float cavefog = pow(1.0 - max(1.0 - linearDistance/far,0.0),2.0);
vec3 cavefogCol = vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B) * cavefog;
cavefogCol *= exp(-7.0*clamp(normalize(np3).y*0.5+0.5,0.0,1.0)) * 0.999 + 0.001;
vec3 cavefogCol = vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B);
#ifdef PER_BIOME_ENVIRONMENT
BiomeFogColor(cavefogCol);
#endif
cavefogCol *= pow(1.0 - max(1.0 - linearDistance/far,0.0),2.0);
cavefogCol *= exp(-7.0*clamp(normalize(np3).y*0.5+0.5,0.0,1.0)) * 0.999 + 0.001;
float skyhole = pow(clamp(1.0-pow(max(np3.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2);
color.rgb = mix(color.rgb + cavefogCol * caveDetection, cavefogCol, z >= 1.0 ? skyhole * caveDetection : 0.0);
}
#endif
////// --------------- Distance fog for the end shader
#ifdef END_SHADER
if (isEyeInWater == 0){
vec3 hazeColor = vec3(0.3,0.75,1.0) * 0.3;
// create a point that "glows" but in worldspace.
// this is not correct but whatever
float CenterdotV = dot(normalize(vec3(0.0,400.0,0.0) - cameraPosition), normalize(p3 + cameraPosition));
float hazeDensity = clamp(1.0 - linearDistance / max(far, 32.0 * 24.0),0.0,1.0);
color.rgb = mix(hazeColor, color.rgb, hazeDensity) ;
}
float distanceFadeOff = pow(min(max(length(cameraPosition)-300.0,0.0)/100.0,1.0),2.0);
color.rgb += vec3(0.1,0.5,1.0) * (exp2(-10.0 * max(-CenterdotV*0.5+0.5,0.0)) + exp(-150.0 * max(-CenterdotV*0.5+0.5,0.0))) * distanceFadeOff;
#endif
////// --------------- underwater fog
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount + 0.01;
@ -421,9 +434,7 @@ void main() {
////// --------------- BLEND FOG INTO SCENE
//////////// apply VL fog over opaque and translucents
// color += skyGroundColor * (1.0 - pow(max(1.0 - linearDistance/far,0.0),3.0)) * rainStrength;
color *= vl.a;
color *= vl.a*cloudAlpha;
color += vl.rgb;
bloomyFogMult *= mix(vl.a,vl.a*0.5 + 0.5, rainStrength);
@ -462,7 +473,7 @@ void main() {
vl.a = 1.0;
}
#endif
gl_FragData[0].r = bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0);
// gl_FragData[1].rgb = vec3(tangentNormals.xy,0.0) ;

View File

@ -117,7 +117,6 @@ float DH_inv_ld (float lindepth){
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
#ifdef OVERWORLD_SHADER
// uniform sampler2D colortex12;
@ -280,12 +279,13 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
#ifdef ambientLight_only
suncol = vec3(0.0);
#endif
vec3 cloudDepth = vec3(0.0);
vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*2.0, skyGroundCol/30.0);
vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*2.0, skyGroundCol/30.0,cloudDepth);
sky = sky*clouds.a + clouds.rgb / 5.0;
sky = mix(dot(sky, vec3(0.333)) * vec3(0.5), sky, pow(clamp(viewVector.y+1.0,0.0,1.0),5));
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*1.75, skyGroundCol/30.0, averageSkyCol_Clouds/30.0);
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*1.75, skyGroundCol/30.0, averageSkyCol_Clouds/30.0,cloudDepth);
sky = sky * VL_Fog.a + VL_Fog.rgb / 5.0;

View File

@ -1,6 +1,7 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
// uniform int dhRenderDistance;
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
@ -145,7 +146,8 @@ void main() {
}
// maximum control of color and luminance
vec3 minimumlight = vec3(0.5,0.75,1.0) * (MIN_LIGHT_AMOUNT*0.001 + nightVision);
// vec3 minimumlight = vec3(0.5,0.75,1.0) * (MIN_LIGHT_AMOUNT*0.001 + nightVision);
vec3 minimumlight = vec3(0.5,0.75,1.0) * nightVision;
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,2.5) * (1.0-rainStrength*0.3), minimumlight);
averageSkyCol = max(averageSkyCol * PLANET_GROUND_BRIGHTNESS, minimumlight);
@ -251,7 +253,10 @@ void main() {
float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2;
exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0);
exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0.0);
// exposure = mix(0.0, 1.0, min(targetExposure,1.0));
// exposure = 1;
float currCenterDepth = ld(texture2D(depthtex2, vec2(0.5)).r);
centerDepth = mix(sqrt(texelFetch2D(colortex4,ivec2(14,37),0).g/65000.0), currCenterDepth, clamp(DoF_Adaptation_Speed*exp(-0.016/frameTime+1.0)/(6.0+currCenterDepth*far),0.0,1.0));
centerDepth = centerDepth * centerDepth * 65000.0;

View File

@ -105,7 +105,7 @@ uniform int dhRenderDistance;
#include "/lib/res_params.glsl"
// #define CLOUDS_INTERSECT_TERRAIN
uniform float eyeAltitude;
#include "/lib/volumetricClouds.glsl"
@ -123,7 +123,10 @@ uniform int dhRenderDistance;
void main() {
/* DRAWBUFFERS:0 */
#if defined OVERWORLD_SHADER && defined VOLUMETRIC_CLOUDS
#if defined OVERWORLD_SHADER && defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN
vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY/RENDER_SCALE+0.5+offsets[framemod8]*CLOUDS_QUALITY*RENDER_SCALE*0.5);
vec2 halfResTC2 = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY+0.5+offsets[framemod8]*CLOUDS_QUALITY*0.5);
@ -141,8 +144,8 @@ void main() {
vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, 1.0));
#endif
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(), blueNoise()), sunColor/80.0, averageSkyCol/30.0);
vec3 tesvar = vec3(0.0);
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(), blueNoise()), sunColor/80.0, averageSkyCol/30.0,tesvar);
gl_FragData[0] = VolumetricClouds;
#else

View File

@ -1,5 +1,6 @@
#include "/lib/settings.glsl"
// uniform int dhRenderDistance;
#if defined Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;

View File

@ -85,6 +85,8 @@ vec3 doMotionBlur(vec2 texcoord, float depth, float noise){
return color / samples;
}
uniform sampler2D shadowcolor1;
void main() {
float depth = texture2D(depthtex0,texcoord*RENDER_SCALE).r;
@ -105,5 +107,13 @@ void main() {
doCameraGridLines(COLOR, texcoord);
#endif
#if DEBUG_VIEW == debug_SHADOWMAP
vec2 shadowUV = texcoord * vec2(2.0, 1.0);
if(shadowUV.x < 1.0 && shadowUV.y < 1.0 && hideGUI == 1)COLOR = texture2D(shadowcolor1,shadowUV).rgb;
#endif
gl_FragColor.rgb = COLOR;
}

View File

@ -11,6 +11,7 @@ flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
flat varying float exposure;
// uniform int dhRenderDistance;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
@ -91,6 +92,7 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
// #define CLOUDS_INTERSECT_TERRAIN
// #define CLOUDSHADOWSONLY
#include "/lib/volumetricClouds.glsl"
#include "/lib/overworld_fog.glsl"
@ -286,42 +288,45 @@ vec2 decodeVec2(float a){
void main() {
/* RENDERTARGETS:13 */
float noise_1 = R2_dither();
float noise_2 = blueNoise();
gl_FragData[0] = vec4(0,0,0,1);
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
bool iswater = texture2D(colortex7,tc).a > 0.99;
float z0 = texture2D(depthtex0,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z0 = texture2D(dhDepthTex,tc).x;
#else
float DH_z0 = 0.0;
#endif
float z = texture2D(depthtex1,tc).x;
//////////////////////////////////////////////////////////
///////////////// BEHIND OF TRANSLUCENTS /////////////////
//////////////////////////////////////////////////////////
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex1,tc).x;
#else
float DH_z = 0.0;
#endif
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
if(texture2D(colortex2, tc).a > 0.0 || iswater){
float noise_1 = R2_dither();
float noise_2 = blueNoise();
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount + 0.1;
// float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
float z0 = texture2D(depthtex0,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z0 = texture2D(dhDepthTex,tc).x;
#else
float DH_z0 = 0.0;
#endif
float z = texture2D(depthtex1,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex1,tc).x;
#else
float DH_z = 0.0;
#endif
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount + 0.1;
// float dirtAmount = Dirt_Amount + 0.01;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
#ifdef BIOME_TINT_WATER
// yoink the biome tint written in this buffer for water only.
@ -332,17 +337,14 @@ void main() {
}
#endif
vec3 directLightColor = lightCol.rgb/80.0;
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
vec3 directLightColor = lightCol.rgb/80.0;
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
//////////////////////////////////////////////////////////
///////////////// BEHIND OF TRANSLUCENTS /////////////////
//////////////////////////////////////////////////////////
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
if(texture2D(colortex2, tc).a > 0.0 || iswater){
#ifdef OVERWORLD_SHADER
// vec2 lightmap = decodeVec2(texture2D(colortex14, tc).a);
@ -365,19 +367,30 @@ void main() {
// float TorchBrightness_autoAdjust = mix(1.0, 30.0, clamp(exp(-10.0*exposure),0.0,1.0)) ;
// indirectLightColor_dynamic += vec3(TORCH_R,TORCH_G,TORCH_B) * TorchBrightness_autoAdjust * pow(1.0-sqrt(1.0-clamp(lightmap.x,0.0,1.0)),2.0) * 2.0;
vec3 cloudDepth = vec3(0.0);
vec4 VolumetricFog2 = vec4(0,0,0,1);
vec4 VolumetricClouds = vec4(0,0,0,1);
#ifdef OVERWORLD_SHADER
if(!iswater) VolumetricFog2 = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor,indirectLightColor_dynamic);
if(!iswater){
#if defined CLOUDS_INTERSECT_TERRAIN
VolumetricClouds = renderClouds(viewPos1, vec2(noise_1,noise_2), directLightColor, indirectLightColor, cloudDepth);
#endif
VolumetricFog2 = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor,indirectLightColor_dynamic,cloudDepth);
#if defined CLOUDS_INTERSECT_TERRAIN
VolumetricFog2 = vec4(VolumetricClouds.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a*VolumetricClouds.a);
#endif
}
#endif
vec4 underwaterVlFog = vec4(0,0,0,1);
if(iswater) underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) );
vec4 fogFinal = vec4(underwaterVlFog.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a * underwaterVlFog.a);
gl_FragData[0] = clamp(fogFinal, 0.0, 65000.0);
}else{
gl_FragData[0] = vec4(0,0,0,1);
}
}

View File

@ -441,7 +441,8 @@ void main() {
}
if (blockId == BLOCK_CAVE_VINE_BERRIES || blockId == ITEM_GLOW_BERRIES) {
lightColor = vec3(0.651, 0.369, 0.157);
lightColor = vec3(1.0, 1.0, 0.5);
lightRange = 14.0;
mixWeight = 1.0;
}
@ -524,7 +525,7 @@ void main() {
}
if (blockId == BLOCK_GLOW_LICHEN || blockId == ITEM_GLOW_LICHEN) {
lightColor = vec3(0.092, 0.217, 0.126);
lightColor = vec3(0.1, 0.2, 0.12);
lightRange = 7.0;
}