improve indoor lighting, fix sunlight breaking hand indoors. fix handheld torch range slider not working. extended minimum brightness slider values.

This commit is contained in:
Xonk 2024-03-22 22:11:43 -04:00
parent f22aa95189
commit 46405f95f1
8 changed files with 100 additions and 108 deletions

View File

@ -144,7 +144,7 @@ void main() {
vec3 Direct_lighting = vec3(0.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(0.2,0.4,1.0);
vec3 MinimumLightColor = vec3(1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);

View File

@ -325,7 +325,7 @@ void main() {
#ifdef Hand_Held_lights
if(HELD_ITEM_BRIGHTNESS > 0.0) torchlightmap = max(torchlightmap, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(fragpos)/10,0.0),1.5),0.0,1.0));
if(HELD_ITEM_BRIGHTNESS > 0.0) torchlightmap = max(torchlightmap, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(fragpos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
#ifdef HAND
torchlightmap *= 0.9;

View File

@ -62,6 +62,7 @@ uniform int isEyeInWater;
uniform float rainStrength;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform ivec2 eyeBrightnessSmooth;
uniform int frameCounter;
uniform float frameTimeCounter;
@ -355,9 +356,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#endif
vec4 COLORTEST = vec4(Albedo, UnchangedAlpha);
#ifdef BIOME_TINT_WATER
if (iswater > 0.95) COLORTEST.rgb = color.rgb;
@ -420,7 +419,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#endif
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(0.2,0.4,1.0);
vec3 MinimumLightColor = vec3(1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Direct_lighting = vec3(0.0);

View File

@ -566,29 +566,29 @@ void Emission(
// uniform mat4 gbufferProjectionInverse;
// uniform mat4 dhProjectionInverse;
vec3 getViewPos() {
ivec2 uv = ivec2(gl_FragCoord.xy);
vec2 viewSize = vec2(viewWidth, viewHeight);
vec2 texcoord = gl_FragCoord.xy / viewSize;
// vec3 getViewPos() {
// ivec2 uv = ivec2(gl_FragCoord.xy);
// vec2 viewSize = vec2(viewWidth, viewHeight);
// vec2 texcoord = gl_FragCoord.xy / viewSize;
vec4 viewPos = vec4(0.0);
// vec4 viewPos = vec4(0.0);
float depth = texelFetch(depthtex0, uv, 0).r;
// float depth = texelFetch(depthtex0, uv, 0).r;
if (depth < 1.0) {
vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
viewPos = gbufferProjectionInverse * ndcPos;
viewPos.xyz /= viewPos.w;
} else {
depth = texelFetch(dhDepthTex, ivec2(gl_FragCoord.xy), 0).r;
// if (depth < 1.0) {
// vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
// viewPos = gbufferProjectionInverse * ndcPos;
// viewPos.xyz /= viewPos.w;
// } else {
// depth = texelFetch(dhDepthTex, ivec2(gl_FragCoord.xy), 0).r;
vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
viewPos = dhProjectionInverse * ndcPos;
viewPos.xyz /= viewPos.w;
}
// vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
// viewPos = dhProjectionInverse * ndcPos;
// viewPos.xyz /= viewPos.w;
// }
return viewPos.xyz;
}
// return viewPos.xyz;
// }
vec4 BilateralUpscale(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
@ -780,11 +780,7 @@ void main() {
vec3 viewPos = toScreenSpace(vec3(texcoord/RENDER_SCALE - TAA_Offset*texelSize*0.5,z));
#endif
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
vec3 feetPlayerPos_normalized = normVec(feetPlayerPos);
vec3 playerPos = mat3(gbufferModelViewInverse) * getViewPos();
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data = texture2D(colortex1,texcoord);
@ -841,6 +837,10 @@ void main() {
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
if(hand) viewPos *= 5.0;
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
vec3 feetPlayerPos_normalized = normVec(feetPlayerPos);
////// --------------- COLORS --------------- //////
float dirtAmount = Dirt_Amount + 0.01;
@ -859,7 +859,7 @@ void main() {
#endif
vec3 Absorbtion = vec3(1.0);
vec3 AmbientLightColor = vec3(0.0);
vec3 MinimumLightColor = vec3(0.2,0.4,1.0);
vec3 MinimumLightColor = vec3(1.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 Indirect_SSS = vec3(0.0);
@ -985,102 +985,94 @@ void main() {
#ifdef OVERWORLD_SHADER
NdotL = clamp((-15 + dot(slopednormal, WsunVec)*255.0) / 240.0 ,0.0,1.0);
// float shadowNDOTL = NdotL;
// #ifndef Variable_Penumbra_Shadows
// shadowNDOTL += LabSSS;
// #endif
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
if(!entities || !hand) GriAndEminShadowFix(shadowPlayerPos, viewToWorld(FlatNormals), vanilla_AO, lightmap.y);
// if(shadowNDOTL > 0.001){
vec3 projectedShadowPosition = mat3(shadowModelView) * shadowPlayerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
//apply distortion
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
if(!hand || !entities) GriAndEminShadowFix(shadowPlayerPos, viewToWorld(FlatNormals), vanilla_AO, lightmap.y, entities);
if(shadowDistanceRenderMul < 0.0) shadowMapFalloff = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0 ? 1.0 : 0.0;
vec3 projectedShadowPosition = mat3(shadowModelView) * shadowPlayerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
if(shadowMapFalloff > 0.0){
shadowMap = vec3(0.0);
vec3 ShadowColor = vec3(0.0);
//apply distortion
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
#else
float distortFactor = 1.0;
#endif
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
if(shadowDistanceRenderMul < 0.0) shadowMapFalloff = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0 ? 1.0 : 0.0;
float biasOffset = 0.0;
if(shadowMapFalloff > 0.0){
shadowMap = vec3(0.0);
vec3 ShadowColor = vec3(0.0);
#ifdef BASIC_SHADOW_FILTER
float rdMul = filteredShadow.x*distortFactor*d0*k/shadowMapResolution;
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
for(int i = 0; i < SHADOW_FILTER_SAMPLE_COUNT; i++){
vec2 offsetS = tapLocation_simple(i, 7, 9, noise_2) * 0.5;
float biasOffset = 0.0;
if(hand) biasOffset = -0.00035;
#ifdef BASIC_SHADOW_FILTER
float rdMul = filteredShadow.x*distortFactor*d0*k/shadowMapResolution;
for(int i = 0; i < SHADOW_FILTER_SAMPLE_COUNT; i++){
vec2 offsetS = tapLocation_simple(i, 7, 9, noise_2) * 0.5;
projectedShadowPosition += vec3(rdMul*offsetS, biasOffset);
#ifdef TRANSLUCENT_COLORED_SHADOWS
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowMap += opaqueShadow / SHADOW_FILTER_SAMPLE_COUNT;
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
float shadowAlpha = clamp(1.0 - pow(translucentShadow.a,5.0),0.0,1.0);
#if SSS_TYPE != 0
if(LabSSS > 0.0) ShadowColor += (DirectLightColor * clamp(pow(1.0-shadowAlpha,5.0),0.0,1.0) + DirectLightColor * translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow)) / SHADOW_FILTER_SAMPLE_COUNT;
else ShadowColor = DirectLightColor;
#endif
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z) shadowMap += (translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow)) / SHADOW_FILTER_SAMPLE_COUNT;
#else
shadowMap += vec3(shadow2D(shadow, projectedShadowPosition).x / SHADOW_FILTER_SAMPLE_COUNT);
#endif
}
#else
projectedShadowPosition += vec3(rdMul*offsetS, biasOffset);
#ifdef TRANSLUCENT_COLORED_SHADOWS
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowMap += opaqueShadow;
shadowMap += opaqueShadow / SHADOW_FILTER_SAMPLE_COUNT;
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
float shadowAlpha = clamp(1.0 - pow(translucentShadow.a,5.0),0.0,1.0);
#if SSS_TYPE != 0
if(LabSSS > 0.0) ShadowColor += DirectLightColor * (1.0 - shadowAlpha) + DirectLightColor * translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow);
if(LabSSS > 0.0) ShadowColor += (DirectLightColor * clamp(pow(1.0-shadowAlpha,5.0),0.0,1.0) + DirectLightColor * translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow)) / SHADOW_FILTER_SAMPLE_COUNT;
else ShadowColor = DirectLightColor;
#endif
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z) shadowMap += translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow);
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z) shadowMap += (translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow)) / SHADOW_FILTER_SAMPLE_COUNT;
#else
shadowMap += shadow2D(shadow, projectedShadowPosition).x;
shadowMap += vec3(shadow2D(shadow, projectedShadowPosition).x / SHADOW_FILTER_SAMPLE_COUNT);
#endif
#endif
}
#else
#ifdef TRANSLUCENT_COLORED_SHADOWS
DirectLightColor = ShadowColor;
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
shadowMap += opaqueShadow;
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
translucentShadow.rgb = normalize(translucentShadow.rgb + 0.0001);
float shadowAlpha = clamp(1.0 - pow(translucentShadow.a,5.0),0.0,1.0);
#if SSS_TYPE != 0
if(LabSSS > 0.0) ShadowColor += DirectLightColor * (1.0 - shadowAlpha) + DirectLightColor * translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow);
else ShadowColor = DirectLightColor;
#endif
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z) shadowMap += translucentShadow.rgb * shadowAlpha * (1.0 - opaqueShadow);
#else
shadowMap += shadow2D(shadow, projectedShadowPosition).x;
#endif
Shadows = shadowMap;
}
if(!iswater) Shadows = mix(vec3(LM_shadowMapFallback), Shadows, shadowMapFalloff2);
#ifdef OLD_LIGHTLEAK_FIX
if (isEyeInWater == 0) Shadows *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
#endif
// }
#ifdef TRANSLUCENT_COLORED_SHADOWS
DirectLightColor = ShadowColor;
#endif
Shadows = shadowMap;
}
if(!iswater) Shadows = mix(vec3(LM_shadowMapFallback), Shadows, shadowMapFalloff2);
#ifdef OLD_LIGHTLEAK_FIX
if (isEyeInWater == 0) Shadows *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
#endif
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// UNDER WATER SHADING ////////////////////////////////

