From 12c1b40e0fe627f96b3179045daae917dd103e87 Mon Sep 17 00:00:00 2001 From: devendrn Date: Mon, 27 Nov 2023 12:05:09 -0500 Subject: [PATCH] Some changes: - Added subtle cloud/aurora reflection - Added SunMoon --- include/newb_config_legacy.h | 5 ++ include/newb_legacy.sh | 77 +++++++++++++++++--- materials/Actor/src/Actor.vertex.sc | 59 ++------------- materials/SunMoon/src/SunMoon.fragment.sc | 16 ++++ materials/SunMoon/src/SunMoon.varying.def.sc | 4 + materials/SunMoon/src/SunMoon.vertex.sc | 20 +++++ pack.sh | 2 +- setup.bat | 2 +- setup.sh | 2 +- 9 files changed, 121 insertions(+), 66 deletions(-) create mode 100644 materials/SunMoon/src/SunMoon.fragment.sc create mode 100644 materials/SunMoon/src/SunMoon.varying.def.sc create mode 100644 materials/SunMoon/src/SunMoon.vertex.sc diff --git a/include/newb_config_legacy.h b/include/newb_config_legacy.h index ea68cb04..c170d75a 100644 --- a/include/newb_config_legacy.h +++ b/include/newb_config_legacy.h @@ -87,6 +87,7 @@ #define NL_WATER_TEX_OPACITY 0.3 // 0.0 plain water ~ 1.0 vanilla water texture #define NL_WATER_WAVE // [toggle] wave effect #define NL_WATER_FOG_FADE // [toggle] fog fade for water +#define NL_WATER_CLOUD_REFLECTION // [toggle] simple clouds/aurora reflection #define NL_WATER_TINT vec3(0.52,0.9,0.45) /* Underwater */ @@ -135,6 +136,10 @@ /* Chunk loading slide in animation */ //#define NL_CHUNK_LOAD_ANIM 100.0 // [toggle] -600.0 fall from top ~ 600.0 rise from bottom +/* Sun/Moon */ +//#define NL_SUNMOON_ANGLE 45.0 // [toggle] 0.0 no tilt - 90.0 tilt of 90 degrees +#define NL_SUNMOON_SIZE 1.0 // 0.3 tiny - 4.0 massive + /* -------- CONFIG ENDS HERE ----------- */ diff --git a/include/newb_legacy.sh b/include/newb_legacy.sh index faffb65e..6c8d36ba 100755 --- a/include/newb_legacy.sh +++ b/include/newb_legacy.sh @@ -23,7 +23,7 @@ vec3 colorCorrection(vec3 col) { // extended reinhard tonemapping const float white_scale = 0.063; col = col*(1.0+col*white_scale)/(1.0+col); - #elif NL_TONEMAP_TYPE==4 + #elif NL_TONEMAP_TYPE == 4 // aces tone mapping const float a = 1.04; const float b = 0.03; @@ -32,10 +32,10 @@ vec3 colorCorrection(vec3 col) { const float e = 0.14; col *= 0.85; col = clamp((col*(a*col + b)) / (col*(c*col + d) + e), 0.0, 1.0); - #elif NL_TONEMAP_TYPE==2 + #elif NL_TONEMAP_TYPE == 2 // simple reinhard tonemapping col = col/(1.0+col); - #elif NL_TONEMAP_TYPE==1 + #elif NL_TONEMAP_TYPE == 1 // exponential tonemapping col = 1.0-exp(-col*0.8); #endif @@ -54,7 +54,7 @@ vec3 colorCorrection(vec3 col) { return col; } -// inv used in fogcolor for end +// inv used in fogcolor for nether vec3 colorCorrectionInv(vec3 col) { #ifdef NL_TINT @@ -312,7 +312,7 @@ vec4 render_clouds_simple(vec3 pos, highp float t, float rain, vec3 zenith_col, vec4 color = vec4(0.02,0.04,0.05,cloudAlpha); color.rgb += fog_col; - color.rgb *= 1.0-0.5*cloudShadow*float(pos.y>0.0); + color.rgb *= 1.0-0.5*cloudShadow*step(0.0,pos.y); color.rgb += zenith_col*0.7; color.rgb *= 1.0 - 0.4*rain; @@ -476,7 +476,7 @@ vec3 nl_lighting(out vec3 torchColor, vec3 COLOR, vec3 FOG_COLOR, float rainFact light += mix(horizonCol,zenithCol,0.5+uv1.y-0.5*lit.y)*(lit.y*(3.0-2.0*uv1.y)*(1.3 + (4.0*nightFactor) - rainDim)); // shadow cast by top light - float shadow = float(uv1.y > NL_CONST_SHADOW_EDGE); + float shadow = step(NL_CONST_SHADOW_EDGE, uv1.y); shadow = max(shadow, (1.0 - NL_SHADOW_INTENSITY + (0.6*NL_SHADOW_INTENSITY*nightFactor))*lit.y); shadow *= shade > 0.8 ? 1.0 : 0.8; @@ -524,6 +524,29 @@ vec4 nl_water(inout vec3 wPos, inout vec4 color, vec3 viewDir, vec3 light, vec3 waterRefl = getSkyRefl(horizonEdgeCol, horizonCol, zenithCol, cosR, -wPos.y); waterRefl += getSunRefl(viewDir.x,horizonEdgeCol.r, FOG_COLOR); + // cloud reflection + #if defined(NL_WATER_CLOUD_REFLECTION) + if (wPos.y < 0.0) { + vec2 parallax = viewDir.xz/viewDir.y; + vec2 projectedPos = wPos.xz - parallax*100.0*(1.0-bump); + + float fade = 1.0 - 0.002*length(projectedPos); + //projectedPos += fade*parallax; + + fade = clamp(2.0*fade,0.0,1.0); + + #ifdef NL_AURORA + vec4 aurora = render_aurora(projectedPos.xyy, t, rainFactor, horizonEdgeCol); + waterRefl += 2.0*aurora.rgb*aurora.a*fade; + #endif + + #if NL_CLOUD_TYPE == 1 + vec4 clouds = render_clouds_simple(projectedPos.xyy, t, rainFactor, zenithCol, horizonCol, horizonEdgeCol); + waterRefl = mix(waterRefl,1.5*clouds.rgb,clouds.a*fade); + #endif + } + #endif + // mask sky reflection if (!end) { waterRefl *= 0.05 + lit.y*1.14; @@ -534,7 +557,7 @@ vec4 nl_water(inout vec3 wPos, inout vec4 color, vec3 viewDir, vec3 light, vec3 if (is(fractCposY, 0.8, 0.9)) { // flat plane - waterRefl *= 1.0 - 0.66*clamp(wPos.y, 0.0, 1.0); + waterRefl *= 1.0 - clamp(wPos.y, 0.0, 0.66); } else { // slanted plane and highly slanted plane waterRefl *= (0.1*sin(t*2.0+cPos.y*12.566)) + (fractCposY > 0.9 ? 0.2 : 0.4); @@ -543,7 +566,7 @@ vec4 nl_water(inout vec3 wPos, inout vec4 color, vec3 viewDir, vec3 light, vec3 // reflection for side plane else { bump *= 0.5 + 0.5*sin(1.5*t + dot(cPos, vec3_splat(NL_CONST_PI_HALF))); - cosR = max(sqrt(dot(viewDir.xz, viewDir.xz)), float(wPos.y < 0.5)); + cosR = max(sqrt(dot(viewDir.xz, viewDir.xz)), step(wPos.y,0.5)); cosR += (1.0-cosR*cosR)*bump; waterRefl = zenithCol*uv1.y*uv1.y*1.3; @@ -560,7 +583,7 @@ vec4 nl_water(inout vec3 wPos, inout vec4 color, vec3 viewDir, vec3 light, vec3 color.a += (1.0-color.a)*opacity*opacity; - color.rgb *= 0.22*NL_WATER_TINT*(1.0-0.4*fresnel); + color.rgb *= 0.22*NL_WATER_TINT*(1.0-0.8*fresnel); #ifdef NL_WATER_WAVE if(camDist < 14.0) { @@ -744,4 +767,40 @@ vec4 nl_refl(inout vec4 color, inout vec4 mistColor, vec2 lit, vec2 uv1, vec3 ti return wetRefl; } +vec3 nl_actor_lighting(vec3 pos, vec4 normal, mat4 world, vec4 tileLightCol, vec4 overlayCol, vec3 horizonCol, bool nether, bool underWater, bool end, float t) { + float intensity; +#ifdef FANCY + vec3 N = normalize(mul(world, normal)).xyz; + N.y *= tileLightCol.w; + N.xz *= N.xz; + + //intensity = (0.5 + N.y*0.5)*0.5 - N.x*0.1 + N.z*0.1 + 0.5; + intensity = 0.75 + N.y*0.25 - N.x*0.1 + N.z*0.1; + intensity *= intensity; +#else + intensity = (0.7+0.3*abs(normal.y))*(0.9+0.1*abs(normal.x)); +#endif + + intensity *= tileLightCol.b*tileLightCol.b*NL_SUN_INTENSITY*1.2; + intensity += overlayCol.a * 0.35; + + float factor = tileLightCol.b-tileLightCol.r; + vec3 light = intensity*vec3(1.0-2.8*factor,1.0-2.7*factor,1.0); + light *= 1.0-0.3*step(0.0,pos.y); + light += 0.55*horizonCol*tileLightCol.x; + + // nether,end,underwater tint + if (nether) { + light *= tileLightCol.x*vec3(1.4,0.96,0.9); + } else if (end) { + light *= vec3(2.1,1.5,2.3); + } else if (underWater) { + light += NL_UNDERWATER_BRIGHTNESS; + light *= mix(normalize(horizonCol),vec3(1.0,1.0,1.0),tileLightCol.x*0.5); + light += NL_CAUSTIC_INTENSITY*max(tileLightCol.x-0.46,0.0)*(0.5+0.5*sin(t + dot(pos,vec3_splat(1.5)) )); + } + + return light; +} + #endif diff --git a/materials/Actor/src/Actor.vertex.sc b/materials/Actor/src/Actor.vertex.sc index 1144c53f..3bb3fb3f 100644 --- a/materials/Actor/src/Actor.vertex.sc +++ b/materials/Actor/src/Actor.vertex.sc @@ -29,36 +29,6 @@ uniform vec4 UVAnimation; uniform mat4 Bones[8]; uniform vec4 ViewPositionAndTime; -vec3 lighting(vec3 position, vec4 normal, mat4 world) { - float intensity; - vec3 light; - -#ifdef FANCY - vec3 N = normalize(mul(world, normal)).xyz; - - N.y *= TileLightColor.w; //TileLightColor.w contains the direction of the light - N.xz *= N.xz; - - intensity = (0.5 + N.y*0.5)*0.5 - N.x*0.1 + N.z*0.1 + 0.5; - intensity *= intensity; -#else - // a_normal is passed in - intensity = (0.7+abs(normal.y)*0.3)*(0.9+abs(normal.x)*0.1); -#endif - - intensity *= TileLightColor.b*TileLightColor.b*NL_SUN_INTENSITY*1.2; - - intensity += OverlayColor.a * 0.35; - - float factor = TileLightColor.b-TileLightColor.r; - light = intensity*vec3(1.0-2.8*factor,1.0-2.7*factor,1.0); - light *= vec3(1.0,1.0,1.0) + FogColor.rgb*0.3; - - light *= 1.0-0.3*float(position.y>0.0); - - return light; -} - void main() { mat4 World = u_model[0]; @@ -77,9 +47,7 @@ void main() { worldPosition = mul(World, vec4(a_position, 1.0)).xyz; #endif - vec4 position; // = mul(u_viewProj, vec4(worldPosition, 1.0)); - //StandardTemplate_InvokeVertexOverrideFunction - position = jitterVertexPosition(worldPosition); + vec4 position = jitterVertexPosition(worldPosition); #if defined(DEPTH_ONLY) v_texcoord0 = vec2(0.0, 0.0); @@ -89,19 +57,15 @@ void main() { v_color0 = a_color0; #endif - vec4 edgeMap = fract(vec4(v_texcoord0.xy*128.0,v_texcoord0.xy*256.0)); - edgeMap.x = float(edgeMap.x<0.5); - edgeMap.y = float(edgeMap.y<0.5); - edgeMap.z = float(edgeMap.z<0.5); - edgeMap.w = float(edgeMap.w<0.5); - edgeMap = 2.0*edgeMap - 1.0; + vec4 edgeMap = fract(vec4(v_texcoord0.xy*128.0, v_texcoord0.xy*256.0)); + edgeMap = 2.0*step(edgeMap, vec4_splat(0.5)) - 1.0; // environment detections bool end = detectEnd(FogColor.rgb, FogControl.xy); bool nether = detectNether(FogColor.rgb, FogControl.xy); bool underWater = detectUnderwater(FogColor.rgb, FogControl.xy); - float rainFactor = detectRain(FogControl.xyz); + vec3 newFog; if (underWater) { newFog = getUnderwaterCol(FogColor.rgb); @@ -117,20 +81,7 @@ void main() { vec4 fogColor = renderFog(newFog, camDist, nether, FogColor.rgb, FogControl.xy); - vec3 light = lighting(a_position, a_normal, World); - light += 0.5*newFog*TileLightColor.x; - - // nether,end,underwater tint - if (nether) { - light *= TileLightColor.x*vec3(1.4,0.96,0.9); - } else if (end) { - light *= vec3(2.1,1.5,2.3); - } else if (underWater) { - light += NL_UNDERWATER_BRIGHTNESS; - light *= mix(normalize(fogColor.rgb),vec3(1.0,1.0,1.0),TileLightColor.x*0.5); - highp float t = ViewPositionAndTime.w; - light += NL_CAUSTIC_INTENSITY*max(TileLightColor.x-0.46,0.0)*(0.5+0.5*sin(t + dot(a_position.xyz,vec3_splat(1.5)) )); - } + vec3 light = nl_actor_lighting(a_position, a_normal, World, TileLightColor, OverlayColor, newFog, nether, underWater, end, ViewPositionAndTime.w); v_fog = fogColor; v_edgemap = edgeMap; diff --git a/materials/SunMoon/src/SunMoon.fragment.sc b/materials/SunMoon/src/SunMoon.fragment.sc new file mode 100644 index 00000000..83599985 --- /dev/null +++ b/materials/SunMoon/src/SunMoon.fragment.sc @@ -0,0 +1,16 @@ +$input v_texcoord0 + +#include +#include + +uniform vec4 SunMoonColor; + +SAMPLER2D(s_SunMoonTexture, 0); + +void main() { + vec4 color = texture2D(s_SunMoonTexture, v_texcoord0); + color.rgb *= SunMoonColor.rgb; + float tr = 1.0 - SunMoonColor.a; + color.a *= 1.0 - tr*tr*tr; + gl_FragColor = color; +} diff --git a/materials/SunMoon/src/SunMoon.varying.def.sc b/materials/SunMoon/src/SunMoon.varying.def.sc new file mode 100644 index 00000000..3b45b9d6 --- /dev/null +++ b/materials/SunMoon/src/SunMoon.varying.def.sc @@ -0,0 +1,4 @@ +vec3 a_position : POSITION; +vec2 a_texcoord0 : TEXCOORD0; + +vec2 v_texcoord0 : TEXCOORD0; \ No newline at end of file diff --git a/materials/SunMoon/src/SunMoon.vertex.sc b/materials/SunMoon/src/SunMoon.vertex.sc new file mode 100644 index 00000000..d57360af --- /dev/null +++ b/materials/SunMoon/src/SunMoon.vertex.sc @@ -0,0 +1,20 @@ +$input a_position, a_texcoord0 +$output v_texcoord0 + +#include +#include + +void main() { + v_texcoord0 = a_texcoord0; + vec3 pos = a_position; + + pos.xz *= NL_SUNMOON_SIZE; + #ifdef NL_SUNMOON_ANGLE + float angle = NL_SUNMOON_ANGLE*0.0174533; + float sinA = sin(angle); + float cosA = cos(angle); + pos.xz = vec2(pos.x*cosA - pos.z*sinA, pos.x*sinA + pos.z*cosA); + #endif + + gl_Position = mul(u_modelViewProj, vec4(pos, 1.0)); +} diff --git a/pack.sh b/pack.sh index 7d171660..326f6f51 100755 --- a/pack.sh +++ b/pack.sh @@ -8,7 +8,7 @@ # pack.sh -w -v 15.0 -m "Custom name" -p android # materials to compile for default -DEFAULT_MATERIALS="RenderChunk Clouds Sky EndSky LegacyCubemap Actor" +DEFAULT_MATERIALS="RenderChunk Clouds Sky EndSky LegacyCubemap Actor SunMoon" # subpacks: # OPTIONS = subpack options diff --git a/setup.bat b/setup.bat index fbb37e75..f28d2ef3 100644 --- a/setup.bat +++ b/setup.bat @@ -7,7 +7,7 @@ set DATA_VER=1.20.10 set DATA_DIR=data\%DATA_VER% set MBT_RELEASE_URL=https://github.com/ddf8196/MaterialBinTool/releases/download/v%MBT_VERSION% -set M_DATA_HTTP=https://cdn.discordapp.com/attachments/1137039470441550004/1137072623617069217/materials-data-%DATA_VER%-few.zip +set M_DATA_HTTP=https://cdn.discordapp.com/attachments/1137039470441550004/1178732085628915803/materials-data-%DATA_VER%-few.zip if not exist %MBT% ( mkdir env\bin\ diff --git a/setup.sh b/setup.sh index ef0c3233..4e262f9e 100755 --- a/setup.sh +++ b/setup.sh @@ -7,7 +7,7 @@ DATA_VER="1.20.10" DATA_DIR=data/$DATA_VER MBT_JAR_URL="https://github.com/ddf8196/MaterialBinTool/releases/download/v$MBT_VERSION/MaterialBinTool-$MBT_VERSION-all.jar" -M_DATA_URL="https://cdn.discordapp.com/attachments/1137039470441550004/1137072623617069217/materials-data-$DATA_VER-few.zip" +M_DATA_URL="https://cdn.discordapp.com/attachments/1137039470441550004/1178732085628915803/materials-data-$DATA_VER-few.zip" SHADERC_URL= CPU_ARCH=$(uname -m)