fix blocklight and ambient light interactions with rtao/ssgi/gtao. fix atmosphere haze self absorbance. fix cloud lighting during nausea. fix the issue were floodfill handheld lights cannot be toggled off. fix hardocded emission writing to the wrong buffer. fix lighting on translucents/particles in the end/nether

This commit is contained in:
Xonk
2024-06-23 21:43:15 -04:00
parent cfbdedfd4c
commit fe459005c9
16 changed files with 153 additions and 188 deletions

View File

@ -21,92 +21,56 @@
}
#endif
vec3 DoAmbientLightColor(
vec3 playerPos,
vec3 lpvPos,
vec3 SkyColor,
vec3 MinimumColor,
vec3 TorchColor,
vec2 Lightmap,
float Exposure
vec3 doBlockLightLighting(
vec3 lightColor, float lightmap, float exposureValue,
vec3 playerPos, vec3 lpvPos
){
// Lightmap = vec2(0.0,1.0);
// float LightLevelZero = clamp(pow(eyeBrightnessSmooth.y/240. + Lightmap.y,2.0) ,0.0,1.0);
// do sky lighting.
float skyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5;
vec3 MinimumLight = MinimumColor * max(MIN_LIGHT_AMOUNT*0.01, nightVision * 0.1);
vec3 IndirectLight = max(SkyColor * ambient_brightness * skyLM * 0.7, MinimumLight);
float lightmapCurve = pow(1.0-sqrt(1.0-clamp(lightmap,0.0,1.0)),2.0) * 2.0;
// do torch lighting
float TorchLM = pow(1.0-sqrt(1.0-clamp(Lightmap.x,0.0,1.0)),2.0) * 2.0;
float TorchBrightness_autoAdjust = mix(1.0, 30.0, clamp(exp(-10.0*Exposure),0.0,1.0));
vec3 TorchLight = TorchColor * TorchLM * TORCH_AMOUNT;
vec3 blockLight = lightColor * lightmapCurve; //;
#if defined IS_LPV_ENABLED && defined MC_GL_EXT_shader_image_load_store
vec4 lpvSample = SampleLpvLinear(lpvPos);
vec3 LpvTorchLight = GetLpvBlockLight(lpvSample);
vec3 lpvBlockLight = GetLpvBlockLight(lpvSample);
// i gotchu
float fadeLength = 10.0; // in blocks
// create a smooth falloff at the edges of the voxel volume.
float fadeLength = 10.0; // in meters
vec3 cubicRadius = clamp( min(((LpvSize3-1.0) - lpvPos)/fadeLength, lpvPos/fadeLength) ,0.0,1.0);
float LpvFadeF = cubicRadius.x*cubicRadius.y*cubicRadius.z;
LpvFadeF = 1.0 - pow(1.0-pow(LpvFadeF,1.5),3.0); // make it nice and soft :)
float voxelRangeFalloff = cubicRadius.x*cubicRadius.y*cubicRadius.z;
voxelRangeFalloff = 1.0 - pow(1.0-pow(voxelRangeFalloff,1.5),3.0);
TorchLight = mix(TorchLight, LpvTorchLight/5.0, LpvFadeF);
// outside the voxel volume, lerp to vanilla lighting as a fallback
blockLight = mix(blockLight, lpvBlockLight/5.0, voxelRangeFalloff);
const vec3 normal = vec3(0.0); // TODO
#ifdef Hand_Held_lights
// create handheld lightsources
const vec3 normal = vec3(0.0); // TODO
if (heldItemId > 0)
TorchLight += GetHandLight(heldItemId, playerPos, normal);
if (heldItemId > 0)
blockLight += GetHandLight(heldItemId, playerPos, normal);
if (heldItemId2 > 0)
TorchLight += GetHandLight(heldItemId2, playerPos, normal);
if (heldItemId2 > 0)
blockLight += GetHandLight(heldItemId2, playerPos, normal);
#endif
#endif
return IndirectLight + TorchLight * TorchBrightness_autoAdjust;
// try to make blocklight have consistent visiblity in different light levels.
float autoBrightness = mix(1.0, 30.0, clamp(exp(-10.0*exposureValue),0.0,1.0));
blockLight *= autoBrightness;
return blockLight * TORCH_AMOUNT;
}
// this is dumb, and i plan to remove it eventually...
vec4 RT_AmbientLight(
vec3 playerPos,
vec3 lpvPos,
float Exposure,
vec2 Lightmap,
vec3 TorchColor
vec3 doIndirectLighting(
vec3 lightColor, vec3 minimumLightColor, float lightmap
){
float skyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5;
float lightmapCurve = (pow(lightmap,15.0)*2.0 + pow(lightmap,2.5))*0.5;
// do torch lighting
float TorchLM = pow(1.0-sqrt(1.0-clamp(Lightmap.x,0.0,1.0)),2.0) * 2.0;
float TorchBrightness_autoAdjust = mix(1.0, 30.0, clamp(exp(-10.0*Exposure),0.0,1.0)) ;
vec3 TorchLight = TorchColor * TorchLM * TORCH_AMOUNT ;
#if defined IS_LPV_ENABLED && defined MC_GL_EXT_shader_image_load_store
vec4 lpvSample = SampleLpvLinear(lpvPos);
vec3 LpvTorchLight = GetLpvBlockLight(lpvSample);
vec3 indirectLight = lightColor * lightmapCurve * ambient_brightness * 0.7;
// i gotchu
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;
indirectLight += minimumLightColor * max(MIN_LIGHT_AMOUNT*0.01, nightVision * 0.1);
LpvFadeF = 1.0 - pow(1.0-pow(LpvFadeF,1.5),3.0); // make it nice and soft :)
TorchLight = mix(TorchLight,LpvTorchLight/5.0, LpvFadeF);
const vec3 normal = vec3(0.0); // TODO
if (heldItemId > 0)
TorchLight += GetHandLight(heldItemId, playerPos, normal);
if (heldItemId2 > 0)
TorchLight += GetHandLight(heldItemId2, playerPos, normal);
#endif
return vec4(TorchLight, skyLM);
return indirectLight;
}

View File

@ -291,22 +291,17 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
return vec3(1.1);
}
void ApplySSRT(
inout vec3 lighting,
vec3 ApplySSRT(
vec3 viewPos,
vec3 normal,
vec3 noise,
vec3 playerPos,
vec3 lpvPos,
float Exposure,
vec2 lightmaps,
vec3 skylightcolor,
vec3 torchcolor,
vec3 indirectLightColor,
vec3 minLightColor,
float lightmap,
bool isGrass,
bool hand
bool isLOD
){
int nrays = RAY_COUNT;
@ -318,9 +313,7 @@ void ApplySSRT(
vec3 occlusion2 = vec3(0.0);
vec3 skycontribution2 = vec3(0.0);
// rgb = torch color * lightmap. a = sky lightmap.
vec4 Lighting = RT_AmbientLight(playerPos, lpvPos, Exposure, lightmaps, torchcolor);
skylightcolor = max(skylightcolor * ambient_brightness * Lighting.a, vec3(1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision));
vec3 ambientColor = doIndirectLighting(indirectLightColor * 2.5, minLightColor, lightmap);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
@ -330,33 +323,32 @@ void ApplySSRT(
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, noise.z, 50.); // ssr rt
#else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 30., hand); // choc sspt
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 30., isLOD); // choc sspt
#endif
#ifdef SKY_CONTRIBUTION_IN_SSRT
#ifdef OVERWORLD_SHADER
if(isGrass) rayDir.y = clamp(rayDir.y + 0.5,-1,1);
// rayDir.y = mix(-1.0, rayDir.y, lightmaps.y*lightmaps.y);
skycontribution = pow(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30, vec3(0.7)) *2.5 * ambient_brightness * Lighting.a + Lighting.rgb;
skycontribution = mix(ambientColor, pow(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30, vec3(0.7)), lightmap);
#else
skycontribution = (pow(skyCloudsFromTexLOD2(rayDir, colortex4, 6).rgb / 30.0,vec3(0.7))/2.5 * ambient_brightness) * Lighting.a + skylightcolor*(1-Lighting.a) + Lighting.rgb;
skycontribution = pow(skyCloudsFromTexLOD2(rayDir, colortex4, 6).rgb / 30.0,vec3(0.7));
#endif
skycontribution = max(skycontribution, vec3(1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision));
skycontribution = max(skycontribution, minLightColor * max(MIN_LIGHT_AMOUNT*0.01, nightVision * 0.1));
#else
#ifdef OVERWORLD_SHADER
if(isGrass) rayDir.y = clamp(rayDir.y + 0.25,-1,1);
skycontribution = skylightcolor * (max(rayDir.y,pow(1.0-lightmaps.y,2))*0.95+0.05) + Lighting.rgb;
skycontribution = ambientColor * (max(rayDir.y,pow(1.0-lightmap,2))*0.95+0.05);
#else
skycontribution = skylightcolor + Lighting.rgb;
skycontribution = ambientColor;
#endif
#if indirect_effect == 4
skycontribution2 = skylightcolor + Lighting.rgb;
skycontribution2 = ambientColor;
#endif
#endif
@ -370,7 +362,6 @@ void ApplySSRT(
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){
radiance += texture2D(colortex5, previousPosition.xy).rgb * GI_Strength + skycontribution;
} else{
radiance += skycontribution;
}
@ -389,14 +380,14 @@ void ApplySSRT(
radiance += skycontribution;
}
}
if(isLOD) return max(radiance/nrays, 0.0);
occlusion *= AO_Strength;
#if indirect_effect == 4
lighting = max(radiance/nrays - max(occlusion, occlusion2*0.5)/nrays, 0.0);
#else
lighting = max(radiance/nrays - occlusion/nrays, 0.0);
#endif
if(hand) lighting = skylightcolor/1.5;
#if indirect_effect == 4
return max(radiance/nrays - max(occlusion, occlusion2*0.5)/nrays, 0.0);
#else
return max(radiance/nrays - occlusion/nrays, 0.0);
#endif
}

View File

@ -112,6 +112,7 @@ vec4 GetVolumetricFog(
vec3 color = vec3(0.0);
float absorbance = 1.0;
float AtmosphereAbsorbance = 1.0;
float lightleakfix = 1.0 - caveDetection;
float lightleakfix2 = pow(clamp(eyeBrightnessSmooth.y/240. ,0.0,1.0),3.0);
@ -235,19 +236,28 @@ vec4 GetVolumetricFog(
absorbance *= fogVolumeCoeff;
//------ ATMOSPHERE HAZE EFFECT
#if defined CloudLayer0 && defined VOLUMETRIC_CLOUDS
float cloudPlaneCutoff = clamp((CloudLayer0_height + max(eyeAltitude-(CloudLayer0_height-100),0)) - progressW.y,0.0,1.0);
#else
float cloudPlaneCutoff = 1.0;
#endif
// just air
vec2 airCoef = exp2(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0)) * (24.0 * atmosphereMult) * Haze_amount * clamp((CloudLayer0_height + max(eyeAltitude-(CloudLayer0_height-100),0)) - progressW.y,0.0,1.0);
vec2 airCoef = exp2(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0)) * (24.0 * atmosphereMult) * Haze_amount * cloudPlaneCutoff;
// Pbr for air, yolo mix between mie and rayleigh for water droplets
vec3 rL = rC*airCoef.x;
vec3 m = mC*(airCoef.y+densityVol*300.0);
// calculate the atmosphere haze seperately and purely additive to color, do not contribute to absorbtion.
vec3 Atmosphere = LightSourcePhased * sh * (rayL*rL + sunPhase*m) + (AveragedAmbientColor*0.7) * (rL+m) * lightleakfix2;
color += (Atmosphere - Atmosphere*exp(-(rL+m)*dd*dL_alternate)) / (rL+m+1e-6) * absorbance;
vec3 atmosphereVolumeCoeff = exp(-(rL+m)*dd*dL_alternate);
vec3 Atmosphere = (LightSourcePhased * sh * (rayL*rL + sunPhase*m) + AveragedAmbientColor * (rL+m)) * lightleakfix2;
color += (Atmosphere - Atmosphere * atmosphereVolumeCoeff) / (rL+m+1e-6) * AtmosphereAbsorbance * absorbance;
AtmosphereAbsorbance *= dot(atmosphereVolumeCoeff, vec3(0.33333));
//------ LPV FOG EFFECT
#if defined LPV_VL_FOG_ILLUMINATION && defined EXCLUDE_WRITE_TO_LUT
#if defined LPV_VL_FOG_ILLUMINATION && defined EXCLUDE_WRITE_TO_LUT
color += LPV_FOG_ILLUMINATION(progressW-cameraPosition, dd, dL) * TorchBrightness_autoAdjust * absorbance;
#endif

View File

@ -699,7 +699,7 @@ const vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631)
#define SELECT_BOX_COL_G 0.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]
#define SELECT_BOX_COL_B 0.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]
// #define OLD_CAVE_DETECTION
#define OLD_CAVE_DETECTION
///////////////////////////////////////////
// ----- DISTANT HORIZONS SETTINGS ----- //

View File

@ -467,7 +467,7 @@ vec4 renderClouds(
dV_Sun *= lightCol.a;
#endif
float SdotV = dot(mat3(gbufferModelView)*WsunVec, normalize(FragPosition)) ;
float SdotV = dot(WsunVec, normalize(mat3(gbufferModelViewInverse)*FragPosition + gbufferModelViewInverse[3].xyz));
float mieDay = phaseg(SdotV, 0.85) + phaseg(SdotV, 0.75);
float mieDayMulti = (phaseg(SdotV, 0.35) + phaseg(-SdotV, 0.35) * 0.5) ;