View File

@ -5,8 +5,7 @@ void GriAndEminShadowFix(
inout vec3 WorldPos,
vec3 FlatNormal,
float VanillaAO,
float SkyLightmap,
bool Entities
float SkyLightmap
){
// float DistanceOffset = clamp(0.17 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ;
@ -15,10 +14,10 @@ void GriAndEminShadowFix(
vec3 finalBias = Bias;
// stop lightleaking
// stop lightleaking by zooming up, centered on blocks
vec2 scale = vec2(0.5); scale.y *= 0.5;
vec3 zoomShadow = scale.y - scale.x * fract(WorldPos + cameraPosition + Bias*scale.y);
if(SkyLightmap < 0.1 && !Entities) finalBias = mix(Bias, zoomShadow, clamp(VanillaAO*5,0,1));
if(SkyLightmap < 0.1) finalBias = mix(Bias, zoomShadow, clamp(VanillaAO*5,0,1));
WorldPos += finalBias;
}

View File

@ -4,18 +4,18 @@ vec3 DoAmbientLightColor(
vec3 TorchColor,
vec2 Lightmap
){
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;
SkyColor = SkyColor * ambient_brightness * skyLM;
vec3 MinimumLight = MinimumColor * (MIN_LIGHT_AMOUNT*0.01 + nightVision);
vec3 IndirectLight = max(SkyColor, MinimumLight);
// vec3(0.2,0.4,1.0)
vec3 IndirectLight = max(SkyColor * ambient_brightness * skyLM, MinimumLight);
// do torch lighting.
float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap.x)),5.0)+0.1));
TorchLM = pow(TorchLM/4,10) + pow(Lightmap.x,1.5)*0.5;
vec3 TorchLight = TorchColor * TORCH_AMOUNT * TorchLM;
vec3 TorchLight = TorchColor * TORCH_AMOUNT * TorchLM * (1.0 + LightLevelZero*dot(SkyColor * ambient_brightness,vec3(0.3333)));
return IndirectLight + TorchLight;
}

View File

@ -79,7 +79,7 @@
// ----- INDIRECT LIGHT RELATED SETTINGS ----- //
/////////////////////////////////////////////////
#define MIN_LIGHT_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 4.0 5.0 6.0 7.0 8.0 9.0 10.0]
#define MIN_LIGHT_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 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 100.0 ]
#define ambient_brightness 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 ]
#define AmbientLight_R 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]

View File

@ -86,8 +86,10 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo
float dist = 1.0 + clamp(position.z*position.z/50.0,0.0,2.0); // shrink sample size as distance increases
for (int i = 0; i <= int(quality); i++) {
vec2 testthing = hand ? spos.xy*texelSize : spos.xy/texelSize/4.0; // fix for ssr on hand
float sp = sqrt((texelFetch2D(colortex4,ivec2(testthing),0).a+0.1)/65000.0);
vec2 scaleUV = hand ? spos.xy*texelSize : spos.xy/texelSize/4.0; // fix for ssr on hand
float sp = sqrt(texelFetch2D(colortex4,ivec2(scaleUV),0).a/65000.0);
sp = invLinZ(sp);
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/RENDER_SCALE,sp);