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

@ -113,14 +113,14 @@ void main() {
}
#endif
vec3 normals = viewToWorld(normals_and_materials.xyz);
vec3 normals = (normals_and_materials.xyz);
float materials = normals_and_materials.a;
vec2 PackLightmaps = lightmapCoords;
// PackLightmaps.y *= 1.05;
PackLightmaps = min(max(PackLightmaps,0.0)*1.05,1.0);
vec4 data1 = clamp( encode(normals.xyz, PackLightmaps), 0.0, 1.0);
vec4 data1 = clamp( encode(normals, PackLightmaps), 0.0, 1.0);
// alpha is material masks, set it to 0.65 to make a DH LODs mask.
vec4 Albedo = vec4(gcolor.rgb, 1.0);

View File

@ -425,32 +425,34 @@ void main() {
#endif
AmbientLightColor = averageSkyCol_Clouds / 30.0;
#ifdef IS_IRIS
AmbientLightColor *= 2.5;
#else
AmbientLightColor *= 0.5;
#endif
Indirect_lighting = doIndirectLighting(AmbientLightColor, MinimumLightColor, lightmap.y);
#endif
#ifdef NETHER_SHADER
AmbientLightColor = skyCloudsFromTexLOD2(vec3(0.0,1.0,0.0), colortex4, 6).rgb / 30.0;
Indirect_lighting = 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;
Indirect_lighting = vec3(0.3,0.6,1.0) * 0.5;
#endif
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING
#ifdef IS_LPV_ENABLED
vec3 lpvPos = GetLpvPosition(feetPlayerPos);
#else
const vec3 lpvPos = vec3(0.0);
#endif
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, lpvPos, AmbientLightColor, MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1), exposure);
Indirect_lighting += doBlockLightLighting( vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, exposure, feetPlayerPos, lpvPos);
#ifdef LINES
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
if(SELECTION_BOX > 0) gl_FragData[0].rgba = vec4(toLinear(vec3(SELECT_BOX_COL_R, SELECT_BOX_COL_G, SELECT_BOX_COL_B)), 1.0);

View File

@ -503,7 +503,7 @@ void main() {
#if EMISSIVE_TYPE == 2
gl_FragData[1].a = SpecularTex.a;
if(SpecularTex.a <= 0.0) gl_FragData[2].a = EMISSIVE;
if(SpecularTex.a <= 0.0) gl_FragData[1].a = EMISSIVE;
#endif
#if EMISSIVE_TYPE == 3
@ -526,13 +526,6 @@ void main() {
#if SSS_TYPE == 3
gl_FragData[1].b = SpecularTex.b;
#endif
// #ifndef ENTITIES
// if(PORTAL > 0){
// gl_FragData[2].rgb = vec3(0);
// gl_FragData[2].a = clamp(ENDPORTAL_EFFECT * 0.9, 0,0.9);
// }
// #endif
#endif
// hit glow effect...

View File

@ -217,7 +217,7 @@ vec3 viewToWorld(vec3 viewPos) {
vec4 pos;
pos.xyz = viewPos;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
pos = gbufferModelViewInverse * pos ;
return pos.xyz;
}
@ -629,19 +629,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.2);
AmbientLightColor *= skylight;
Indirect_lighting = doIndirectLighting(AmbientLightColor, MinimumLightColor, lightmap.y);
#endif
#ifdef NETHER_SHADER
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(worldSpaceNormal, 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( worldSpaceNormal.y, 0), 2);
// down *= pow( max(-worldSpaceNormal.y, 0), 2);
// AmbientLightColor += up + down;
vec3 AmbientLightColor = vec3(0.1);
Indirect_lighting = skyCloudsFromTexLOD2(worldSpaceNormal, colortex4, 6).rgb / 30.0 ;
#endif
#ifdef END_SHADER
@ -658,14 +651,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.3,0.6,1.0) * 0.5;
AmbientLightColor = AmbientLightColor + 0.7 * AmbientLightColor * dot(worldSpaceNormal, normalize(feetPlayerPos));
Indirect_lighting = AmbientLightColor + 0.7 * AmbientLightColor * dot(worldSpaceNormal, normalize(feetPlayerPos));
#endif
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING
#ifdef IS_LPV_ENABLED
vec3 normalOffset = vec3(0.0);
@ -684,7 +675,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
const vec3 lpvPos = vec3(0.0);
#endif
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, lpvPos, AmbientLightColor, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, exposure);
Indirect_lighting += doBlockLightLighting( vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, exposure, feetPlayerPos, lpvPos);
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;

