Skip to content

Commit

Permalink
Update sky
Browse files Browse the repository at this point in the history
- Add simple cloudy fog effect (#17)
- Mirror sky gradient
  • Loading branch information
devendrn committed Oct 3, 2024
1 parent a178e81 commit 096c738
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/materials/RenderChunk/vertex.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/newb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/newb/functions/noise.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions src/newb/functions/sky.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 096c738

Please sign in to comment.