From da3d14958a4dc09c72f2e21c34cbea5933f3d656 Mon Sep 17 00:00:00 2001 From: Xonk Date: Fri, 21 Mar 2025 21:50:36 -0400 Subject: [PATCH] re-add resourcepack skybox support --- shaders/dimensions/composite1.fsh | 22 ++-- shaders/dimensions/deferred2.fsh | 150 +++-------------------- shaders/dimensions/deferred2.vsh | 49 +------- shaders/shaders.properties | 12 +- shaders/world-1/gbuffers_skytextured.fsh | 39 +----- shaders/world-1/gbuffers_skytextured.vsh | 35 ------ shaders/world0/gbuffers_skytextured.fsh | 19 ++- shaders/world0/gbuffers_skytextured.vsh | 3 + shaders/world1/gbuffers_skytextured.fsh | 39 +----- shaders/world1/gbuffers_skytextured.vsh | 35 ------ 10 files changed, 46 insertions(+), 357 deletions(-) diff --git a/shaders/dimensions/composite1.fsh b/shaders/dimensions/composite1.fsh index 0441744..82d6d13 100644 --- a/shaders/dimensions/composite1.fsh +++ b/shaders/dimensions/composite1.fsh @@ -786,6 +786,8 @@ void main() { vec4 data = texelFetch2D(colortex1, ivec2(gl_FragCoord.xy), 0); + vec3 skyboxCol = data.rgb; + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); @@ -1299,6 +1301,7 @@ void main() { }else{ vec3 Background = vec3(0.0); + #ifdef OVERWORLD_SHADER float atmosphereGround = 1.0 - exp2(-50.0 * pow(clamp(feetPlayerPos_normalized.y+0.025,0.0,1.0),2.0) ); // darken the ground in the sky. @@ -1330,21 +1333,16 @@ void main() { vec3 Sky = skyFromTex(feetPlayerPos_normalized, colortex4)/1200.0 * Sky_Brightness; Background += Sky; - #endif + #if RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 2 || RESOURCEPACK_SKY == 3 + vec3 resourcePackskyBox = skyboxCol * clamp(unsigned_WsunVec.y*2.0,0.1,1.0); - // #if RESOURCEPACK_SKY == 1 || RESOURCEPACK_SKY == 2 || RESOURCEPACK_SKY == 3 - // vec3 resourcePackskyBox = toLinear(texture2D(colortex10, texcoord).rgb * 5.0) * 15.0 * clamp(unsigned_WsunVec.y*2.0,0.1,1.0); + #ifdef SKY_GROUND + resourcePackskyBox *= atmosphereGround; + #endif - // #ifdef SKY_GROUND - // resourcePackskyBox *= atmosphereGround; - // #endif + Background += resourcePackskyBox; + #endif - // Background += resourcePackskyBox; - // #endif - - #if defined OVERWORLD_SHADER && defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN - vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise, RENDER_SCALE.x); - Background = Background * Clouds.a + Clouds.rgb; #endif gl_FragData[0].rgb = clamp(fp10Dither(Background, triangularize(noise_2)), 0.0, 65000.); diff --git a/shaders/dimensions/deferred2.fsh b/shaders/dimensions/deferred2.fsh index 5a48d21..10897ac 100644 --- a/shaders/dimensions/deferred2.fsh +++ b/shaders/dimensions/deferred2.fsh @@ -1,123 +1,10 @@ #include "/lib/settings.glsl" -//Computes volumetric clouds at variable resolution (default 1/4 res) - -flat varying vec3 sunColor; -// flat varying vec3 moonColor; -flat varying vec3 averageSkyCol; - -flat varying float tempOffsets; -// uniform float far; -uniform float near; uniform sampler2D depthtex0; - -#ifdef DISTANT_HORIZONS uniform sampler2D dhDepthTex; -uniform sampler2D dhDepthTex1; -#endif - - -// uniform sampler2D colortex4; -uniform sampler2D noisetex; - -uniform sampler2D colortex12; - -flat varying vec3 WsunVec; -uniform float sunElevation; -uniform vec3 sunVec; +uniform sampler2D colortex1; +uniform sampler2D colortex2; uniform vec2 texelSize; -uniform float frameTimeCounter; -uniform float rainStrength; -uniform int frameCounter; -uniform int framemod8; -uniform mat4 gbufferProjectionInverse; -uniform mat4 gbufferModelViewInverse; -uniform vec3 cameraPosition; - -uniform mat4 gbufferModelView; -uniform mat4 gbufferProjection; -// flat varying vec2 TAA_Offset; - -#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) -#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) - - -vec3 toScreenSpace(vec3 p) { - vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); - vec3 p3 = p * 2. - 1.; - vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; - return fragposition.xyz / fragposition.w; -} - - -#include "/lib/DistantHorizons_projections.glsl" - -float R2_dither(){ - #ifdef TAA - vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0; - #else - - vec2 coord = gl_FragCoord.xy; - #endif - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha.x * coord.x + alpha.y * coord.y ) ; -} -float interleaved_gradientNoise(){ - vec2 alpha = vec2(0.75487765, 0.56984026); - vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter; - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); - return noise; -} - - - -#include "/lib/TAA_jitter.glsl" - -float blueNoise(){ - #ifdef TAA - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); - #else - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a); - #endif -} - - -vec3 normVec (vec3 vec){ - return vec*inversesqrt(dot(vec,vec)); -} -uniform float far; - - -float ld(float dist) { - return (2.0 * near) / (far + near - dist * (far - near)); -} - -uniform int dhRenderDistance; - -#include "/lib/lightning_stuff.glsl" -#include "/lib/sky_gradient.glsl" -#include "/lib/res_params.glsl" - -#define CLOUDS_INTERSECT_TERRAIN -uniform float eyeAltitude; - - - #ifdef Daily_Weather - flat varying vec4 dailyWeatherParams0; - flat varying vec4 dailyWeatherParams1; - #else - vec4 dailyWeatherParams0 = vec4(CloudLayer0_coverage, CloudLayer1_coverage, CloudLayer2_coverage, 0.0); - vec4 dailyWeatherParams1 = vec4(CloudLayer0_density, CloudLayer1_density, CloudLayer2_density, 0.0); - #endif - - -#include "/lib/volumetricClouds.glsl" - - - - - - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -125,34 +12,25 @@ uniform float eyeAltitude; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// +#if defined OVERWORLD_SHADER + /* RENDERTARGETS:1,2 */ +#endif void main() { + vec2 texcoord = gl_FragCoord.xy * texelSize; + gl_FragData[0] = texelFetch2D(colortex1, ivec2(gl_FragCoord.xy),0); - #if defined OVERWORLD_SHADER && defined VOLUMETRIC_CLOUDS && !defined CLOUDS_INTERSECT_TERRAIN - vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY/RENDER_SCALE+0.5+offsets[framemod8]*CLOUDS_QUALITY*RENDER_SCALE*0.5); + if(texelFetch2D(depthtex0, ivec2(gl_FragCoord.xy), 0).x < 1.0 || texelFetch2D(dhDepthTex, ivec2(gl_FragCoord.xy), 0).x < 1.0) { + // doing this for precision reasons, DH does NOT like depth => 1.0 + }else{ - vec2 halfResTC2 = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY+0.5+offsets[framemod8]*CLOUDS_QUALITY*0.5); - - #ifdef CLOUDS_INTERSECT_TERRAIN - float depth = texelFetch2D(depthtex0, ivec2(halfResTC2), 0).x; + gl_FragData[0].rgb = texelFetch2D(colortex2, ivec2(gl_FragCoord.xy),0).rgb * 10.0; + gl_FragData[0].a = 0.0; - #ifdef DISTANT_HORIZONS - float DH_depth = texelFetch2D(dhDepthTex, ivec2(halfResTC2),0).x; - vec3 viewPos = toScreenSpace_DH(halfResTC*texelSize, depth, DH_depth); - #else - vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, depth)); - #endif - #else - vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, 1.0)); - #endif + } - vec3 tesvar = vec3(0.0); - vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(), blueNoise()), sunColor/80.0, averageSkyCol/30.0,tesvar); + gl_FragData[1] = vec4(0,0,0,0); - gl_FragData[0] = VolumetricClouds; - #else - gl_FragData[0] = vec4(0.0,0.0,0.0,1.0); - #endif } \ No newline at end of file diff --git a/shaders/dimensions/deferred2.vsh b/shaders/dimensions/deferred2.vsh index 8dd15ea..3b61b94 100644 --- a/shaders/dimensions/deferred2.vsh +++ b/shaders/dimensions/deferred2.vsh @@ -1,56 +1,9 @@ -#include "/lib/settings.glsl" - -// uniform int dhRenderDistance; - - #ifdef Daily_Weather - flat varying vec4 dailyWeatherParams0; - flat varying vec4 dailyWeatherParams1; - #endif - - -flat varying vec3 averageSkyCol; -flat varying vec3 sunColor; -// flat varying vec3 moonColor; - - -flat varying float tempOffsets; -flat varying vec3 WsunVec; -uniform mat4 gbufferModelViewInverse; -uniform vec3 sunPosition; -uniform float sunElevation; - -uniform sampler2D colortex4; -uniform int frameCounter; -uniform float frameTimeCounter; - -#include "/lib/util.glsl" #include "/lib/res_params.glsl" -#include "/lib/Shadow_Params.glsl" - void main() { - gl_Position = ftransform(); - gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(CLOUDS_QUALITY+0.01,0.0,1.0)*2.0-1.0; - #if defined Daily_Weather - dailyWeatherParams0 = vec4(texelFetch2D(colortex4,ivec2(1,1),0).rgb / 1500.0, 0.0); - dailyWeatherParams1 = vec4(texelFetch2D(colortex4,ivec2(2,1),0).rgb / 1500.0, 0.0); - #endif - - averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb; - sunColor = texelFetch2D(colortex4,ivec2(6,37),0).rgb; - // moonColor = texelFetch2D(colortex4,ivec2(13,37),0).rgb; - - // sunColor = texelFetch2D(colortex4,ivec2(8,37),0).rgb; - // moonColor = texelFetch2D(colortex4,ivec2(9,37),0).rgb; - - - WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);// * (float(sunElevation > 1e-5)*2.0-1.0); - // WsunVec = normalize(LightDir); - - tempOffsets = HaltonSeq2(frameCounter%10000); #ifdef TAA_UPSCALING gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; #endif -} \ No newline at end of file +} diff --git a/shaders/shaders.properties b/shaders/shaders.properties index a742e59..d6c288f 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -75,16 +75,6 @@ program.world1/gbuffers_block_translucent.enabled = TRANSLUCENT_ENTITIES && IS_I program.world-1/dh_water.enabled = false #endif - -#ifdef CLOUDS_INTERSECT_TERRAIN - program.world0/deferred2.enabled = false - program.world0/deferred2.enabled = false - program.world1/deferred2.enabled = false - program.world1/deferred2.enabled = false - program.world-1/deferred2.enabled = false - program.world-1/deferred2.enabled = false -#endif - program.world0/composite11.enabled = false program.world0/composite5.enabled = TAA_UPSCALING program.world1/composite5.enabled = TAA_UPSCALING @@ -106,7 +96,7 @@ blend.gbuffers_block_translucent = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_A blend.gbuffers_beaconbeam = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE blend.gbuffers_entities_translucent = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE blend.gbuffers_spidereyes = ONE ONE ONE ONE -blend.gbuffers_skytextured = ONE ONE ONE ZERO +blend.gbuffers_skytextured = ONE ONE ONE ONE blend.shadow = ONE ZERO ONE ZERO # Disable blending diff --git a/shaders/world-1/gbuffers_skytextured.fsh b/shaders/world-1/gbuffers_skytextured.fsh index 653be9a..26ce0e9 100644 --- a/shaders/world-1/gbuffers_skytextured.fsh +++ b/shaders/world-1/gbuffers_skytextured.fsh @@ -1,43 +1,6 @@ #version 120 -#include "/lib/settings.glsl" - -#if RESOURCEPACK_SKY != 0 - varying vec4 color; - varying vec2 texcoord; - uniform sampler2D texture; - - uniform int renderStage; - - float interleaved_gradientNoise(){ - // vec2 coord = gl_FragCoord.xy + (frameCounter%40000); - vec2 coord = gl_FragCoord.xy ; - // vec2 coord = gl_FragCoord.xy; - float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); - return noise ; - } -#endif void main() { - #if RESOURCEPACK_SKY != 0 - /* RENDERTARGETS:10 */ - - vec4 COLOR = texture2D(texture, texcoord.xy)*color; - - #if RESOURCEPACK_SKY == 3 - if(renderStage == 1 || renderStage == 3) { discard; return; } - #endif - - #if RESOURCEPACK_SKY == 1 - if(renderStage == 4 || renderStage == 5) { discard; return; } - #else - if(renderStage == 4) COLOR.rgb *= 5.0; - #endif - - COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0); - - gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a); - #else - discard; - #endif + discard; return; } diff --git a/shaders/world-1/gbuffers_skytextured.vsh b/shaders/world-1/gbuffers_skytextured.vsh index 081e29e..7f8b4b1 100644 --- a/shaders/world-1/gbuffers_skytextured.vsh +++ b/shaders/world-1/gbuffers_skytextured.vsh @@ -1,40 +1,5 @@ #version 120 -#include "/lib/settings.glsl" - -#if RESOURCEPACK_SKY != 0 - #include "/lib/res_params.glsl" - /* - !! DO NOT REMOVE !! - This code is from Chocapic13' shaders - Read the terms of modification and sharing before changing something below please ! - !! DO NOT REMOVE !! - */ - varying vec4 color; - varying vec2 texcoord; - uniform vec2 texelSize; - uniform int framemod8; - const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - -#endif void main() { gl_Position = ftransform(); - - #if RESOURCEPACK_SKY != 0 - texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; - color = gl_Color; - #ifdef TAA_UPSCALING - gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; - #endif - #ifdef TAA - gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; - #endif - #endif } \ No newline at end of file diff --git a/shaders/world0/gbuffers_skytextured.fsh b/shaders/world0/gbuffers_skytextured.fsh index 653be9a..5b52ad9 100644 --- a/shaders/world0/gbuffers_skytextured.fsh +++ b/shaders/world0/gbuffers_skytextured.fsh @@ -5,8 +5,10 @@ varying vec4 color; varying vec2 texcoord; uniform sampler2D texture; + uniform sampler2D depthtex0; uniform int renderStage; + uniform vec2 texelSize; float interleaved_gradientNoise(){ // vec2 coord = gl_FragCoord.xy + (frameCounter%40000); @@ -15,14 +17,23 @@ float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); return noise ; } + + vec3 toLinear(vec3 sRGB){ + return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); + } + #endif + void main() { #if RESOURCEPACK_SKY != 0 - /* RENDERTARGETS:10 */ + /* RENDERTARGETS:2 */ - vec4 COLOR = texture2D(texture, texcoord.xy)*color; + gl_FragData[0] = vec4(0.0,0.0,0.0,1.0); + vec4 COLOR = texture2D(texture, texcoord.xy); + COLOR.rgb = toLinear(COLOR.rgb); + COLOR *= color; #if RESOURCEPACK_SKY == 3 if(renderStage == 1 || renderStage == 3) { discard; return; } @@ -31,12 +42,12 @@ void main() { #if RESOURCEPACK_SKY == 1 if(renderStage == 4 || renderStage == 5) { discard; return; } #else - if(renderStage == 4) COLOR.rgb *= 5.0; + if(renderStage == 4 || renderStage == MC_RENDER_STAGE_SUN) COLOR.rgb *= 5.0; #endif COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0); - gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a); + gl_FragData[0] = vec4(COLOR.rgb*0.1, COLOR.a); #else discard; #endif diff --git a/shaders/world0/gbuffers_skytextured.vsh b/shaders/world0/gbuffers_skytextured.vsh index 081e29e..331c8de 100644 --- a/shaders/world0/gbuffers_skytextured.vsh +++ b/shaders/world0/gbuffers_skytextured.vsh @@ -28,13 +28,16 @@ void main() { gl_Position = ftransform(); #if RESOURCEPACK_SKY != 0 + texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; color = gl_Color; + #ifdef TAA_UPSCALING gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; #endif #ifdef TAA gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; #endif + #endif } \ No newline at end of file diff --git a/shaders/world1/gbuffers_skytextured.fsh b/shaders/world1/gbuffers_skytextured.fsh index 653be9a..26ce0e9 100644 --- a/shaders/world1/gbuffers_skytextured.fsh +++ b/shaders/world1/gbuffers_skytextured.fsh @@ -1,43 +1,6 @@ #version 120 -#include "/lib/settings.glsl" - -#if RESOURCEPACK_SKY != 0 - varying vec4 color; - varying vec2 texcoord; - uniform sampler2D texture; - - uniform int renderStage; - - float interleaved_gradientNoise(){ - // vec2 coord = gl_FragCoord.xy + (frameCounter%40000); - vec2 coord = gl_FragCoord.xy ; - // vec2 coord = gl_FragCoord.xy; - float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); - return noise ; - } -#endif void main() { - #if RESOURCEPACK_SKY != 0 - /* RENDERTARGETS:10 */ - - vec4 COLOR = texture2D(texture, texcoord.xy)*color; - - #if RESOURCEPACK_SKY == 3 - if(renderStage == 1 || renderStage == 3) { discard; return; } - #endif - - #if RESOURCEPACK_SKY == 1 - if(renderStage == 4 || renderStage == 5) { discard; return; } - #else - if(renderStage == 4) COLOR.rgb *= 5.0; - #endif - - COLOR.rgb = max(COLOR.rgb - COLOR.rgb * interleaved_gradientNoise()*0.05, 0.0); - - gl_FragData[0] = vec4(COLOR.rgb/5.0, COLOR.a); - #else - discard; - #endif + discard; return; } diff --git a/shaders/world1/gbuffers_skytextured.vsh b/shaders/world1/gbuffers_skytextured.vsh index 081e29e..7f8b4b1 100644 --- a/shaders/world1/gbuffers_skytextured.vsh +++ b/shaders/world1/gbuffers_skytextured.vsh @@ -1,40 +1,5 @@ #version 120 -#include "/lib/settings.glsl" - -#if RESOURCEPACK_SKY != 0 - #include "/lib/res_params.glsl" - /* - !! DO NOT REMOVE !! - This code is from Chocapic13' shaders - Read the terms of modification and sharing before changing something below please ! - !! DO NOT REMOVE !! - */ - varying vec4 color; - varying vec2 texcoord; - uniform vec2 texelSize; - uniform int framemod8; - const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - -#endif void main() { gl_Position = ftransform(); - - #if RESOURCEPACK_SKY != 0 - texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; - color = gl_Color; - #ifdef TAA_UPSCALING - gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; - #endif - #ifdef TAA - gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; - #endif - #endif } \ No newline at end of file