View File

@ -440,7 +440,7 @@ void main() {
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
if(z >= 1.0){
FlatNormals = worldToView(normal);
FlatNormals = normal;
}
vec2 SSAO_SSS = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);

View File

@ -6,9 +6,13 @@ flat varying vec3 WsunVec;
uniform sampler2D colortex4;
uniform int frameCounter;
uniform float sunElevation;
uniform vec3 sunPosition;
uniform mat4 gbufferModelViewInverse;
#include "/lib/util.glsl"
#include "/lib/res_params.glsl"

View File

@ -809,8 +809,9 @@ void main() {
normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1);
if(isDHrange){
FlatNormals = normal;
normal = viewToWorld(normal);
slopednormal = normal;
FlatNormals = worldToView(normal);
}
@ -899,6 +900,8 @@ void main() {
bool inShadowmapBounds = false;
#endif
MinimumLightColor = MinimumLightColor + 0.7 * MinimumLightColor * dot(slopednormal, feetPlayerPos_normalized);
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// FILTER STUFF //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
@ -1023,7 +1026,7 @@ void main() {
Shadows = ComputeShadowMap(projectedShadowPosition, distortFactor, noise_2, filteredShadow.x, flatNormNdotL, shadowMapFalloff, DirectLightColor, ShadowAlpha, LabSSS > 0.0);
// transition to fallback lightmap shadow mask.
Shadows = mix(isWater ? 1.0 : LM_shadowMapFallback, Shadows, shadowMapFalloff);
Shadows = mix(isWater ? lightLeakFix : LM_shadowMapFallback, Shadows, shadowMapFalloff);
#ifdef OLD_LIGHTLEAK_FIX
if (isEyeInWater == 0) Shadows *= lightLeakFix; // light leak fix
@ -1080,29 +1083,29 @@ void main() {
///////////////////////////// INDIRECT LIGHTING /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#if defined OVERWORLD_SHADER && (indirect_effect == 0 || indirect_effect == 1)
#if defined OVERWORLD_SHADER
Indirect_lighting = AmbientLightColor;
float allDirections = dot(abs(slopednormal),vec3(1.0));
vec3 ambientcoefs = slopednormal / allDirections;
float SkylightDir = ambientcoefs.y*1.5;
if(isGrass) SkylightDir = 1.5;
float skylight = max(pow(viewToWorld(FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1-lightmap.y)*0.8*0) ;
float skylight = 1.0;
#if indirect_effect != 2
float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y*1.5;
if(isGrass) SkylightDir = 1.5;
#if indirect_effect == 1
skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) ));
skylight = max(pow(viewToWorld(FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1-lightmap.y)*0.8);
#if indirect_effect == 1
skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-SSAO_SSS.x, 0.5),2.0) ));
#endif
#endif
Indirect_lighting *= skylight;
Indirect_lighting = doIndirectLighting(AmbientLightColor * skylight, MinimumLightColor, lightmap.y);
#endif
#ifdef NETHER_SHADER
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));
Indirect_lighting = mix(up, Indirect_lighting, clamp(pow(1.0-pow(1.0-SSAO_SSS.x, 0.5),2.0),0.0,1.0));
AmbientLightColor = Indirect_lighting / 5.0;
#endif
@ -1112,28 +1115,7 @@ void main() {
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
vec3 normalOffset = vec3(0.0);
if (any(greaterThan(abs(FlatNormals), vec3(1.0e-6))))
normalOffset = 0.5*viewToWorld(FlatNormals);
#if LPV_NORMAL_STRENGTH > 0
vec3 texNormalOffset = -normalOffset + slopednormal;
normalOffset = mix(normalOffset, texNormalOffset, (LPV_NORMAL_STRENGTH*0.01));
#endif
vec3 lpvPos = GetLpvPosition(feetPlayerPos) + normalOffset;
#else
const vec3 lpvPos = vec3(0.0);
#endif
// little highlight effect just to make caves look a little less flat.
MinimumLightColor = MinimumLightColor + MinimumLightColor*dot(feetPlayerPos_normalized, slopednormal)*0.7;
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, lpvPos, Indirect_lighting, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B) , lightmap.xy, exposure);
#ifdef OVERWORLD_SHADER
Indirect_lighting += LightningFlashLighting;
#endif
@ -1166,29 +1148,56 @@ void main() {
Indirect_lighting *= AO;
#endif
// GTAO
// GTAO... this is so dumb but whatevverrr
#if indirect_effect == 2
vec2 r2 = fract(R2_samples((frameCounter%40000) + frameCounter*2) + bnoise);
Indirect_lighting = AmbientLightColor/2.5;
AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z), viewPos, worldToView(slopednormal), r2) * vec3(1.0);
float vanillaAO_curve = pow(1.0 - vanilla_AO*vanilla_AO,5.0);
Indirect_lighting *= AO;
vec2 r2 = fract(R2_samples((frameCounter%40000) + frameCounter*2) + bnoise);
float GTAO = !hand ? ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z), viewPos, worldToView(slopednormal), r2) : 1.0;
AO = vec3(min(vanillaAO_curve,GTAO));
vec3 IndirectColor = Indirect_lighting;
float SkylightDir = (slopednormal / dot(abs(slopednormal),vec3(1.0))).y*1.5;
if(isGrass) SkylightDir = 1.5;
skylight = max(pow(viewToWorld(FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1-lightmap.y)*0.8);
skylight = min(skylight, mix(0.95, 2.5, pow(1-pow(1-GTAO, 0.5),2.0) ));
IndirectColor *= skylight;
Indirect_lighting = doIndirectLighting(IndirectColor, lightmap.y) * AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
// Indirect_lighting = AmbientLightColor;
ApplySSRT(Indirect_lighting, viewPos, normal, vec3(bnoise, noise_2), feetPlayerPos, lpvPos, exposure, lightmap.xy, AmbientLightColor*2.5, vec3(TORCH_R,TORCH_G,TORCH_B), isGrass, hand);
if(!hand) Indirect_lighting = ApplySSRT(viewPos, normal, vec3(bnoise, noise_2), AmbientLightColor, MinimumLightColor, lightmap.y, isGrass, isDHrange);
#endif
#if defined END_SHADER
Direct_lighting *= AO;
#endif
///////////////////////// BLOCKLIGHT LIGHTING OR LPV LIGHTING OR FLOODFILL COLORED LIGHTING
#ifdef IS_LPV_ENABLED
vec3 normalOffset = vec3(0.0);
if (any(greaterThan(abs(FlatNormals), vec3(1.0e-6))))
normalOffset = 0.5*viewToWorld(FlatNormals);
#if LPV_NORMAL_STRENGTH > 0
vec3 texNormalOffset = -normalOffset + slopednormal;
normalOffset = mix(normalOffset, texNormalOffset, (LPV_NORMAL_STRENGTH*0.01));
#endif
vec3 lpvPos = GetLpvPosition(feetPlayerPos) + normalOffset;
#else
const vec3 lpvPos = vec3(0.0);
#endif
Indirect_lighting += doBlockLightLighting( vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, exposure, feetPlayerPos, lpvPos);
////////////////////////////////////////////////////////////////////////////////
///////////////////////// SUB SURFACE SCATTERING ////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@ -1237,9 +1246,8 @@ void main() {
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;
Direct_SSS *= lightLeakFix;
#ifndef SCREENSPACE_CONTACT_SHADOWS
Direct_SSS = mix(vec3(0.0), Direct_SSS, shadowMapFalloff2);
@ -1298,7 +1306,7 @@ void main() {
#endif
#if DEBUG_VIEW == debug_NORMALS
if(swappedDepth >= 1.0) Direct_lighting = vec3(1.0);
gl_FragData[0].rgb = normalize(worldToView(normal));
gl_FragData[0].rgb = normal ;
#endif
#if DEBUG_VIEW == debug_SPECULAR
if(swappedDepth >= 1.0) Direct_lighting = vec3(1.0);

View File

@ -70,6 +70,8 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
return (near * far) / (depth * (near - far) + far);
}
#define IS_LPV_ENABLED
#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED
flat varying float exposure;

View File

@ -434,7 +434,7 @@ void main() {
////// --------------- BLEND FOG INTO SCENE
//////////// apply VL fog over opaque and translucents
color *= vl.a*cloudAlpha;
color *= vl.a*cloudAlpha ;
color += vl.rgb;
bloomyFogMult *= mix(vl.a,vl.a*0.5 + 0.5, rainStrength);

View File

@ -148,7 +148,7 @@ 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) * nightVision;
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,2.5) * (1.0-rainStrength*0.3), minimumlight);
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,2.5) * (1.0-rainStrength*0.7), minimumlight);
averageSkyCol = max(averageSkyCol * PLANET_GROUND_BRIGHTNESS, minimumlight);
////////////////////////////////////////