From 3f2032ba1428430eab95b3a579348b80b8facf82 Mon Sep 17 00:00:00 2001 From: spiralhalo Date: Sun, 26 Dec 2021 22:17:04 +0700 Subject: [PATCH] Fix leftover sunlight color, fix caustics normal ...broken since `Cloud fade and early sunrise` probably ...broken since `Caustics uses texture` --- assets/lumi/shaders/common/atmosphere.glsl | 38 +++++++++++----------- assets/lumi/shaders/pass/color.frag | 11 ++++--- assets/lumi/shaders/pass/hand.frag | 3 +- assets/lumi/shaders/prog/shading.glsl | 8 ++--- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/assets/lumi/shaders/common/atmosphere.glsl b/assets/lumi/shaders/common/atmosphere.glsl index 94fed691..5a5af275 100644 --- a/assets/lumi/shaders/common/atmosphere.glsl +++ b/assets/lumi/shaders/common/atmosphere.glsl @@ -143,12 +143,11 @@ const float CAVEFOG_STR = 0.05; const int SRISC = 0; const int SNONC = 1; const int SMONC = 2; -const vec3[3] CELEST_COLOR = vec3[](SUNRISE_LIGHT_COLOR, NOON_SUNLIGHT_COLOR, vec3(1.0)); - float[3] CELEST_STR = float[](SUNLIGHT_STR , SUNLIGHT_STR , MOONLIGHT_STR * USER_NIGHT_AMBIENT_MULTIPLIER); +const vec3[3] SUN_COLOR = vec3[](SUNRISE_LIGHT_COLOR, NOON_SUNLIGHT_COLOR, vec3(1.0)); const float[3] TWG_FACTOR = float[](1.0, 0.0, 0.0); // maps celest color to twilight factor -const int CELEST_LEN = 8; -const int[CELEST_LEN] CELEST_INDICES = int[] (SMONC, SRISC, SRISC, SNONC, SNONC, SRISC, SRISC, SMONC); -const float[CELEST_LEN] CELEST_TIMES = float[](-0.05, -0.04, 0.00, 0.01, 0.49, 0.5, 0.54, 0.55); +const int SUN_LEN = 8; +const int[SUN_LEN] SUN_COL_ID = int[] (SMONC, SRISC, SRISC, SNONC, SNONC, SRISC, SRISC, SMONC); +const float[SUN_LEN] SUN_TIMES = float[](-0.05, -0.04, 0.00, 0.01, 0.49, 0.5, 0.54, 0.55); const int DAYC = 0; const int NGTC = 1; @@ -166,32 +165,33 @@ const float[SKY_LEN] SKY_TIMES = float[](-0.05, -0.01, 0.51, 0.55); void atmos_generateAtmosphereModel() { - CELEST_STR[SMONC] *= 0.5 + 0.5 * frx_moonSize; + float moonlightStrength = MOONLIGHT_STR * USER_NIGHT_AMBIENT_MULTIPLIER * (0.5 + 0.5 * frx_moonSize); // SKY_AMBIENT[NGTC] *= 0.5 + 0.5 * frx_moonSize; - - float horizonTime = frx_worldTime < 0.75 ? frx_worldTime:frx_worldTime - 1.0; // [-0.25, 0.75) - if (horizonTime <= CELEST_TIMES[0]) { - atmosv_CelestialRadiance = CELEST_COLOR[CELEST_INDICES[0]] * CELEST_STR[CELEST_INDICES[0]]; + vec3 sunColor; + float horizonTime = frx_worldTime < 0.75 ? frx_worldTime : (frx_worldTime - 1.0); // [-0.25, 0.75) + + if (horizonTime <= SUN_TIMES[0]) { + sunColor = SUN_COLOR[SUN_COL_ID[0]]; + #ifdef POST_SHADER - atmosv_OWTwilightFactor = TWG_FACTOR[CELEST_INDICES[0]]; + atmosv_OWTwilightFactor = TWG_FACTOR[SUN_COL_ID[0]]; #endif } else { int sunI = 1; - while (horizonTime > CELEST_TIMES[sunI] && sunI < CELEST_LEN - 1) sunI++; - float celestTransition = l2_clampScale(CELEST_TIMES[sunI-1], CELEST_TIMES[sunI], horizonTime); - atmosv_CelestialRadiance = mix(CELEST_COLOR[CELEST_INDICES[sunI-1]] * CELEST_STR[CELEST_INDICES[sunI-1]], - CELEST_COLOR[CELEST_INDICES[sunI]] * CELEST_STR[CELEST_INDICES[sunI]], - celestTransition); + while (horizonTime > SUN_TIMES[sunI] && sunI < SUN_LEN - 1) sunI++; + float sunTransition = l2_clampScale(SUN_TIMES[sunI-1], SUN_TIMES[sunI], horizonTime); + sunColor = mix(SUN_COLOR[SUN_COL_ID[sunI-1]], SUN_COLOR[SUN_COL_ID[sunI]], sunTransition); #ifdef POST_SHADER - atmosv_OWTwilightFactor = mix(TWG_FACTOR[CELEST_INDICES[sunI-1]], TWG_FACTOR[CELEST_INDICES[sunI]], celestTransition); + atmosv_OWTwilightFactor = mix(TWG_FACTOR[SUN_COL_ID[sunI-1]], TWG_FACTOR[SUN_COL_ID[sunI]], sunTransition); #endif } - atmosv_CelestialRadiance *= frx_skyLightTransitionFactor; - atmosv_CelestialRadiance.gb *= vec2(frx_skyLightTransitionFactor * frx_skyLightTransitionFactor); + sunColor.gb *= vec2(frx_skyLightTransitionFactor * frx_skyLightTransitionFactor); + + atmosv_CelestialRadiance = mix(sunColor * SUNLIGHT_STR, vec3(moonlightStrength), frx_worldIsMoonlit) * frx_skyLightTransitionFactor; diff --git a/assets/lumi/shaders/pass/color.frag b/assets/lumi/shaders/pass/color.frag index a416f1a4..c7e7b9c6 100644 --- a/assets/lumi/shaders/pass/color.frag +++ b/assets/lumi/shaders/pass/color.frag @@ -63,6 +63,7 @@ void main() vec4 light = texture(u_gbuffer_light, vec3(uvSolid, ID_SOLID_LIGT)); vec3 rawMat = texture(u_gbuffer_main_etc, vec3(uvSolid, ID_SOLID_MATS)).xyz; vec3 normal = texture(u_gbuffer_normal, vec3(uvSolid, ID_SOLID_MNORM)).xyz * 2.0 - 1.0; + float vertexNormaly = texture(u_gbuffer_normal, vec3(uvSolid, ID_SOLID_NORM)).y * 2.0 - 1.0; light.w = denoisedShadowFactor(u_gbuffer_shadow, uvSolid, eyePos, dSolid, light.y); @@ -78,7 +79,7 @@ void main() if (dSolid == 1.0) { base = customSky(u_tex_sun, u_tex_moon, toFrag, cSolid.rgb, solidIsUnderwater); } else { - base = shading(cSolid, u_tex_nature, light, rawMat, eyePos, normal, solidIsUnderwater, disableDiffuse); + base = shading(cSolid, u_tex_nature, light, rawMat, eyePos, normal, vertexNormaly, solidIsUnderwater, disableDiffuse); base = overlay(base, u_tex_glint, miscSolid); } @@ -120,19 +121,19 @@ void main() light = vec4(1.0); rawMat = vec3(1.0, 0.0, 1.0); normal = -frx_cameraView; + vertexNormaly = normal.y; disableDiffuse = 0.0; if (dMin == dTrans) { light = texture(u_gbuffer_light, vec3(v_texcoord, ID_TRANS_LIGT)); rawMat = texture(u_gbuffer_main_etc, vec3(v_texcoord, ID_TRANS_MATS)).xyz; normal = texture(u_gbuffer_normal, vec3(v_texcoord, ID_TRANS_MNORM)).xyz * 2.0 - 1.0; + vertexNormaly = texture(u_gbuffer_normal, vec3(v_texcoord, ID_TRANS_NORM)).y * 2.0 - 1.0; disableDiffuse = bit_unpack(miscTrans.z, 4); #ifdef WATER_FOAM if (transIsWater) { - // vec3 viewVertexNormal = frx_normalModelMatrix * (texture(u_gbuffer_normal, vec3(v_texcoord, ID_TRANS_NORM)).xyz * 2.0 - 1.0); - vec3 vertexNormal = texture(u_gbuffer_normal, vec3(v_texcoord, ID_TRANS_NORM)).xyz * 2.0 - 1.0; - foamPreprocess(next, u_tex_nature, eyePos + frx_cameraPos, vertexNormal.y, base.rgb, dVanilla, dTrans); + foamPreprocess(next, u_tex_nature, eyePos + frx_cameraPos, vertexNormaly, base.rgb, dVanilla, dTrans); } #endif @@ -147,7 +148,7 @@ void main() light.w = transIsWater ? lightmapRemap (light.y) : denoisedShadowFactor(u_gbuffer_shadow, v_texcoord, eyePos, dMin, light.y); if (next.a != 0.0) { - next = shading(next, u_tex_nature, light, rawMat, eyePos, normal, nextIsUnderwater, disableDiffuse); + next = shading(next, u_tex_nature, light, rawMat, eyePos, normal, vertexNormaly, nextIsUnderwater, disableDiffuse); if (dMin == dTrans && light.x != 0.0) { next = overlay(next, u_tex_glint, miscTrans); diff --git a/assets/lumi/shaders/pass/hand.frag b/assets/lumi/shaders/pass/hand.frag index 9968faa6..665d42d5 100644 --- a/assets/lumi/shaders/pass/hand.frag +++ b/assets/lumi/shaders/pass/hand.frag @@ -42,11 +42,12 @@ void main() vec3 normal = texture(u_gbuffer_normal, vec3(v_texcoord, 1.)).xyz * 2.0 - 1.0; vec3 misc = texture(u_gbuffer_main_etc, vec3(v_texcoord, ID_SOLID_MISC)).xyz; float disableDiffuse = bit_unpack(misc.z, 4); + float vertexNormaly = texture(u_gbuffer_normal, vec3(v_texcoord, ID_SOLID_NORM)).y * 2.0 - 1.0; light.w = lightmapRemap(light.y); normal = normal * frx_normalModelMatrix; - fragColor = shading(cSolid, u_tex_nature, light, rawMat, eyePos, normal, frx_cameraInWater == 1., disableDiffuse); + fragColor = shading(cSolid, u_tex_nature, light, rawMat, eyePos, normal, vertexNormaly, frx_cameraInWater == 1., disableDiffuse); fragColor += skyReflection(u_tex_sun, u_tex_moon, u_tex_noise, cSolid.rgb, rawMat.xy, normalize(eyePos), normal, light.yy); fragColor = overlay(fragColor, u_tex_glint, misc); diff --git a/assets/lumi/shaders/prog/shading.glsl b/assets/lumi/shaders/prog/shading.glsl index e65a4ad4..284eb05e 100644 --- a/assets/lumi/shaders/prog/shading.glsl +++ b/assets/lumi/shaders/prog/shading.glsl @@ -165,7 +165,7 @@ void lightPbr(vec3 albedo, float alpha, vec3 radiance, float roughness, vec3 f0, shading0.diffuse = albedo * radiance * diffuseNdotL * (1.0 - fresnel) / PI; } -vec4 shading(vec4 color, sampler2D natureTexture, vec4 light, float ao, vec2 material, vec3 eyePos, vec3 normal, bool isUnderwater, float disableDiffuse) +vec4 shading(vec4 color, sampler2D natureTexture, vec4 light, float ao, vec2 material, vec3 eyePos, vec3 normal, float vertexNormaly, bool isUnderwater, float disableDiffuse) { vec3 albedo = hdr_fromGamma(color.rgb); @@ -176,7 +176,7 @@ vec4 shading(vec4 color, sampler2D natureTexture, vec4 light, float ao, vec2 mat #ifdef WATER_CAUSTICS if (isUnderwater && frx_worldHasSkylight == 1) { - causticLight = caustics(natureTexture, eyePos + frx_cameraPos, normal.y); + causticLight = caustics(natureTexture, eyePos + frx_cameraPos, vertexNormaly); causticLight = pow(causticLight, 15.0); causticLight *= smoothstep(0.0, 1.0, light.y); } @@ -252,7 +252,7 @@ vec4 shading(vec4 color, sampler2D natureTexture, vec4 light, float ao, vec2 mat return vec4(shaded, color.a); } -vec4 shading(vec4 color, sampler2D natureTexture, vec4 light, vec3 rawMat, vec3 eyePos, vec3 normal, bool isUnderwater, float disableDiffuse) { - return shading(color, natureTexture, light, rawMat.z, rawMat.xy, eyePos, normal, isUnderwater, disableDiffuse); +vec4 shading(vec4 color, sampler2D natureTexture, vec4 light, vec3 rawMat, vec3 eyePos, vec3 normal, float vertexNormaly, bool isUnderwater, float disableDiffuse) { + return shading(color, natureTexture, light, rawMat.z, rawMat.xy, eyePos, normal, vertexNormaly, isUnderwater, disableDiffuse); } #endif