Skip to content

Commit

Permalink
Update sky
Browse files Browse the repository at this point in the history
- Add underwater streaks
- Add rainbow option
- Increase sky bloom distance
  • Loading branch information
devendrn committed Apr 25, 2024
1 parent 04a13ab commit 5fea25f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
8 changes: 7 additions & 1 deletion include/newb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
#define NL_DAWN_HORIZON_COL vec3(0.9,0.3,0.3)
#define NL_DAWN_EDGE_COL vec3(1.0,0.4,0.2)

/* Rainbow */
//#define NL_RAINBOW // [toggle] enable rainbow in sky
#define NL_RAINBOW_CLEAR 0.0 // 0.3 subtle ~ 1.7 bright during clear
#define NL_RAINBOW_RAIN 1.0 // 0.5 subtle ~ 2.0 bright during rain

/* Ore glow intensity */
#define NL_GLOW_TEX 2.2 // 0.4 weak ~ 8.0 bright
#define NL_GLOW_SHIMMER // [toggle] shimmer effect
Expand All @@ -102,7 +107,8 @@
#define NL_UNDERWATER_BRIGHTNESS 0.8 // 0.0 dark ~ 3.0 bright
#define NL_CAUSTIC_INTENSITY 1.9 // 0.5 weak ~ 5.0 bright
#define NL_UNDERWATER_WAVE 0.1 // [toggle] 0.02 subtle ~ 0.6 trippy
#define NL_UNDERWATER_TINT vec3(0.9,1.0,0.9)
#define NL_UNDERWATER_STREAKS 1.0 // [toggle] 0.8 subtle - 2.0 bright streaks from top
#define NL_UNDERWATER_TINT vec3(0.9,1.0,0.9) // fog tint color when underwater

