From 096c7385f14a1570e130107f6ccf86d6f1ff8315 Mon Sep 17 00:00:00 2001 From: devendrn <91605478+devendrn@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:06:58 +0800 Subject: [PATCH] Update sky - Add simple cloudy fog effect (#17) - Mirror sky gradient --- src/materials/RenderChunk/vertex.sc | 6 ++++++ src/newb/config.h | 3 ++- src/newb/functions/noise.h | 14 ++++++++++++++ src/newb/functions/sky.h | 12 ++++++++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/materials/RenderChunk/vertex.sc b/src/materials/RenderChunk/vertex.sc index 741c379f..fdddac41 100755 --- a/src/materials/RenderChunk/vertex.sc +++ b/src/materials/RenderChunk/vertex.sc @@ -132,6 +132,12 @@ void main() { fogColor.rgb = mix(fogColor.rgb, vec3(0.8,0.2,0.12)*1.5, lit.x*(1.67-fogColor.a*1.67)); } + #ifdef NL_CLOUDY_FOG + float fg = smoothstep(0.0, 1.0-NL_CLOUDY_FOG, relativeDist); + fg *= noise2D(4.0*viewDir.xz - 3.0*abs(viewDir.y) + 0.2*t); + fogColor.a += (1.0-fogColor.a)*fg; + #endif + vec4 refl = vec4(0.0,0.0,0.0,0.0); vec4 pos; diff --git a/src/newb/config.h b/src/newb/config.h index 23b569dd..5866d392 100644 --- a/src/newb/config.h +++ b/src/newb/config.h @@ -62,6 +62,7 @@ #define NL_FOG_TYPE 2 // 0:no fog, 1:vanilla, 2:smoother vanilla #define NL_MIST_DENSITY 0.18 // 0.0 no mist ~ 1.0 misty #define NL_RAIN_MIST_OPACITY 0.12 // [toggle] 0.04 very subtle ~ 0.5 thick rain mist blow +#define NL_CLOUDY_FOG 0.1 // [toggle] 0.0 subtle - 0.8 dense fog clouds /* Sky colors - zenith=top, horizon=bottom */ #define NL_DAY_ZENITH_COL vec3(0.15,0.45,1.0) @@ -146,7 +147,7 @@ /* Shooting star */ #define NL_SHOOTING_STAR 1.0 // [toggle] 0.2 dim ~ 1.0 bright #define NL_SHOOTING_STAR_PERIOD 6.0 // 0.4 fast ~ 12.0 slow (12 secs) -#define NL_SHOOTING_STAR_DELAY 64.0 // 0.0 no delay ~ 100.0 long time (100 secs) +#define NL_SHOOTING_STAR_DELAY 64.0 // 0.0 no delay ~ 100.0 long time (100 secs) /* Chunk loading slide in animation */ //#define NL_CHUNK_LOAD_ANIM 100.0 // [toggle] -600.0 fall from top ~ 600.0 rise from bottom diff --git a/src/newb/functions/noise.h b/src/newb/functions/noise.h index 1c8f9923..4064e81d 100644 --- a/src/newb/functions/noise.h +++ b/src/newb/functions/noise.h @@ -32,4 +32,18 @@ float disp(vec3 pos, highp float t) { return mix(fastRand(pos.xz), fastRand(pos.xz+vec2_splat(1.0)), val); } +float noise2D(vec2 u) { + vec2 u0 = floor(u); + vec2 v = u-u0; + v = 3.0*v*v - 2.0*v*v*v; + + float c0 = rand(u0); + float c1 = rand(u0+vec2(1.0, 0.0)); + float c2 = rand(u0+vec2(1.0, 1.0)); + float c3 = rand(u0+vec2(0.0, 1.0)); + + float n = mix(mix(c0, c3, v.y),mix(c1, c2, v.y), v.x); + return n; +} + #endif diff --git a/src/newb/functions/sky.h b/src/newb/functions/sky.h index f6f89c1a..54b92487 100644 --- a/src/newb/functions/sky.h +++ b/src/newb/functions/sky.h @@ -61,18 +61,22 @@ vec3 getHorizonEdgeCol(vec3 horizonCol, float rainFactor, vec3 FOG_COLOR) { // 1D sky with three color gradient vec3 renderOverworldSky(vec3 horizonEdgeCol, vec3 horizonColor, vec3 zenithColor, vec3 viewDir) { - float h = max(viewDir.y, 0.0); - h = 1.0-h*h; + float h = 1.0-viewDir.y*viewDir.y; float hsq = h*h; + if (viewDir.y < 0.0) { + hsq *= hsq*hsq; + hsq *= hsq; + } // gradient 1 h^16 // gradient 2 h^8 mix h^2 - float gradient1 = hsq*hsq*hsq*hsq; + float gradient1 = hsq*hsq; + gradient1 *= gradient1; float gradient2 = 0.6*gradient1 + 0.4*hsq; gradient1 *= gradient1; vec3 sky = mix(horizonColor, horizonEdgeCol, gradient1); - sky = mix(zenithColor,horizonColor, gradient2); + sky = mix(zenithColor, horizonColor, gradient2); return sky; }