tweaks to subsurface scattering, improve SSS in the distance. make screenspace shadows have consistent step length across all window resolutions. tweak torch lighting (make it slightly brighter and a warmer color). tweak TAA handling of the hand. tweak specular reflection handling of the hand to be slightly more stable. make the shader use moonPosition instead of inverted sunPosition for moon related code. add support for Caelium moon positions. improve water parallax. remove some unused code improve specular handling of translucent entities with inside faces (slimes). add settings for refraction effects. re-enable block breaking effect and glass tint (it was off accidentally lol)

This commit is contained in:
Xonk
2025-01-28 23:19:33 -05:00
parent 6c41c008c0
commit a58cdfb9e9
24 changed files with 298 additions and 949 deletions

View File

@ -33,15 +33,9 @@ vec3 doBlockLightLighting(
float lightmapLight = 1.0-sqrt(1.0-lightmap);
lightmapLight *= lightmapLight;
float lightmapCurve = mix(lightmapLight, 2.0, lightmapBrightspot);
// lightmapCurve = lightmap*lightmap;
// float lightmapCurve = (exp(-15.0 * (1.0-lightmap))*10.0 + lightmap*pow(1.0-pow(1.0-lightmap,2.0),2.0))*0.5;
// float lightmapCurve = (pow(min(max(lightmap-0.6, 0.0) * 2.5,1.0),4.0) * 10.0 + lightmap*pow(1.0-pow(1.0-lightmap,2.0),2.0))*0.5;
// float lightmapCurve = pow(1.0-pow(1.0-lightmap,2.0),2.0);
float lightmapCurve = mix(lightmapLight, 2.5, lightmapBrightspot);
vec3 blockLight = lightmapCurve * lightColor;
vec3 blockLight = lightColor * lightmapCurve;
#if defined IS_LPV_ENABLED && defined MC_GL_EXT_shader_image_load_store
vec4 lpvSample = SampleLpvLinear(lpvPos);

View File

@ -69,6 +69,7 @@ float phaseCloudFog(float x, float g){
uniform ivec2 eyeBrightness;
vec4 GetVolumetricFog(
in vec3 viewPosition,
in vec3 sunVector,
in vec2 dither,
in vec3 LightColor,
in vec3 AmbientColor,
@ -125,8 +126,7 @@ vec4 GetVolumetricFog(
// float atmosphereAbsorbance = 1.0;
vec3 atmosphereAbsorbance = vec3(1.0);
vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec;
float SdotV = dot(sunVec, normalize(viewPosition))*lightCol.a;
float SdotV = dot(mat3(gbufferModelView) * sunVector, normalize(viewPosition));
///// ----- fog lighting
//Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx)
@ -154,23 +154,6 @@ vec4 GetVolumetricFog(
float inBiome = BiomeVLFogColors(biomeDirect, biomeIndirect);
#endif
#ifdef RAYMARCH_CLOUDS_WITH_FOG
vec3 SkyLightColor = AmbientColor;
vec3 LightSourceColor = LightColor;
#ifdef ambientLight_only
LightSourceColor = vec3(0.0);
#endif
vec3 dV_Sun = WsunVec;
float mieDay = phaseg(SdotV, 0.85) + phaseg(SdotV, 0.75);
float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5);
vec3 directScattering = LightSourceColor * mieDay * 3.14;
vec3 directMultiScattering = LightSourceColor * mieDayMulti * 3.14 * 2.0;
#endif
#if defined LPV_VL_FOG_ILLUMINATION && defined EXCLUDE_WRITE_TO_LUT
float TorchBrightness_autoAdjust = mix(1.0, 30.0, clamp(exp(-10.0*exposure),0.0,1.0)) / 5.0;
#endif
@ -219,7 +202,7 @@ vec4 GetVolumetricFog(
#endif
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow(progressW, WsunVec*lightCol.a);
sh *= GetCloudShadow(progressW, sunVector);
#endif
#ifdef PER_BIOME_ENVIRONMENT
@ -285,68 +268,6 @@ vec4 GetVolumetricFog(
#if defined LPV_VL_FOG_ILLUMINATION && defined EXCLUDE_WRITE_TO_LUT
color += LPV_FOG_ILLUMINATION(progressW-cameraPosition, dd, dL) * totalAbsorbance;
#endif
//------------------------------------
//------ STUPID RENDER CLOUDS AS FOG EFFECT
//------------------------------------
#ifdef RAYMARCH_CLOUDS_WITH_FOG
float otherlayer = max(progressW.y - (CloudLayer0_height+99.5), 0.0) > 0.0 ? 0.0 : 1.0;
float DUAL_MIN_HEIGHT = otherlayer > 0.0 ? CloudLayer0_height : CloudLayer1_height;
float DUAL_MAX_HEIGHT = DUAL_MIN_HEIGHT + 100.0;
float DUAL_DENSITY = otherlayer > 0.0 ? CloudLayer0_density : CloudLayer1_density;
if(clamp(progressW.y - DUAL_MAX_HEIGHT,0.0,1.0) < 1.0 && clamp(progressW.y - DUAL_MIN_HEIGHT,0.0,1.0) > 0.0){
#if defined CloudLayer1 && defined CloudLayer0
float upperLayerOcclusion = otherlayer > 0.0 ? GetCumulusDensity(1, progressW + vec3(0.0,1.0,0.0) * max((LAYER1_minHEIGHT+30) - progressW.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT) : 0.0;
float skylightOcclusion = mix(1.0, (1.0 - LAYER1_DENSITY)*0.8 + 0.2, (1.0 - exp2(-5.0 * (upperLayerOcclusion*upperLayerOcclusion))));
#else
float skylightOcclusion = 1.0;
#endif
float DUAL_MIN_HEIGHT_2 = otherlayer > 0.0 ? CloudLayer0_height : CloudLayer1_height;
float DUAL_MAX_HEIGHT_2 = DUAL_MIN_HEIGHT + 100.0;
float cumulus = GetCumulusDensity(-1, progressW, 1, CloudLayer0_height, CloudLayer1_height);
float fadedDensity = DUAL_DENSITY * pow(clamp((progressW.y - DUAL_MIN_HEIGHT_2)/25,0.0,1.0),2.0);
float muE = cumulus*fadedDensity;
float directLight = 0.0;
if(muE > 1e-5){
for (int j=0; j < 3; j++){
// vec3 shadowSamplePos = progressW + dV_Sun * (0.1 + j * (0.1 + dither.y*0.05));
vec3 shadowSamplePos = progressW + dV_Sun * (20.0 + j * (20.0 + dither.y*20.0));
float shadow = GetCumulusDensity(-1, shadowSamplePos, 0, DUAL_MIN_HEIGHT, DUAL_MAX_HEIGHT) * DUAL_DENSITY;
directLight += shadow;
}
/// shadows cast from one layer to another
/// large cumulus -> small cumulus
#if defined CloudLayer1 && defined CloudLayer0
if(otherlayer > 0.0) directLight += LAYER1_DENSITY * 2.0 * GetCumulusDensity(1, progressW + dV_Sun/abs(dV_Sun.y) * max((LAYER1_minHEIGHT+35) - progressW.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT);
#endif
// altostratus -> cumulus
#ifdef CloudLayer2
vec3 HighAlt_shadowPos = progressW + dV_Sun/abs(dV_Sun.y) * max(LAYER2_HEIGHT - progressW.y,0.0);
float HighAlt_shadow = GetAltostratusDensity(HighAlt_shadowPos) * CloudLayer2_density * (1.0-abs(WsunVec.y));
directLight += HighAlt_shadow;
#endif
float skyScatter = clamp(((DUAL_MAX_HEIGHT - progressW.y) / 100.0),0.0,1.0); // linear gradient from bottom to top of cloud layer
float distantfade = 1- exp( -10*pow(clamp(1.0 - length(progressW - cameraPosition)/(32*65),0.0,1.0),2));
vec3 cloudlighting = DoCloudLighting(DUAL_DENSITY * cumulus, SkyLightColor*skylightOcclusion, skyScatter, directLight, directScattering*sh_forClouds, directMultiScattering*sh_forClouds, 1);
color += max(cloudlighting - cloudlighting*exp(-muE*dd*dL_alternate),0.0) * totalAbsorbance * lightLevelZero;
totalAbsorbance *= max(exp(-muE*dd*dL_alternate),1.0-lightLevelZero);
}
}
#else
// if (totalAbsorbance < 1e-5) break;
#endif
}
// sceneColor = finalsceneColor;

View File

@ -27,7 +27,7 @@
#define FAKE_REFRACTION_EFFECT
#define FAKE_DISPERSION_EFFECT
#define REFRACTION_SMUDGE
// #define REFRACTION_SMUDGE
#define SSR_STEPS 30 // [10 15 20 25 30 35 40 50 100 200 400]
#define USE_QUARTER_RES_DEPTH
@ -87,8 +87,8 @@
#define TORCH_AMOUNT 1.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 TORCH_R 1.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 TORCH_G 0.75 // [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 TORCH_B 0.65 // [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 TORCH_G 0.5 // [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 TORCH_B 0.25 // [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 Hand_Held_lights
#define HANDHELD_LIGHT_RANGE 16 // [1 2 3 4 5 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 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255]

View File

@ -1,14 +1,21 @@
#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;
vec3 drawSun(float cosY, float sunInt,vec3 nsunlight, vec3 inColor){
// return nsunlight * min(max(cosY-0.9994,0.0)/(1.0-0.9994),1.0) * 100.0;
return (inColor+nsunlight/0.0008821203*pow(smoothstep(cos(0.0093084168595*3.2),cos(0.0093084168595*1.8),cosY),3.)*0.62);
}
vec3 drawMoon(vec3 PlayerPos, vec3 WorldSunVec, vec3 Color, inout vec3 occludeStars){
float Shape = clamp((exp(1 + -1000 * dot(WorldSunVec+PlayerPos,PlayerPos)) - 1.5),0.0,25.0);
float Shape = min(max(dot(WorldSunVec,PlayerPos)-0.9994,0.0)/(1.0-0.9994),1.0);// * clamp(-dot(WorldSunVec,PlayerPos),0,1);
occludeStars *= max(1.0-Shape*5,0.0);
return Shape * Color * 40.0;
/*
float shape2 = pow(exp(Shape * -10),0.15) * 255.0;
vec3 sunNormal = vec3(dot(WorldSunVec+PlayerPos, vec3(shape2,0,0)), dot(PlayerPos+WorldSunVec, vec3(0,shape2,0)), -dot(WorldSunVec, PlayerPos) * 15.0);
@ -27,8 +34,10 @@ vec3 drawMoon(vec3 PlayerPos, vec3 WorldSunVec, vec3 Color, inout vec3 occludeSt
);
vec3 LightDir = phase[moonPhase];
return Shape * pow(clamp(dot(sunNormal,LightDir)/5,0.0,1.5),5) * Color * 10.0 + clamp(Shape * 4.0 * pow(shape2/200,2.0),0.0,1.0)*0.004;
*/
}
const float pi = 3.141592653589793238462643383279502884197169;

View File

@ -129,7 +129,9 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo
for (int i = 0; i <= int(quality); i++) {
float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0));
// if(hand) convertHandDepth(sp);
float currZ = linZ(spos.z);
float nextZ = linZ(sp);
@ -173,14 +175,15 @@ vec4 screenSpaceReflections(
float LOD = mix(0.0, 6.0*(1.0-exp(-15.0*sqrt(roughness))), 1.0-pow(1.0-reflectionLength,5.0));
// float LOD = mix(0.0, 6.0*pow(roughness,0.1), 1.0-pow(1.0-reflectionLength,5.0));
// float LOD = clamp(pow(reflectionLength, pow(1.0-sqrt(roughness),5.0) * 3.0) * 6.0, 0.0, 6.0*pow(roughness,0.1));
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(raytracePos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(raytracePos) + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
// fix UV pos dragging behind due to hand not having a good previous frame position.
previousPosition.xy = isHand ? raytracePos.xy : previousPosition.xy;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) {
reflection.a = 1.0;
@ -297,9 +300,10 @@ vec3 specularReflections(
f0 = f0 == 0.0 ? 0.02 : f0;
// if(isHand){
// f0 = 0.9;
// roughness = 0.0;
// }
bool isMetal = f0 > 229.5/255.0;
// get reflected vector
@ -312,10 +316,12 @@ vec3 specularReflections(
// get reflectance and f0/HCM values
// float shlickFresnel = pow(clamp(1.0 + dot(-reflectedVector, samplePoints),0.0,1.0),5.0);
if(isHand) reflectedVector_L = reflect(playerPos, normal);
#else
vec3 reflectedVector_L = reflect(playerPos, normal);
#endif
float shlickFresnel = shlickFresnelRoughness(dot(-normalize(viewDir), vec3(0.0,0.0,1.0)), roughness);
#if defined FORWARD_SPECULAR && defined SNELLS_WINDOW
@ -342,6 +348,7 @@ vec3 specularReflections(
#if defined DEFERRED_BACKGROUND_REFLECTION || defined FORWARD_BACKGROUND_REFLECTION || defined DEFERRED_ENVIORNMENT_REFLECTION || defined FORWARD_ENVIORNMENT_REFLECTION
if(reflectionVisibilty < 1.0){
#if defined DEFERRED_BACKGROUND_REFLECTION || defined FORWARD_BACKGROUND_REFLECTION
#if !defined OVERWORLD_SHADER && !defined FORWARD_SPECULAR
vec3 backgroundReflection = volumetricsFromTex(reflectedVector_L, colortex4, roughness).rgb / 1200.0;
@ -363,7 +370,6 @@ vec3 specularReflections(
// composite all the different reflections together
#if defined DEFERRED_BACKGROUND_REFLECTION || defined FORWARD_BACKGROUND_REFLECTION
specularReflections = mix(DarkenedDiffuseLighting, backgroundReflection, lightmap);
#endif

View File

@ -186,6 +186,7 @@ float getCloudScattering(
}else{
shadowRayPosition = rayPosition + sunVector * (1.0 + i + dither)*20.0;
}
// float fadeddensity = density * pow(clamp((shadowRayPosition.y - minHeight)/(max(maxHeight-minHeight,1.0)*0.25),0.0,1.0),2.0);
shadow += getCloudShape(LayerIndex, LOD, shadowRayPosition, minHeight, maxHeight) * density;
@ -394,10 +395,10 @@ vec4 GetVolumetricClouds(
vec4 NormPlayerPos = normalize(gbufferModelViewInverse * vec4(viewPos, 1.0) + vec4(gbufferModelViewInverse[3].xyz,0.0));
vec3 signedSunVec = sunVector;
vec3 unignedSunVec = sunVector * (float(sunElevation > 1e-5)*2.0-1.0);
vec3 unignedSunVec = sunVector;// * (float(sunElevation > 1e-5)*2.0-1.0);
float SdotV = dot(unignedSunVec, NormPlayerPos.xyz);
NormPlayerPos.y += 0.025*heightRelativeToClouds;
// NormPlayerPos.y += 0.025*heightRelativeToClouds;
int maxSamples = 15;
int minSamples = 10;

View File

@ -54,15 +54,19 @@ float getWaterHeightmap(vec2 posxz) {
return (heightSum / 60.0) * WavesLarge;
}
vec3 getWaveNormal(vec3 posxz, bool isLOD){
vec3 getWaveNormal(vec3 waterPos, vec3 playerpos, bool isLOD){
// vary the normal's "smooth" factor as distance changes, to avoid noise from too much details.
// float range = pow(clamp(1.0 - length(posxz - cameraPosition)/(32*4),0.0,1.0),2.0);
// float deltaPos = mix(0.5, 0.1, range);
float range = min(length(posxz - cameraPosition) / (16*14.0), 3.0);
float range = min(length(playerpos) / (16*12.0), 3.0) ;
float deltaPos = range + 0.15;
// float range = 1-max(1.0-length(playerpos) / (16.0*16.0) ,0.0) ;
// range = (1.0-pow(1.0-pow(range,2.0),2.0)) * 3.0;
// float deltaPos = range + 0.15;
// float normalMult = 1.0 * WATER_WAVE_STRENGTH;
// if(isLOD){
@ -75,7 +79,7 @@ vec3 getWaveNormal(vec3 posxz, bool isLOD){
deltaPos = 0.025;
#endif
vec2 coord = posxz.xz;
vec2 coord = waterPos.xy;
float h0 = getWaterHeightmap(coord);
float h1 = getWaterHeightmap(coord + vec2(deltaPos,0.0));