/* Cloud type */
#define NL_CLOUD_TYPE 1 // 0:vanilla, 1:soft, 2:rounded
Expand Down
2 changes: 1 addition & 1 deletion include/newb/functions/rain.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ vec4 nlRefl(

if (wPos.y < 0.0) {
// wetRefl.rgb = getRainSkyRefl(horizonCol, zenithCol, cosR);
wetRefl.rgb = getSkyRefl(horizonEdgeCol, horizonCol, zenithCol, viewDir, FOG_COLOR, t, -wPos.y, end, underWater, nether);
wetRefl.rgb = getSkyRefl(horizonEdgeCol, horizonCol, zenithCol, viewDir, FOG_COLOR, t, -wPos.y, rainFactor, end, underWater, nether);
wetRefl.a = calculateFresnel(cosR, 0.03)*reflective;

#if defined(NL_GROUND_AURORA_REFL) && defined(NL_AURORA) && defined (NL_GROUND_REFL)
Expand Down
32 changes: 25 additions & 7 deletions include/newb/functions/sky.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ vec3 renderOverworldSky(vec3 horizonEdgeCol, vec3 horizonColor, vec3 zenithColor
vec3 getSunBloom(float viewDirX, vec3 horizonEdgeCol, vec3 FOG_COLOR) {
float factor = FOG_COLOR.r/length(FOG_COLOR);
factor *= factor;
factor *= factor;

float sunBloom = smoothstep(0.0, 0.95, abs(viewDirX));
sunBloom *= sunBloom*sunBloom*factor*factor;
sunBloom *= sunBloom*2.0;
float spread = smoothstep(0.0, 1.0, abs(viewDirX));
float sunBloom = spread*spread;
sunBloom = 0.5*spread + sunBloom*sunBloom*sunBloom*1.5;

return horizonEdgeCol*sunBloom*NL_MORNING_SUN_COL;
return NL_MORNING_SUN_COL*horizonEdgeCol*(sunBloom*factor*factor);
}


Expand Down Expand Up @@ -115,14 +116,31 @@ vec3 renderEndSky(vec3 horizonCol, vec3 zenithCol, vec3 viewDir, float t) {
return sky;
}

vec3 nlRenderSky(vec3 horizonEdgeCol, vec3 horizonCol, vec3 zenithCol, vec3 viewDir, vec3 FOG_COLOR, float t, bool end, bool underWater, bool nether) {
vec3 nlRenderSky(vec3 horizonEdgeCol, vec3 horizonCol, vec3 zenithCol, vec3 viewDir, vec3 FOG_COLOR, float t, float rainFactor, bool end, bool underWater, bool nether) {
vec3 sky;
viewDir.y = -viewDir.y;

if (end) {
sky = renderEndSky(horizonCol, zenithCol, viewDir, t);
} else {
sky = renderOverworldSky(horizonEdgeCol, horizonCol, zenithCol, viewDir);
#ifdef NL_RAINBOW
sky += mix(NL_RAINBOW_CLEAR, NL_RAINBOW_RAIN, rainFactor)*spectrum((viewDir.z+0.6)*8.0)*max(viewDir.y, 0.0)*FOG_COLOR.g;
#endif
#ifdef NL_UNDERWATER_STREAKS
if (underWater) {
float a = atan2(viewDir.x, viewDir.z);
float grad = 0.5 + 0.5*viewDir.y;
grad *= grad;
float spread = (0.5 + 0.5*sin(3.0*a + 0.2*t + 2.0*sin(5.0*a - 0.4*t)));
spread *= (0.5 + 0.5*sin(3.0*a - sin(0.5*t)))*grad;
spread += (1.0-spread)*grad;
float streaks = spread*spread;
streaks *= streaks;
streaks = (spread + 3.0*grad*grad + 4.0*streaks*streaks);
sky += 2.0*streaks*horizonCol;
} else
#endif
if (!nether) {
sky += getSunBloom(viewDir.x, horizonEdgeCol, FOG_COLOR);
}
Expand All @@ -132,9 +150,9 @@ vec3 nlRenderSky(vec3 horizonEdgeCol, vec3 horizonCol, vec3 zenithCol, vec3 view
}

// sky reflection on plane
vec3 getSkyRefl(vec3 horizonEdgeCol, vec3 horizonCol, vec3 zenithCol, vec3 viewDir, vec3 FOG_COLOR, float t, float h, bool end, bool underWater, bool nether) {
vec3 getSkyRefl(vec3 horizonEdgeCol, vec3 horizonCol, vec3 zenithCol, vec3 viewDir, vec3 FOG_COLOR, float t, float h, float rainFactor, bool end, bool underWater, bool nether) {
viewDir.y = -viewDir.y;
vec3 refl = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, viewDir, FOG_COLOR, t, end, underWater, nether);
vec3 refl = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, viewDir, FOG_COLOR, t, rainFactor, end, underWater, nether);

if (!(underWater || nether)) {
float specular = smoothstep(0.7, 0.0, abs(viewDir.z));
Expand Down
2 changes: 1 addition & 1 deletion include/newb/functions/water.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ vec4 nlWater(
viewDir.y = cosR;

// sky reflection
waterRefl = getSkyRefl(horizonEdgeCol, horizonCol, zenithCol, viewDir, FOG_COLOR, t, -wPos.y, end, underWater, nether);
waterRefl = getSkyRefl(horizonEdgeCol, horizonCol, zenithCol, viewDir, FOG_COLOR, t, -wPos.y, rainFactor, end, underWater, nether);

// cloud and aurora reflection
#if defined(NL_WATER_CLOUD_REFLECTION)
Expand Down
4 changes: 2 additions & 2 deletions materials/LegacyCubemap/src/LegacyCubemap.fragment.sc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void main() {

vec3 viewDir = normalize(v_worldPos);
bool underWater = v_underwaterRainTime.x > 0.5;
float rainFactor = v_underwaterRainTime.y;

vec3 zenithCol;
vec3 horizonCol;
Expand All @@ -20,14 +21,13 @@ void main() {
horizonCol = fogcol;
horizonEdgeCol = fogcol;
} else {
float rainFactor = v_underwaterRainTime.y;
vec3 fs = getSkyFactors(v_fogColor);
zenithCol = getZenithCol(rainFactor, v_fogColor, fs);
horizonCol = getHorizonCol(rainFactor, v_fogColor, fs);
horizonEdgeCol = getHorizonEdgeCol(horizonCol, rainFactor, v_fogColor);
}

vec3 skyColor = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, -viewDir, v_fogColor, v_underwaterRainTime.z, false, underWater, false);
vec3 skyColor = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, -viewDir, v_fogColor, v_underwaterRainTime.z, rainFactor, false, underWater, false);

float fade = clamp(-10.0*viewDir.y, 0.0, 1.0);
vec4 color = vec4(colorCorrection(skyColor), fade);
Expand Down
2 changes: 1 addition & 1 deletion materials/RenderChunk/src/RenderChunk.vertex.sc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void main() {
relativeDist += RenderChunkFogAlpha.x;

vec4 fogColor;
fogColor.rgb = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, viewDir, FogColor.rgb, t, end, underWater, nether);
fogColor.rgb = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, viewDir, FogColor.rgb, t, rainFactor, end, underWater, nether);
fogColor.a = nlRenderFogFade(relativeDist, FogColor.rgb, FogAndDistanceControl.xy);
#ifdef NL_GODRAY
fogColor.a = mix(fogColor.a, 1.0, NL_GODRAY*nlRenderGodRayIntensity(cPos, worldPos, t, uv1, relativeDist, FogColor.rgb));
Expand Down
4 changes: 2 additions & 2 deletions materials/Sky/src/Sky.fragment.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void main() {
#ifdef OPAQUE
vec3 viewDir = normalize(v_worldPos);
bool underWater = v_underwaterRainTime.x > 0.5;
float rainFactor = v_underwaterRainTime.y;

vec3 zenithCol;
vec3 horizonCol;
Expand All @@ -19,14 +20,13 @@ void main() {
horizonCol = fogcol;
horizonEdgeCol = fogcol;
} else {
float rainFactor = v_underwaterRainTime.y;
vec3 fs = getSkyFactors(v_fogColor);
zenithCol = getZenithCol(rainFactor, v_fogColor, fs);
horizonCol = getHorizonCol(rainFactor, v_fogColor, fs);
horizonEdgeCol = getHorizonEdgeCol(horizonCol, rainFactor, v_fogColor);
}

vec3 skyColor = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, -viewDir, v_fogColor, v_underwaterRainTime.z, false, underWater, false);
vec3 skyColor = nlRenderSky(horizonEdgeCol, horizonCol, zenithCol, -viewDir, v_fogColor, v_underwaterRainTime.z, rainFactor, false, underWater, false);
skyColor = colorCorrection(skyColor);

gl_FragColor = vec4(skyColor, 1.0);
Expand Down

0 comments on commit 5fea25f

Please sign in to comment.