From efb6925a35a8fbab0082c0811a6adcf18ed411ee Mon Sep 17 00:00:00 2001 From: Merlin1809 <88194861+Merlin1809@users.noreply.github.com> Date: Sun, 22 Mar 2026 21:13:52 +0100 Subject: [PATCH] Add Photonics 0.3.1 support, add denoised rough reflections, add reflections of handheld colored lights, improve look of hardcoded SSS on snowy grass, fix multiple photonics issues, add more photonics settings, fix physics mod oceans not working with newest physics mod --- shaders/block.properties | 4 +- shaders/dimensions/DH_translucent.fsh | 4 +- shaders/dimensions/all_particles.fsh | 13 +- shaders/dimensions/all_solid.fsh | 6 +- shaders/dimensions/all_translucent.fsh | 12 +- shaders/dimensions/begin.csh | 4 + shaders/dimensions/composite.fsh | 71 +- shaders/dimensions/composite1.fsh | 73 +- shaders/dimensions/composite10.fsh | 392 +--- shaders/dimensions/composite10.vsh | 14 +- shaders/dimensions/composite11.fsh | 497 +++-- shaders/dimensions/composite11.vsh | 3 +- shaders/dimensions/composite12.fsh | 190 ++ shaders/dimensions/composite12.vsh | 14 + shaders/dimensions/composite2.fsh | 1326 +++++-------- shaders/dimensions/composite2.vsh | 78 +- shaders/dimensions/composite3.fsh | 1693 +++++++++-------- shaders/dimensions/composite3.vsh | 78 +- shaders/dimensions/composite4.fsh | 998 +++++++++- shaders/dimensions/composite4.vsh | 53 +- shaders/dimensions/composite5.fsh | 514 +---- shaders/dimensions/composite5.vsh | 24 +- shaders/dimensions/composite6.fsh | 469 ++++- shaders/dimensions/composite6.vsh | 33 +- shaders/dimensions/composite7.fsh | 52 +- shaders/dimensions/composite7.vsh | 2 +- shaders/dimensions/composite8.fsh | 60 +- shaders/dimensions/composite8.vsh | 10 +- shaders/dimensions/composite9.fsh | 35 +- shaders/dimensions/prepare4.fsh | 5 +- shaders/dimensions/voxels.fsh | 260 +-- shaders/dimensions/voxels.vsh | 2 - shaders/dimensions/voxels_shadow.fsh | 38 +- shaders/dimensions/voxels_shadow.vsh | 25 +- shaders/dimensions/voxy.json | 4 + shaders/lang/en_us.lang | 21 +- shaders/lang/zh_cn.lang | 2 +- shaders/lib/SSBOs.glsl | 4 + shaders/lib/blocks.glsl | 1 + shaders/lib/diffuse_lighting.glsl | 107 +- shaders/lib/oceans.glsl | 29 - shaders/lib/overworld_fog.glsl | 8 +- shaders/lib/settings.glsl | 30 +- shaders/lib/specular.glsl | 204 +- shaders/lib/volumetricClouds.glsl | 6 +- shaders/photonics/restir/lighting.fsh | 99 + shaders/photonics/shader_interface.glsl | 2 + shaders/shaders.properties | 34 +- shaders/world-1/composite12.fsh | 5 + shaders/world-1/composite12.vsh | 5 + shaders/world0/composite12.fsh | 5 + shaders/world0/composite12.vsh | 5 + shaders/world0/shadow.vsh | 27 +- .../world0_with_aether_flag/composite12.fsh | 6 + .../world0_with_aether_flag/composite12.vsh | 6 + .../composite12.fsh | 6 + .../composite12.vsh | 6 + shaders/world1/composite12.fsh | 5 + shaders/world1/composite12.vsh | 5 + 59 files changed, 4377 insertions(+), 3307 deletions(-) create mode 100644 shaders/dimensions/composite12.fsh create mode 100644 shaders/dimensions/composite12.vsh create mode 100644 shaders/photonics/restir/lighting.fsh create mode 100644 shaders/world-1/composite12.fsh create mode 100644 shaders/world-1/composite12.vsh create mode 100644 shaders/world0/composite12.fsh create mode 100644 shaders/world0/composite12.vsh create mode 100644 shaders/world0_with_aether_flag/composite12.fsh create mode 100644 shaders/world0_with_aether_flag/composite12.vsh create mode 100644 shaders/world0_with_twilight_forest_flag/composite12.fsh create mode 100644 shaders/world0_with_twilight_forest_flag/composite12.vsh create mode 100644 shaders/world1/composite12.fsh create mode 100644 shaders/world1/composite12.vsh diff --git a/shaders/block.properties b/shaders/block.properties index d408373..a2c697c 100644 --- a/shaders/block.properties +++ b/shaders/block.properties @@ -198,7 +198,7 @@ block.80=minecraft:pink_petals minecraft:wildflowers minecraft:attached_melon_st #define snow_layers_5_8_entry snow:layers=5 snow:layers=6 snow:layers=7 snow:layers=8 #endif ## weak sss and floodfill ignore -block.81=minecraft:pitcher_plant minecraft:grass_block:snowy=true weeping_vines_plant twisting_vines_plant tube_coral tube_coral_block tube_coral_fan tube_coral_wall_fan horn_coral horn_coral_block horn_coral_fan horn_coral_wall_fan fire_coral fire_coral_block fire_coral_fan fire_coral_wall_fan dead_brain_coral dead_brain_coral_block dead_brain_coral_fan dead_brain_coral_wall_fan dead_bubble_coral dead_bubble_coral_block dead_bubble_coral_fan dead_bubble_coral_wall_fan dead_fire_coral dead_fire_coral_block dead_fire_coral_fan dead_fire_coral_wall_fan dead_horn_coral dead_horn_coral_block dead_horn_coral_fan dead_horn_coral_wall_fan dead_tube_coral dead_tube_coral_block dead_tube_coral_fan dead_tube_coral_wall_fan bubble_coral bubble_coral_block bubble_coral_fan bubble_coral_wall_fan brain_coral brain_coral_block brain_coral_fan brain_coral_wall_fan minecraft:spore_blossom minecraft:mushroom_stem minecraft:sea_pickle:waterlogged=false \ +block.81=minecraft:pitcher_plant weeping_vines_plant twisting_vines_plant tube_coral tube_coral_block tube_coral_fan tube_coral_wall_fan horn_coral horn_coral_block horn_coral_fan horn_coral_wall_fan fire_coral fire_coral_block fire_coral_fan fire_coral_wall_fan dead_brain_coral dead_brain_coral_block dead_brain_coral_fan dead_brain_coral_wall_fan dead_bubble_coral dead_bubble_coral_block dead_bubble_coral_fan dead_bubble_coral_wall_fan dead_fire_coral dead_fire_coral_block dead_fire_coral_fan dead_fire_coral_wall_fan dead_horn_coral dead_horn_coral_block dead_horn_coral_fan dead_horn_coral_wall_fan dead_tube_coral dead_tube_coral_block dead_tube_coral_fan dead_tube_coral_wall_fan bubble_coral bubble_coral_block bubble_coral_fan bubble_coral_wall_fan brain_coral brain_coral_block brain_coral_fan brain_coral_wall_fan minecraft:spore_blossom minecraft:mushroom_stem minecraft:sea_pickle:waterlogged=false \ aquamirae:painting_anglerfish aquamirae:painting_oxygelium aquamirae:painting_tortured_soul aquamirae:painting_aurora \ beachparty:seashell_block beachparty:beach_parasol \ biomesoplenty:toadstool \ @@ -243,6 +243,8 @@ block.88=minecraft:small_amethyst_bud pointed_dripstone block.89=minecraft:cactus +block.90=minecraft:grass_block:snowy=true + ####### ----- lightsources ----- ####### block.101=large_amethyst_bud \ diff --git a/shaders/dimensions/DH_translucent.fsh b/shaders/dimensions/DH_translucent.fsh index d4ae118..aca728b 100644 --- a/shaders/dimensions/DH_translucent.fsh +++ b/shaders/dimensions/DH_translucent.fsh @@ -17,7 +17,7 @@ uniform float frameTimeCounter; uniform sampler2D noisetex; const bool shadowHardwareFiltering = true; -uniform sampler2DShadow shadow; +uniform sampler2DShadow shadowtex0HW; #ifdef DISTANT_HORIZONS uniform sampler2D dhDepthTex; @@ -393,7 +393,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) Shadows = 0.0; projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5); - Shadows = texture(shadow, projectedShadowPosition + vec3(0.0,0.0, smallbias)).x; + Shadows = texture(shadowtex0HW, projectedShadowPosition + vec3(0.0,0.0, smallbias)).x; } #endif diff --git a/shaders/dimensions/all_particles.fsh b/shaders/dimensions/all_particles.fsh index 7259fbb..04071d9 100644 --- a/shaders/dimensions/all_particles.fsh +++ b/shaders/dimensions/all_particles.fsh @@ -41,12 +41,11 @@ in DATA { #ifdef OVERWORLD_SHADER const bool shadowHardwareFiltering = true; - uniform sampler2DShadow shadow; + uniform sampler2DShadow shadowtex0HW; #ifdef TRANSLUCENT_COLORED_SHADOWS uniform sampler2D shadowcolor0; - uniform sampler2DShadow shadowtex0; - uniform sampler2DShadow shadowtex1; + uniform sampler2DShadow shadowtex1HW; #endif #endif @@ -208,10 +207,10 @@ float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDis #ifdef TRANSLUCENT_COLORED_SHADOWS // determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth - float shadowDepthDiff = pow(clamp((texture(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); + float shadowDepthDiff = pow(clamp((texture(shadowtex1HW, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); // get opaque shadow data to get opaque data from translucent shadows. - float opaqueShadow = texture(shadowtex0, projectedShadowPosition).x; + float opaqueShadow = texture(shadowtex0HW, projectedShadowPosition).x; shadowmap += max(opaqueShadow, shadowDepthDiff); // get translucent shadow data @@ -228,7 +227,7 @@ float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDis translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff); #else - shadowmap += texture(shadow, projectedShadowPosition).x; + shadowmap += texture(shadowtex0HW, projectedShadowPosition).x; #endif #ifdef TRANSLUCENT_COLORED_SHADOWS @@ -345,7 +344,7 @@ void main() { float maxdist = MAX_OCCLUSION_DISTANCE; if (dist < maxdist) { - float depthmap = readNormal(clamp(texcoord.st, texcoordam.st, texcoordam.st + texcoordam.pq)).a; + float depthmap = readNormal(texcoord.st).a; float used_POM_DEPTH = 1.0; if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) { diff --git a/shaders/dimensions/all_solid.fsh b/shaders/dimensions/all_solid.fsh index 26a9b6b..83a28e9 100644 --- a/shaders/dimensions/all_solid.fsh +++ b/shaders/dimensions/all_solid.fsh @@ -445,7 +445,7 @@ void main() { if (falloff > 0.0) #endif { - float depthmap = readNormal(clamp(data_in.texcoord.st, data_in.texcoordam.st, data_in.texcoordam.st + data_in.texcoordam.pq)).a; + float depthmap = readNormal(data_in.texcoord.st).a; float pomdepth = POM_DEPTH * falloff; if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) { @@ -799,7 +799,9 @@ void main() { #endif ) { SSSAMOUNT = 0.5; - } + } else if(data_in.blockID == GRASS_BLOCK_SNOWY) { + SSSAMOUNT = 0.5 * smoothstep(0.0, 1.0, fract(worldpos.y)); + } #if defined CUTOUT else if (data_in.blockID == -BLOCK_GRASS) { SSSAMOUNT = 0.3; diff --git a/shaders/dimensions/all_translucent.fsh b/shaders/dimensions/all_translucent.fsh index 0f5a715..6eb3ebb 100644 --- a/shaders/dimensions/all_translucent.fsh +++ b/shaders/dimensions/all_translucent.fsh @@ -53,12 +53,11 @@ uniform vec4 entityColor; #if defined OVERWORLD_SHADER || (defined END_ISLAND_LIGHT && defined END_SHADER) const bool shadowHardwareFiltering = true; - uniform sampler2DShadow shadow; + uniform sampler2DShadow shadowtex0HW; #ifdef TRANSLUCENT_COLORED_SHADOWS uniform sampler2D shadowcolor0; - uniform sampler2DShadow shadowtex0; - uniform sampler2DShadow shadowtex1; + uniform sampler2DShadow shadowtex1HW; #endif uniform float lightSign; @@ -225,6 +224,7 @@ vec2 decodeVec2(float a){ #define VOXEL_REFLECTIONS_TRANSLUCENT #ifdef VOXEL_REFLECTIONS_TRANSLUCENT + #define VOXEL_REFLECTIONS #endif #ifdef PHOTONICS @@ -441,10 +441,10 @@ float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDis #ifdef TRANSLUCENT_COLORED_SHADOWS // determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth - float shadowDepthDiff = pow(clamp((texture(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); + float shadowDepthDiff = pow(clamp((texture(shadowtex1HW, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); // get opaque shadow data to get opaque data from translucent shadows. - float opaqueShadow = texture(shadowtex0, projectedShadowPosition).x; + float opaqueShadow = texture(shadowtex0HW, projectedShadowPosition).x; shadowmap += max(opaqueShadow, shadowDepthDiff); // get translucent shadow data @@ -461,7 +461,7 @@ float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDis translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff); #else - shadowmap += texture(shadow, projectedShadowPosition).x; + shadowmap += texture(shadowtex0HW, projectedShadowPosition).x; #endif #ifdef BASIC_SHADOW_FILTER diff --git a/shaders/dimensions/begin.csh b/shaders/dimensions/begin.csh index 5a803d4..72f8055 100644 --- a/shaders/dimensions/begin.csh +++ b/shaders/dimensions/begin.csh @@ -221,6 +221,10 @@ void main() { customShadowMatrixSSBO = BuildShadowViewMatrix(normalize(END_LIGHT_POS)); customShadowPerspectiveSSBO = createPerspectiveMatrix(); #endif + + #ifdef PHOTONICS + customShadowMatrixInverseSSBO = inverse(customShadowMatrixSSBO); + #endif #ifdef OVERWORLD_SHADER //////////////////////////////// diff --git a/shaders/dimensions/composite.fsh b/shaders/dimensions/composite.fsh index 6cdff13..2d05419 100644 --- a/shaders/dimensions/composite.fsh +++ b/shaders/dimensions/composite.fsh @@ -10,6 +10,7 @@ in DATA { #endif }; +#include "/lib/util.glsl" #include "/lib/res_params.glsl" uniform sampler2D depthtex0; @@ -30,8 +31,12 @@ uniform sampler2D depthtex2; #define dhVoxyDepthTex1 vxDepthTexOpaque #endif +#include "/lib/Shadow_Params.glsl" + uniform sampler2D colortex1; uniform sampler2D colortex3; // Noise +uniform sampler2D colortex4; +uniform sampler2D colortex5; uniform sampler2D colortex6; // Noise uniform sampler2D colortex7; // Noise uniform sampler2D colortex8; // Noise @@ -41,11 +46,13 @@ uniform sampler2D colortex10; // Noise uniform sampler2D colortex12; // Noise uniform sampler2D colortex13; // Noise uniform int isEyeInWater; -uniform sampler2D shadow; + +const bool shadowHardwareFiltering = true; +uniform sampler2D shadowtex0; +uniform sampler2DShadow shadowtex0HW; #ifdef TRANSLUCENT_COLORED_SHADOWS uniform sampler2D shadowcolor0; - uniform sampler2D shadowtex0; uniform sampler2D shadowtex1; #endif @@ -58,21 +65,9 @@ uniform float rainStrength; uniform int frameCounter; uniform ivec2 eyeBrightnessSmooth; - -uniform mat4 gbufferModelViewInverse; -uniform mat4 gbufferModelView; - - -uniform vec3 cameraPosition; -uniform mat4 gbufferProjection; -uniform mat4 gbufferProjectionInverse; - uniform vec3 previousCameraPosition; -uniform mat4 gbufferPreviousProjection; uniform mat4 gbufferPreviousModelView; -uniform mat4 shadowModelView; -uniform mat4 shadowProjection; uniform float viewWidth; uniform float aspectRatio; uniform float viewHeight; @@ -81,19 +76,32 @@ uniform float viewHeight; uniform float near; uniform float dhVoxyFarPlane; uniform float dhVoxyNearPlane; +uniform float nightVision; +#define DEFERRED_SPECULAR +#define DEFERRED_SSR_QUALITY 30 // [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 200 300 400 500] +#define DEFERRED_BACKGROUND_REFLECTION +#define DEFERRED_ROUGH_REFLECTION + +#ifdef DEFERRED_SPECULAR +#endif +#if DEFERRED_SSR_QUALITY > -1 +#endif +#ifdef DEFERRED_BACKGROUND_REFLECTION +#endif +#ifdef DEFERRED_ROUGH_REFLECTION +#endif + +uniform float waterEnteredAltitude; +uniform float sunElevation; + +#include "/lib/projections.glsl" +#include "/lib/DistantHorizons_projections.glsl" +#include "/lib/color_transforms.glsl" +#include "/lib/waterBump.glsl" #include "/lib/Shadows.glsl" #define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0) -#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; -} - vec3 worldToView(vec3 worldPos) { vec4 pos = vec4(worldPos, 0.0); @@ -178,13 +186,6 @@ vec2 R2_samples(int n){ return fract(alpha * n); } - - - - - - - vec3 viewToWorld(vec3 viewPos) { vec4 pos; pos.xyz = viewPos; @@ -193,10 +194,7 @@ vec3 viewToWorld(vec3 viewPos) { return pos.xyz; } -#include "/lib/Shadow_Params.glsl" - -const float PI = 3.141592653589793238462643383279502884197169; vec2 SpiralSample( int samples, int totalSamples, float rotation, float Xi ){ @@ -238,8 +236,6 @@ vec2 CleanSample( -#include "/lib/DistantHorizons_projections.glsl" - float DH_ld(float dist) { return (2.0 * dhVoxyNearPlane) / (dhVoxyFarPlane + dhVoxyNearPlane - dist * (dhVoxyFarPlane - dhVoxyNearPlane)); } @@ -398,7 +394,6 @@ float ld(float dist) { /* RENDERTARGETS:3,14,9*/ void main() { - float noise = R2_dither(); vec2 texcoord = gl_FragCoord.xy*texelSize; @@ -411,7 +406,7 @@ void main() { float lightLeakFix = clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); - gl_FragData[1] = vec4(0.0,0.0, texelFetch(colortex14, ivec2(gl_FragCoord.xy), 0).b, 0.0); + gl_FragData[1] = vec4(0.0); vec4 SpecularData = texelFetch(colortex8, ivec2(gl_FragCoord.xy), 0); @@ -602,7 +597,7 @@ void main() { float weight = 3.0 + (i+noise) * rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7; - float d = texelFetch(shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x; + float d = texelFetch(shadowtex0, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x; float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d); blockerCount += b; diff --git a/shaders/dimensions/composite1.fsh b/shaders/dimensions/composite1.fsh index c0f2562..f521e20 100644 --- a/shaders/dimensions/composite1.fsh +++ b/shaders/dimensions/composite1.fsh @@ -29,12 +29,11 @@ uniform float rainStrength; #if defined OVERWORLD_SHADER || (defined END_ISLAND_LIGHT && defined END_SHADER) const bool shadowHardwareFiltering = true; - uniform sampler2DShadow shadow; + uniform sampler2DShadow shadowtex0HW; #ifdef TRANSLUCENT_COLORED_SHADOWS uniform sampler2D shadowcolor0; - uniform sampler2DShadow shadowtex0; - uniform sampler2DShadow shadowtex1; + uniform sampler2DShadow shadowtex1HW; #endif #if ShaderSnow > 0 @@ -118,6 +117,8 @@ uniform sampler2D colortex12; uniform sampler2D colortex13; uniform sampler2D colortex14; uniform sampler2D colortex15; +uniform sampler2D colortex17; +uniform sampler2D colortex18; in DATA { flat vec2 TAA_Offset; @@ -132,7 +133,7 @@ in DATA { uniform float sunElevation; -#if defined IS_LPV_ENABLED || defined PHOTONICS && defined PHOTONICS && !defined PH_ENABLE_HANDHELD_LIGHT +#if defined IS_LPV_ENABLED || defined PHOTONICS uniform usampler1D texBlockData; uniform sampler3D texLpv1; uniform sampler3D texLpv2; @@ -168,14 +169,13 @@ uniform vec3 sunVec; #define VOXEL_REFLECTIONS_SOLID #ifdef VOXEL_REFLECTIONS_SOLID + #define VOXEL_REFLECTIONS #endif #ifdef PHOTONICS - #ifdef VOXEL_REFLECTIONS - #define PHOTONICS_INCLUDED + #define PHOTONICS_INCLUDED - #include "/photonics/photonics.glsl" - #endif + #include "/photonics/photonics.glsl" #endif @@ -242,6 +242,10 @@ float convertHandDepth_2(in float depth, bool hand) { #ifdef DEFERRED_ROUGH_REFLECTION #endif +#ifndef DEFERRED_ROUGH_REFLECTION + #undef DENOISED_REFLECTIONS +#endif + #define MAIN_SHADOW_PASS #define FULLRESDEPTH @@ -746,8 +750,8 @@ vec3 ComputeShadowMap_COLOR(in vec3 projectedShadowPosition, float distortFactor #endif #ifdef TRANSLUCENT_COLORED_SHADOWS - float opaqueShadow = texture(shadowtex0, projectedShadowPosition).x; - float opaqueShadowT = texture(shadowtex1, projectedShadowPosition).x; + float opaqueShadow = texture(shadowtex0HW, projectedShadowPosition).x; + float opaqueShadowT = texture(shadowtex1HW, projectedShadowPosition).x; vec4 translucentShadow = texture(shadowcolor0, projectedShadowPosition.xy); float shadowAlpha = pow(1.0-pow(1.0-translucentShadow.a,2.0),5.0); @@ -760,8 +764,8 @@ vec3 ComputeShadowMap_COLOR(in vec3 projectedShadowPosition, float distortFactor translucentTint += mix(translucentShadow.rgb, vec3(1.0), max(opaqueShadow, backface * (shadowAlpha < 1.0 ? 0.0 : 1.0))); FUNNYSHADOW += ((1.0-shadowAlpha) * opaqueShadowT)/samples; #else - // shadowColor += directLightColor * texture(shadow, projectedShadowPosition).x; - shadowColor += vec3(1.0) * texture(shadow, projectedShadowPosition).x; + // shadowColor += directLightColor * texture(shadowtex0HW, projectedShadowPosition).x; + shadowColor += vec3(1.0) * texture(shadowtex0HW, projectedShadowPosition).x; #endif @@ -770,7 +774,7 @@ vec3 ComputeShadowMap_COLOR(in vec3 projectedShadowPosition, float distortFactor #endif #if DEBUG_VIEW == debug_SHADOWMAP - shadowDebug = texture(shadow, projectedShadowPosition).x; + shadowDebug = texture(shadowtex0HW, projectedShadowPosition).x; #endif // #ifdef TRANSLUCENT_COLORED_SHADOWS // // directLightColor *= mix(vec3(1.0), translucentTint.rgb / samples, maxDistFade); @@ -865,8 +869,8 @@ uniform float wetness; vec2 driprate = vec2(0.0,frameTimeCounter)*0.05; - vec2 UV = mix(worldPos.xz, worldPos.xy*vec2(2.0, 0.5)+driprate, abs(flatNormals.z)); - UV = mix(UV, worldPos.zy*vec2(2.0, 0.5)+driprate, abs(flatNormals.x)); + vec2 UV = mix(worldPos.xz, worldPos.xy*vec2(2.0, 0.5)+driprate, 0.0); + UV = mix(UV, worldPos.zy*vec2(2.0, 0.5)+driprate, 0.0); #ifdef SHADER_GRASS if(isShaderGrass) UV = worldPos.xz; @@ -968,8 +972,30 @@ uniform float wetness; } #endif -void main() { +//encoding by jodie +float encodeVec2(vec2 a){ + const vec2 constant1 = vec2( 1., 256.) / 65535.; + vec2 temp = floor( a * 255. ); + return temp.x*constant1.x+temp.y*constant1.y; +} +float encodeVec2(float x,float y){ + return encodeVec2(vec2(x,y)); +} +vec2 encodeNormal(vec3 n){ + n.xy = n.xy / dot(abs(n), vec3(1.0)); + n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy; + vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0); + + return encn; +} + +void main() { + #if defined DEFERRED_SPECULAR && defined DENOISED_REFLECTIONS + gl_FragData[1] = vec4(0.0); + gl_FragData[2] = vec4(0.0); + gl_FragData[3] = vec4(0.0); + #endif vec3 DEBUG = vec3(1.0); ////// --------------- SETUP STUFF --------------- ////// @@ -1676,8 +1702,17 @@ void main() { vec2 specularNoises = vec2(blueNoise(), ig_noise); vec3 specularNormal = normal; if (dot(normal, (feetPlayerPos_normalized)) > 0.0) specularNormal = FlatNormals; + + vec4 reflections = vec4(0.0,0.0,0.0,1.0); + float SunReflectionAlpha = 0.0; - FINAL_COLOR = specularReflections(viewPos, feetPlayerPos, feetPlayerPos_normalized, WsunVec, specularNoises, FlatNormals, specularNormal, SpecularTex.r, SpecularTex.g, albedo, FINAL_COLOR, DirectLightColor*shadowColor*shadowColor, lightmap.y, hand, flashLightSpecularData); + FINAL_COLOR = specularReflections(viewPos, feetPlayerPos, feetPlayerPos_normalized, WsunVec, specularNoises, FlatNormals, specularNormal, SpecularTex.r, SpecularTex.g, albedo, FINAL_COLOR, DirectLightColor*shadowColor*shadowColor, lightmap.y, hand, reflections, SunReflectionAlpha, flashLightSpecularData); + + #if defined DEFERRED_SPECULAR && defined DENOISED_REFLECTIONS + gl_FragData[1] = reflections; + gl_FragData[2].rgb = DirectLightColor*shadowColor*shadowColor*SunReflectionAlpha; + gl_FragData[3] = vec4(encodeNormal(specularNormal), SpecularTex.r, SpecularTex.g); + #endif #endif gl_FragData[0].rgb = FINAL_COLOR; @@ -1886,5 +1921,9 @@ void main() { // } #endif + #if defined DEFERRED_SPECULAR && defined DENOISED_REFLECTIONS + /* RENDERTARGETS:3,0,15,8 */ + #else /* RENDERTARGETS:3 */ + #endif } \ No newline at end of file diff --git a/shaders/dimensions/composite10.fsh b/shaders/dimensions/composite10.fsh index 5d2ab88..1065deb 100644 --- a/shaders/dimensions/composite10.fsh +++ b/shaders/dimensions/composite10.fsh @@ -1,367 +1,55 @@ -#include "/lib/settings.glsl" - -#include "/lib/res_params.glsl" - -#include "/lib/SSBOs.glsl" - -in vec2 texcoord; - -const bool colortex5MipmapEnabled = true; -// uniform sampler2D colortex4; -uniform sampler2D colortex5; -uniform sampler2D colortex3; -// uniform sampler2D colortex6; -uniform sampler2D colortex7; -// uniform sampler2D colortex8; // specular -uniform sampler2D colortex9; // specular -uniform sampler2D depthtex0; -uniform sampler2D depthtex1; -uniform sampler2D noisetex; +uniform sampler2D colortex6; uniform vec2 texelSize; - -uniform ivec2 eyeBrightnessSmooth; uniform float viewWidth; uniform float viewHeight; -uniform float frameTimeCounter; -uniform int frameCounter; -uniform int isEyeInWater; -uniform float near; -uniform float aspectRatio; -uniform float far; -uniform float rainStrength; -uniform float screenBrightness; -uniform vec4 Moon_Weather_properties; // R = cloud coverage G = fog density -uniform int hideGUI; - -uniform int framemod8; -#include "/lib/TAA_jitter.glsl" - - -uniform mat4 gbufferModelViewInverse; -uniform mat4 gbufferProjectionInverse; -vec4 Weather_properties = Moon_Weather_properties; - -#include "/lib/color_transforms.glsl" -#include "/lib/color_dither.glsl" -// #include "/lib/biome_specifics.glsl" -#include "/lib/bokeh.glsl" - -float cdist(vec2 coord) { - return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0; -} -float blueNoise(){ - return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); -} -float ld(float depth) { - return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near -} - -// uniform float viewWidth; -// uniform float viewHeight; - -// uniform sampler2D depthtex0; - -#ifdef DISTANT_HORIZONS - uniform sampler2D dhDepthTex; - #define dhVoxyDepthTex dhDepthTex -#endif - -#ifdef VOXY - uniform sampler2D vxDepthTexTrans; - #define dhVoxyDepthTex vxDepthTexTrans -#endif -uniform float dhVoxyNearPlane; -uniform float dhVoxyFarPlane; - -float linearizeDepthFast(const in float depth, const in float near, const in float far) { - return (near * far) / (depth * (near - far) + far); -} - -float bloomWeight(){ - - float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 ); - // float weights[7] = float[]( 0.7, pow(0.5,2), pow(0.5,3), pow(0.5,4), pow(0.5,5), pow(0.5,6), pow(0.5,7) ); - - float result = 0.0; - - for ( int i = 0; i < 7; i++) { - result += weights[i]; +vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); +vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ + vec4 tot = vec4(0.); + float maxTC = 0.25*resScale.y; + float minTC = 0.; + for (int i = -maxIT;i minTC && spCoord.y < maxTC); } - - return result; -} -vec3 invTonemap(vec3 col){ - return col/(1-luma(col)); -} -#define linear_to_srgb(x) (pow(x, vec3(1.0/2.2))) - -uniform sampler2D colortex6; - - -float w0(float a) -{ - return (1.0/6.0)*(a*(a*(-a + 3.0) - 3.0) + 1.0); + return tot.rgb/max(1.0,tot.a); } -float w1(float a) -{ - return (1.0/6.0)*(a*a*(3.0*a - 6.0) + 4.0); -} - -float w2(float a) -{ - return (1.0/6.0)*(a*(a*(-3.0*a + 3.0) + 3.0) + 1.0); -} - -float w3(float a) -{ - return (1.0/6.0)*(a*a*a); -} - -float g0(float a) -{ - return w0(a) + w1(a); -} - -float g1(float a) -{ - return w2(a) + w3(a); -} - -float h0(float a) -{ - return -1.0 + w1(a) / (w0(a) + w1(a)); -} - -float h1(float a) -{ - return 1.0 + w3(a) / (w2(a) + w3(a)); -} - -vec4 texture_bicubic(sampler2D tex, vec2 uv) -{ - vec4 texelSize = vec4(texelSize,1.0/texelSize); - uv = uv*texelSize.zw; - vec2 iuv = floor( uv ); - vec2 fuv = fract( uv ); - - float g0x = g0(fuv.x); - float g1x = g1(fuv.x); - float h0x = h0(fuv.x); - float h1x = h1(fuv.x); - float h0y = h0(fuv.y); - float h1y = h1(fuv.y); - - vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texelSize.xy; - vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texelSize.xy; - vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texelSize.xy; - vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texelSize.xy; - - return g0(fuv.y) * (g0x * texture(tex, p0) + - g1x * texture(tex, p1)) + - g1(fuv.y) * (g0x * texture(tex, p2) + - g1x * texture(tex, p3)); -} - -// vec3 lenseFlare(vec2 UV){ -// float noise = blueNoise(); - -// float vignetteLength = 0.2; -// float vignette = 0.5+length(texcoord-0.5);//min(max(length(texcoord-0.5) - vignetteLength,0.0) / (1.0/(1.0-vignetteLength)),1.0); - -// float aberrationStrength = vignette;//clamp(CHROMATIC_ABERRATION_STRENGTH * 0.01 * (1.0 - vignette),0.0,0.9) * vignette * 0.75; - -// vec2 centeredUV = texcoord - 0.5; - -// vec3 color = vec3(0.0); -// color = texture(colortex7, texcoord).rgb; - -// vec2 distortedUV = (centeredUV - (centeredUV ) * aberrationStrength) + 0.5; - -// color += texture(colortex7, distortedUV).rgb; -// // color.r = texture(colortex7, (centeredUV - (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).r; -// // color.g = texture(colortex7, texcoord).g; -// // color.b = texture(colortex7, (centeredUV + (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).b; - -// return color; -// } - -vec3 srgbToLinear(vec3 srgb){ - return mix( - srgb / 12.92, - pow(.947867 * srgb + .0521327, vec3(2.4) ), - step( .04045, srgb ) - ); -} -vec3 blackbody(float Temp) -{ - float t = pow(Temp, -1.5); - float lt = log(Temp); - - vec3 WB_temp = vec3(0.0); - WB_temp.r = 220000.0 * t + 0.58039215686; - WB_temp.g = 0.39231372549 * lt - 2.44549019608; - WB_temp.g = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : WB_temp.g; - WB_temp.b = 0.76078431372 * lt - 5.68078431373; - WB_temp = clamp(WB_temp,0,1); - WB_temp = Temp < 1000. ? WB_temp * Temp * 0.001 : WB_temp; - - return srgbToLinear(WB_temp); -} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// void main() { - /* RENDERTARGETS:7 */ - float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.); - vec3 col = texture(colortex5,texcoord).rgb; +/* RENDERTARGETS:6 */ +vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; - vec2 rodExposureDepth = rodExposureDepthSSBO; - rodExposureDepth.y = sqrt(rodExposureDepth.y/65000.0); +vec2 gaussDir = vec2(0.0,1.0); +gl_FragData[0].rgb = vec3(0.0); +vec2 tc2 = texcoord*vec2(2.0,1.); +if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,4.0),gaussDir,0.16,0); - vec4 exposure = vec4(exposureSSBO); +vec2 tc4 = texcoord*vec2(4.0,2.)-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*4.0; +if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,2.0),gaussDir,0.16,3); +vec2 tc8 = texcoord*vec2(8.0,4.)-vec2(0.75*resScale.x+8.*texelSize.x,0.)*8.0; +if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,2.0)/vec2(2.0,2.0),gaussDir,0.035,6); - #if DOF_QUALITY >= 0 - /*--------------------------------*/ - float z = ld(texture(depthtex1, texcoord*RENDER_SCALE).r)*far; - #if MANUAL_FOCUS == -2 - float focus = rodExposureDepth.y*far; - #elif MANUAL_FOCUS == -1 - float focus = mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25); - #elif MANUAL_FOCUS > 0 - float focus = MANUAL_FOCUS; - #endif - #if DOF_QUALITY < 5 - float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0); - #ifdef FAR_BLUR_ONLY - pcoc *= float(z > focus); - #endif - #ifdef REMOVE_HAND_BLUR - pcoc *= float(z > 0.56); - #endif - // float noise = blueNoise()*6.28318530718; - // mat2 noiseM = mat2( cos( noise ), -sin( noise ), - // sin( noise ), cos( noise ) - // ); - vec3 bcolor = vec3(0.); - float nb = 0.0; - vec2 bcoord = vec2(0.0); - /*--------------------------------*/ - float dofLodLevel = pcoc * 200.0; +vec2 tc16 = texcoord*vec2(16.0,8.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*16.0; +if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,4.0)/vec2(2.0,2.0),gaussDir,0.0085,12); - vec2 dispersion = (texcoord - 0.5) * pcoc * 200.0 * DOF_DISPERSION_MULT; +vec2 tc32 = texcoord*vec2(32.0,16.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*32.0; +if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,8.0)/vec2(2.0,2.0),gaussDir,0.002,30); - for ( int i = 0; i < BOKEH_SAMPLES; i++) { - // bcolor += textureLod(colortex5, texcoord.xy + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).rgb; - - bcolor.r += textureLod(colortex5, texcoord + (bokeh_offsets[i] + dispersion)*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).r; - bcolor.g += textureLod(colortex5, texcoord + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).g; - bcolor.b += textureLod(colortex5, texcoord + (bokeh_offsets[i] - dispersion)*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).b; - } - col = bcolor/BOKEH_SAMPLES; - #endif - #endif +vec2 tc64 = texcoord*vec2(64.0,32.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*64.0; +if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,16.0)/vec2(2.0,2.0),gaussDir,0.0005,60); - vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); - - vec2 resScale = vec2(1920.,1080.)/clampedRes; - vec2 bloomTileUV = (((gl_FragCoord.xy)*2.0 + 0.5)*texelSize/2.0) / clampedRes*vec2(1920.,1080.); - - vec3 bloomTile0 = texture_bicubic(colortex3, bloomTileUV/2.).rgb; //1/4 res - vec3 bloomTile1 = texture_bicubic(colortex6, bloomTileUV/4.).rgb; //1/8 res - vec3 bloomTile2 = texture_bicubic(colortex6, bloomTileUV/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res - vec3 bloomTile3 = texture_bicubic(colortex6, bloomTileUV/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res - vec3 bloomTile4 = texture_bicubic(colortex6, bloomTileUV/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb; //1/64 res - vec3 bloomTile5 = texture_bicubic(colortex6, bloomTileUV/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb; //1/128 res - vec3 bloomTile6 = texture_bicubic(colortex6, bloomTileUV/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb; //1/256 res - - #ifdef OLD_BLOOM - vec3 bloom = (bloomTile0 + bloomTile1 + bloomTile2 + bloomTile3 + bloomTile4 + bloomTile5 + bloomTile6) / 7.0; - vec3 fogBloom = bloom; - - float lightScat = clamp((BLOOM_STRENGTH+3.0) * 0.05 * pow(exposure.a, 0.2) ,0.0,1.0) * vignette; - #else - float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 ); - vec3 bloom = (bloomTile0*weights[0] + bloomTile1*weights[1] + bloomTile2*weights[2] + bloomTile3*weights[3] + bloomTile4*weights[4] + bloomTile5*weights[5] + bloomTile6*weights[6]) / bloomWeight(); - vec3 fogBloom = (bloomTile0 + bloomTile1 + bloomTile2 + bloomTile3 + bloomTile4 + bloomTile5 + bloomTile6) / 7.0; - - float lightScat = clamp(BLOOM_STRENGTH * 0.3,0.0,1.0) * vignette; - #endif - - float VL_abs = texture(colortex7, texcoord*RENDER_SCALE).r; - - float bloomyFog_Mult = BLOOMY_FOG; - if(isEyeInWater == 1) bloomyFog_Mult = UNDERWATER_BLOOMY_FOG; - - #if Purkinje_strength > 0 - float pstrength = float(Purkinje_strength) / 100.0; - - #ifdef AUTO_EXPOSURE - float purkinje = clamp(exposure.a*exposure.a,0.0,1.0) * clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*pstrength,0,1); - #else - float purkinje = clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*pstrength,0,1); - #endif - - VL_abs = clamp((1.0-VL_abs)*bloomyFog_Mult*0.75*(1.0+rainStrength) * (1.0-purkinje*0.3),0.0,1.0)*clamp(1.0-pow(cdist(texcoord),15.0),0.0,1.0); - col = (mix(col, fogBloom, VL_abs) + bloom*lightScat) * exposure.rgb; - - float lum = dot(col, vec3(0.15,0.3,0.55)); - float lum2 = dot(col, vec3(0.85,0.7,0.45)); - float rodLum = lum2*200.0; - float rodCurve = clamp(mix(1.0, rodLum/(2.5+rodLum), purkinje),0.0,1.0); - - col = mix(lum * vec3(Purkinje_R, Purkinje_G, Purkinje_B) * Purkinje_Multiplier, col, rodCurve); - #else - VL_abs = clamp((1.0-VL_abs)*bloomyFog_Mult*0.75*(1.0+rainStrength),0.0,1.0)*clamp(1.0-pow(cdist(texcoord),15.0),0.0,1.0); - col = (mix(col, fogBloom, VL_abs) + bloom*lightScat) * exposure.rgb; - #endif - - #if WHITE_BALANCE != 6500 - col *= blackbody(WHITE_BALANCE); - #endif - - #ifndef USE_ACES_COLORSPACE_APPROXIMATION - col = LinearTosRGB(TONEMAP(col)); - #else - col = col * ACESInputMat; - col = TONEMAP(col); - - col = LinearTosRGB(clamp(col * ACESOutputMat, 0.0, 1.0)); - #endif - - gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0); - - #if DOF_QUALITY == 5 - #if FOCUS_LASER_COLOR == 0 // Red - vec3 laserColor = vec3(25, 0, 0); - #elif FOCUS_LASER_COLOR == 1 // Green - vec3 laserColor = vec3(0, 25, 0); - #elif FOCUS_LASER_COLOR == 2 // Blue - vec3 laserColor = vec3(0, 0, 25); - #elif FOCUS_LASER_COLOR == 3 // Pink - vec3 laserColor = vec3(25, 10, 15); - #elif FOCUS_LASER_COLOR == 4 // Yellow - vec3 laserColor = vec3(25, 25, 0); - #elif FOCUS_LASER_COLOR == 5 // White - vec3 laserColor = vec3(25); - #endif - float depth = texture(depthtex0, texcoord).r; - - #if defined DISTANT_HORIZONS || defined VOXY - float _near = near; - float _far = far*4.0; - - if (depth >= 1.0) { - depth = texture(dhVoxyDepthTex, texcoord).x; - _near = dhVoxyNearPlane; - _far = dhVoxyFarPlane; - } - - depth = linearizeDepthFast(depth, _near, _far); - #else - depth = linearizeDepthFast(depth, near, far); - #endif - - // focus = gl_FragCoord.x * 0.1; - if( hideGUI < 1) gl_FragData[0].rgb += laserColor * pow( clamp( 1.0-abs(focus-abs(depth)) ,0,1),25) ; - #endif -} \ No newline at end of file +gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); +} diff --git a/shaders/dimensions/composite10.vsh b/shaders/dimensions/composite10.vsh index 892369c..0c48242 100644 --- a/shaders/dimensions/composite10.vsh +++ b/shaders/dimensions/composite10.vsh @@ -1,7 +1,5 @@ -#include "/lib/settings.glsl" - -out vec2 texcoord; - +uniform float viewWidth; +uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -10,6 +8,10 @@ out vec2 texcoord; //////////////////////////////VOID MAIN////////////////////////////// void main() { + vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0)); gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; -} \ No newline at end of file + //0-0.25 + gl_Position.y = (gl_Position.y*0.5+0.5)*0.25/clampedRes.y*1080.0*2.0-1.0; + //0-0.5 + gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0; +} diff --git a/shaders/dimensions/composite11.fsh b/shaders/dimensions/composite11.fsh index 0201586..5d2ab88 100644 --- a/shaders/dimensions/composite11.fsh +++ b/shaders/dimensions/composite11.fsh @@ -1,190 +1,367 @@ #include "/lib/settings.glsl" +#include "/lib/res_params.glsl" + +#include "/lib/SSBOs.glsl" + in vec2 texcoord; +const bool colortex5MipmapEnabled = true; +// uniform sampler2D colortex4; +uniform sampler2D colortex5; +uniform sampler2D colortex3; +// uniform sampler2D colortex6; +uniform sampler2D colortex7; +// uniform sampler2D colortex8; // specular +uniform sampler2D colortex9; // specular +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; +uniform sampler2D noisetex; uniform vec2 texelSize; -uniform sampler2D colortex7; -uniform sampler2D colortex14; -uniform sampler2D depthtex0; -uniform sampler2D noisetex; - -uniform float viewHeight; +uniform ivec2 eyeBrightnessSmooth; uniform float viewWidth; -uniform float aspectRatio; - +uniform float viewHeight; uniform float frameTimeCounter; uniform int frameCounter; - +uniform int isEyeInWater; +uniform float near; +uniform float aspectRatio; +uniform float far; +uniform float rainStrength; +uniform float screenBrightness; +uniform vec4 Moon_Weather_properties; // R = cloud coverage G = fog density uniform int hideGUI; +uniform int framemod8; +#include "/lib/TAA_jitter.glsl" + + +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferProjectionInverse; +vec4 Weather_properties = Moon_Weather_properties; + #include "/lib/color_transforms.glsl" #include "/lib/color_dither.glsl" -#include "/lib/res_params.glsl" +// #include "/lib/biome_specifics.glsl" +#include "/lib/bokeh.glsl" -/* -vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize ) -{ - // We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding - // down the sample location to get the exact center of our "starting" texel. The starting texel will be at - // location [1, 1] in the grid, where [0, 0] is the top left corner. - vec2 samplePos = uv * texSize; - vec2 texPos1 = floor(samplePos - 0.5) + 0.5; - - // Compute the fractional offset from our starting texel to our original sample location, which we'll - // feed into the Catmull-Rom spline function to get our filter weights. - vec2 f = samplePos - texPos1; - - // Compute the Catmull-Rom weights using the fractional offset that we calculated earlier. - // These equations are pre-expanded based on our knowledge of where the texels will be located, - // which lets us avoid having to evaluate a piece-wise function. - vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f)); - vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f); - vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) ); - vec2 w3 = f * f * (-0.5 + 0.5 * f); - - // Work out weighting factors and sampling offsets that will let us use bilinear filtering to - // simultaneously evaluate the middle 2 samples from the 4x4 grid. - vec2 w12 = w1 + w2; - vec2 offset12 = w2 / (w1 + w2); - - // Compute the final UV coordinates we'll use for sampling the texture - vec2 texPos0 = texPos1 - vec2(1.0); - vec2 texPos3 = texPos1 + vec2(2.0); - vec2 texPos12 = texPos1 + offset12; - - texPos0 *= texelSize; - texPos3 *= texelSize; - texPos12 *= texelSize; - - vec4 result = vec4(0.0); - result += texture(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; - result += texture(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; - result += texture(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; - - result += texture(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; - result += texture(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; - result += texture(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; - - result += texture(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; - result += texture(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; - result += texture(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; - - return result; -} -*/ - -float lowerCurve(float x) { - float y = 16 * x * (0.5 - x) * 0.1; - return clamp(y, 0.0, 1.0); -} - -float upperCurve(float x) { - float y = 16 * (0.5 - x) * (x - 1.0) * 0.1; - return clamp(y, 0.0, 1.0); -} - -vec3 luminanceCurve(vec3 color){ - color.r += LOWER_CURVE * lowerCurve(color.r) + UPPER_CURVE * upperCurve(color.r); - color.g += LOWER_CURVE * lowerCurve(color.g) + UPPER_CURVE * upperCurve(color.g); - color.b += LOWER_CURVE * lowerCurve(color.b) + UPPER_CURVE * upperCurve(color.b); - return color; -} - -vec3 colorGrading(vec3 color) { - float grade_luma = dot(color, vec3(1.0 / 3.0)); - float shadows_amount = saturate(-6.0 * grade_luma + 2.75); - float mids_amount = saturate(-abs(6.0 * grade_luma - 3.0) + 1.25); - float highlights_amount = saturate(6.0 * grade_luma - 3.25); - - vec3 graded_shadows = color * SHADOWS_TARGET * SHADOWS_GRADE_MUL * 1.7320508076; - vec3 graded_mids = color * MIDS_TARGET * MIDS_GRADE_MUL * 1.7320508076; - vec3 graded_highlights = color * HIGHLIGHTS_TARGET * HIGHLIGHTS_GRADE_MUL * 1.7320508076; - - return saturate(graded_shadows * shadows_amount + graded_mids * mids_amount + graded_highlights * highlights_amount); -} - -vec3 contrastAdaptiveSharpening(vec3 color, vec2 texcoord){ - float sharpen_strength = float(SHARPENING)/100.0; - //Weights : 1 in the center, 0.5 middle, 0.25 corners - vec3 albedoCurrent1 = texture(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent2 = texture(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent3 = texture(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent4 = texture(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - - vec3 m1 = -0.5/3.5*color + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5; - - vec3 std = abs(color - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) + - abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1); - - float contrast = 1.0 - luma(std)/5.0; - - color = color*(1.0+(sharpen_strength+UPSCALING_SHARPNENING)*contrast) - - (sharpen_strength+UPSCALING_SHARPNENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*color); - - return color; -} - -vec3 saturationAndCrosstalk(vec3 color){ - - float luminance = luma(color); - - vec3 lumaColDiff = color - luminance; - - color = color + lumaColDiff*(-luminance*CROSSTALK + SATURATION); - - return color; -} - -float interleaved_gradientNoise(){ - vec2 coord = gl_FragCoord.xy; - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); - return noise; +float cdist(vec2 coord) { + return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0; } float blueNoise(){ return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); } +float ld(float depth) { + return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near +} -vec3 chromaticAberration(vec2 UV){ - float noise = blueNoise() - 0.5; +// uniform float viewWidth; +// uniform float viewHeight; - vec2 centeredUV = (texcoord - 0.5); - // not stretched by aspect ratio; circular by choice :) it makes most the abberation on the left/right of the screen. - float vignette = 1.0 - clamp(1.0 - length(centeredUV * vec2(aspectRatio,1.0)) / 200.0,0.0,1.0); +// uniform sampler2D depthtex0; - float aberrationStrength = CHROMATIC_ABERRATION_STRENGTH * vignette; +#ifdef DISTANT_HORIZONS + uniform sampler2D dhDepthTex; + #define dhVoxyDepthTex dhDepthTex +#endif - vec3 color = vec3(0.0); - color.r = texture(colortex7, (centeredUV - (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).r; - color.g = texture(colortex7, texcoord).g; - color.b = texture(colortex7, (centeredUV + (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).b; +#ifdef VOXY + uniform sampler2D vxDepthTexTrans; + #define dhVoxyDepthTex vxDepthTexTrans +#endif +uniform float dhVoxyNearPlane; +uniform float dhVoxyFarPlane; - return color; +float linearizeDepthFast(const in float depth, const in float near, const in float far) { + return (near * far) / (depth * (near - far) + far); +} + +float bloomWeight(){ + + float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 ); + // float weights[7] = float[]( 0.7, pow(0.5,2), pow(0.5,3), pow(0.5,4), pow(0.5,5), pow(0.5,6), pow(0.5,7) ); + + float result = 0.0; + + for ( int i = 0; i < 7; i++) { + result += weights[i]; + } + + return result; +} +vec3 invTonemap(vec3 col){ + return col/(1-luma(col)); +} +#define linear_to_srgb(x) (pow(x, vec3(1.0/2.2))) + +uniform sampler2D colortex6; + + +float w0(float a) +{ + return (1.0/6.0)*(a*(a*(-a + 3.0) - 3.0) + 1.0); +} + +float w1(float a) +{ + return (1.0/6.0)*(a*a*(3.0*a - 6.0) + 4.0); +} + +float w2(float a) +{ + return (1.0/6.0)*(a*(a*(-3.0*a + 3.0) + 3.0) + 1.0); +} + +float w3(float a) +{ + return (1.0/6.0)*(a*a*a); +} + +float g0(float a) +{ + return w0(a) + w1(a); +} + +float g1(float a) +{ + return w2(a) + w3(a); +} + +float h0(float a) +{ + return -1.0 + w1(a) / (w0(a) + w1(a)); +} + +float h1(float a) +{ + return 1.0 + w3(a) / (w2(a) + w3(a)); +} + +vec4 texture_bicubic(sampler2D tex, vec2 uv) +{ + vec4 texelSize = vec4(texelSize,1.0/texelSize); + uv = uv*texelSize.zw; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + + float g0x = g0(fuv.x); + float g1x = g1(fuv.x); + float h0x = h0(fuv.x); + float h1x = h1(fuv.x); + float h0y = h0(fuv.y); + float h1y = h1(fuv.y); + + vec2 p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texelSize.xy; + vec2 p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texelSize.xy; + vec2 p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texelSize.xy; + vec2 p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texelSize.xy; + + return g0(fuv.y) * (g0x * texture(tex, p0) + + g1x * texture(tex, p1)) + + g1(fuv.y) * (g0x * texture(tex, p2) + + g1x * texture(tex, p3)); +} + +// vec3 lenseFlare(vec2 UV){ +// float noise = blueNoise(); + +// float vignetteLength = 0.2; +// float vignette = 0.5+length(texcoord-0.5);//min(max(length(texcoord-0.5) - vignetteLength,0.0) / (1.0/(1.0-vignetteLength)),1.0); + +// float aberrationStrength = vignette;//clamp(CHROMATIC_ABERRATION_STRENGTH * 0.01 * (1.0 - vignette),0.0,0.9) * vignette * 0.75; + +// vec2 centeredUV = texcoord - 0.5; + +// vec3 color = vec3(0.0); +// color = texture(colortex7, texcoord).rgb; + +// vec2 distortedUV = (centeredUV - (centeredUV ) * aberrationStrength) + 0.5; + +// color += texture(colortex7, distortedUV).rgb; +// // color.r = texture(colortex7, (centeredUV - (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).r; +// // color.g = texture(colortex7, texcoord).g; +// // color.b = texture(colortex7, (centeredUV + (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).b; + +// return color; +// } + +vec3 srgbToLinear(vec3 srgb){ + return mix( + srgb / 12.92, + pow(.947867 * srgb + .0521327, vec3(2.4) ), + step( .04045, srgb ) + ); +} +vec3 blackbody(float Temp) +{ + float t = pow(Temp, -1.5); + float lt = log(Temp); + + vec3 WB_temp = vec3(0.0); + WB_temp.r = 220000.0 * t + 0.58039215686; + WB_temp.g = 0.39231372549 * lt - 2.44549019608; + WB_temp.g = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : WB_temp.g; + WB_temp.b = 0.76078431372 * lt - 5.68078431373; + WB_temp = clamp(WB_temp,0,1); + WB_temp = Temp < 1000. ? WB_temp * Temp * 0.001 : WB_temp; + + return srgbToLinear(WB_temp); } void main() { - /* RENDERTARGETS:7 */ - - #ifdef CHROMATIC_ABERRATION - vec3 color = chromaticAberration(texcoord); - #else - vec3 color = texture(colortex7,texcoord).rgb; - #endif + float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.); + vec3 col = texture(colortex5,texcoord).rgb; - #if SHARPENING > 0 - color = contrastAdaptiveSharpening(color, texcoord); + vec2 rodExposureDepth = rodExposureDepthSSBO; + rodExposureDepth.y = sqrt(rodExposureDepth.y/65000.0); + + vec4 exposure = vec4(exposureSSBO); + + + #if DOF_QUALITY >= 0 + /*--------------------------------*/ + float z = ld(texture(depthtex1, texcoord*RENDER_SCALE).r)*far; + #if MANUAL_FOCUS == -2 + float focus = rodExposureDepth.y*far; + #elif MANUAL_FOCUS == -1 + float focus = mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25); + #elif MANUAL_FOCUS > 0 + float focus = MANUAL_FOCUS; + #endif + #if DOF_QUALITY < 5 + float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0); + #ifdef FAR_BLUR_ONLY + pcoc *= float(z > focus); + #endif + #ifdef REMOVE_HAND_BLUR + pcoc *= float(z > 0.56); + #endif + // float noise = blueNoise()*6.28318530718; + // mat2 noiseM = mat2( cos( noise ), -sin( noise ), + // sin( noise ), cos( noise ) + // ); + vec3 bcolor = vec3(0.); + float nb = 0.0; + vec2 bcoord = vec2(0.0); + /*--------------------------------*/ + float dofLodLevel = pcoc * 200.0; + + vec2 dispersion = (texcoord - 0.5) * pcoc * 200.0 * DOF_DISPERSION_MULT; + + for ( int i = 0; i < BOKEH_SAMPLES; i++) { + // bcolor += textureLod(colortex5, texcoord.xy + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).rgb; + + bcolor.r += textureLod(colortex5, texcoord + (bokeh_offsets[i] + dispersion)*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).r; + bcolor.g += textureLod(colortex5, texcoord + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).g; + bcolor.b += textureLod(colortex5, texcoord + (bokeh_offsets[i] - dispersion)*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).b; + } + col = bcolor/BOKEH_SAMPLES; + #endif #endif - - color = saturationAndCrosstalk(color); - - #ifdef LUMINANCE_CURVE - color = luminanceCurve(color); - #endif - #ifdef COLOR_GRADING_ENABLED - color = colorGrading(color); - #endif - - gl_FragData[0] = vec4(clamp(int8Dither(color, texcoord),0.0,1.0), 0.0); -} + vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); + + vec2 resScale = vec2(1920.,1080.)/clampedRes; + vec2 bloomTileUV = (((gl_FragCoord.xy)*2.0 + 0.5)*texelSize/2.0) / clampedRes*vec2(1920.,1080.); + + vec3 bloomTile0 = texture_bicubic(colortex3, bloomTileUV/2.).rgb; //1/4 res + vec3 bloomTile1 = texture_bicubic(colortex6, bloomTileUV/4.).rgb; //1/8 res + vec3 bloomTile2 = texture_bicubic(colortex6, bloomTileUV/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res + vec3 bloomTile3 = texture_bicubic(colortex6, bloomTileUV/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res + vec3 bloomTile4 = texture_bicubic(colortex6, bloomTileUV/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb; //1/64 res + vec3 bloomTile5 = texture_bicubic(colortex6, bloomTileUV/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb; //1/128 res + vec3 bloomTile6 = texture_bicubic(colortex6, bloomTileUV/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb; //1/256 res + + #ifdef OLD_BLOOM + vec3 bloom = (bloomTile0 + bloomTile1 + bloomTile2 + bloomTile3 + bloomTile4 + bloomTile5 + bloomTile6) / 7.0; + vec3 fogBloom = bloom; + + float lightScat = clamp((BLOOM_STRENGTH+3.0) * 0.05 * pow(exposure.a, 0.2) ,0.0,1.0) * vignette; + #else + float weights[7] = float[]( 1.0, 1.0/2.0, 1.0/3.0, 1.0/5.5, 1.0/8.0, 1.0/10.0, 1.0/12.0 ); + vec3 bloom = (bloomTile0*weights[0] + bloomTile1*weights[1] + bloomTile2*weights[2] + bloomTile3*weights[3] + bloomTile4*weights[4] + bloomTile5*weights[5] + bloomTile6*weights[6]) / bloomWeight(); + vec3 fogBloom = (bloomTile0 + bloomTile1 + bloomTile2 + bloomTile3 + bloomTile4 + bloomTile5 + bloomTile6) / 7.0; + + float lightScat = clamp(BLOOM_STRENGTH * 0.3,0.0,1.0) * vignette; + #endif + + float VL_abs = texture(colortex7, texcoord*RENDER_SCALE).r; + + float bloomyFog_Mult = BLOOMY_FOG; + if(isEyeInWater == 1) bloomyFog_Mult = UNDERWATER_BLOOMY_FOG; + + #if Purkinje_strength > 0 + float pstrength = float(Purkinje_strength) / 100.0; + + #ifdef AUTO_EXPOSURE + float purkinje = clamp(exposure.a*exposure.a,0.0,1.0) * clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*pstrength,0,1); + #else + float purkinje = clamp(rodExposureDepth.x/(1.0+rodExposureDepth.x)*pstrength,0,1); + #endif + + VL_abs = clamp((1.0-VL_abs)*bloomyFog_Mult*0.75*(1.0+rainStrength) * (1.0-purkinje*0.3),0.0,1.0)*clamp(1.0-pow(cdist(texcoord),15.0),0.0,1.0); + col = (mix(col, fogBloom, VL_abs) + bloom*lightScat) * exposure.rgb; + + float lum = dot(col, vec3(0.15,0.3,0.55)); + float lum2 = dot(col, vec3(0.85,0.7,0.45)); + float rodLum = lum2*200.0; + float rodCurve = clamp(mix(1.0, rodLum/(2.5+rodLum), purkinje),0.0,1.0); + + col = mix(lum * vec3(Purkinje_R, Purkinje_G, Purkinje_B) * Purkinje_Multiplier, col, rodCurve); + #else + VL_abs = clamp((1.0-VL_abs)*bloomyFog_Mult*0.75*(1.0+rainStrength),0.0,1.0)*clamp(1.0-pow(cdist(texcoord),15.0),0.0,1.0); + col = (mix(col, fogBloom, VL_abs) + bloom*lightScat) * exposure.rgb; + #endif + + #if WHITE_BALANCE != 6500 + col *= blackbody(WHITE_BALANCE); + #endif + + #ifndef USE_ACES_COLORSPACE_APPROXIMATION + col = LinearTosRGB(TONEMAP(col)); + #else + col = col * ACESInputMat; + col = TONEMAP(col); + + col = LinearTosRGB(clamp(col * ACESOutputMat, 0.0, 1.0)); + #endif + + gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0); + + #if DOF_QUALITY == 5 + #if FOCUS_LASER_COLOR == 0 // Red + vec3 laserColor = vec3(25, 0, 0); + #elif FOCUS_LASER_COLOR == 1 // Green + vec3 laserColor = vec3(0, 25, 0); + #elif FOCUS_LASER_COLOR == 2 // Blue + vec3 laserColor = vec3(0, 0, 25); + #elif FOCUS_LASER_COLOR == 3 // Pink + vec3 laserColor = vec3(25, 10, 15); + #elif FOCUS_LASER_COLOR == 4 // Yellow + vec3 laserColor = vec3(25, 25, 0); + #elif FOCUS_LASER_COLOR == 5 // White + vec3 laserColor = vec3(25); + #endif + float depth = texture(depthtex0, texcoord).r; + + #if defined DISTANT_HORIZONS || defined VOXY + float _near = near; + float _far = far*4.0; + + if (depth >= 1.0) { + depth = texture(dhVoxyDepthTex, texcoord).x; + _near = dhVoxyNearPlane; + _far = dhVoxyFarPlane; + } + + depth = linearizeDepthFast(depth, _near, _far); + #else + depth = linearizeDepthFast(depth, near, far); + #endif + + // focus = gl_FragCoord.x * 0.1; + if( hideGUI < 1) gl_FragData[0].rgb += laserColor * pow( clamp( 1.0-abs(focus-abs(depth)) ,0,1),25) ; + #endif +} \ No newline at end of file diff --git a/shaders/dimensions/composite11.vsh b/shaders/dimensions/composite11.vsh index 8f1b8a8..892369c 100644 --- a/shaders/dimensions/composite11.vsh +++ b/shaders/dimensions/composite11.vsh @@ -2,6 +2,7 @@ out vec2 texcoord; + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -11,4 +12,4 @@ out vec2 texcoord; void main() { gl_Position = ftransform(); texcoord = gl_MultiTexCoord0.xy; -} +} \ No newline at end of file diff --git a/shaders/dimensions/composite12.fsh b/shaders/dimensions/composite12.fsh new file mode 100644 index 0000000..0201586 --- /dev/null +++ b/shaders/dimensions/composite12.fsh @@ -0,0 +1,190 @@ +#include "/lib/settings.glsl" + +in vec2 texcoord; + +uniform vec2 texelSize; + +uniform sampler2D colortex7; +uniform sampler2D colortex14; +uniform sampler2D depthtex0; +uniform sampler2D noisetex; + +uniform float viewHeight; +uniform float viewWidth; +uniform float aspectRatio; + +uniform float frameTimeCounter; +uniform int frameCounter; + +uniform int hideGUI; + +#include "/lib/color_transforms.glsl" +#include "/lib/color_dither.glsl" +#include "/lib/res_params.glsl" + +/* +vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize ) +{ + // We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding + // down the sample location to get the exact center of our "starting" texel. The starting texel will be at + // location [1, 1] in the grid, where [0, 0] is the top left corner. + vec2 samplePos = uv * texSize; + vec2 texPos1 = floor(samplePos - 0.5) + 0.5; + + // Compute the fractional offset from our starting texel to our original sample location, which we'll + // feed into the Catmull-Rom spline function to get our filter weights. + vec2 f = samplePos - texPos1; + + // Compute the Catmull-Rom weights using the fractional offset that we calculated earlier. + // These equations are pre-expanded based on our knowledge of where the texels will be located, + // which lets us avoid having to evaluate a piece-wise function. + vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f)); + vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f); + vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) ); + vec2 w3 = f * f * (-0.5 + 0.5 * f); + + // Work out weighting factors and sampling offsets that will let us use bilinear filtering to + // simultaneously evaluate the middle 2 samples from the 4x4 grid. + vec2 w12 = w1 + w2; + vec2 offset12 = w2 / (w1 + w2); + + // Compute the final UV coordinates we'll use for sampling the texture + vec2 texPos0 = texPos1 - vec2(1.0); + vec2 texPos3 = texPos1 + vec2(2.0); + vec2 texPos12 = texPos1 + offset12; + + texPos0 *= texelSize; + texPos3 *= texelSize; + texPos12 *= texelSize; + + vec4 result = vec4(0.0); + result += texture(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; + result += texture(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; + result += texture(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; + + result += texture(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; + result += texture(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; + result += texture(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; + + result += texture(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; + result += texture(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; + result += texture(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; + + return result; +} +*/ + +float lowerCurve(float x) { + float y = 16 * x * (0.5 - x) * 0.1; + return clamp(y, 0.0, 1.0); +} + +float upperCurve(float x) { + float y = 16 * (0.5 - x) * (x - 1.0) * 0.1; + return clamp(y, 0.0, 1.0); +} + +vec3 luminanceCurve(vec3 color){ + color.r += LOWER_CURVE * lowerCurve(color.r) + UPPER_CURVE * upperCurve(color.r); + color.g += LOWER_CURVE * lowerCurve(color.g) + UPPER_CURVE * upperCurve(color.g); + color.b += LOWER_CURVE * lowerCurve(color.b) + UPPER_CURVE * upperCurve(color.b); + return color; +} + +vec3 colorGrading(vec3 color) { + float grade_luma = dot(color, vec3(1.0 / 3.0)); + float shadows_amount = saturate(-6.0 * grade_luma + 2.75); + float mids_amount = saturate(-abs(6.0 * grade_luma - 3.0) + 1.25); + float highlights_amount = saturate(6.0 * grade_luma - 3.25); + + vec3 graded_shadows = color * SHADOWS_TARGET * SHADOWS_GRADE_MUL * 1.7320508076; + vec3 graded_mids = color * MIDS_TARGET * MIDS_GRADE_MUL * 1.7320508076; + vec3 graded_highlights = color * HIGHLIGHTS_TARGET * HIGHLIGHTS_GRADE_MUL * 1.7320508076; + + return saturate(graded_shadows * shadows_amount + graded_mids * mids_amount + graded_highlights * highlights_amount); +} + +vec3 contrastAdaptiveSharpening(vec3 color, vec2 texcoord){ + float sharpen_strength = float(SHARPENING)/100.0; + //Weights : 1 in the center, 0.5 middle, 0.25 corners + vec3 albedoCurrent1 = texture(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + vec3 albedoCurrent2 = texture(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + vec3 albedoCurrent3 = texture(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + vec3 albedoCurrent4 = texture(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + + vec3 m1 = -0.5/3.5*color + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5; + + vec3 std = abs(color - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) + + abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1); + + float contrast = 1.0 - luma(std)/5.0; + + color = color*(1.0+(sharpen_strength+UPSCALING_SHARPNENING)*contrast) - + (sharpen_strength+UPSCALING_SHARPNENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*color); + + return color; +} + +vec3 saturationAndCrosstalk(vec3 color){ + + float luminance = luma(color); + + vec3 lumaColDiff = color - luminance; + + color = color + lumaColDiff*(-luminance*CROSSTALK + SATURATION); + + return color; +} + +float interleaved_gradientNoise(){ + vec2 coord = gl_FragCoord.xy; + float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); + return noise; +} +float blueNoise(){ + return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); +} + +vec3 chromaticAberration(vec2 UV){ + float noise = blueNoise() - 0.5; + + vec2 centeredUV = (texcoord - 0.5); + // not stretched by aspect ratio; circular by choice :) it makes most the abberation on the left/right of the screen. + float vignette = 1.0 - clamp(1.0 - length(centeredUV * vec2(aspectRatio,1.0)) / 200.0,0.0,1.0); + + float aberrationStrength = CHROMATIC_ABERRATION_STRENGTH * vignette; + + vec3 color = vec3(0.0); + color.r = texture(colortex7, (centeredUV - (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).r; + color.g = texture(colortex7, texcoord).g; + color.b = texture(colortex7, (centeredUV + (centeredUV + centeredUV*noise) * aberrationStrength) + 0.5).b; + + return color; +} + +void main() { + + /* RENDERTARGETS:7 */ + + #ifdef CHROMATIC_ABERRATION + vec3 color = chromaticAberration(texcoord); + #else + vec3 color = texture(colortex7,texcoord).rgb; + #endif + + #if SHARPENING > 0 + color = contrastAdaptiveSharpening(color, texcoord); + #endif + + color = saturationAndCrosstalk(color); + + #ifdef LUMINANCE_CURVE + color = luminanceCurve(color); + #endif + + #ifdef COLOR_GRADING_ENABLED + color = colorGrading(color); + #endif + + gl_FragData[0] = vec4(clamp(int8Dither(color, texcoord),0.0,1.0), 0.0); +} diff --git a/shaders/dimensions/composite12.vsh b/shaders/dimensions/composite12.vsh new file mode 100644 index 0000000..8f1b8a8 --- /dev/null +++ b/shaders/dimensions/composite12.vsh @@ -0,0 +1,14 @@ +#include "/lib/settings.glsl" + +out vec2 texcoord; + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { + gl_Position = ftransform(); + texcoord = gl_MultiTexCoord0.xy; +} diff --git a/shaders/dimensions/composite2.fsh b/shaders/dimensions/composite2.fsh index 1a69d84..7df8ef6 100644 --- a/shaders/dimensions/composite2.fsh +++ b/shaders/dimensions/composite2.fsh @@ -2,10 +2,15 @@ #include "/lib/SSBOs.glsl" -#define EXCLUDE_WRITE_TO_LUT - -uniform float skyLightLevelSmooth; +#ifdef OVERWORLD_SHADER + in DATA { + flat vec3 WsunVec; + flat vec3 WmoonVec; + }; +#endif +#define DEFERRED_SPECULAR +#define DEFERRED_SSR_QUALITY 30 // [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 200 300 400 500] uniform sampler2D noisetex; uniform sampler2D depthtex0; @@ -26,661 +31,200 @@ uniform sampler2D depthtex1; #endif uniform sampler2D colortex0; +uniform sampler2D colortex1; uniform sampler2D colortex2; uniform sampler2D colortex3; -// uniform sampler2D colortex4; +uniform sampler2D colortex4; +uniform sampler2D colortex5; uniform sampler2D colortex6; uniform sampler2D colortex7; +uniform sampler2D colortex8; +uniform sampler2D colortex9; uniform sampler2D colortex10; +uniform sampler2D colortex11; +uniform sampler2D colortex12; +uniform sampler2D colortex13; uniform sampler2D colortex14; - -#if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 -layout (rgba16f) uniform image2D cloudDepthTex; -#endif - -in DATA { - flat vec3 WsunVec; - flat vec3 WrealSunVec; - flat vec3 WmoonVec; -}; - -uniform vec3 sunVec; -uniform float sunElevation; - -// uniform float far; -uniform float near; -uniform float dhVoxyFarPlane; -uniform float dhVoxyNearPlane; - -uniform mat4 gbufferPreviousModelView; -uniform vec3 previousCameraPosition; -uniform vec3 relativeEyePosition; - -#if defined VIVECRAFT - uniform bool vivecraftIsVR; - uniform vec3 vivecraftRelativeMainHandPos; - uniform vec3 vivecraftRelativeOffHandPos; - uniform mat4 vivecraftRelativeMainHandRot; - uniform mat4 vivecraftRelativeOffHandRot; -#endif - -uniform int frameCounter; -uniform float frameTimeCounter; - +uniform sampler2D colortex15; uniform vec2 texelSize; -uniform int isEyeInWater; -uniform float rainStrength; -uniform ivec2 eyeBrightnessSmooth; -uniform float eyeAltitude; -uniform float caveDetection; - -// uniform int dhVoxyRenderDistance; -#define DHVLFOG -#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) -#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) - -#include "/lib/color_transforms.glsl" -#include "/lib/color_dither.glsl" -#include "/lib/projections.glsl" -#include "/lib/res_params.glsl" -#include "/lib/sky_gradient.glsl" -#include "/lib/Shadow_Params.glsl" -#include "/lib/waterBump.glsl" - -#include "/lib/DistantHorizons_projections.glsl" - -float DH_ld(float dist) { - return (2.0 * dhVoxyNearPlane) / (dhVoxyFarPlane + dhVoxyNearPlane - dist * (dhVoxyFarPlane - dhVoxyNearPlane)); -} -float DH_inv_ld (float lindepth){ - return -((2.0*dhVoxyNearPlane/lindepth)-dhVoxyFarPlane-dhVoxyNearPlane)/(dhVoxyFarPlane-dhVoxyNearPlane); -} - -float linearizeDepthFast(const in float depth, const in float near, const in float far) { - return (near * far) / (depth * (near - far) + far); -} - -uniform float nightVision; - -#ifdef OVERWORLD_SHADER - uniform float auroraAmount; - const bool shadowHardwareFiltering = true; - uniform sampler2DShadow shadow; - - #ifdef TRANSLUCENT_COLORED_SHADOWS - uniform sampler2D shadowcolor0; - uniform sampler2DShadow shadowtex0; - uniform sampler2DShadow shadowtex1; - #endif - - - #include "/lib/scene_controller.glsl" - - #define TIMEOFDAYFOG - #include "/lib/lightning_stuff.glsl" - - #include "/lib/volumetricClouds.glsl" - - #include "/lib/climate_settings.glsl" - #include "/lib/overworld_fog.glsl" -#endif -#ifdef NETHER_SHADER -uniform sampler2D colortex4; - #include "/lib/nether_fog.glsl" -#endif -#ifdef END_SHADER -uniform sampler2D colortex4; - #include "/lib/end_fog.glsl" -#endif - -#define IS_LPV_ENABLED - -#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED - #extension GL_ARB_shader_image_load_store: enable - #extension GL_ARB_shading_language_packing: enable - - uniform usampler1D texBlockData; - uniform sampler3D texLpv1; - uniform sampler3D texLpv2; - - #include "/lib/hsv.glsl" - #include "/lib/lpv_blocks.glsl" - #include "/lib/lpv_common.glsl" - #include "/lib/lpv_render.glsl" - - #if defined LPV_VL_FOG_ILLUMINATION_HANDHELD_WATER || defined LPV_VL_FOG_ILLUMINATION_HANDHELD - uniform int heldItemId; - uniform int heldItemId2; - - #include "/lib/util.glsl" - #include "/lib/diffuse_lighting.glsl" - #endif - #ifdef LPV_VL_FOG_ILLUMINATION_HANDHELD - #endif -#endif - -bool eyeInWater = isEyeInWater == 1; - -vec4 raymarchLPV( - in vec3 viewPos, - in float dither -){ - #if (!defined LPV_VL_FOG_ILLUMINATION || !defined IS_LPV_ENABLED) && (!defined FLASHLIGHT_FOG_ILLUMINATION || !defined FLASHLIGHT) - return vec4(0.0); - #endif - - const int SAMPLECOUNT = 8; - float minimumDensity = 0.000025; - if(eyeInWater) minimumDensity = 0.00006; - const float fadeLength = 10.0; // in blocks - - vec3 LPVrayStartPos = mat3(gbufferModelViewInverse) * viewPos; - - // ensure the max marching distance is the voxel distance, or the render distance if the voxels go farther than it - float LPVRayLength = length(LPVrayStartPos); - #if LPV_SIZE == 8 - LPVrayStartPos *= min(LPVRayLength, min(256.0,far))/LPVRayLength; - #elif LPV_SIZE == 7 - LPVrayStartPos *= min(LPVRayLength, min(128.0,far))/LPVRayLength; - #elif LPV_SIZE == 6 - LPVrayStartPos *= min(LPVRayLength, min(64.0,far))/LPVRayLength; - #endif - LPVRayLength = length(LPVrayStartPos); - - vec3 rayProgress = vec3(0.0); - vec4 color = vec4(0.0,0.0,0.0,1.0); - const float expFactor = 11.0; - - for (int i = 0; i < SAMPLECOUNT; i++) { - float d = (pow(expFactor, float(i+dither)/float(SAMPLECOUNT))/expFactor - 1.0/expFactor)/(1.0-1.0/expFactor); - float dd = pow(expFactor, float(i+dither)/float(SAMPLECOUNT)) * log(expFactor) / float(SAMPLECOUNT)/(expFactor-1.0); - - rayProgress = gbufferModelViewInverse[3].xyz + d*LPVrayStartPos; - - float density; - float _minimumDensity = minimumDensity; - - #ifdef OVERWORLD_SHADER - if(caveDetection < 0.9999) density = cloudVol(rayProgress + cameraPosition, 0.0) * (1.0 - caveDetection); - - _minimumDensity += caveDetection * minimumDensity; - #elif defined NETHER_SHADER - vec3 progressW = rayProgress + cameraPosition; - density = cloudVol(progressW); - - float dist = length(rayProgress); - float clearArea = 1.0 - min(max(1.0 - dist / 24.0,0.0),1.0); - - float plumeDensity = min(density * pow(min(max(100.0-progressW.y,0.0)/30.0,1.0),4.0), pow(clamp(1.0 - dist/far,0.0,1.0),5.0)); - plumeDensity *= NETHER_PLUME_DENSITY; - - float ceilingSmokeDensity = 0.001 * pow(min(max(progressW.y-40.0,0.0)/50.0,1.0),3.0); - ceilingSmokeDensity *= NETHER_CEILING_SMOKE_DENSITY; - - density = plumeDensity + ceilingSmokeDensity; - #elif defined END_SHADER - float volumeDensity = fogShape(rayProgress + cameraPosition); - float clearArea = 1.0-min(max(1.0 - length(rayProgress) / 100,0.0),1.0); - density = min(volumeDensity, clearArea*clearArea * END_STORM_DENSTIY); - #endif - - density = max(density/1000.0, _minimumDensity); - - // density = 0.0001; - - float volumeCoeff = exp(-dd*density*LPVRayLength); - - #if defined IS_LPV_ENABLED && defined LPV_VL_FOG_ILLUMINATION - vec3 lpvPos = GetLpvPosition(rayProgress); - - vec3 cubicRadius = clamp(min(((LpvSize3-1.0) - lpvPos)/fadeLength, lpvPos/fadeLength), 0.0, 1.0); - float LpvFadeF = cubicRadius.x*cubicRadius.y*cubicRadius.z; - - if(LpvFadeF < 0.01) break; - - vec3 sampleColor = SampleLpvLinear(lpvPos).rgb; - #ifdef VANILLA_LIGHTMAP_MASK - vec3 lighting = sampleColor * LPV_VL_FOG_ILLUMINATION_BRIGHTNESS * 25. * exp(-10 * (1.0-luma(sampleColor))); - #else - vec3 lighting = sampleColor * LPV_VL_FOG_ILLUMINATION_BRIGHTNESS * 25. * exp(-5 * (1.0-luma(sampleColor))); - #endif - - if(eyeInWater) lighting *= 2.5; - - #ifdef LPV_VL_FOG_ILLUMINATION_HANDHELD - float lightRange = 0.0; - vec3 handLightCol = GetHandLight(heldItemId, rayProgress, lightRange); - - vec3 handLightCol2 = GetHandLight(heldItemId2, rayProgress, lightRange); - - lighting += (handLightCol + handLightCol2) * TORCH_AMOUNT * LPV_VL_FOG_ILLUMINATION_BRIGHTNESS * 0.04; - #endif - - color.rgb += (lighting - lighting * volumeCoeff) * color.a; - #endif - - #if defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION - // vec3 shiftedViewPos = mat3(gbufferModelView)*(progressW-cameraPosition) + vec3(-0.25, 0.2, 0.0); - // vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos; - vec3 shiftedViewPos; - vec3 shiftedPlayerPos; - float forwardOffset; - - #ifdef VIVECRAFT - if (vivecraftIsVR) { - forwardOffset = 0.0; - shiftedPlayerPos = (rayProgress) + ( vivecraftRelativeMainHandPos); - shiftedViewPos = shiftedPlayerPos * mat3(vivecraftRelativeMainHandRot); - } else - #endif - { - forwardOffset = 0.5; - shiftedViewPos = mat3(gbufferModelView)*(rayProgress) + vec3(-0.25, 0.2, 0.0); - shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos; - } - - vec2 scaledViewPos = shiftedViewPos.xy / max(-shiftedViewPos.z - forwardOffset, 1e-7); - float linearDistance = length(shiftedPlayerPos); - float shiftedLinearDistance = length(scaledViewPos); - - float lightFalloff = 1.0 - clamp(1.0-linearDistance/FLASHLIGHT_RANGE, -0.999,1.0); - lightFalloff = max(exp(-10.0 * FLASHLIGHT_BRIGHTNESS_FALLOFF_MULT * lightFalloff),0.0); - float projectedCircle = clamp(1.0 - shiftedLinearDistance*FLASHLIGHT_SIZE,0.0,1.0); - - vec3 flashlightGlow = 25.0 * vec3(FLASHLIGHT_R,FLASHLIGHT_G,FLASHLIGHT_B) * lightFalloff * projectedCircle * FLASHLIGHT_BRIGHTNESS_MULT; - - color.rgb += (flashlightGlow - flashlightGlow * volumeCoeff) * color.a; - #endif - - color.a *= volumeCoeff; - } - return color; -} - -float invLinZ (float lindepth){ - return -((2.0*near/lindepth)-far-near)/(far-near); -} - -/* -from https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence/ -Copyright 2019 Alan Wolfe - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -float interleaved_gradientNoise_temporal(){ - vec2 coord = gl_FragCoord.xy + 5.588238 * float(frameCounter%64); - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)) ; - return noise; -} -float interleaved_gradientNoise(){ - vec2 coord = gl_FragCoord.xy; - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); - return noise; -} - -float blueNoise(){ - return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter ); -} - -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 ) ; -} - -uniform float waterEnteredAltitude; -float lightSourceCheck = float(sunElevation > 1e-5)*2.0 - 1.0; - -vec4 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL, vec3 LPV){ - const int spCount = 8; - - vec3 start = toShadowSpaceProjected(rayStart); - vec3 end = toShadowSpaceProjected(rayEnd); - vec3 dV = (end-start); - - //limit ray length at 32 blocks for performance and reducing integration error - //you can't see above this anyway - float maxZ = min(rayLength,32.0)/(1e-8+rayLength); - - dV *= maxZ; - rayLength *= maxZ; - - vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; - - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - #ifdef OVERWORLD_SHADER - float phase = fogPhase(VdotL) * 5.0; - #else - const float phase = 0.0; - #endif - - float thing = -normalize(dVWorld).y; - thing = clamp(thing + 0.333,0.0,1.0); - thing = pow(1.0-pow(1.0-thing,2.0),2.0); - thing *= 15.0; - - const float expFactor = 11.0; - for (int i=0;i pos.z && sh.x < 1.0){ - vec4 translucentShadow = texture(shadowcolor0, pos.xy); - if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001); - } - #else - sh = vec3(texture(shadow, pos).x); - #endif - } - - sh *= GetCloudShadow(progressW, WsunVec * lightSourceCheck); - - #endif - - float bubble = exp2(-10.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0)); - float caustics = max(max(waterCaustics(progressW, WsunVec, -(progressW.y - waterEnteredAltitude)), phase*0.5) * mix(0.5, 1.5, bubble), phase); - - vec3 sunAbsorbance = exp(-waterCoefs * (distanceFromWaterSurface/abs(WsunVec.y))); - vec3 WaterAbsorbance = exp(-waterCoefs * (distanceFromWaterSurface + thing)); - - vec3 Directlight = lightSource * sh * phase * caustics * sunAbsorbance; - - vec3 _ambient = ambient; - - #ifdef OVERWORLD_SHADER - float horizontalDist = length((progressP.xz) - lightningBoltPosition.xz); - if (horizontalDist < 250.0 && lightningBoltPosition.w > 0.0) { - float lightningIntensity = exp(-horizontalDist * 0.02) * lightningFlash; - _ambient = mix(_ambient, vec3(1.3,1.5,3.0) * sh, lightningIntensity); - } - #endif - - vec3 Indirectlight = _ambient * WaterAbsorbance; - - #if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED && defined LPV_VL_FOG_ILLUMINATION_HANDHELD_WATER - float lightRange = 0.0; - vec3 handLightCol = GetHandLight(heldItemId, progressP, lightRange); - - vec3 handLightCol2 = GetHandLight(heldItemId2, progressP, lightRange); - - Indirectlight += (handLightCol + handLightCol2) * TORCH_AMOUNT * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS / 100.0) * 0.2 * exp(-waterCoefs * (length(progressP) + 0.05 * thing)); - #endif - - - vec3 light = (Indirectlight + Directlight + LPV) * scatterCoef; - - vec3 volumeCoeff = exp(-waterCoefs * length(dd*dVWorld)); - vL += (light - light * volumeCoeff) / waterCoefs * absorbance; - absorbance *= volumeCoeff; - - } - - return vec4(vL, dot(absorbance,vec3(0.333333))); -} - -vec4 blueNoise(vec2 coord){ - return texelFetch(colortex6, ivec2(coord)%512 , 0) ; -} -vec2 R2_samples(int n){ - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha * n); -} - -float fogPhase2(float lightPoint){ - float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0); - float linear2 = 1.0 - clamp(lightPoint,0.0,1.0); - - float exponential = exp2(pow(linear,0.3) * -15.0 ) * 1.5; - exponential += sqrt(exp2(sqrt(linear) * -12.5)); - - return exponential; -} -//encoding by jodie -float encodeVec2(vec2 a){ - const vec2 constant1 = vec2( 1., 256.) / 65535.; - vec2 temp = floor( a * 255. ); - return temp.x*constant1.x+temp.y*constant1.y; -} - - - -uniform int framemod8; -#include "/lib/TAA_jitter.glsl" - -float convertHandDepth(float depth) { - float ndcDepth = depth * 2.0 - 1.0; - ndcDepth /= MC_HAND_DEPTH; - return ndcDepth * 0.5 + 0.5; -} - -float swapperlinZ(float depth, float _near, float _far) { - return (2.0 * _near) / (_far + _near - depth * (_far - _near)); - // l = (2*n)/(f+n-d(f-n)) - // f+n-d(f-n) = 2n/l - // -d(f-n) = ((2n/l)-f-n) - // d = -((2n/l)-f-n)/(f-n) - -} - - -vec3 alterCoords(in vec3 coords, bool lighting){ - - float theDistance = length(coords + (lighting ? vec3(0.0) : cameraPosition)); - - coords.x = coords.x*3; - - coords.y = coords.y; - - coords.z = coords.z*3; - - return coords; -} - uniform float viewHeight; uniform float viewWidth; -float godrayTest( in vec3 viewPos, in vec3 lightDir, float noise, float vanilladepth){ +uniform float nightVision; +uniform float fogEnd; +uniform vec3 fogColor; +uniform vec3 sunVec; +uniform float frameTimeCounter; +uniform int frameCounter; +uniform float far; +uniform float near; +uniform float farPlane; +uniform float dhVoxyNearPlane; +uniform float dhVoxyFarPlane; - // return 1.0;1 +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferModelView; +uniform mat4 gbufferPreviousModelView; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferProjection; +uniform mat4 gbufferPreviousProjection; +uniform vec3 cameraPosition; +uniform vec3 previousCameraPosition; - float godrays = 0.0; - float samples = 8.0; +uniform int hideGUI; +uniform int dhVoxyRenderDistance; +uniform int isEyeInWater; +uniform ivec2 eyeBrightnessSmooth; +uniform ivec2 eyeBrightness; +uniform float rainStrength; +uniform float blindness; +uniform float darknessFactor; +uniform float darknessLightFactor; +uniform float caveDetection; +uniform float sunElevation; - float _near = near; float _far = far*4.0; +#include "/lib/res_params.glsl" - // #ifdef DISTANT_HORIZONS - // bool depthCheck = true; - // #else - // bool depthCheck = false; - // #endif - - bool depthCheck = true; - - if (depthCheck) { - _near = dhVoxyNearPlane; - _far = dhVoxyFarPlane; - } - - float lightRange = pow(clamp(-dot(normalize(viewPos), lightDir)+0.65,0.0,1.0),2.0); - vec3 position = toClipSpace3_DH(viewPos, depthCheck) ; - - //prevents the ray from going behind the camera - float rayLength = ((viewPos.z + lightDir.z * _far * sqrt(3.)) > -_near) ? (-_near - viewPos.z) / lightDir.z : _far * sqrt(3.); - - vec3 direction = toClipSpace3_DH(viewPos + lightDir*rayLength, depthCheck) - position; - - direction.xyz = direction.xyz / max(max(abs(direction.x)/0.0005, abs(direction.y)/0.0005),500.0); //fixed step size - direction *= 60.0; - - position.xy *= RENDER_SCALE; - direction.xy *= RENDER_SCALE; - - vec3 newPos = position + direction*noise; - - vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); - - for (int i = 0; i < int(samples); i++) { - newPos.xy = clamp(newPos.xy, screenEdges, 1.0-screenEdges); - - float sampleDepth = invLinZ(sqrt(texelFetch(colortex4, ivec2(newPos.xy/texelSize/4.0),0).a/65000.0)); - - #ifdef DISTANT_HORIZONS - if(depthCheck) sampleDepth = texelFetch(dhDepthTex1, ivec2(newPos.xy/texelSize),0).x; - #endif - - godrays += (swapperlinZ(sampleDepth, _near, _far) > 1.0 ? 1.0 : lightRange); - newPos += direction; - } - - return godrays/samples; +#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; } -vec4 waterVolumetrics_alt( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ - int spCount = rayMarchSampleCount; +float linearize(float dist) { + return (2.0 * near) / (far + near - dist * (far - near)); +} - vec3 start = toShadowSpaceProjected(rayStart); - vec3 end = toShadowSpaceProjected(rayEnd); - vec3 dV = (end-start); +vec3 toClipSpace3Prev(vec3 viewSpacePosition) { + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +} - //limit ray length at 32 blocks for performance and reducing integration error - //you can't see above this anyway - float maxZ = min(rayLength,12.0)/(1e-8+rayLength); - dV *= maxZ; - rayLength *= maxZ; - estEndDepth *= maxZ; - estSunDepth *= maxZ; - - vec3 dVWorld = mat3(gbufferModelViewInverse) * rayStart; - vec3 wpos = dVWorld + gbufferModelViewInverse[3].xyz; - - #ifdef OVERWORLD_SHADER - float phase = fogPhase(VdotL) * 5.0; +vec3 bilateralUpsample2(vec2 fragcoord, sampler2D colortex, out float outerEdgeResults, float referenceDepth, sampler2D depth, bool hand){ + + vec3 colorSum = vec3(0.0); + float edgeSum = 0.0; + + const float threshold = 0.005; + + + const int samples = 5; + + vec2 coord = fragcoord - 1.5; + + vec2 UV = coord; + const ivec2 SCALE = ivec2(1.0); + ivec2 UV_COLOR = ivec2(UV); + ivec2 UV_NOISE = ivec2(gl_FragCoord.xy*texelSize + 1); + + const ivec2 OFFSET[5] = ivec2[5]( + ivec2(-1,-1), + ivec2( 1, 1), + ivec2(-1, 1), + ivec2( 1,-1), + ivec2( 0, 0) + // ,ivec2( 0, 1), + // ivec2( 0,-1), + // ivec2( 1, 0), + // ivec2(-1, 0) + ); + + for(int i = 0; i < samples; i++) { + float offsetDepth = linearize(texelFetch(depth, UV_COLOR + (OFFSET[i] + UV_NOISE), 0).r); + + float edgeDiff = abs(offsetDepth - referenceDepth) < threshold ? 1.0 : 1e-7; + outerEdgeResults = max(outerEdgeResults, abs(referenceDepth - offsetDepth)); + + vec3 offsetColor = texelFetch(colortex, UV_COLOR + OFFSET[i] + UV_NOISE, 0).rgb; + colorSum += offsetColor*edgeDiff; + edgeSum += edgeDiff; + + } + + outerEdgeResults = outerEdgeResults > (hand ? 0.005 : referenceDepth*0.05 + 0.1) ? 1.0 : 0.0; + + return colorSum / edgeSum; +} + +vec3 VLTemporalFiltering2(vec2 texcoord, vec3 playerPosIn, in float referenceDepth, sampler2D depth, bool hand, vec3 currentFrame, float roughness){ + // get previous frames position stuff for UV + vec3 playerPos = playerPosIn + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; + previousPosition = toClipSpace3Prev(previousPosition); + + vec2 velocity = previousPosition.xy - texcoord; + previousPosition.xy = texcoord + velocity; + + // return vec4(outerEdgeResults,0,0,1); + // return upsampledCurrentFrame; + + if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0 || hand) return currentFrame.rgb; + + // to fill pixel gaps in geometry edges, do a bilateral upsample. + // pass a mask to only show upsampled color around the edges of blocks. this is so it doesnt blur reprojected results. + float outerEdgeResults = 0.0; + vec3 upsampledCurrentFrame = bilateralUpsample2(gl_FragCoord.xy , colortex0, outerEdgeResults, referenceDepth, depth, hand); + //return currentFrame; + // vec4 upsampledCurrentFrame = BilateralUpscale(colortex0, depth, gl_FragCoord.xy - 1.5, referenceDepth); + // /* + + vec4 frameHistoryTex = texture(colortex12, previousPosition.xy*RENDER_SCALE); + float prevDepth = frameHistoryTex.a; + float linPrevDepth = linearize(previousPosition.z); + + vec3 frameHistory = frameHistoryTex.rgb; + + vec3 reprojectFrame = currentFrame.rgb; + + if(!(frameHistory.r == 0.0 && frameHistory.g == 0.0 && frameHistory.b == 0.0) && (abs(prevDepth-linPrevDepth) < max(linPrevDepth * 0.02, 0.001))) { + vec3 col1 = texture(colortex0, texcoord + vec2( texelSize.x, texelSize.y)).rgb; + vec3 col2 = texture(colortex0, texcoord + vec2( texelSize.x, -texelSize.y)).rgb; + vec3 col3 = texture(colortex0, texcoord + vec2(-texelSize.x, -texelSize.y)).rgb; + vec3 col4 = texture(colortex0, texcoord + vec2(-texelSize.x, texelSize.y)).rgb; + vec3 col5 = texture(colortex0, texcoord + vec2( 0.0, texelSize.y)).rgb; + vec3 col6 = texture(colortex0, texcoord + vec2( 0.0, -texelSize.y)).rgb; + vec3 col7 = texture(colortex0, texcoord + vec2(-texelSize.x, 0.0)).rgb; + vec3 col8 = texture(colortex0, texcoord + vec2( texelSize.x, 0.0)).rgb; + + vec3 colMax = max(currentFrame.rgb,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); + vec3 colMin = min(currentFrame.rgb,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); + + vec3 clampedFrameHistory = clamp(frameHistory, colMin, colMax); + + float blendingFactor = mix(0.025, 1.0, smoothstep(0.05, 0.25, length(cameraPosition-previousCameraPosition))); + blendingFactor = mix(1.0, blendingFactor, smoothstep(0.0, 0.1, roughness)); + reprojectFrame = mix(clampedFrameHistory, currentFrame.rgb, blendingFactor); + } + + // return clamp(reprojectFrame,0.0,65000.0); + return clamp(mix(reprojectFrame, upsampledCurrentFrame, outerEdgeResults),0.0,65000.0); + // */ + +} + +float blueNoise(){ + #ifdef TAA + return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); #else - const float phase = 1.0; + return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887); + #endif +} + +float interleaved_gradientNoise_temporal(){ + // #ifdef TAA + // return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter); + // #else + // return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887); + // #endif + + vec2 coord = gl_FragCoord.xy; + #ifdef TAA + coord += (frameCounter%40000) * 2.0; #endif - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - float expFactor = 11.0; - vec3 sh = vec3(1.0); - - // do this outside raymarch loop, masking the water surface is good enough - #if defined OVERWORLD_SHADER - sh *= GetCloudShadow(wpos+cameraPosition, WsunVec); - #endif - - float thing = -normalize(dVWorld).y; - thing = clamp(thing - 0.333,0.0,1.0); - thing = pow(1.0-pow(1.0-thing,2.0),2.0); - thing *= 15.0; - - for (int i=0;i pos.z && sh2.x < 1.0){ - vec4 translucentShadow = texture(shadowcolor0, pos.xy); - if(translucentShadow.a < 0.9) sh2 = normalize(translucentShadow.rgb+0.0001); - } - #else - sh2 *= vec3(texture(shadow, pos).x); - #endif - } - #endif - - vec3 sunAbsorbance = exp(-waterCoefs * estSunDepth * d); - vec3 ambientAbsorbance = exp(-waterCoefs * (estEndDepth * d + thing)); - - vec3 Directlight = lightSource * sh2 * phase * sunAbsorbance; - - vec3 _ambient = ambient; - - #ifdef OVERWORLD_SHADER - float horizontalDist = length(progressP.xz - lightningBoltPosition.xz); - if (horizontalDist < 250.0 && lightningBoltPosition.w > 0.0) { - float lightningIntensity = exp(-horizontalDist * 0.02) * lightningFlash; - _ambient = mix(_ambient, vec3(1.3,1.5,3.0) * sh2, lightningIntensity); - } - #endif - - #if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED && defined LPV_VL_FOG_ILLUMINATION_HANDHELD_WATER - float lightRange = 0.0; - vec3 handLightCol = GetHandLight(heldItemId, progressP, lightRange); - - vec3 handLightCol2 = GetHandLight(heldItemId2, progressP, lightRange); - - _ambient += (handLightCol + handLightCol2) * TORCH_AMOUNT * 0.225 * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS / 100.0); - #endif - - vec3 Indirectlight = _ambient * ambientAbsorbance; - - vec3 light = (Indirectlight + Directlight) * scatterCoef; - - vec3 volumeCoeff = exp(-waterCoefs * dd * rayLength); - vL += (light - light * volumeCoeff) / waterCoefs * absorbance; - absorbance *= volumeCoeff; - } - - return vec4(vL, dot(absorbance,vec3(0.333333))); + return fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y ) + 1.0/1.6180339887); } vec2 decodeVec2(float a){ @@ -689,233 +233,361 @@ vec2 decodeVec2(float a){ return fract( a * constant1 ) * constant2 ; } +vec3 decode (vec2 encn){ + vec3 n = vec3(0.0); + encn = encn * 2.0 - 1.0; + n.xy = abs(encn); + n.z = 1.0 - n.x - n.y; + n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn; + return clamp(normalize(n.xyz),-1.0,1.0); +} -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +vec3 toLinear(vec3 sRGB){ +return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); +} +float shlickFresnelRoughness(float XdotN, float roughness){ + + float shlickFresnel = clamp(1.0 + XdotN,0.0,1.0); + + float curves = exp(-4.0*pow(1.0-(roughness),2.5)); + float brightness = exp(-3.0*pow(1.0-sqrt(roughness),3.50)); + + shlickFresnel = pow(1.0-pow(1.0-shlickFresnel, mix(1.0, 1.9, curves)),mix(5.0, 2.6, curves)); + shlickFresnel = mix(0.0, mix(1.0,0.065, brightness) , clamp(shlickFresnel,0.0,1.0)); + + return shlickFresnel; +} + +void frisvad(in vec3 n, out vec3 f, out vec3 r){ + if(n.z < -0.9) { + f = vec3(0.,-1,0); + r = vec3(-1, 0, 0); + } else { + float a = 1./(1.+n.z); + float b = -n.x*n.y*a; + f = vec3(1. - n.x*n.x*a, b, -n.x) ; + r = vec3(b, 1. - n.y*n.y*a , -n.y); + } +} + +mat3 CoordBase(vec3 n){ + vec3 x,y; + frisvad(n,x,y); + return mat3(x,y,n); +} + +vec3 GGX(vec3 n, vec3 v, vec3 l, float r, vec3 f0, vec3 metalAlbedoTint) { + r = max(pow(r,2.5), 0.0001); + + vec3 h = normalize(l + v); + float hn = inversesqrt(dot(h, h)); + + float dotLH = clamp(dot(h,l)*hn,0.,1.); + float dotNH = clamp(dot(h,n)*hn,0.,1.) ; + float dotNL = clamp(dot(n,l),0.,1.); + float dotNHsq = dotNH*dotNH; + + float denom = dotNHsq * r - dotNHsq + 1.; + float D = r / (3.141592653589793 * denom * denom); + + vec3 F = (f0 + (1. - f0) * exp2((-5.55473*dotLH-6.98316)*dotLH)) * metalAlbedoTint; + float k2 = .25 * r; + + return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2); +} + +#ifdef IEXT_ENABLED +uniform bool IEXT_KEY_0; +#endif + +vec4 calculateFlashlightData(in vec3 viewPos, bool hand){ + #ifdef IEXT_ENABLED + if(!IEXT_KEY_0) return vec4(0.0); + #endif + + vec4 flashLightSpecularData = vec4(0.0); + if(hand){ + return flashLightSpecularData; + } + + // vec3 shiftedViewPos = viewPos + vec3(-0.25, 0.2, 0.0); + // vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition) * 3.0; + // shiftedViewPos = mat3(gbufferPreviousModelView) * shiftedPlayerPos + gbufferPreviousModelView[3].xyz; + vec3 shiftedViewPos; + vec3 shiftedPlayerPos; + float forwardOffset; + + #ifdef VIVECRAFT + if (vivecraftIsVR) { + forwardOffset = 0.0; + shiftedPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + vivecraftRelativeMainHandPos; + shiftedViewPos = shiftedPlayerPos * mat3(vivecraftRelativeMainHandRot); + } else + #endif + { + forwardOffset = 0.5; + shiftedViewPos = viewPos + vec3(-0.25, 0.2, 0.0); + shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition) * 3.0; + shiftedViewPos = mat3(gbufferPreviousModelView) * shiftedPlayerPos + gbufferPreviousModelView[3].xyz; + } + + + + vec2 scaledViewPos = shiftedViewPos.xy / max(-shiftedViewPos.z - forwardOffset, 1e-7); + float linearDistance = length(shiftedPlayerPos); + float shiftedLinearDistance = length(scaledViewPos); + + float lightFalloff = 1.0 - clamp(1.0-linearDistance/FLASHLIGHT_RANGE, -0.999,1.0); + lightFalloff = max(exp(-10.0 * FLASHLIGHT_BRIGHTNESS_FALLOFF_MULT * lightFalloff),0.0); + + float flashLightSpecular = lightFalloff * exp2(-7.0*shiftedLinearDistance*shiftedLinearDistance) * FLASHLIGHT_BRIGHTNESS_MULT; + flashLightSpecularData = vec4(normalize(shiftedPlayerPos), flashLightSpecular); + + return flashLightSpecularData; +} + +#if defined IS_LPV_ENABLED || defined PHOTONICS && defined PHOTONICS && !defined PH_ENABLE_HANDHELD_LIGHT + uniform bool firstPersonCamera; + uniform vec3 relativeEyePosition; + uniform int heldItemId; + uniform int heldItemId2; + + uniform sampler3D texLpv1; + uniform sampler3D texLpv2; + + #include "/lib/util.glsl" + #include "/lib/hsv.glsl" + #include "/lib/lpv_common.glsl" + #include "/lib/lpv_render.glsl" + #include "/lib/blocks.glsl" + #include "/lib/lpv_blocks.glsl" + + vec3 GetHandLight(const in int itemId, const in vec3 playerPos, inout float lightRange) { + vec3 lightFinal = vec3(0.0); + + uint blockData = imageLoad(imgBlockData, itemId).r; + vec4 lightColorRange = unpackUnorm4x8(blockData); + lightRange = lightColorRange.a * 255.0; + + if (lightRange > 0.0) { + vec3 lightColor = srgbToLinear(lightColorRange.rgb); + float lightDist = length(playerPos+relativeEyePosition)*0.7; + float falloff = pow(1.0 - lightDist / lightRange, 3.0); + lightFinal = lightColor * max(falloff, 0.0); + } + + return lightFinal; + } + + #ifdef BELTBORNE_LANTERNS + uniform int IEXT_beltborne_lanterns_Id; + #endif +#endif + +float getReflectionVisibility(float f0, float roughness){ + + // the goal is to determine if the reflection is even visible. + // if it reaches a point in smoothness or reflectance where it is not visible, allow it to interpolate to diffuse lighting. + #if ROUGHNESS_THRESHOLD < 1 + return 0.0; + #else + float thresholdValue = ROUGHNESS_THRESHOLD/100.0; + + // the visibility gradient should only happen for dialectric materials. because metal is always shiny i guess or something + float dialectrics = max(f0*255.0 - 26.0,0.0)/229.0; + float value = 0.35; // so to a value you think is good enough. + float thresholdA = min(max( (1.0-dialectrics) - value, 0.0)/value, 1.0); + + // use perceptual smoothness instead of linear roughness. it just works better i guess + float smoothness = 1.0-sqrt(roughness); + value = thresholdValue; // this one is typically want you want to scale. + float thresholdB = min(max(smoothness - value, 0.0)/value, 1.0); + + // preserve super smooth reflections. if thresholdB's value is really high, then fully smooth, low f0 materials would be removed (like water). + value = 0.1; // super low so only the smoothest of materials are includes. + float thresholdC = 1.0-min(max(value - (1.0-smoothness), 0.0)/value, 1.0); + + float visibilityGradient = max(thresholdA*thresholdC - thresholdB,0.0); + + // a curve to make the gradient look smooth/nonlinear. just preference + visibilityGradient = 1.0-visibilityGradient; + visibilityGradient *=visibilityGradient; + visibilityGradient = 1.0-visibilityGradient; + visibilityGradient *=visibilityGradient; + + return visibilityGradient; + #endif +} + +/* RENDERTARGETS:12,3 */ void main() { - /* RENDERTARGETS:0,13 */ + vec2 texcoord = gl_FragCoord.xy*texelSize; + float depth = texelFetch(depthtex1, ivec2(gl_FragCoord.xy),0).x; + // bool hand = depth < 0.56; + float z = depth; - gl_FragData[1] = vec4(0.0,0.0,0.0, 1.0); + #if defined DISTANT_HORIZONS || defined VOXY + float DH_depth1 = 1.0; + float swappedDepth; + if(z >= 1.0) { + DH_depth1 = texelFetch(dhVoxyDepthTex1,ivec2(gl_FragCoord.xy),0).x; + swappedDepth = DH_depth1; + } else { + swappedDepth = z; + } + #else + float DH_depth1 = 1.0; + float swappedDepth = z; + #endif - float noise_1 = interleaved_gradientNoise_temporal(); - // float noise_2 = blueNoise(); - // float noise_2 = interleaved_gradientNoise_temporal(); - vec2 bnoise = blueNoise(gl_FragCoord.xy ).rg; + bool isSky = swappedDepth >= 1.0; + + gl_FragData[0] = vec4(0.0); + vec3 FINAL_COLOR = texture(colortex3, texcoord).rgb; + if(!isSky) { - int seed = frameCounter%40000; - vec2 r2_sequence = R2_samples(seed).xy*5.0; - vec2 BN = fract(r2_sequence + bnoise); + float frDepth = linearize(z); + gl_FragData[0].a = frDepth; - vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_SCALE*texelSize + texelSize*0.5; - // vec2 tc = (gl_FragCoord.xy - 0.5)/VL_RENDER_SCALE*texelSize; + vec4 data = texelFetch(colortex1, ivec2(gl_FragCoord.xy), 0); - // bool iswater = texture(colortex7,tc).a > 0.99; + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps - ivec2 texcoord = ivec2(tc/texelSize); + float opaqueMasks = dataUnpacked1.w; + bool hand = abs(opaqueMasks-0.75) < 0.01; + bool entities = abs(opaqueMasks-0.45) < 0.01; - float alpha = texelFetch(colortex7,texcoord,0).a ; - float blendedAlpha = texelFetch(colortex2, texcoord,0).a; + vec3 viewPos = toScreenSpace(vec3(texcoord/RENDER_SCALE, z)); - bool iswater = alpha > 0.99; - - float z0 = texelFetch(depthtex0, texcoord,0).x; - - // z0 = depth < 0.56 ? convertHandDepth(depth) : depth; - - #if defined DISTANT_HORIZONS || defined VOXY - float DH_z0 = 0.0; - - if (z0 >= 1.0) DH_z0 = texelFetch(dhVoxyDepthTex, texcoord,0).x; - #else - float DH_z0 = 0.0; - #endif - - vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0); - vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos0 + gbufferModelViewInverse[3].xyz; - vec3 playerPos_normalized = normalize(playerPos); - - // vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); - // vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B); - vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); - vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; - - vec3 directLightColor = lightSourceColorSSBO / 2400.0; - - vec3 directSunlightColor = sunColorSSBO / 2400.0; - #ifdef CUSTOM_MOON_ROTATION - directSunlightColor *= smoothstep(0.005, 0.09, length(WmoonVec - WrealSunVec)); - #endif - - vec3 directMoonlightColor = moonColorSSBO / 2400.0; - #ifdef CUSTOM_MOON_ROTATION - directMoonlightColor *= mix(0.0, 1.0, clamp(WmoonVec.y + 0.05, 0.0, 0.1)/0.1); - #endif - - vec3 indirectLightColor = skyGroundColSSBO / 1200.0; - vec3 indirectLightColor_dynamic = averageSkyCol_CloudsSSBO / 1200.0; - - // #if defined DISTANT_HORIZONS || defined VOXY - // float godrays = godrayTest(viewPos0, normalize(WsunVec*mat3(gbufferModelViewInverse)),BN.x, z0); - // #else - // float godrays = 1.0; - // #endif - - #if (defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED) || (defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION) - vec4 LPV_ILLUMINATION = raymarchLPV(viewPos0, BN.y); - #else - vec4 LPV_ILLUMINATION = vec4(0.0,0.0,0.0,1.0); - #endif - - vec3 indirectLight = indirectLightColor_dynamic * skyLightLevelSmooth * ambient_brightness; - float minimumLightAmount = 0.02*nightVision + 0.001 * mix(MIN_LIGHT_AMOUNT_INSIDE, MIN_LIGHT_AMOUNT, clamp(skyLightLevelSmooth, 0.0, 1.0)); - indirectLight += vec3(1.0) * minimumLightAmount; - - vec3 indirectLight_fog = indirectLightColor * ambient_brightness; - indirectLight_fog += vec3(1.0) * (0.02*nightVision + 0.001 * mix(MIN_LIGHT_AMOUNT_INSIDE, MIN_LIGHT_AMOUNT, skyLightLevelSmooth)); + vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos; + vec3 NplayerPos = normalize(playerPos); + playerPos += gbufferModelViewInverse[3].xyz; - float cloudPlaneDistance = 0.0; - vec2 cloudDistance = vec2(0.0); // r = cumulus, g = cumulonimbus + // derived from N and K from labPBR wiki https://shaderlabs.org/wiki/LabPBR_Material_Standard + // using ((1.0 - N)^2 + K^2) / ((1.0 + N)^2 + K^2) + const vec3 HCM_F0 [8] = vec3[8]( + vec3(0.531228825312, 0.51235724246, 0.495828545714),// iron + vec3(0.944229966045, 0.77610211732, 0.373402004593),// gold + vec3(0.912298031535, 0.91385063144, 0.919680580954),// Aluminum + vec3(0.55559681715, 0.55453707574, 0.554779427513),// Chrome + vec3(0.925952196272, 0.72090163805, 0.504154241735),// Copper + vec3(0.632483812932, 0.62593707362, 0.641478899539),// Lead + vec3(0.678849234658, 0.64240055565, 0.588409633571),// Platinum + vec3(0.961999998804, 0.94946811207, 0.922115710997) // Silver + ); - vec4 VolumetricFog; - #ifdef OVERWORLD_SHADER - vec4 VolumetricClouds; - #endif - - if (eyeInWater){ - vec4 underWaterFog = waterVolumetrics(vec3(0.0), viewPos0, length(viewPos0), vec2(noise_1, BN.y), totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos0), normalize(sunVec * lightSourceCheck)), LPV_ILLUMINATION.rgb); - VolumetricFog = vec4(underWaterFog.rgb, 1.0); - } else { - #ifdef OVERWORLD_SHADER - VolumetricClouds = GetVolumetricClouds(viewPos0, BN, WrealSunVec, WmoonVec, directSunlightColor, directMoonlightColor, indirectLightColor, cloudPlaneDistance, cloudDistance); - - #if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 - imageStore(cloudDepthTex, ivec2(gl_FragCoord.xy), vec4(cloudDistance.r, cloudDistance.g, 0, 1)); - #endif + vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); + vec2 lightmap = dataUnpacked1.yz; - #ifdef CAVE_FOG - #if CAVE_DETECTION < 2 - #if CAVE_DETECTION == 1 - float caveFactor = 1.0 - smoothstep(60.0, 63.0, cameraPosition.y); - #else - const float caveFactor = 1.0; - #endif - #else - const float caveFactor = 0.0; - #endif + vec4 stuff = texelFetch(colortex8, ivec2(gl_FragCoord.xy), 0); + vec3 normal = decode(stuff.xy); + vec2 speculars = stuff.zw; - float skyhole = pow(clamp(1.0-pow(max(playerPos_normalized.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2)* caveDetection * caveFactor; - VolumetricClouds.rgb *= 1.0-skyhole; - VolumetricClouds.a = mix(VolumetricClouds.a, 1.0, skyhole); - #endif + float roughness = speculars.r; + float f0 = speculars.g; + roughness = 1.0 - roughness; + roughness *= roughness; - VolumetricFog = GetVolumetricFog(viewPos0, WsunVec, BN, directLightColor, indirectLight_fog, indirectLightColor_dynamic, cloudPlaneDistance); + f0 = f0 == 0.0 ? 0.02 : f0; - #if (defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED) || (defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION) - VolumetricFog.a *= LPV_ILLUMINATION.a; - VolumetricFog.rgb = VolumetricFog.rgb * LPV_ILLUMINATION.a + LPV_ILLUMINATION.rgb; - #endif + bool isMetal = f0 > 229.5/255.0; - // for bloomy fog mask - gl_FragData[1].a = VolumetricFog.a; + // get reflected vector + mat3 basis = CoordBase(normal); + vec3 viewDir = -NplayerPos*basis; + float VdotN = dot(-normalize(viewDir), vec3(0.0,0.0,1.0)); + float shlickFresnel = shlickFresnelRoughness(VdotN, roughness); - VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a); - #endif - - #if defined NETHER_SHADER || defined END_SHADER - VolumetricFog = GetVolumetricFog(viewPos0, noise_1, noise_1); + // F0 < 230 dialectrics + // F0 >= 230 hardcoded metal f0 + // F0 == 255 use albedo for f0 + albedo = f0 == 1.0 ? sqrt(albedo) : albedo; + vec3 metalAlbedoTint = isMetal ? albedo : vec3(1.0); + // get F0 values for hardcoded metals. + vec3 hardCodedMetalsF0 = f0 == 1.0 ? albedo : HCM_F0[int(clamp(f0*255.0 - 229.5,0.0,7.0))]; + vec3 reflectance = isMetal ? hardCodedMetalsF0 : vec3(f0); + vec3 F0 = (reflectance + (1.0-reflectance) * shlickFresnel) * metalAlbedoTint; - #if (defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED) || (defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION) - VolumetricFog.a *= LPV_ILLUMINATION.a; - VolumetricFog.rgb = VolumetricFog.rgb * LPV_ILLUMINATION.a + LPV_ILLUMINATION.rgb; - #endif + vec4 currentFrame = texture(colortex0, texcoord); + float alpha = getReflectionVisibility(f0, roughness); - // for bloomy fog mask - gl_FragData[1].a = VolumetricFog.a; - #endif - } + vec3 denoisedReflections = currentFrame.rgb; - // VolumetricFog = vec4(godrays,godrays,godrays,0.0); - // VolumetricFog = raymarchTest(viewPos0, BN); - // VolumetricFog = vec4(0.0,0.0,0.0,1.0); - // VolumetricFog.rgb = vec3(0); + if(roughness > 0.005 && alpha < 0.9999 && !hand && !entities + #if defined DISTANT_HORIZONS || defined VOXY + && z < 1.0 + #endif + ) { + denoisedReflections = VLTemporalFiltering2(texcoord, playerPos, frDepth, depthtex1, hand, currentFrame.rgb, roughness); - gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0); + gl_FragData[0].rgb = denoisedReflections; + } + denoisedReflections.rgb = mix(FINAL_COLOR, denoisedReflections.rgb, F0); + FINAL_COLOR = mix(denoisedReflections.rgb, FINAL_COLOR, alpha); + #if defined OVERWORLD_SHADER && SUN_SPECULAR_MULT > 0 + vec3 lightSourceReflection = SUN_SPECULAR_MULT * texture(colortex15, texcoord).rgb * GGX(normal, -NplayerPos, WsunVec, roughness, reflectance, metalAlbedoTint); + FINAL_COLOR += lightSourceReflection; + #endif - /// FOG BEHIND TRANSLUCENTS + #if defined FLASHLIGHT_SPECULAR && (defined DEFERRED_SPECULAR || defined FORWARD_SPECULAR) + vec4 flashlightData = calculateFlashlightData(viewPos, hand); + vec3 flashLightReflection = vec3(FLASHLIGHT_R,FLASHLIGHT_G,FLASHLIGHT_B) * flashlightData.a * GGX(normal, -flashlightData.xyz, -flashlightData.xyz, roughness, reflectance, metalAlbedoTint); + FINAL_COLOR += flashLightReflection; + #endif - if(blendedAlpha > 0.0 || iswater){ - vec2 lightmap = decodeVec2(texelFetch(colortex14,texcoord,0).z); - lightmap = min(max(lightmap - 0.05,0.0)*1.06,1.0); + #if defined Hand_Held_lights && (defined IS_LPV_ENABLED || defined PHOTONICS) + if(!hand && firstPersonCamera) { + if (heldItemId > 0){ + vec3 shiftedViewPos = viewPos + vec3(-0.25, 0.2, 0.0); + vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); - #ifndef OVERWORLD_SHADER - lightmap.y = 1.0; - #endif + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId, shiftedPlayerPos, lightRange); - vec2 curvedLightmaps = lightmap; - float lightmapBrightspot = min(max(lightmap.x-0.7,0.0)*3.3333,1.0); - lightmapBrightspot *= lightmapBrightspot*lightmapBrightspot; - float lightmapLight = 1.0-sqrt(1.0-lightmap.x); - lightmapLight *= lightmapLight; - curvedLightmaps.x = mix(lightmapLight, 2.5, lightmapBrightspot); - curvedLightmaps.y = (pow(lightmap.y,15.0)*2.0 + lightmap.y*lightmap.y)/3.0; + if(lightRange > 0.0) { + vec3 handheldReflection1 = handLightCol * GGX(normal, -shiftedPlayerPos, -shiftedPlayerPos, roughness, reflectance, metalAlbedoTint); + FINAL_COLOR += handheldReflection1; + } + } - float z1 = texelFetch(depthtex1, texcoord,0).x; + if (heldItemId2 > 0){ + vec3 shiftedViewPos = viewPos + vec3(0.25, 0.2, 0.0); + vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); - #if defined DISTANT_HORIZONS || defined VOXY - float DH_z1 = 0.0; - if (z1 >= 1.0) DH_z1 = texelFetch(dhVoxyDepthTex1, texcoord,0).x; - #else - float DH_z1 = 0.0; - #endif + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId2, shiftedPlayerPos, lightRange); - vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z1, DH_z1); + if(lightRange > 0.0) { + vec3 handheldReflection1 = handLightCol * GGX(normal, -shiftedPlayerPos, -shiftedPlayerPos, roughness, reflectance, metalAlbedoTint); + FINAL_COLOR += handheldReflection1; + } + } - indirectLight = indirectLightColor_dynamic * skyLightLevelSmooth * ambient_brightness; + #ifdef BELTBORNE_LANTERNS + if (IEXT_beltborne_lanterns_Id > 0){ + vec3 shiftedViewPos = viewPos + vec3(0.15, 0.2, 0.0); + vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(IEXT_beltborne_lanterns_Id, shiftedPlayerPos, lightRange); - if(iswater && !eyeInWater){ - float Vdiff = distance(viewPos1, viewPos0); - float estimatedDepth = Vdiff * abs(playerPos_normalized.y); - float estimatedSunDepth = Vdiff / abs(WsunVec.y); //assuming water plane + if(lightRange > 0.0) { + vec3 handheldReflection1 = handLightCol * GGX(normal, -shiftedPlayerPos, -shiftedPlayerPos, roughness, reflectance, metalAlbedoTint); + FINAL_COLOR += handheldReflection1; + } + } + #endif + } + #endif + + } - float lightleakfix = clamp(lightmap.y + (1.0-caveDetection),0.0,1.0); - - directLightColor *= lightleakfix; - - indirectLight *= curvedLightmaps.y; - - indirectLight += mix(MIN_LIGHT_AMOUNT * 0.004 + nightVision*0.02, MIN_LIGHT_AMOUNT_INSIDE * 0.004 + nightVision*0.02, 1.0 - lightmap.y); - - indirectLight += vec3(TORCH_R,TORCH_G,TORCH_B) * curvedLightmaps.x * TORCH_AMOUNT * blendedAlpha; - - VolumetricFog = waterVolumetrics_alt(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLight, directLightColor, dot(normalize(viewPos0), normalize(sunVec*lightSourceCheck))); - } else { - #if defined OVERWORLD_SHADER - VolumetricClouds = GetVolumetricClouds(viewPos1, vec2(noise_1), WrealSunVec, WmoonVec, directSunlightColor, directMoonlightColor, indirectLightColor, cloudPlaneDistance, cloudDistance); - - #if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 - imageStore(cloudDepthTex, ivec2(gl_FragCoord.xy), vec4(cloudDistance.r, cloudDistance.g, 0, 1)); - #endif - - VolumetricFog = GetVolumetricFog(viewPos1, WsunVec, vec2(noise_1), directLightColor, indirectLight_fog, indirectLight, cloudPlaneDistance); - - VolumetricFog = vec4(VolumetricClouds.rgb*VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a); - #endif - - #if defined NETHER_SHADER || defined END_SHADER - VolumetricFog = GetVolumetricFog(viewPos1, noise_1, noise_1); - #endif - } - - gl_FragData[1] = clamp(VolumetricFog, 0.0, 65000.0); - } + gl_FragData[1].rgb = FINAL_COLOR; } \ No newline at end of file diff --git a/shaders/dimensions/composite2.vsh b/shaders/dimensions/composite2.vsh index 8f2e1dd..b6a5f05 100644 --- a/shaders/dimensions/composite2.vsh +++ b/shaders/dimensions/composite2.vsh @@ -1,39 +1,31 @@ #include "/lib/settings.glsl" -#include "/lib/util.glsl" -#include "/lib/res_params.glsl" -#if defined CUSTOM_MOON_ROTATION && defined OVERWORLD_SHADER - #include "/lib/SSBOs.glsl" +#include "/lib/SSBOs.glsl" + +#if defined BorderFog || (defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS) > 0 + uniform sampler2D colortex4; + #include "/lib/scene_controller.glsl" #endif -#include "/lib/scene_controller.glsl" - - -out DATA { +#ifdef OVERWORLD_SHADER + out DATA { flat vec3 WsunVec; - flat vec3 WrealSunVec; flat vec3 WmoonVec; -}; + }; +#endif -uniform vec2 texelSize; +uniform float far; +uniform float near; +uniform float dhVoxyFarPlane; +uniform float dhVoxyNearPlane; -uniform sampler2D colortex4; - -uniform float sunElevation; +uniform mat4 gbufferModelViewInverse; uniform vec3 sunPosition; uniform vec3 moonPosition; -uniform mat4 gbufferModelViewInverse; -uniform int frameCounter; - - +uniform float sunElevation; uniform int framemod8; #include "/lib/TAA_jitter.glsl" -uniform float frameTimeCounter; -#include "/lib/Shadow_Params.glsl" -#include "/lib/sky_gradient.glsl" - - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -41,11 +33,6 @@ uniform float frameTimeCounter; //////////////////////////////VOID MAIN////////////////////////////// void main() { - gl_Position = ftransform(); - - gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_SCALE)*2.0-1.0; - - float lightSourceCheck = float(sunElevation > 1e-5)*2.0 - 1.0; #ifdef OVERWORLD_SHADER #ifdef SMOOTH_SUN_ROTATION @@ -53,29 +40,22 @@ void main() { #else WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition); #endif - - #ifdef CUSTOM_MOON_ROTATION - #if LIGHTNING_SHADOWS > 0 - vec3 moonVec = customMoonVec2SSBO; - #else - vec3 moonVec = customMoonVecSSBO; - #endif - #else - #ifdef SMOOTH_MOON_ROTATION - vec3 moonVec = WmoonVecSmooth; + + #if AURORA_LOCATION > 0 + #ifdef CUSTOM_MOON_ROTATION + WmoonVec = customMoonVecSSBO; #else - vec3 moonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition); + #ifdef SMOOTH_MOON_ROTATION + WmoonVec = WmoonVecSmooth; + #else + WmoonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition); + #endif + if(dot(-WmoonVec, WsunVec) < 0.9999) WmoonVec = -WmoonVec; #endif - if(dot(-moonVec, WsunVec) < 0.9999) moonVec = -moonVec; #endif - WmoonVec = moonVec; - - WrealSunVec = WsunVec; - WsunVec = mix(WmoonVec, WsunVec, clamp(lightSourceCheck,0,1)); - #else - WmoonVec = vec3(0.0, 1.0, 0.0); - WsunVec = vec3(0.0, 1.0, 0.0); - WrealSunVec = vec3(0.0, 1.0, 0.0); + WsunVec = mix(WmoonVec, WsunVec, clamp(float(sunElevation > 1e-5)*2.0 - 1.0,0,1)); #endif -} + + gl_Position = ftransform(); +} \ No newline at end of file diff --git a/shaders/dimensions/composite3.fsh b/shaders/dimensions/composite3.fsh index 4f8ea8a..b07d5a7 100644 --- a/shaders/dimensions/composite3.fsh +++ b/shaders/dimensions/composite3.fsh @@ -2,12 +2,10 @@ #include "/lib/SSBOs.glsl" -#ifdef OVERWORLD_SHADER - in DATA { - flat vec3 WsunVec; - flat vec3 WmoonVec; - }; -#endif +#define EXCLUDE_WRITE_TO_LUT + +uniform float skyLightLevelSmooth; + uniform sampler2D noisetex; uniform sampler2D depthtex0; @@ -15,197 +13,87 @@ uniform sampler2D depthtex1; #ifdef DISTANT_HORIZONS uniform sampler2D dhDepthTex; - uniform sampler2D dhDepthTex1; + uniform sampler2D dhDepthTex1; #define dhVoxyDepthTex dhDepthTex - #define dhVoxyDepthTex1 dhDepthTex1 + #define dhVoxyDepthTex1 dhDepthTex1 #endif #ifdef VOXY - uniform sampler2D vxDepthTexOpaque; + uniform sampler2D vxDepthTexOpaque; uniform sampler2D vxDepthTexTrans; #define dhVoxyDepthTex vxDepthTexTrans - #define dhVoxyDepthTex1 vxDepthTexOpaque + #define dhVoxyDepthTex1 vxDepthTexOpaque #endif uniform sampler2D colortex0; -uniform sampler2D colortex1; uniform sampler2D colortex2; uniform sampler2D colortex3; -uniform sampler2D colortex4; -uniform sampler2D colortex5; +// uniform sampler2D colortex4; uniform sampler2D colortex6; uniform sampler2D colortex7; -uniform sampler2D colortex8; -uniform sampler2D colortex9; uniform sampler2D colortex10; uniform sampler2D colortex11; -uniform sampler2D colortex12; -uniform sampler2D colortex13; uniform sampler2D colortex14; -uniform vec2 texelSize; - -uniform float viewHeight; -uniform float viewWidth; -uniform float nightVision; -uniform float fogEnd; -uniform vec3 fogColor; -uniform vec3 sunVec; -uniform float frameTimeCounter; -uniform int frameCounter; -uniform float far; -uniform float near; -uniform float farPlane; -uniform float dhVoxyNearPlane; -uniform float dhVoxyFarPlane; - -uniform mat4 gbufferModelViewInverse; -uniform mat4 gbufferModelView; -uniform mat4 gbufferPreviousModelView; -uniform mat4 gbufferProjectionInverse; -uniform mat4 gbufferProjection; -uniform mat4 gbufferPreviousProjection; -uniform vec3 cameraPosition; -uniform vec3 previousCameraPosition; - -uniform int hideGUI; -uniform int dhVoxyRenderDistance; -uniform int isEyeInWater; -uniform ivec2 eyeBrightnessSmooth; -uniform ivec2 eyeBrightness; -uniform float rainStrength; -uniform float blindness; -uniform float darknessFactor; -uniform float darknessLightFactor; -uniform float caveDetection; -uniform float sunElevation; - -#if defined CUMULONIMBUS_LIGHTNING && defined OVERWORLD_SHADER && CUMULONIMBUS > 0 - uniform vec4 lightningBoltPosition; - - #include "/lib/scene_controller.glsl" - - uniform sampler2D lightningTex1; - uniform sampler2D lightningTex2; - uniform sampler2D lightningTex3; - uniform sampler2D lightningTex4; - uniform sampler2D lightningTex5; - uniform sampler2D lightningTex6; - uniform sampler2D lightningTex7; - uniform sampler2D lightningTex8; - uniform sampler2D lightningTex9; - uniform sampler2D lightningTex10; - uniform sampler2D lightningTex11; - uniform sampler2D lightningTex12; - uniform sampler2D lightningTex13; - uniform sampler2D lightningTex14; - uniform sampler2D lightningTex15; - uniform sampler2D lightningTex16; - - #define LIGHTNINGONLY - #include "/lib/volumetricClouds.glsl" -#else - uniform int worldDay; -#endif #if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 layout (rgba16f) uniform image2D cloudDepthTex; #endif -#include "/lib/waterBump.glsl" -#include "/lib/res_params.glsl" +in DATA { + flat vec3 WsunVec; + flat vec3 WrealSunVec; + flat vec3 WmoonVec; +}; -#ifdef OVERWORLD_SHADER - #include "/lib/climate_settings.glsl" +uniform vec3 sunVec; +uniform float sunElevation; + +// uniform float far; +uniform float near; +uniform float dhVoxyFarPlane; +uniform float dhVoxyNearPlane; + +uniform mat4 gbufferPreviousModelView; +uniform vec3 previousCameraPosition; +uniform vec3 relativeEyePosition; + +#if defined VIVECRAFT + uniform bool vivecraftIsVR; + uniform vec3 vivecraftRelativeMainHandPos; + uniform vec3 vivecraftRelativeOffHandPos; + uniform mat4 vivecraftRelativeMainHandRot; + uniform mat4 vivecraftRelativeOffHandRot; #endif -#include "/lib/sky_gradient.glsl" +uniform int frameCounter; +uniform float frameTimeCounter; -#if RAINBOW > 0 && defined OVERWORLD_SHADER - uniform float rainbowAmount; - #include "/lib/hsv.glsl" -#endif +uniform vec2 texelSize; +uniform int isEyeInWater; +uniform float rainStrength; +uniform ivec2 eyeBrightnessSmooth; uniform float eyeAltitude; +uniform float caveDetection; +// uniform int dhVoxyRenderDistance; +#define DHVLFOG #define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) #define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) -// float ld(float depth) { -// return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near -// } - -float convertHandDepth(float depth) { - float ndcDepth = depth * 2.0 - 1.0; - ndcDepth /= MC_HAND_DEPTH; - return ndcDepth * 0.5 + 0.5; -} - -float linearize(float dist) { - return (2.0 * near) / (far + near - dist * (far - near)); -} - -float luma(vec3 color) { - return dot(color,vec3(0.21, 0.72, 0.07)); -} - -vec3 toLinear(vec3 sRGB){ - return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); -} - -vec3 toScreenSpace(vec3 p) { - vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); - vec3 playerPos = p * 2. - 1.; - vec4 fragposition = iProjDiag * playerPos.xyzz + gbufferProjectionInverse[3]; - return fragposition.xyz / fragposition.w; -} +#include "/lib/color_transforms.glsl" +#include "/lib/color_dither.glsl" +#include "/lib/projections.glsl" +#include "/lib/res_params.glsl" +#include "/lib/sky_gradient.glsl" +#include "/lib/Shadow_Params.glsl" +#include "/lib/waterBump.glsl" #include "/lib/DistantHorizons_projections.glsl" -float interleaved_gradientNoise_temporal(){ - #ifdef TAA - return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter); - #else - return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887); - #endif -} - -float interleaved_gradientNoise(){ - vec2 coord = gl_FragCoord.xy; - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); - return noise; -} - -float R2_dither(){ - vec2 coord = gl_FragCoord.xy ; - - #ifdef TAA - coord += (frameCounter%40000) * 2.0; - #endif - - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha.x * coord.x + alpha.y * coord.y ) ; -} - -float blueNoise(){ - #ifdef TAA - return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); - #else - return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887); - #endif -} - -vec4 blueNoise(vec2 coord){ - return texelFetch(colortex6, ivec2(coord)%512 , 0) ; -} - -vec3 normVec (vec3 vec){ - return vec*inversesqrt(dot(vec,vec)); -} - float DH_ld(float dist) { return (2.0 * dhVoxyNearPlane) / (dhVoxyFarPlane + dhVoxyNearPlane - dist * (dhVoxyFarPlane - dhVoxyNearPlane)); } - float DH_inv_ld (float lindepth){ return -((2.0*dhVoxyNearPlane/lindepth)-dhVoxyFarPlane-dhVoxyNearPlane)/(dhVoxyFarPlane-dhVoxyNearPlane); } @@ -214,742 +102,863 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo return (near * far) / (depth * (near - far) + far); } +uniform float nightVision; + +#ifdef OVERWORLD_SHADER + uniform float auroraAmount; + const bool shadowHardwareFiltering = true; + uniform sampler2DShadow shadowtex0HW; + + #ifdef TRANSLUCENT_COLORED_SHADOWS + uniform sampler2D shadowcolor0; + uniform sampler2DShadow shadowtex1HW; + #endif + + + #include "/lib/scene_controller.glsl" + + #define TIMEOFDAYFOG + #include "/lib/lightning_stuff.glsl" + + #include "/lib/volumetricClouds.glsl" + + #include "/lib/climate_settings.glsl" + #include "/lib/overworld_fog.glsl" +#endif +#ifdef NETHER_SHADER +uniform sampler2D colortex4; + #include "/lib/nether_fog.glsl" +#endif +#ifdef END_SHADER +uniform sampler2D colortex4; + #include "/lib/end_fog.glsl" +#endif + +#include "/lib/util.glsl" + +#define IS_LPV_ENABLED + +#if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED + #extension GL_ARB_shader_image_load_store: enable + #extension GL_ARB_shading_language_packing: enable + + uniform usampler1D texBlockData; + uniform sampler3D texLpv1; + uniform sampler3D texLpv2; + + #include "/lib/hsv.glsl" + #include "/lib/lpv_blocks.glsl" + #include "/lib/lpv_common.glsl" + #include "/lib/lpv_render.glsl" + + #if defined LPV_VL_FOG_ILLUMINATION_HANDHELD_WATER || defined LPV_VL_FOG_ILLUMINATION_HANDHELD + uniform int heldItemId; + uniform int heldItemId2; + + #include "/lib/diffuse_lighting.glsl" + #endif + #ifdef LPV_VL_FOG_ILLUMINATION_HANDHELD + #endif +#endif + +bool eyeInWater = isEyeInWater == 1; + +vec4 raymarchLPV( + in vec3 viewPos, + in float dither +){ + #if (!defined LPV_VL_FOG_ILLUMINATION || !defined IS_LPV_ENABLED) && (!defined FLASHLIGHT_FOG_ILLUMINATION || !defined FLASHLIGHT) + return vec4(0.0); + #endif + + const int SAMPLECOUNT = 8; + float minimumDensity = 0.000025; + if(eyeInWater) minimumDensity = 0.00006; + const float fadeLength = 10.0; // in blocks + + vec3 LPVrayStartPos = mat3(gbufferModelViewInverse) * viewPos; + + // ensure the max marching distance is the voxel distance, or the render distance if the voxels go farther than it + float LPVRayLength = length(LPVrayStartPos); + #if LPV_SIZE == 8 + LPVrayStartPos *= min(LPVRayLength, min(256.0,far))/LPVRayLength; + #elif LPV_SIZE == 7 + LPVrayStartPos *= min(LPVRayLength, min(128.0,far))/LPVRayLength; + #elif LPV_SIZE == 6 + LPVrayStartPos *= min(LPVRayLength, min(64.0,far))/LPVRayLength; + #endif + LPVRayLength = length(LPVrayStartPos); + + vec3 rayProgress = vec3(0.0); + vec4 color = vec4(0.0,0.0,0.0,1.0); + const float expFactor = 11.0; + + for (int i = 0; i < SAMPLECOUNT; i++) { + float d = (pow(expFactor, float(i+dither)/float(SAMPLECOUNT))/expFactor - 1.0/expFactor)/(1.0-1.0/expFactor); + float dd = pow(expFactor, float(i+dither)/float(SAMPLECOUNT)) * log(expFactor) / float(SAMPLECOUNT)/(expFactor-1.0); + + rayProgress = gbufferModelViewInverse[3].xyz + d*LPVrayStartPos; + + float density; + float _minimumDensity = minimumDensity; + + #ifdef OVERWORLD_SHADER + if(caveDetection < 0.9999) density = cloudVol(rayProgress + cameraPosition, 0.0) * (1.0 - caveDetection); + + _minimumDensity += caveDetection * minimumDensity; + #elif defined NETHER_SHADER + vec3 progressW = rayProgress + cameraPosition; + density = cloudVol(progressW); + + float dist = length(rayProgress); + float clearArea = 1.0 - min(max(1.0 - dist / 24.0,0.0),1.0); + + float plumeDensity = min(density * pow(min(max(100.0-progressW.y,0.0)/30.0,1.0),4.0), pow(clamp(1.0 - dist/far,0.0,1.0),5.0)); + plumeDensity *= NETHER_PLUME_DENSITY; + + float ceilingSmokeDensity = 0.001 * pow(min(max(progressW.y-40.0,0.0)/50.0,1.0),3.0); + ceilingSmokeDensity *= NETHER_CEILING_SMOKE_DENSITY; + + density = plumeDensity + ceilingSmokeDensity; + #elif defined END_SHADER + float volumeDensity = fogShape(rayProgress + cameraPosition); + float clearArea = 1.0-min(max(1.0 - length(rayProgress) / 100,0.0),1.0); + density = min(volumeDensity, clearArea*clearArea * END_STORM_DENSTIY); + #endif + + density = max(density/1000.0, _minimumDensity); + + // density = 0.0001; + + float volumeCoeff = exp(-dd*density*LPVRayLength); + + #if defined IS_LPV_ENABLED && defined LPV_VL_FOG_ILLUMINATION + vec3 lpvPos = GetLpvPosition(rayProgress); + + vec3 cubicRadius = clamp(min(((LpvSize3-1.0) - lpvPos)/fadeLength, lpvPos/fadeLength), 0.0, 1.0); + float LpvFadeF = cubicRadius.x*cubicRadius.y*cubicRadius.z; + + if(LpvFadeF < 0.01) break; + + vec3 sampleColor = SampleLpvLinear(lpvPos).rgb; + #ifdef VANILLA_LIGHTMAP_MASK + vec3 lighting = sampleColor * LPV_VL_FOG_ILLUMINATION_BRIGHTNESS * 25. * exp(-10 * (1.0-luma(sampleColor))); + #else + vec3 lighting = sampleColor * LPV_VL_FOG_ILLUMINATION_BRIGHTNESS * 25. * exp(-5 * (1.0-luma(sampleColor))); + #endif + + if(eyeInWater) lighting *= 2.5; + + #ifdef LPV_VL_FOG_ILLUMINATION_HANDHELD + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId, rayProgress, lightRange); + + vec3 handLightCol2 = GetHandLight(heldItemId2, rayProgress, lightRange); + + lighting += (handLightCol + handLightCol2) * TORCH_AMOUNT * LPV_VL_FOG_ILLUMINATION_BRIGHTNESS * 0.04; + #endif + + color.rgb += (lighting - lighting * volumeCoeff) * color.a; + #endif + + #if defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION + // vec3 shiftedViewPos = mat3(gbufferModelView)*(progressW-cameraPosition) + vec3(-0.25, 0.2, 0.0); + // vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos; + vec3 shiftedViewPos; + vec3 shiftedPlayerPos; + float forwardOffset; + + #ifdef VIVECRAFT + if (vivecraftIsVR) { + forwardOffset = 0.0; + shiftedPlayerPos = (rayProgress) + ( vivecraftRelativeMainHandPos); + shiftedViewPos = shiftedPlayerPos * mat3(vivecraftRelativeMainHandRot); + } else + #endif + { + forwardOffset = 0.5; + shiftedViewPos = mat3(gbufferModelView)*(rayProgress) + vec3(-0.25, 0.2, 0.0); + shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos; + } + + vec2 scaledViewPos = shiftedViewPos.xy / max(-shiftedViewPos.z - forwardOffset, 1e-7); + float linearDistance = length(shiftedPlayerPos); + float shiftedLinearDistance = length(scaledViewPos); + + float lightFalloff = 1.0 - clamp(1.0-linearDistance/FLASHLIGHT_RANGE, -0.999,1.0); + lightFalloff = max(exp(-10.0 * FLASHLIGHT_BRIGHTNESS_FALLOFF_MULT * lightFalloff),0.0); + float projectedCircle = clamp(1.0 - shiftedLinearDistance*FLASHLIGHT_SIZE,0.0,1.0); + + vec3 flashlightGlow = 25.0 * vec3(FLASHLIGHT_R,FLASHLIGHT_G,FLASHLIGHT_B) * lightFalloff * projectedCircle * FLASHLIGHT_BRIGHTNESS_MULT; + + color.rgb += (flashlightGlow - flashlightGlow * volumeCoeff) * color.a; + #endif + + color.a *= volumeCoeff; + } + return color; +} + +float invLinZ (float lindepth){ + return -((2.0*near/lindepth)-far-near)/(far-near); +} + +/* +from https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence/ +Copyright 2019 Alan Wolfe + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +float interleaved_gradientNoise_temporal(){ + vec2 coord = gl_FragCoord.xy + 5.588238 * float(frameCounter%64); + float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)) ; + return noise; +} +float interleaved_gradientNoise(){ + vec2 coord = gl_FragCoord.xy; + float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); + return noise; +} + +float blueNoise(){ + return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter ); +} + +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 ) ; +} + +uniform float waterEnteredAltitude; +float lightSourceCheck = float(sunElevation > 1e-5)*2.0 - 1.0; + +uniform vec3 fogColor; + + +float waterPhase(float VdotL) { + // from https://www.desmos.com/calculator/tbl4g5bvlc + + const float ge = 100.0; + const float gHG = -0.27; + const float gHG2 = gHG*gHG; + const float wk = 0.797; + + float fKN = ge / (2.0 * PI * (ge * (1.0 - VdotL) + 1.0) * log(2.0 * ge + 1.0)); + float fCS = (3.0 * (1.0 - gHG2)) / (8.0 * PI * (2.0 + gHG2)) * ((1.0 + VdotL * VdotL) / pow(1.0 + gHG2 - 2.0 * gHG * VdotL, 1.5)); + + + return fKN * wk + fCS * (1.0 - wk); +} + +float waterPhase2(in float x) + { + const float g = 0.7; + const float a = 0.9; + float gg = g * g; + return ((1 - gg)*(1 + a*x*x))/(4.*(1 + (a*(1 + 2*gg))/3.) * 3.1415926 * pow(1 + gg - 2*g*x,1.5)); + } + +vec4 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL, vec3 LPV){ + const int spCount = 8; + + vec3 start = toShadowSpaceProjected(rayStart); + vec3 end = toShadowSpaceProjected(rayEnd); + vec3 dV = (end-start); + + //limit ray length at 32 blocks for performance and reducing integration error + //you can't see above this anyway + float maxZ = min(rayLength,32.0)/(1e-8+rayLength); + + dV *= maxZ; + rayLength *= maxZ; + + vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; + + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); + + #ifdef OVERWORLD_SHADER + float phase = fogPhase(VdotL) * 5.0; + #else + const float phase = 0.0; + #endif + + float thing = -normalize(dVWorld).y; + thing = clamp(thing + 0.333,0.0,1.0); + thing = pow(1.0-pow(1.0-thing,2.0),2.0); + thing *= 15.0; + + const float expFactor = 11.0; + for (int i=0;i pos.z && sh.x < 1.0){ + vec4 translucentShadow = texture(shadowcolor0, pos.xy); + if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001); + } + #else + sh = vec3(texture(shadowtex0HW, pos).x); + #endif + } + + sh *= GetCloudShadow(progressW, WsunVec * lightSourceCheck); + + #endif + + float bubble = exp2(-10.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0)); + float caustics = max(max(waterCaustics(progressW, WsunVec, -(progressW.y - waterEnteredAltitude)), phase*0.5) * mix(0.5, 1.5, bubble), phase); + + vec3 sunAbsorbance = exp(-waterCoefs * (distanceFromWaterSurface/abs(WsunVec.y))); + vec3 WaterAbsorbance = exp(-waterCoefs * (distanceFromWaterSurface + thing)); + + vec3 Directlight = lightSource * sh * phase * caustics * sunAbsorbance; + + vec3 _ambient = ambient; + + // #ifdef BIOME_TINT_WATER + // _ambient *= sqrt(fogColor); + // Directlight *= pow(fogColor, vec3(0.01,0.01,3.75)); + // #endif + + #ifdef OVERWORLD_SHADER + float horizontalDist = length((progressP.xz) - lightningBoltPosition.xz); + if (horizontalDist < 250.0 && lightningBoltPosition.w > 0.0) { + float lightningIntensity = exp(-horizontalDist * 0.02) * lightningFlash; + _ambient = mix(_ambient, vec3(1.3,1.5,3.0) * sh, lightningIntensity); + } + #endif + + vec3 Indirectlight = _ambient * WaterAbsorbance; + + #if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED && defined LPV_VL_FOG_ILLUMINATION_HANDHELD_WATER + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId, progressP, lightRange); + + vec3 handLightCol2 = GetHandLight(heldItemId2, progressP, lightRange); + + Indirectlight += (handLightCol + handLightCol2) * TORCH_AMOUNT * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS / 100.0) * 0.2 * exp(-waterCoefs * (length(progressP) + 0.05 * thing)); + #endif + + + vec3 light = (Indirectlight + Directlight + LPV) * scatterCoef; + + vec3 volumeCoeff = exp(-waterCoefs * length(dd*dVWorld)); + vL += (light - light * volumeCoeff) / waterCoefs * absorbance; + absorbance *= volumeCoeff; + + } + + return vec4(vL, dot(absorbance,vec3(0.333333))); +} + +vec4 blueNoise(vec2 coord){ + return texelFetch(colortex6, ivec2(coord)%512 , 0) ; +} +vec2 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n); +} + +float fogPhase2(float lightPoint){ + float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0); + float linear2 = 1.0 - clamp(lightPoint,0.0,1.0); + + float exponential = exp2(pow(linear,0.3) * -15.0 ) * 1.5; + exponential += sqrt(exp2(sqrt(linear) * -12.5)); + + return exponential; +} +//encoding by jodie +float encodeVec2(vec2 a){ + const vec2 constant1 = vec2( 1., 256.) / 65535.; + vec2 temp = floor( a * 255. ); + return temp.x*constant1.x+temp.y*constant1.y; +} + + + +uniform int framemod8; +#include "/lib/TAA_jitter.glsl" + +float convertHandDepth(float depth) { + float ndcDepth = depth * 2.0 - 1.0; + ndcDepth /= MC_HAND_DEPTH; + return ndcDepth * 0.5 + 0.5; +} + +float swapperlinZ(float depth, float _near, float _far) { + return (2.0 * _near) / (_far + _near - depth * (_far - _near)); + // l = (2*n)/(f+n-d(f-n)) + // f+n-d(f-n) = 2n/l + // -d(f-n) = ((2n/l)-f-n) + // d = -((2n/l)-f-n)/(f-n) + +} + + +vec3 alterCoords(in vec3 coords, bool lighting){ + + float theDistance = length(coords + (lighting ? vec3(0.0) : cameraPosition)); + + coords.x = coords.x*3; + + coords.y = coords.y; + + coords.z = coords.z*3; + + return coords; +} + +uniform float viewHeight; +uniform float viewWidth; +float godrayTest( in vec3 viewPos, in vec3 lightDir, float noise, float vanilladepth){ + + // return 1.0;1 + + float godrays = 0.0; + float samples = 8.0; + + float _near = near; float _far = far*4.0; + + // #ifdef DISTANT_HORIZONS + // bool depthCheck = true; + // #else + // bool depthCheck = false; + // #endif + + bool depthCheck = true; + + if (depthCheck) { + _near = dhVoxyNearPlane; + _far = dhVoxyFarPlane; + } + + float lightRange = pow(clamp(-dot(normalize(viewPos), lightDir)+0.65,0.0,1.0),2.0); + vec3 position = toClipSpace3_DH(viewPos, depthCheck) ; + + //prevents the ray from going behind the camera + float rayLength = ((viewPos.z + lightDir.z * _far * sqrt(3.)) > -_near) ? (-_near - viewPos.z) / lightDir.z : _far * sqrt(3.); + + vec3 direction = toClipSpace3_DH(viewPos + lightDir*rayLength, depthCheck) - position; + + direction.xyz = direction.xyz / max(max(abs(direction.x)/0.0005, abs(direction.y)/0.0005),500.0); //fixed step size + direction *= 60.0; + + position.xy *= RENDER_SCALE; + direction.xy *= RENDER_SCALE; + + vec3 newPos = position + direction*noise; + + vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); + + for (int i = 0; i < int(samples); i++) { + newPos.xy = clamp(newPos.xy, screenEdges, 1.0-screenEdges); + + float sampleDepth = invLinZ(sqrt(texelFetch(colortex4, ivec2(newPos.xy/texelSize/4.0),0).a/65000.0)); + + #ifdef DISTANT_HORIZONS + if(depthCheck) sampleDepth = texelFetch(dhDepthTex1, ivec2(newPos.xy/texelSize),0).x; + #endif + + godrays += (swapperlinZ(sampleDepth, _near, _far) > 1.0 ? 1.0 : lightRange); + newPos += direction; + } + + return godrays/samples; +} + +vec4 waterVolumetrics_alt( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ + int spCount = rayMarchSampleCount; + + vec3 start = toShadowSpaceProjected(rayStart); + vec3 end = toShadowSpaceProjected(rayEnd); + vec3 dV = (end-start); + + //limit ray length at 32 blocks for performance and reducing integration error + //you can't see above this anyway + float maxZ = min(rayLength,12.0)/(1e-8+rayLength); + dV *= maxZ; + rayLength *= maxZ; + estEndDepth *= maxZ; + estSunDepth *= maxZ; + + vec3 dVWorld = mat3(gbufferModelViewInverse) * rayStart; + vec3 wpos = dVWorld + gbufferModelViewInverse[3].xyz; + + #ifdef OVERWORLD_SHADER + float phase = fogPhase(VdotL) * 5.0; + #else + const float phase = 1.0; + #endif + + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); + + float expFactor = 11.0; + vec3 sh = vec3(1.0); + + // do this outside raymarch loop, masking the water surface is good enough + #if defined OVERWORLD_SHADER + sh *= GetCloudShadow(wpos+cameraPosition, WsunVec); + #endif + + float thing = -normalize(dVWorld).y; + thing = clamp(thing - 0.333,0.0,1.0); + thing = pow(1.0-pow(1.0-thing,2.0),2.0); + thing *= 15.0; + + for (int i=0;i pos.z && sh2.x < 1.0){ + vec4 translucentShadow = texture(shadowcolor0, pos.xy); + if(translucentShadow.a < 0.9) sh2 = normalize(translucentShadow.rgb+0.0001); + } + #else + sh2 *= vec3(texture(shadowtex0HW, pos).x); + #endif + } + #endif + + vec3 sunAbsorbance = exp(-waterCoefs * estSunDepth * d); + vec3 ambientAbsorbance = exp(-waterCoefs * (estEndDepth * d + thing)); + + vec3 Directlight = lightSource * sh2 * phase * sunAbsorbance; + + vec3 _ambient = ambient; + + #ifdef OVERWORLD_SHADER + float horizontalDist = length(progressP.xz - lightningBoltPosition.xz); + if (horizontalDist < 250.0 && lightningBoltPosition.w > 0.0) { + float lightningIntensity = exp(-horizontalDist * 0.02) * lightningFlash; + _ambient = mix(_ambient, vec3(1.3,1.5,3.0) * sh2, lightningIntensity); + } + #endif + + #if defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED && defined LPV_VL_FOG_ILLUMINATION_HANDHELD_WATER + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId, progressP, lightRange); + + vec3 handLightCol2 = GetHandLight(heldItemId2, progressP, lightRange); + + _ambient += (handLightCol + handLightCol2) * TORCH_AMOUNT * 0.225 * (LPV_VL_FOG_ILLUMINATION_BRIGHTNESS / 100.0); + #endif + + vec3 Indirectlight = _ambient * ambientAbsorbance; + + vec3 light = (Indirectlight + Directlight) * scatterCoef; + + vec3 volumeCoeff = exp(-waterCoefs * dd * rayLength); + vL += (light - light * volumeCoeff) / waterCoefs * absorbance; + absorbance *= volumeCoeff; + } + + return vec4(vL, dot(absorbance,vec3(0.333333))); +} + vec2 decodeVec2(float a){ const vec2 constant1 = 65535. / vec2( 256., 65536.); const float constant2 = 256. / 255.; return fract( a * constant1 ) * constant2 ; } -vec3 decode (vec2 encn){ - vec3 n = vec3(0.0); - encn = encn * 2.0 - 1.0; - n.xy = abs(encn); - n.z = 1.0 - n.x - n.y; - n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn; - return clamp(normalize(n.xyz),-1.0,1.0); -} -vec3 worldToView(vec3 worldPos) { - vec4 pos = vec4(worldPos, 0.0); - pos = gbufferModelView * pos; - return pos.xyz; -} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// -vec3 viewToWorld(vec3 viewPosition) { - vec4 pos; - pos.xyz = viewPosition; - pos.w = 0.0; - pos = gbufferModelViewInverse * pos; - return pos.xyz; -} - -vec2 clampUV(in vec2 uv, vec2 texcoord){ - // return uv; - - // get the gradient when a refracted axis and non refracted axis go above 1.0 or below 0.0 - // use this gradient to lerp between refracted and non refracted uv - // the goal of this is to stretch the uv back to normal when the refracted image exposes off screen uv - // emphasis on *stretch*, as i want the transition to remain looking like refraction, not a sharp cut. - - float vignette = max(uv.x * texcoord.x, 0.0); - vignette = max(uv.y * texcoord.y, vignette); - vignette = max((uv.x-1.0) * (texcoord.x-1.0), vignette); - vignette = max((uv.y-1.0) * (texcoord.y-1.0), vignette); - vignette *= vignette*vignette*vignette*vignette; - - return clamp(mix(uv, texcoord, vignette),0.0,0.9999999); -} - -vec3 doRefractionEffect( inout vec2 passTexcoord, vec2 normal, float linearDistance, bool isReflectiveEntity, bool underwater){ - // correct normal directions to match texcoord directions (right facing X, up facing Y) - normal.y = -normal.y; - vec2 texcoord = passTexcoord; - - vec3 color = vec3(0.0); - - float refractAmount = float(FAKE_REFRACTION_AMOUNT)/4.0; - float dispersionAmount = float(FAKE_DISPERSION_AMOUNT)/4.0; - float smudgeAmount = float(REFRACTION_SMUDGE_AMOUNT)/4.0; - - refractAmount *= 0.5 / (1.0 + pow(linearDistance,0.8) * (underwater ? 0.1 : 1.0)); - if(isReflectiveEntity) refractAmount *= 0.5; - - dispersionAmount *= 0.035; - smudgeAmount *= 0.035; - - vec2 dispersion = (clamp(normal, -0.2, 0.2) / 0.2); - - #if REFRACTION_SMUDGE_AMOUNT > 0 - vec2 smudge = smudgeAmount * dispersion * (blueNoise()-0.5); - #else - vec2 smudge = vec2(0.0, 0.0); - #endif - - dispersion *= dispersionAmount; - - #if FAKE_DISPERSION_AMOUNT > 0 - // do not offset texcoord if alpha is 1.0 - refractAmount *= min( decodeVec2(texelFetch(colortex11, ivec2(clampUV(texcoord - ((normal + dispersion) + smudge)*refractAmount, texcoord)/texelSize),0).b).g, - decodeVec2(texelFetch(colortex11, ivec2(clampUV(texcoord - ((normal - dispersion) + smudge)*refractAmount, texcoord)/texelSize),0).b).g ) > 0.0 ? 1.0 : 0.0; - - // create offsets - vec2 offsetTexcoord = clampUV(texcoord - (normal + smudge)*refractAmount, texcoord); - passTexcoord = offsetTexcoord; - - // sample color with offsetted texcoord. in this case, the red and blue channels have offsets in opposite directions for a dispersion effect. - color.g = texture(colortex3, offsetTexcoord).g; - - offsetTexcoord = clampUV(texcoord - ((normal + dispersion) + smudge)*refractAmount, texcoord); - color.r = texture(colortex3, offsetTexcoord).r; - - offsetTexcoord = clampUV(texcoord - ((normal - dispersion) + smudge)*refractAmount, texcoord); - color.b = texture(colortex3, offsetTexcoord).b; - #else - // do not offset texcoord if alpha is 1.0 - refractAmount *= decodeVec2(texelFetch(colortex11, ivec2(clampUV(texcoord - (normal + smudge)*refractAmount, texcoord)/texelSize),0).b).g > 0.0 ? 1.0 : 0.0; - - // create offsets - vec2 offsetTexcoord = clampUV(texcoord - (normal + smudge)*refractAmount, texcoord); - passTexcoord = offsetTexcoord; - - // sample color with distorted texcoords - color.rgb = texture(colortex3, offsetTexcoord).rgb; - #endif - - return color; -} - -vec3 toClipSpace3Prev(vec3 viewSpacePosition) { - return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; -} - -vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) { - - #if defined DISTANT_HORIZONS || defined VOXY - mat4 projectionMatrix = depthCheck ? dhVoxyProjectionPrev : gbufferPreviousProjection; - return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; - #else - return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; - #endif -} - -vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeResults, float referenceDepth, sampler2D depth, bool hand, const int behindTranslucents){ - - vec4 colorSum = vec4(0.0); - float edgeSum = 0.0; - #if defined DISTANT_HORIZONS || defined VOXY - const float threshold = 0.05; - #else - const float threshold = 0.005; - #endif - - #ifdef HQ_CLOUD_UPSAMPLE - const int samples = 9; - #else - const int samples = 5; - #endif - - vec2 coord = fragcoord - 1.5; - - vec2 UV = coord; - const ivec2 SCALE = ivec2(1.0/VL_RENDER_SCALE); - ivec2 UV_DEPTH = ivec2(UV*VL_RENDER_SCALE)*SCALE; - ivec2 UV_COLOR = ivec2(UV*VL_RENDER_SCALE); - ivec2 UV_NOISE = ivec2(gl_FragCoord.xy*texelSize + 1); - - const ivec2 OFFSET[9] = ivec2[9]( - ivec2(-1,-1), - ivec2( 1, 1), - ivec2(-1, 1), - ivec2( 1,-1), - ivec2( 0, 0), - ivec2( 0, 1), - ivec2( 0,-1), - ivec2( 1, 0), - ivec2(-1, 0) - ); - - for(int i = 0; i < samples; i++) { - - #if defined DISTANT_HORIZONS || defined VOXY - float offsetDepth = sqrt(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE,0)[behindTranslucents]); - #else - float offsetDepth = linearize(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE, 0).r); - #endif - - float edgeDiff = abs(offsetDepth - referenceDepth) < threshold ? 1.0 : 1e-7; - outerEdgeResults = max(outerEdgeResults, abs(referenceDepth - offsetDepth)); - - vec4 offsetColor = texelFetch(colortex, UV_COLOR + OFFSET[i] + UV_NOISE, 0); - colorSum += offsetColor*edgeDiff; - edgeSum += edgeDiff; - - } - - outerEdgeResults = outerEdgeResults > (hand ? 0.005 : referenceDepth*0.05 + 0.1) ? 1.0 : 0.0; - - return colorSum / edgeSum; -} - -vec4 VLTemporalFiltering(vec3 playerPosIn, in float referenceDepth, sampler2D depth, bool hand){ - vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); - vec2 offsetTexcoord = clamp(gl_FragCoord.xy*texelSize, screenEdges, 1.0-screenEdges); - vec2 VLtexCoord = offsetTexcoord * VL_RENDER_SCALE; - - // get previous frames position stuff for UV - vec3 playerPos = playerPosIn + (cameraPosition - previousCameraPosition); - vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; - previousPosition = toClipSpace3Prev(previousPosition); - - vec2 velocity = previousPosition.xy - offsetTexcoord; - previousPosition.xy = offsetTexcoord + velocity; - - vec4 currentFrame = texture(colortex0, VLtexCoord); - - // return vec4(outerEdgeResults,0,0,1); - // return upsampledCurrentFrame; - - if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame; - - // to fill pixel gaps in geometry edges, do a bilateral upsample. - // pass a mask to only show upsampled color around the edges of blocks. this is so it doesnt blur reprojected results. - float outerEdgeResults = 0.0; - vec4 upsampledCurrentFrame = bilateralUpsample(gl_FragCoord.xy , colortex0, outerEdgeResults, referenceDepth, depth, hand, 2); - // vec4 upsampledCurrentFrame = BilateralUpscale(colortex0, depth, gl_FragCoord.xy - 1.5, referenceDepth); - - vec4 col1 = texture(colortex0, VLtexCoord + vec2( texelSize.x, texelSize.y)); - vec4 col2 = texture(colortex0, VLtexCoord + vec2( texelSize.x, -texelSize.y)); - vec4 col3 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, -texelSize.y)); - vec4 col4 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, texelSize.y)); - vec4 col5 = texture(colortex0, VLtexCoord + vec2( 0.0, texelSize.y)); - vec4 col6 = texture(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y)); - vec4 col7 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0)); - vec4 col8 = texture(colortex0, VLtexCoord + vec2( texelSize.x, 0.0)); - - vec4 colMax = max(currentFrame,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); - vec4 colMin = min(currentFrame,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); - - vec4 frameHistory = texture(colortex10, previousPosition.xy*RENDER_SCALE); - vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax); - - float blendingFactor = 0.1; - - // variance - if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0; - - vec4 reprojectFrame = mix(clampedFrameHistory, currentFrame, blendingFactor); - - // return clamp(reprojectFrame,0.0,65000.0); - return clamp(mix(reprojectFrame, upsampledCurrentFrame, outerEdgeResults),0.0,65000.0); - -} - -uniform float waterEnteredAltitude; - -void blendAllFogTypes( inout vec3 color, inout float bloomyFogMult, vec4 volumetrics, float linearDistance, vec3 playerPos, vec3 cameraPosition, bool isSky, bool isLightning){ - - // blend cave fog - #if defined OVERWORLD_SHADER && defined CAVE_FOG - if (isEyeInWater == 0 && eyeAltitude < 1500){ - vec3 cavefogCol = vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B) * 0.3; - cavefogCol *= 1.0-pow(1.0-pow(1.0 - max(1.0 - linearDistance/far,0),2),CaveFogFallOff); - cavefogCol *= exp(-7.0*clamp(playerPos.y*0.5+0.5,0,1)) * 0.999 + 0.001; - - float skyhole = pow(clamp(1.0-pow(max(playerPos.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2); - - #if CAVE_DETECTION < 2 - #if CAVE_DETECTION == 1 - float caveFactor = 1.0 - smoothstep(60.0, 63.0, cameraPosition.y); - #else - const float caveFactor = 1.0; - #endif - #else - const float caveFactor = 0.0; - #endif - - color.rgb = mix(color.rgb + cavefogCol * caveDetection, cavefogCol, isSky ? skyhole * caveDetection * caveFactor: 0.0); - } - #endif - - /// water absorption; it is completed when volumetrics are blended. - if(isEyeInWater == 1){ - vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); - vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; - - float distanceFromWaterSurface = playerPos.y + 1.0 + (cameraPosition.y - waterEnteredAltitude)/waterEnteredAltitude; - distanceFromWaterSurface = clamp(distanceFromWaterSurface,0,1); - - vec3 transmittance = exp(-totEpsilon * linearDistance); - color.rgb *= transmittance; - - vec3 transmittance2 = exp(-totEpsilon * 50.0); - float fogfade = 1.0 - max((1.0 - linearDistance / min(far, 16.0*7.0) ),0); - color.rgb += (transmittance2 * scatterCoef) * fogfade; - - bloomyFogMult *= dot(transmittance,vec3(0.3333))*0.75 + 0.25; - } - - /// blend volumetrics - if(!isLightning) color = color * volumetrics.a; - color += volumetrics.rgb; - - // make bloomy fog only work outside of the overworld (unless underwater) - #if !defined OVERWORLD_SHADER - bloomyFogMult = min(bloomyFogMult, volumetrics.a); - #endif - - // blend vanilla fogs (blindness, darkness, lava, powdered snow) - if(isEyeInWater > 1 || blindness > 0 || darknessFactor > 0){ - float enviornmentFogDensity = 1.0 - clamp(linearDistance/fogEnd,0,1); - enviornmentFogDensity = 1.0 - enviornmentFogDensity*enviornmentFogDensity; - enviornmentFogDensity *= enviornmentFogDensity; - enviornmentFogDensity = mix(enviornmentFogDensity, 1.0, min(darknessLightFactor*2.0,1)); - - color = mix(color, toLinear(fogColor), enviornmentFogDensity); - } -} - -void blendForwardRendering( inout vec3 color, vec4 translucentShader ){ - // REMEMBER that forward rendered color is written as color.rgb/10.0, invert it. - if(translucentShader.a > 0) { - color = color * (1.0 - translucentShader.a) + translucentShader.rgb * 10.0; - } -} - -float getBorderFogDensity(float linearDistance, vec3 playerPos, bool sky){ - - if(sky) return 0.0; - - #if defined DISTANT_HORIZONS || defined VOXY - float borderFogDensity = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance / dhVoxyRenderDistance,0.0)*3.0/BorderFogIntensity,1.0) ); - #else - float borderFogDensity = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance / far,0.0)*3.0/BorderFogIntensity,1.0) ); - #endif - - borderFogDensity *= exp(-10.0 * pow(clamp(playerPos.y,0.0,1.0)*4.0,2.0)); - borderFogDensity *= (1.0-caveDetection); - - return borderFogDensity; -} - -#if AURORA_LOCATION > 0 - uniform float auroraAmount; - #include "/lib/aurora.glsl" -#endif void main() { - /* RENDERTARGETS:7,3,10 */ - ////// --------------- SETUP STUFF --------------- ////// - vec2 texcoord = gl_FragCoord.xy*texelSize; - float depth = texelFetch(depthtex0, ivec2(gl_FragCoord.xy),0).x; - bool hand = depth < 0.56; - float z = depth; + /* RENDERTARGETS:0,13 */ - float frDepth = linearize(z); + gl_FragData[1] = vec4(0.0,0.0,0.0, 1.0); + + float noise_1 = interleaved_gradientNoise_temporal(); + // float noise_2 = blueNoise(); + // float noise_2 = interleaved_gradientNoise_temporal(); + vec2 bnoise = blueNoise(gl_FragCoord.xy ).rg; + + int seed = frameCounter%40000; + vec2 r2_sequence = R2_samples(seed).xy*5.0; + vec2 BN = fract(r2_sequence + bnoise); + + vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_SCALE*texelSize + texelSize*0.5; + // vec2 tc = (gl_FragCoord.xy - 0.5)/VL_RENDER_SCALE*texelSize; + + // bool iswater = texture(colortex7,tc).a > 0.99; + + ivec2 texcoord = ivec2(tc/texelSize); + + float alpha = texelFetch(colortex7,texcoord,0).a ; + float blendedAlpha = texelFetch(colortex2, texcoord,0).a; + + bool iswater = alpha > 0.99; + + float z0 = texelFetch(depthtex0, texcoord,0).x; + + // z0 = depth < 0.56 ? convertHandDepth(depth) : depth; #if defined DISTANT_HORIZONS || defined VOXY - float DH_depth0 = 0.0; - bool isDHrange = z >= 1.0; - if(isDHrange) DH_depth0 = texelFetch(dhVoxyDepthTex, ivec2(gl_FragCoord.xy),0).x; - - bool isSky = DH_depth0 >= 1.0; + float DH_z0 = 0.0; + + if (z0 >= 1.0) DH_z0 = texelFetch(dhVoxyDepthTex, texcoord,0).x; #else - bool isSky = z >= 1.0; - float DH_depth0 = 1.0; + float DH_z0 = 0.0; #endif - - #if !defined DISTANT_HORIZONS && !defined VOXY || (AURORA_LOCATION > 0 && defined OVERWORLD_SHADER) - float z2 = texelFetch(depthtex1, ivec2(gl_FragCoord.xy),0).x; - #endif - - #if AURORA_LOCATION > 0 && defined OVERWORLD_SHADER - #if defined DISTANT_HORIZONS || defined VOXY - float DH_depth1 = texelFetch(dhVoxyDepthTex, ivec2(gl_FragCoord.xy),0).x; - bool isSkyTranslucent = z2 >= 1.0 && DH_depth1 >= 1.0; - #else - bool isSkyTranslucent = z2 >= 1.0; - #endif - #endif - - vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth0); - vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz; - - float linearDistance = length(playerPos); - float linearDistance_cylinder = length(playerPos.xz); + + vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0); + vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos0 + gbufferModelViewInverse[3].xyz; vec3 playerPos_normalized = normalize(playerPos); - #if !defined DISTANT_HORIZONS && !defined VOXY - vec3 viewPos_alt = toScreenSpace(vec3(texcoord/RENDER_SCALE, z2)); - vec3 playerPos_alt = mat3(gbufferModelViewInverse) * viewPos_alt + gbufferModelViewInverse[3].xyz; - float linearDistance_cylinder_alt = length(playerPos_alt.xz); - #endif + // vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); + // vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B); + vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); + vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; - // float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2.) ,0.0,1.0); - // float lightleakfixfast = clamp(eyeBrightness.y/240.,0.0,1.0); + vec3 directLightColor = lightSourceColorSSBO / 2400.0; - ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// - // float opaqueMasks = decodeVec2(texture(colortex1,texcoord).a).y; - // bool isOpaque_entity = abs(opaqueMasks-0.45) < 0.01; + vec3 directSunlightColor = sunColorSSBO / 2400.0; + #ifdef CUSTOM_MOON_ROTATION + directSunlightColor *= smoothstep(0.005, 0.09, length(WmoonVec - WrealSunVec)); + #endif - ////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- ////// - vec4 data = texelFetch(colortex11,ivec2(texcoord/texelSize),0).rgba; - vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)); - vec2 unpack1 = decodeVec2(data.b); + vec3 directMoonlightColor = moonColorSSBO / 2400.0; + #ifdef CUSTOM_MOON_ROTATION + directMoonlightColor *= mix(0.0, 1.0, clamp(WmoonVec.y + 0.05, 0.0, 0.1)/0.1); + #endif + + vec3 indirectLightColor = skyGroundColSSBO / 1200.0; + vec3 indirectLightColor_dynamic = averageSkyCol_CloudsSSBO / 1200.0; + + // #if defined DISTANT_HORIZONS || defined VOXY + // float godrays = godrayTest(viewPos0, normalize(WsunVec*mat3(gbufferModelViewInverse)),BN.x, z0); + // #else + // float godrays = 1.0; + // #endif + + #if (defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED) || (defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION) + vec4 LPV_ILLUMINATION = raymarchLPV(viewPos0, BN.y); + #else + vec4 LPV_ILLUMINATION = vec4(0.0,0.0,0.0,1.0); + #endif + + vec3 indirectLight = indirectLightColor_dynamic * skyLightLevelSmooth * ambient_brightness; + float minimumLightAmount = 0.02*nightVision + 0.001 * mix(MIN_LIGHT_AMOUNT_INSIDE, MIN_LIGHT_AMOUNT, clamp(skyLightLevelSmooth, 0.0, 1.0)); + indirectLight += vec3(1.0) * minimumLightAmount; - vec4 albedo = vec4(unpack0.ba,unpack1); - vec2 tangentNormals = unpack0.xy*2.0-1.0; - - bool nameTagMask = abs(data.a - 0.1) < 0.01; - float nametagbackground = nameTagMask ? 0.25 : 1.0; + vec3 indirectLight_fog = indirectLightColor * ambient_brightness; + indirectLight_fog += vec3(1.0) * (0.02*nightVision + 0.001 * mix(MIN_LIGHT_AMOUNT_INSIDE, MIN_LIGHT_AMOUNT, skyLightLevelSmooth)); - if(albedo.a < 0.01) tangentNormals = vec2(0.0); - ////// --------------- UNPACK MISC --------------- ////// - // 1.0 = water mask - // 0.9 = entity mask - // 0.8 = reflective entities - // 0.7 = reflective blocks - float translucentMasks = texelFetch(colortex7, ivec2(gl_FragCoord.xy),0).a; + float cloudPlaneDistance = 0.0; + vec2 cloudDistance = vec2(0.0); // r = cumulus, g = cumulonimbus - bool isWater = translucentMasks > 0.99; - bool isReflectiveEntity = abs(translucentMasks - 0.2) < 0.01; - bool isReflective = abs(translucentMasks - 0.1) < 0.01 || isWater || isReflectiveEntity; - bool isEntity = abs(translucentMasks - 0.4) < 0.01 || isReflectiveEntity; + vec4 VolumetricFog; + #ifdef OVERWORLD_SHADER + vec4 VolumetricClouds; + #endif + + if (eyeInWater){ + vec4 underWaterFog = waterVolumetrics(vec3(0.0), viewPos0, length(viewPos0), vec2(noise_1, BN.y), totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor, dot(normalize(viewPos0), normalize(sunVec * lightSourceCheck)), LPV_ILLUMINATION.rgb); + VolumetricFog = vec4(underWaterFog.rgb, 1.0); + } else { + #ifdef OVERWORLD_SHADER + VolumetricClouds = GetVolumetricClouds(viewPos0, BN, WrealSunVec, WmoonVec, directSunlightColor, directMoonlightColor, indirectLightColor, cloudPlaneDistance, cloudDistance); + + #if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 + imageStore(cloudDepthTex, ivec2(gl_FragCoord.xy), vec4(cloudDistance.r, cloudDistance.g, 0, 1)); + #endif - ////// --------------- get volumetrics - #if defined DISTANT_HORIZONS || defined VOXY - float DH_mixedLinearZ = sqrt(texelFetch(colortex9,ivec2(gl_FragCoord.xy),0).z); - vec4 temporallyFilteredVL = VLTemporalFiltering(playerPos, DH_mixedLinearZ, colortex9, hand); - #else - vec4 temporallyFilteredVL = VLTemporalFiltering(playerPos, frDepth, depthtex0, hand); - #endif + #ifdef CAVE_FOG + #if CAVE_DETECTION < 2 + #if CAVE_DETECTION == 1 + float caveFactor = 1.0 - smoothstep(60.0, 63.0, cameraPosition.y); + #else + const float caveFactor = 1.0; + #endif + #else + const float caveFactor = 0.0; + #endif - gl_FragData[2] = temporallyFilteredVL; - float bloomyFogMult = 1.0; + float skyhole = pow(clamp(1.0-pow(max(playerPos_normalized.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2)* caveDetection * caveFactor; + VolumetricClouds.rgb *= 1.0-skyhole; + VolumetricClouds.a = mix(VolumetricClouds.a, 1.0, skyhole); + #endif - ////// --------------- MAIN COLOR BUFFER - ////// --------------- distort texcoords as a refraction effect - vec2 refractedCoord = texcoord; - #if FAKE_REFRACTION_AMOUNT > 0 - vec3 color; - #if defined DISTANT_HORIZONS || defined VOXY + VolumetricFog = GetVolumetricFog(viewPos0, WsunVec, BN, directLightColor, indirectLight_fog, indirectLightColor_dynamic, cloudPlaneDistance); - bool isLOD = abs(data.a - 0.5) < 0.01; - if(isDHrange || hand || isLOD) { - color = texture(colortex3, texcoord).rgb; - } - else - #endif - { - color = doRefractionEffect(refractedCoord, tangentNormals.xy, linearDistance, isReflectiveEntity, isWater && isEyeInWater == 1); - } - #else - vec3 color = texture(colortex3, texcoord).rgb; - #endif + #if (defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED) || (defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION) + VolumetricFog.a *= LPV_ILLUMINATION.a; + VolumetricFog.rgb = VolumetricFog.rgb * LPV_ILLUMINATION.a + LPV_ILLUMINATION.rgb; + #endif - ////// --------------- lightning effect + // for bloomy fog mask + gl_FragData[1].a = VolumetricFog.a; - bool isLightning = false; + VolumetricFog = vec4(VolumetricClouds.rgb * VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a); + #endif + + #if defined NETHER_SHADER || defined END_SHADER + VolumetricFog = GetVolumetricFog(viewPos0, noise_1, noise_1); - #if defined OVERWORLD_SHADER && defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 && defined VOLUMETRIC_CLOUDS + #if (defined LPV_VL_FOG_ILLUMINATION && defined IS_LPV_ENABLED) || (defined FLASHLIGHT && defined FLASHLIGHT_FOG_ILLUMINATION) + VolumetricFog.a *= LPV_ILLUMINATION.a; + VolumetricFog.rgb = VolumetricFog.rgb * LPV_ILLUMINATION.a + LPV_ILLUMINATION.rgb; + #endif - vec2 cloudDepth = imageLoad(cloudDepthTex, ivec2(gl_FragCoord.xy*VL_RENDER_SCALE*RENDER_SCALE)).rg; + // for bloomy fog mask + gl_FragData[1].a = VolumetricFog.a; + #endif + } - vec3 lightningpos = vec3(getLightningPosition(600, 4680)); - //lightningpos = vec3(0,0,1); + // VolumetricFog = vec4(godrays,godrays,godrays,0.0); + // VolumetricFog = raymarchTest(viewPos0, BN); + // VolumetricFog = vec4(0.0,0.0,0.0,1.0); + // VolumetricFog.rgb = vec3(0); - float lightningDist = length(lightningpos); + gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0); - if ((lightningDist < cloudDepth.r || cloudDepth.r == 0.0) && (thunderStrength > 0.0 || rainStrength == 0.0)) { - vec2 tc = (gl_FragCoord.xy - 0.5)*texelSize; - float depth = z; - - float z0 = depth < 0.56 ? convertHandDepth(depth) : depth; - float uvScalar = 3.0 * CUSTOM_LIGHTNING_SCALE; + /// FOG BEHIND TRANSLUCENTS - vec3 normLightningpos = normalize(lightningpos); - - vec3 worldDir = normalize(mat3(gbufferModelViewInverse) * toScreenSpace(vec3(texcoord /RENDER_SCALE,1.0))); + if(blendedAlpha > 0.0 || iswater){ + vec2 lightmap = decodeVec2(texelFetch(colortex14,texcoord,0).z); + lightmap = min(max(lightmap - 0.05,0.0)*1.06,1.0); - vec3 tangent = normalize(cross(normLightningpos, vec3(0.0, 1.0, 0.0))); - vec3 binormal = cross(normLightningpos, tangent); - vec3 dirDiff = worldDir - normLightningpos; + #ifndef OVERWORLD_SHADER + lightmap.y = 1.0; + #endif - float u = -1.0; - float v = -1.0; - vec4 lightningTex = vec4(0.0); - if (dot(worldDir, normLightningpos) > 0.0) { - u = dot(dirDiff, tangent) + 0.5/uvScalar; - v = 0.55*dot(dirDiff, binormal) + 0.1/uvScalar; + vec2 curvedLightmaps = lightmap; + float lightmapBrightspot = min(max(lightmap.x-0.7,0.0)*3.3333,1.0); + lightmapBrightspot *= lightmapBrightspot*lightmapBrightspot; + float lightmapLight = 1.0-sqrt(1.0-lightmap.x); + lightmapLight *= lightmapLight; + curvedLightmaps.x = mix(lightmapLight, 2.5, lightmapBrightspot); + curvedLightmaps.y = (pow(lightmap.y,15.0)*2.0 + lightmap.y*lightmap.y)/3.0; - vec2 uv = vec2(u, v) * uvScalar; + float z1 = texelFetch(depthtex1, texcoord,0).x; - float randomTex = 16.0*rand(lightningTimer*72.82723486); + #if defined DISTANT_HORIZONS || defined VOXY + float DH_z1 = 0.0; + if (z1 >= 1.0) DH_z1 = texelFetch(dhVoxyDepthTex1, texcoord,0).x; + #else + float DH_z1 = 0.0; + #endif - #if CUSTOM_LIGHTNING_TEX > 0 - randomTex = CUSTOM_LIGHTNING_TEX - 1.0; - #endif + vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z1, DH_z1); - // TODO: There has to be a better way to do this............. - if (randomTex < 1.0) { - lightningTex = texture(lightningTex1, uv); - } else if (randomTex < 2.0) { - lightningTex = texture(lightningTex2, uv); - } else if (randomTex < 3.0) { - u = 1.3*dot(dirDiff, tangent) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex3, uv); - } else if (randomTex < 4.0) { - lightningTex = texture(lightningTex4, uv); - } else if (randomTex < 5.0) { - lightningTex = texture(lightningTex5, uv); - } else if (randomTex < 6.0) { - u = 1.25*dot(dirDiff, tangent) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex6, uv); - } else if (randomTex < 7.0) { - lightningTex = texture(lightningTex7, uv); - } else if (randomTex < 8.0) { - lightningTex = texture(lightningTex8, uv); - } else if (randomTex < 9.0) { - u = 1.4*dot(dirDiff, tangent) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex9, uv); - } else if (randomTex < 10.0) { - lightningTex = texture(lightningTex10, uv); - } else if (randomTex < 11.0) { - u = 0.5*dot(dirDiff, tangent)+0.5/uvScalar; - v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex11, uv); - } else if (randomTex < 12.0) { - u = 0.45*dot(dirDiff, tangent)+0.5/uvScalar; - v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex12, uv); - } else if (randomTex < 13.0) { - u = 0.45*dot(dirDiff, tangent)+0.5/uvScalar; - v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex13, uv); - } else if (randomTex < 14.0) { - u = 0.5*dot(dirDiff, tangent)+0.5/uvScalar; - v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex14, uv); - } else if (randomTex < 15.0) { - u = 0.45*dot(dirDiff, tangent)+0.5/uvScalar; - v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex15, uv); - } else { - u = 0.4*dot(dirDiff, tangent)+0.5/uvScalar; - v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; - uv = vec2(u, v) * uvScalar; - lightningTex = texture(lightningTex16, uv); - } + indirectLight = indirectLightColor_dynamic * skyLightLevelSmooth * ambient_brightness; - lightningTex.rgb *= vec3(CUSTOM_LIGHTNING_R, CUSTOM_LIGHTNING_G, CUSTOM_LIGHTNING_B) * CUMULONIMBUS_LIGHTNING_BRIGHTNESS * 0.01; - if(cloudDepth.g > 0.0) lightningTex.rgb *= smoothstep(7000.0, 1500.0, lightningDist - cloudDepth.g); + if(iswater && !eyeInWater){ + float Vdiff = distance(viewPos1, viewPos0); + float estimatedDepth = Vdiff * abs(playerPos_normalized.y); + float estimatedSunDepth = Vdiff / abs(WsunVec.y); //assuming water plane - if(lightningTex.rgb != vec3(0.0)) { - #if defined CUSTOM_LIGHTNING_POS && CUSTOM_LIGHTNING_TEX > 0 - lightningTex.a *= pow(lightningTex.a, 2.0); + float lightleakfix = clamp(lightmap.y + (1.0-caveDetection),0.0,1.0); - lightningTex.rgb *= 75; - #else - lightningTex.a *= pow(lightningTex.a, lightningStart); // fade alpha in for cool expansion effect + directLightColor *= lightleakfix; - lightningTex.rgb += 120 * lightningMid * lightningTex.rgb; // bright flash in the middle + // #ifdef BIOME_TINT_WATER + // vec4 data = texelFetch(colortex11,texcoord,0).rgba; + // bool isBlockBreaking = data.a > 0.99; +// +// + // if(!isBlockBreaking) { + // vec4 albedo = vec4(decodeVec2(data.g),decodeVec2(data.b)); + // scatterCoef *= 0.85 + vec3(0.35,0.35,1.0)*log(albedo.rgb + 1e-6); + // } + // #endif - lightningTex.rgb *= 75 * lightningFade; // fade out - #endif - } + indirectLight *= curvedLightmaps.y; - if (length(lightningTex.rgb) == 0.0) lightningTex.a = 0.0; - } + indirectLight += mix(MIN_LIGHT_AMOUNT * 0.004 + nightVision*0.02, MIN_LIGHT_AMOUNT_INSIDE * 0.004 + nightVision*0.02, 1.0 - lightmap.y); - // bool isSky = z0 == 1.0 && DH_z0 == 1.0; - bool oneTexOnly = u > 0 && v > 0 && u*uvScalar < 1 && v*uvScalar < 1; - - if (lightningTex.a > 0.01 && oneTexOnly && isSky) { - color = lightningTex.rgb * lightningFlash; - isLightning = true; - } - } - #endif + indirectLight += vec3(TORCH_R,TORCH_G,TORCH_B) * curvedLightmaps.x * TORCH_AMOUNT * blendedAlpha; - ////// --------------- get volumetrics behind translucents - float blank = 0.0; - #if defined DISTANT_HORIZONS || defined VOXY - DH_mixedLinearZ = sqrt(texelFetch(colortex9,ivec2(gl_FragCoord.xy),0).a); - vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, DH_mixedLinearZ, colortex9, hand, 3); - #else - vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, linearize(texelFetch(depthtex1, ivec2(refractedCoord/texelSize),0).x), depthtex1, hand, 3); - #endif + VolumetricFog = waterVolumetrics_alt(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLight, directLightColor, dot(normalize(viewPos0), normalize(sunVec*lightSourceCheck))); + } else { + #if defined OVERWORLD_SHADER + VolumetricClouds = GetVolumetricClouds(viewPos1, vec2(noise_1), WrealSunVec, WmoonVec, directSunlightColor, directMoonlightColor, indirectLightColor, cloudPlaneDistance, cloudDistance); - ////// --------------- START BLENDING FOGS AND FORWARD RENDERED COLOR - vec4 TranslucentShader = texelFetch(colortex2, ivec2(gl_FragCoord.xy), 0); - - bool translucentCheck = TranslucentShader.a > 0.0 && TranslucentShader.a < 1.0; - - ////// --------------- AURORA - - #if AURORA_LOCATION > 0 && defined OVERWORLD_SHADER - if (WsunVec.y < 0.0 && temporallyFilteredVL.a > 0.001 && VLBehindTranslucents.a > 0.001 && isSkyTranslucent - #if AURORA_LOCATION < 2 - && auroraAmount > 0.001 - #endif - #ifdef AURORA_MOON - && WmoonVec.y < 0.1 - #endif - #if AURORA_CHANCE < 100 - && hash_aurora(float(worldDay)) <= 0.01 * float(AURORA_CHANCE) - #endif - ) - { - vec3 aurora = 0.0875*aurora(playerPos_normalized, 21, blueNoise(), WmoonVec.y, WsunVec.y); - - color += aurora; - } - #endif - - // ensure that bloomy fog mask in this VLBehindTranslucents.a does not darken outside of glass areas. - if(translucentCheck) color.rgb = color.rgb * VLBehindTranslucents.a + VLBehindTranslucents.rgb; - // to avoid bloomy fog applying to the surface of water, and the clouds, swap between high and low quality VL buffers. - bloomyFogMult *= isWater ? temporallyFilteredVL.a * 0.75 + 0.25 : (TranslucentShader.a < 0.9995 ? VLBehindTranslucents.a * 0.75 + 0.25 : 1.0); - - // blend border fog. be sure to blend before and after forward rendered color blends. - #if defined BorderFog && defined OVERWORLD_SHADER - float borderFogDensity = getBorderFogDensity(linearDistance_cylinder, playerPos_normalized, isSky); - vec4 borderFog; - - #if !defined SKY_GROUND - borderFog.rgb = skyFromTex(playerPos_normalized, colortex4)/1200.0 * Sky_Brightness; - #else - borderFog.rgb = skyGroundColSSBO / 1200.0 * Sky_Brightness; - #endif - borderFog.a = borderFogDensity; - - #if !defined DISTANT_HORIZONS && !defined VOXY - if(!isWater) color = mix(color, borderFog.rgb, getBorderFogDensity(linearDistance_cylinder_alt, normalize(playerPos_alt), z2 >= 1.0 || !translucentCheck)); - #endif - #else - vec4 borderFog = vec4(0.0); - #endif - - // apply block breaking effect. - bool isBlockBreaking = data.a > 0.99; - if(albedo.a > 0.01 && !isWater && !isEntity && isBlockBreaking && !hand) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb; - - // apply multiplicative color blend for glass n stuff - #ifdef Glass_Tint - if(!isWater && translucentCheck && !isBlockBreaking) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(borderFog.a, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ; - #endif - - // blend forward rendered programs onto the color. - blendForwardRendering(color, TranslucentShader); - - #if defined BorderFog && defined OVERWORLD_SHADER - color = mix(color, borderFog.rgb, borderFogDensity); - #endif - - // tweaks to VL for nametag rendering - #if defined IS_IRIS - temporallyFilteredVL.a = min(temporallyFilteredVL.a + (1.0-nametagbackground),1.0); - temporallyFilteredVL.rgb *= nametagbackground; - #endif - - // blend all fog types. volumetric fog, volumetric clouds, distance based fogs for lava, powdered snow, blindness, and darkness. - blendAllFogTypes(color, bloomyFogMult, temporallyFilteredVL, linearDistance, playerPos_normalized, cameraPosition, isSky, isLightning); - - ////// --------------- RAINBOW - - #if RAINBOW > 0 && defined OVERWORLD_SHADER - #if RAINBOW > 1 - float rainbowAmount = 1.0; - #endif - - float cosAngle = dot(-WsunVec, playerPos_normalized); - if (isEyeInWater == 0 && rainbowAmount > 0.0 && cosAngle < 0.7431448 && cosAngle > 0.7071068) { - #if defined DISTANT_HORIZONS || defined VOXY - float clippingDistance = dhVoxyFarPlane; - #else - float clippingDistance = 4.0 * far; - #endif - if (RAINBOW_DISTANCE > 0.99999*clippingDistance) { - if (linearDistance > 0.99999*clippingDistance) linearDistance = 1.1 * RAINBOW_DISTANCE; // allow rainbow distances greater than clipping distance - } - - float angleFromSun = degrees(acos(cosAngle)); - float rainbowHue = 1.0 - smoothstep(41.4, 44.0, angleFromSun); // remove the red at the bottom - vec3 rainbowColor = HsvToRgb(vec3(rainbowHue, 1.0, RAINBOW_BRIGHTNESS)) * smoothstep(42.0, 43.0, angleFromSun) * smoothstep(44.0, 43.0, angleFromSun); - - rainbowColor *= smoothstep(RAINBOW_DISTANCE*0.9, RAINBOW_DISTANCE*1.1, linearDistance) * smoothstep(0.025, 0.1, sunElevation); - - #if RAINBOW < 2 - rainbowColor *= rainbowAmount * (1.0 - rainStrength); - #endif - - #ifndef RAINBOW_ONLY_BELOW_CLOUDS - rainbowColor *= smoothstep(CloudLayer0_height+CloudLayer0_tallness, CloudLayer0_height, playerPos_normalized.y*RAINBOW_DISTANCE+cameraPosition.y); - #else - rainbowColor = mix(rainbowColor*temporallyFilteredVL.a, rainbowColor, smoothstep(CloudLayer0_height+CloudLayer0_tallness, CloudLayer0_height, playerPos_normalized.y*RAINBOW_DISTANCE+cameraPosition.y)); - #endif - - color += rainbowColor * (1.0 - caveDetection); - } - #endif - - // (bloomy) rain effect - #ifdef OVERWORLD_SHADER - #if RAIN_MODE == 0 // brighten the color behind - float rainDrops = texelFetch(colortex9,ivec2(texcoord/texelSize),0).r; - if(hand) rainDrops *= (1.0-TranslucentShader.a); - - if(rainDrops > 0.01) { - bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0); - color.rgb += color.rgb * RAIN_BRIGHTNESS * rainDrops; - } - #else // add albedo of weather particle - vec4 rainDrops = texelFetch(colortex9,ivec2(texcoord/texelSize),0); - rainDrops = vec4(decodeVec2(rainDrops.x), decodeVec2(rainDrops.y)); - if(hand) rainDrops.a *= (1.0-TranslucentShader.a); - - if(rainDrops.a > 0.01) { - bloomyFogMult *= clamp(1.0 - pow(rainDrops.a*5.0,2),0.0,1.0); - color.rgb += RAIN_BRIGHTNESS * rainDrops.rgb * rainDrops.a; - } - #endif - #endif - -////// --------------- FINALIZE - #ifdef display_LUT - float zoomLevel = 2.0; - vec3 thingy = texelFetch(colortex4,ivec2(gl_FragCoord.xy/zoomLevel),0).rgb /1200.0; - - if(luma(thingy) > 0.0){ - color.rgb = thingy; - bloomyFogMult = 1.0; - } - - #if defined OVERWORLD_SHADER - if( hideGUI == 1) color.rgb = skyCloudsFromTex(playerPos_normalized, colortex4).rgb/1200.0; - #else - if( hideGUI == 1) color.rgb = volumetricsFromTex(playerPos_normalized, colortex4, 0.0).rgb/1200.0; - #endif - - #endif - gl_FragData[0] = vec4(bloomyFogMult,0.0,0.0,1.0); // pass fog alpha so bloom can do bloomy fog - gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0); - - // gl_FragData[1].rgb = vec3(tangentNormals.xy,0.0) * 0.1 ; - // gl_FragData[1].rgb = vec3(1.0) * ld( (data.a > 0.0 ? data.a : texture(depthtex0, texcoord).x ) ) ; - // gl_FragData[1].rgb = gl_FragData[1].rgb * (1.0-TranslucentShader.a) + TranslucentShader.rgb*10.0; - // gl_FragData[1].rgb = 1-(texcoord.x > 0.5 ? vec3(TranslucentShader.a) : vec3(data.a)); + #if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 + imageStore(cloudDepthTex, ivec2(gl_FragCoord.xy), vec4(cloudDistance.r, cloudDistance.g, 0, 1)); + #endif + + VolumetricFog = GetVolumetricFog(viewPos1, WsunVec, vec2(noise_1), directLightColor, indirectLight_fog, indirectLight, cloudPlaneDistance); + VolumetricFog = vec4(VolumetricClouds.rgb*VolumetricFog.a + VolumetricFog.rgb, VolumetricFog.a*VolumetricClouds.a); + #endif + + #if defined NETHER_SHADER || defined END_SHADER + VolumetricFog = GetVolumetricFog(viewPos1, noise_1, noise_1); + #endif + } + + gl_FragData[1] = clamp(VolumetricFog, 0.0, 65000.0); + } } \ No newline at end of file diff --git a/shaders/dimensions/composite3.vsh b/shaders/dimensions/composite3.vsh index d311477..8f2e1dd 100644 --- a/shaders/dimensions/composite3.vsh +++ b/shaders/dimensions/composite3.vsh @@ -1,31 +1,39 @@ #include "/lib/settings.glsl" +#include "/lib/util.glsl" +#include "/lib/res_params.glsl" -#include "/lib/SSBOs.glsl" - -#if defined BorderFog || (defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS) > 0 - uniform sampler2D colortex4; - #include "/lib/scene_controller.glsl" +#if defined CUSTOM_MOON_ROTATION && defined OVERWORLD_SHADER + #include "/lib/SSBOs.glsl" #endif -#ifdef OVERWORLD_SHADER - out DATA { +#include "/lib/scene_controller.glsl" + + +out DATA { flat vec3 WsunVec; + flat vec3 WrealSunVec; flat vec3 WmoonVec; - }; -#endif +}; -uniform float far; -uniform float near; -uniform float dhVoxyFarPlane; -uniform float dhVoxyNearPlane; +uniform vec2 texelSize; -uniform mat4 gbufferModelViewInverse; +uniform sampler2D colortex4; + +uniform float sunElevation; uniform vec3 sunPosition; uniform vec3 moonPosition; -uniform float sunElevation; +uniform mat4 gbufferModelViewInverse; +uniform int frameCounter; + + uniform int framemod8; #include "/lib/TAA_jitter.glsl" +uniform float frameTimeCounter; +#include "/lib/Shadow_Params.glsl" +#include "/lib/sky_gradient.glsl" + + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -33,6 +41,11 @@ uniform int framemod8; //////////////////////////////VOID MAIN////////////////////////////// void main() { + gl_Position = ftransform(); + + gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_SCALE)*2.0-1.0; + + float lightSourceCheck = float(sunElevation > 1e-5)*2.0 - 1.0; #ifdef OVERWORLD_SHADER #ifdef SMOOTH_SUN_ROTATION @@ -40,20 +53,29 @@ void main() { #else WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition); #endif - - #if AURORA_LOCATION > 0 - #ifdef CUSTOM_MOON_ROTATION - WmoonVec = customMoonVecSSBO; - #else - #ifdef SMOOTH_MOON_ROTATION - WmoonVec = WmoonVecSmooth; - #else - WmoonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition); - #endif - if(dot(-WmoonVec, WsunVec) < 0.9999) WmoonVec = -WmoonVec; + + #ifdef CUSTOM_MOON_ROTATION + #if LIGHTNING_SHADOWS > 0 + vec3 moonVec = customMoonVec2SSBO; + #else + vec3 moonVec = customMoonVecSSBO; #endif + #else + #ifdef SMOOTH_MOON_ROTATION + vec3 moonVec = WmoonVecSmooth; + #else + vec3 moonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition); + #endif + if(dot(-moonVec, WsunVec) < 0.9999) moonVec = -moonVec; #endif - #endif - gl_Position = ftransform(); + WmoonVec = moonVec; + + WrealSunVec = WsunVec; + WsunVec = mix(WmoonVec, WsunVec, clamp(lightSourceCheck,0,1)); + #else + WmoonVec = vec3(0.0, 1.0, 0.0); + WsunVec = vec3(0.0, 1.0, 0.0); + WrealSunVec = vec3(0.0, 1.0, 0.0); + #endif } diff --git a/shaders/dimensions/composite4.fsh b/shaders/dimensions/composite4.fsh index b7e4966..4f8ea8a 100644 --- a/shaders/dimensions/composite4.fsh +++ b/shaders/dimensions/composite4.fsh @@ -1,77 +1,955 @@ #include "/lib/settings.glsl" -uniform sampler2D colortex3; +#include "/lib/SSBOs.glsl" +#ifdef OVERWORLD_SHADER + in DATA { + flat vec3 WsunVec; + flat vec3 WmoonVec; + }; +#endif + +uniform sampler2D noisetex; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; + +#ifdef DISTANT_HORIZONS + uniform sampler2D dhDepthTex; + uniform sampler2D dhDepthTex1; + #define dhVoxyDepthTex dhDepthTex + #define dhVoxyDepthTex1 dhDepthTex1 +#endif + +#ifdef VOXY + uniform sampler2D vxDepthTexOpaque; + uniform sampler2D vxDepthTexTrans; + #define dhVoxyDepthTex vxDepthTexTrans + #define dhVoxyDepthTex1 vxDepthTexOpaque +#endif + +uniform sampler2D colortex0; +uniform sampler2D colortex1; +uniform sampler2D colortex2; +uniform sampler2D colortex3; +uniform sampler2D colortex4; +uniform sampler2D colortex5; +uniform sampler2D colortex6; +uniform sampler2D colortex7; +uniform sampler2D colortex8; +uniform sampler2D colortex9; +uniform sampler2D colortex10; +uniform sampler2D colortex11; +uniform sampler2D colortex12; +uniform sampler2D colortex13; +uniform sampler2D colortex14; uniform vec2 texelSize; -uniform int framemod8; -#include "/lib/TAA_jitter.glsl" -// Compute 3x3 min max for TAA uniform float viewHeight; uniform float viewWidth; +uniform float nightVision; +uniform float fogEnd; +uniform vec3 fogColor; +uniform vec3 sunVec; +uniform float frameTimeCounter; +uniform int frameCounter; +uniform float far; +uniform float near; +uniform float farPlane; +uniform float dhVoxyNearPlane; +uniform float dhVoxyFarPlane; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferModelView; +uniform mat4 gbufferPreviousModelView; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferProjection; +uniform mat4 gbufferPreviousProjection; +uniform vec3 cameraPosition; +uniform vec3 previousCameraPosition; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +uniform int hideGUI; +uniform int dhVoxyRenderDistance; +uniform int isEyeInWater; +uniform ivec2 eyeBrightnessSmooth; +uniform ivec2 eyeBrightness; +uniform float rainStrength; +uniform float blindness; +uniform float darknessFactor; +uniform float darknessLightFactor; +uniform float caveDetection; +uniform float sunElevation; + +#if defined CUMULONIMBUS_LIGHTNING && defined OVERWORLD_SHADER && CUMULONIMBUS > 0 + uniform vec4 lightningBoltPosition; + + #include "/lib/scene_controller.glsl" + + uniform sampler2D lightningTex1; + uniform sampler2D lightningTex2; + uniform sampler2D lightningTex3; + uniform sampler2D lightningTex4; + uniform sampler2D lightningTex5; + uniform sampler2D lightningTex6; + uniform sampler2D lightningTex7; + uniform sampler2D lightningTex8; + uniform sampler2D lightningTex9; + uniform sampler2D lightningTex10; + uniform sampler2D lightningTex11; + uniform sampler2D lightningTex12; + uniform sampler2D lightningTex13; + uniform sampler2D lightningTex14; + uniform sampler2D lightningTex15; + uniform sampler2D lightningTex16; + + #define LIGHTNINGONLY + #include "/lib/volumetricClouds.glsl" +#else + uniform int worldDay; +#endif + +#if defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 +layout (rgba16f) uniform image2D cloudDepthTex; +#endif + +#include "/lib/waterBump.glsl" +#include "/lib/res_params.glsl" + +#ifdef OVERWORLD_SHADER + #include "/lib/climate_settings.glsl" +#endif + +#include "/lib/sky_gradient.glsl" + +#if RAINBOW > 0 && defined OVERWORLD_SHADER + uniform float rainbowAmount; + #include "/lib/hsv.glsl" +#endif + +uniform float eyeAltitude; + +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) + +// float ld(float depth) { +// return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near +// } + +float convertHandDepth(float depth) { + float ndcDepth = depth * 2.0 - 1.0; + ndcDepth /= MC_HAND_DEPTH; + return ndcDepth * 0.5 + 0.5; +} + +float linearize(float dist) { + return (2.0 * near) / (far + near - dist * (far - near)); +} + +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} + +vec3 toLinear(vec3 sRGB){ + return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); +} + +vec3 toScreenSpace(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 playerPos = p * 2. - 1.; + vec4 fragposition = iProjDiag * playerPos.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} + +#include "/lib/DistantHorizons_projections.glsl" + +float interleaved_gradientNoise_temporal(){ + #ifdef TAA + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter); + #else + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887); + #endif +} + +float interleaved_gradientNoise(){ + vec2 coord = gl_FragCoord.xy; + float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); + return noise; +} + +float R2_dither(){ + vec2 coord = gl_FragCoord.xy ; + + #ifdef TAA + coord += (frameCounter%40000) * 2.0; + #endif + + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha.x * coord.x + alpha.y * coord.y ) ; +} + +float blueNoise(){ + #ifdef TAA + return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); + #else + return fract(texelFetch(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887); + #endif +} + +vec4 blueNoise(vec2 coord){ + return texelFetch(colortex6, ivec2(coord)%512 , 0) ; +} + +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} + +float DH_ld(float dist) { + return (2.0 * dhVoxyNearPlane) / (dhVoxyFarPlane + dhVoxyNearPlane - dist * (dhVoxyFarPlane - dhVoxyNearPlane)); +} + +float DH_inv_ld (float lindepth){ + return -((2.0*dhVoxyNearPlane/lindepth)-dhVoxyFarPlane-dhVoxyNearPlane)/(dhVoxyFarPlane-dhVoxyNearPlane); +} + +float linearizeDepthFast(const in float depth, const in float near, const in float far) { + return (near * far) / (depth * (near - far) + far); +} + +vec2 decodeVec2(float a){ + const vec2 constant1 = 65535. / vec2( 256., 65536.); + const float constant2 = 256. / 255.; + return fract( a * constant1 ) * constant2 ; +} + +vec3 decode (vec2 encn){ + vec3 n = vec3(0.0); + encn = encn * 2.0 - 1.0; + n.xy = abs(encn); + n.z = 1.0 - n.x - n.y; + n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn; + return clamp(normalize(n.xyz),-1.0,1.0); +} + +vec3 worldToView(vec3 worldPos) { + vec4 pos = vec4(worldPos, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; +} + +vec3 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} + +vec2 clampUV(in vec2 uv, vec2 texcoord){ + // return uv; + + // get the gradient when a refracted axis and non refracted axis go above 1.0 or below 0.0 + // use this gradient to lerp between refracted and non refracted uv + // the goal of this is to stretch the uv back to normal when the refracted image exposes off screen uv + // emphasis on *stretch*, as i want the transition to remain looking like refraction, not a sharp cut. + + float vignette = max(uv.x * texcoord.x, 0.0); + vignette = max(uv.y * texcoord.y, vignette); + vignette = max((uv.x-1.0) * (texcoord.x-1.0), vignette); + vignette = max((uv.y-1.0) * (texcoord.y-1.0), vignette); + vignette *= vignette*vignette*vignette*vignette; + + return clamp(mix(uv, texcoord, vignette),0.0,0.9999999); +} + +vec3 doRefractionEffect( inout vec2 passTexcoord, vec2 normal, float linearDistance, bool isReflectiveEntity, bool underwater){ + // correct normal directions to match texcoord directions (right facing X, up facing Y) + normal.y = -normal.y; + vec2 texcoord = passTexcoord; + + vec3 color = vec3(0.0); + + float refractAmount = float(FAKE_REFRACTION_AMOUNT)/4.0; + float dispersionAmount = float(FAKE_DISPERSION_AMOUNT)/4.0; + float smudgeAmount = float(REFRACTION_SMUDGE_AMOUNT)/4.0; + + refractAmount *= 0.5 / (1.0 + pow(linearDistance,0.8) * (underwater ? 0.1 : 1.0)); + if(isReflectiveEntity) refractAmount *= 0.5; + + dispersionAmount *= 0.035; + smudgeAmount *= 0.035; + + vec2 dispersion = (clamp(normal, -0.2, 0.2) / 0.2); + + #if REFRACTION_SMUDGE_AMOUNT > 0 + vec2 smudge = smudgeAmount * dispersion * (blueNoise()-0.5); + #else + vec2 smudge = vec2(0.0, 0.0); + #endif + + dispersion *= dispersionAmount; + + #if FAKE_DISPERSION_AMOUNT > 0 + // do not offset texcoord if alpha is 1.0 + refractAmount *= min( decodeVec2(texelFetch(colortex11, ivec2(clampUV(texcoord - ((normal + dispersion) + smudge)*refractAmount, texcoord)/texelSize),0).b).g, + decodeVec2(texelFetch(colortex11, ivec2(clampUV(texcoord - ((normal - dispersion) + smudge)*refractAmount, texcoord)/texelSize),0).b).g ) > 0.0 ? 1.0 : 0.0; + + // create offsets + vec2 offsetTexcoord = clampUV(texcoord - (normal + smudge)*refractAmount, texcoord); + passTexcoord = offsetTexcoord; + + // sample color with offsetted texcoord. in this case, the red and blue channels have offsets in opposite directions for a dispersion effect. + color.g = texture(colortex3, offsetTexcoord).g; + + offsetTexcoord = clampUV(texcoord - ((normal + dispersion) + smudge)*refractAmount, texcoord); + color.r = texture(colortex3, offsetTexcoord).r; + + offsetTexcoord = clampUV(texcoord - ((normal - dispersion) + smudge)*refractAmount, texcoord); + color.b = texture(colortex3, offsetTexcoord).b; + #else + // do not offset texcoord if alpha is 1.0 + refractAmount *= decodeVec2(texelFetch(colortex11, ivec2(clampUV(texcoord - (normal + smudge)*refractAmount, texcoord)/texelSize),0).b).g > 0.0 ? 1.0 : 0.0; + + // create offsets + vec2 offsetTexcoord = clampUV(texcoord - (normal + smudge)*refractAmount, texcoord); + passTexcoord = offsetTexcoord; + + // sample color with distorted texcoords + color.rgb = texture(colortex3, offsetTexcoord).rgb; + #endif + + return color; +} + +vec3 toClipSpace3Prev(vec3 viewSpacePosition) { + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +} + +vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) { + + #if defined DISTANT_HORIZONS || defined VOXY + mat4 projectionMatrix = depthCheck ? dhVoxyProjectionPrev : gbufferPreviousProjection; + return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #else + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #endif +} + +vec4 bilateralUpsample(vec2 fragcoord, sampler2D colortex, out float outerEdgeResults, float referenceDepth, sampler2D depth, bool hand, const int behindTranslucents){ + + vec4 colorSum = vec4(0.0); + float edgeSum = 0.0; + #if defined DISTANT_HORIZONS || defined VOXY + const float threshold = 0.05; + #else + const float threshold = 0.005; + #endif + + #ifdef HQ_CLOUD_UPSAMPLE + const int samples = 9; + #else + const int samples = 5; + #endif + + vec2 coord = fragcoord - 1.5; + + vec2 UV = coord; + const ivec2 SCALE = ivec2(1.0/VL_RENDER_SCALE); + ivec2 UV_DEPTH = ivec2(UV*VL_RENDER_SCALE)*SCALE; + ivec2 UV_COLOR = ivec2(UV*VL_RENDER_SCALE); + ivec2 UV_NOISE = ivec2(gl_FragCoord.xy*texelSize + 1); + + const ivec2 OFFSET[9] = ivec2[9]( + ivec2(-1,-1), + ivec2( 1, 1), + ivec2(-1, 1), + ivec2( 1,-1), + ivec2( 0, 0), + ivec2( 0, 1), + ivec2( 0,-1), + ivec2( 1, 0), + ivec2(-1, 0) + ); + + for(int i = 0; i < samples; i++) { + + #if defined DISTANT_HORIZONS || defined VOXY + float offsetDepth = sqrt(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE,0)[behindTranslucents]); + #else + float offsetDepth = linearize(texelFetch(depth, UV_DEPTH + (OFFSET[i] + UV_NOISE) * SCALE, 0).r); + #endif + + float edgeDiff = abs(offsetDepth - referenceDepth) < threshold ? 1.0 : 1e-7; + outerEdgeResults = max(outerEdgeResults, abs(referenceDepth - offsetDepth)); + + vec4 offsetColor = texelFetch(colortex, UV_COLOR + OFFSET[i] + UV_NOISE, 0); + colorSum += offsetColor*edgeDiff; + edgeSum += edgeDiff; + + } + + outerEdgeResults = outerEdgeResults > (hand ? 0.005 : referenceDepth*0.05 + 0.1) ? 1.0 : 0.0; + + return colorSum / edgeSum; +} + +vec4 VLTemporalFiltering(vec3 playerPosIn, in float referenceDepth, sampler2D depth, bool hand){ + vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); + vec2 offsetTexcoord = clamp(gl_FragCoord.xy*texelSize, screenEdges, 1.0-screenEdges); + vec2 VLtexCoord = offsetTexcoord * VL_RENDER_SCALE; + + // get previous frames position stuff for UV + vec3 playerPos = playerPosIn + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; + previousPosition = toClipSpace3Prev(previousPosition); + + vec2 velocity = previousPosition.xy - offsetTexcoord; + previousPosition.xy = offsetTexcoord + velocity; + + vec4 currentFrame = texture(colortex0, VLtexCoord); + + // return vec4(outerEdgeResults,0,0,1); + // return upsampledCurrentFrame; + + if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame; + + // to fill pixel gaps in geometry edges, do a bilateral upsample. + // pass a mask to only show upsampled color around the edges of blocks. this is so it doesnt blur reprojected results. + float outerEdgeResults = 0.0; + vec4 upsampledCurrentFrame = bilateralUpsample(gl_FragCoord.xy , colortex0, outerEdgeResults, referenceDepth, depth, hand, 2); + // vec4 upsampledCurrentFrame = BilateralUpscale(colortex0, depth, gl_FragCoord.xy - 1.5, referenceDepth); + + vec4 col1 = texture(colortex0, VLtexCoord + vec2( texelSize.x, texelSize.y)); + vec4 col2 = texture(colortex0, VLtexCoord + vec2( texelSize.x, -texelSize.y)); + vec4 col3 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, -texelSize.y)); + vec4 col4 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, texelSize.y)); + vec4 col5 = texture(colortex0, VLtexCoord + vec2( 0.0, texelSize.y)); + vec4 col6 = texture(colortex0, VLtexCoord + vec2( 0.0, -texelSize.y)); + vec4 col7 = texture(colortex0, VLtexCoord + vec2(-texelSize.x, 0.0)); + vec4 col8 = texture(colortex0, VLtexCoord + vec2( texelSize.x, 0.0)); + + vec4 colMax = max(currentFrame,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); + vec4 colMin = min(currentFrame,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); + + vec4 frameHistory = texture(colortex10, previousPosition.xy*RENDER_SCALE); + vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax); + + float blendingFactor = 0.1; + + // variance + if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0; + + vec4 reprojectFrame = mix(clampedFrameHistory, currentFrame, blendingFactor); + + // return clamp(reprojectFrame,0.0,65000.0); + return clamp(mix(reprojectFrame, upsampledCurrentFrame, outerEdgeResults),0.0,65000.0); + +} + +uniform float waterEnteredAltitude; + +void blendAllFogTypes( inout vec3 color, inout float bloomyFogMult, vec4 volumetrics, float linearDistance, vec3 playerPos, vec3 cameraPosition, bool isSky, bool isLightning){ + + // blend cave fog + #if defined OVERWORLD_SHADER && defined CAVE_FOG + if (isEyeInWater == 0 && eyeAltitude < 1500){ + vec3 cavefogCol = vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B) * 0.3; + cavefogCol *= 1.0-pow(1.0-pow(1.0 - max(1.0 - linearDistance/far,0),2),CaveFogFallOff); + cavefogCol *= exp(-7.0*clamp(playerPos.y*0.5+0.5,0,1)) * 0.999 + 0.001; + + float skyhole = pow(clamp(1.0-pow(max(playerPos.y - 0.6,0.0)*5.0,2.0),0.0,1.0),2); + + #if CAVE_DETECTION < 2 + #if CAVE_DETECTION == 1 + float caveFactor = 1.0 - smoothstep(60.0, 63.0, cameraPosition.y); + #else + const float caveFactor = 1.0; + #endif + #else + const float caveFactor = 0.0; + #endif + + color.rgb = mix(color.rgb + cavefogCol * caveDetection, cavefogCol, isSky ? skyhole * caveDetection * caveFactor: 0.0); + } + #endif + + /// water absorption; it is completed when volumetrics are blended. + if(isEyeInWater == 1){ + vec3 totEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); + vec3 scatterCoef = Dirt_Amount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; + + float distanceFromWaterSurface = playerPos.y + 1.0 + (cameraPosition.y - waterEnteredAltitude)/waterEnteredAltitude; + distanceFromWaterSurface = clamp(distanceFromWaterSurface,0,1); + + vec3 transmittance = exp(-totEpsilon * linearDistance); + color.rgb *= transmittance; + + vec3 transmittance2 = exp(-totEpsilon * 50.0); + float fogfade = 1.0 - max((1.0 - linearDistance / min(far, 16.0*7.0) ),0); + color.rgb += (transmittance2 * scatterCoef) * fogfade; + + bloomyFogMult *= dot(transmittance,vec3(0.3333))*0.75 + 0.25; + } + + /// blend volumetrics + if(!isLightning) color = color * volumetrics.a; + color += volumetrics.rgb; + + // make bloomy fog only work outside of the overworld (unless underwater) + #if !defined OVERWORLD_SHADER + bloomyFogMult = min(bloomyFogMult, volumetrics.a); + #endif + + // blend vanilla fogs (blindness, darkness, lava, powdered snow) + if(isEyeInWater > 1 || blindness > 0 || darknessFactor > 0){ + float enviornmentFogDensity = 1.0 - clamp(linearDistance/fogEnd,0,1); + enviornmentFogDensity = 1.0 - enviornmentFogDensity*enviornmentFogDensity; + enviornmentFogDensity *= enviornmentFogDensity; + enviornmentFogDensity = mix(enviornmentFogDensity, 1.0, min(darknessLightFactor*2.0,1)); + + color = mix(color, toLinear(fogColor), enviornmentFogDensity); + } +} + +void blendForwardRendering( inout vec3 color, vec4 translucentShader ){ + // REMEMBER that forward rendered color is written as color.rgb/10.0, invert it. + if(translucentShader.a > 0) { + color = color * (1.0 - translucentShader.a) + translucentShader.rgb * 10.0; + } +} + +float getBorderFogDensity(float linearDistance, vec3 playerPos, bool sky){ + + if(sky) return 0.0; + + #if defined DISTANT_HORIZONS || defined VOXY + float borderFogDensity = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance / dhVoxyRenderDistance,0.0)*3.0/BorderFogIntensity,1.0) ); + #else + float borderFogDensity = smoothstep(1.0, 0.0, min(max(1.0 - linearDistance / far,0.0)*3.0/BorderFogIntensity,1.0) ); + #endif + + borderFogDensity *= exp(-10.0 * pow(clamp(playerPos.y,0.0,1.0)*4.0,2.0)); + borderFogDensity *= (1.0-caveDetection); + + return borderFogDensity; +} + +#if AURORA_LOCATION > 0 + uniform float auroraAmount; + #include "/lib/aurora.glsl" +#endif void main() { -/* RENDERTARGETS:0,6 */ - vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); - vec2 jitter = offsets[framemod8]*texelSize*0.5; - ivec2 center = ivec2(clamp(gl_FragCoord.xy*texelSize, screenEdges, 1.0-screenEdges)/texelSize); + /* RENDERTARGETS:7,3,10 */ - // vec3 current = texelFetch(colortex3, center, 0).rgb; - // vec3 cMin = current; - // vec3 cMax = current; - // current = texelFetch(colortex3, center + ivec2(-1, -1), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(-1, 0), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(-1, 1), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(0, -1), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(0, 1), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(1, -1), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(1, 0), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // current = texelFetch(colortex3, center + ivec2(1, 1), 0).rgb; - // cMin = min(cMin, current); - // cMax = max(cMax, current); - // gl_FragData[0].rgb = cMax; - // gl_FragData[1].rgb = cMin; + ////// --------------- SETUP STUFF --------------- ////// + vec2 texcoord = gl_FragCoord.xy*texelSize; + float depth = texelFetch(depthtex0, ivec2(gl_FragCoord.xy),0).x; + bool hand = depth < 0.56; + float z = depth; - vec3 col0 = texelFetch(colortex3, center, 0).rgb; - vec3 col1 = texelFetch(colortex3, center + ivec2(1, 1), 0).rgb; - vec3 col2 = texelFetch(colortex3, center + ivec2(1, -1), 0).rgb; - vec3 col3 = texelFetch(colortex3, center + ivec2(-1, -1), 0).rgb; - vec3 col4 = texelFetch(colortex3, center + ivec2(-1, 1), 0).rgb; - vec3 col5 = texelFetch(colortex3, center + ivec2(0, 1), 0).rgb; - vec3 col6 = texelFetch(colortex3, center + ivec2(0, -1), 0).rgb; - vec3 col7 = texelFetch(colortex3, center + ivec2(-1, 0), 0).rgb; - vec3 col8 = texelFetch(colortex3, center + ivec2(1, 0), 0).rgb; + float frDepth = linearize(z); - vec3 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); - vec3 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); + #if defined DISTANT_HORIZONS || defined VOXY + float DH_depth0 = 0.0; + bool isDHrange = z >= 1.0; + if(isDHrange) DH_depth0 = texelFetch(dhVoxyDepthTex, ivec2(gl_FragCoord.xy),0).x; - vec3 colMax5 = max(col0,max(col5,max(col6,max(col7,col8)))); - vec3 colMin5 = min(col0,min(col5,min(col6,min(col7,col8)))); + bool isSky = DH_depth0 >= 1.0; + #else + bool isSky = z >= 1.0; + float DH_depth0 = 1.0; + #endif - colMin = 0.5 * (colMin + colMin5); - colMax = 0.5 * (colMax + colMax5); + #if !defined DISTANT_HORIZONS && !defined VOXY || (AURORA_LOCATION > 0 && defined OVERWORLD_SHADER) + float z2 = texelFetch(depthtex1, ivec2(gl_FragCoord.xy),0).x; + #endif - gl_FragData[0].rgb = colMax; - gl_FragData[1].rgb = colMin; -} + #if AURORA_LOCATION > 0 && defined OVERWORLD_SHADER + #if defined DISTANT_HORIZONS || defined VOXY + float DH_depth1 = texelFetch(dhVoxyDepthTex, ivec2(gl_FragCoord.xy),0).x; + bool isSkyTranslucent = z2 >= 1.0 && DH_depth1 >= 1.0; + #else + bool isSkyTranslucent = z2 >= 1.0; + #endif + #endif + + vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE, z, DH_depth0); + vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz; + + float linearDistance = length(playerPos); + float linearDistance_cylinder = length(playerPos.xz); + vec3 playerPos_normalized = normalize(playerPos); + + #if !defined DISTANT_HORIZONS && !defined VOXY + vec3 viewPos_alt = toScreenSpace(vec3(texcoord/RENDER_SCALE, z2)); + vec3 playerPos_alt = mat3(gbufferModelViewInverse) * viewPos_alt + gbufferModelViewInverse[3].xyz; + float linearDistance_cylinder_alt = length(playerPos_alt.xz); + #endif + + // float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2.) ,0.0,1.0); + // float lightleakfixfast = clamp(eyeBrightness.y/240.,0.0,1.0); + + ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// + // float opaqueMasks = decodeVec2(texture(colortex1,texcoord).a).y; + // bool isOpaque_entity = abs(opaqueMasks-0.45) < 0.01; + + ////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- ////// + vec4 data = texelFetch(colortex11,ivec2(texcoord/texelSize),0).rgba; + vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)); + vec2 unpack1 = decodeVec2(data.b); + + vec4 albedo = vec4(unpack0.ba,unpack1); + vec2 tangentNormals = unpack0.xy*2.0-1.0; + + bool nameTagMask = abs(data.a - 0.1) < 0.01; + float nametagbackground = nameTagMask ? 0.25 : 1.0; + + if(albedo.a < 0.01) tangentNormals = vec2(0.0); + + ////// --------------- UNPACK MISC --------------- ////// + // 1.0 = water mask + // 0.9 = entity mask + // 0.8 = reflective entities + // 0.7 = reflective blocks + float translucentMasks = texelFetch(colortex7, ivec2(gl_FragCoord.xy),0).a; + + bool isWater = translucentMasks > 0.99; + bool isReflectiveEntity = abs(translucentMasks - 0.2) < 0.01; + bool isReflective = abs(translucentMasks - 0.1) < 0.01 || isWater || isReflectiveEntity; + bool isEntity = abs(translucentMasks - 0.4) < 0.01 || isReflectiveEntity; + + ////// --------------- get volumetrics + #if defined DISTANT_HORIZONS || defined VOXY + float DH_mixedLinearZ = sqrt(texelFetch(colortex9,ivec2(gl_FragCoord.xy),0).z); + vec4 temporallyFilteredVL = VLTemporalFiltering(playerPos, DH_mixedLinearZ, colortex9, hand); + #else + vec4 temporallyFilteredVL = VLTemporalFiltering(playerPos, frDepth, depthtex0, hand); + #endif + + gl_FragData[2] = temporallyFilteredVL; + float bloomyFogMult = 1.0; + + ////// --------------- MAIN COLOR BUFFER + ////// --------------- distort texcoords as a refraction effect + vec2 refractedCoord = texcoord; + #if FAKE_REFRACTION_AMOUNT > 0 + vec3 color; + #if defined DISTANT_HORIZONS || defined VOXY + + bool isLOD = abs(data.a - 0.5) < 0.01; + if(isDHrange || hand || isLOD) { + color = texture(colortex3, texcoord).rgb; + } + else + #endif + { + color = doRefractionEffect(refractedCoord, tangentNormals.xy, linearDistance, isReflectiveEntity, isWater && isEyeInWater == 1); + } + #else + vec3 color = texture(colortex3, texcoord).rgb; + #endif + + ////// --------------- lightning effect + + bool isLightning = false; + + #if defined OVERWORLD_SHADER && defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS > 0 && defined VOLUMETRIC_CLOUDS + + vec2 cloudDepth = imageLoad(cloudDepthTex, ivec2(gl_FragCoord.xy*VL_RENDER_SCALE*RENDER_SCALE)).rg; + + vec3 lightningpos = vec3(getLightningPosition(600, 4680)); + //lightningpos = vec3(0,0,1); + + float lightningDist = length(lightningpos); + + if ((lightningDist < cloudDepth.r || cloudDepth.r == 0.0) && (thunderStrength > 0.0 || rainStrength == 0.0)) { + vec2 tc = (gl_FragCoord.xy - 0.5)*texelSize; + + float depth = z; + + float z0 = depth < 0.56 ? convertHandDepth(depth) : depth; + + float uvScalar = 3.0 * CUSTOM_LIGHTNING_SCALE; + + vec3 normLightningpos = normalize(lightningpos); + + vec3 worldDir = normalize(mat3(gbufferModelViewInverse) * toScreenSpace(vec3(texcoord /RENDER_SCALE,1.0))); + + vec3 tangent = normalize(cross(normLightningpos, vec3(0.0, 1.0, 0.0))); + vec3 binormal = cross(normLightningpos, tangent); + vec3 dirDiff = worldDir - normLightningpos; + + float u = -1.0; + float v = -1.0; + vec4 lightningTex = vec4(0.0); + if (dot(worldDir, normLightningpos) > 0.0) { + u = dot(dirDiff, tangent) + 0.5/uvScalar; + v = 0.55*dot(dirDiff, binormal) + 0.1/uvScalar; + + vec2 uv = vec2(u, v) * uvScalar; + + float randomTex = 16.0*rand(lightningTimer*72.82723486); + + #if CUSTOM_LIGHTNING_TEX > 0 + randomTex = CUSTOM_LIGHTNING_TEX - 1.0; + #endif + + // TODO: There has to be a better way to do this............. + if (randomTex < 1.0) { + lightningTex = texture(lightningTex1, uv); + } else if (randomTex < 2.0) { + lightningTex = texture(lightningTex2, uv); + } else if (randomTex < 3.0) { + u = 1.3*dot(dirDiff, tangent) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex3, uv); + } else if (randomTex < 4.0) { + lightningTex = texture(lightningTex4, uv); + } else if (randomTex < 5.0) { + lightningTex = texture(lightningTex5, uv); + } else if (randomTex < 6.0) { + u = 1.25*dot(dirDiff, tangent) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex6, uv); + } else if (randomTex < 7.0) { + lightningTex = texture(lightningTex7, uv); + } else if (randomTex < 8.0) { + lightningTex = texture(lightningTex8, uv); + } else if (randomTex < 9.0) { + u = 1.4*dot(dirDiff, tangent) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex9, uv); + } else if (randomTex < 10.0) { + lightningTex = texture(lightningTex10, uv); + } else if (randomTex < 11.0) { + u = 0.5*dot(dirDiff, tangent)+0.5/uvScalar; + v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex11, uv); + } else if (randomTex < 12.0) { + u = 0.45*dot(dirDiff, tangent)+0.5/uvScalar; + v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex12, uv); + } else if (randomTex < 13.0) { + u = 0.45*dot(dirDiff, tangent)+0.5/uvScalar; + v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex13, uv); + } else if (randomTex < 14.0) { + u = 0.5*dot(dirDiff, tangent)+0.5/uvScalar; + v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex14, uv); + } else if (randomTex < 15.0) { + u = 0.45*dot(dirDiff, tangent)+0.5/uvScalar; + v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex15, uv); + } else { + u = 0.4*dot(dirDiff, tangent)+0.5/uvScalar; + v = 0.7*dot(dirDiff, binormal) + 0.5/uvScalar; + uv = vec2(u, v) * uvScalar; + lightningTex = texture(lightningTex16, uv); + } + + lightningTex.rgb *= vec3(CUSTOM_LIGHTNING_R, CUSTOM_LIGHTNING_G, CUSTOM_LIGHTNING_B) * CUMULONIMBUS_LIGHTNING_BRIGHTNESS * 0.01; + + if(cloudDepth.g > 0.0) lightningTex.rgb *= smoothstep(7000.0, 1500.0, lightningDist - cloudDepth.g); + + if(lightningTex.rgb != vec3(0.0)) { + #if defined CUSTOM_LIGHTNING_POS && CUSTOM_LIGHTNING_TEX > 0 + lightningTex.a *= pow(lightningTex.a, 2.0); + + lightningTex.rgb *= 75; + #else + lightningTex.a *= pow(lightningTex.a, lightningStart); // fade alpha in for cool expansion effect + + lightningTex.rgb += 120 * lightningMid * lightningTex.rgb; // bright flash in the middle + + lightningTex.rgb *= 75 * lightningFade; // fade out + #endif + } + + if (length(lightningTex.rgb) == 0.0) lightningTex.a = 0.0; + } + + // bool isSky = z0 == 1.0 && DH_z0 == 1.0; + bool oneTexOnly = u > 0 && v > 0 && u*uvScalar < 1 && v*uvScalar < 1; + + if (lightningTex.a > 0.01 && oneTexOnly && isSky) { + color = lightningTex.rgb * lightningFlash; + isLightning = true; + } + } + #endif + + ////// --------------- get volumetrics behind translucents + float blank = 0.0; + #if defined DISTANT_HORIZONS || defined VOXY + DH_mixedLinearZ = sqrt(texelFetch(colortex9,ivec2(gl_FragCoord.xy),0).a); + vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, DH_mixedLinearZ, colortex9, hand, 3); + #else + vec4 VLBehindTranslucents = bilateralUpsample(refractedCoord/texelSize, colortex13, blank, linearize(texelFetch(depthtex1, ivec2(refractedCoord/texelSize),0).x), depthtex1, hand, 3); + #endif + + ////// --------------- START BLENDING FOGS AND FORWARD RENDERED COLOR + vec4 TranslucentShader = texelFetch(colortex2, ivec2(gl_FragCoord.xy), 0); + + bool translucentCheck = TranslucentShader.a > 0.0 && TranslucentShader.a < 1.0; + + ////// --------------- AURORA + + #if AURORA_LOCATION > 0 && defined OVERWORLD_SHADER + if (WsunVec.y < 0.0 && temporallyFilteredVL.a > 0.001 && VLBehindTranslucents.a > 0.001 && isSkyTranslucent + #if AURORA_LOCATION < 2 + && auroraAmount > 0.001 + #endif + #ifdef AURORA_MOON + && WmoonVec.y < 0.1 + #endif + #if AURORA_CHANCE < 100 + && hash_aurora(float(worldDay)) <= 0.01 * float(AURORA_CHANCE) + #endif + ) + { + vec3 aurora = 0.0875*aurora(playerPos_normalized, 21, blueNoise(), WmoonVec.y, WsunVec.y); + + color += aurora; + } + #endif + + // ensure that bloomy fog mask in this VLBehindTranslucents.a does not darken outside of glass areas. + if(translucentCheck) color.rgb = color.rgb * VLBehindTranslucents.a + VLBehindTranslucents.rgb; + // to avoid bloomy fog applying to the surface of water, and the clouds, swap between high and low quality VL buffers. + bloomyFogMult *= isWater ? temporallyFilteredVL.a * 0.75 + 0.25 : (TranslucentShader.a < 0.9995 ? VLBehindTranslucents.a * 0.75 + 0.25 : 1.0); + + // blend border fog. be sure to blend before and after forward rendered color blends. + #if defined BorderFog && defined OVERWORLD_SHADER + float borderFogDensity = getBorderFogDensity(linearDistance_cylinder, playerPos_normalized, isSky); + vec4 borderFog; + + #if !defined SKY_GROUND + borderFog.rgb = skyFromTex(playerPos_normalized, colortex4)/1200.0 * Sky_Brightness; + #else + borderFog.rgb = skyGroundColSSBO / 1200.0 * Sky_Brightness; + #endif + borderFog.a = borderFogDensity; + + #if !defined DISTANT_HORIZONS && !defined VOXY + if(!isWater) color = mix(color, borderFog.rgb, getBorderFogDensity(linearDistance_cylinder_alt, normalize(playerPos_alt), z2 >= 1.0 || !translucentCheck)); + #endif + #else + vec4 borderFog = vec4(0.0); + #endif + + // apply block breaking effect. + bool isBlockBreaking = data.a > 0.99; + if(albedo.a > 0.01 && !isWater && !isEntity && isBlockBreaking && !hand) color = mix(color*6.0, color, luma(albedo.rgb)) * albedo.rgb; + + // apply multiplicative color blend for glass n stuff + #ifdef Glass_Tint + if(!isWater && translucentCheck && !isBlockBreaking) color *= mix(normalize(albedo.rgb+1e-7), vec3(1.0), max(borderFog.a, min(max(0.1-albedo.a,0.0) * 10.0,1.0))) ; + #endif + + // blend forward rendered programs onto the color. + blendForwardRendering(color, TranslucentShader); + + #if defined BorderFog && defined OVERWORLD_SHADER + color = mix(color, borderFog.rgb, borderFogDensity); + #endif + + // tweaks to VL for nametag rendering + #if defined IS_IRIS + temporallyFilteredVL.a = min(temporallyFilteredVL.a + (1.0-nametagbackground),1.0); + temporallyFilteredVL.rgb *= nametagbackground; + #endif + + // blend all fog types. volumetric fog, volumetric clouds, distance based fogs for lava, powdered snow, blindness, and darkness. + blendAllFogTypes(color, bloomyFogMult, temporallyFilteredVL, linearDistance, playerPos_normalized, cameraPosition, isSky, isLightning); + + ////// --------------- RAINBOW + + #if RAINBOW > 0 && defined OVERWORLD_SHADER + #if RAINBOW > 1 + float rainbowAmount = 1.0; + #endif + + float cosAngle = dot(-WsunVec, playerPos_normalized); + if (isEyeInWater == 0 && rainbowAmount > 0.0 && cosAngle < 0.7431448 && cosAngle > 0.7071068) { + #if defined DISTANT_HORIZONS || defined VOXY + float clippingDistance = dhVoxyFarPlane; + #else + float clippingDistance = 4.0 * far; + #endif + if (RAINBOW_DISTANCE > 0.99999*clippingDistance) { + if (linearDistance > 0.99999*clippingDistance) linearDistance = 1.1 * RAINBOW_DISTANCE; // allow rainbow distances greater than clipping distance + } + + float angleFromSun = degrees(acos(cosAngle)); + float rainbowHue = 1.0 - smoothstep(41.4, 44.0, angleFromSun); // remove the red at the bottom + vec3 rainbowColor = HsvToRgb(vec3(rainbowHue, 1.0, RAINBOW_BRIGHTNESS)) * smoothstep(42.0, 43.0, angleFromSun) * smoothstep(44.0, 43.0, angleFromSun); + + rainbowColor *= smoothstep(RAINBOW_DISTANCE*0.9, RAINBOW_DISTANCE*1.1, linearDistance) * smoothstep(0.025, 0.1, sunElevation); + + #if RAINBOW < 2 + rainbowColor *= rainbowAmount * (1.0 - rainStrength); + #endif + + #ifndef RAINBOW_ONLY_BELOW_CLOUDS + rainbowColor *= smoothstep(CloudLayer0_height+CloudLayer0_tallness, CloudLayer0_height, playerPos_normalized.y*RAINBOW_DISTANCE+cameraPosition.y); + #else + rainbowColor = mix(rainbowColor*temporallyFilteredVL.a, rainbowColor, smoothstep(CloudLayer0_height+CloudLayer0_tallness, CloudLayer0_height, playerPos_normalized.y*RAINBOW_DISTANCE+cameraPosition.y)); + #endif + + color += rainbowColor * (1.0 - caveDetection); + } + #endif + + // (bloomy) rain effect + #ifdef OVERWORLD_SHADER + #if RAIN_MODE == 0 // brighten the color behind + float rainDrops = texelFetch(colortex9,ivec2(texcoord/texelSize),0).r; + if(hand) rainDrops *= (1.0-TranslucentShader.a); + + if(rainDrops > 0.01) { + bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0); + color.rgb += color.rgb * RAIN_BRIGHTNESS * rainDrops; + } + #else // add albedo of weather particle + vec4 rainDrops = texelFetch(colortex9,ivec2(texcoord/texelSize),0); + rainDrops = vec4(decodeVec2(rainDrops.x), decodeVec2(rainDrops.y)); + if(hand) rainDrops.a *= (1.0-TranslucentShader.a); + + if(rainDrops.a > 0.01) { + bloomyFogMult *= clamp(1.0 - pow(rainDrops.a*5.0,2),0.0,1.0); + color.rgb += RAIN_BRIGHTNESS * rainDrops.rgb * rainDrops.a; + } + #endif + #endif + +////// --------------- FINALIZE + #ifdef display_LUT + float zoomLevel = 2.0; + vec3 thingy = texelFetch(colortex4,ivec2(gl_FragCoord.xy/zoomLevel),0).rgb /1200.0; + + if(luma(thingy) > 0.0){ + color.rgb = thingy; + bloomyFogMult = 1.0; + } + + #if defined OVERWORLD_SHADER + if( hideGUI == 1) color.rgb = skyCloudsFromTex(playerPos_normalized, colortex4).rgb/1200.0; + #else + if( hideGUI == 1) color.rgb = volumetricsFromTex(playerPos_normalized, colortex4, 0.0).rgb/1200.0; + #endif + + #endif + gl_FragData[0] = vec4(bloomyFogMult,0.0,0.0,1.0); // pass fog alpha so bloom can do bloomy fog + gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0); + + // gl_FragData[1].rgb = vec3(tangentNormals.xy,0.0) * 0.1 ; + // gl_FragData[1].rgb = vec3(1.0) * ld( (data.a > 0.0 ? data.a : texture(depthtex0, texcoord).x ) ) ; + // gl_FragData[1].rgb = gl_FragData[1].rgb * (1.0-TranslucentShader.a) + TranslucentShader.rgb*10.0; + // gl_FragData[1].rgb = 1-(texcoord.x > 0.5 ? vec3(TranslucentShader.a) : vec3(data.a)); + +} \ No newline at end of file diff --git a/shaders/dimensions/composite4.vsh b/shaders/dimensions/composite4.vsh index 4451d61..d311477 100644 --- a/shaders/dimensions/composite4.vsh +++ b/shaders/dimensions/composite4.vsh @@ -1,5 +1,30 @@ #include "/lib/settings.glsl" -#include "/lib/res_params.glsl" + +#include "/lib/SSBOs.glsl" + +#if defined BorderFog || (defined CUMULONIMBUS_LIGHTNING && CUMULONIMBUS) > 0 + uniform sampler2D colortex4; + #include "/lib/scene_controller.glsl" +#endif + +#ifdef OVERWORLD_SHADER + out DATA { + flat vec3 WsunVec; + flat vec3 WmoonVec; + }; +#endif + +uniform float far; +uniform float near; +uniform float dhVoxyFarPlane; +uniform float dhVoxyNearPlane; + +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform vec3 moonPosition; +uniform float sunElevation; +uniform int framemod8; +#include "/lib/TAA_jitter.glsl" //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -8,9 +33,27 @@ //////////////////////////////VOID MAIN////////////////////////////// void main() { - gl_Position = ftransform(); - - #ifdef TAA_UPSCALING - gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + + #ifdef OVERWORLD_SHADER + #ifdef SMOOTH_SUN_ROTATION + WsunVec = WsunVecSmooth; + #else + WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition); + #endif + + #if AURORA_LOCATION > 0 + #ifdef CUSTOM_MOON_ROTATION + WmoonVec = customMoonVecSSBO; + #else + #ifdef SMOOTH_MOON_ROTATION + WmoonVec = WmoonVecSmooth; + #else + WmoonVec = normalize(mat3(gbufferModelViewInverse) * moonPosition); + #endif + if(dot(-WmoonVec, WsunVec) < 0.9999) WmoonVec = -WmoonVec; + #endif + #endif #endif + + gl_Position = ftransform(); } diff --git a/shaders/dimensions/composite5.fsh b/shaders/dimensions/composite5.fsh index edf5d16..b7e4966 100644 --- a/shaders/dimensions/composite5.fsh +++ b/shaders/dimensions/composite5.fsh @@ -1,461 +1,77 @@ #include "/lib/settings.glsl" -#include "/lib/res_params.glsl" -#include "/lib/SSBOs.glsl" - -/* -const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2) + low res VL (composite5->composite15) -const int colortex1Format = RGBA16; // terrain gbuffer (gbuffer->composite2) -const int colortex2Format = RGBA16F; // forward + transparencies (gbuffer->composite4) -const int colortex3Format = R11F_G11F_B10F; // frame buffer + bloom (deferred6->final) -const int colortex4Format = RGBA16F; // light values and skyboxes (everything) -const int colortex6Format = R11F_G11F_B10F; // additional buffer for bloom (composite3->final) -const int colortex7Format = RGBA8; // Final output, transparencies id (gbuffer->composite4) -const int colortex8Format = RGBA16; // Specular Texture, flat normals, vanilla AO - -const int colortex9Format = RGBA16; // rain (encoded rg: gbuffers_weather -> composite3), resource pack sky (rgba: gbuffers_skytextured, gbuffers_skybasic -> deferred1), combined depth quarter res (ba: composite -> wherever) - -const int colortex10Format = RGBA16F; // cloud history -const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha and tangent normals -const int colortex12Format = RGBA16F; // empty - -const int colortex13Format = RGBA16F; // low res VL (composite5->composite15) -const int colortex14Format = RGBA16; // rg = SSAO and SS-SSS. a = skylightmap for translucents. -const int colortex15Format = R11F_G11F_B10F; // PHOTONICS GI - -#ifdef VOXY - const int colortex16Format = RGBA16F; // voxy translucent stuff... -#endif -*/ - -//no need to clear the buffers, saves a few fps -const bool colortex0Clear = false; -const bool colortex1Clear = false; -const bool colortex2Clear = true; -const bool colortex3Clear = false; -const bool colortex4Clear = false; -const bool colortex5Clear = false; -const bool colortex6Clear = false; -const bool colortex7Clear = false; -const bool colortex8Clear = false; -const bool colortex9Clear = true; -const bool colortex10Clear = false; -const bool colortex11Clear = true; -const bool colortex12Clear = false; -const bool colortex13Clear = false; -const bool colortex14Clear = true; -const bool colortex15Clear = true; -#ifdef VOXY - const bool colortex16Clear = true; -#endif - - -#ifdef SCREENSHOT_MODE - /* - const int colortex5Format = RGBA32F; //TAA buffer (everything) - */ -#else - /* - const int colortex5Format = RGBA16F; //TAA buffer (everything) - */ -#endif - -in DATA { - vec2 texcoord; - flat float tempOffsets; -}; - -uniform sampler2D colortex0; -uniform sampler2D colortex1; uniform sampler2D colortex3; -uniform sampler2D colortex5; -uniform sampler2D colortex6; -uniform sampler2D depthtex0; -uniform sampler2D depthtex1; uniform vec2 texelSize; -uniform float frameTimeCounter; +uniform int framemod8; +#include "/lib/TAA_jitter.glsl" +// Compute 3x3 min max for TAA + uniform float viewHeight; uniform float viewWidth; -uniform vec3 previousCameraPosition; -uniform mat4 gbufferPreviousModelView; -uniform mat4 gbufferPreviousModelViewInverse; - -uniform int hideGUI; - -#ifdef DAMAGE_TAKEN_EFFECT - uniform float CriticalDamageTaken; -#endif - -#include "/lib/util.glsl" -#include "/lib/projections.glsl" - - -uniform int framemod8; -#include "/lib/TAA_jitter.glsl" - -vec2 decodeVec2(float a){ - const vec2 constant1 = 65535. / vec2( 256., 65536.); - const float constant2 = 256. / 255.; - return fract( a * constant1 ) * constant2 ; -} - -float luma(vec3 color) { - return dot(color,vec3(0.21, 0.72, 0.07)); -} -float interleaved_gradientNoise(){ - return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); -} -float triangularize(float dither) -{ - float center = dither*2.0-1.0; - dither = center*inversesqrt(abs(center)); - return clamp(dither-fsign(center),0.0,1.0); -} -vec4 fp10Dither(vec4 color ,float dither){ - const vec3 mantissaBits = vec3(6.,6.,5.); - vec3 exponent = floor(log2(color.rgb)); - return vec4(color.rgb + dither*exp2(-mantissaBits)*exp2(exponent), color.a); -} - -vec3 toClipSpace3Prev(vec3 viewSpacePosition) { - return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; -} -vec3 tonemap(vec3 col){ - return col/(1.+luma(col)); -} -vec3 invTonemap(vec3 col){ - return col/(1.-luma(col)); -} -void convertHandDepth(inout float depth) { - float ndcDepth = depth * 2.0 - 1.0; - ndcDepth /= MC_HAND_DEPTH; - depth = ndcDepth * 0.5 + 0.5; -} -float convertHandDepth2( float depth) { - float ndcDepth = depth * 2.0 - 1.0; - ndcDepth /= MC_HAND_DEPTH; - return ndcDepth * 0.5 + 0.5; -} - - -#ifdef DISTANT_HORIZONS - uniform sampler2D dhDepthTex; - #define dhVoxyDepthTex dhDepthTex -#endif - -#ifdef VOXY - uniform sampler2D vxDepthTexTrans; - #define dhVoxyDepthTex vxDepthTexTrans -#endif - -uniform float near; -uniform float far; -uniform float dhVoxyFarPlane; -uniform float dhVoxyNearPlane; - -#include "/lib/DistantHorizons_projections.glsl" - - -float ld(float dist) { - return (2.0 * near) / (far + near - dist * (far - near)); -} -float DH_ld(float dist) { - return (2.0 * dhVoxyNearPlane) / (dhVoxyFarPlane + dhVoxyNearPlane - dist * (dhVoxyFarPlane - dhVoxyNearPlane)); -} -float DH_inv_ld (float lindepth){ - return -((2.0*dhVoxyNearPlane/lindepth)-dhVoxyFarPlane-dhVoxyNearPlane)/(dhVoxyFarPlane-dhVoxyNearPlane); -} - -float linearizeDepthFast(const in float depth, const in float near, const in float far) { - return (near * far) / (depth * (near - far) + far); -} -float invertlinearDepthFast(const in float depth, const in float near, const in float far) { - return ((2.0*near/depth)-far-near)/(far-near); -} - -vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) { - - #if defined DISTANT_HORIZONS || defined VOXY - mat4 projectionMatrix = depthCheck ? dhVoxyProjectionPrev : gbufferPreviousProjection; - return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; - #else - return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; - #endif -} - -vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) { - - vec4 viewPos = vec4(0.0); - vec3 feetPlayerPos = vec3(0.0); - vec4 iProjDiag = vec4(0.0); - #if defined DISTANT_HORIZONS || defined VOXY - if (depthCheck) { - iProjDiag = vec4(dhVoxyProjectionInverse[0].x, dhVoxyProjectionInverse[1].y, dhVoxyProjectionInverse[2].zw); - - feetPlayerPos = POS * 2.0 - 1.0; - viewPos = iProjDiag * feetPlayerPos.xyzz + dhVoxyProjectionInverse[3]; - viewPos.xyz /= viewPos.w; - - } else { - #endif - iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); - - feetPlayerPos = POS * 2.0 - 1.0; - viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3]; - viewPos.xyz /= viewPos.w; - - #if defined DISTANT_HORIZONS || defined VOXY - } - #endif - - return viewPos.xyz; -} - -//Modified texture interpolation from inigo quilez -vec4 smoothfilter(in sampler2D tex, in vec2 uv) -{ - vec2 textureResolution = vec2(viewWidth,viewHeight); - uv = uv*textureResolution + 0.5; - vec2 iuv = floor( uv ); - vec2 fuv = fract( uv ); - - #ifndef SMOOTHESTSTEP_INTERPOLATION - uv = iuv + (fuv*fuv)*(3.0-2.0*fuv); - #endif - #ifdef SMOOTHESTSTEP_INTERPOLATION - uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0); - #endif - - uv = (uv - 0.5)/textureResolution; - - return texture(tex, uv); -} -vec2 smoothfilterUV(in vec2 uv) -{ - vec2 textureResolution = vec2(viewWidth,viewHeight); - uv = uv*textureResolution + 0.5; - vec2 iuv = floor( uv ); - vec2 fuv = fract( uv ); - - #ifndef SMOOTHESTSTEP_INTERPOLATION - uv = iuv + (fuv*fuv)*(3.0-2.0*fuv); - #endif - #ifdef SMOOTHESTSTEP_INTERPOLATION - uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0); - #endif - - uv = (uv - 0.5)/textureResolution; - - return uv; -} -//approximation from SMAA presentation from siggraph 2016 -vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount) -{ - vec2 position = rtMetrics.zw * texcoord; - vec2 centerPosition = floor(position - 0.5) + 0.5; - vec2 f = position - centerPosition; - vec2 f2 = f * f; - vec2 f3 = f * f2; - - float c = sharpenAmount; - vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f; - vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0; - vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f; - vec2 w3 = c * f3 - c * f2; - - vec2 w12 = w1 + w2; - vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12); - vec3 centerColor = texture(colorTex, vec2(tc12.x, tc12.y)).rgb; - vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); - vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); - vec4 color = vec4(texture(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + - vec4(texture(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + - vec4(centerColor, 1.0) * (w12.x * w12.y) + - vec4(texture(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + - vec4(texture(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); - - return color.rgb/color.a; - -} - -vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth) -{ - vec2 du = vec2(texelSize.x*2., 0.0); - vec2 dv = vec2(0.0, texelSize.y*2.); - - vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture(depth, texcoord - dv - du).x); - vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture(depth, texcoord - dv + du).x); - vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture(depth, texcoord).x); - vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture(depth, texcoord + dv - du).x); - vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture(depth, texcoord + dv + du).x); - - vec3 dmin = dmc; - dmin = dmin.z > dtr.z ? dtr : dmin; - dmin = dmin.z > dtl.z ? dtl : dmin; - dmin = dmin.z > dbl.z ? dbl : dmin; - dmin = dmin.z > dbr.z ? dbr : dmin; - - #ifdef TAA_UPSCALING - dmin.xy = dmin.xy/RENDER_SCALE; - #endif - - return dmin; -} - -vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck) -{ - vec2 du = vec2(texelSize.x*2., 0.0); - vec2 dv = vec2(0.0, texelSize.y*2.); - - vec3 dtl = vec3(texcoord,0.); - vec3 dtr = vec3(texcoord,0.); - vec3 dmc = vec3(texcoord,0.); - vec3 dbl = vec3(texcoord,0.); - vec3 dbr = vec3(texcoord,0.); - - dtl += vec3(-texelSize, depthCheck ? texture(dhDepth, texcoord - dv - du).x : texture(depth, texcoord - dv - du).x); - dtr += vec3( texelSize.x, -texelSize.y, depthCheck ? texture(dhDepth, texcoord - dv + du).x : texture(depth, texcoord - dv + du).x); - dmc += vec3( 0.0, 0.0, depthCheck ? texture(dhDepth, texcoord).x : texture(depth, texcoord).x); - dbl += vec3(-texelSize.x, texelSize.y, depthCheck ? texture(dhDepth, texcoord + dv - du).x : texture(depth, texcoord + dv - du).x); - dbr += vec3( texelSize.x, texelSize.y, depthCheck ? texture(dhDepth, texcoord + dv + du).x : texture(depth, texcoord + dv + du).x); - - vec3 dmin = dmc; - dmin = dmin.z > dtr.z ? dtr : dmin; - dmin = dmin.z > dtl.z ? dtl : dmin; - dmin = dmin.z > dbl.z ? dbl : dmin; - dmin = dmin.z > dbr.z ? dbr : dmin; - - #ifdef TAA_UPSCALING - dmin.xy = dmin.xy/RENDER_SCALE; - #endif - - return dmin; -} - -vec4 computeTAA(vec2 texcoord, bool hand){ - - vec2 jitter = offsets[framemod8]*texelSize*0.5; - vec2 adjTC = clamp(texcoord*RENDER_SCALE - texelSize*0.5, vec2(0.0), RENDER_SCALE- texelSize*1.5); - vec2 adjTC_noJitter = adjTC + jitter; - - // get previous frames position stuff for UV - //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion - #if defined DISTANT_HORIZONS || defined VOXY - bool depthCheck = texture(depthtex0,adjTC).x >= 1.0; - vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhVoxyDepthTex, depthCheck); - vec3 viewPos = toScreenSpace_DH_special(closestToCamera, depthCheck); - #else - vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); - vec3 viewPos = toScreenSpace(closestToCamera); - #endif - - vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); - vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; - - #if defined DISTANT_HORIZONS || defined VOXY - previousPosition = toClipSpace3Prev_DH(previousPosition, depthCheck); - #else - previousPosition = toClipSpace3Prev(previousPosition); - #endif - - vec2 velocity = previousPosition.xy - closestToCamera.xy; - - previousPosition.xy = texcoord + (hand ? vec2(0.0) : velocity); - - // sample current frame, and make sure it is de-jittered - #ifdef TAA_UPSCALING - vec3 currentFrame = smoothfilter(colortex3, adjTC_noJitter).rgb; - #else - vec3 currentFrame = texelFetch(colortex3, ivec2(adjTC_noJitter/texelSize), 0).rgb; - #endif - - //reject history if off-screen and early exit - if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return vec4(currentFrame, 1.0); - - #ifdef TAA_UPSCALING - // Interpolating neighboorhood clampling boundaries between pixels - vec3 colMax = texture(colortex0, adjTC).rgb; - vec3 colMin = texture(colortex6, adjTC).rgb; - #else - //Assuming the history color is a blend of the 3x3 neighborhood, we clamp the history to the min and max of each channel in the 3x3 neighborhood - vec3 col0 = currentFrame; // can use this because its the center sample. - vec3 col1 = texture(colortex3, adjTC_noJitter + vec2( texelSize.x, texelSize.y)).rgb; - vec3 col2 = texture(colortex3, adjTC_noJitter + vec2( texelSize.x, -texelSize.y)).rgb; - vec3 col3 = texture(colortex3, adjTC_noJitter + vec2(-texelSize.x, -texelSize.y)).rgb; - vec3 col4 = texture(colortex3, adjTC_noJitter + vec2(-texelSize.x, texelSize.y)).rgb; - vec3 col5 = texture(colortex3, adjTC_noJitter + vec2( 0.0, texelSize.y)).rgb; - vec3 col6 = texture(colortex3, adjTC_noJitter + vec2( 0.0, -texelSize.y)).rgb; - vec3 col7 = texture(colortex3, adjTC_noJitter + vec2(-texelSize.x, 0.0)).rgb; - vec3 col8 = texture(colortex3, adjTC_noJitter + vec2( texelSize.x, 0.0)).rgb; - - vec3 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); - vec3 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); - - colMin = 0.5 * (colMin + min(col0,min(col5,min(col6,min(col7,col8))))); - colMax = 0.5 * (colMax + max(col0,max(col5,max(col6,max(col7,col8))))); - - #endif - - #ifdef DAMAGE_TAKEN_EFFECT - ////// when this triggers, use current frame UV to sample history, for a funny trailing effect. - bool criticalDamageTaken = CriticalDamageTaken > 0.01; - if(criticalDamageTaken) previousPosition.xy = texcoord; - #endif - - vec3 frameHistory = max(FastCatmulRom(colortex5, previousPosition.xy, vec4(texelSize, 1.0/texelSize), 0.75).xyz,0.0); - vec3 clampedframeHistory = clamp(frameHistory, colMin, colMax); - - float blendingFactor = BLEND_FACTOR; - - float cameraMovement = length(velocity/texelSize); - blendingFactor = clamp(cameraMovement, blendingFactor, BLEND_FACTOR_DURING_MOVEMENT); - if(hand) blendingFactor = clamp(cameraMovement, blendingFactor, 1.0); - - ////// Increases blending factor when far from AABB, reduces ghosting - blendingFactor = clamp(blendingFactor + luma(abs(clampedframeHistory - frameHistory)/clampedframeHistory),0.0,1.0); - - ////// Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering - vec3 finalResult = invTonemap(mix(tonemap(clampedframeHistory), tonemap(currentFrame), blendingFactor)); - - #ifdef DAMAGE_TAKEN_EFFECT - ////// when this triggers, do a funny trailing effect. - if(criticalDamageTaken) finalResult = mix(finalResult, frameHistory, sqrt(CriticalDamageTaken)*0.8); - #endif - #ifdef SCREENSHOT_MODE - // when this is on, do "infinite frame accumulation " - if (hideGUI == 0) return vec4(finalResult, 1.0); - - vec4 superSampledHistory = texture(colortex5, previousPosition.xy); - vec3 superSampledResult = superSampledHistory.rgb * superSampledHistory.a + currentFrame; - - return vec4(superSampledResult/(superSampledHistory.a+1.0), superSampledHistory.a+1.0); - #endif - - return vec4(finalResult, 1.0); -} - +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// void main() { -/* RENDERTARGETS:5 */ - #ifdef TAA - vec2 taauTC = clamp(texcoord*RENDER_SCALE, vec2(0.0), RENDER_SCALE - texelSize*2.0); - - float dataUnpacked = decodeVec2(texelFetch(colortex1,ivec2(gl_FragCoord.xy*RENDER_SCALE),0).w).y; - - bool hand = abs(dataUnpacked-0.75) < 0.01 && texture(depthtex1,taauTC).x < 1.0; - - vec4 color = computeTAA(texcoord, hand); +/* RENDERTARGETS:0,6 */ + vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight); + vec2 jitter = offsets[framemod8]*texelSize*0.5; + ivec2 center = ivec2(clamp(gl_FragCoord.xy*texelSize, screenEdges, 1.0-screenEdges)/texelSize); - #ifdef SCREENSHOT_MODE - gl_FragData[0] = clamp(color, 0.0, 65000.0); - #else - gl_FragData[0] = clamp(fp10Dither(color, triangularize(interleaved_gradientNoise())), 0.0, 65000.0); - #endif - #else - vec3 color = clamp(fp10Dither(vec4(texture(colortex3,texcoord).rgb,1.0), triangularize(interleaved_gradientNoise())).rgb,0.0,65000.); - gl_FragData[0].rgb = color; - #endif -} \ No newline at end of file + // vec3 current = texelFetch(colortex3, center, 0).rgb; + // vec3 cMin = current; + // vec3 cMax = current; + // current = texelFetch(colortex3, center + ivec2(-1, -1), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(-1, 0), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(-1, 1), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(0, -1), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(0, 1), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(1, -1), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(1, 0), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // current = texelFetch(colortex3, center + ivec2(1, 1), 0).rgb; + // cMin = min(cMin, current); + // cMax = max(cMax, current); + // gl_FragData[0].rgb = cMax; + // gl_FragData[1].rgb = cMin; + + vec3 col0 = texelFetch(colortex3, center, 0).rgb; + vec3 col1 = texelFetch(colortex3, center + ivec2(1, 1), 0).rgb; + vec3 col2 = texelFetch(colortex3, center + ivec2(1, -1), 0).rgb; + vec3 col3 = texelFetch(colortex3, center + ivec2(-1, -1), 0).rgb; + vec3 col4 = texelFetch(colortex3, center + ivec2(-1, 1), 0).rgb; + vec3 col5 = texelFetch(colortex3, center + ivec2(0, 1), 0).rgb; + vec3 col6 = texelFetch(colortex3, center + ivec2(0, -1), 0).rgb; + vec3 col7 = texelFetch(colortex3, center + ivec2(-1, 0), 0).rgb; + vec3 col8 = texelFetch(colortex3, center + ivec2(1, 0), 0).rgb; + + vec3 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); + vec3 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); + + vec3 colMax5 = max(col0,max(col5,max(col6,max(col7,col8)))); + vec3 colMin5 = min(col0,min(col5,min(col6,min(col7,col8)))); + + colMin = 0.5 * (colMin + colMin5); + colMax = 0.5 * (colMax + colMax5); + + gl_FragData[0].rgb = colMax; + gl_FragData[1].rgb = colMin; +} diff --git a/shaders/dimensions/composite5.vsh b/shaders/dimensions/composite5.vsh index 1a229d7..4451d61 100644 --- a/shaders/dimensions/composite5.vsh +++ b/shaders/dimensions/composite5.vsh @@ -1,25 +1,15 @@ -#include "/lib/util.glsl" +#include "/lib/settings.glsl" #include "/lib/res_params.glsl" -out DATA { - vec2 texcoord; - flat float tempOffsets; -}; - -uniform sampler2D colortex4; -uniform int frameCounter; - - -uniform int framemod8; -#include "/lib/TAA_jitter.glsl" +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// void main() { - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - - tempOffsets = HaltonSeq2(frameCounter%10000); - + #ifdef TAA_UPSCALING gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; #endif diff --git a/shaders/dimensions/composite6.fsh b/shaders/dimensions/composite6.fsh index 50a07d6..7c27574 100644 --- a/shaders/dimensions/composite6.fsh +++ b/shaders/dimensions/composite6.fsh @@ -1,12 +1,101 @@ #include "/lib/settings.glsl" #include "/lib/res_params.glsl" -uniform sampler2D depthtex0; +#include "/lib/SSBOs.glsl" + +/* +const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2) + low res VL (composite5->composite15) +const int colortex1Format = RGBA16; // terrain gbuffer (gbuffer->composite2) +const int colortex2Format = RGBA16F; // forward + transparencies (gbuffer->composite4) +const int colortex3Format = R11F_G11F_B10F; // frame buffer + bloom (deferred6->final) +const int colortex4Format = RGBA16F; // light values and skyboxes (everything) +const int colortex6Format = R11F_G11F_B10F; // additional buffer for bloom (composite3->final) +const int colortex7Format = RGBA8; // Final output, transparencies id (gbuffer->composite4) +const int colortex8Format = RGBA16; // Specular Texture, flat normals, vanilla AO + +const int colortex9Format = RGBA16; // rain (encoded rg: gbuffers_weather -> composite3), resource pack sky (rgba: gbuffers_skytextured, gbuffers_skybasic -> deferred1), combined depth quarter res (ba: composite -> wherever) + +const int colortex10Format = RGBA16F; // cloud history +const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha and tangent normals +const int colortex12Format = RGBA16F; // reflections + +const int colortex13Format = RGBA16F; // low res VL (composite5->composite15) +const int colortex14Format = RGBA16; // rg = SSAO and SS-SSS. z = skylightmap for translucents. +const int colortex15Format = R11F_G11F_B10F; // PHOTONICS GI + +#ifdef VOXY + const int colortex16Format = RGBA16F; // voxy translucent stuff... +#endif +*/ + +//no need to clear the buffers, saves a few fps +const bool colortex0Clear = false; +const bool colortex1Clear = false; +const bool colortex2Clear = true; +const bool colortex3Clear = false; +const bool colortex4Clear = false; +const bool colortex5Clear = false; +const bool colortex6Clear = false; +const bool colortex7Clear = false; +const bool colortex8Clear = false; +const bool colortex9Clear = true; +const bool colortex10Clear = false; +const bool colortex11Clear = true; +const bool colortex12Clear = false; +const bool colortex13Clear = false; +const bool colortex14Clear = true; +const bool colortex15Clear = true; +const bool colortex17Clear = false; +const bool colortex18Clear = false; +#ifdef VOXY + const bool colortex16Clear = true; +#endif + + +#ifdef SCREENSHOT_MODE + /* + const int colortex5Format = RGBA32F; //TAA buffer (everything) + */ +#else + /* + const int colortex5Format = RGBA16F; //TAA buffer (everything) + */ +#endif + +in DATA { + vec2 texcoord; + flat float tempOffsets; +}; + +uniform sampler2D colortex0; uniform sampler2D colortex1; +uniform sampler2D colortex3; uniform sampler2D colortex5; +uniform sampler2D colortex6; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; + uniform vec2 texelSize; -uniform float viewWidth; +uniform float frameTimeCounter; uniform float viewHeight; +uniform float viewWidth; + +uniform vec3 previousCameraPosition; +uniform mat4 gbufferPreviousModelView; +uniform mat4 gbufferPreviousModelViewInverse; + +uniform int hideGUI; + +#ifdef DAMAGE_TAKEN_EFFECT + uniform float CriticalDamageTaken; +#endif + +#include "/lib/util.glsl" +#include "/lib/projections.glsl" + + +uniform int framemod8; +#include "/lib/TAA_jitter.glsl" vec2 decodeVec2(float a){ const vec2 constant1 = 65535. / vec2( 256., 65536.); @@ -14,45 +103,361 @@ vec2 decodeVec2(float a){ return fract( a * constant1 ) * constant2 ; } -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} +float interleaved_gradientNoise(){ + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); +} +float triangularize(float dither) +{ + float center = dither*2.0-1.0; + dither = center*inversesqrt(abs(center)); + return clamp(dither-fsign(center),0.0,1.0); +} +vec4 fp10Dither(vec4 color ,float dither){ + const vec3 mantissaBits = vec3(6.,6.,5.); + vec3 exponent = floor(log2(color.rgb)); + return vec4(color.rgb + dither*exp2(-mantissaBits)*exp2(exponent), color.a); +} -void main() { +vec3 toClipSpace3Prev(vec3 viewSpacePosition) { + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +} +vec3 tonemap(vec3 col){ + return col/(1.+luma(col)); +} +vec3 invTonemap(vec3 col){ + return col/(1.-luma(col)); +} +void convertHandDepth(inout float depth) { + float ndcDepth = depth * 2.0 - 1.0; + ndcDepth /= MC_HAND_DEPTH; + depth = ndcDepth * 0.5 + 0.5; +} +float convertHandDepth2( float depth) { + float ndcDepth = depth * 2.0 - 1.0; + ndcDepth /= MC_HAND_DEPTH; + return ndcDepth * 0.5 + 0.5; +} -/* RENDERTARGETS:3 */ -vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*2.0*resScale*texelSize; +#ifdef DISTANT_HORIZONS + uniform sampler2D dhDepthTex; + #define dhVoxyDepthTex dhDepthTex +#endif -// vec2 texcoord = (gl_FragCoord.xy*2.0*resScale*texelSize) * RENDER_SCALE; +#ifdef VOXY + uniform sampler2D vxDepthTexTrans; + #define dhVoxyDepthTex vxDepthTexTrans +#endif -// bool hand = abs(decodeVec2(texture(colortex1,texcoord).w).y-0.75) < 0.01 && texture(depthtex0,texcoord).x < 1.0; +uniform float near; +uniform float far; +uniform float dhVoxyFarPlane; +uniform float dhVoxyNearPlane; - //0.5 - gl_FragData[0] = texture(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; - gl_FragData[0] += texture(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; +#include "/lib/DistantHorizons_projections.glsl" - //0.25 - gl_FragData[0] += texture(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; - gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; - gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(0.0,-texelSize.y))/2.*0.125; - gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2.*0.125; - //0.125 - gl_FragData[0] += texture(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; - gl_FragData[0] += texture(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; +float ld(float dist) { + return (2.0 * near) / (far + near - dist * (far - near)); +} +float DH_ld(float dist) { + return (2.0 * dhVoxyNearPlane) / (dhVoxyFarPlane + dhVoxyNearPlane - dist * (dhVoxyFarPlane - dhVoxyNearPlane)); +} +float DH_inv_ld (float lindepth){ + return -((2.0*dhVoxyNearPlane/lindepth)-dhVoxyFarPlane-dhVoxyNearPlane)/(dhVoxyFarPlane-dhVoxyNearPlane); +} - //0.125 - gl_FragData[0] += texture(colortex5,quarterResTC)*0.125; +float linearizeDepthFast(const in float depth, const in float near, const in float far) { + return (near * far) / (depth * (near - far) + far); +} +float invertlinearDepthFast(const in float depth, const in float near, const in float far) { + return ((2.0*near/depth)-far-near)/(far-near); +} - gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); - if (quarterResTC.x > 1.0 - 3.5*texelSize.x || quarterResTC.y > 1.0 -3.5*texelSize.y || quarterResTC.x < 3.5*texelSize.x || quarterResTC.y < 3.5*texelSize.y) gl_FragData[0].rgb = vec3(0.0); +vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) { + + #if defined DISTANT_HORIZONS || defined VOXY + mat4 projectionMatrix = depthCheck ? dhVoxyProjectionPrev : gbufferPreviousProjection; + return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #else + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + #endif +} + +vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) { + + vec4 viewPos = vec4(0.0); + vec3 feetPlayerPos = vec3(0.0); + vec4 iProjDiag = vec4(0.0); + #if defined DISTANT_HORIZONS || defined VOXY + if (depthCheck) { + iProjDiag = vec4(dhVoxyProjectionInverse[0].x, dhVoxyProjectionInverse[1].y, dhVoxyProjectionInverse[2].zw); + + feetPlayerPos = POS * 2.0 - 1.0; + viewPos = iProjDiag * feetPlayerPos.xyzz + dhVoxyProjectionInverse[3]; + viewPos.xyz /= viewPos.w; + + } else { + #endif + iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + + feetPlayerPos = POS * 2.0 - 1.0; + viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3]; + viewPos.xyz /= viewPos.w; + + #if defined DISTANT_HORIZONS || defined VOXY + } + #endif + + return viewPos.xyz; +} + +//Modified texture interpolation from inigo quilez +vec4 smoothfilter(in sampler2D tex, in vec2 uv) +{ + vec2 textureResolution = vec2(viewWidth,viewHeight); + uv = uv*textureResolution + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + + #ifndef SMOOTHESTSTEP_INTERPOLATION + uv = iuv + (fuv*fuv)*(3.0-2.0*fuv); + #endif + #ifdef SMOOTHESTSTEP_INTERPOLATION + uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0); + #endif + + uv = (uv - 0.5)/textureResolution; + + return texture(tex, uv); +} +vec2 smoothfilterUV(in vec2 uv) +{ + vec2 textureResolution = vec2(viewWidth,viewHeight); + uv = uv*textureResolution + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + + #ifndef SMOOTHESTSTEP_INTERPOLATION + uv = iuv + (fuv*fuv)*(3.0-2.0*fuv); + #endif + #ifdef SMOOTHESTSTEP_INTERPOLATION + uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0); + #endif + + uv = (uv - 0.5)/textureResolution; + + return uv; +} +//approximation from SMAA presentation from siggraph 2016 +vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount) +{ + vec2 position = rtMetrics.zw * texcoord; + vec2 centerPosition = floor(position - 0.5) + 0.5; + vec2 f = position - centerPosition; + vec2 f2 = f * f; + vec2 f3 = f * f2; + + float c = sharpenAmount; + vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f; + vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0; + vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f; + vec2 w3 = c * f3 - c * f2; + + vec2 w12 = w1 + w2; + vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12); + vec3 centerColor = texture(colorTex, vec2(tc12.x, tc12.y)).rgb; + vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); + vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); + vec4 color = vec4(texture(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + + vec4(texture(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + + vec4(centerColor, 1.0) * (w12.x * w12.y) + + vec4(texture(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + + vec4(texture(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); + + return color.rgb/color.a; } + +vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth) +{ + vec2 du = vec2(texelSize.x*2., 0.0); + vec2 dv = vec2(0.0, texelSize.y*2.); + + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture(depth, texcoord - dv - du).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture(depth, texcoord - dv + du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture(depth, texcoord).x); + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture(depth, texcoord + dv - du).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture(depth, texcoord + dv + du).x); + + vec3 dmin = dmc; + dmin = dmin.z > dtr.z ? dtr : dmin; + dmin = dmin.z > dtl.z ? dtl : dmin; + dmin = dmin.z > dbl.z ? dbl : dmin; + dmin = dmin.z > dbr.z ? dbr : dmin; + + #ifdef TAA_UPSCALING + dmin.xy = dmin.xy/RENDER_SCALE; + #endif + + return dmin; +} + +vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck) +{ + vec2 du = vec2(texelSize.x*2., 0.0); + vec2 dv = vec2(0.0, texelSize.y*2.); + + vec3 dtl = vec3(texcoord,0.); + vec3 dtr = vec3(texcoord,0.); + vec3 dmc = vec3(texcoord,0.); + vec3 dbl = vec3(texcoord,0.); + vec3 dbr = vec3(texcoord,0.); + + dtl += vec3(-texelSize, depthCheck ? texture(dhDepth, texcoord - dv - du).x : texture(depth, texcoord - dv - du).x); + dtr += vec3( texelSize.x, -texelSize.y, depthCheck ? texture(dhDepth, texcoord - dv + du).x : texture(depth, texcoord - dv + du).x); + dmc += vec3( 0.0, 0.0, depthCheck ? texture(dhDepth, texcoord).x : texture(depth, texcoord).x); + dbl += vec3(-texelSize.x, texelSize.y, depthCheck ? texture(dhDepth, texcoord + dv - du).x : texture(depth, texcoord + dv - du).x); + dbr += vec3( texelSize.x, texelSize.y, depthCheck ? texture(dhDepth, texcoord + dv + du).x : texture(depth, texcoord + dv + du).x); + + vec3 dmin = dmc; + dmin = dmin.z > dtr.z ? dtr : dmin; + dmin = dmin.z > dtl.z ? dtl : dmin; + dmin = dmin.z > dbl.z ? dbl : dmin; + dmin = dmin.z > dbr.z ? dbr : dmin; + + #ifdef TAA_UPSCALING + dmin.xy = dmin.xy/RENDER_SCALE; + #endif + + return dmin; +} + +vec4 computeTAA(vec2 texcoord, bool hand){ + + vec2 jitter = offsets[framemod8]*texelSize*0.5; + vec2 adjTC = clamp(texcoord*RENDER_SCALE - texelSize*0.5, vec2(0.0), RENDER_SCALE- texelSize*1.5); + vec2 adjTC_noJitter = adjTC + jitter; + + // get previous frames position stuff for UV + //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion + #if defined DISTANT_HORIZONS || defined VOXY + bool depthCheck = texture(depthtex0,adjTC).x >= 1.0; + vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhVoxyDepthTex, depthCheck); + vec3 viewPos = toScreenSpace_DH_special(closestToCamera, depthCheck); + #else + vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); + vec3 viewPos = toScreenSpace(closestToCamera); + #endif + + vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; + + #if defined DISTANT_HORIZONS || defined VOXY + previousPosition = toClipSpace3Prev_DH(previousPosition, depthCheck); + #else + previousPosition = toClipSpace3Prev(previousPosition); + #endif + + vec2 velocity = previousPosition.xy - closestToCamera.xy; + + previousPosition.xy = texcoord + (hand ? vec2(0.0) : velocity); + + // sample current frame, and make sure it is de-jittered + #ifdef TAA_UPSCALING + vec3 currentFrame = smoothfilter(colortex3, adjTC_noJitter).rgb; + #else + vec3 currentFrame = texelFetch(colortex3, ivec2(adjTC_noJitter/texelSize), 0).rgb; + #endif + + //reject history if off-screen and early exit + if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return vec4(currentFrame, 1.0); + + #ifdef TAA_UPSCALING + // Interpolating neighboorhood clampling boundaries between pixels + vec3 colMax = texture(colortex0, adjTC).rgb; + vec3 colMin = texture(colortex6, adjTC).rgb; + #else + //Assuming the history color is a blend of the 3x3 neighborhood, we clamp the history to the min and max of each channel in the 3x3 neighborhood + vec3 col0 = currentFrame; // can use this because its the center sample. + vec3 col1 = texture(colortex3, adjTC_noJitter + vec2( texelSize.x, texelSize.y)).rgb; + vec3 col2 = texture(colortex3, adjTC_noJitter + vec2( texelSize.x, -texelSize.y)).rgb; + vec3 col3 = texture(colortex3, adjTC_noJitter + vec2(-texelSize.x, -texelSize.y)).rgb; + vec3 col4 = texture(colortex3, adjTC_noJitter + vec2(-texelSize.x, texelSize.y)).rgb; + vec3 col5 = texture(colortex3, adjTC_noJitter + vec2( 0.0, texelSize.y)).rgb; + vec3 col6 = texture(colortex3, adjTC_noJitter + vec2( 0.0, -texelSize.y)).rgb; + vec3 col7 = texture(colortex3, adjTC_noJitter + vec2(-texelSize.x, 0.0)).rgb; + vec3 col8 = texture(colortex3, adjTC_noJitter + vec2( texelSize.x, 0.0)).rgb; + + vec3 colMax = max(col0,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8)))))))); + vec3 colMin = min(col0,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8)))))))); + + colMin = 0.5 * (colMin + min(col0,min(col5,min(col6,min(col7,col8))))); + colMax = 0.5 * (colMax + max(col0,max(col5,max(col6,max(col7,col8))))); + + #endif + + #ifdef DAMAGE_TAKEN_EFFECT + ////// when this triggers, use current frame UV to sample history, for a funny trailing effect. + bool criticalDamageTaken = CriticalDamageTaken > 0.01; + if(criticalDamageTaken) previousPosition.xy = texcoord; + #endif + + vec3 frameHistory = max(FastCatmulRom(colortex5, previousPosition.xy, vec4(texelSize, 1.0/texelSize), 0.75).xyz,0.0); + vec3 clampedframeHistory = clamp(frameHistory, colMin, colMax); + + float blendingFactor = BLEND_FACTOR; + + float cameraMovement = length(velocity/texelSize); + blendingFactor = clamp(cameraMovement, blendingFactor, BLEND_FACTOR_DURING_MOVEMENT); + if(hand) blendingFactor = clamp(cameraMovement, blendingFactor, 1.0); + + ////// Increases blending factor when far from AABB, reduces ghosting + blendingFactor = clamp(blendingFactor + luma(abs(clampedframeHistory - frameHistory)/clampedframeHistory),0.0,1.0); + + ////// Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering + vec3 finalResult = invTonemap(mix(tonemap(clampedframeHistory), tonemap(currentFrame), blendingFactor)); + + #ifdef DAMAGE_TAKEN_EFFECT + ////// when this triggers, do a funny trailing effect. + if(criticalDamageTaken) finalResult = mix(finalResult, frameHistory, sqrt(CriticalDamageTaken)*0.8); + #endif + #ifdef SCREENSHOT_MODE + // when this is on, do "infinite frame accumulation " + if (hideGUI == 0) return vec4(finalResult, 1.0); + + vec4 superSampledHistory = texture(colortex5, previousPosition.xy); + vec3 superSampledResult = superSampledHistory.rgb * superSampledHistory.a + currentFrame; + + return vec4(superSampledResult/(superSampledHistory.a+1.0), superSampledHistory.a+1.0); + #endif + + return vec4(finalResult, 1.0); +} + + + +void main() { +/* RENDERTARGETS:5 */ + #ifdef TAA + vec2 taauTC = clamp(texcoord*RENDER_SCALE, vec2(0.0), RENDER_SCALE - texelSize*2.0); + + float dataUnpacked = decodeVec2(texelFetch(colortex1,ivec2(gl_FragCoord.xy*RENDER_SCALE),0).w).y; + + bool hand = abs(dataUnpacked-0.75) < 0.01 && texture(depthtex1,taauTC).x < 1.0; + + vec4 color = computeTAA(texcoord, hand); + + #ifdef SCREENSHOT_MODE + gl_FragData[0] = clamp(color, 0.0, 65000.0); + #else + gl_FragData[0] = clamp(fp10Dither(color, triangularize(interleaved_gradientNoise())), 0.0, 65000.0); + #endif + #else + vec3 color = clamp(fp10Dither(vec4(texture(colortex3,texcoord).rgb,1.0), triangularize(interleaved_gradientNoise())).rgb,0.0,65000.); + gl_FragData[0].rgb = color; + #endif +} \ No newline at end of file diff --git a/shaders/dimensions/composite6.vsh b/shaders/dimensions/composite6.vsh index 7a54acb..1a229d7 100644 --- a/shaders/dimensions/composite6.vsh +++ b/shaders/dimensions/composite6.vsh @@ -1,15 +1,26 @@ -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#include "/lib/util.glsl" +#include "/lib/res_params.glsl" + +out DATA { + vec2 texcoord; + flat float tempOffsets; +}; + +uniform sampler2D colortex4; +uniform int frameCounter; + + +uniform int framemod8; +#include "/lib/TAA_jitter.glsl" void main() { - //Improves performances and makes sure bloom radius stays the same at high resolution (>1080p) - vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); + gl_Position = ftransform(); - //*0.51 to avoid errors when sampling outside since clearing is disabled - gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51/clampedRes*vec2(1920.0,1080.)*2.0-1.0; + texcoord = gl_MultiTexCoord0.xy; + + tempOffsets = HaltonSeq2(frameCounter%10000); + + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif } diff --git a/shaders/dimensions/composite7.fsh b/shaders/dimensions/composite7.fsh index 6dd0aab..50a07d6 100644 --- a/shaders/dimensions/composite7.fsh +++ b/shaders/dimensions/composite7.fsh @@ -1,7 +1,19 @@ -uniform sampler2D colortex3; +#include "/lib/settings.glsl" +#include "/lib/res_params.glsl" + +uniform sampler2D depthtex0; +uniform sampler2D colortex1; +uniform sampler2D colortex5; uniform vec2 texelSize; uniform float viewWidth; uniform float viewHeight; + +vec2 decodeVec2(float a){ + const vec2 constant1 = 65535. / vec2( 256., 65536.); + const float constant2 = 256. / 255.; + return fract( a * constant1 ) * constant2 ; +} + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -10,33 +22,37 @@ uniform float viewHeight; void main() { -/* RENDERTARGETS:6 */ +/* RENDERTARGETS:3 */ + vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*2.*texelSize; +vec2 quarterResTC = gl_FragCoord.xy*2.0*resScale*texelSize; + +// vec2 texcoord = (gl_FragCoord.xy*2.0*resScale*texelSize) * RENDER_SCALE; + +// bool hand = abs(decodeVec2(texture(colortex1,texcoord).w).y-0.75) < 0.01 && texture(depthtex0,texcoord).x < 1.0; //0.5 - gl_FragData[0] = texture(colortex3,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture(colortex3,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture(colortex3,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; - gl_FragData[0] += texture(colortex3,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; + gl_FragData[0] = texture(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; + gl_FragData[0] += texture(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; //0.25 - gl_FragData[0] += texture(colortex3,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; - gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; - gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(0.0,-texelSize.y))/2.*0.125; - gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(0.0,-texelSize.y))/2.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2.*0.125; //0.125 - gl_FragData[0] += texture(colortex3,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture(colortex3,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; - gl_FragData[0] += texture(colortex3,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; //0.125 - gl_FragData[0] += texture(colortex3,quarterResTC)*0.125; + gl_FragData[0] += texture(colortex5,quarterResTC)*0.125; gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); - - + if (quarterResTC.x > 1.0 - 3.5*texelSize.x || quarterResTC.y > 1.0 -3.5*texelSize.y || quarterResTC.x < 3.5*texelSize.x || quarterResTC.y < 3.5*texelSize.y) gl_FragData[0].rgb = vec3(0.0); } diff --git a/shaders/dimensions/composite7.vsh b/shaders/dimensions/composite7.vsh index fc29d67..7a54acb 100644 --- a/shaders/dimensions/composite7.vsh +++ b/shaders/dimensions/composite7.vsh @@ -11,5 +11,5 @@ void main() { vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); gl_Position = ftransform(); //*0.51 to avoid errors when sampling outside since clearing is disabled - gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.26/clampedRes*vec2(1920.0,1080.)*2.0-1.0; + gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51/clampedRes*vec2(1920.0,1080.)*2.0-1.0; } diff --git a/shaders/dimensions/composite8.fsh b/shaders/dimensions/composite8.fsh index 288aba1..6dd0aab 100644 --- a/shaders/dimensions/composite8.fsh +++ b/shaders/dimensions/composite8.fsh @@ -1,21 +1,7 @@ -uniform sampler2D colortex6; +uniform sampler2D colortex3; uniform vec2 texelSize; uniform float viewWidth; uniform float viewHeight; -vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); -vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ - vec4 tot = vec4(0.); - float maxTC = 0.25*resScale.x; - float minTC = 0.; - for (int i = -maxIT;i minTC && spCoord.x < maxTC); - } - return tot.rgb/max(1.0,tot.a); -} - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -23,34 +9,34 @@ vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ //////////////////////////////VOID MAIN////////////////////////////// void main() { + /* RENDERTARGETS:6 */ +vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); +vec2 quarterResTC = gl_FragCoord.xy*2.*texelSize; -vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; -vec2 gaussDir = vec2(1.0,0.0); -gl_FragData[0].rgb = vec3(0.0); -vec2 tc2 = texcoord*vec2(2.0,1.)/2.; -if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc2/2,gaussDir,0.16,0); + //0.5 + gl_FragData[0] = texture(colortex3,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture(colortex3,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture(colortex3,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; + gl_FragData[0] += texture(colortex3,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; -vec2 tc4 = texcoord*vec2(4.0,1.)/2.-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*2.0; -if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc4/2,gaussDir,0.16,3); + //0.25 + gl_FragData[0] += texture(colortex3,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; + gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; + gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(0.0,-texelSize.y))/2.*0.125; + gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2.*0.125; -vec2 tc8 = texcoord*vec2(8.0,1.)/2.-vec2(0.75*resScale.x+8.*texelSize.x,0.)*4.0; -if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc8/2,gaussDir,0.035,6); + //0.125 + gl_FragData[0] += texture(colortex3,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex3,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex3,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; + gl_FragData[0] += texture(colortex3,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; -vec2 tc16 = texcoord*vec2(8.0,1./2.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*8.0; -if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc16/2,gaussDir,0.0085,12); + //0.125 + gl_FragData[0] += texture(colortex3,quarterResTC)*0.125; + + gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); -vec2 tc32 = texcoord*vec2(16.0,1./2.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*16.0; -if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc32/2,gaussDir,0.002,28); -vec2 tc64 = texcoord*vec2(32.0,1./2.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*32.0; -if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc64/2,gaussDir,0.0005,60); -gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); } diff --git a/shaders/dimensions/composite8.vsh b/shaders/dimensions/composite8.vsh index 0c48242..fc29d67 100644 --- a/shaders/dimensions/composite8.vsh +++ b/shaders/dimensions/composite8.vsh @@ -1,6 +1,5 @@ uniform float viewWidth; uniform float viewHeight; - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -8,10 +7,9 @@ uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// void main() { - vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0)); + //Improves performances and makes sure bloom radius stays the same at high resolution (>1080p) + vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); gl_Position = ftransform(); - //0-0.25 - gl_Position.y = (gl_Position.y*0.5+0.5)*0.25/clampedRes.y*1080.0*2.0-1.0; - //0-0.5 - gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0; + //*0.51 to avoid errors when sampling outside since clearing is disabled + gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.26/clampedRes*vec2(1920.0,1080.)*2.0-1.0; } diff --git a/shaders/dimensions/composite9.fsh b/shaders/dimensions/composite9.fsh index 1065deb..288aba1 100644 --- a/shaders/dimensions/composite9.fsh +++ b/shaders/dimensions/composite9.fsh @@ -5,14 +5,15 @@ uniform float viewHeight; vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ vec4 tot = vec4(0.); - float maxTC = 0.25*resScale.y; + float maxTC = 0.25*resScale.x; float minTC = 0.; for (int i = -maxIT;i minTC && spCoord.y < maxTC); + tot += vec4(texture(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.x > minTC && spCoord.x < maxTC); } - return tot.rgb/max(1.0,tot.a); + return tot.rgb/max(1.0,tot.a); } //////////////////////////////VOID MAIN////////////////////////////// @@ -23,33 +24,33 @@ vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ void main() { /* RENDERTARGETS:6 */ + vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; - -vec2 gaussDir = vec2(0.0,1.0); +vec2 gaussDir = vec2(1.0,0.0); gl_FragData[0].rgb = vec3(0.0); -vec2 tc2 = texcoord*vec2(2.0,1.); +vec2 tc2 = texcoord*vec2(2.0,1.)/2.; if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,4.0),gaussDir,0.16,0); +gl_FragData[0].xyz = gauss1D(tc2/2,gaussDir,0.16,0); -vec2 tc4 = texcoord*vec2(4.0,2.)-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*4.0; +vec2 tc4 = texcoord*vec2(4.0,1.)/2.-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*2.0; if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,2.0),gaussDir,0.16,3); +gl_FragData[0].xyz = gauss1D(tc4/2,gaussDir,0.16,3); -vec2 tc8 = texcoord*vec2(8.0,4.)-vec2(0.75*resScale.x+8.*texelSize.x,0.)*8.0; +vec2 tc8 = texcoord*vec2(8.0,1.)/2.-vec2(0.75*resScale.x+8.*texelSize.x,0.)*4.0; if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,2.0)/vec2(2.0,2.0),gaussDir,0.035,6); +gl_FragData[0].xyz = gauss1D(tc8/2,gaussDir,0.035,6); -vec2 tc16 = texcoord*vec2(16.0,8.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*16.0; +vec2 tc16 = texcoord*vec2(8.0,1./2.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*8.0; if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,4.0)/vec2(2.0,2.0),gaussDir,0.0085,12); +gl_FragData[0].xyz = gauss1D(tc16/2,gaussDir,0.0085,12); -vec2 tc32 = texcoord*vec2(32.0,16.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*32.0; +vec2 tc32 = texcoord*vec2(16.0,1./2.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*16.0; if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,8.0)/vec2(2.0,2.0),gaussDir,0.002,30); +gl_FragData[0].xyz = gauss1D(tc32/2,gaussDir,0.002,28); -vec2 tc64 = texcoord*vec2(64.0,32.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*64.0; +vec2 tc64 = texcoord*vec2(32.0,1./2.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*32.0; if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,16.0)/vec2(2.0,2.0),gaussDir,0.0005,60); +gl_FragData[0].xyz = gauss1D(tc64/2,gaussDir,0.0005,60); gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); } diff --git a/shaders/dimensions/prepare4.fsh b/shaders/dimensions/prepare4.fsh index e124b86..f6511ab 100644 --- a/shaders/dimensions/prepare4.fsh +++ b/shaders/dimensions/prepare4.fsh @@ -150,14 +150,13 @@ float invLinZ (float lindepth){ // uniform sampler2D colortex4; // uniform sampler2D colortex12; // const bool shadowHardwareFiltering = true; - uniform sampler2DShadow shadow; + uniform sampler2DShadow shadowtex0HW; // #undef TRANSLUCENT_COLORED_SHADOWS #ifdef TRANSLUCENT_COLORED_SHADOWS uniform sampler2D shadowcolor0; - uniform sampler2DShadow shadowtex0; - uniform sampler2DShadow shadowtex1; + uniform sampler2DShadow shadowtex1HW; #endif // #define TEST diff --git a/shaders/dimensions/voxels.fsh b/shaders/dimensions/voxels.fsh index 90e4a88..a0518c7 100644 --- a/shaders/dimensions/voxels.fsh +++ b/shaders/dimensions/voxels.fsh @@ -36,7 +36,6 @@ in DATA { #endif vec3 block_normal; - flat int blockID; } data_in; const float mincoord = 1.0/4096.0; @@ -354,11 +353,6 @@ void main() { float saveDepth = 0.0; if(!ifPOM) adjustedTexCoord = data_in.lmtexcoord.xy; - - float opaqueMasks = 1.0; - - // if(data_in.blockID == BLOCK_GROUND_WAVING_VERTICAL || data_in.blockID == BLOCK_GRASS_SHORT || data_in.blockID == BLOCK_GRASS_TALL_LOWER || data_in.blockID == BLOCK_GRASS_TALL_UPPER ) opaqueMasks = 0.60; - // else if(data_in.blockID == BLOCK_AIR_WAVING) opaqueMasks = 0.55; //////////////////////////////// //////////////////////////////// @@ -387,6 +381,7 @@ void main() { if (!ray.result_hit) discard; if (ray.result_normal == vec3(0.0)) ray.result_normal = data_in.block_normal; + int blockID = result_block_id; playerpos = ray.result_position + world_offset - cameraPosition; vec3 viewPos = (gbufferModelView * vec4(playerpos, 1.0f)).xyz; @@ -407,35 +402,40 @@ void main() { Albedo.rgb = vec3(0.5); #endif + float opaqueMasks = 1.0; + + if(blockID == BLOCK_GROUND_WAVING_VERTICAL || blockID == BLOCK_GRASS_SHORT || blockID == BLOCK_GRASS_TALL_LOWER || blockID == BLOCK_GRASS_TALL_UPPER ) opaqueMasks = 0.60; + else if(blockID == BLOCK_AIR_WAVING) opaqueMasks = 0.55; + - // #ifdef AEROCHROME_MODE - // float gray = dot(Albedo.rgb, vec3(0.2, 1.0, 0.07)); - // if ( - // data_in.blockID == BLOCK_AMETHYST_BUD_MEDIUM || data_in.blockID == BLOCK_AMETHYST_BUD_LARGE || data_in.blockID == BLOCK_AMETHYST_CLUSTER - // || data_in.blockID == BLOCK_SSS_STRONG || data_in.blockID == BLOCK_SSS_STRONG3 || data_in.blockID == BLOCK_SSS_WEAK || data_in.blockID == BLOCK_CACTUS - // || data_in.blockID == BLOCK_CELESTIUM || data_in.blockID == BLOCK_SNOW_LAYERS - // || data_in.blockID >= 10 && data_in.blockID < 80 - // ) { - // // IR Reflective (Pink-red) - // Albedo.rgb = mix(vec3(gray), aerochrome_color, 0.7); - // } - // else if(data_in.blockID == BLOCK_GRASS) { - // // Special handling for grass block - // float strength = 1.0 - Color.b; - // Albedo.rgb = mix(Albedo.rgb, aerochrome_color, strength); - // } - // #ifdef AEROCHROME_WOOL_ENABLED - // else if (data_in.blockID == BLOCK_SSS_WEAK_2 || data_in.blockID == BLOCK_CARPET) { - // // Wool - // Albedo.rgb = mix(Albedo.rgb, aerochrome_color, 0.3); - // } - // #endif - // else if(data_in.blockID == BLOCK_WATER || (data_in.blockID >= 300 && data_in.blockID < 400)) - // { - // // IR Absorbsive? Dark. - // Albedo.rgb = mix(Albedo.rgb, vec3(0.01, 0.08, 0.15), 0.5); - // } - // #endif + #ifdef AEROCHROME_MODE + float gray = dot(Albedo.rgb, vec3(0.2, 1.0, 0.07)); + if ( + blockID == BLOCK_AMETHYST_BUD_MEDIUM || blockID == BLOCK_AMETHYST_BUD_LARGE || blockID == BLOCK_AMETHYST_CLUSTER + || blockID == BLOCK_SSS_STRONG || blockID == BLOCK_SSS_STRONG3 || blockID == BLOCK_SSS_WEAK || blockID == BLOCK_CACTUS + || blockID == BLOCK_CELESTIUM || blockID == BLOCK_SNOW_LAYERS + || blockID >= 10 && blockID < 80 + ) { + // IR Reflective (Pink-red) + Albedo.rgb = mix(vec3(gray), aerochrome_color, 0.7); + } + else if(blockID == BLOCK_GRASS) { + // Special handling for grass block + float strength = 1.0 - Color.b; + Albedo.rgb = mix(Albedo.rgb, aerochrome_color, strength); + } + #ifdef AEROCHROME_WOOL_ENABLED + else if (blockID == BLOCK_SSS_WEAK_2 || blockID == BLOCK_CARPET) { + // Wool + Albedo.rgb = mix(Albedo.rgb, aerochrome_color, 0.3); + } + #endif + else if(blockID == BLOCK_WATER || (blockID >= 300 && blockID < 400)) + { + // IR Absorbsive? Dark. + Albedo.rgb = mix(Albedo.rgb, vec3(0.01, 0.08, 0.15), 0.5); + } + #endif Albedo.a = opaqueMasks; @@ -446,96 +446,96 @@ void main() { normal = viewToWorld(normal); float SSSAMOUNT = 0.0; - // #if (SSS_TYPE == 1 || SSS_TYPE == 2) && !defined HAND - // #ifdef ENTITIES - // #ifdef MOB_SSS - // /////// ----- SSS ON MOBS----- /////// - // // strong - // if(data_in.blockID == ENTITY_SSS_MEDIUM) SSSAMOUNT = 0.75; - // - // // medium - // - // // low - // else if(data_in.blockID == ENTITY_SSS_WEAK || data_in.blockID == ENTITY_PLAYER || data_in.blockID == ENTITY_CURRENT_PLAYER) SSSAMOUNT = 0.4; - // #endif - // #else - // #if defined SHADER_GRASS && !defined CUTOUT - // if (ShaderGrass) SSSAMOUNT = 0.65; - // else - // #endif -// - // /////// ----- SSS ON BLOCKS ----- /////// - // // strong - // if ( - // data_in.blockID == BLOCK_SSS_STRONG || data_in.blockID == BLOCK_SSS_STRONG3 || data_in.blockID == BLOCK_AIR_WAVING || data_in.blockID == BLOCK_SSS_STRONG_2 - // ) { - // SSSAMOUNT = 1.0; - // } - // // medium - // else if ( - // data_in.blockID == BLOCK_GROUND_WAVING || data_in.blockID == BLOCK_GROUND_WAVING_VERTICAL || - // data_in.blockID == BLOCK_GRASS_SHORT || data_in.blockID == BLOCK_GRASS_TALL_UPPER || data_in.blockID == BLOCK_GRASS_TALL_LOWER || - // data_in.blockID == BLOCK_SSS_WEAK || data_in.blockID == BLOCK_CACTUS || data_in.blockID == BLOCK_SSS_WEAK_2 || - // data_in.blockID == BLOCK_CELESTIUM || (data_in.blockID >= 269 && data_in.blockID <= 274) || data_in.blockID == BLOCK_SNOW_LAYERS || data_in.blockID == BLOCK_CARPET || - // data_in.blockID == BLOCK_AMETHYST_BUD_MEDIUM || data_in.blockID == BLOCK_AMETHYST_BUD_LARGE || data_in.blockID == BLOCK_AMETHYST_CLUSTER || - // data_in.blockID == BLOCK_BAMBOO || data_in.blockID == BLOCK_SAPLING || (data_in.blockID >= BLOCK_VINE_NORTH && data_in.blockID <= BLOCK_VINE_UP) || data_in.blockID == BLOCK_VINE_OTHER - // #ifdef MISC_BLOCK_SSS - // || data_in.blockID == BLOCK_SSS_WEIRD || data_in.blockID == BLOCK_GRASS - // #endif - // ) { - // SSSAMOUNT = 0.5; - // } - // #endif -// - // #ifdef BLOCKENTITIES - // /////// ----- SSS ON BLOCK ENTITIES----- /////// - // // strong -// - // // medium - // if(data_in.blockID == BLOCK_SSS_WEAK_3) SSSAMOUNT = 0.4; -// - // // low -// - // #endif - // #endif + #if (SSS_TYPE == 1 || SSS_TYPE == 2) && !defined HAND + #ifdef ENTITIES + #ifdef MOB_SSS + /////// ----- SSS ON MOBS----- /////// + // strong + if(blockID == ENTITY_SSS_MEDIUM) SSSAMOUNT = 0.75; + + // medium + + // low + else if(blockID == ENTITY_SSS_WEAK || blockID == ENTITY_PLAYER || blockID == ENTITY_CURRENT_PLAYER) SSSAMOUNT = 0.4; + #endif + #else + #if defined SHADER_GRASS && !defined CUTOUT + if (ShaderGrass) SSSAMOUNT = 0.65; + else + #endif + + /////// ----- SSS ON BLOCKS ----- /////// + // strong + if ( + blockID == BLOCK_SSS_STRONG || blockID == BLOCK_SSS_STRONG3 || blockID == BLOCK_AIR_WAVING || blockID == BLOCK_SSS_STRONG_2 + ) { + SSSAMOUNT = 1.0; + } + // medium + else if ( + blockID == BLOCK_GROUND_WAVING || blockID == BLOCK_GROUND_WAVING_VERTICAL || + blockID == BLOCK_GRASS_SHORT || blockID == BLOCK_GRASS_TALL_UPPER || blockID == BLOCK_GRASS_TALL_LOWER || + blockID == BLOCK_SSS_WEAK || blockID == BLOCK_CACTUS || blockID == BLOCK_SSS_WEAK_2 || + blockID == BLOCK_CELESTIUM || (blockID >= 269 && blockID <= 274) || blockID == BLOCK_SNOW_LAYERS || blockID == BLOCK_CARPET || + blockID == BLOCK_AMETHYST_BUD_MEDIUM || blockID == BLOCK_AMETHYST_BUD_LARGE || blockID == BLOCK_AMETHYST_CLUSTER || + blockID == BLOCK_BAMBOO || blockID == BLOCK_SAPLING || blockID == BLOCK_VINE || blockID == BLOCK_VINE_OTHER + #ifdef MISC_BLOCK_SSS + || blockID == BLOCK_SSS_WEIRD || blockID == BLOCK_GRASS + #endif + ) { + SSSAMOUNT = 0.5; + } + #endif + + #ifdef BLOCKENTITIES + /////// ----- SSS ON BLOCK ENTITIES----- /////// + // strong + + // medium + if(blockID == BLOCK_SSS_WEAK_3) SSSAMOUNT = 0.4; + + // low + + #endif + #endif float EMISSIVE = 0.0; - // #if EMISSIVE_TYPE == 1 || EMISSIVE_TYPE == 2 - // /////// ----- EMISSIVE STUFF ----- /////// -// - // // if(vNameTags > 0) EMISSIVE = 0.9; -// - // // normal block lightsources - // if(data_in.blockID >= 100 && data_in.blockID < 282) { - // EMISSIVE = 0.5; -// - // if(data_in.blockID == 266 || (data_in.blockID >= 276 && data_in.blockID <= 281)) EMISSIVE = 0.2; // sculk stuff -// - // else if(data_in.blockID == 195) EMISSIVE = 2.3; // glow lichen -// - // else if(data_in.blockID == 185) EMISSIVE = 1.5; // crying obsidian -// - // else if(data_in.blockID == 105) EMISSIVE = 2.0; // brewing stand - // - // else if(data_in.blockID == 236) EMISSIVE = 1.0; // respawn anchor -// - // else if(data_in.blockID == 101) EMISSIVE = 0.7; // large amethyst bud -// - // else if(data_in.blockID == 103) EMISSIVE = 1.0; // amethyst cluster -// - // else if(data_in.blockID == 244) EMISSIVE = 1.5; // soul fire - // } -// - // #if EMISSIVE_ORES > 0 - // if(data_in.blockID == 502) { - // EMISSIVE = EMISSIVE_ORES_STRENGTH; -// - // #ifndef HARDCODED_EMISSIVES_APPROX - // EMISSIVE *= getEmission(Albedo.rgb); - // #endif - // } - // #endif - // #endif + #if EMISSIVE_TYPE == 1 || EMISSIVE_TYPE == 2 + /////// ----- EMISSIVE STUFF ----- /////// + + // if(vNameTags > 0) EMISSIVE = 0.9; + + // normal block lightsources + if(blockID >= 100 && blockID < 282) { + EMISSIVE = 0.5; + + if(blockID == 266 || (blockID >= 276 && blockID <= 281)) EMISSIVE = 0.2; // sculk stuff + + else if(blockID == 195) EMISSIVE = 2.3; // glow lichen + + else if(blockID == 185) EMISSIVE = 1.5; // crying obsidian + + else if(blockID == 105) EMISSIVE = 2.0; // brewing stand + + else if(blockID == 236) EMISSIVE = 1.0; // respawn anchor + + else if(blockID == 101) EMISSIVE = 0.7; // large amethyst bud + + else if(blockID == 103) EMISSIVE = 1.0; // amethyst cluster + + else if(blockID == 244) EMISSIVE = 1.5; // soul fire + } + + #if EMISSIVE_ORES > 0 + if(blockID == 502) { + EMISSIVE = EMISSIVE_ORES_STRENGTH; + + #ifndef HARDCODED_EMISSIVES_APPROX + EMISSIVE *= getEmission(Albedo.rgb); + #endif + } + #endif + #endif vec4 SpecularTex = vec4(0.0); @@ -545,13 +545,13 @@ void main() { OutSpecular = vec4(0.0,0.0,0.0,0.0); OutSpecular.rg = SpecularTex.rg; - // #if EMISSIVE_ORES > 1 && EMISSIVE_TYPE > 1 - // if(data_in.blockID == 502) { - // SpecularTex.a = EMISSIVE_ORES_STRENGTH; - // - // SpecularTex.a *= getEmission(Albedo.rgb); - // } - // #endif + #if EMISSIVE_ORES > 1 && EMISSIVE_TYPE > 1 + if(blockID == 502) { + SpecularTex.a = EMISSIVE_ORES_STRENGTH; + + SpecularTex.a *= getEmission(Albedo.rgb); + } + #endif #if EMISSIVE_TYPE == 2 @@ -559,7 +559,7 @@ void main() { #endif // #ifdef MIRROR_IRON - // if(data_in.blockID == 504 || currentRenderedItemId == 504) { + // if(blockID == 504 || currentRenderedItemId == 504) { // OutSpecular.rg = vec2(1.0, 1.0); // Albedo.rgb = vec3(1.0); // } diff --git a/shaders/dimensions/voxels.vsh b/shaders/dimensions/voxels.vsh index b5f3788..9cb3cd6 100644 --- a/shaders/dimensions/voxels.vsh +++ b/shaders/dimensions/voxels.vsh @@ -34,7 +34,6 @@ out DATA { #endif vec3 block_normal; - flat int blockID; } data_out; #ifdef MC_NORMAL_MAP @@ -224,7 +223,6 @@ void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; - data_out.blockID = int(mc_Entity.x); /////// ----- COLOR STUFF ----- /////// data_out.color = gl_Color; diff --git a/shaders/dimensions/voxels_shadow.fsh b/shaders/dimensions/voxels_shadow.fsh index eafeed1..cc75e2a 100644 --- a/shaders/dimensions/voxels_shadow.fsh +++ b/shaders/dimensions/voxels_shadow.fsh @@ -1,4 +1,5 @@ #include "/lib/settings.glsl" +#include "/lib/SSBOs.glsl" in vec3 worldPos; in vec3 cageNormal; @@ -22,7 +23,13 @@ void main() { #else RayJob ray = RayJob(vec3(0), vec3(0), vec3(0), vec3(0), vec3(0), false); ray.origin = worldPos + cameraPosition - world_offset - 0.01f * cageNormal; - ray.direction = mat3(shadowModelViewInverse) * vec3(0.0f, 0.0f, -1.0f); + + #ifdef CUSTOM_MOON_ROTATION + ray.direction = mat3(customShadowMatrixInverseSSBO) * vec3(0.0f, 0.0f, -1.0f); + #else + ray.direction = mat3(shadowModelViewInverse) * vec3(0.0f, 0.0f, -1.0f); + #endif + ray_constraint = ivec3(ray.origin); trace_ray(ray); @@ -32,6 +39,33 @@ void main() { vec4 shadowColor = vec4(ray.result_color, 1.0f); + vec3 playerpos = ray.result_position - (cameraPosition - world_offset); + + #ifdef OVERWORLD_SHADER + #ifdef CUSTOM_MOON_ROTATION + vec3 viewPos = mat3(customShadowMatrixSSBO) * playerpos + customShadowMatrixSSBO[3].xyz; + #else + vec3 viewPos = mat3(shadowModelView) * playerpos + shadowModelView[3].xyz; + #endif + + vec4 ndc4 = shadowProjection * vec4(viewPos, 1.0f); + + ndc4.z /= 6.0; + vec3 screenPos = ndc4.xyz / ndc4.w * 0.5f + 0.5f; + #endif + + #if defined END_ISLAND_LIGHT && defined END_SHADER + vec4 ndc4 = customShadowPerspectiveSSBO * customShadowMatrixSSBO * vec4(playerpos, 1.0); + ndc4.z /= 6.0; + + vec3 screenPos = ndc4.xyz / ndc4.w * 0.5f + 0.5f; + #endif + + #if defined END_ISLAND_LIGHT && defined END_SHADER || defined OVERWORLD_SHADER + gl_FragDepth = screenPos.z; + #endif + gl_FragData[0] = shadowColor; #endif -} \ No newline at end of file +} + diff --git a/shaders/dimensions/voxels_shadow.vsh b/shaders/dimensions/voxels_shadow.vsh index 1efb455..2481c74 100644 --- a/shaders/dimensions/voxels_shadow.vsh +++ b/shaders/dimensions/voxels_shadow.vsh @@ -52,14 +52,12 @@ vec4 toClipSpace3(vec3 viewSpacePosition) { void main() { color = gl_Color.rgb; - #ifdef NETHER_SHADER - worldPos = vec3(0.0); - cageNormal = vec3(0.0); - - gl_Position = vec4(-1.0); - #else - cageNormal = gl_Normal; + worldPos = vec3(0.0); + cageNormal = gl_Normal; + + gl_Position = vec4(-1.0); + #if defined OVERWORLD_SHADER vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; worldPos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; @@ -76,6 +74,19 @@ void main() { gl_Position = toClipSpace3(position); #endif + gl_Position.z /= 6.0; + + #elif defined END_SHADER && defined END_ISLAND_LIGHT + vec3 shadowViewPos = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; + worldPos = mat3(shadowModelViewInverse) * shadowViewPos + shadowModelViewInverse[3].xyz; + + #ifdef PLANET_CURVATURE + float curvature = length(worldPos.xz) / (16*8); + worldPos.y -= curvature*curvature * CURVATURE_AMOUNT; + #endif + + gl_Position = customShadowPerspectiveSSBO * customShadowMatrixSSBO * vec4(worldPos, 1.0); + gl_Position.z /= 6.0; #endif } \ No newline at end of file diff --git a/shaders/dimensions/voxy.json b/shaders/dimensions/voxy.json index c1e2790..b106ee6 100644 --- a/shaders/dimensions/voxy.json +++ b/shaders/dimensions/voxy.json @@ -25,6 +25,10 @@ "ssbos": {4:"{ mat4 customShadowMatrixSSBO; + #ifdef PHOTONICS + mat4 customShadowMatrixInverseSSBO; + #endif + vec3 customMoonVecSSBO; vec3 customMoonVec2SSBO; diff --git a/shaders/lang/en_us.lang b/shaders/lang/en_us.lang index ccd35bc..041e48c 100644 --- a/shaders/lang/en_us.lang +++ b/shaders/lang/en_us.lang @@ -1,6 +1,6 @@ option.SHADER_VERSION_LABEL = §d§lECLIPSE§r - A Bliss Edit prefix.SHADER_VERSION_LABEL = V - value.SHADER_VERSION_LABEL.482 = 7.0.2 + value.SHADER_VERSION_LABEL.482 = 8.0.0 iris_extension.keybind.key0.name=Flashlight @@ -242,7 +242,7 @@ screen.Direct_Light = Direct Light option.LPV_REDSTONE_LIGHTS = Redstone Lights option.LPV_COLORED_CANDLES = Colored Candles option.LPV_NOSHADOW_HACK = Iris <= 1.7.0 Fix - option.LPV_VL_FOG_ILLUMINATION = Fog Light Propagation + option.LPV_VL_FOG_ILLUMINATION = Floodfill Fog Light Propagation value.LPV_VL_FOG_ILLUMINATION.0 = Off value.LPV_VL_FOG_ILLUMINATION.1 = Only Indoors value.LPV_VL_FOG_ILLUMINATION.2 = On @@ -821,6 +821,7 @@ screen.Resource_Pack_Support = Materials / Resource Pack Support suffix.DEFERRED_SSR_QUALITY = §§ samples option.DEFERRED_BACKGROUND_REFLECTION =^ Background reflections option.DEFERRED_ROUGH_REFLECTION =^ Rough reflections + option.DENOISED_REFLECTIONS =^ Denoised rough reflections option.FORWARD_SPECULAR = Reflections on water, glass option.FORWARD_SSR_QUALITY =^ Environment reflections value.FORWARD_SSR_QUALITY.0 =§c OFF @@ -1194,7 +1195,7 @@ screen.Post_Processing.comment = Configure settings for all post processing effe screen.TAA_OPTIONS.comment = Configure settings related to anti-aliasing. option.SCREENSHOT_MODE.comment = §aTHIS DOES NOT CHANGE GRAPHICS QUALITY IN ANY WAY§r. Toggle frame accumulation to get a low noise image. §bWhat is this?§r It stacks frames that happend onto the next frame that is generated, so it is like a long exposure photo. option.TAA.comment = Toggle temporal anti-aliasing. This removes all jagged edges on things, softens the image, and helps remove noise for many effects. This will cause ghosting or trailing because it uses past frames for extra information on the world. §aPERFORMANCE COST:§r low - option.BLEND_FACTOR.comment = Configure how much of frame history is used. high numbers means it relies less on frame history, so it may look flickery and noisy. low numbers rely more on frame history, so it may look less moisy, but more smudged with more trailing. + option.BLEND_FACTOR.comment = Configure how much of frame history is used. high numbers means it relies less on frame history, so it may look flickery and noisy. low numbers rely more on frame history, so it may look less noisy, but more smudged with more trailing. option.TAA_UPSCALING.comment = Toggle temporal upscaling. This retains a good amount of quality from a lower resolution image when it upscales. so you can still have a high looking resolution compared to typical upsampling and still have better performance. option.SCALE_FACTOR.comment = Configure from what fraction of your resolution to upscale from - §abelow 0.50x is not recommended, it is only allowed for fun!§r @@ -1275,9 +1276,21 @@ screen.VOXY_SETTINGS = Voxy Settings screen.PHOTONICS_SETTINGS = Photonics Settings option.PHOTONICS_ACTIVE = Enable Photonics + option.ENABLE_PHOTONICS_HANDHELD = Photonics Handheld Lighting + option.ENABLE_PHOTONICS_GI = Photonics Global Illumination + option.ENABLE_PHOTONICS_BLOCKLIGHT = Photonics Blocklight option.PHOTONICS_INDIRECT_BRIGHTNESS = GI Brightness option.PHOTONICS_GI_ONLY = GI Only - option.PHOTONICS_FLOODFILL_FOG_LIGHT_PROPAGATION = Fog Light Propagation (Floodfill!) + option.PHOTONICS_LIGHTING_MODE = Lighting Mode + option.PHOTONICS_ALPHA_MODE = Alpha Mode + option.PHOTONICS_MAX_SAMPLES = Max Samples + option.PHOTONICS_MAX_LIGHTS = Max Lights + option.VOXEL_REFLECTIONS_SOLID = World Space Reflections (Terrain) + option.VOXEL_REFLECTIONS_TRANSLUCENT = World Space Reflections (Water) + option.TRANSLUCENT_IN_REFLECTIONS = Translucents in Reflections + option.MIRROR_IRON = Iron Block Mirror + option.VOXEL_REFLECTIONS_FOG = Fog in Reflections + option.VOXEL_REFLECTIONS_LPV_FOG = Floodfill Fog Light Propagation in Reflections option.TRANSLUCENT_COLORED_SHADOWS.comment = §bWhat is this?§r This effect allows translucent things like stained glass to color the sunlight as it passes through it. §aPERFORMANCE COST:§r medium diff --git a/shaders/lang/zh_cn.lang b/shaders/lang/zh_cn.lang index 0859cd1..4438e4d 100644 --- a/shaders/lang/zh_cn.lang +++ b/shaders/lang/zh_cn.lang @@ -1,6 +1,6 @@ option.SHADER_VERSION_LABEL = §d§lECLIPSE§r - Bliss 编辑版 prefix.SHADER_VERSION_LABEL = 版本 - value.SHADER_VERSION_LABEL.482 = 7.0.1 + value.SHADER_VERSION_LABEL.482 = 8.0.0 # 如果你是来翻译的,这不是玩笑,这些选项的功能正如其名 profile.POTATO=§4土豆 (极低配置) diff --git a/shaders/lib/SSBOs.glsl b/shaders/lib/SSBOs.glsl index 7fcbc58..0325032 100644 --- a/shaders/lib/SSBOs.glsl +++ b/shaders/lib/SSBOs.glsl @@ -1,6 +1,10 @@ layout(std430, binding = 4) buffer SSBO1 { mat4 customShadowMatrixSSBO; // 64 bytes + #ifdef PHOTONICS + mat4 customShadowMatrixInverseSSBO; + #endif + vec3 customMoonVecSSBO; // 12 bytes vec3 customMoonVec2SSBO; // 12 bytes diff --git a/shaders/lib/blocks.glsl b/shaders/lib/blocks.glsl index ef1df0e..e633156 100644 --- a/shaders/lib/blocks.glsl +++ b/shaders/lib/blocks.glsl @@ -31,6 +31,7 @@ #define BLOCK_GRASS 85 #define BLOCK_SSS_STRONG3 87 #define BLOCK_CACTUS 89 +#define GRASS_BLOCK_SNOWY 90 #define BLOCK_AMETHYST_BUD_LARGE 101 #define BLOCK_AMETHYST_BUD_MEDIUM 102 #define BLOCK_AMETHYST_CLUSTER 103 diff --git a/shaders/lib/diffuse_lighting.glsl b/shaders/lib/diffuse_lighting.glsl index d7951b2..3cabbbd 100644 --- a/shaders/lib/diffuse_lighting.glsl +++ b/shaders/lib/diffuse_lighting.glsl @@ -7,7 +7,7 @@ if(hand) return 1.0; - vec3 WlightDir = normalize((gbufferModelViewInverse*vec4(lightDir, 1.0)) .xyz); + vec3 WlightDir = normalize((gbufferModelViewInverse*vec4(lightDir, 1.0)).xyz); float NdotL = dot(normals, WlightDir); NdotL = smoothstep(0.0, 0.2, abs(NdotL)); @@ -73,14 +73,13 @@ #if (defined IS_LPV_ENABLED || defined PHOTONICS && defined PHOTONICS && !defined PH_ENABLE_HANDHELD_LIGHT) && !defined VOXY_PROGRAM vec3 GetHandLight(const in int itemId, const in vec3 playerPos, inout float lightRange) { vec3 lightFinal = vec3(0.0); - vec3 lightColor = vec3(0.0); uint blockData = imageLoad(imgBlockData, itemId).r; vec4 lightColorRange = unpackUnorm4x8(blockData); - lightColor = srgbToLinear(lightColorRange.rgb); lightRange = lightColorRange.a * 255.0; if (lightRange > 0.0) { + vec3 lightColor = srgbToLinear(lightColorRange.rgb); float lightDist = length(playerPos+relativeEyePosition); // vec3 lightDir = playerPos / lightDist; const float NoL = 1.0;//max(dot(normal, lightDir), 0.0); @@ -98,6 +97,10 @@ uniform sampler2D radiosity_handheld; #endif +#ifdef BELTBORNE_LANTERNS +uniform int IEXT_beltborne_lanterns_Id; +#endif + vec3 doBlockLightLighting( vec3 lightColor, float lightmap, vec3 playerPos, vec3 lpvPos @@ -136,41 +139,58 @@ vec3 doBlockLightLighting( #ifdef Hand_Held_lights // create handheld lightsources - #if !defined ENABLE_PHOTONICS_HANDHELD || !defined PHOTONICS_LIGHT_PASS - if (heldItemId > 0){ - float lightRange = 0.0; - vec3 handLightCol = GetHandLight(heldItemId, playerPos, lightRange); + #if !defined PH_ENABLE_HANDHELD_LIGHT || !defined PHOTONICS_LIGHT_PASS + if (heldItemId > 0){ + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId, playerPos, lightRange); - #if defined MAIN_SHADOW_PASS && defined LPV_HANDHELD_SHADOWS - if (lightRange > 0.0 && firstPersonCamera) handLightCol *= SSRT_Handlight_Shadows(viewPos, depthCheck, -(viewPos + vec3(-0.25, 0.2, 0.0)), noise, normals, hand); - #endif + #if defined MAIN_SHADOW_PASS && defined LPV_HANDHELD_SHADOWS + if (lightRange > 0.0 && firstPersonCamera) handLightCol *= SSRT_Handlight_Shadows(viewPos, depthCheck, -(viewPos + vec3(-0.25, 0.2, 0.0)), noise, normals, hand); + #endif - #ifdef WEATHER - handLightCol *= 0.5; - #endif + #ifdef WEATHER + handLightCol *= 0.5; + #endif - blockLight += handLightCol; - } - + blockLight += handLightCol; + } + - if (heldItemId2 > 0){ - float lightRange2 = 0.0; - vec3 handLightCol2 = GetHandLight(heldItemId2, playerPos, lightRange2); - - #if defined MAIN_SHADOW_PASS && defined LPV_HANDHELD_SHADOWS - if (lightRange2 > 0.0 && firstPersonCamera) handLightCol2 *= SSRT_Handlight_Shadows(viewPos, depthCheck, -(viewPos + vec3(0.25, 0.2, 0.0)), noise, normals, hand); - #endif + if (heldItemId2 > 0){ + float lightRange2 = 0.0; + vec3 handLightCol2 = GetHandLight(heldItemId2, playerPos, lightRange2); + + #if defined MAIN_SHADOW_PASS && defined LPV_HANDHELD_SHADOWS + if (lightRange2 > 0.0 && firstPersonCamera) handLightCol2 *= SSRT_Handlight_Shadows(viewPos, depthCheck, -(viewPos + vec3(0.25, 0.2, 0.0)), noise, normals, hand); + #endif - #ifdef WEATHER - handLightCol2 *= 0.5; - #endif + #ifdef WEATHER + handLightCol2 *= 0.5; + #endif - blockLight += handLightCol2; - } + blockLight += handLightCol2; + } + + #ifdef BELTBORNE_LANTERNS + if (IEXT_beltborne_lanterns_Id > 0){ + float lightRange2 = 0.0; + vec3 handLightCol2 = GetHandLight(IEXT_beltborne_lanterns_Id, playerPos, lightRange2); + + #if defined MAIN_SHADOW_PASS && defined LPV_HANDHELD_SHADOWS + if (lightRange2 > 0.0 && firstPersonCamera) handLightCol2 *= SSRT_Handlight_Shadows(viewPos, depthCheck, -(viewPos + vec3(0.125, 0.2, 0.0)), noise, normals, hand); + #endif + + #ifdef WEATHER + handLightCol2 *= 0.5; + #endif + + blockLight += handLightCol2; + } + #endif #endif - #if defined PH_ENABLE_HANDHELD_LIGHT && !defined PH_ENABLE_BLOCKLIGHT && !defined PHOTONICS_LIGHT_PASS - vec3 ph_direct_hand = texture(radiosity_handheld, gl_FragCoord.xy*texelSize/RENDER_SCALE).xyz; + #if defined PH_ENABLE_HANDHELD_LIGHT && !defined PH_ENABLE_BLOCKLIGHT && defined PHOTONICS_INCLUDED + vec3 ph_direct_hand = sample_photonics_handheld(gl_FragCoord.xy*texelSize/RENDER_SCALE).xyz; blockLight += ph_direct_hand * 1.35; #endif #endif @@ -182,13 +202,13 @@ vec3 doBlockLightLighting( #endif { vec3 photonicsLight = vec3(0.0); + vec3 handLight = vec3(0.0); #if defined PH_ENABLE_HANDHELD_LIGHT - vec3 ph_direct_hand = texture(radiosity_handheld, gl_FragCoord.xy*texelSize/RENDER_SCALE).xyz; - vec3 handLight = ph_direct_hand * 1.35; + vec3 ph_direct_hand = sample_photonics_handheld(gl_FragCoord.xy*texelSize/RENDER_SCALE).xyz; + handLight = ph_direct_hand * 1.35; #else #ifdef Hand_Held_lights - vec3 handLight = vec3(0.0); if (heldItemId > 0){ float lightRange = 0.0; vec3 handLightCol = GetHandLight(heldItemId, playerPos, lightRange); @@ -219,14 +239,29 @@ vec3 doBlockLightLighting( handLight += handLightCol2; } + + #ifdef BELTBORNE_LANTERNS + if (IEXT_beltborne_lanterns_Id > 0){ + float lightRange2 = 0.0; + vec3 handLightCol3 = GetHandLight(IEXT_beltborne_lanterns_Id, playerPos, lightRange2); + + #if defined MAIN_SHADOW_PASS && defined LPV_HANDHELD_SHADOWS + if (lightRange2 > 0.0 && firstPersonCamera) handLightCol3 *= SSRT_Handlight_Shadows(viewPos, depthCheck, -(viewPos + vec3(0.125, 0.2, 0.0)), noise, normals, hand); + #endif + + #ifdef WEATHER + handLightCol3 *= 0.5; + #endif + + handLight += handLightCol3; + } + #endif #endif #endif #ifdef PH_ENABLE_BLOCKLIGHT - vec3 ph_direct = texture(radiosity_direct, gl_FragCoord.xy*texelSize/RENDER_SCALE).xyz; - vec4 ph_direct_soft = texture(radiosity_direct_soft, gl_FragCoord.xy*texelSize/RENDER_SCALE); + vec3 ph_direct = sample_photonics_direct(gl_FragCoord.xy*texelSize/RENDER_SCALE).xyz; photonicsLight += ph_direct; - photonicsLight += (ph_direct_soft.xyz / max(ph_direct_soft.w, 1.0f)); photonicsLight += lightColor * 2.5 * min(max(lightmap-0.999,0.0)/(1.0-0.999),1.0); #endif diff --git a/shaders/lib/oceans.glsl b/shaders/lib/oceans.glsl index cd1cba9..0601a69 100644 --- a/shaders/lib/oceans.glsl +++ b/shaders/lib/oceans.glsl @@ -99,35 +99,6 @@ float physics_waveHeight(vec2 position, int iterations, float factor, float time return height / waveSum * physics_oceanHeight * factor - physics_oceanHeight * factor * 0.5; } -vec2 physics_waveDirection(vec2 position, int iterations, float time) { - position = (position - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale; - float iter = 0.0; - float frequency = PHYSICS_FREQUENCY; - float speed = PHYSICS_SPEED; - float weight = 1.0; - float waveSum = 0.0; - float modifiedTime = time * PHYSICS_TIME_MULTIPLICATOR; - vec2 dx = vec2(0.0); - - for (int i = 0; i < iterations; i++) { - vec2 direction = vec2(sin(iter), cos(iter)); - float x = dot(direction, position) * frequency + modifiedTime * speed; - float wave = exp(sin(x) - 1.0); - float result = wave * cos(x); - vec2 force = result * weight * direction; - - dx += force / pow(weight, PHYSICS_W_DETAIL); - position -= force * PHYSICS_DRAG_MULT; - iter += PHYSICS_ITER_INC; - waveSum += weight; - weight *= PHYSICS_WEIGHT; - frequency *= PHYSICS_FREQUENCY_MULT; - speed *= PHYSICS_SPEED_MULT; - } - - return vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL)); -} - vec3 physics_waveNormal(const in vec2 position, const in vec2 direction, const in float factor, const in float time) { float oceanHeightFactor = physics_oceanHeight / 13.0; float totalFactor = oceanHeightFactor * factor; diff --git a/shaders/lib/overworld_fog.glsl b/shaders/lib/overworld_fog.glsl index 8c1c389..742123b 100644 --- a/shaders/lib/overworld_fog.glsl +++ b/shaders/lib/overworld_fog.glsl @@ -13,7 +13,7 @@ float densityAtPosFog(in vec3 pos){ } -float cloudVol(in vec3 pos, float maxDistance ){ +float cloudVol(in vec3 pos, float maxDistance){ float fogYstart = FOG_START_HEIGHT + 3.0; vec3 samplePos = pos*vec3(1.0,1./24.,1.0); @@ -200,14 +200,14 @@ vec4 GetVolumetricFog( shadowPos = shadowPos*vec3(0.5,0.5,0.5/6.0)+0.5; #ifdef TRANSLUCENT_COLORED_SHADOWS - sh = vec3(texture(shadowtex0, shadowPos).x); + sh = vec3(texture(shadowtex0HW, shadowPos).x); - if(texture(shadowtex1, shadowPos).x > shadowPos.z && sh.x < 1.0){ + if(texture(shadowtex1HW, shadowPos).x > shadowPos.z && sh.x < 1.0){ vec4 translucentShadow = texture(shadowcolor0, shadowPos.xy); if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001); } #else - sh = vec3(texture(shadow, shadowPos).x); + sh = vec3(texture(shadowtex0HW, shadowPos).x); #endif } diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl index 6935355..bc740e3 100644 --- a/shaders/lib/settings.glsl +++ b/shaders/lib/settings.glsl @@ -1174,11 +1174,17 @@ const vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631) // ----- PHOTONICS SETTINGS ----- // ////////////////////////////////// -#define VOXEL_REFLECTIONS +#define VOXEL_REFLECTIONS_TRANSLUCENT +#define VOXEL_REFLECTIONS_SOLID + +#define DENOISED_REFLECTIONS +#ifdef DENOISED_REFLECTIONS +#endif + #define PHOTONICS_ACTIVE -#if defined VOXEL_REFLECTIONS && defined PHOTONICS && defined PHOTONICS_ACTIVE +#if defined VOXEL_REFLECTIONS_TRANSLUCENT || defined VOXEL_REFLECTIONS_SOLID && defined PHOTONICS && defined PHOTONICS_ACTIVE #define LPV_ENABLED #define IS_LPV_ENABLED #endif @@ -1192,15 +1198,10 @@ const vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631) #undef PHOTONICS_ACTIVE #endif -// #define PHOTONICS_FLOODFILL_FOG_LIGHT_PROPAGATION - -#ifdef PHOTONICS_FLOODFILL_FOG_LIGHT_PROPAGATION -#endif - // TODO: THIS IS HORRENDOUS #define ENABLE_PHOTONICS_GI #define ENABLE_PHOTONICS_BLOCKLIGHT -#define ENABLE_PHOTONICS_HANDHELD +// #define ENABLE_PHOTONICS_HANDHELD #ifdef ENABLE_PHOTONICS_GI #endif @@ -1229,14 +1230,16 @@ const vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631) #endif #if defined PHOTONICS && defined PHOTONICS_ACTIVE + #undef DEPTH_WRITE_POM #undef VOXELIZE - #if !defined PHOTONICS_FLOODFILL_FOG_LIGHT_PROPAGATION && !defined VOXEL_REFLECTIONS && defined PH_ENABLE_BLOCKLIGHT + #if !defined LPV_VL_FOG_ILLUMINATION && !defined VOXEL_REFLECTIONS_TRANSLUCENT && !defined VOXEL_REFLECTIONS_SOLID && (defined PH_ENABLE_BLOCKLIGHT || defined ENABLE_PHOTONICS_HANDHELD) #undef IS_LPV_ENABLED #undef LPV_ENABLED #endif #else - #undef VOXEL_REFLECTIONS + #undef VOXEL_REFLECTIONS_TRANSLUCENT + #undef VOXEL_REFLECTIONS_SOLID #endif #define PHOTONICS_ALPHA_MODE BLOCK // [NONE BLOCK VOXEL] @@ -1245,12 +1248,15 @@ const vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631) #define PHOTONICS_INDIRECT_BRIGHTNESS 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.5 3.0 3.5 4.0 4.5 5.0] -#define VOXEL_REFLECTIONS_FOG -#define VOXEL_REFLECTIONS_LPV_FOG +// #define VOXEL_REFLECTIONS_FOG +// #define VOXEL_REFLECTIONS_LPV_FOG #ifdef VOXEL_REFLECTIONS_FOG #endif +#define PHOTONICS_LIGHTING_MODE RESTIR // [BASIC RESTIR] +// #define TRANSLUCENT_IN_REFLECTIONS + //////////////////////////////// // ----- DEBUG SETTINGS ----- // //////////////////////////////// diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl index 4600aa6..72c64bc 100644 --- a/shaders/lib/specular.glsl +++ b/shaders/lib/specular.glsl @@ -391,10 +391,10 @@ float ComputeVoxelShadowMap(inout vec3 directLightColor, vec3 playerPos, float m #ifdef TRANSLUCENT_COLORED_SHADOWS // determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth - float shadowDepthDiff = pow(clamp((texture(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); + float shadowDepthDiff = pow(clamp((texture(shadowtex1HW, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); // get opaque shadow data to get opaque data from translucent shadows. - float opaqueShadow = texture(shadowtex0, projectedShadowPosition).x; + float opaqueShadow = texture(shadowtex0HW, projectedShadowPosition).x; shadowmap += max(opaqueShadow, shadowDepthDiff); // get translucent shadow data @@ -411,7 +411,7 @@ float ComputeVoxelShadowMap(inout vec3 directLightColor, vec3 playerPos, float m translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff); #else - shadowmap += texture(shadow, projectedShadowPosition).x; + shadowmap += texture(shadowtex0HW, projectedShadowPosition.xy).x; #endif #ifdef BASIC_SHADOW_FILTER @@ -1162,10 +1162,10 @@ float ComputePhotonicsShadowMap(inout vec3 directLightColor, vec3 playerPos, flo #ifdef TRANSLUCENT_COLORED_SHADOWS // determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth - float shadowDepthDiff = pow(clamp((texture(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); + float shadowDepthDiff = pow(clamp((texture(shadowtex1HW, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0); // get opaque shadow data to get opaque data from translucent shadows. - float opaqueShadow = texture(shadowtex0, projectedShadowPosition).x; + float opaqueShadow = texture(shadowtex0HW, projectedShadowPosition).x; shadowmap += max(opaqueShadow, shadowDepthDiff); // get translucent shadow data @@ -1182,7 +1182,7 @@ float ComputePhotonicsShadowMap(inout vec3 directLightColor, vec3 playerPos, flo translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff); #else - shadowmap += texture(shadow, projectedShadowPosition).x; + shadowmap += texture(shadowtex0HW, projectedShadowPosition).x; #endif #ifdef BASIC_SHADOW_FILTER @@ -1223,7 +1223,7 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra job.direction = normalize(job.direction); vec3 direction_inv = 1.0f / job.direction; - float t0 = intersects_world(direction_inv, 16.0f * job.origin); + float t0 = ph_intersects_world(direction_inv, 16.0f * job.origin); if (t0 == -1.0f) { job.result_position = vec3(47823934.0f) - world_offset; return; @@ -1260,7 +1260,7 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra ivec3 w = ivec3(position); // TODO: maybe use uvec3, no negative check neccessary // ivec3 block_position = w >> 4; - if (!is_inside(position)) // outside of world? + if (!ph_is_inside(position)) // outside of world? return; // if ((job.result_hit = block_position == ray_target)) { // ray target reached? @@ -1273,14 +1273,14 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra int scale = 0; int entry = 0; - new_index.x = get_world_index((w >> 8) & 31); + new_index.x = ph_get_world_index((w >> 8) & 31); if (new_index.x != old_index.x) { // TODO: CRITICAL! UBOs are too tiny for 32x32x32 entries.x = root_array[new_index.x]; } if (entries.x < 0) { // found chunk? ivec3 block_pos = (w >> 4) & 15; - new_index.y = -entries.x + get_index(block_pos); + new_index.y = -entries.x + ph_get_index(block_pos); if (new_index.y != old_index.y) { entries.y = cb_array[new_index.y]; @@ -1290,7 +1290,7 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra block_index = block_data & 0xfff; block_index = block_index * (ph_byte_size / 4); - ph_result_sky_brightness = block_data >> 12; + ph_result_sky_brightness = block_data >> 13; block_id = cb_array[block_index]; voxel_index = block_index + 2; } else { @@ -1300,7 +1300,7 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra if (block_index != -1) { // found block ivec3 voxel_pos = w & 15; - new_index.z = voxel_index + get_index(voxel_pos); + new_index.z = voxel_index + ph_get_index(voxel_pos); if (new_index.z != old_index.z) { entries.z = cb_array[new_index.z]; @@ -1328,13 +1328,17 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra intersection_offset = max(ivec3(ray_direction_sign), 0); } else #endif - { - if ((-entries.z & 0x7f000000) == 0 || block_id == 85 || block_id == 13) { + { + #ifdef TRANSLUCENT_IN_REFLECTIONS + if ((-entries.z & 0x7f000000) == 0) + #endif + { job.result_hit = true; break; } - vec4 color = unpack_color(-entries.z); + #ifdef TRANSLUCENT_IN_REFLECTIONS + vec4 color = ph_unpack_color(-entries.z); if (previous_block_id != block_id) { if (color.a > 0.01 && translucentHits < 10u) { @@ -1352,10 +1356,11 @@ void trace_wsr(inout RayJob job, bool transparency, inout translucentHit[10] tra previous_block_id = block_id; } + #endif } scale = 4; - entry = to_fake_air_entry(block_pos); + entry = ph_to_fake_air_entry(block_pos); } else { scale = 0; entry = entries.z; } } else { scale = 4; entry = entries.y; previous_block_id = -1;} @@ -1712,14 +1717,14 @@ vec3 doBlockLightLightingVoxel( shadowPos = shadowPos*vec3(0.5,0.5,0.5/6.0)+0.5; #ifdef TRANSLUCENT_COLORED_SHADOWS - sh = vec3(texture(shadowtex0, shadowPos).x); + sh = vec3(texture(shadowtex0HW, shadowPos).x); - if(texture(shadowtex1, shadowPos).x > shadowPos.z && sh.x < 1.0){ + if(texture(shadowtex1HW, shadowPos).x > shadowPos.z && sh.x < 1.0){ vec4 translucentShadow = texture(shadowcolor0, shadowPos.xy); if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001); } #else - sh = vec3(texture(shadow, shadowPos).x); + sh = vec3(texture(shadowtex0HW, shadowPos).x); #endif } @@ -1851,17 +1856,17 @@ vec3 doBlockLightLightingVoxel( vec3 pos = vec3(spPos.xy*distortFactor, spPos.z); if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){ pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5; - // sh = texture( shadow, pos).x; + // sh = texture( shadowtex0HW, pos).x; #ifdef TRANSLUCENT_COLORED_SHADOWS - sh = vec3(texture(shadowtex0, pos).x); + sh = vec3(texture(shadowtex0HW, pos).x); - if(texture(shadowtex1, pos).x > pos.z && sh.x < 1.0){ + if(texture(shadowtex1HW, pos).x > pos.z && sh.x < 1.0){ vec4 translucentShadow = texture(shadowcolor0, pos.xy); if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001); } #else - sh = vec3(texture(shadow, pos).x); + sh = vec3(texture(shadowtex0HW, pos).x); #endif } @@ -2021,7 +2026,7 @@ vec4 photonicsReflection( ); translucentHit[10] translucentHitRays; - uint translucentHits; + uint translucentHits = 0u; int blockID = 0; translucentHitRays[0].hitColor = vec4(0.0); @@ -2054,6 +2059,7 @@ vec4 photonicsReflection( vec3 endPos = ray.result_position - rt_camera_position; vec3 endPosW = endPos + cameraPosition; + #ifdef TRANSLUCENT_IN_REFLECTIONS for (uint i = 0; i < translucentHits; i++) { vec4 sampleColor = translucentHitRays[i].hitColor; // return vec4(sampleColor.rgb, 1.0); @@ -2069,14 +2075,15 @@ vec4 photonicsReflection( if(color.a > 0.995) return color; } - backgroundTint = mix(normalize(translucentHitRays[0].hitColor.rgb+1e-7), vec3(1.0), min(max(0.1-translucentHitRays[0].hitColor.a,0.0) * 10.0,1.0)); - + if(hitTranslucent) backgroundTint = mix(normalize(translucentHitRays[0].hitColor.rgb+1e-7), vec3(1.0), min(max(0.1-translucentHitRays[0].hitColor.a,0.0) * 10.0,1.0)); + #endif + if (ray.result_hit) { vec4 sampleColor = vec4(toLinear(ray.result_color), 1.0); photonicsReflectionShading(sampleColor, ray.result_normal, endPosW, noise.y, DirectLightColor, AmbientLightColor, blockID, skylightmap); - #if defined VOXEL_REFLECTIONS_FOG && defined OVERWORLD_SHADER + #if defined VOXEL_REFLECTIONS_FOG && defined OVERWORLD_SHADER && defined TRANSLUCENT_IN_REFLECTIONS if(hitTranslucent && isEyeInWater != 1) { vec4 fog = raymarchWSRfog(translucentHitRays[0].hitPos + world_offset - cameraPosition, endPos, noise, DirectLightColor, indirectLight_fog, indirectLight, 3); @@ -2093,7 +2100,9 @@ vec4 photonicsReflection( } #if defined VOXEL_REFLECTIONS_FOG && defined OVERWORLD_SHADER + #ifdef TRANSLUCENT_IN_REFLECTIONS if(hitTranslucent && isEyeInWater != 1) endPos = translucentHitRays[0].hitPos + world_offset - cameraPosition; + #endif #ifdef VOXEL_REFLECTIONS_LPV_FOG vec4 LPVfog = raymarchWSR_LPV(origin, endPos, noise.x); @@ -2260,7 +2269,7 @@ float getReflectionVisibility(float f0, float roughness){ // derived from N and K from labPBR wiki https://shaderlabs.org/wiki/LabPBR_Material_Standard // using ((1.0 - N)^2 + K^2) / ((1.0 + N)^2 + K^2) -const vec3 HCM_F0 [8] = vec3[]( +const vec3 HCM_F0 [8] = vec3[8]( vec3(0.531228825312, 0.51235724246, 0.495828545714),// iron vec3(0.944229966045, 0.77610211732, 0.373402004593),// gold vec3(0.912298031535, 0.91385063144, 0.919680580954),// Aluminum @@ -2294,6 +2303,10 @@ vec3 specularReflections( , bool isWater , inout float reflectanceForAlpha #endif + #ifdef DEFERRED_SPECULAR + , inout vec4 specularOut + , inout float SunReflectionAlpha + #endif ,in vec4 flashLight_stuff @@ -2326,30 +2339,32 @@ vec3 specularReflections( vec3 reflectedVector_L = reflect(NplayerPos, normal); #endif - float VdotN = dot(-normalize(viewDir), vec3(0.0,0.0,1.0)); - float shlickFresnel = shlickFresnelRoughness(VdotN, roughness); + #if defined FORWARD_SPECULAR || defined DEFERRED_SPECULAR && !defined DENOISED_REFLECTIONS + float VdotN = dot(-normalize(viewDir), vec3(0.0,0.0,1.0)); + float shlickFresnel = shlickFresnelRoughness(VdotN, roughness); - // F0 < 230 dialectrics - // F0 >= 230 hardcoded metal f0 - // F0 == 255 use albedo for f0 - albedo = f0 == 1.0 ? sqrt(albedo) : albedo; - vec3 metalAlbedoTint = isMetal ? albedo : vec3(1.0); - // get F0 values for hardcoded metals. - vec3 hardCodedMetalsF0 = f0 == 1.0 ? albedo : HCM_F0[int(clamp(f0*255.0 - 229.5,0.0,7.0))]; - vec3 reflectance = isMetal ? hardCodedMetalsF0 : vec3(f0); - vec3 F0 = (reflectance + (1.0-reflectance) * shlickFresnel) * metalAlbedoTint; + // F0 < 230 dialectrics + // F0 >= 230 hardcoded metal f0 + // F0 == 255 use albedo for f0 + albedo = f0 == 1.0 ? sqrt(albedo) : albedo; + vec3 metalAlbedoTint = isMetal ? albedo : vec3(1.0); + // get F0 values for hardcoded metals. + vec3 hardCodedMetalsF0 = f0 == 1.0 ? albedo : HCM_F0[int(clamp(f0*255.0 - 229.5,0.0,7.0))]; + vec3 reflectance = isMetal ? hardCodedMetalsF0 : vec3(f0); + vec3 F0 = (reflectance + (1.0-reflectance) * shlickFresnel) * metalAlbedoTint; - #if defined FORWARD_SPECULAR - reflectanceForAlpha = clamp(dot(F0, vec3(0.3333333)), 0.0,1.0); - - #if defined SNELLS_WINDOW - if(isEyeInWater == 1 && isWater){ - // emulate how mojang did snells window in vibrant visuals because it works nicely tbh - float snellsWindow = min(max(0.54 - clamp(1.0 + VdotN,0,1),0.)/0.1,1.); - snellsWindow = 1.0-snellsWindow*snellsWindow; - snellsWindow *= snellsWindow*snellsWindow; - reflectanceForAlpha = f0 + (1.0-f0) * snellsWindow; - } + #if defined FORWARD_SPECULAR + reflectanceForAlpha = clamp(dot(F0, vec3(0.3333333)), 0.0,1.0); + + #if defined SNELLS_WINDOW + if(isEyeInWater == 1 && isWater){ + // emulate how mojang did snells window in vibrant visuals because it works nicely tbh + float snellsWindow = min(max(0.54 - clamp(1.0 + VdotN,0,1),0.)/0.1,1.); + snellsWindow = 1.0-snellsWindow*snellsWindow; + snellsWindow *= snellsWindow*snellsWindow; + reflectanceForAlpha = f0 + (1.0-f0) * snellsWindow; + } + #endif #endif #endif @@ -2360,6 +2375,10 @@ vec3 specularReflections( vec4 enviornmentReflection = vec4(0.0); float backgroundReflectMask = lightmap; + #if defined DEFERRED_SPECULAR && defined DENOISED_REFLECTIONS + SunReflectionAlpha = backgroundReflectMask; + #endif + #if (defined DEFERRED_BACKGROUND_REFLECTION || defined FORWARD_BACKGROUND_REFLECTION) || (DEFERRED_SSR_QUALITY > 0 || FORWARD_SSR_QUALITY > 0) if(reflectionVisibilty < 1.0){ #if defined DEFERRED_BACKGROUND_REFLECTION || defined FORWARD_BACKGROUND_REFLECTION @@ -2388,6 +2407,10 @@ vec3 specularReflections( #endif // darkening for metals. vec3 DarkenedDiffuseLighting = isMetal ? diffuseLighting * (1.0-enviornmentReflection.a) * (1.0-lightmap) : diffuseLighting; + + #if defined DEFERRED_SPECULAR && defined DENOISED_REFLECTIONS + vec3 DarkenedDiffuseLighting2 = isMetal ? vec3(0.0) : diffuseLighting; + #endif #else // darkening for metals. vec3 DarkenedDiffuseLighting = isMetal ? diffuseLighting * (1.0-lightmap) : diffuseLighting; @@ -2402,25 +2425,78 @@ vec3 specularReflections( specularReflections = mix(specularReflections, enviornmentReflection.rgb, enviornmentReflection.a); #endif - specularReflections = mix(DarkenedDiffuseLighting, specularReflections, F0); + #if defined DEFERRED_SPECULAR && defined DENOISED_REFLECTIONS + specularOut.rgb = specularReflections; + SunReflectionAlpha *= 1.0 - enviornmentReflection.a; + // specularOut.a = 1.0 - enviornmentReflection.a; + return DarkenedDiffuseLighting2; + #endif + #if defined FORWARD_SPECULAR || defined DEFERRED_SPECULAR && !defined DENOISED_REFLECTIONS + specularReflections = mix(DarkenedDiffuseLighting, specularReflections, F0); - // lerp back to diffuse lighting if the reflection has not been deemed visible enough - specularReflections = mix(specularReflections, diffuseLighting, reflectionVisibilty); + // lerp back to diffuse lighting if the reflection has not been deemed visible enough + specularReflections = mix(specularReflections, DarkenedDiffuseLighting, reflectionVisibilty); + #endif } #endif - - #if defined OVERWORLD_SHADER && SUN_SPECULAR_MULT > 0 - vec3 lightSourceReflection = backgroundReflectMask*SUN_SPECULAR_MULT * lightColor * GGX(normal, -NplayerPos, lightVec, roughness, reflectance, metalAlbedoTint); - #if DEFERRED_SSR_QUALITY > 0 || FORWARD_SSR_QUALITY > 0 - specularReflections += mix(lightSourceReflection, vec3(0.0), enviornmentReflection.a); - #else - specularReflections += lightSourceReflection*backgroundReflectMask; + + #if defined FORWARD_SPECULAR || defined DEFERRED_SPECULAR && !defined DENOISED_REFLECTIONS + #if defined OVERWORLD_SHADER && SUN_SPECULAR_MULT > 0 + vec3 lightSourceReflection = backgroundReflectMask*SUN_SPECULAR_MULT * lightColor * GGX(normal, -NplayerPos, lightVec, roughness, reflectance, metalAlbedoTint); + #if DEFERRED_SSR_QUALITY > 0 || FORWARD_SSR_QUALITY > 0 + specularReflections += lightSourceReflection * (1.0 - enviornmentReflection.a); + #else + specularReflections += lightSourceReflection; + #endif #endif - #endif - #if defined FLASHLIGHT_SPECULAR && (defined DEFERRED_SPECULAR || defined FORWARD_SPECULAR) - vec3 flashLightReflection = vec3(FLASHLIGHT_R,FLASHLIGHT_G,FLASHLIGHT_B) * flashLight_stuff.a * GGX(normal, -flashLight_stuff.xyz, -flashLight_stuff.xyz, roughness, reflectance, metalAlbedoTint); - specularReflections += flashLightReflection; + #if defined FLASHLIGHT_SPECULAR && (defined DEFERRED_SPECULAR || defined FORWARD_SPECULAR) + vec3 flashLightReflection = vec3(FLASHLIGHT_R,FLASHLIGHT_G,FLASHLIGHT_B) * flashLight_stuff.a * GGX(normal, -flashLight_stuff.xyz, -flashLight_stuff.xyz, roughness, reflectance, metalAlbedoTint); + specularReflections += flashLightReflection; + #endif + + if(!isHand && firstPersonCamera) { + if (heldItemId > 0){ + vec3 shiftedViewPos = viewPos + vec3(-0.25, 0.2, 0.0); + vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId, shiftedPlayerPos, lightRange); + + if(lightRange > 0.0) { + vec3 handheldReflection1 = handLightCol * GGX(normal, -shiftedPlayerPos, -shiftedPlayerPos, roughness, reflectance, metalAlbedoTint); + specularReflections += handheldReflection1; + } + } + + if (heldItemId2 > 0){ + vec3 shiftedViewPos = viewPos + vec3(0.25, 0.2, 0.0); + vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(heldItemId2, shiftedPlayerPos, lightRange); + + if(lightRange > 0.0) { + vec3 handheldReflection1 = handLightCol * GGX(normal, -shiftedPlayerPos, -shiftedPlayerPos, roughness, reflectance, metalAlbedoTint); + specularReflections += handheldReflection1; + } + } + + #ifdef BELTBORNE_LANTERNS + if (IEXT_beltborne_lanterns_Id > 0){ + vec3 shiftedViewPos = viewPos + vec3(0.15, 0.2, 0.0); + vec3 shiftedPlayerPos = mat3(gbufferModelViewInverse) * shiftedViewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + + float lightRange = 0.0; + vec3 handLightCol = GetHandLight(IEXT_beltborne_lanterns_Id, shiftedPlayerPos, lightRange); + + if(lightRange > 0.0) { + vec3 handheldReflection1 = handLightCol * GGX(normal, -shiftedPlayerPos, -shiftedPlayerPos, roughness, reflectance, metalAlbedoTint); + specularReflections += handheldReflection1; + } + } + #endif + } #endif return specularReflections; diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index 5dd472c..e3cdf67 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -842,14 +842,14 @@ vec4 raymarchCloud( shadowPos = shadowPos*vec3(0.5,0.5,0.5/6.0)+0.5; #ifdef TRANSLUCENT_COLORED_SHADOWS - sh = vec3(texture(shadowtex0, shadowPos).x); + sh = vec3(texture(shadowtex0HW, shadowPos).x); - if(texture(shadowtex1, shadowPos).x > shadowPos.z && sh.x < 1.0){ + if(texture(shadowtex1HW, shadowPos).x > shadowPos.z && sh.x < 1.0){ vec4 translucentShadow = texture(shadowcolor0, shadowPos.xy); if(translucentShadow.a < 0.9) sh = normalize(translucentShadow.rgb+0.0001); } #else - sh = vec3(texture(shadow, shadowPos).x); + sh = vec3(texture(shadowtex0HW, shadowPos).x); #endif } #else diff --git a/shaders/photonics/restir/lighting.fsh b/shaders/photonics/restir/lighting.fsh new file mode 100644 index 0000000..5800cc6 --- /dev/null +++ b/shaders/photonics/restir/lighting.fsh @@ -0,0 +1,99 @@ +#version 430 + +/* + -- INPUT VARIABLES -- +*/ +in vec4 direction_vert_out; + +/* + -- OUTPUT VARIABLES -- +*/ +layout(location = 2) out vec4 reservoir_frag_out; +layout(location = 3) out vec4 lighting_frag_out; + +#ifdef PH_ENABLE_HANDHELD_LIGHT +layout(location = 5) out vec4 handheld_frag_out; +#endif + +#include "/photonics/common/header.glsl" + +const float ph_spatial_reuse_radius = PH_RESTIR_SPATIAL_REUSE_RADIUS * PH_RENDER_SCALE; +vec3 ph_sun_direction = ph_signed_nudge(sun_direction); + +#include "/photonics/restir/restir.glsl" +#include "/photonics/common/ph_lighting_common.glsl" + +void main() { + if (!is_in_world()) { + lighting_frag_out = vec4(0f); + #ifdef PH_ENABLE_HANDHELD_LIGHT + handheld_frag_out = vec4(0f); + #endif + + return; + } + + load_fragment_variables(albedo, world_pos, block_normal, normal); + rt_pos = world_pos - world_offset; + bad_angle = is_bad_angle(world_pos, block_normal); + ph_frag_is_hand = ph_is_hand(); + + #ifdef PH_ENABLE_HANDHELD_LIGHT + sample_handheld(handheld_frag_out); + #endif + + #ifdef PH_ENABLE_GI + RAY_ITERATION_COUNT = 20; + + // Detect edge + // TODO: we probably should do fract(2.0f * base_position) + ivec3 inside = ivec3(lessThan(abs(fract(rt_pos) - 0.5f), vec3(0.48f))); + bool onEdge = inside.x + inside.y + inside.z <= 1; + + if (!onEdge) sample_indirect(); + + RAY_ITERATION_COUNT = 100; + #endif + + if (ph_light_count == 0) { + lighting_frag_out = vec4(0f); + return; + } + + Reservoir reservoir = reservoir_new(); + vec4 frag = texelFetch(radiosity_reservoirs, tex_coord, 0); + + reservoir_decode(reservoir, frag, rt_pos, false); + + Reservoir temp_reservoir = reservoir_new(); + + for (int i = 0; i < PH_RESTIR_SPATIAL_REUSE_SAMPLES; i++) { + vec2 offset = 2.0 * vec2(rand_next_float(), rand_next_float()) - 1f; + ivec2 uv = ivec2(tex_coord + offset * ph_spatial_reuse_radius); + + if (!reservoir_reuse(temp_reservoir, uv)) continue; + + reservoir_update( + reservoir, + temp_reservoir.light, + temp_reservoir.light.weight * temp_reservoir.weight * temp_reservoir.samples, + temp_reservoir.samples + ); + } + + if (reservoir_is_valid(reservoir)) { + #ifdef PH_RESTIR_SOFT_SHADOWS + light_sample_trace_hit(reservoir.light, true); + #else + light_sample_trace_hit(reservoir.light, false); + #endif + + reservoir_compute_weight(reservoir); + + reservoir_frag_out = reservoir_encode(reservoir); + lighting_frag_out = vec4(reservoir.light.color * reservoir.weight * result_tint_color, 1f); + } else { + reservoir_frag_out = reservoir_encode(reservoir); + lighting_frag_out = vec4(0f); + } +} \ No newline at end of file diff --git a/shaders/photonics/shader_interface.glsl b/shaders/photonics/shader_interface.glsl index e5565ed..c305dff 100644 --- a/shaders/photonics/shader_interface.glsl +++ b/shaders/photonics/shader_interface.glsl @@ -18,6 +18,8 @@ uniform float skyLightLevelSmooth; uniform int framemod8; uniform float sunElevation; +#include "/photonics/photonics.glsl" + #include "/lib/res_params.glsl" #include "/lib/util.glsl" diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 6db0cba..a37dc9b 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -30,7 +30,7 @@ sky = false iris.features.required = SSBO COMPUTE_SHADERS -iris.features.optional = ENTITY_TRANSLUCENT REVERSED_CULLING CUSTOM_IMAGES BLOCK_EMISSION_ATTRIBUTE TESSELLATION_SHADERS FADE_VARIABLE TEXTURE_FILTERING +iris.features.optional = SEPARATE_HARDWARE_SAMPLERS ENTITY_TRANSLUCENT REVERSED_CULLING CUSTOM_IMAGES BLOCK_EMISSION_ATTRIBUTE TESSELLATION_SHADERS FADE_VARIABLE TEXTURE_FILTERING #ifdef FLASHLIGHT iext_key.0 = TOGGLE @@ -58,7 +58,7 @@ iext.geometry.gbuffers_terrain=false #else photonics.enableBlockLight=false #endif - #ifdef ENABLE_PHOTONICS_HANDHELD + #if defined ENABLE_PHOTONICS_HANDHELD && !defined FLASHLIGHT photonics.enableHandheldLight=true #else photonics.enableHandheldLight=false @@ -66,6 +66,12 @@ iext.geometry.gbuffers_terrain=false photonics.maxLights = PHOTONICS_MAX_LIGHTS photonics.maxSamples = PHOTONICS_MAX_SAMPLES photonics.alphaMode = PHOTONICS_ALPHA_MODE + + #if !defined ENABLE_PHOTONICS_GI && !defined ENABLE_PHOTONICS_BLOCKLIGHT && !defined ENABLE_PHOTONICS_HANDHELD + photonics.lightingMode = OFF + #else + photonics.lightingMode = PHOTONICS_LIGHTING_MODE + #endif #endif #ifdef REALMOON @@ -185,9 +191,13 @@ program.world1/gbuffers_block_translucent.enabled = TRANSLUCENT_ENTITIES && IS_I program.world-1/dh_terrain.enabled = false program.world-1/dh_water.enabled = false #endif -program.world0/composite4.enabled = TAA_UPSCALING -program.world1/composite4.enabled = TAA_UPSCALING -program.world-1/composite4.enabled = TAA_UPSCALING +program.world0/composite5.enabled = TAA_UPSCALING +program.world1/composite5.enabled = TAA_UPSCALING +program.world-1/composite5.enabled = TAA_UPSCALING + +program.world0/composite2.enabled = DENOISED_REFLECTIONS && DEFERRED_SPECULAR && DEFERRED_ROUGH_REFLECTION +program.world1/composite2.enabled = DENOISED_REFLECTIONS && DEFERRED_SPECULAR && DEFERRED_ROUGH_REFLECTION +program.world-1/composite2.enabled = DENOISED_REFLECTIONS && DEFERRED_SPECULAR && DEFERRED_ROUGH_REFLECTION #if RESOURCEPACK_SKY == 0 && !defined VOXY program.world0/deferred2.enabled = false @@ -234,10 +244,10 @@ blend.gbuffers_entities_translucent.colortex11 = off # blend.colortex4 = off blend.composite.colortex5 = off blend.deferred1.colortex9 = off -blend.composite.colortex9 = off -blend.composite3.colortex9 = off -blend.composite.colortex13 = off -blend.composite.colortex14 = off +blend.composite1.colortex9 = off +blend.composite4.colortex9 = off +blend.composite1.colortex13 = off +blend.composite1.colortex14 = off # Alpha test alphaTest.gbuffers_weather = off @@ -332,7 +342,7 @@ SHADER_VERSION_LABEL \ screen.SPECULAR.columns=1 screen.SPECULAR = \ - QUARTER_RES_SSR SUN_SPECULAR_MULT ROUGHNESS_THRESHOLD DEFERRED_SPECULAR DEFERRED_SSR_QUALITY DEFERRED_BACKGROUND_REFLECTION DEFERRED_ROUGH_REFLECTION FORWARD_SPECULAR FORWARD_SSR_QUALITY FORWARD_BACKGROUND_REFLECTION FORWARD_ROUGH_REFLECTION + QUARTER_RES_SSR SUN_SPECULAR_MULT ROUGHNESS_THRESHOLD DEFERRED_SPECULAR DEFERRED_SSR_QUALITY DEFERRED_BACKGROUND_REFLECTION DEFERRED_ROUGH_REFLECTION DENOISED_REFLECTIONS FORWARD_SPECULAR FORWARD_SSR_QUALITY FORWARD_BACKGROUND_REFLECTION FORWARD_ROUGH_REFLECTION screen.Subsurface_Scattering.columns=1 screen.Subsurface_Scattering = SSS_TYPE_SETTING sss_density_multiplier sss_absorbance_multiplier LabSSS_Curve MISC_BLOCK_SSS MOB_SSS Ambient_SSS ambientsss_brightness SCREENSPACE_DIRECT_SSS_BLENDING @@ -560,8 +570,8 @@ SHADER_VERSION_LABEL \ ######## MOD SUPPORT SETTINGS screen.Mod_support = [DISTANT_HORIZONS_SETTINGS] [PHYSICS_MOD_OCEAN] [VOXY_SETTINGS] CAELUM_SUPPORT [PHOTONICS_SETTINGS] - screen.PHOTONICS_SETTINGS.columns = 1 - screen.PHOTONICS_SETTINGS = PHOTONICS_ACTIVE PHOTONICS_MAX_SAMPLES PHOTONICS_MAX_LIGHTS PHOTONICS_INDIRECT_BRIGHTNESS PHOTONICS_ALPHA_MODE PHOTONICS_FLOODFILL_FOG_LIGHT_PROPAGATION VOXEL_REFLECTIONS MIRROR_IRON VOXEL_REFLECTIONS_FOG VOXEL_REFLECTIONS_LPV_FOG + screen.PHOTONICS_SETTINGS.columns = 2 + screen.PHOTONICS_SETTINGS = PHOTONICS_ACTIVE PHOTONICS_LIGHTING_MODE PHOTONICS_ALPHA_MODE ENABLE_PHOTONICS_HANDHELD ENABLE_PHOTONICS_GI ENABLE_PHOTONICS_BLOCKLIGHT PHOTONICS_INDIRECT_BRIGHTNESS PHOTONICS_MAX_SAMPLES PHOTONICS_MAX_LIGHTS LPV_VL_FOG_ILLUMINATION VOXEL_REFLECTIONS_SOLID VOXEL_REFLECTIONS_TRANSLUCENT TRANSLUCENT_IN_REFLECTIONS MIRROR_IRON VOXEL_REFLECTIONS_FOG VOXEL_REFLECTIONS_LPV_FOG screen.DISTANT_HORIZONS_SETTINGS.columns = 1 screen.DISTANT_HORIZONS_SETTINGS = DH_OVERDRAW_PREVENTION OVERDRAW_MAX_DISTANCE DH_CHUNK_FADING DH_AMBIENT_OCCLUSION DH_SUBSURFACE_SCATTERING DH_SCREENSPACE_REFLECTIONS DH_TAA_JITTER DH_NOISE_TEXTURE NOISE_RESOLUTION NOISE_INTENSITY NOISE_DROPOFF DISTANT_HORIZONS_SHADOWMAP shadowDistance shadowMapResolution TOGGLE_VL_FOG VOLUMETRIC_CLOUDS diff --git a/shaders/world-1/composite12.fsh b/shaders/world-1/composite12.fsh new file mode 100644 index 0000000..2127413 --- /dev/null +++ b/shaders/world-1/composite12.fsh @@ -0,0 +1,5 @@ +#version 430 compatibility + +#define NETHER_SHADER + +#include "/dimensions/composite12.fsh" \ No newline at end of file diff --git a/shaders/world-1/composite12.vsh b/shaders/world-1/composite12.vsh new file mode 100644 index 0000000..71581ac --- /dev/null +++ b/shaders/world-1/composite12.vsh @@ -0,0 +1,5 @@ +#version 430 compatibility + +#define NETHER_SHADER + +#include "/dimensions/composite12.vsh" \ No newline at end of file diff --git a/shaders/world0/composite12.fsh b/shaders/world0/composite12.fsh new file mode 100644 index 0000000..bffc98f --- /dev/null +++ b/shaders/world0/composite12.fsh @@ -0,0 +1,5 @@ +#version 430 compatibility + +#define OVERWORLD_SHADER + +#include "/dimensions/composite12.fsh" \ No newline at end of file diff --git a/shaders/world0/composite12.vsh b/shaders/world0/composite12.vsh new file mode 100644 index 0000000..0d48cc0 --- /dev/null +++ b/shaders/world0/composite12.vsh @@ -0,0 +1,5 @@ +#version 430 compatibility + +#define OVERWORLD_SHADER + +#include "/dimensions/composite12.vsh" \ No newline at end of file diff --git a/shaders/world0/shadow.vsh b/shaders/world0/shadow.vsh index c34d8b8..921684a 100644 --- a/shaders/world0/shadow.vsh +++ b/shaders/world0/shadow.vsh @@ -10,6 +10,9 @@ #define RENDER_SHADOW +uniform float alphaTestRef; +uniform vec3 previousCameraPosition; +// #define SAVE_VOXEL_STUFF /* !! DO NOT REMOVE !! @@ -58,6 +61,23 @@ uniform float shadowMaxProj; uniform int blockEntityId; uniform int entityId; +//encoding by jodie +float encodeVec2(vec2 a){ + const vec2 constant1 = vec2( 1., 256.) / 65535.; + vec2 temp = floor( a * 255. ); + return temp.x*constant1.x+temp.y*constant1.y; +} +float encodeVec2(float x,float y){ + return encodeVec2(vec2(x,y)); +} +vec3 viewToWorld(vec3 viewPos) { + vec4 pos; + pos.xyz = viewPos; + pos.w = 0.0; + pos = shadowModelViewInverse * pos; + return pos.xyz; +} + #include "/lib/Shadow_Params.glsl" #include "/lib/bokeh.glsl" #include "/lib/blocks.glsl" @@ -142,13 +162,6 @@ vec4 toClipSpace3(vec3 viewSpacePosition) { return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),1.0); } -vec3 viewToWorld(vec3 viewPos) { - vec4 pos; - pos.xyz = viewPos; - pos.w = 0.0; - pos = shadowModelViewInverse * pos; - return pos.xyz; -} // uniform int renderStage; diff --git a/shaders/world0_with_aether_flag/composite12.fsh b/shaders/world0_with_aether_flag/composite12.fsh new file mode 100644 index 0000000..d2a50a5 --- /dev/null +++ b/shaders/world0_with_aether_flag/composite12.fsh @@ -0,0 +1,6 @@ +#version 430 compatibility + +#define OVERWORLD_SHADER +#define AETHER_FLAG + +#include "/dimensions/composite12.fsh" \ No newline at end of file diff --git a/shaders/world0_with_aether_flag/composite12.vsh b/shaders/world0_with_aether_flag/composite12.vsh new file mode 100644 index 0000000..22be04c --- /dev/null +++ b/shaders/world0_with_aether_flag/composite12.vsh @@ -0,0 +1,6 @@ +#version 430 compatibility + +#define OVERWORLD_SHADER +#define AETHER_FLAG + +#include "/dimensions/composite12.vsh" \ No newline at end of file diff --git a/shaders/world0_with_twilight_forest_flag/composite12.fsh b/shaders/world0_with_twilight_forest_flag/composite12.fsh new file mode 100644 index 0000000..b22622a --- /dev/null +++ b/shaders/world0_with_twilight_forest_flag/composite12.fsh @@ -0,0 +1,6 @@ +#version 430 compatibility + +#define OVERWORLD_SHADER +#define TWILIGHT_FOREST_FLAG + +#include "/dimensions/composite12.fsh" \ No newline at end of file diff --git a/shaders/world0_with_twilight_forest_flag/composite12.vsh b/shaders/world0_with_twilight_forest_flag/composite12.vsh new file mode 100644 index 0000000..a6f92f3 --- /dev/null +++ b/shaders/world0_with_twilight_forest_flag/composite12.vsh @@ -0,0 +1,6 @@ +#version 430 compatibility + +#define OVERWORLD_SHADER +#define TWILIGHT_FOREST_FLAG + +#include "/dimensions/composite12.vsh" \ No newline at end of file diff --git a/shaders/world1/composite12.fsh b/shaders/world1/composite12.fsh new file mode 100644 index 0000000..8cbe700 --- /dev/null +++ b/shaders/world1/composite12.fsh @@ -0,0 +1,5 @@ +#version 430 compatibility + +#define END_SHADER + +#include "/dimensions/composite12.fsh" \ No newline at end of file diff --git a/shaders/world1/composite12.vsh b/shaders/world1/composite12.vsh new file mode 100644 index 0000000..14cad22 --- /dev/null +++ b/shaders/world1/composite12.vsh @@ -0,0 +1,5 @@ +#version 430 compatibility + +#define END_SHADER + +#include "/dimensions/composite12.vsh" \ No newline at end of file