From 848cccd9daaa599492f78ac395bedd2955707821 Mon Sep 17 00:00:00 2001 From: Xonk Date: Thu, 3 Aug 2023 00:23:29 -0400 Subject: [PATCH] combine end and nether shaders into one group of programs. for my own ease of use. --- shaders/composite1.fsh | 2 +- .../all_particles.fsh | 45 +- .../all_particles.vsh | 0 .../{programs => dimensions}/all_solid.fsh | 0 .../{programs => dimensions}/all_solid.vsh | 0 .../all_translucent.fsh | 8 +- .../all_translucent.vsh | 0 shaders/dimensions/composite.fsh | 669 ++++++++++++++++++ shaders/dimensions/composite.vsh | 49 ++ shaders/dimensions/composite1.fsh | 129 ++++ shaders/dimensions/composite1.vsh | 20 + shaders/dimensions/composite2.fsh | 305 ++++++++ shaders/dimensions/composite2.vsh | 17 + shaders/dimensions/composite3.fsh | 350 +++++++++ shaders/dimensions/composite3.vsh | 17 + shaders/dimensions/composite4.fsh | 42 ++ .../composite4.vsh} | 2 - .../composite5.fsh} | 3 - .../composite5.vsh} | 2 - .../composite6.fsh} | 4 - .../composite6.vsh} | 3 - .../composite7.fsh} | 5 - .../composite7.vsh} | 3 +- .../composite8.fsh} | 3 - shaders/dimensions/composite8.vsh | 15 + .../composite9.fsh} | 14 +- .../composite9.vsh} | 3 - shaders/dimensions/deferred.fsh | 110 +++ shaders/dimensions/deferred.vsh | 104 +++ .../deferred1.fsh} | 2 - .../deferred1.vsh} | 2 - shaders/dimensions/final.fsh | 139 ++++ .../composite15.vsh => dimensions/final.vsh} | 20 - shaders/gbuffers_all_particles.fsh | 2 +- shaders/gbuffers_all_translucent.fsh | 2 +- shaders/lib/diffuse_lighting.glsl | 100 ++- shaders/lib/end_fog.glsl | 11 +- shaders/lib/nether_fog.glsl | 5 +- shaders/lib/specular.glsl | 2 +- shaders/world-1/composite.fsh | 5 + shaders/world-1/composite.vsh | 5 + shaders/world-1/composite1.fsh | 5 + shaders/world-1/composite1.vsh | 5 + shaders/world-1/composite15.fsh | 107 --- shaders/world-1/composite2.fsh | 650 +---------------- shaders/world-1/composite2.vsh | 50 +- shaders/world-1/composite3.fsh | 128 +--- shaders/world-1/composite3.vsh | 36 +- shaders/world-1/composite4.fsh | 5 + shaders/world-1/composite4.vsh | 5 + shaders/world-1/composite5.fsh | 5 + shaders/world-1/composite5.vsh | 5 + shaders/world-1/composite6.fsh | 308 +------- shaders/world-1/composite6.vsh | 18 +- shaders/world-1/composite7.fsh | 5 + shaders/world-1/composite7.vsh | 5 + shaders/world-1/composite8.fsh | 353 +-------- shaders/world-1/composite8.vsh | 19 +- shaders/world-1/composite9.fsh | 44 +- shaders/world-1/composite9.vsh | 16 +- shaders/world-1/deferred.fsh | 91 +-- shaders/world-1/deferred.vsh | 107 +-- shaders/world-1/deferred1.fsh | 5 + shaders/world-1/deferred1.vsh | 5 + shaders/world-1/final.fsh | 108 +-- shaders/world-1/final.vsh | 19 +- shaders/world-1/gbuffers_basic.fsh | 5 +- shaders/world-1/gbuffers_basic.vsh | 4 +- shaders/world-1/gbuffers_beaconbeam.fsh | 34 +- shaders/world-1/gbuffers_beaconbeam.vsh | 4 - shaders/world-1/gbuffers_block.fsh | 4 +- shaders/world-1/gbuffers_block.vsh | 5 +- shaders/world-1/gbuffers_entities.fsh | 4 +- shaders/world-1/gbuffers_entities.vsh | 4 +- shaders/world-1/gbuffers_hand.fsh | 5 +- shaders/world-1/gbuffers_hand.vsh | 4 +- shaders/world-1/gbuffers_hand_water.fsh | 6 +- shaders/world-1/gbuffers_hand_water.vsh | 6 +- shaders/world-1/gbuffers_skybasic.fsh | 6 +- shaders/world-1/gbuffers_skybasic.vsh | 11 +- shaders/world-1/gbuffers_skytextured.fsh | 21 +- shaders/world-1/gbuffers_skytextured.vsh | 31 - shaders/world-1/gbuffers_spidereyes.fsh | 36 +- shaders/world-1/gbuffers_spidereyes.vsh | 5 - shaders/world-1/gbuffers_terrain.fsh | 4 +- shaders/world-1/gbuffers_terrain.vsh | 4 +- shaders/world-1/gbuffers_textured.fsh | 5 +- shaders/world-1/gbuffers_textured.vsh | 5 +- shaders/world-1/gbuffers_textured_lit.fsh | 4 +- shaders/world-1/gbuffers_textured_lit.vsh | 5 +- shaders/world-1/gbuffers_water.fsh | 5 +- shaders/world-1/gbuffers_water.vsh | 6 +- shaders/world1/composite.fsh | 637 +---------------- shaders/world1/composite.vsh | 50 +- shaders/world1/composite1.fsh | 5 + shaders/world1/composite1.vsh | 5 + shaders/world1/composite2.fsh | 140 +--- shaders/world1/composite2.vsh | 21 +- shaders/world1/composite3.fsh | 307 +------- shaders/world1/composite3.vsh | 18 +- shaders/world1/composite4.fsh | 353 +-------- shaders/world1/composite4.vsh | 19 +- shaders/world1/composite5.fsh | 44 +- shaders/world1/composite5.vsh | 16 +- shaders/world1/composite6.fsh | 44 +- shaders/world1/composite6.vsh | 16 +- shaders/world1/composite7.fsh | 60 +- shaders/world1/composite7.vsh | 19 +- shaders/world1/composite8.fsh | 60 +- shaders/world1/composite8.vsh | 20 +- shaders/world1/composite9.fsh | 102 +-- shaders/world1/composite9.vsh | 16 +- shaders/world1/deferred.fsh | 109 +-- shaders/world1/deferred.vsh | 195 +---- shaders/world1/deferred1.fsh | 5 + shaders/world1/deferred1.vsh | 5 + shaders/world1/deferred2.fsh | 30 - shaders/world1/deferred2.vsh | 11 - shaders/world1/final.fsh | 108 +-- shaders/world1/final.vsh | 20 +- shaders/world1/gbuffers_basic.fsh | 5 +- shaders/world1/gbuffers_basic.vsh | 5 +- shaders/world1/gbuffers_block.fsh | 5 +- shaders/world1/gbuffers_block.vsh | 5 +- shaders/world1/gbuffers_entities.fsh | 4 +- shaders/world1/gbuffers_entities.vsh | 5 +- shaders/world1/gbuffers_hand.fsh | 4 +- shaders/world1/gbuffers_hand.vsh | 4 +- shaders/world1/gbuffers_hand_water.fsh | 4 +- shaders/world1/gbuffers_hand_water.vsh | 4 +- shaders/world1/gbuffers_terrain.fsh | 4 +- shaders/world1/gbuffers_terrain.vsh | 4 +- shaders/world1/gbuffers_textured.fsh | 5 +- shaders/world1/gbuffers_textured.vsh | 5 +- shaders/world1/gbuffers_textured_lit.fsh | 4 +- shaders/world1/gbuffers_textured_lit.vsh | 5 +- shaders/world1/gbuffers_water.fsh | 5 +- shaders/world1/gbuffers_water.vsh | 4 +- 138 files changed, 2362 insertions(+), 4710 deletions(-) rename shaders/{programs => dimensions}/all_particles.fsh (72%) rename shaders/{programs => dimensions}/all_particles.vsh (100%) rename shaders/{programs => dimensions}/all_solid.fsh (100%) rename shaders/{programs => dimensions}/all_solid.vsh (100%) rename shaders/{programs => dimensions}/all_translucent.fsh (99%) rename shaders/{programs => dimensions}/all_translucent.vsh (100%) create mode 100644 shaders/dimensions/composite.fsh create mode 100644 shaders/dimensions/composite.vsh create mode 100644 shaders/dimensions/composite1.fsh create mode 100644 shaders/dimensions/composite1.vsh create mode 100644 shaders/dimensions/composite2.fsh create mode 100644 shaders/dimensions/composite2.vsh create mode 100644 shaders/dimensions/composite3.fsh create mode 100644 shaders/dimensions/composite3.vsh create mode 100644 shaders/dimensions/composite4.fsh rename shaders/{world-1/composite14.vsh => dimensions/composite4.vsh} (98%) rename shaders/{world-1/composite10.fsh => dimensions/composite5.fsh} (97%) rename shaders/{world-1/composite10.vsh => dimensions/composite5.vsh} (98%) rename shaders/{world-1/composite11.fsh => dimensions/composite6.fsh} (97%) rename shaders/{world-1/composite12.vsh => dimensions/composite6.vsh} (98%) rename shaders/{world-1/composite12.fsh => dimensions/composite7.fsh} (97%) rename shaders/{world-1/composite11.vsh => dimensions/composite7.vsh} (98%) rename shaders/{world-1/composite14.fsh => dimensions/composite8.fsh} (97%) create mode 100644 shaders/dimensions/composite8.vsh rename shaders/{world1/composite10.fsh => dimensions/composite9.fsh} (97%) rename shaders/{world1/composite10.vsh => dimensions/composite9.vsh} (93%) create mode 100644 shaders/dimensions/deferred.fsh create mode 100644 shaders/dimensions/deferred.vsh rename shaders/{world-1/deferred2.fsh => dimensions/deferred1.fsh} (94%) rename shaders/{world-1/deferred2.vsh => dimensions/deferred1.vsh} (83%) create mode 100644 shaders/dimensions/final.fsh rename shaders/{world-1/composite15.vsh => dimensions/final.vsh} (58%) create mode 100644 shaders/world-1/composite.fsh create mode 100644 shaders/world-1/composite.vsh create mode 100644 shaders/world-1/composite1.fsh create mode 100644 shaders/world-1/composite1.vsh delete mode 100644 shaders/world-1/composite15.fsh create mode 100644 shaders/world-1/composite4.fsh create mode 100644 shaders/world-1/composite4.vsh create mode 100644 shaders/world-1/composite5.fsh create mode 100644 shaders/world-1/composite5.vsh create mode 100644 shaders/world-1/composite7.fsh create mode 100644 shaders/world-1/composite7.vsh create mode 100644 shaders/world-1/deferred1.fsh create mode 100644 shaders/world-1/deferred1.vsh create mode 100644 shaders/world1/composite1.fsh create mode 100644 shaders/world1/composite1.vsh create mode 100644 shaders/world1/deferred1.fsh create mode 100644 shaders/world1/deferred1.vsh delete mode 100644 shaders/world1/deferred2.fsh delete mode 100644 shaders/world1/deferred2.vsh diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh index 2c212ab..2f67789 100644 --- a/shaders/composite1.fsh +++ b/shaders/composite1.fsh @@ -151,7 +151,7 @@ vec3 viewToWorld(vec3 viewPosition) { #include "/lib/volumetricClouds.glsl" #include "/lib/waterBump.glsl" -#define OVERWORLD +#define OVERWORLD_SHADER #include "/lib/specular.glsl" #include "/lib/diffuse_lighting.glsl" diff --git a/shaders/programs/all_particles.fsh b/shaders/dimensions/all_particles.fsh similarity index 72% rename from shaders/programs/all_particles.fsh rename to shaders/dimensions/all_particles.fsh index 9b748fa..af7eed5 100644 --- a/shaders/programs/all_particles.fsh +++ b/shaders/dimensions/all_particles.fsh @@ -2,21 +2,13 @@ varying vec4 lmtexcoord; varying vec4 color; -flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) -flat varying vec3 avgAmbient; - -uniform vec3 sunVec; -flat varying vec3 WsunVec; - uniform sampler2D texture; -uniform sampler2DShadow shadow; -uniform sampler2D gaux1; -uniform sampler2D noisetex; -uniform float frameTimeCounter; -uniform ivec2 eyeBrightnessSmooth; -uniform vec2 texelSize; -uniform float rainStrength; +uniform sampler2D noisetex; + +uniform sampler2D colortex4; + + uniform mat4 gbufferProjectionInverse; uniform mat4 gbufferModelViewInverse; uniform mat4 gbufferModelView; @@ -24,12 +16,16 @@ uniform mat4 shadowModelView; uniform mat4 shadowProjection; uniform vec3 cameraPosition; +uniform float frameTimeCounter; + +uniform vec2 texelSize; + +uniform ivec2 eyeBrightnessSmooth; +uniform float rainStrength; #include "/lib/settings.glsl" - -#define END -#define NETHER #include "/lib/diffuse_lighting.glsl" +#include "/lib/sky_gradient.glsl" vec3 toLinear(vec3 sRGB){ return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); @@ -76,8 +72,23 @@ void main() { vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; vec3 np3 = normVec(p3); + vec3 Indirect_lighting = vec3(1.0); + float lightmap = lmtexcoord.z; + vec3 nothing = vec3(0.0); - vec3 Indirect_lighting = DoAmbientLighting_Nether(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.z, normalize(vec3(0.0)), normalize(vec3(0.0)), p3 + cameraPosition); + #ifdef END_SHADER + float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(lightmap)),5.0)+0.1)); + TorchLM = pow(TorchLM/4,10) + pow(lightmap,1.5)*0.5; + vec3 TorchLight = (vec3(TORCH_R,TORCH_G,TORCH_B) * TorchLM * 0.75) * TORCH_AMOUNT; + + Indirect_lighting = max(vec3(0.5,0.75,1.0) * 0.1, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) ) + TorchLight; + #endif + + #ifdef NETHER_SHADER + vec3 AmbientLightColor = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10; + + Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap, nothing, nothing, nothing); + #endif gl_FragData[0].rgb = Indirect_lighting * Albedo; } \ No newline at end of file diff --git a/shaders/programs/all_particles.vsh b/shaders/dimensions/all_particles.vsh similarity index 100% rename from shaders/programs/all_particles.vsh rename to shaders/dimensions/all_particles.vsh diff --git a/shaders/programs/all_solid.fsh b/shaders/dimensions/all_solid.fsh similarity index 100% rename from shaders/programs/all_solid.fsh rename to shaders/dimensions/all_solid.fsh diff --git a/shaders/programs/all_solid.vsh b/shaders/dimensions/all_solid.vsh similarity index 100% rename from shaders/programs/all_solid.vsh rename to shaders/dimensions/all_solid.vsh diff --git a/shaders/programs/all_translucent.fsh b/shaders/dimensions/all_translucent.fsh similarity index 99% rename from shaders/programs/all_translucent.fsh rename to shaders/dimensions/all_translucent.fsh index e541fc0..c5217c1 100644 --- a/shaders/programs/all_translucent.fsh +++ b/shaders/dimensions/all_translucent.fsh @@ -72,7 +72,7 @@ flat varying vec3 averageSkyCol_Clouds; #include "/lib/clouds.glsl" #include "/lib/stars.glsl" #include "/lib/volumetricClouds.glsl" -#define OVERWORLD +#define OVERWORLD_SHADER #include "/lib/diffuse_lighting.glsl" @@ -298,7 +298,6 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize vec4 COLORTEST = vec4(Albedo,UnchangedAlpha); - vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; vec3 normal = normalMat.xyz; @@ -337,13 +336,12 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha); - vec3 WS_normal = viewToWorld(normal); vec2 lightmaps2 = lmtexcoord.zw; vec3 Indirect_lighting = vec3(0.0); - #ifdef NETHER + #ifdef NETHER_SHADER WS_normal.xz = -WS_normal.xz; vec3 AmbientLightColor = skyCloudsFromTexLOD2(WS_normal, colortex4, 6).rgb / 15; @@ -359,7 +357,7 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, vec3(0.0), vec3(0.0), vec3(0.0)); #endif - #ifdef END + #ifdef END_SHADER // do all ambient lighting stuff Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmaps2.x, normal, p3 ); #endif diff --git a/shaders/programs/all_translucent.vsh b/shaders/dimensions/all_translucent.vsh similarity index 100% rename from shaders/programs/all_translucent.vsh rename to shaders/dimensions/all_translucent.vsh diff --git a/shaders/dimensions/composite.fsh b/shaders/dimensions/composite.fsh new file mode 100644 index 0000000..c0230d0 --- /dev/null +++ b/shaders/dimensions/composite.fsh @@ -0,0 +1,669 @@ +#include "/lib/settings.glsl" + +#include "/lib/diffuse_lighting.glsl" + + +varying vec2 texcoord; + + + +const bool colortex5MipmapEnabled = true; +const bool colortex4MipmapEnabled = true; + +uniform sampler2D noisetex;//depth + +uniform sampler2D depthtex1;//depth +uniform sampler2D depthtex0;//depth + +uniform sampler2D colortex0;//clouds +uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16 +uniform sampler2D colortex2; +uniform sampler2D colortex3; +uniform sampler2D colortex4;//Skybox +uniform sampler2D colortex5; +uniform sampler2D colortex6;//Skybox +uniform sampler2D colortex7; +uniform sampler2D colortex8; +uniform sampler2D colortex10; +uniform sampler2D colortex15; + + +uniform mat4 shadowModelView; +uniform mat4 shadowModelViewInverse; +uniform mat4 shadowProjection; +uniform mat4 shadowProjectionInverse; +uniform mat4 gbufferProjection; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelView; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferPreviousProjection; +uniform mat4 gbufferPreviousModelView; + +uniform vec3 cameraPosition; +uniform vec3 previousCameraPosition; + +uniform float far; +uniform float near; + +uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; +uniform float aspectRatio; + +flat varying vec2 TAA_Offset; + +uniform int frameCounter; +uniform float frameTimeCounter; + +uniform float rainStrength; +uniform int isEyeInWater; +uniform ivec2 eyeBrightnessSmooth; + +uniform vec3 sunVec; + +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) + +vec3 toScreenSpace(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 p3 = p * 2. - 1.; + vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} + +#include "/lib/color_transforms.glsl" +#include "/lib/waterBump.glsl" +#include "/lib/sky_gradient.glsl" + + +float ld(float dist) { + return (2.0 * near) / (far + near - dist * (far - near)); +} + +vec2 RENDER_SCALE = vec2(1.0); + +#include "/lib/end_fog.glsl" + +#undef LIGHTSOURCE_REFLECTION +#define ENDSPECULAR +#include "/lib/specular.glsl" + + +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} +float lengthVec (vec3 vec){ + return sqrt(dot(vec,vec)); +} +#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) +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); +} + +vec3 fp10Dither(vec3 color,float dither){ + const vec3 mantissaBits = vec3(6.,6.,5.); + vec3 exponent = floor(log2(color)); + return color + dither*exp2(-mantissaBits)*exp2(exponent); +} + + + +float facos(float sx){ + float x = clamp(abs( sx ),0.,1.); + return sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 ); +} +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); +} +vec2 decodeVec2(float a){ + const vec2 constant1 = 65535. / vec2( 256., 65536.); + const float constant2 = 256. / 255.; + return fract( a * constant1 ) * constant2 ; +} +// float linZ(float depth) { +// 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) + +// } +// float invLinZ (float lindepth){ +// return -((2.0*near/lindepth)-far-near)/(far-near); +// } + +// vec3 toClipSpace3(vec3 viewSpacePosition) { +// return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +// } + + + + +vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort) +{ + float alpha0 = sampleNumber/nb; + float alpha = (sampleNumber+jitter)/nb; + float angle = jitter*6.28 + alpha * 4.0 * 6.28; + + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + + return vec2(cos_v, sin_v)*sqrt(alpha); +} + + + +vec3 BilateralFiltering(sampler2D tex, sampler2D depth,vec2 coord,float frDepth,float maxZ){ + vec4 sampled = vec4(texelFetch2D(tex,ivec2(coord),0).rgb,1.0); + + return vec3(sampled.x,sampled.yz/sampled.w); +} +float interleaved_gradientNoise(){ + // vec2 coord = gl_FragCoord.xy + (frameCounter%40000); + vec2 coord = gl_FragCoord.xy + frameTimeCounter; + // vec2 coord = gl_FragCoord.xy; + float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); + return noise ; +} + +vec2 R2_dither(){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return vec2(fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter), fract((1.0-alpha.x) * gl_FragCoord.x + (1.0-alpha.y) * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter)); +} +float blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * (frameCounter*0.5+0.5) ); +} +vec4 blueNoise(vec2 coord){ + return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ; +} +vec3 toShadowSpaceProjected(vec3 p3){ + p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz; + p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz; + p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz; + + return p3; +} +vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot,float r0) +{ + float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb))); + float angle = alpha * (nbRot * 6.28) + spinAngle*6.28; + + float ssR = alpha; + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + + return vec2(cos_v, sin_v)*ssR; +} + + +float ssao(vec3 fragpos, float dither,vec3 normal) +{ + float mulfov = 1.0; + ivec2 pos = ivec2(gl_FragCoord.xy); + const float tan70 = tan(70.*3.14/180.); + float mulfov2 = gbufferProjection[1][1]/tan70; + + const float PI = 3.14159265; + const float samplingRadius = 0.712; + float angle_thresh = 0.05; + + + + + float rd = mulfov2*0.05; + //pre-rotate direction + float n = 0.; + + float occlusion = 0.0; + + vec2 acc = -vec2(TAA_Offset)*texelSize*0.5; + float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5; + + vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026)); + for (int j = 0; j < 7+2 ;j++) { + vec2 sp = tapLocation(j,v.x,7+2,2.,v.y); + vec2 sampleOffset = sp*rd; + ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight)); + if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) { + vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x)); + + vec3 vec = t0.xyz - fragpos; + float dsquared = dot(vec,vec); + if (dsquared > 1e-5){ + if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){ + float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.); + occlusion += NdotV; + } + n += 1.0; + } + } + } + + + + + return clamp(1.0-occlusion/n*2.0,0.,1.0); +} +vec3 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} +vec3 worldToView(vec3 worldPos) { + vec4 pos = vec4(worldPos, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; +} +void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ + inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value + 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; + vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; + rayLength *= maxZ; + float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; + estEndDepth *= maxZ; + estSunDepth *= maxZ; + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); + + + float expFactor = 11.0; + vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; + for (int i=0;i -near) ? + (-near -position.z) / dir.z : far*sqrt(3.) ; + vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space + direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size + vec3 stepv = direction * 3.0 * clamp(MC_RENDER_QUALITY,1.,2.0); + + vec3 spos = clipPosition; + spos += stepv*dither ; + + for (int i = 0; i < int(quality); i++) { + spos += stepv; + + float sp = texture2D(depthtex1,spos.xy).x; + + if( sp < spos.z) { + float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z); + if (dist < 0.015 ) return i / quality; + } + } + return 1.0; +} + + + +vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){ + + vec3 clipPosition = toClipSpace3(position); + float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? + (-near -position.z) / dir.z : far*sqrt(3.); + vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space + direction.xy = normalize(direction.xy); + + //get at which length the ray intersects with the edge of the screen + vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; + float mult = maxLengths.y; + + vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither; + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; + + spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; + + float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases + + for(int i = 0; i < int(quality); i++){ + spos += stepv; + float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0); + float currZ = linZ(spos.z); + + if( sp < currZ) { + float dist = abs(sp-currZ)/currZ; + if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); + } + spos += stepv; + } + return vec3(1.1); +} +vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){ + float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + + float stepSize = stepsizes / dist; + int maxSteps = STEPS; + vec3 clipPosition = toClipSpace3(position); + float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ? + (-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far; + vec3 end = toClipSpace3(position+dir*rayLength) ; + vec3 direction = end-clipPosition ; //convert to clip space + + float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize; + //get at which length the ray intersects with the edge of the screen + vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; + + float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0; + + vec3 stepv = direction/len; + + int iterations = min(int(min(len, mult*len)-2), maxSteps); + + //Do one iteration for closest texel (good contact shadows) + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; + spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; + spos += stepv/(stepSize/2); + + float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + + for(int i = 0; i < iterations; i++){ + if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1); + spos += stepv*noise; + + float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0); + float currZ = linZ(spos.z); + + if( sp < currZ) { + float dist = abs(sp-currZ)/currZ; + if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); + } + } + return vec3(1.1); +} + +vec3 cosineHemisphereSample(vec2 Xi, float roughness){ + float r = sqrt(Xi.x); + float theta = 2.0 * 3.14159265359 * Xi.y; + + float x = r * cos(theta); + float y = r * sin(theta); + + return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); +} + +vec3 TangentToWorld(vec3 N, vec3 H, float roughness){ + vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); + vec3 T = normalize(cross(UpVector, N)); + vec3 B = cross(N, T); + + return vec3((T * H.x) + (B * H.y) + (N * H.z)); +} +vec2 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n); +} + +void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){ + int nrays = RAY_COUNT; + + vec3 radiance = vec3(0.0); + vec3 occlusion = vec3(0.0); + vec3 skycontribution = vec3(0.0); + + // float skyLM = 0.0; + // vec3 torchlight = vec3(0.0); + // vec3 blank = vec3(0.0); + // DoRTAmbientLighting(torchcolor, vec2(lightmaps,1.0), skyLM, torchlight, blank); + + for (int i = 0; i < nrays; i++){ + int seed = (frameCounter%40000)*nrays+i; + vec2 ij = fract(R2_samples(seed) + noise ); + + vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0); + + #ifdef HQ_SSGI + vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt + #else + vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt + #endif + + skycontribution = lighting; + + if (rayHit.z < 1.){ + + #if indirect_effect == 4 + vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; + previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; + previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; + if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ + radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength; + }else{ + radiance += skycontribution; + } + #else + radiance += skycontribution; + #endif + + occlusion += skycontribution * GI_Strength; + + } else { + radiance += skycontribution; + } + } + + occlusion *= AO_Strength; + + lighting = max(radiance/nrays - occlusion/nrays, 0.0); +} + +void main() { + + ////// --------------- SETUP COORDINATE SPACES --------------- ////// + + float z0 = texture2D(depthtex0,texcoord).x; + float z = texture2D(depthtex1,texcoord).x; + + vec2 tempOffset=TAA_Offset; + float noise = blueNoise(); + + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// + + vec4 data = texture2D(colortex1,texcoord); + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps + // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + + vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); + vec2 lightmap = dataUnpacked1.yz; + vec3 normal = decode(dataUnpacked0.yw); + + ////// --------------- UNPACK MISC --------------- ////// + + vec4 SpecularTex = texture2D(colortex8,texcoord); + float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0); + + vec4 normalAndAO = texture2D(colortex15,texcoord); + vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; + vec3 slopednormal = normal; + + #ifdef POM + #ifdef Horrible_slope_normals + vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it. + slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) ); + #endif + #endif + + float vanilla_AO = clamp(normalAndAO.a,0,1); + normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1); + + + ////// --------------- MASKS/BOOLEANS --------------- ////// + + bool iswater = texture2D(colortex7,texcoord).a > 0.99; + bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01; + bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01; + bool entities = abs(dataUnpacked1.w-0.45) < 0.01; + bool hand = abs(dataUnpacked1.w-0.75) < 0.01; + // bool blocklights = abs(dataUnpacked1.w-0.8) <0.01; + + + ////// --------------- COLORS --------------- ////// + + float dirtAmount = Dirt_Amount; + 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 = dirtEpsilon*dirtAmount + waterEpsilon; + vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; + + vec3 Indirect_lighting = vec3(1.0); + vec3 Direct_lighting = vec3(0.0); + + ///////////////////////////// start drawin :D + + if (z >= 1.0) { + + gl_FragData[0].rgb = vec3(0.0); + + } else { + + p3 += gbufferModelViewInverse[3].xyz; + + //////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////// MAJOR LIGHTSOURCE STUFF //////////////////////// + //////////////////////////////////////////////////////////////////////////////////// + + #ifdef END_SHADER + vec3 LightColor = LightSourceColor(clamp(sqrt(length(p3+cameraPosition) / 150.0 - 1.0) ,0.0,1.0)); + vec3 LightPos = LightSourcePosition(p3+cameraPosition, cameraPosition); + + float LightFalloff = max(exp2(4.0 + length(LightPos) / -25),0.0); + + float NdotL = clamp( dot(normal,normalize(-LightPos)),0.0,1.0); + NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); + + float fogshadow = GetCloudShadow(p3+cameraPosition, LightPos, blueNoise()); + Direct_lighting = (LightColor * max(LightColor - (1-fogshadow) ,0.0)) * LightFalloff * NdotL; + // vec3 LightSource = LightColor * fogshadow * LightFalloff * NdotL ; + + + + float LightFalloff2 = max(1.0-length(LightPos)/120,0.0); + LightFalloff2 = pow(1.0-pow(1.0-LightFalloff2,0.5),2.0); + LightFalloff2 *= 25; + + Direct_lighting += (LightColor * max(LightColor - 0.6,0.0)) * vec3(1.0,1.3,1.0) * LightFalloff2 * (NdotL*0.7+0.3); + + // float RT_Shadows = rayTraceShadow(worldToView(normalize(-LightPos)), fragpos_RTSHADOW, blueNoise()); + // if(!hand) LightSource *= RT_Shadows*RT_Shadows; + #endif + + ///////////////////////////////////////////////////////////////////////////////// + ///////////////////////////// INDIRECT LIGHTING ///////////////////////////// + ///////////////////////////////////////////////////////////////////////////////// + + #ifdef END_SHADER + Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3); + #endif + + #ifdef NETHER_SHADER + vec3 AmbientLightColor = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 10; + + vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10; + vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb / 10; + + up *= pow( max( slopednormal.y, 0), 2); + down *= pow( max(-slopednormal.y, 0), 2); + AmbientLightColor += up + down; + + // do all ambient lighting stuff + Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3, p3 ); + #endif + ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////// EFFECTS FOR INDIRECT ///////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + + #if indirect_effect == 0 + vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; + if(!hand) Indirect_lighting *= AO; + #endif + + #if indirect_effect == 1 + vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; + if(!hand) Indirect_lighting *= ssao(fragpos,noise,FlatNormals) * AO; + #endif + + // RTAO and/or SSGI + #if indirect_effect == 3 || indirect_effect == 4 + if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.x,vec3(TORCH_R,TORCH_G,TORCH_B)); + #endif + + ///////////////////////////////////////////////////////////////////////// + ///////////////////////////// FINALIZE ///////////////////////////// + ///////////////////////////////////////////////////////////////////////// + + gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo; + + #ifdef Specular_Reflections + vec3 specNoise = vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise()); + DoSpecularReflections(gl_FragData[0].rgb, fragpos, np3, vec3(0.0), specNoise, normal, SpecularTex.r, SpecularTex.g, albedo, vec3(0.0), 1.0, hand); + #endif + + Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); + + if(lightningBolt) gl_FragData[0].rgb = vec3(1); + + } + + if (iswater && isEyeInWater == 0){ + vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); + float Vdiff = distance(fragpos,fragpos0); + float VdotU = np3.y; + float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane + + vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)); + + waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol); + } + +/* DRAWBUFFERS:3 */ +} diff --git a/shaders/dimensions/composite.vsh b/shaders/dimensions/composite.vsh new file mode 100644 index 0000000..50ae0c2 --- /dev/null +++ b/shaders/dimensions/composite.vsh @@ -0,0 +1,49 @@ + +#include "/lib/settings.glsl" + +varying vec2 texcoord; + +flat varying vec3 avgAmbient; + +flat varying float tempOffsets; +flat varying vec2 TAA_Offset; +flat varying vec3 zMults; + +uniform sampler2D colortex4; + +uniform float far; +uniform float near; +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform float rainStrength; +uniform float sunElevation; +uniform int frameCounter; + +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); + + +#include "/lib/util.glsl" + +void main() { + gl_Position = ftransform(); + texcoord = gl_MultiTexCoord0.xy; + + tempOffsets = HaltonSeq2(frameCounter%10000); + + TAA_Offset = offsets[frameCounter%8]; + + #ifndef TAA + TAA_Offset = vec2(0.0); + #endif + + + avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; + zMults = vec3((far * near)*2.0,far+near,far-near); +} diff --git a/shaders/dimensions/composite1.fsh b/shaders/dimensions/composite1.fsh new file mode 100644 index 0000000..06b0afd --- /dev/null +++ b/shaders/dimensions/composite1.fsh @@ -0,0 +1,129 @@ +#include "/lib/settings.glsl" + + +uniform sampler2D noisetex; +uniform sampler2D depthtex0; + +uniform sampler2D colortex2; +uniform sampler2D colortex3; +// uniform sampler2D colortex4; + +uniform vec3 sunVec; +uniform float sunElevation; +uniform float far; + +uniform int frameCounter; +uniform float frameTimeCounter; + +varying vec2 texcoord; +uniform vec2 texelSize; +flat varying vec2 TAA_Offset; + +uniform int isEyeInWater; +uniform float rainStrength; +uniform ivec2 eyeBrightnessSmooth; + +#include "/lib/color_transforms.glsl" +#include "/lib/color_dither.glsl" +#include "/lib/projections.glsl" + +#ifdef END_SHADER + #include "/lib/end_fog.glsl" +#endif + +#ifdef NETHER_SHADER + #include "/lib/nether_fog.glsl" +#endif + +#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) + +float interleaved_gradientNoise(){ + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+TAA_Offset.x); +} +float blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); +} + +void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ + inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value + + 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; + + float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; + estEndDepth *= maxZ; + estSunDepth *= maxZ; + + vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; + vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); + + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); + + float expFactor = 11.0; + for (int i=0;i 0.99; + float translucentAlpha = trpData.a; + + // vec4 speculartex = texture2D(colortex8,texcoord); // translucents + // float sunlight = speculartex.b; + + //3x3 bilateral upscale from half resolution + float z = texture2D(depthtex0,texcoord).x; + float z2 = texture2D(depthtex1,texcoord).x; + float frDepth = ld(z2); + + // vec4 vl = texture2D(colortex0,texcoord * 0.5); + + ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// + vec4 data_opaque = texture2D(colortex1,texcoord); + vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps + // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + + bool hand = abs(dataUnpacked1.w-0.75) < 0.01; + vec2 lightmap = dataUnpacked1.yz; + + ////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- ////// + + vec3 data = texture2D(colortex11,texcoord).rgb; + + vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ; + vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ; + + + + vec4 albedo = vec4(unpack0.ba,unpack1.rg); + + vec2 tangentNormals = unpack0.xy*2.0-1.0; + + if(albedo.a <= 0.0) tangentNormals = vec2(0.0); + + vec4 TranslucentShader = texture2D(colortex2,texcoord); + + float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0); + + + vec2 tempOffset = TAA_Offset; + vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); + vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2)); + + + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + + vec2 refractedCoord = texcoord; + + /// --- REFRACTION --- /// + #ifdef Refraction + refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE; + // refractedCoord += tangentNormals * 0.1 * RENDER_SCALE; + + float refractedalpha = decodeVec2(texture2D(colortex11,refractedCoord).b).g; + float refractedalpha2 = texture2D(colortex7,refractedCoord).a; + if( refractedalpha <= 0.001 ||z < 0.56) refractedCoord = texcoord; // remove refracted coords on solids + #endif + + /// --- MAIN COLOR BUFFER --- /// + // it is sampled with distorted texcoords + vec3 color = texture2D(colortex3,refractedCoord).rgb; + + vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0)); + float bloomyFogMult = 1.0; + + if (TranslucentShader.a > 0.0){ + #ifdef Glass_Tint + if(albedo.a > 0.2) color = color*albedo.rgb + color * clamp(pow(1.0-luma(albedo.rgb),20.),0.0,1.0); + #endif + + color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb; + } + + // underwater fog + if (isEyeInWater == 1){ + float dirtAmount = Dirt_Amount; + 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 = dirtEpsilon*dirtAmount + waterEpsilon; + + // float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0); + // vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0); + vec3 fogfade = clamp( exp( (-length(fragpos)) * totEpsilon ) ,0.0,1.0); + fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0); + + color.rgb *= fogfade ; + bloomyFogMult *= 0.4; + } + + // apply VL fog to the scene + color *= vl.a; + color += vl.rgb; + +// bloomy rain effect + float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); + if(rainDrops > 0.0) bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0); + + /// lava. + if (isEyeInWater == 2){ + color.rgb = vec3(4.0,0.5,0.1); + } + + /// powdered snow + if (isEyeInWater == 3){ + color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); + bloomyFogMult = 0.0; + } + + // blidnesss + color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness); + + // darkness effect + color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); + + #ifdef display_LUT + vec2 movedTC = texcoord; + vec3 thingy = texture2D(colortex4,movedTC).rgb / 150. * 5.0; + if(luma(thingy) > 0.0 ) color.rgb = thingy; + #endif + + gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog + + gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); + +} \ No newline at end of file diff --git a/shaders/dimensions/composite2.vsh b/shaders/dimensions/composite2.vsh new file mode 100644 index 0000000..1717e80 --- /dev/null +++ b/shaders/dimensions/composite2.vsh @@ -0,0 +1,17 @@ + +varying vec2 texcoord; +flat varying vec3 zMults; +uniform float far; +uniform float near; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { + zMults = vec3(1.0/(far * near),far+near,far-near); + gl_Position = ftransform(); + texcoord = gl_MultiTexCoord0.xy; + +} diff --git a/shaders/dimensions/composite3.fsh b/shaders/dimensions/composite3.fsh new file mode 100644 index 0000000..c47e9fc --- /dev/null +++ b/shaders/dimensions/composite3.fsh @@ -0,0 +1,350 @@ +#include "/lib/settings.glsl" + +const int noiseTextureResolution = 32; + + +/* +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 colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) +const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final) +const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) +*/ +//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; + +varying vec2 texcoord; +flat varying float exposureA; +flat varying float tempOffsets; +uniform sampler2D colortex3; +uniform sampler2D colortex5; +uniform sampler2D colortex10; +uniform sampler2D depthtex0; + +uniform vec2 texelSize; +uniform float frameTimeCounter; +uniform int framemod8; +uniform float viewHeight; +uniform float viewWidth; +uniform vec3 previousCameraPosition; +uniform mat4 gbufferPreviousModelView; + + + + +#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) + +#include "/lib/projections.glsl" + + +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); +} +vec3 fp10Dither(vec3 color,float dither){ + const vec3 mantissaBits = vec3(6.,6.,5.); + vec3 exponent = floor(log2(color)); + return color + dither*exp2(-mantissaBits)*exp2(exponent); +} + + +//returns the projected coordinates of the closest point to the camera in the 3x3 neighborhood +vec3 closestToCamera3x3() +{ + vec2 du = vec2(texelSize.x, 0.0); + vec2 dv = vec2(0.0, texelSize.y); + + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthtex0, texcoord - dv - du).x); + vec3 dtc = vec3(texcoord,0.) + vec3( 0.0, -texelSize.y, texture2D(depthtex0, texcoord - dv).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthtex0, texcoord - dv + du).x); + + vec3 dml = vec3(texcoord,0.) + vec3(-texelSize.x, 0.0, texture2D(depthtex0, texcoord - du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthtex0, texcoord).x); + vec3 dmr = vec3(texcoord,0.) + vec3( texelSize.x, 0.0, texture2D(depthtex0, texcoord + du).x); + + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv - du).x); + vec3 dbc = vec3(texcoord,0.) + vec3( 0.0, texelSize.y, texture2D(depthtex0, texcoord + dv).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv + du).x); + + vec3 dmin = dmc; + + dmin = dmin.z > dtc.z? dtc : dmin; + dmin = dmin.z > dtr.z? dtr : dmin; + + dmin = dmin.z > dml.z? dml : dmin; + dmin = dmin.z > dtl.z? dtl : dmin; + dmin = dmin.z > dmr.z? dmr : dmin; + + dmin = dmin.z > dbl.z? dbl : dmin; + dmin = dmin.z > dbc.z? dbc : dmin; + dmin = dmin.z > dbr.z? dbr : dmin; + + return dmin; +} + +//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 texture2D( tex, uv); +} +//Due to low sample count we "tonemap" the inputs to preserve colors and smoother edges +vec3 weightedSample(sampler2D colorTex, vec2 texcoord){ + vec3 wsample = texture2D(colorTex,texcoord).rgb*exposureA; + return wsample/(1.0+luma(wsample)); + +} + + +//from : https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 +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 += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; + result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; + result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; + + result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; + result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; + result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; + + result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; + result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; + result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; + + return result; +} +//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 = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb; + + vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); + vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); + vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + + vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + + vec4(centerColor, 1.0) * (w12.x * w12.y) + + vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + + vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); + return color.rgb/color.a; + +} + +vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max) + { + vec3 p_clip = 0.5 * (aabb_max + aabb_min); + vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001; + + vec3 v_clip = q - vec3(p_clip); + vec3 v_unit = v_clip.xyz / e_clip; + vec3 a_unit = abs(v_unit); + float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); + + if (ma_unit > 1.0) + return vec3(p_clip) + v_clip / ma_unit; + else + return q; + } +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)); +} +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, texture2D(depth, texcoord - dv - du).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(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; + + return dmin; +} +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); + +vec3 TAA_hq(){ + + vec2 adjTC = texcoord; + + + //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion + #ifdef CLOSEST_VELOCITY + vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); + #endif + + #ifndef CLOSEST_VELOCITY + vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x); + #endif + + //reproject previous frame + vec3 fragposition = toScreenSpace(closestToCamera); + fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz; + previousPosition = toClipSpace3Prev(previousPosition); + vec2 velocity = previousPosition.xy - closestToCamera.xy; + previousPosition.xy = texcoord + velocity; + + //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 smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz; + + + vec3 albedoCurrent0 = texture2D(colortex3, adjTC).rgb; + vec3 albedoCurrent1 = texture2D(colortex3, adjTC + vec2(texelSize.x,texelSize.y)).rgb; + vec3 albedoCurrent2 = texture2D(colortex3, adjTC + vec2(texelSize.x,-texelSize.y)).rgb; + vec3 albedoCurrent3 = texture2D(colortex3, adjTC + vec2(-texelSize.x,-texelSize.y)).rgb; + vec3 albedoCurrent4 = texture2D(colortex3, adjTC + vec2(-texelSize.x,texelSize.y)).rgb; + vec3 albedoCurrent5 = texture2D(colortex3, adjTC + vec2(0.0,texelSize.y)).rgb; + vec3 albedoCurrent6 = texture2D(colortex3, adjTC + vec2(0.0,-texelSize.y)).rgb; + vec3 albedoCurrent7 = texture2D(colortex3, adjTC + vec2(-texelSize.x,0.0)).rgb; + vec3 albedoCurrent8 = texture2D(colortex3, adjTC + vec2(texelSize.x,0.0)).rgb; + //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 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8)))))); + vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8)))))); + albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).rgb; + + + #ifndef NO_CLIP + vec3 albedoPrev = max(FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.75).xyz, 0.0); + vec3 finalcAcc = clamp(albedoPrev,cMin,cMax); + + //Increases blending factor when far from AABB and in motion, reduces ghosting + float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5; + float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0); + + float test = 0.05; + + bool isEntities = texture2D(colortex10,texcoord).x > 0.0; + // if(isEntities) test = 0.15; + // if(istranslucent) test = 0.1; + + //Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering + // vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.))); + + vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.))); + #endif + + + #ifdef NO_CLIP + vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz; + vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.)); + #endif + + //De-tonemap + return supersampled; +} + +void main() { + +/* DRAWBUFFERS:5 */ + gl_FragData[0].a = 1.0; + + #ifdef TAA + vec3 color = TAA_hq(); + gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0); + #endif + + #ifndef TAA + vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.); + gl_FragData[0].rgb = color; + #endif + + + + + +} diff --git a/shaders/dimensions/composite3.vsh b/shaders/dimensions/composite3.vsh new file mode 100644 index 0000000..263f476 --- /dev/null +++ b/shaders/dimensions/composite3.vsh @@ -0,0 +1,17 @@ +#include "/lib/util.glsl" + +varying vec2 texcoord; +flat varying float exposureA; +flat varying float tempOffsets; +uniform sampler2D colortex4; +uniform int frameCounter; + + + +void main() { + + tempOffsets = HaltonSeq2(frameCounter%10000); + gl_Position = ftransform(); + texcoord = gl_MultiTexCoord0.xy; + exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r; +} diff --git a/shaders/dimensions/composite4.fsh b/shaders/dimensions/composite4.fsh new file mode 100644 index 0000000..c6aa254 --- /dev/null +++ b/shaders/dimensions/composite4.fsh @@ -0,0 +1,42 @@ +uniform sampler2D colortex5; +uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { + +/* DRAWBUFFERS:3 */ +vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); +vec2 quarterResTC = gl_FragCoord.xy*2.*resScale*texelSize; + + //0.5 + gl_FragData[0] = texture2D(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture2D(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; + + //0.25 + gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125; + + //0.125 + gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; + + //0.125 + gl_FragData[0] += texture2D(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/world-1/composite14.vsh b/shaders/dimensions/composite4.vsh similarity index 98% rename from shaders/world-1/composite14.vsh rename to shaders/dimensions/composite4.vsh index 386f006..7a54acb 100644 --- a/shaders/world-1/composite14.vsh +++ b/shaders/dimensions/composite4.vsh @@ -1,5 +1,3 @@ -#version 120 - uniform float viewWidth; uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// diff --git a/shaders/world-1/composite10.fsh b/shaders/dimensions/composite5.fsh similarity index 97% rename from shaders/world-1/composite10.fsh rename to shaders/dimensions/composite5.fsh index 25c81c0..a76a667 100644 --- a/shaders/world-1/composite10.fsh +++ b/shaders/dimensions/composite5.fsh @@ -1,6 +1,3 @@ -#version 120 -//downsample 1st pass (half res) for bloom - uniform sampler2D colortex3; uniform vec2 texelSize; uniform float viewWidth; diff --git a/shaders/world-1/composite10.vsh b/shaders/dimensions/composite5.vsh similarity index 98% rename from shaders/world-1/composite10.vsh rename to shaders/dimensions/composite5.vsh index 8d47d5c..c33e780 100644 --- a/shaders/world-1/composite10.vsh +++ b/shaders/dimensions/composite5.vsh @@ -1,5 +1,3 @@ -#version 120 - uniform float viewWidth; uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// diff --git a/shaders/world-1/composite11.fsh b/shaders/dimensions/composite6.fsh similarity index 97% rename from shaders/world-1/composite11.fsh rename to shaders/dimensions/composite6.fsh index 1320222..4c2f776 100644 --- a/shaders/world-1/composite11.fsh +++ b/shaders/dimensions/composite6.fsh @@ -1,7 +1,3 @@ -#version 120 -//6 Horizontal gaussian blurs and horizontal downsampling - - uniform sampler2D colortex6; uniform vec2 texelSize; varying vec2 texcoord; diff --git a/shaders/world-1/composite12.vsh b/shaders/dimensions/composite6.vsh similarity index 98% rename from shaders/world-1/composite12.vsh rename to shaders/dimensions/composite6.vsh index 56683b4..cbc9838 100644 --- a/shaders/world-1/composite12.vsh +++ b/shaders/dimensions/composite6.vsh @@ -1,5 +1,3 @@ -#version 120 - uniform float viewWidth; uniform float viewHeight; varying vec2 texcoord; @@ -17,5 +15,4 @@ void main() { //0-0.5 gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0; texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.); - } diff --git a/shaders/world-1/composite12.fsh b/shaders/dimensions/composite7.fsh similarity index 97% rename from shaders/world-1/composite12.fsh rename to shaders/dimensions/composite7.fsh index dd63b74..656f295 100644 --- a/shaders/world-1/composite12.fsh +++ b/shaders/dimensions/composite7.fsh @@ -1,8 +1,3 @@ -#version 120 -//6 Vertical gaussian blurs and vertical downsampling - - - uniform sampler2D colortex6; uniform vec2 texelSize; varying vec2 texcoord; diff --git a/shaders/world-1/composite11.vsh b/shaders/dimensions/composite7.vsh similarity index 98% rename from shaders/world-1/composite11.vsh rename to shaders/dimensions/composite7.vsh index b299614..366226a 100644 --- a/shaders/world-1/composite11.vsh +++ b/shaders/dimensions/composite7.vsh @@ -1,5 +1,3 @@ -#version 120 - uniform float viewWidth; uniform float viewHeight; varying vec2 texcoord; @@ -17,4 +15,5 @@ void main() { //0-0.5 gl_Position.x = (gl_Position.x*0.5+0.5)*0.5/clampedRes.x*1920.0*2.0-1.0; texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.); + } diff --git a/shaders/world-1/composite14.fsh b/shaders/dimensions/composite8.fsh similarity index 97% rename from shaders/world-1/composite14.fsh rename to shaders/dimensions/composite8.fsh index 6bfa802..49a54fb 100644 --- a/shaders/world-1/composite14.fsh +++ b/shaders/dimensions/composite8.fsh @@ -1,6 +1,3 @@ -#version 120 -//Merge and upsample the blurs into a 1/4 res bloom buffer - uniform sampler2D colortex3; uniform sampler2D colortex6; diff --git a/shaders/dimensions/composite8.vsh b/shaders/dimensions/composite8.vsh new file mode 100644 index 0000000..7a54acb --- /dev/null +++ b/shaders/dimensions/composite8.vsh @@ -0,0 +1,15 @@ +uniform float viewWidth; +uniform float viewHeight; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +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; +} diff --git a/shaders/world1/composite10.fsh b/shaders/dimensions/composite9.fsh similarity index 97% rename from shaders/world1/composite10.fsh rename to shaders/dimensions/composite9.fsh index 25a8f87..02e5034 100644 --- a/shaders/world1/composite10.fsh +++ b/shaders/dimensions/composite9.fsh @@ -1,7 +1,3 @@ -#version 120 -//Vignetting, applies bloom, applies exposure and tonemaps the final image -//#extension GL_EXT_gpu_shader4 : disable - #include "/lib/settings.glsl" #ifdef DOF @@ -461,14 +457,8 @@ void main() { VL_abs = clamp((1.0-VL_abs*1.05)*BLOOMY_FOG*0.5,0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0); col = ( mix(col, bloom, VL_abs) + bloom*lightScat) * exposure.rgb; -/* - //Purkinje Effect - float lum = dot(col,vec3(0.15,0.3,0.55)); - float lum2 = dot(col,vec3(0.85,0.7,0.45))/2; - float rodLum = lum2*300.0; - float rodCurve = mix(1.0, rodLum/(2.5+rodLum), rodExposure/2.0*Purkinje_strength); - col = mix(lum*Purkinje_Multiplier*vec3(Purkinje_R, Purkinje_G, Purkinje_B)+0.001, col, rodCurve); -*/ + + #ifndef USE_ACES_COLORSPACE_APPROXIMATION col = LinearTosRGB(TONEMAP(col)); #else diff --git a/shaders/world1/composite10.vsh b/shaders/dimensions/composite9.vsh similarity index 93% rename from shaders/world1/composite10.vsh rename to shaders/dimensions/composite9.vsh index 3275077..e77b7c4 100644 --- a/shaders/world1/composite10.vsh +++ b/shaders/dimensions/composite9.vsh @@ -1,6 +1,3 @@ -#version 120 -//#extension GL_EXT_gpu_shader4 : disable - #include "/lib/settings.glsl" varying vec2 texcoord; diff --git a/shaders/dimensions/deferred.fsh b/shaders/dimensions/deferred.fsh new file mode 100644 index 0000000..2a0e3dc --- /dev/null +++ b/shaders/dimensions/deferred.fsh @@ -0,0 +1,110 @@ +#include "/lib/settings.glsl" + + +// flat varying vec3 ambientUp; +// flat varying vec3 ambientLeft; +// flat varying vec3 ambientRight; +// flat varying vec3 ambientB; +// flat varying vec3 ambientF; +// flat varying vec3 ambientDown; + +flat varying vec3 lightSourceColor; +flat varying vec3 sunColor; +flat varying vec3 sunColorCloud; +flat varying vec3 moonColor; +flat varying vec3 moonColorCloud; +flat varying vec3 zenithColor; +flat varying vec3 avgSky; +flat varying vec2 tempOffsets; +flat varying float exposure; +flat varying float rodExposure; +flat varying float avgBrightness; +flat varying float exposureF; +flat varying float fogAmount; +flat varying float VFAmount; + +uniform sampler2D colortex4; +uniform sampler2D noisetex; + +uniform int frameCounter; +uniform float rainStrength; +uniform float eyeAltitude; +uniform vec3 sunVec; +uniform vec2 texelSize; +uniform float frameTimeCounter; +uniform mat4 gbufferProjection; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferPreviousProjection; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferModelView; +uniform mat4 shadowModelView; +uniform mat4 shadowProjection; +uniform float sunElevation; +uniform vec3 cameraPosition; +uniform float far; +uniform ivec2 eyeBrightnessSmooth; + +#include "/lib/util.glsl" +#include "/lib/ROBOBO_sky.glsl" + +vec3 toShadowSpaceProjected(vec3 p3){ + p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz; + p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz; + p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz; + + return p3; +} +float interleaved_gradientNoise(){ + vec2 coord = gl_FragCoord.xy; + float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887); + return noise; +} +float blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); +} + + + +#ifdef END_SHADER + #include "/lib/end_fog.glsl" +#endif + +#ifdef NETHER_SHADER + #include "/lib/nether_fog.glsl" +#endif + +void main() { +/* DRAWBUFFERS:4 */ + +gl_FragData[0] = vec4(0.0); + +vec2 fogPos = vec2(256.0 - 256.0*0.12,1.0); + +//Sky gradient with clouds +if (gl_FragCoord.x > (fogPos.x - fogPos.x*0.22) && gl_FragCoord.y > 0.4 && gl_FragCoord.x < 535){ + // vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0); + vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.2,1.2); + vec3 viewVector = cartToSphere(p); + + vec3 BackgroundColor = vec3(0.0); + + vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., fract(frameCounter/1.6180339887), fract(frameCounter/2.6180339887)); + + BackgroundColor += VL_Fog.rgb/5.0; + + gl_FragData[0] = vec4(BackgroundColor, 1.0); + +} + +//Temporally accumulate sky and light values +vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb; +vec3 curr = gl_FragData[0].rgb*150.; +gl_FragData[0].rgb = clamp(mix(temp,curr,0.07),0.0,65000.); + +//Exposure values +if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(exposure,avgBrightness,exposureF,1.0); +if (gl_FragCoord.x > 14. && gl_FragCoord.x < 15. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(rodExposure,0.0,0.0,1.0); + +} diff --git a/shaders/dimensions/deferred.vsh b/shaders/dimensions/deferred.vsh new file mode 100644 index 0000000..7303523 --- /dev/null +++ b/shaders/dimensions/deferred.vsh @@ -0,0 +1,104 @@ +#include "/lib/settings.glsl" +#include "/lib/res_params.glsl" + +flat varying vec2 tempOffsets; +flat varying float exposure; +flat varying float avgBrightness; +flat varying float rodExposure; +flat varying float avgL2; +flat varying float centerDepth; + +uniform sampler2D colortex4; +uniform sampler2D colortex6; +uniform sampler2D depthtex0; + +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform vec2 texelSize; +uniform float sunElevation; +uniform float eyeAltitude; +uniform float near; +uniform float far; +uniform float frameTime; +uniform int frameCounter; +uniform float rainStrength; + +// uniform int worldTime; +vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition); + +#include "/lib/sky_gradient.glsl" +#include "/lib/util.glsl" +#include "/lib/ROBOBO_sky.glsl" + +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} + +//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ +vec2 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n); +} +float tanh(float x){ + return (exp(x) - exp(-x))/(exp(x) + exp(-x)); +} +float ld(float depth) { + return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near +} + +uniform float nightVision; + + +void main() { + + gl_Position = ftransform()*0.5+0.5; + gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize; + gl_Position.xy = gl_Position.xy*2.-1.0; + +////////////////////////////// +/// --- EXPOSURE STUFF --- /// +////////////////////////////// + + float avgLuma = 0.0; + float m2 = 0.0; + int n=100; + vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.)); + float avgExp = 0.0; + float avgB = 0.0; + vec2 resScale = vec2(1920.,1080.)/clampedRes; + const int maxITexp = 50; + float w = 0.0; + for (int i = 0; i < maxITexp; i++){ + vec2 ij = R2_samples((frameCounter%2000)*maxITexp+i); + vec2 tc = 0.5 + (ij-0.5) * 0.7; + vec3 sp = texture2D(colortex6,tc/16. * resScale+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; + avgExp += log(luma(sp)); + avgB += log(min(dot(sp,vec3(0.07,0.22,0.71)),8e-2)); + } + + avgExp = exp(avgExp/maxITexp); + avgB = exp(avgB/maxITexp); + + avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0); + + float L = max(avgBrightness,1e-8); + float keyVal = 1.03-2.0/(log(L*4000/150.*8./3.0+1.0)/log(10.0)+2.0); + float expFunc = 0.5+0.5*tanh(log(L)); + float targetExposure = 0.18/log2(L*2.5+1.045)*0.62; + + avgL2 = clamp(mix(avgB,texelFetch2D(colortex4,ivec2(10,37),0).b,0.985),0.00003051757,65000.0); + float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2; + + + exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0); + float currCenterDepth = ld(texture2D(depthtex0, vec2(0.5)).r); + centerDepth = mix(sqrt(texelFetch2D(colortex4,ivec2(14,37),0).g/65000.0), currCenterDepth, clamp(DoF_Adaptation_Speed*exp(-0.016/frameTime+1.0)/(6.0+currCenterDepth*far),0.0,1.0)); + centerDepth = centerDepth * centerDepth * 65000.0; + + rodExposure = targetrodExposure; + + #ifndef AUTO_EXPOSURE + exposure = Manual_exposure_value; + rodExposure = clamp(log(Manual_exposure_value*2.0+1.0)-0.1,0.0,2.0); + #endif +} \ No newline at end of file diff --git a/shaders/world-1/deferred2.fsh b/shaders/dimensions/deferred1.fsh similarity index 94% rename from shaders/world-1/deferred2.fsh rename to shaders/dimensions/deferred1.fsh index 579bfc1..44218cd 100644 --- a/shaders/world-1/deferred2.fsh +++ b/shaders/dimensions/deferred1.fsh @@ -1,5 +1,3 @@ -#version 120 -//#extension GL_EXT_gpu_shader4 : disable #include "/lib/settings.glsl" uniform sampler2D colortex4; diff --git a/shaders/world-1/deferred2.vsh b/shaders/dimensions/deferred1.vsh similarity index 83% rename from shaders/world-1/deferred2.vsh rename to shaders/dimensions/deferred1.vsh index 1d24af4..3aafbff 100644 --- a/shaders/world-1/deferred2.vsh +++ b/shaders/dimensions/deferred1.vsh @@ -1,5 +1,3 @@ -#version 120 -//#extension GL_EXT_gpu_shader4 : disable #include "/lib/settings.glsl" uniform vec2 texelSize; diff --git a/shaders/dimensions/final.fsh b/shaders/dimensions/final.fsh new file mode 100644 index 0000000..7820a0f --- /dev/null +++ b/shaders/dimensions/final.fsh @@ -0,0 +1,139 @@ +#include "/lib/settings.glsl" + +varying vec2 texcoord; + +uniform sampler2D colortex7; +// uniform sampler2D noisetex; +uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; +uniform float aspectRatio; +uniform float frameTimeCounter; +uniform int frameCounter; +uniform int isEyeInWater; + + +#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 += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; + result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; + result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; + + result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; + result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; + result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; + + result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; + result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; + result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; + + return result; +} + +/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595 +void applyContrast(inout vec3 color, float contrast){ + color = (color - 0.5) * contrast + 0.5; +} + +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); +} +void applyLuminanceCurve(inout vec3 color, float darks, float brights){ + + // color.r = color.r < 0.5 ? pow(2.0 * color.r, darks) / 2.0 : 1.0 - (pow(2.0 - 2.0 * color.r, brights) / 2.0); + // color.g = color.g < 0.5 ? pow(2.0 * color.g, darks) / 2.0 : 1.0 - (pow(2.0 - 2.0 * color.g, brights) / 2.0); + // color.b = color.b < 0.5 ? pow(2.0 * color.b, darks) / 2.0 : 1.0 - (pow(2.0 - 2.0 * color.b, brights) / 2.0); + + color.r += darks * lowerCurve(color.r) + brights * upperCurve(color.r); + color.g += darks * lowerCurve(color.g) + brights * upperCurve(color.g); + color.b += darks * lowerCurve(color.b) + brights * upperCurve(color.b); +} + +void applyColorCurve(inout vec3 color, vec4 darks, vec4 brights){ + + color.r += (darks.r + darks.a) * lowerCurve(color.r) + (brights.r + brights.a) * upperCurve(color.r); + color.g += (darks.g + darks.a) * lowerCurve(color.g) + (brights.g + brights.a) * upperCurve(color.g); + color.b += (darks.b + darks.a) * lowerCurve(color.b) + (brights.b + brights.a) * upperCurve(color.b); + +} + +void main() { + #ifdef BICUBIC_UPSCALING + vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb; + #else + vec3 col = texture2D(colortex7,texcoord).rgb; + #endif + + + #ifdef CONTRAST_ADAPTATIVE_SHARPENING + //Weights : 1 in the center, 0.5 middle, 0.25 corners + vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; + + + vec3 m1 = -0.5/3.5*col + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5; + vec3 std = abs(col - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) + + abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1); + float contrast = 1.0 - luma(std)/5.0; + col = col*(1.0+(SHARPENING+UPSCALING_SHARPNENING)*contrast) + - (SHARPENING+UPSCALING_SHARPNENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*col); + #endif + + float lum = luma(col); + vec3 diff = col-lum; + col = col + diff*(-lum*CROSSTALK + SATURATION); + + vec3 FINAL_COLOR = clamp(int8Dither(col,texcoord),0.0,1.0); + + #ifdef COLOR_CURVE + applyColorCurve(FINAL_COLOR, vec4(R_LOWER_CURVE, G_LOWER_CURVE, B_LOWER_CURVE, LOWER_CURVE), vec4(R_UPPER_CURVE, G_UPPER_CURVE, B_UPPER_CURVE, UPPER_CURVE)); + #endif + + applyContrast(FINAL_COLOR, CONTRAST); // for fun + + gl_FragColor.rgb = FINAL_COLOR ; +} diff --git a/shaders/world-1/composite15.vsh b/shaders/dimensions/final.vsh similarity index 58% rename from shaders/world-1/composite15.vsh rename to shaders/dimensions/final.vsh index e5dec68..a42ee54 100644 --- a/shaders/world-1/composite15.vsh +++ b/shaders/dimensions/final.vsh @@ -1,24 +1,9 @@ -#version 120 -//#extension GL_EXT_gpu_shader4 : disable #include "/lib/settings.glsl" - varying vec2 texcoord; flat varying vec4 exposure; -flat varying vec2 rodExposureDepth; uniform sampler2D colortex4; -uniform vec2 texelSize; -uniform int framemod8; -const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -27,12 +12,7 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), void main() { - gl_Position = ftransform(); - - texcoord = gl_MultiTexCoord0.xy; exposure=vec4(texelFetch2D(colortex4,ivec2(10,37),0).r*vec3(FinalR,FinalG,FinalB),texelFetch2D(colortex4,ivec2(10,37),0).r); - rodExposureDepth = texelFetch2D(colortex4,ivec2(14,37),0).rg; - rodExposureDepth.y = sqrt(rodExposureDepth.y/65000.0); } diff --git a/shaders/gbuffers_all_particles.fsh b/shaders/gbuffers_all_particles.fsh index c07f6a0..046df43 100644 --- a/shaders/gbuffers_all_particles.fsh +++ b/shaders/gbuffers_all_particles.fsh @@ -37,7 +37,7 @@ uniform vec3 cameraPosition; #include "/lib/sky_gradient.glsl" #include "/lib/volumetricClouds.glsl" -#define OVERWORLD +#define OVERWORLD_SHADER #include "/lib/diffuse_lighting.glsl" //faster and actually more precise than pow 2.2 diff --git a/shaders/gbuffers_all_translucent.fsh b/shaders/gbuffers_all_translucent.fsh index 0f829ad..a244ce1 100644 --- a/shaders/gbuffers_all_translucent.fsh +++ b/shaders/gbuffers_all_translucent.fsh @@ -71,7 +71,7 @@ flat varying vec3 averageSkyCol_Clouds; #include "/lib/clouds.glsl" #include "/lib/stars.glsl" #include "/lib/volumetricClouds.glsl" -#define OVERWORLD +#define OVERWORLD_SHADER #include "/lib/diffuse_lighting.glsl" diff --git a/shaders/lib/diffuse_lighting.glsl b/shaders/lib/diffuse_lighting.glsl index 03e5708..fc96bd7 100644 --- a/shaders/lib/diffuse_lighting.glsl +++ b/shaders/lib/diffuse_lighting.glsl @@ -15,72 +15,64 @@ void DoRTAmbientLighting (vec3 TorchColor, vec2 Lightmap, inout float SkyLM, ino SkyLight = max(SkyLight * SkyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.025 + nightVision)); } -//// OVERWORLD //// -#ifdef OVERWORLD -vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float skyLightDir){ - // Lightmap.x = 0.0; - // Lightmap.y = 1.0; +#ifdef OVERWORLD_SHADER - float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap.x)),5.0)+0.1)); - TorchLM = pow(TorchLM/4,10) + pow(Lightmap.x,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5; - vec3 TorchLight = TorchColor * TorchLM * 0.75; - TorchLight *= TORCH_AMOUNT; - - SkyColor = (SkyColor * ambient_brightness) / 30.0; - - float skyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5; - vec3 SkyLight = max(SkyColor * skyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision) ); - - return SkyLight * skyLightDir + TorchLight; -} -vec3 DoDirectLighting(vec3 SunColor, float Shadow, float NdotL, float SubsurfaceScattering){ - - // vec3 SunLight = max(NdotL * Shadow, SubsurfaceScattering) * SunColor; - vec3 SunLight = NdotL * Shadow * SunColor; + vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float skyLightDir){ + // Lightmap.x = 0.0; + // Lightmap.y = 1.0; - return SunLight; -} + float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap.x)),5.0)+0.1)); + TorchLM = pow(TorchLM/4,10) + pow(Lightmap.x,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5; + vec3 TorchLight = TorchColor * TorchLM * 0.75; + TorchLight *= TORCH_AMOUNT; + + SkyColor = (SkyColor * ambient_brightness) / 30.0; + + float skyLM = (pow(Lightmap.y,15.0)*2.0 + pow(Lightmap.y,2.5))*0.5; + vec3 SkyLight = max(SkyColor * skyLM, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision) ); + + return SkyLight * skyLightDir + TorchLight; + } + + vec3 DoDirectLighting(vec3 SunColor, float Shadow, float NdotL, float SubsurfaceScattering){ + + vec3 SunLight = NdotL * Shadow * SunColor; + + return SunLight; + } + #endif -#ifdef NETHER -//// NETHER //// -vec3 DoAmbientLighting_Nether(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3, vec3 WorldPos){ - - float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1)); - TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5; - vec3 TorchLight = TorchColor * TorchLM * 0.75; - TorchLight *= TORCH_AMOUNT; +#ifdef NETHER_SHADER + vec3 DoAmbientLighting_Nether(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3, vec3 WorldPos){ - FogColor = max(FogColor, vec3(0.05) * MIN_LIGHT_AMOUNT*0.01 + nightVision); + float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1)); + TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5; + vec3 TorchLight = TorchColor * TorchLM * 0.75; + TorchLight *= TORCH_AMOUNT; - return FogColor + TorchLight ; -} + FogColor = max(FogColor, vec3(0.05) * MIN_LIGHT_AMOUNT*0.01 + nightVision); + + return FogColor + TorchLight ; + } #endif -#ifdef END -//// END //// -vec3 DoAmbientLighting_End(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3){ +#ifdef END_SHADER + vec3 DoAmbientLighting_End(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3){ - // vec3 TorchLight = TorchColor * clamp(pow(Lightmap,3.0),0.0,1.0); - // vec3 TorchLight = TorchColor * pow(1.0-pow(1.0-clamp(Lightmap,0.0,1.0) ,0.1),2); - // TorchLight = exp(TorchLight * 30) - 1.0; - - float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1)); - TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; //pow(TorchLM/4.5,10)*2.5 + pow(Lightmap.x,1.5)*0.5; - vec3 TorchLight = TorchColor * TorchLM * 0.75; - TorchLight *= TORCH_AMOUNT; + float TorchLM = 10.0 - ( 1.0 / (pow(exp(-0.5*inversesqrt(Lightmap)),5.0)+0.1)); + TorchLM = pow(TorchLM/4,10) + pow(Lightmap,1.5)*0.5; + vec3 TorchLight = TorchColor * TorchLM * 0.75; + TorchLight *= TORCH_AMOUNT; - FogColor = (FogColor / pow(0.00001 + dot(FogColor,vec3(0.3333)),1.0) ) * 0.1; - // vec3 AmbientLight = sqrt( clamp(1.25 + dot(Normal,np3),0.0,1.0)) * (vec3(0.5,0.75,1.0) * 0.05); - // vec3 AmbientLight = sqrt( clamp(1.25 + dot(Normal,np3),0.0,1.0)*0.5) * FogColor; - // vec3 AmbientLight = vec3(0.5,0.75,1.0) * 0.05 + FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0)*0.5; + FogColor = (FogColor / pow(0.00001 + dot(FogColor,vec3(0.3333)),1.0) ) * 0.1; - vec3 FogTint = FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0) * 0.05; - - vec3 AmbientLight = max(vec3(0.5,0.75,1.0) * 0.05, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) ); + vec3 FogTint = FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0) * 0.05; + + vec3 AmbientLight = max(vec3(0.5,0.75,1.0) * 0.05, (MIN_LIGHT_AMOUNT*0.01 + nightVision*0.5) ); - return TorchLight + AmbientLight + FogTint; -} + return TorchLight + AmbientLight + FogTint; + } #endif \ No newline at end of file diff --git a/shaders/lib/end_fog.glsl b/shaders/lib/end_fog.glsl index 8fda10b..cc16f75 100644 --- a/shaders/lib/end_fog.glsl +++ b/shaders/lib/end_fog.glsl @@ -223,7 +223,11 @@ float cloudVol(in vec3 pos, int LOD){ } -mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) { +vec4 GetVolumetricFog( + vec3 fragpos, + float dither, + float dither2 +) { int SAMPLES = 16; //project pixel position into projected shadowmap space vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; @@ -250,12 +254,11 @@ mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) { vec3 vL = vec3(0.); float dL = length(dVWorld); - vec3 absorbance = vec3(1.0); + float absorbance = 1.0; float expFactor = 11.0; vec3 fogColor = (gl_Fog.color.rgb / max(pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1),0.01) ) ; - for (int i=0;i= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) { - vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x)); - - vec3 vec = t0.xyz - fragpos; - float dsquared = dot(vec,vec); - if (dsquared > 1e-5){ - if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){ - float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.); - occlusion += NdotV; - } - n += 1.0; - } - } - } - - - - - return clamp(1.0-occlusion/n*2.0,0.,1.0); -} -vec3 viewToWorld(vec3 viewPosition) { - vec4 pos; - pos.xyz = viewPosition; - pos.w = 0.0; - pos = gbufferModelViewInverse * pos; - return pos.xyz; -} -vec3 worldToView(vec3 worldPos) { - vec4 pos = vec4(worldPos, 0.0); - pos = gbufferModelView * pos; - return pos.xyz; -} -void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ - inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value - - 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; - - float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; - estEndDepth *= maxZ; - estSunDepth *= maxZ; - - vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; - vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); - - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - float expFactor = 11.0; - for (int i=0;i= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) { - vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x) ); - vec3 vec = t0.xyz - fragpos; - float dsquared = dot(vec,vec); - - if (dsquared > 1e-5){ - if(dsquared > maxR2_2){ - float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.); - sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0); - } - n += 1; - } - } - } - sss = max(1.0 - sss/n, 0.0); -} - - - -vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){ - - vec3 clipPosition = toClipSpace3(position); - float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? - (-near -position.z) / dir.z : far*sqrt(3.); - vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space - direction.xy = normalize(direction.xy); - - //get at which length the ray intersects with the edge of the screen - vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; - float mult = maxLengths.y; - - vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither; - vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; - - spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; - - float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases - - for(int i = 0; i < int(quality); i++){ - spos += stepv; - float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0); - float currZ = linZ(spos.z); - - if( sp < currZ) { - float dist = abs(sp-currZ)/currZ; - if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); - } - spos += stepv; - } - return vec3(1.1); -} -vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){ - float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases - - float stepSize = stepsizes / dist; - int maxSteps = STEPS; - vec3 clipPosition = toClipSpace3(position); - float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ? - (-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far; - vec3 end = toClipSpace3(position+dir*rayLength) ; - vec3 direction = end-clipPosition ; //convert to clip space - - float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize; - //get at which length the ray intersects with the edge of the screen - vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; - - float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0; - - vec3 stepv = direction/len; - - int iterations = min(int(min(len, mult*len)-2), maxSteps); - - //Do one iteration for closest texel (good contact shadows) - vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; - spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; - spos += stepv/(stepSize/2); - - float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases - - for(int i = 0; i < iterations; i++){ - if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1); - spos += stepv*noise; - - float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0); - float currZ = linZ(spos.z); - - if( sp < currZ) { - float dist = abs(sp-currZ)/currZ; - if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); - } - } - return vec3(1.1); -} - -vec3 cosineHemisphereSample(vec2 Xi, float roughness){ - float r = sqrt(Xi.x); - float theta = 2.0 * 3.14159265359 * Xi.y; - - float x = r * cos(theta); - float y = r * sin(theta); - - return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); -} - -vec3 TangentToWorld(vec3 N, vec3 H, float roughness){ - vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); - vec3 T = normalize(cross(UpVector, N)); - vec3 B = cross(N, T); - - return vec3((T * H.x) + (B * H.y) + (N * H.z)); -} -vec2 R2_samples(int n){ - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha * n); -} - -void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){ - int nrays = RAY_COUNT; - - vec3 radiance = vec3(0.0); - vec3 occlusion = vec3(0.0); - vec3 skycontribution = vec3(0.0); - - for (int i = 0; i < nrays; i++){ - int seed = (frameCounter%40000)*nrays+i; - vec2 ij = fract(R2_samples(seed) + noise ); - - vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0); - - #ifdef HQ_SSGI - vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt - #else - vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt - #endif - - skycontribution = lighting; - - if (rayHit.z < 1.){ - - #if indirect_effect == 4 - vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; - previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; - previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; - if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ - radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength; - }else{ - radiance += skycontribution; - } - - #else - radiance += skycontribution; - #endif - - occlusion += skycontribution * GI_Strength; - - } else { - radiance += skycontribution; - } - } - - occlusion *= AO_Strength; - - lighting = max(radiance/nrays - occlusion/nrays, 0.0); -} -void main() { - float dirtAmount = Dirt_Amount; - 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 = dirtEpsilon*dirtAmount + waterEpsilon; - vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; - - float z0 = texture2D(depthtex0,texcoord).x; - float z = texture2D(depthtex1,texcoord).x; - - vec2 tempOffset=TAA_Offset; - float noise = blueNoise(); - - vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z)); - vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; - vec3 np3 = normVec(p3); - - - ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// - - vec4 data = texture2D(colortex1,texcoord); - vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks - vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps - // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); - - vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); - vec2 lightmap = dataUnpacked1.yz; - vec3 normal = decode(dataUnpacked0.yw); - - ////// --------------- UNPACK MISC --------------- ////// - - vec4 SpecularTex = texture2D(colortex8,texcoord); - float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0); - - vec4 normalAndAO = texture2D(colortex15,texcoord); - vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; - vec3 slopednormal = normal; - - #ifdef POM - #ifdef Horrible_slope_normals - vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it. - slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) ); - #endif - #endif - - float vanilla_AO = normalAndAO.a; - normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1); - - bool iswater = texture2D(colortex7,texcoord).a > 0.99; - bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01; - bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01; - bool entities = abs(dataUnpacked1.w-0.45) < 0.01; - - bool hand = abs(dataUnpacked1.w-0.75) < 0.01; - // bool blocklights = abs(dataUnpacked1.w-0.8) <0.01; - - vec3 waterAmbientLightCol = vec3(0.0); - - if (z >=1.0) { - vec3 color = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.02; - - gl_FragData[0].rgb = clamp(fp10Dither(color*8./3. * (1.0-rainStrength*0.4),triangularize(noise)),0.0,65000.); - - } else { - - p3 += gbufferModelViewInverse[3].xyz + cameraPosition; - - // vec3 FogColor = (gl_Fog.color.rgb / pow(0.00001 + dot(gl_Fog.color.rgb,vec3(0.3333)),1.0) ) * 0.2; - // vec3 fogColor = (gl_Fog.color.rgb / max(pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1),0.01) ) ; - // vec3 FogColor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01) ); - - vec3 AmbientLightColor = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb / 10; - - vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 10; - vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb / 10; - - waterAmbientLightCol = down; - - up *= pow( max( slopednormal.y, 0), 2); - down *= pow( max(-slopednormal.y, 0), 2); - AmbientLightColor += up + down; - - // do all ambient lighting stuff - vec3 Indirect_lighting = DoAmbientLighting_Nether(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3, p3 ); - - - #if indirect_effect == 0 - vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; - if(!hand) Indirect_lighting *= AO; - #endif - - #if indirect_effect == 1 - vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; - if(!hand) Indirect_lighting *= ssao(fragpos,noise,FlatNormals) * AO; - #endif - - // RTAO and/or SSGI - #if indirect_effect == 3 || indirect_effect == 4 - if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.x,vec3(TORCH_R,TORCH_G,TORCH_B)); - #endif - - // finalize - gl_FragData[0].rgb = Indirect_lighting * albedo; - - - #ifdef Specular_Reflections - // MaterialReflections_N(gl_FragData[0].rgb, SpecularTex.r, vec3(SpecularTex.g), albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand); - vec3 specNoise = vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise()); - DoSpecularReflections(gl_FragData[0].rgb, fragpos, np3, vec3(0.0), specNoise, normal, SpecularTex.r, SpecularTex.g, albedo, vec3(0.0), 1.0, hand); - #endif - - Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); - - if(lightningBolt) gl_FragData[0].rgb += vec3(77.0, 153.0, 255.0); - - // gl_FragData[0].rgb = AmbientLightColor; - - - - } - - if (iswater && isEyeInWater == 0){ - vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); - float Vdiff = distance(fragpos,fragpos0); - float VdotU = np3.y; - float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane - - vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)); - - waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol); - } - - -/* DRAWBUFFERS:3 */ -} +#include "/dimensions/composite2.fsh" \ No newline at end of file diff --git a/shaders/world-1/composite2.vsh b/shaders/world-1/composite2.vsh index 2d4e654..e2bee5e 100644 --- a/shaders/world-1/composite2.vsh +++ b/shaders/world-1/composite2.vsh @@ -1,51 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define NETHER_SHADER -varying vec2 texcoord; - -// flat varying vec3 avgAmbient; - -flat varying float tempOffsets; -flat varying vec2 TAA_Offset; -flat varying vec3 zMults; - -uniform sampler2D colortex4; - -uniform float far; -uniform float near; -uniform mat4 gbufferModelViewInverse; -uniform vec3 sunPosition; -uniform float rainStrength; -uniform float sunElevation; -uniform int frameCounter; - -const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - - -#include "/lib/util.glsl" - -void main() { - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - - tempOffsets = HaltonSeq2(frameCounter%10000); - - TAA_Offset = offsets[frameCounter%8]; - - #ifndef TAA - TAA_Offset = vec2(0.0); - #endif - - - // avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; - zMults = vec3((far * near)*2.0,far+near,far-near); -} +#include "/dimensions/composite2.vsh" \ No newline at end of file diff --git a/shaders/world-1/composite3.fsh b/shaders/world-1/composite3.fsh index 92e88ff..a08fb95 100644 --- a/shaders/world-1/composite3.fsh +++ b/shaders/world-1/composite3.fsh @@ -1,129 +1,5 @@ #version 120 -//Volumetric fog rendering -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define NETHER_SHADER -flat varying float tempOffsets; -flat varying vec2 TAA_Offset; -uniform sampler2D noisetex; -uniform sampler2D depthtex0; - -uniform sampler2D colortex2; -uniform sampler2D colortex3; -// uniform sampler2D colortex4; - -uniform vec3 sunVec; -uniform float far; -uniform int frameCounter; -uniform float rainStrength; -uniform float sunElevation; -uniform ivec2 eyeBrightnessSmooth; -uniform float frameTimeCounter; -uniform int isEyeInWater; -uniform vec2 texelSize; - -uniform vec3 previousCameraPosition; -varying vec2 texcoord; - -#include "/lib/color_transforms.glsl" -#include "/lib/color_dither.glsl" -#include "/lib/projections.glsl" - - -#include "/lib/nether_fog.glsl" - - -#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) - -float interleaved_gradientNoise(){ - return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); -} -float blueNoise(){ - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); -} - -void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ - inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value - - 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; - - float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; - estEndDepth *= maxZ; - estSunDepth *= maxZ; - - vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; - vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); - - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - float expFactor = 11.0; - for (int i=0;i 0.99; - float translucentAlpha = trpData.a; - - // vec4 speculartex = texture2D(colortex8,texcoord); // translucents - // float sunlight = speculartex.b; - - //3x3 bilateral upscale from half resolution - float z = texture2D(depthtex0,texcoord).x; - float z2 = texture2D(depthtex1,texcoord).x; - float frDepth = ld(z2); - - // vec4 vl = texture2D(colortex0,texcoord * 0.5); - - ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// - vec4 data_opaque = texture2D(colortex1,texcoord); - vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps - // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); - - bool hand = abs(dataUnpacked1.w-0.75) < 0.01; - vec2 lightmap = dataUnpacked1.yz; - - ////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- ////// - - vec3 data = texture2D(colortex11,texcoord).rgb; - - vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ; - vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ; - - - - vec4 albedo = vec4(unpack0.ba,unpack1.rg); - - vec2 tangentNormals = unpack0.xy*2.0-1.0; - - if(albedo.a <= 0.0) tangentNormals = vec2(0.0); - - vec4 TranslucentShader = texture2D(colortex2,texcoord); - - float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0); - - - vec2 tempOffset = TAA_Offset; - vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); - vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2)); - - - vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; - vec3 np3 = normVec(p3); - - - vec2 refractedCoord = texcoord; - - /// --- REFRACTION --- /// - #ifdef Refraction - refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE; - // refractedCoord += tangentNormals * 0.1 * RENDER_SCALE; - - float refractedalpha = decodeVec2(texture2D(colortex11,refractedCoord).b).g; - float refractedalpha2 = texture2D(colortex7,refractedCoord).a; - if( refractedalpha <= 0.001 ||z < 0.56) refractedCoord = texcoord; // remove refracted coords on solids - #endif - - /// --- MAIN COLOR BUFFER --- /// - // it is sampled with distorted texcoords - vec3 color = texture2D(colortex3,refractedCoord).rgb; - - vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0)); - float bloomyFogMult = 1.0; - - if (TranslucentShader.a > 0.0){ - #ifdef Glass_Tint - if(albedo.a > 0.2) color = color*albedo.rgb + color * clamp(pow(1.0-luma(albedo.rgb),20.),0.0,1.0); - #endif - - color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb; - } - - - // underwater fog - if (isEyeInWater == 1){ - float dirtAmount = Dirt_Amount; - 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 = dirtEpsilon*dirtAmount + waterEpsilon; - - // float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0); - // vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0); - vec3 fogfade = clamp( exp( (-length(fragpos)) * totEpsilon ) ,0.0,1.0); - fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0); - - color.rgb *= fogfade ; - bloomyFogMult *= 0.4; - } - - // apply VL fog to the scene - color *= vl.a; - color += vl.rgb; - -// bloomy rain effect - float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); - if(rainDrops > 0.0) bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0); - - /// lava. - if (isEyeInWater == 2){ - color.rgb = vec3(4.0,0.5,0.1); - } - - /// powdered snow - if (isEyeInWater == 3){ - color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); - bloomyFogMult = 0.0; - } - - // blidnesss - color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness); - - // darkness effect - color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); - - #ifdef display_LUT - vec2 movedTC = texcoord; - vec3 thingy = texture2D(colortex4,movedTC).rgb / 150. * 5.0; - if(luma(thingy) > 0.0 ) color.rgb = thingy; - #endif - - gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog - - gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); - -} \ No newline at end of file +#include "/dimensions/composite6.fsh" \ No newline at end of file diff --git a/shaders/world-1/composite6.vsh b/shaders/world-1/composite6.vsh index ba85ff0..1a6f8de 100644 --- a/shaders/world-1/composite6.vsh +++ b/shaders/world-1/composite6.vsh @@ -1,19 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -varying vec2 texcoord; -flat varying vec3 zMults; -uniform float far; -uniform float near; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define NETHER_SHADER -void main() { - zMults = vec3(1.0/(far * near),far+near,far-near); - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - -} +#include "/dimensions/composite6.vsh" \ No newline at end of file diff --git a/shaders/world-1/composite7.fsh b/shaders/world-1/composite7.fsh new file mode 100644 index 0000000..98dd642 --- /dev/null +++ b/shaders/world-1/composite7.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define NETHER_SHADER + +#include "/dimensions/composite7.fsh" \ No newline at end of file diff --git a/shaders/world-1/composite7.vsh b/shaders/world-1/composite7.vsh new file mode 100644 index 0000000..226fed4 --- /dev/null +++ b/shaders/world-1/composite7.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define NETHER_SHADER + +#include "/dimensions/composite7.vsh" \ No newline at end of file diff --git a/shaders/world-1/composite8.fsh b/shaders/world-1/composite8.fsh index 2e6773c..f46e843 100644 --- a/shaders/world-1/composite8.fsh +++ b/shaders/world-1/composite8.fsh @@ -1,354 +1,5 @@ #version 120 -//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader) -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" -#include "/lib/res_params.glsl" +#define NETHER_SHADER -const int noiseTextureResolution = 32; - - -/* -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 colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) -const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final) -const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) -*/ -//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; - -varying vec2 texcoord; -flat varying float exposureA; -flat varying float tempOffsets; -uniform sampler2D colortex3; -uniform sampler2D colortex0; -uniform sampler2D colortex5; -uniform sampler2D colortex6; -uniform sampler2D depthtex0; - -uniform vec2 texelSize; -uniform float frameTimeCounter; -uniform int framemod8; -uniform float viewHeight; -uniform float viewWidth; -uniform vec3 previousCameraPosition; -uniform mat4 gbufferPreviousModelView; - - - - -#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) - -#include "/lib/projections.glsl" - - -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); -} -vec3 fp10Dither(vec3 color,float dither){ - const vec3 mantissaBits = vec3(6.,6.,5.); - vec3 exponent = floor(log2(color)); - return color + dither*exp2(-mantissaBits)*exp2(exponent); -} - - -//returns the projected coordinates of the closest point to the camera in the 3x3 neighborhood -vec3 closestToCamera3x3() -{ - vec2 du = vec2(texelSize.x, 0.0); - vec2 dv = vec2(0.0, texelSize.y); - - vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthtex0, texcoord - dv - du).x); - vec3 dtc = vec3(texcoord,0.) + vec3( 0.0, -texelSize.y, texture2D(depthtex0, texcoord - dv).x); - vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthtex0, texcoord - dv + du).x); - - vec3 dml = vec3(texcoord,0.) + vec3(-texelSize.x, 0.0, texture2D(depthtex0, texcoord - du).x); - vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthtex0, texcoord).x); - vec3 dmr = vec3(texcoord,0.) + vec3( texelSize.x, 0.0, texture2D(depthtex0, texcoord + du).x); - - vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv - du).x); - vec3 dbc = vec3(texcoord,0.) + vec3( 0.0, texelSize.y, texture2D(depthtex0, texcoord + dv).x); - vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv + du).x); - - vec3 dmin = dmc; - - dmin = dmin.z > dtc.z? dtc : dmin; - dmin = dmin.z > dtr.z? dtr : dmin; - - dmin = dmin.z > dml.z? dml : dmin; - dmin = dmin.z > dtl.z? dtl : dmin; - dmin = dmin.z > dmr.z? dmr : dmin; - - dmin = dmin.z > dbl.z? dbl : dmin; - dmin = dmin.z > dbc.z? dbc : dmin; - dmin = dmin.z > dbr.z? dbr : dmin; - - return dmin; -} - -//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 texture2D( tex, uv); -} -//Due to low sample count we "tonemap" the inputs to preserve colors and smoother edges -vec3 weightedSample(sampler2D colorTex, vec2 texcoord){ - vec3 wsample = texture2D(colorTex,texcoord).rgb*exposureA; - return wsample/(1.0+luma(wsample)); - -} - - -//from : https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 -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 += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; - result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; - result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; - - result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; - result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; - result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; - - result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; - result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; - result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; - - return result; -} -//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 = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb; - - vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); - vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); - vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + - vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + - vec4(centerColor, 1.0) * (w12.x * w12.y) + - vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + - vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); - return color.rgb/color.a; - -} - -vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max) - { - vec3 p_clip = 0.5 * (aabb_max + aabb_min); - vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001; - - vec3 v_clip = q - vec3(p_clip); - vec3 v_unit = v_clip.xyz / e_clip; - vec3 a_unit = abs(v_unit); - float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); - - if (ma_unit > 1.0) - return vec3(p_clip) + v_clip / ma_unit; - else - return q; - } -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)); -} -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, texture2D(depth, texcoord - dv - du).x); - vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); - vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); - vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); - vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(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; - - return dmin; -} -const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - -vec3 TAA_hq(){ - - vec2 adjTC = texcoord; - - - //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion - #ifdef CLOSEST_VELOCITY - vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); - #endif - - #ifndef CLOSEST_VELOCITY - vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x); - #endif - - //reproject previous frame - vec3 fragposition = toScreenSpace(closestToCamera); - fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); - vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz; - previousPosition = toClipSpace3Prev(previousPosition); - vec2 velocity = previousPosition.xy - closestToCamera.xy; - previousPosition.xy = texcoord + velocity; - - //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 smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz; - - - vec3 albedoCurrent0 = texture2D(colortex3, adjTC).rgb; - vec3 albedoCurrent1 = texture2D(colortex3, adjTC + vec2(texelSize.x,texelSize.y)).rgb; - vec3 albedoCurrent2 = texture2D(colortex3, adjTC + vec2(texelSize.x,-texelSize.y)).rgb; - vec3 albedoCurrent3 = texture2D(colortex3, adjTC + vec2(-texelSize.x,-texelSize.y)).rgb; - vec3 albedoCurrent4 = texture2D(colortex3, adjTC + vec2(-texelSize.x,texelSize.y)).rgb; - vec3 albedoCurrent5 = texture2D(colortex3, adjTC + vec2(0.0,texelSize.y)).rgb; - vec3 albedoCurrent6 = texture2D(colortex3, adjTC + vec2(0.0,-texelSize.y)).rgb; - vec3 albedoCurrent7 = texture2D(colortex3, adjTC + vec2(-texelSize.x,0.0)).rgb; - vec3 albedoCurrent8 = texture2D(colortex3, adjTC + vec2(texelSize.x,0.0)).rgb; - //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 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8)))))); - vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8)))))); - albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).rgb; - - - #ifndef NO_CLIP - vec3 albedoPrev = max(FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.75).xyz, 0.0); - vec3 finalcAcc = clamp(albedoPrev,cMin,cMax); - - //Increases blending factor when far from AABB and in motion, reduces ghosting - float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5; - float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0); - - float test = 0.05; - // if(hand) movementRejection *= 5; - // if(istranslucent) test = 0.1; - - //Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering - // vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.))); - - vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.))); - #endif - - - #ifdef NO_CLIP - vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz; - vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.)); - #endif - - //De-tonemap - return supersampled; -} - -void main() { - -/* DRAWBUFFERS:5 */ - gl_FragData[0].a = 1.0; - - #ifdef TAA - vec3 color = TAA_hq(); - gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0); - #endif - - #ifndef TAA - vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.); - gl_FragData[0].rgb = color; - #endif - - - - - -} +#include "/dimensions/composite8.fsh" \ No newline at end of file diff --git a/shaders/world-1/composite8.vsh b/shaders/world-1/composite8.vsh index 2ead011..1424be4 100644 --- a/shaders/world-1/composite8.vsh +++ b/shaders/world-1/composite8.vsh @@ -1,20 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable +#define NETHER_SHADER -varying vec2 texcoord; -flat varying float exposureA; -flat varying float tempOffsets; -uniform sampler2D colortex4; -uniform int frameCounter; - - -#include "/lib/util.glsl" - -void main() { - - tempOffsets = HaltonSeq2(frameCounter%10000); - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r; -} +#include "/dimensions/composite8.vsh" \ No newline at end of file diff --git a/shaders/world-1/composite9.fsh b/shaders/world-1/composite9.fsh index a4b6244..bad4613 100644 --- a/shaders/world-1/composite9.fsh +++ b/shaders/world-1/composite9.fsh @@ -1,45 +1,5 @@ #version 120 -//downsample 1st pass (half res) for bloom -uniform sampler2D colortex5; -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define NETHER_SHADER -void main() { - -/* DRAWBUFFERS:3 */ -vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*2.*resScale*texelSize; - - //0.5 - gl_FragData[0] = texture2D(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; - - //0.25 - gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125; - - //0.125 - gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; - - //0.125 - gl_FragData[0] += texture2D(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); - - -} +#include "/dimensions/composite9.fsh" \ No newline at end of file diff --git a/shaders/world-1/composite9.vsh b/shaders/world-1/composite9.vsh index 386f006..4260062 100644 --- a/shaders/world-1/composite9.vsh +++ b/shaders/world-1/composite9.vsh @@ -1,17 +1,5 @@ #version 120 -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define NETHER_SHADER -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; -} +#include "/dimensions/composite9.vsh" \ No newline at end of file diff --git a/shaders/world-1/deferred.fsh b/shaders/world-1/deferred.fsh index 7a39f29..2a4b0f6 100644 --- a/shaders/world-1/deferred.fsh +++ b/shaders/world-1/deferred.fsh @@ -1,92 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable +#define NETHER_SHADER -#include "/lib/settings.glsl" - -flat varying vec2 tempOffsets; - -flat varying float exposure; -flat varying float avgBrightness; -flat varying float rodExposure; -flat varying float avgL2; -flat varying float centerDepth; - -uniform sampler2D colortex4; -uniform sampler2D noisetex; - -uniform int frameCounter; -uniform float rainStrength; -uniform float eyeAltitude; -uniform vec3 sunVec; -uniform vec2 texelSize; -uniform float frameTimeCounter; -uniform mat4 gbufferProjection; -uniform mat4 gbufferProjectionInverse; -uniform mat4 gbufferPreviousProjection; -uniform mat4 gbufferModelViewInverse; -uniform mat4 gbufferModelView; -uniform mat4 shadowModelView; -uniform mat4 shadowProjection; -uniform float sunElevation; -uniform vec3 cameraPosition; -uniform float far; -uniform ivec2 eyeBrightnessSmooth; - - -#include "/lib/util.glsl" - - -vec3 toShadowSpaceProjected(vec3 p3){ - p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz; - p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz; - p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz; - - return p3; -} -float interleaved_gradientNoise(){ - vec2 coord = gl_FragCoord.xy; - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887); - return noise; -} -float blueNoise(){ - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); -} - -#include "/lib/nether_fog.glsl" - -void main() { -/* DRAWBUFFERS:4 */ - -gl_FragData[0] = vec4(0.0,0.0,0.0,0.0); - -vec2 fogPos = vec2(256.0 - 256.0*0.12,1.0); -//Sky gradient with clouds -if (gl_FragCoord.x > (fogPos.x - fogPos.x*0.22) && gl_FragCoord.y > 0.4 && gl_FragCoord.x < 535){ - - // vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0); - vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.2,1.2); - vec3 viewVector = cartToSphere(p); - - // vec3 BackgroundColor = (gl_Fog.color.rgb / max(dot(gl_Fog.color.rgb,vec3(0.3333)),0.01)) / 30.0; - // BackgroundColor *= abs(viewVector.y+0.5); - vec3 BackgroundColor = vec3(0.0); - - vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*256., fract(frameCounter/1.6180339887)); - BackgroundColor += VL_Fog.rgb/5.0; - - gl_FragData[0] = vec4(BackgroundColor,1.0); -} - -//Temporally accumulate sky and light values -vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb; -vec3 curr = gl_FragData[0].rgb*150.; -gl_FragData[0].rgb = clamp(mix(temp,curr,0.05),0.0,65000.); - -//Exposure values -if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) -gl_FragData[0] = vec4(exposure,avgBrightness,avgL2,1.0); -if (gl_FragCoord.x > 14. && gl_FragCoord.x < 15. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) -gl_FragData[0] = vec4(rodExposure,centerDepth,0.0, 1.0); - -} +#include "/dimensions/deferred.fsh" \ No newline at end of file diff --git a/shaders/world-1/deferred.vsh b/shaders/world-1/deferred.vsh index 92ced44..f0c470c 100644 --- a/shaders/world-1/deferred.vsh +++ b/shaders/world-1/deferred.vsh @@ -1,108 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable +#define NETHER_SHADER -#include "/lib/settings.glsl" -#include "/lib/res_params.glsl" - -flat varying vec2 tempOffsets; -flat varying float exposure; -flat varying float avgBrightness; -flat varying float rodExposure; -flat varying float avgL2; -flat varying float centerDepth; - -uniform sampler2D colortex4; -uniform sampler2D colortex6; -uniform sampler2D depthtex0; - -uniform mat4 gbufferModelViewInverse; -uniform vec3 sunPosition; -uniform vec2 texelSize; -uniform float sunElevation; -uniform float eyeAltitude; -uniform float near; -uniform float far; -uniform float frameTime; -uniform int frameCounter; -uniform float rainStrength; - -// uniform int worldTime; -vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition); - -#include "/lib/sky_gradient.glsl" -#include "/lib/util.glsl" -#include "/lib/ROBOBO_sky.glsl" - -float luma(vec3 color) { - return dot(color,vec3(0.21, 0.72, 0.07)); -} - -//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ -vec2 R2_samples(int n){ - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha * n); -} -float tanh(float x){ - return (exp(x) - exp(-x))/(exp(x) + exp(-x)); -} -float ld(float depth) { - return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near -} - -uniform float nightVision; - - -void main() { - - gl_Position = ftransform()*0.5+0.5; - gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize; - gl_Position.xy = gl_Position.xy*2.-1.0; - -////////////////////////////// -/// --- EXPOSURE STUFF --- /// -////////////////////////////// - - float avgLuma = 0.0; - float m2 = 0.0; - int n=100; - vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.)); - float avgExp = 0.0; - float avgB = 0.0; - vec2 resScale = vec2(1920.,1080.)/clampedRes; - const int maxITexp = 50; - float w = 0.0; - for (int i = 0; i < maxITexp; i++){ - vec2 ij = R2_samples((frameCounter%2000)*maxITexp+i); - vec2 tc = 0.5 + (ij-0.5) * 0.7; - vec3 sp = texture2D(colortex6,tc/16. * resScale+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; - avgExp += log(luma(sp)); - avgB += log(min(dot(sp,vec3(0.07,0.22,0.71)),8e-2)); - } - - avgExp = exp(avgExp/maxITexp); - avgB = exp(avgB/maxITexp); - - avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0); - - float L = max(avgBrightness,1e-8); - float keyVal = 1.03-2.0/(log(L*4000/150.*8./3.0+1.0)/log(10.0)+2.0); - float expFunc = 0.5+0.5*tanh(log(L)); - float targetExposure = 0.18/log2(L*2.5+1.045)*0.62; - - avgL2 = clamp(mix(avgB,texelFetch2D(colortex4,ivec2(10,37),0).b,0.985),0.00003051757,65000.0); - float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2; - - - exposure = max(targetExposure*EXPOSURE_MULTIPLIER, 0); - float currCenterDepth = ld(texture2D(depthtex0, vec2(0.5)).r); - centerDepth = mix(sqrt(texelFetch2D(colortex4,ivec2(14,37),0).g/65000.0), currCenterDepth, clamp(DoF_Adaptation_Speed*exp(-0.016/frameTime+1.0)/(6.0+currCenterDepth*far),0.0,1.0)); - centerDepth = centerDepth * centerDepth * 65000.0; - - rodExposure = targetrodExposure; - - #ifndef AUTO_EXPOSURE - exposure = Manual_exposure_value; - rodExposure = clamp(log(Manual_exposure_value*2.0+1.0)-0.1,0.0,2.0); - #endif -} \ No newline at end of file +#include "/dimensions/deferred.vsh" \ No newline at end of file diff --git a/shaders/world-1/deferred1.fsh b/shaders/world-1/deferred1.fsh new file mode 100644 index 0000000..50561d8 --- /dev/null +++ b/shaders/world-1/deferred1.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define NETHER_SHADER + +#include "/dimensions/deferred1.fsh" \ No newline at end of file diff --git a/shaders/world-1/deferred1.vsh b/shaders/world-1/deferred1.vsh new file mode 100644 index 0000000..7dd0e85 --- /dev/null +++ b/shaders/world-1/deferred1.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define NETHER_SHADER + +#include "/dimensions/deferred1.vsh" \ No newline at end of file diff --git a/shaders/world-1/final.fsh b/shaders/world-1/final.fsh index 55c84a7..140612c 100644 --- a/shaders/world-1/final.fsh +++ b/shaders/world-1/final.fsh @@ -1,109 +1,5 @@ #version 120 -//Vignetting, applies bloom, applies exposure and tonemaps the final image -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define NETHER_SHADER - -varying vec2 texcoord; - -uniform sampler2D colortex7; -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; -uniform float frameTimeCounter; -uniform int frameCounter; -uniform int isEyeInWater; - -#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 += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; - result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; - result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; - - result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; - result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; - result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; - - result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; - result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; - result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; - - return result; -} - -/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595 -void applyContrast(inout vec3 color, float contrast){ - color = (color - 0.5) * contrast + 0.5; -} - -void main() { - #ifdef BICUBIC_UPSCALING - vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb; - #else - vec3 col = texture2D(colortex7,texcoord).rgb; - #endif - - #ifdef CONTRAST_ADAPTATIVE_SHARPENING - //Weights : 1 in the center, 0.5 middle, 0.25 corners - vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - - - vec3 m1 = -0.5/3.5*col + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5; - vec3 std = abs(col - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) + - abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1); - float contrast = 1.0 - luma(std)/5.0; - col = col*(1.0+(SHARPENING)*contrast) - - (SHARPENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*col); - #endif - - float lum = luma(col); - vec3 diff = col-lum; - col = col + diff*(-lum*CROSSTALK + SATURATION); - //col = -vec3(-lum*CROSSFADING + SATURATION); - - applyContrast(col, CONTRAST); - - gl_FragColor.rgb = clamp(int8Dither(col,texcoord),0.0,1.0); - //gl_FragColor.rgb = vec3(contrast); -} +#include "/dimensions/final.fsh" \ No newline at end of file diff --git a/shaders/world-1/final.vsh b/shaders/world-1/final.vsh index 822a7b0..60af4d5 100644 --- a/shaders/world-1/final.vsh +++ b/shaders/world-1/final.vsh @@ -1,20 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" -varying vec2 texcoord; -flat varying vec4 exposure; -uniform sampler2D colortex4; +#define NETHER_SHADER -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// - -void main() { - - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - exposure=vec4(texelFetch2D(colortex4,ivec2(10,37),0).r*vec3(FinalR,FinalG,FinalB),texelFetch2D(colortex4,ivec2(10,37),0).r); -} +#include "/dimensions/final.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_basic.fsh b/shaders/world-1/gbuffers_basic.fsh index 7bb4bf0..b6c50e0 100644 --- a/shaders/world-1/gbuffers_basic.fsh +++ b/shaders/world-1/gbuffers_basic.fsh @@ -3,4 +3,7 @@ // #define ENTITIES #define BLOCKENTITIES #define WORLD -#include "/programs/all_solid.fsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_basic.vsh b/shaders/world-1/gbuffers_basic.vsh index b2c0524..47026d7 100644 --- a/shaders/world-1/gbuffers_basic.vsh +++ b/shaders/world-1/gbuffers_basic.vsh @@ -5,4 +5,6 @@ #define BLOCKENTITIES #define WORLD -#include "/programs/all_solid.vsh" \ No newline at end of file +#define NETHER_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_beaconbeam.fsh b/shaders/world-1/gbuffers_beaconbeam.fsh index 4ddf770..6c6a7bf 100644 --- a/shaders/world-1/gbuffers_beaconbeam.fsh +++ b/shaders/world-1/gbuffers_beaconbeam.fsh @@ -1,9 +1,10 @@ #version 120 +#include "/lib/settings.glsl" -varying vec4 color; +varying vec4 lmtexcoord; varying vec2 texcoord; - +varying vec4 color; uniform sampler2D texture; //faster and actually more precise than pow 2.2 @@ -11,24 +12,6 @@ vec3 toLinear(vec3 sRGB){ return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); } -vec4 encode (vec3 n, vec2 lightmaps){ - 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 vec4(encn,vec2(lightmaps.x,lightmaps.y)); -} - -//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)); -} - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -38,10 +21,9 @@ float encodeVec2(float x,float y){ void main() { - vec4 Albedo = vec4(texture2D(texture, texcoord).rgb*5.0,1.0); - Albedo *= color; - Albedo.rgb = toLinear(Albedo.rgb); + vec4 Albedo = texture2D(texture, texcoord.xy) * color * 1.5; + + gl_FragData[0] = vec4(toLinear(Albedo.rgb), 1.0); + gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.5); - gl_FragData[0] = Albedo; - gl_FragData[1] = vec4(0.0,0.0,0.0,0.9); -} \ No newline at end of file +} diff --git a/shaders/world-1/gbuffers_beaconbeam.vsh b/shaders/world-1/gbuffers_beaconbeam.vsh index 845f4ba..32726c5 100644 --- a/shaders/world-1/gbuffers_beaconbeam.vsh +++ b/shaders/world-1/gbuffers_beaconbeam.vsh @@ -33,15 +33,11 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), void main() { gl_Position = ftransform(); - if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1); texcoord = (gl_MultiTexCoord0).xy; color = gl_Color; - #ifdef TAA_UPSCALING - gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; - #endif #ifdef TAA gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; #endif diff --git a/shaders/world-1/gbuffers_block.fsh b/shaders/world-1/gbuffers_block.fsh index 3f53c5f..73877eb 100644 --- a/shaders/world-1/gbuffers_block.fsh +++ b/shaders/world-1/gbuffers_block.fsh @@ -3,4 +3,6 @@ #define WORLD #define BLOCKENTITIES -#include "/programs/all_solid.fsh" \ No newline at end of file +#define NETHER_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_block.vsh b/shaders/world-1/gbuffers_block.vsh index dd49c86..175b144 100644 --- a/shaders/world-1/gbuffers_block.vsh +++ b/shaders/world-1/gbuffers_block.vsh @@ -2,4 +2,7 @@ #define WORLD #define BLOCKENTITIES -#include "/programs/all_solid.vsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_entities.fsh b/shaders/world-1/gbuffers_entities.fsh index 234213a..432bac4 100644 --- a/shaders/world-1/gbuffers_entities.fsh +++ b/shaders/world-1/gbuffers_entities.fsh @@ -3,4 +3,6 @@ #define WORLD #define ENTITIES -#include "/programs/all_solid.fsh" \ No newline at end of file +#define NETHER_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_entities.vsh b/shaders/world-1/gbuffers_entities.vsh index 866d895..06e81ed 100644 --- a/shaders/world-1/gbuffers_entities.vsh +++ b/shaders/world-1/gbuffers_entities.vsh @@ -4,4 +4,6 @@ // #define WORLD #define ENTITIES -#include "/programs/all_solid.vsh" \ No newline at end of file +#define NETHER_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand.fsh b/shaders/world-1/gbuffers_hand.fsh index 2d14b09..56f2457 100644 --- a/shaders/world-1/gbuffers_hand.fsh +++ b/shaders/world-1/gbuffers_hand.fsh @@ -2,4 +2,7 @@ #define WORLD #define HAND -#include "/programs/all_solid.fsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand.vsh b/shaders/world-1/gbuffers_hand.vsh index a2820e6..1aee1c3 100644 --- a/shaders/world-1/gbuffers_hand.vsh +++ b/shaders/world-1/gbuffers_hand.vsh @@ -3,4 +3,6 @@ #define WORLD #define HAND -#include "/programs/all_solid.vsh" \ No newline at end of file +#define NETHER_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand_water.fsh b/shaders/world-1/gbuffers_hand_water.fsh index 59a7bed..27407c9 100644 --- a/shaders/world-1/gbuffers_hand_water.fsh +++ b/shaders/world-1/gbuffers_hand_water.fsh @@ -1,3 +1,7 @@ #version 120 -#include "/programs/all_translucent.fsh" \ No newline at end of file +#define NETHER + +#define NETHER_SHADER + +#include "/dimensions/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand_water.vsh b/shaders/world-1/gbuffers_hand_water.vsh index afcff5d..1aaf6cc 100644 --- a/shaders/world-1/gbuffers_hand_water.vsh +++ b/shaders/world-1/gbuffers_hand_water.vsh @@ -1,3 +1,7 @@ #version 120 -#include "/programs/all_translucent.vsh" \ No newline at end of file +#define NETHER + +#define NETHER_SHADER + +#include "/dimensions/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_skybasic.fsh b/shaders/world-1/gbuffers_skybasic.fsh index 563a191..21db346 100644 --- a/shaders/world-1/gbuffers_skybasic.fsh +++ b/shaders/world-1/gbuffers_skybasic.fsh @@ -1,9 +1,7 @@ #version 120 -/* DRAWBUFFERS:3 */ - - +/* RENDERTARGETS:0 */ void main() { - + discard; } diff --git a/shaders/world-1/gbuffers_skybasic.vsh b/shaders/world-1/gbuffers_skybasic.vsh index b76e386..0a2f94b 100644 --- a/shaders/world-1/gbuffers_skybasic.vsh +++ b/shaders/world-1/gbuffers_skybasic.vsh @@ -1,14 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable - - -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// void main() { - - gl_Position.w = -1.0; + gl_Position = ftransform(); } diff --git a/shaders/world-1/gbuffers_skytextured.fsh b/shaders/world-1/gbuffers_skytextured.fsh index 8ad1592..21db346 100644 --- a/shaders/world-1/gbuffers_skytextured.fsh +++ b/shaders/world-1/gbuffers_skytextured.fsh @@ -1,24 +1,7 @@ #version 120 -/* -!! DO NOT REMOVE !! -This code is from Chocapic13' shaders -Read the terms of modification and sharing before changing something below please ! -!! DO NOT REMOVE !! -*/ +/* RENDERTARGETS:0 */ -/* DRAWBUFFERS:1 */ - -varying vec4 color; -varying vec2 texcoord; -//faster and actually more precise than pow 2.2 -vec3 toLinear(vec3 sRGB){ - return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); -} - -uniform sampler2D texture; void main() { - - gl_FragData[0] = texture2D(texture,texcoord.xy)*color; - gl_FragData[0].rgb = gl_FragData[0].rgb*gl_FragData[0].a; + discard; } diff --git a/shaders/world-1/gbuffers_skytextured.vsh b/shaders/world-1/gbuffers_skytextured.vsh index 2c401c5..0a2f94b 100644 --- a/shaders/world-1/gbuffers_skytextured.vsh +++ b/shaders/world-1/gbuffers_skytextured.vsh @@ -1,36 +1,5 @@ #version 120 -#define TAA -/* -!! DO NOT REMOVE !! -This code is from Chocapic13' shaders -Read the terms of modification and sharing before changing something below please ! -!! DO NOT REMOVE !! -*/ - -varying vec4 color; -varying vec2 texcoord; - -uniform vec2 texelSize; -uniform int framemod8; - const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); void main() { - texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; - - - - color = gl_Color; - gl_Position = ftransform(); - #ifdef TAA - gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; - #endif } - diff --git a/shaders/world-1/gbuffers_spidereyes.fsh b/shaders/world-1/gbuffers_spidereyes.fsh index ece8cad..8255274 100644 --- a/shaders/world-1/gbuffers_spidereyes.fsh +++ b/shaders/world-1/gbuffers_spidereyes.fsh @@ -1,9 +1,10 @@ #version 120 +#include "/lib/settings.glsl" -varying vec4 color; +varying vec4 lmtexcoord; varying vec2 texcoord; - +varying vec4 color; uniform sampler2D texture; //faster and actually more precise than pow 2.2 @@ -11,24 +12,6 @@ vec3 toLinear(vec3 sRGB){ return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); } -vec4 encode (vec3 n, vec2 lightmaps){ - 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 vec4(encn,vec2(lightmaps.x,lightmaps.y)); -} - -//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)); -} - //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -38,12 +21,9 @@ float encodeVec2(float x,float y){ void main() { - vec4 Albedo = texture2D(texture, texcoord); + vec4 Albedo = texture2D(texture, texcoord.xy) * color; + + gl_FragData[0] = vec4(toLinear(Albedo.rgb), Albedo.a); + gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.5); - Albedo *= color; - Albedo.rgb = toLinear(Albedo.rgb); - - gl_FragData[0] = Albedo; - - gl_FragData[1] = vec4(0.0,0.0,0.0,0.5); -} \ No newline at end of file +} diff --git a/shaders/world-1/gbuffers_spidereyes.vsh b/shaders/world-1/gbuffers_spidereyes.vsh index 597ab25..70f53ae 100644 --- a/shaders/world-1/gbuffers_spidereyes.vsh +++ b/shaders/world-1/gbuffers_spidereyes.vsh @@ -34,14 +34,9 @@ void main() { gl_Position = ftransform(); - // if(gl_Color.a < 0.1 ) gl_Position = vec4(10,10,10,1); - texcoord = (gl_MultiTexCoord0).xy; color = gl_Color; - #ifdef TAA_UPSCALING - gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; - #endif #ifdef TAA gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; #endif diff --git a/shaders/world-1/gbuffers_terrain.fsh b/shaders/world-1/gbuffers_terrain.fsh index d9afdd3..620bdc2 100644 --- a/shaders/world-1/gbuffers_terrain.fsh +++ b/shaders/world-1/gbuffers_terrain.fsh @@ -1,5 +1,7 @@ #version 120 +#define NETHER_SHADER + #define WORLD -#include "/programs/all_solid.fsh" \ No newline at end of file +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_terrain.vsh b/shaders/world-1/gbuffers_terrain.vsh index d18fc18..ee6cf82 100644 --- a/shaders/world-1/gbuffers_terrain.vsh +++ b/shaders/world-1/gbuffers_terrain.vsh @@ -1,5 +1,7 @@ #version 120 +#define NETHER_SHADER + #define WORLD -#include "/programs/all_solid.vsh" \ No newline at end of file +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured.fsh b/shaders/world-1/gbuffers_textured.fsh index 0f62590..a9b24b2 100644 --- a/shaders/world-1/gbuffers_textured.fsh +++ b/shaders/world-1/gbuffers_textured.fsh @@ -1,3 +1,6 @@ #version 120 -#include "/programs/all_particles.fsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured.vsh b/shaders/world-1/gbuffers_textured.vsh index a6d1cbf..d5d05e9 100644 --- a/shaders/world-1/gbuffers_textured.vsh +++ b/shaders/world-1/gbuffers_textured.vsh @@ -1,3 +1,6 @@ #version 120 -#include "/programs/all_particles.vsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured_lit.fsh b/shaders/world-1/gbuffers_textured_lit.fsh index 0f62590..b86b50a 100644 --- a/shaders/world-1/gbuffers_textured_lit.fsh +++ b/shaders/world-1/gbuffers_textured_lit.fsh @@ -1,3 +1,5 @@ #version 120 -#include "/programs/all_particles.fsh" \ No newline at end of file +#define NETHER_SHADER + +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured_lit.vsh b/shaders/world-1/gbuffers_textured_lit.vsh index c9e7eab..e484278 100644 --- a/shaders/world-1/gbuffers_textured_lit.vsh +++ b/shaders/world-1/gbuffers_textured_lit.vsh @@ -2,4 +2,7 @@ // #define WEATHER #define PARTICLES -#include "/programs/all_particles.vsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_water.fsh b/shaders/world-1/gbuffers_water.fsh index 06e8753..27407c9 100644 --- a/shaders/world-1/gbuffers_water.fsh +++ b/shaders/world-1/gbuffers_water.fsh @@ -1,4 +1,7 @@ #version 120 #define NETHER -#include "/programs/all_translucent.fsh" \ No newline at end of file + +#define NETHER_SHADER + +#include "/dimensions/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_water.vsh b/shaders/world-1/gbuffers_water.vsh index afcff5d..1aaf6cc 100644 --- a/shaders/world-1/gbuffers_water.vsh +++ b/shaders/world-1/gbuffers_water.vsh @@ -1,3 +1,7 @@ #version 120 -#include "/programs/all_translucent.vsh" \ No newline at end of file +#define NETHER + +#define NETHER_SHADER + +#include "/dimensions/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world1/composite.fsh b/shaders/world1/composite.fsh index 2869aa9..598bc16 100644 --- a/shaders/world1/composite.fsh +++ b/shaders/world1/composite.fsh @@ -1,638 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER -#define END -#include "/lib/diffuse_lighting.glsl" - - -varying vec2 texcoord; - -flat varying vec3 avgAmbient; - -flat varying vec2 TAA_Offset; -flat varying float tempOffsets; - -const bool colortex5MipmapEnabled = true; -const bool colortex4MipmapEnabled = true; - -uniform sampler2D colortex0;//clouds -uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16 -uniform sampler2D colortex4;//Skybox -uniform sampler2D colortex3; -uniform sampler2D colortex7; -uniform sampler2D colortex5; -uniform sampler2D colortex2; -uniform sampler2D colortex8; -uniform sampler2D colortex10; -uniform sampler2D colortex15; -uniform sampler2D colortex6;//Skybox -uniform sampler2D depthtex1;//depth -uniform sampler2D depthtex0;//depth -uniform sampler2D noisetex;//depth - -uniform int heldBlockLightValue; -uniform int frameCounter; -uniform int isEyeInWater; -uniform mat4 shadowModelViewInverse; -uniform mat4 shadowProjectionInverse; -uniform float far; -uniform float near; -uniform float frameTimeCounter; -uniform float rainStrength; -uniform mat4 gbufferProjection; -uniform mat4 gbufferProjectionInverse; -uniform mat4 gbufferModelViewInverse; -uniform mat4 shadowModelView; -uniform mat4 shadowProjection; -uniform mat4 gbufferModelView; - -uniform mat4 gbufferPreviousModelView; -uniform mat4 gbufferPreviousProjection; -uniform vec3 previousCameraPosition; - -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; -uniform float aspectRatio; -uniform vec3 cameraPosition; -uniform vec3 sunVec; -uniform ivec2 eyeBrightnessSmooth; - -#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) -#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) - -vec3 toScreenSpace(vec3 p) { - vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); - vec3 p3 = p * 2. - 1.; - vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; - return fragposition.xyz / fragposition.w; -} -#include "/lib/color_transforms.glsl" -#include "/lib/waterBump.glsl" -#include "/lib/sky_gradient.glsl" - - - - -float ld(float dist) { - return (2.0 * near) / (far + near - dist * (far - near)); -} - -vec2 RENDER_SCALE = vec2(1.0); - -#include "/lib/end_fog.glsl" - -#undef LIGHTSOURCE_REFLECTION -#define ENDSPECULAR -#include "/lib/specular.glsl" - - -vec3 normVec (vec3 vec){ - return vec*inversesqrt(dot(vec,vec)); -} -float lengthVec (vec3 vec){ - return sqrt(dot(vec,vec)); -} -#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) -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); -} - -vec3 fp10Dither(vec3 color,float dither){ - const vec3 mantissaBits = vec3(6.,6.,5.); - vec3 exponent = floor(log2(color)); - return color + dither*exp2(-mantissaBits)*exp2(exponent); -} - - - -float facos(float sx){ - float x = clamp(abs( sx ),0.,1.); - return sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 ); -} -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); -} -vec2 decodeVec2(float a){ - const vec2 constant1 = 65535. / vec2( 256., 65536.); - const float constant2 = 256. / 255.; - return fract( a * constant1 ) * constant2 ; -} -// float linZ(float depth) { -// 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) - -// } -// float invLinZ (float lindepth){ -// return -((2.0*near/lindepth)-far-near)/(far-near); -// } - -// vec3 toClipSpace3(vec3 viewSpacePosition) { -// return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; -// } - - - - -vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort) -{ - float alpha0 = sampleNumber/nb; - float alpha = (sampleNumber+jitter)/nb; - float angle = jitter*6.28 + alpha * 4.0 * 6.28; - - float sin_v, cos_v; - - sin_v = sin(angle); - cos_v = cos(angle); - - return vec2(cos_v, sin_v)*sqrt(alpha); -} - - - -vec3 BilateralFiltering(sampler2D tex, sampler2D depth,vec2 coord,float frDepth,float maxZ){ - vec4 sampled = vec4(texelFetch2D(tex,ivec2(coord),0).rgb,1.0); - - return vec3(sampled.x,sampled.yz/sampled.w); -} -float interleaved_gradientNoise(){ - // vec2 coord = gl_FragCoord.xy + (frameCounter%40000); - vec2 coord = gl_FragCoord.xy + frameTimeCounter; - // vec2 coord = gl_FragCoord.xy; - float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); - return noise ; -} - -vec2 R2_dither(){ - vec2 alpha = vec2(0.75487765, 0.56984026); - return vec2(fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter), fract((1.0-alpha.x) * gl_FragCoord.x + (1.0-alpha.y) * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter)); -} -float blueNoise(){ - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * (frameCounter*0.5+0.5) ); -} -vec4 blueNoise(vec2 coord){ - return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ; -} -vec3 toShadowSpaceProjected(vec3 p3){ - p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz; - p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz; - p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz; - - return p3; -} -vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot,float r0) -{ - float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb))); - float angle = alpha * (nbRot * 6.28) + spinAngle*6.28; - - float ssR = alpha; - float sin_v, cos_v; - - sin_v = sin(angle); - cos_v = cos(angle); - - return vec2(cos_v, sin_v)*ssR; -} - - -float ssao(vec3 fragpos, float dither,vec3 normal) -{ - float mulfov = 1.0; - ivec2 pos = ivec2(gl_FragCoord.xy); - const float tan70 = tan(70.*3.14/180.); - float mulfov2 = gbufferProjection[1][1]/tan70; - - const float PI = 3.14159265; - const float samplingRadius = 0.712; - float angle_thresh = 0.05; - - - - - float rd = mulfov2*0.05; - //pre-rotate direction - float n = 0.; - - float occlusion = 0.0; - - vec2 acc = -vec2(TAA_Offset)*texelSize*0.5; - float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5; - - vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026)); - for (int j = 0; j < 7+2 ;j++) { - vec2 sp = tapLocation(j,v.x,7+2,2.,v.y); - vec2 sampleOffset = sp*rd; - ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight)); - if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) { - vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x)); - - vec3 vec = t0.xyz - fragpos; - float dsquared = dot(vec,vec); - if (dsquared > 1e-5){ - if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){ - float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.); - occlusion += NdotV; - } - n += 1.0; - } - } - } - - - - - return clamp(1.0-occlusion/n*2.0,0.,1.0); -} -vec3 viewToWorld(vec3 viewPosition) { - vec4 pos; - pos.xyz = viewPosition; - pos.w = 0.0; - pos = gbufferModelViewInverse * pos; - return pos.xyz; -} -vec3 worldToView(vec3 worldPos) { - vec4 pos = vec4(worldPos, 0.0); - pos = gbufferModelView * pos; - return pos.xyz; -} -void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ - inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value - 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; - vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; - rayLength *= maxZ; - float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; - estEndDepth *= maxZ; - estSunDepth *= maxZ; - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - - float expFactor = 11.0; - vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; - for (int i=0;i -near) ? - (-near -position.z) / dir.z : far*sqrt(3.) ; - vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space - direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size - vec3 stepv = direction * 3.0 * clamp(MC_RENDER_QUALITY,1.,2.0); - - vec3 spos = clipPosition; - spos += stepv*dither ; - - for (int i = 0; i < int(quality); i++) { - spos += stepv; - - float sp = texture2D(depthtex1,spos.xy).x; - - if( sp < spos.z) { - float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z); - if (dist < 0.015 ) return i / quality; - } - } - return 1.0; -} - - - -vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){ - - vec3 clipPosition = toClipSpace3(position); - float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? - (-near -position.z) / dir.z : far*sqrt(3.); - vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space - direction.xy = normalize(direction.xy); - - //get at which length the ray intersects with the edge of the screen - vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; - float mult = maxLengths.y; - - vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither; - vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; - - spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; - - float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases - - for(int i = 0; i < int(quality); i++){ - spos += stepv; - float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0); - float currZ = linZ(spos.z); - - if( sp < currZ) { - float dist = abs(sp-currZ)/currZ; - if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); - } - spos += stepv; - } - return vec3(1.1); -} -vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){ - float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases - - float stepSize = stepsizes / dist; - int maxSteps = STEPS; - vec3 clipPosition = toClipSpace3(position); - float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ? - (-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far; - vec3 end = toClipSpace3(position+dir*rayLength) ; - vec3 direction = end-clipPosition ; //convert to clip space - - float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize; - //get at which length the ray intersects with the edge of the screen - vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; - - float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0; - - vec3 stepv = direction/len; - - int iterations = min(int(min(len, mult*len)-2), maxSteps); - - //Do one iteration for closest texel (good contact shadows) - vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; - spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; - spos += stepv/(stepSize/2); - - float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases - - for(int i = 0; i < iterations; i++){ - if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1); - spos += stepv*noise; - - float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0); - float currZ = linZ(spos.z); - - if( sp < currZ) { - float dist = abs(sp-currZ)/currZ; - if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); - } - } - return vec3(1.1); -} - -vec3 cosineHemisphereSample(vec2 Xi, float roughness){ - float r = sqrt(Xi.x); - float theta = 2.0 * 3.14159265359 * Xi.y; - - float x = r * cos(theta); - float y = r * sin(theta); - - return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); -} - -vec3 TangentToWorld(vec3 N, vec3 H, float roughness){ - vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); - vec3 T = normalize(cross(UpVector, N)); - vec3 B = cross(N, T); - - return vec3((T * H.x) + (B * H.y) + (N * H.z)); -} -vec2 R2_samples(int n){ - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha * n); -} - -void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmaps, vec3 torchcolor){ - int nrays = RAY_COUNT; - - vec3 radiance = vec3(0.0); - vec3 occlusion = vec3(0.0); - vec3 skycontribution = vec3(0.0); - - // float skyLM = 0.0; - // vec3 torchlight = vec3(0.0); - // vec3 blank = vec3(0.0); - // DoRTAmbientLighting(torchcolor, vec2(lightmaps,1.0), skyLM, torchlight, blank); - - for (int i = 0; i < nrays; i++){ - int seed = (frameCounter%40000)*nrays+i; - vec2 ij = fract(R2_samples(seed) + noise ); - - vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0); - - #ifdef HQ_SSGI - vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt - #else - vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt - #endif - - skycontribution = lighting; - - if (rayHit.z < 1.){ - - #if indirect_effect == 4 - vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; - previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; - previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; - if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ - radiance += (texture2D(colortex5,previousPosition.xy).rgb + skycontribution) * GI_Strength; - }else{ - radiance += skycontribution; - } - #else - radiance += skycontribution; - #endif - - occlusion += skycontribution * GI_Strength; - - } else { - radiance += skycontribution; - } - } - - occlusion *= AO_Strength; - - lighting = max(radiance/nrays - occlusion/nrays, 0.0); -} -void main() { - float dirtAmount = Dirt_Amount; - 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 = dirtEpsilon*dirtAmount + waterEpsilon; - vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; - - float z0 = texture2D(depthtex0,texcoord).x; - float z = texture2D(depthtex1,texcoord).x; - - vec2 tempOffset=TAA_Offset; - float noise = blueNoise(); - - vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z)); - vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; - vec3 np3 = normVec(p3); - - - ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// - - vec4 data = texture2D(colortex1,texcoord); - vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); // albedo, masks - vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); // normals, lightmaps - // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); - - vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); - vec2 lightmap = dataUnpacked1.yz; - vec3 normal = decode(dataUnpacked0.yw); - - ////// --------------- UNPACK MISC --------------- ////// - - vec4 SpecularTex = texture2D(colortex8,texcoord); - float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0); - - vec4 normalAndAO = texture2D(colortex15,texcoord); - vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; - vec3 slopednormal = normal; - - #ifdef POM - #ifdef Horrible_slope_normals - vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it. - slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) ); - #endif - #endif - - float vanilla_AO = clamp(normalAndAO.a,0,1); - normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1); - - - - bool iswater = texture2D(colortex7,texcoord).a > 0.99; - bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01; - bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01; - bool entities = abs(dataUnpacked1.w-0.45) < 0.01; - - bool hand = abs(dataUnpacked1.w-0.75) < 0.01; - // bool blocklights = abs(dataUnpacked1.w-0.8) <0.01; - - if (z >= 1.0) { - - gl_FragData[0].rgb = vec3(0.0); - - } else { - - p3 += gbufferModelViewInverse[3].xyz; - - // do all ambient lighting stuff - vec3 Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3); - - vec3 LightColor = LightSourceColor(clamp(sqrt(length(p3+cameraPosition) / 150.0 - 1.0) ,0.0,1.0)); - vec3 LightPos = LightSourcePosition(p3+cameraPosition, cameraPosition); - - float LightFalloff = max(exp2(4.0 + length(LightPos) / -25),0.0); - - float NdotL = clamp( dot(normal,normalize(-LightPos)),0.0,1.0); - NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); - - float fogshadow = GetCloudShadow(p3+cameraPosition, LightPos, blueNoise()); - vec3 LightSource = (LightColor * max(LightColor - (1-fogshadow) ,0.0)) * LightFalloff * NdotL; - // vec3 LightSource = LightColor * fogshadow * LightFalloff * NdotL ; - - - - float LightFalloff2 = max(1.0-length(LightPos)/120,0.0); - LightFalloff2 = pow(1.0-pow(1.0-LightFalloff2,0.5),2.0); - LightFalloff2 *= 25; - - LightSource += (LightColor * max(LightColor - 0.6,0.0)) * vec3(1.0,1.3,1.0) * LightFalloff2 * (NdotL*0.7+0.3); - - // float RT_Shadows = rayTraceShadow(worldToView(normalize(-LightPos)), fragpos_RTSHADOW, blueNoise()); - // if(!hand) LightSource *= RT_Shadows*RT_Shadows; - - - - #if indirect_effect == 0 - vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; - if(!hand) Indirect_lighting *= AO; - #endif - - #if indirect_effect == 1 - vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; - if(!hand) Indirect_lighting *= ssao(fragpos,noise,FlatNormals) * AO; - #endif - - // RTAO and/or SSGI - #if indirect_effect == 3 || indirect_effect == 4 - if (!hand) ApplySSRT(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.x,vec3(TORCH_R,TORCH_G,TORCH_B)); - #endif - - // finalize - gl_FragData[0].rgb = (Indirect_lighting + LightSource) * albedo; - - // #ifdef Specular_Reflections - // MaterialReflections_E(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand, LightColor * LightFalloff, normalize(-LightPos), entities); - // #endif - - #ifdef Specular_Reflections - vec3 specNoise = vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise()); - DoSpecularReflections(gl_FragData[0].rgb, fragpos, np3, vec3(0.0), specNoise, normal, SpecularTex.r, SpecularTex.g, albedo, vec3(0.0), 1.0, hand); - #endif - - - - Emission(gl_FragData[0].rgb, albedo, SpecularTex.a); - - if(lightningBolt) gl_FragData[0].rgb = LightColor * 10 ; - - - - } - - if (iswater && isEyeInWater == 0){ - vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0)); - float Vdiff = distance(fragpos,fragpos0); - float VdotU = np3.y; - float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane - - vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)); - - waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol); - } - - -/* DRAWBUFFERS:3 */ -} +#include "/dimensions/composite.fsh" \ No newline at end of file diff --git a/shaders/world1/composite.vsh b/shaders/world1/composite.vsh index 4904423..032f8fa 100644 --- a/shaders/world1/composite.vsh +++ b/shaders/world1/composite.vsh @@ -1,51 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER -varying vec2 texcoord; - -flat varying vec3 avgAmbient; - -flat varying float tempOffsets; -flat varying vec2 TAA_Offset; -flat varying vec3 zMults; - -uniform sampler2D colortex4; - -uniform float far; -uniform float near; -uniform mat4 gbufferModelViewInverse; -uniform vec3 sunPosition; -uniform float rainStrength; -uniform float sunElevation; -uniform int frameCounter; - -const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - - -#include "/lib/util.glsl" - -void main() { - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - - tempOffsets = HaltonSeq2(frameCounter%10000); - - TAA_Offset = offsets[frameCounter%8]; - - #ifndef TAA - TAA_Offset = vec2(0.0); - #endif - - - avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; - zMults = vec3((far * near)*2.0,far+near,far-near); -} +#include "/dimensions/composite.vsh" \ No newline at end of file diff --git a/shaders/world1/composite1.fsh b/shaders/world1/composite1.fsh new file mode 100644 index 0000000..275a6fe --- /dev/null +++ b/shaders/world1/composite1.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define END_SHADER + +#include "/dimensions/composite1.fsh" \ No newline at end of file diff --git a/shaders/world1/composite1.vsh b/shaders/world1/composite1.vsh new file mode 100644 index 0000000..b606182 --- /dev/null +++ b/shaders/world1/composite1.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define END_SHADER + +#include "/dimensions/composite1.vsh" \ No newline at end of file diff --git a/shaders/world1/composite2.fsh b/shaders/world1/composite2.fsh index 1679dbb..dcb6e3c 100644 --- a/shaders/world1/composite2.fsh +++ b/shaders/world1/composite2.fsh @@ -1,141 +1,5 @@ #version 120 -//Volumetric fog rendering -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER -flat varying vec4 lightCol; -// flat varying vec3 ambientUp; -// flat varying vec3 ambientLeft; -// flat varying vec3 ambientRight; -// flat varying vec3 ambientB; -// flat varying vec3 ambientF; -// flat varying vec3 ambientDown; -flat varying vec2 TAA_Offset; -flat varying float tempOffsets; -flat varying float fogAmount; -flat varying float VFAmount; -uniform sampler2D noisetex; -uniform sampler2D depthtex0; - - -uniform sampler2D colortex2; -uniform sampler2D colortex3; -// uniform sampler2D colortex4; - -uniform vec3 sunVec; -uniform float far; -uniform int frameCounter; -uniform float rainStrength; -uniform float sunElevation; -uniform ivec2 eyeBrightnessSmooth; -uniform float frameTimeCounter; -uniform int isEyeInWater; -uniform vec2 texelSize; - - -#include "/lib/color_transforms.glsl" -#include "/lib/color_dither.glsl" -#include "/lib/projections.glsl" -#include "/lib/end_fog.glsl" - - -#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) - -float interleaved_gradientNoise(){ - return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); -} -float blueNoise(){ - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); -} - -void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ - inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value - - 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; - - float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; - estEndDepth *= maxZ; - estSunDepth *= maxZ; - - vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; - vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); - - vec3 absorbance = vec3(1.0); - vec3 vL = vec3(0.0); - - float expFactor = 11.0; - for (int i=0;i 0.99; - float translucentAlpha = trpData.a; - - // vec4 speculartex = texture2D(colortex8,texcoord); // translucents - // float sunlight = speculartex.b; - - //3x3 bilateral upscale from half resolution - float z = texture2D(depthtex0,texcoord).x; - float z2 = texture2D(depthtex1,texcoord).x; - float frDepth = ld(z2); - - // vec4 vl = texture2D(colortex0,texcoord * 0.5); - - ////// --------------- UNPACK OPAQUE GBUFFERS --------------- ////// - vec4 data_opaque = texture2D(colortex1,texcoord); - vec4 dataUnpacked1 = vec4(decodeVec2(data_opaque.z),decodeVec2(data_opaque.w)); // normals, lightmaps - // vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); - - bool hand = abs(dataUnpacked1.w-0.75) < 0.01; - vec2 lightmap = dataUnpacked1.yz; - - ////// --------------- UNPACK TRANSLUCENT GBUFFERS --------------- ////// - - vec3 data = texture2D(colortex11,texcoord).rgb; - - vec4 unpack0 = vec4(decodeVec2(data.r),decodeVec2(data.g)) ; - vec4 unpack1 = vec4(decodeVec2(data.b),0,0) ; - - - - vec4 albedo = vec4(unpack0.ba,unpack1.rg); - - vec2 tangentNormals = unpack0.xy*2.0-1.0; - - if(albedo.a <= 0.0) tangentNormals = vec2(0.0); - - vec4 TranslucentShader = texture2D(colortex2,texcoord); - - float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0); - - - vec2 tempOffset = TAA_Offset; - vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); - vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2)); - - - vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; - vec3 np3 = normVec(p3); - - - vec2 refractedCoord = texcoord; - - /// --- REFRACTION --- /// - #ifdef Refraction - refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE; - // refractedCoord += tangentNormals * 0.1 * RENDER_SCALE; - - float refractedalpha = decodeVec2(texture2D(colortex11,refractedCoord).b).g; - float refractedalpha2 = texture2D(colortex7,refractedCoord).a; - if( refractedalpha <= 0.001 ||z < 0.56) refractedCoord = texcoord; // remove refracted coords on solids - #endif - - /// --- MAIN COLOR BUFFER --- /// - // it is sampled with distorted texcoords - vec3 color = texture2D(colortex3,refractedCoord).rgb; - - vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth, vec2(0.0)); - float bloomyFogMult = 1.0; - - if (TranslucentShader.a > 0.0){ - #ifdef Glass_Tint - if(albedo.a > 0.2) color = color*albedo.rgb + color * clamp(pow(1.0-luma(albedo.rgb),20.),0.0,1.0); - #endif - - color = color*(1.0-TranslucentShader.a) + TranslucentShader.rgb; - } - - // underwater fog - if (isEyeInWater == 1){ - float dirtAmount = Dirt_Amount; - 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 = dirtEpsilon*dirtAmount + waterEpsilon; - - // float fogfade = clamp( exp(length(fragpos) / -20) ,0.0,1.0); - // vec3 fogfade = clamp( exp( (length(fragpos) / -4) * totEpsilon ) ,0.0,1.0); - vec3 fogfade = clamp( exp( (-length(fragpos)) * totEpsilon ) ,0.0,1.0); - fogfade *= 1.0 - clamp( length(fragpos) / far,0.0,1.0); - - color.rgb *= fogfade ; - bloomyFogMult *= 0.4; - } - - // apply VL fog to the scene - color *= vl.a; - color += vl.rgb; - -// bloomy rain effect - float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); - if(rainDrops > 0.0) bloomyFogMult *= clamp(1.0 - pow(rainDrops*5.0,2),0.0,1.0); - - /// lava. - if (isEyeInWater == 2){ - color.rgb = vec3(4.0,0.5,0.1); - } - - /// powdered snow - if (isEyeInWater == 3){ - color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); - bloomyFogMult = 0.0; - } - - // blidnesss - color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -1),0.,1.) , blindness); - - // darkness effect - color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); - - #ifdef display_LUT - vec2 movedTC = texcoord; - vec3 thingy = texture2D(colortex4,movedTC).rgb / 150. * 5.0; - if(luma(thingy) > 0.0 ) color.rgb = thingy; - #endif - - gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog - - gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); - -} \ No newline at end of file +#include "/dimensions/composite3.fsh" \ No newline at end of file diff --git a/shaders/world1/composite3.vsh b/shaders/world1/composite3.vsh index ba85ff0..aa0a507 100644 --- a/shaders/world1/composite3.vsh +++ b/shaders/world1/composite3.vsh @@ -1,19 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -varying vec2 texcoord; -flat varying vec3 zMults; -uniform float far; -uniform float near; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -void main() { - zMults = vec3(1.0/(far * near),far+near,far-near); - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - -} +#include "/dimensions/composite3.vsh" \ No newline at end of file diff --git a/shaders/world1/composite4.fsh b/shaders/world1/composite4.fsh index 666e2ea..ca6df9c 100644 --- a/shaders/world1/composite4.fsh +++ b/shaders/world1/composite4.fsh @@ -1,354 +1,5 @@ #version 120 -//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader) -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER -const int noiseTextureResolution = 32; - - -/* -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 colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) -const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final) -const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) -*/ -//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; - -varying vec2 texcoord; -flat varying float exposureA; -flat varying float tempOffsets; -uniform sampler2D colortex3; -uniform sampler2D colortex5; -uniform sampler2D colortex10; -uniform sampler2D depthtex0; - -uniform vec2 texelSize; -uniform float frameTimeCounter; -uniform int framemod8; -uniform float viewHeight; -uniform float viewWidth; -uniform vec3 previousCameraPosition; -uniform mat4 gbufferPreviousModelView; - - - - -#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) - -#include "/lib/projections.glsl" - - -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); -} -vec3 fp10Dither(vec3 color,float dither){ - const vec3 mantissaBits = vec3(6.,6.,5.); - vec3 exponent = floor(log2(color)); - return color + dither*exp2(-mantissaBits)*exp2(exponent); -} - - -//returns the projected coordinates of the closest point to the camera in the 3x3 neighborhood -vec3 closestToCamera3x3() -{ - vec2 du = vec2(texelSize.x, 0.0); - vec2 dv = vec2(0.0, texelSize.y); - - vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthtex0, texcoord - dv - du).x); - vec3 dtc = vec3(texcoord,0.) + vec3( 0.0, -texelSize.y, texture2D(depthtex0, texcoord - dv).x); - vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthtex0, texcoord - dv + du).x); - - vec3 dml = vec3(texcoord,0.) + vec3(-texelSize.x, 0.0, texture2D(depthtex0, texcoord - du).x); - vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthtex0, texcoord).x); - vec3 dmr = vec3(texcoord,0.) + vec3( texelSize.x, 0.0, texture2D(depthtex0, texcoord + du).x); - - vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv - du).x); - vec3 dbc = vec3(texcoord,0.) + vec3( 0.0, texelSize.y, texture2D(depthtex0, texcoord + dv).x); - vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv + du).x); - - vec3 dmin = dmc; - - dmin = dmin.z > dtc.z? dtc : dmin; - dmin = dmin.z > dtr.z? dtr : dmin; - - dmin = dmin.z > dml.z? dml : dmin; - dmin = dmin.z > dtl.z? dtl : dmin; - dmin = dmin.z > dmr.z? dmr : dmin; - - dmin = dmin.z > dbl.z? dbl : dmin; - dmin = dmin.z > dbc.z? dbc : dmin; - dmin = dmin.z > dbr.z? dbr : dmin; - - return dmin; -} - -//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 texture2D( tex, uv); -} -//Due to low sample count we "tonemap" the inputs to preserve colors and smoother edges -vec3 weightedSample(sampler2D colorTex, vec2 texcoord){ - vec3 wsample = texture2D(colorTex,texcoord).rgb*exposureA; - return wsample/(1.0+luma(wsample)); - -} - - -//from : https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 -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 += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; - result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; - result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; - - result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; - result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; - result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; - - result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; - result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; - result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; - - return result; -} -//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 = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb; - - vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); - vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); - vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + - vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + - vec4(centerColor, 1.0) * (w12.x * w12.y) + - vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + - vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); - return color.rgb/color.a; - -} - -vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max) - { - vec3 p_clip = 0.5 * (aabb_max + aabb_min); - vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001; - - vec3 v_clip = q - vec3(p_clip); - vec3 v_unit = v_clip.xyz / e_clip; - vec3 a_unit = abs(v_unit); - float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); - - if (ma_unit > 1.0) - return vec3(p_clip) + v_clip / ma_unit; - else - return q; - } -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)); -} -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, texture2D(depth, texcoord - dv - du).x); - vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); - vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); - vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); - vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(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; - - return dmin; -} -const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), - vec2(-1.,3.)/8., - vec2(5.0,1.)/8., - vec2(-3,-5.)/8., - vec2(-5.,5.)/8., - vec2(-7.,-1.)/8., - vec2(3,7.)/8., - vec2(7.,-7.)/8.); - -vec3 TAA_hq(){ - - vec2 adjTC = texcoord; - - - //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion - #ifdef CLOSEST_VELOCITY - vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); - #endif - - #ifndef CLOSEST_VELOCITY - vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x); - #endif - - //reproject previous frame - vec3 fragposition = toScreenSpace(closestToCamera); - fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); - vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz; - previousPosition = toClipSpace3Prev(previousPosition); - vec2 velocity = previousPosition.xy - closestToCamera.xy; - previousPosition.xy = texcoord + velocity; - - //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 smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz; - - - vec3 albedoCurrent0 = texture2D(colortex3, adjTC).rgb; - vec3 albedoCurrent1 = texture2D(colortex3, adjTC + vec2(texelSize.x,texelSize.y)).rgb; - vec3 albedoCurrent2 = texture2D(colortex3, adjTC + vec2(texelSize.x,-texelSize.y)).rgb; - vec3 albedoCurrent3 = texture2D(colortex3, adjTC + vec2(-texelSize.x,-texelSize.y)).rgb; - vec3 albedoCurrent4 = texture2D(colortex3, adjTC + vec2(-texelSize.x,texelSize.y)).rgb; - vec3 albedoCurrent5 = texture2D(colortex3, adjTC + vec2(0.0,texelSize.y)).rgb; - vec3 albedoCurrent6 = texture2D(colortex3, adjTC + vec2(0.0,-texelSize.y)).rgb; - vec3 albedoCurrent7 = texture2D(colortex3, adjTC + vec2(-texelSize.x,0.0)).rgb; - vec3 albedoCurrent8 = texture2D(colortex3, adjTC + vec2(texelSize.x,0.0)).rgb; - //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 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8)))))); - vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8)))))); - albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).rgb; - - - #ifndef NO_CLIP - vec3 albedoPrev = max(FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.75).xyz, 0.0); - vec3 finalcAcc = clamp(albedoPrev,cMin,cMax); - - //Increases blending factor when far from AABB and in motion, reduces ghosting - float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5; - float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0); - - float test = 0.05; - - bool isEntities = texture2D(colortex10,texcoord).x > 0.0; - // if(isEntities) test = 0.15; - // if(istranslucent) test = 0.1; - - //Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering - // vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.))); - - vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.))); - #endif - - - #ifdef NO_CLIP - vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz; - vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.)); - #endif - - //De-tonemap - return supersampled; -} - -void main() { - -/* DRAWBUFFERS:5 */ - gl_FragData[0].a = 1.0; - - #ifdef TAA - vec3 color = TAA_hq(); - gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0); - #endif - - #ifndef TAA - vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.); - gl_FragData[0].rgb = color; - #endif - - - - - -} +#include "/dimensions/composite4.fsh" \ No newline at end of file diff --git a/shaders/world1/composite4.vsh b/shaders/world1/composite4.vsh index 2ead011..b439e0e 100644 --- a/shaders/world1/composite4.vsh +++ b/shaders/world1/composite4.vsh @@ -1,20 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable +#define END_SHADER -varying vec2 texcoord; -flat varying float exposureA; -flat varying float tempOffsets; -uniform sampler2D colortex4; -uniform int frameCounter; - - -#include "/lib/util.glsl" - -void main() { - - tempOffsets = HaltonSeq2(frameCounter%10000); - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r; -} +#include "/dimensions/composite4.vsh" \ No newline at end of file diff --git a/shaders/world1/composite5.fsh b/shaders/world1/composite5.fsh index a4b6244..5d88de6 100644 --- a/shaders/world1/composite5.fsh +++ b/shaders/world1/composite5.fsh @@ -1,45 +1,5 @@ #version 120 -//downsample 1st pass (half res) for bloom -uniform sampler2D colortex5; -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -void main() { - -/* DRAWBUFFERS:3 */ -vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*2.*resScale*texelSize; - - //0.5 - gl_FragData[0] = texture2D(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; - - //0.25 - gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125; - - //0.125 - gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; - - //0.125 - gl_FragData[0] += texture2D(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); - - -} +#include "/dimensions/composite5.fsh" \ No newline at end of file diff --git a/shaders/world1/composite5.vsh b/shaders/world1/composite5.vsh index 386f006..0d7fb8a 100644 --- a/shaders/world1/composite5.vsh +++ b/shaders/world1/composite5.vsh @@ -1,17 +1,5 @@ #version 120 -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -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; -} +#include "/dimensions/composite5.vsh" \ No newline at end of file diff --git a/shaders/world1/composite6.fsh b/shaders/world1/composite6.fsh index 25c81c0..766e494 100644 --- a/shaders/world1/composite6.fsh +++ b/shaders/world1/composite6.fsh @@ -1,45 +1,5 @@ #version 120 -//downsample 1st pass (half res) for bloom -uniform sampler2D colortex3; -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -void main() { - -/* DRAWBUFFERS:6 */ -vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*2.*texelSize; - - //0.5 - gl_FragData[0] = texture2D(colortex3,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex3,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; - gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; - - //0.25 - gl_FragData[0] += texture2D(colortex3,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; - gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; - gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125; - gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125; - - //0.125 - gl_FragData[0] += texture2D(colortex3,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex3,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; - gl_FragData[0] += texture2D(colortex3,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; - - //0.125 - gl_FragData[0] += texture2D(colortex3,quarterResTC)*0.125; - - gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); - - - -} +#include "/dimensions/composite6.fsh" \ No newline at end of file diff --git a/shaders/world1/composite6.vsh b/shaders/world1/composite6.vsh index 8d47d5c..50c159b 100644 --- a/shaders/world1/composite6.vsh +++ b/shaders/world1/composite6.vsh @@ -1,17 +1,5 @@ #version 120 -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -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.26/clampedRes*vec2(1920.0,1080.)*2-1.0; -} +#include "/dimensions/composite6.vsh" \ No newline at end of file diff --git a/shaders/world1/composite7.fsh b/shaders/world1/composite7.fsh index 1320222..9af2e0e 100644 --- a/shaders/world1/composite7.fsh +++ b/shaders/world1/composite7.fsh @@ -1,61 +1,5 @@ #version 120 -//6 Horizontal gaussian blurs and horizontal downsampling +#define END_SHADER -uniform sampler2D colortex6; -uniform vec2 texelSize; -varying vec2 texcoord; -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////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// - -void main() { -/* DRAWBUFFERS:6 */ - -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); - -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); - -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); - -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); - -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.); -} +#include "/dimensions/composite7.fsh" \ No newline at end of file diff --git a/shaders/world1/composite7.vsh b/shaders/world1/composite7.vsh index b299614..b1cd0be 100644 --- a/shaders/world1/composite7.vsh +++ b/shaders/world1/composite7.vsh @@ -1,20 +1,5 @@ #version 120 -uniform float viewWidth; -uniform float viewHeight; -varying vec2 texcoord; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -void main() { - vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0)); - 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; - texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.); -} +#include "/dimensions/composite7.vsh" \ No newline at end of file diff --git a/shaders/world1/composite8.fsh b/shaders/world1/composite8.fsh index dd63b74..eda3677 100644 --- a/shaders/world1/composite8.fsh +++ b/shaders/world1/composite8.fsh @@ -1,61 +1,5 @@ #version 120 -//6 Vertical gaussian blurs and vertical downsampling +#define END_SHADER - -uniform sampler2D colortex6; -uniform vec2 texelSize; -varying vec2 texcoord; -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.y; - float minTC = 0.; - for (int i = -maxIT;i minTC && spCoord.y < maxTC); - } - return tot.rgb/max(1.0,tot.a); -} - -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// - -void main() { -/* DRAWBUFFERS:6 */ -vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; - -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); - -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); - -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 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); - -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); - -gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); -} +#include "/dimensions/composite8.fsh" \ No newline at end of file diff --git a/shaders/world1/composite8.vsh b/shaders/world1/composite8.vsh index 56683b4..db8cb16 100644 --- a/shaders/world1/composite8.vsh +++ b/shaders/world1/composite8.vsh @@ -1,21 +1,5 @@ #version 120 -uniform float viewWidth; -uniform float viewHeight; -varying vec2 texcoord; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -void main() { - vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0)); - 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; - texcoord = gl_MultiTexCoord0.xy/clampedRes*vec2(1920.,1080.); - -} +#include "/dimensions/composite8.vsh" \ No newline at end of file diff --git a/shaders/world1/composite9.fsh b/shaders/world1/composite9.fsh index 6bfa802..c4b6b42 100644 --- a/shaders/world1/composite9.fsh +++ b/shaders/world1/composite9.fsh @@ -1,103 +1,5 @@ #version 120 -//Merge and upsample the blurs into a 1/4 res bloom buffer -uniform sampler2D colortex3; -uniform sampler2D colortex6; +#define END_SHADER -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; - -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 texture2D_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 * texture2D(tex, p0) + - g1x * texture2D(tex, p1)) + - g1(fuv.y) * (g0x * texture2D(tex, p2) + - g1x * texture2D(tex, p3)); -} - -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// - -void main() { -/* DRAWBUFFERS:3 */ -vec2 resScale = vec2(1920.,1080.)/max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); -vec2 texcoord = ((gl_FragCoord.xy)*2.+0.5)*texelSize; -vec3 bloom = texture2D_bicubic(colortex3,texcoord/2.0).rgb; //1/4 res - -bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res - -bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res - -bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res - -bloom += texture2D_bicubic(colortex6,texcoord/32.+vec2(0.4375*resScale.x+6.5*texelSize.x,.0)).rgb*1.0; //1/64 res -bloom += texture2D_bicubic(colortex6,texcoord/64.+vec2(0.46875*resScale.x+8.5*texelSize.x,.0)).rgb*1.0; //1/128 res -bloom += texture2D_bicubic(colortex6,texcoord/128.+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb*1.0; //1/256 res - -//bloom = texture2D_bicubic(colortex6,texcoord).rgb*6.; //1/8 res - -gl_FragData[0].rgb = bloom*2.; - -gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); -} +#include "/dimensions/composite9.fsh" \ No newline at end of file diff --git a/shaders/world1/composite9.vsh b/shaders/world1/composite9.vsh index 386f006..b487c6a 100644 --- a/shaders/world1/composite9.vsh +++ b/shaders/world1/composite9.vsh @@ -1,17 +1,5 @@ #version 120 -uniform float viewWidth; -uniform float viewHeight; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +#define END_SHADER -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; -} +#include "/dimensions/composite9.vsh" \ No newline at end of file diff --git a/shaders/world1/deferred.fsh b/shaders/world1/deferred.fsh index cc09257..8738dc1 100644 --- a/shaders/world1/deferred.fsh +++ b/shaders/world1/deferred.fsh @@ -1,110 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable +#define END_SHADER -#include "/lib/settings.glsl" - - -// flat varying vec3 ambientUp; -// flat varying vec3 ambientLeft; -// flat varying vec3 ambientRight; -// flat varying vec3 ambientB; -// flat varying vec3 ambientF; -// flat varying vec3 ambientDown; - -flat varying vec3 lightSourceColor; -flat varying vec3 sunColor; -flat varying vec3 sunColorCloud; -flat varying vec3 moonColor; -flat varying vec3 moonColorCloud; -flat varying vec3 zenithColor; -flat varying vec3 avgSky; -flat varying vec2 tempOffsets; -flat varying float exposure; -flat varying float rodExposure; -flat varying float avgBrightness; -flat varying float exposureF; -flat varying float fogAmount; -flat varying float VFAmount; - -uniform sampler2D colortex4; -uniform sampler2D noisetex; - -uniform int frameCounter; -uniform float rainStrength; -uniform float eyeAltitude; -uniform vec3 sunVec; -uniform vec2 texelSize; -uniform float frameTimeCounter; -uniform mat4 gbufferProjection; -uniform mat4 gbufferProjectionInverse; -uniform mat4 gbufferPreviousProjection; -uniform mat4 gbufferModelViewInverse; -uniform mat4 gbufferModelView; -uniform mat4 shadowModelView; -uniform mat4 shadowProjection; -uniform float sunElevation; -uniform vec3 cameraPosition; -uniform float far; -uniform ivec2 eyeBrightnessSmooth; - - -#include "/lib/util.glsl" -#include "/lib/ROBOBO_sky.glsl" - - -vec3 toShadowSpaceProjected(vec3 p3){ - p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz; - p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz; - p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz; - - return p3; -} -float interleaved_gradientNoise(){ - vec2 coord = gl_FragCoord.xy; - float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887); - return noise; -} -float blueNoise(){ - return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); -} -vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.); -const float[17] Slightmap = float[17](14.0,17.,19.0,22.0,24.0,28.0,31.0,40.0,60.0,79.0,93.0,110.0,132.0,160.0,197.0,249.0,249.0); - -#include "/lib/end_fog.glsl" - -void main() { -/* DRAWBUFFERS:4 */ - -gl_FragData[0] = vec4(0.0); - -//Fog for reflections -// if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+257.){ - -vec2 fogPos = vec2(256.0 - 256.0*0.12,1.0); -//Sky gradient with clouds -if (gl_FragCoord.x > (fogPos.x - fogPos.x*0.22) && gl_FragCoord.y > 0.4 && gl_FragCoord.x < 535){ - // vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0); - vec2 p = clamp(floor(gl_FragCoord.xy-fogPos)/256.+tempOffsets/256.,-0.2,1.2); - vec3 viewVector = cartToSphere(p); - - mat2x3 vl = getVolumetricRays(fract(frameCounter/1.6180339887),mat3(gbufferModelView)*viewVector*1024.,fract(frameCounter/2.6180339887)); - - float absorbance = dot(vl[1],vec3(0.22,0.71,0.07)); - - gl_FragData[0] = clamp(vec4(vl[0]*0.7,absorbance),0.000001,65000.); - -} - -//Temporally accumulate sky and light values -vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb; -vec3 curr = gl_FragData[0].rgb*150.; -gl_FragData[0].rgb = clamp(mix(temp,curr,0.07),0.0,65000.); - -//Exposure values -if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) -gl_FragData[0] = vec4(exposure,avgBrightness,exposureF,1.0); -if (gl_FragCoord.x > 14. && gl_FragCoord.x < 15. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) -gl_FragData[0] = vec4(rodExposure,0.0,0.0,1.0); - -} +#include "/dimensions/deferred.fsh" \ No newline at end of file diff --git a/shaders/world1/deferred.vsh b/shaders/world1/deferred.vsh index dc314c3..32ad331 100644 --- a/shaders/world1/deferred.vsh +++ b/shaders/world1/deferred.vsh @@ -1,196 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER -flat varying vec3 ambientUp; -flat varying vec3 ambientLeft; -flat varying vec3 ambientRight; -flat varying vec3 ambientB; -flat varying vec3 ambientF; -flat varying vec3 ambientDown; -flat varying vec3 zenithColor; -flat varying vec3 sunColor; -flat varying vec3 sunColorCloud; -flat varying vec3 moonColor; -flat varying vec3 moonColorCloud; -flat varying vec3 lightSourceColor; -flat varying vec3 avgSky; -flat varying vec2 tempOffsets; -flat varying float exposure; -flat varying float avgBrightness; -flat varying float exposureF; -flat varying float rodExposure; -flat varying float fogAmount; -flat varying float VFAmount; - -uniform sampler2D colortex4; -uniform sampler2D colortex6; - -uniform mat4 gbufferModelViewInverse; -uniform vec3 sunPosition; -uniform vec2 texelSize; -uniform float rainStrength; -uniform float sunElevation; -uniform float nightVision; -uniform float frameTime; -uniform float eyeAltitude; -uniform int frameCounter; -uniform int worldTime; -vec3 sunVec = vec3(0.0,1.0,0.0); - - - -#include "/lib/sky_gradient.glsl" -#include "/lib/util.glsl" -#include "/lib/ROBOBO_sky.glsl" - - -vec3 rodSample(vec2 Xi) -{ - float r = sqrt(1.0f - Xi.x*Xi.y); - float phi = 2 * 3.14159265359 * Xi.y; - - return normalize(vec3(cos(phi) * r, sin(phi) * r, Xi.x)).xzy; -} -vec3 cosineHemisphereSample(vec2 Xi) -{ - float r = sqrt(Xi.x); - float theta = 2.0 * 3.14159265359 * Xi.y; - - float x = r * cos(theta); - float y = r * sin(theta); - - return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); -} - -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); -} - - -vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter) -{ - float alpha = float(sampleNumber+jitter)/nb; - float angle = (jitter+alpha) * (nbRot * 6.28); - - float ssR = alpha; - float sin_v, cos_v; - - sin_v = sin(angle); - cos_v = cos(angle); - - return vec2(cos_v, sin_v)*ssR; -} -//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ -vec2 R2_samples(int n){ - vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha * n); -} -void main() { - - gl_Position = ftransform()*0.5+0.5; - gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize; - gl_Position.xy = gl_Position.xy*2.-1.0; - -// tempOffsets = R2_samples(frameCounter%10000); - -// ambientUp = vec3(0.0); -// ambientDown = vec3(0.0); -// ambientLeft = vec3(0.0); -// ambientRight = vec3(0.0); -// ambientB = vec3(0.0); -// ambientF = vec3(0.0); -// avgSky = vec3(0.0); - - - -// //Fake bounced sunlight -// vec3 bouncedSun = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)/4000.*0.08; -// ambientUp += bouncedSun*clamp(-sunVec.y+5.,0.,6.0); -// ambientLeft += bouncedSun*clamp(sunVec.x+5.,0.0,6.); -// ambientRight += bouncedSun*clamp(-sunVec.x+5.,0.0,6.); -// ambientB += bouncedSun*clamp(-sunVec.z+5.,0.0,6.); -// ambientF += bouncedSun*clamp(sunVec.z+5.,0.0,6.); -// ambientDown += bouncedSun*clamp(sunVec.y+5.,0.0,6.); - - -// float avgLuma = 0.0; -// float m2 = 0.0; -// int n=100; -// vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.)); -// float avgExp = 0.0; -// vec2 resScale = vec2(1920.,1080.)/clampedRes; -// float v[25]; -// float temp; -// // 5x5 Median filter by morgan mcguire -// // We take the median value of the most blurred bloom buffer -// #define s2(a, b) temp = a; a = min(a, b); b = max(temp, b); -// #define t2(a, b) s2(v[a], v[b]); -// #define t24(a, b, c, d, e, f, g, h) t2(a, b); t2(c, d); t2(e, f); t2(g, h); -// #define t25(a, b, c, d, e, f, g, h, i, j) t24(a, b, c, d, e, f, g, h); t2(i, j); -// for (int i = 0; i < 5; i++){ -// for (int j = 0; j < 5; j++){ -// vec2 tc = 0.5 + vec2(i-2,j-2)/2.0 * 0.35; -// v[i+j*5] = luma(texture2D(colortex6,tc/128. * resScale+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb); -// } -// } -// t25(0, 1, 3, 4, 2, 4, 2, 3, 6, 7); -// t25(5, 7, 5, 6, 9, 7, 1, 7, 1, 4); -// t25(12, 13, 11, 13, 11, 12, 15, 16, 14, 16); -// t25(14, 15, 18, 19, 17, 19, 17, 18, 21, 22); -// t25(20, 22, 20, 21, 23, 24, 2, 5, 3, 6); -// t25(0, 6, 0, 3, 4, 7, 1, 7, 1, 4); -// t25(11, 14, 8, 14, 8, 11, 12, 15, 9, 15); -// t25(9, 12, 13, 16, 10, 16, 10, 13, 20, 23); -// t25(17, 23, 17, 20, 21, 24, 18, 24, 18, 21); -// t25(19, 22, 8, 17, 9, 18, 0, 18, 0, 9); -// t25(10, 19, 1, 19, 1, 10, 11, 20, 2, 20); -// t25(2, 11, 12, 21, 3, 21, 3, 12, 13, 22); -// t25(4, 22, 4, 13, 14, 23, 5, 23, 5, 14); -// t25(15, 24, 6, 24, 6, 15, 7, 16, 7, 19); -// t25(3, 11, 5, 17, 11, 17, 9, 17, 4, 10); -// t25(6, 12, 7, 14, 4, 6, 4, 7, 12, 14); -// t25(10, 14, 6, 7, 10, 12, 6, 10, 6, 17); -// t25(12, 17, 7, 17, 7, 10, 12, 18, 7, 12); -// t24(10, 18, 12, 20, 10, 20, 10, 12); -// avgExp = v[12]; // Median value - - -// avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0); - -// float currentExposure = texelFetch2D(colortex4,ivec2(10,37),0).b; -// float L = max(avgBrightness,1e-8); -// float keyVal = 1.03-2.0/(log(L+1.0)/log(10.0)+2.0); -// float targetExposure = 1.0*keyVal/L; - -// float targetrodExposure = clamp(log(targetExposure*2.0+1.0)-0.1,0.0,2.0); -// float currentrodExposure = texelFetch2D(colortex4,ivec2(14,37),0).r; - -// targetExposure = clamp(targetExposure,2.0,3.0); -// float rad = sqrt(currentExposure); -// float rtarget = sqrt(targetExposure); -// float dir = sign(rtarget-rad); -// float dist = abs(rtarget-rad); -// float maxApertureChange = 0.0032*frameTime/0.016666*Exposure_Speed * exp2(max(rad,rtarget)*0.5); - -// maxApertureChange *= 1.0+nightVision*4.; -// rad = rad+dir*min(dist,maxApertureChange); - -// exposureF = rad*rad; -// exposure=exposureF*EXPOSURE_MULTIPLIER; - - -// dir = sign(targetrodExposure-currentrodExposure); -// dist = abs(targetrodExposure-currentrodExposure); -// maxApertureChange = 0.0032*frameTime/0.016666*Exposure_Speed * exp2(max(rad,rtarget)*0.5); - -// rodExposure = currentrodExposure + dir * min(dist,maxApertureChange); - - exposure = 1.0; - rodExposure = clamp(log(1.0*2.0+1.0)-0.1,0.0,2.0); - -} +#include "/dimensions/deferred.vsh" \ No newline at end of file diff --git a/shaders/world1/deferred1.fsh b/shaders/world1/deferred1.fsh new file mode 100644 index 0000000..99b8921 --- /dev/null +++ b/shaders/world1/deferred1.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define END_SHADER + +#include "/dimensions/deferred1.fsh" \ No newline at end of file diff --git a/shaders/world1/deferred1.vsh b/shaders/world1/deferred1.vsh new file mode 100644 index 0000000..ffe856b --- /dev/null +++ b/shaders/world1/deferred1.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define END_SHADER + +#include "/dimensions/deferred1.vsh" \ No newline at end of file diff --git a/shaders/world1/deferred2.fsh b/shaders/world1/deferred2.fsh deleted file mode 100644 index 579bfc1..0000000 --- a/shaders/world1/deferred2.fsh +++ /dev/null @@ -1,30 +0,0 @@ -#version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" - -uniform sampler2D colortex4; -uniform sampler2D depthtex1; - -uniform float near; -uniform float far; - - -float linZ(float depth) { - return (2.0 * near) / (far + near - depth * (far - near)); -} -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// - -void main() { -/* DRAWBUFFERS:4 */ - vec3 oldTex = texelFetch2D(colortex4, ivec2(gl_FragCoord.xy), 0).xyz; - float newTex = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x; - - if (newTex < 1.0) - gl_FragData[0] = vec4(oldTex, linZ(newTex)*linZ(newTex)*65000.0); - else - gl_FragData[0] = vec4(oldTex, 2.0); -} diff --git a/shaders/world1/deferred2.vsh b/shaders/world1/deferred2.vsh deleted file mode 100644 index 1d24af4..0000000 --- a/shaders/world1/deferred2.vsh +++ /dev/null @@ -1,11 +0,0 @@ -#version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" - -uniform vec2 texelSize; -#include "/lib/res_params.glsl" -void main() { - gl_Position = ftransform(); - vec2 scaleRatio = max(vec2(0.25), vec2(18.+258*2,258.)*texelSize); - gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(scaleRatio+0.01,0.0,1.0)*2.0-1.0; -} diff --git a/shaders/world1/final.fsh b/shaders/world1/final.fsh index 55c84a7..590696e 100644 --- a/shaders/world1/final.fsh +++ b/shaders/world1/final.fsh @@ -1,109 +1,5 @@ #version 120 -//Vignetting, applies bloom, applies exposure and tonemaps the final image -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER - -varying vec2 texcoord; - -uniform sampler2D colortex7; -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; -uniform float frameTimeCounter; -uniform int frameCounter; -uniform int isEyeInWater; - -#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 += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; - result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; - result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; - - result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; - result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; - result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; - - result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; - result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; - result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; - - return result; -} - -/// thanks stackoverflow https://stackoverflow.com/questions/944713/help-with-pixel-shader-effect-for-brightness-and-contrast#3027595 -void applyContrast(inout vec3 color, float contrast){ - color = (color - 0.5) * contrast + 0.5; -} - -void main() { - #ifdef BICUBIC_UPSCALING - vec3 col = SampleTextureCatmullRom(colortex7,texcoord,1.0/texelSize).rgb; - #else - vec3 col = texture2D(colortex7,texcoord).rgb; - #endif - - #ifdef CONTRAST_ADAPTATIVE_SHARPENING - //Weights : 1 in the center, 0.5 middle, 0.25 corners - vec3 albedoCurrent1 = texture2D(colortex7, texcoord + vec2(texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent2 = texture2D(colortex7, texcoord + vec2(texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent3 = texture2D(colortex7, texcoord + vec2(-texelSize.x,-texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - vec3 albedoCurrent4 = texture2D(colortex7, texcoord + vec2(-texelSize.x,texelSize.y)/MC_RENDER_QUALITY*0.5).rgb; - - - vec3 m1 = -0.5/3.5*col + albedoCurrent1/3.5 + albedoCurrent2/3.5 + albedoCurrent3/3.5 + albedoCurrent4/3.5; - vec3 std = abs(col - m1) + abs(albedoCurrent1 - m1) + abs(albedoCurrent2 - m1) + - abs(albedoCurrent3 - m1) + abs(albedoCurrent3 - m1) + abs(albedoCurrent4 - m1); - float contrast = 1.0 - luma(std)/5.0; - col = col*(1.0+(SHARPENING)*contrast) - - (SHARPENING)/(1.0-0.5/3.5)*contrast*(m1 - 0.5/3.5*col); - #endif - - float lum = luma(col); - vec3 diff = col-lum; - col = col + diff*(-lum*CROSSTALK + SATURATION); - //col = -vec3(-lum*CROSSFADING + SATURATION); - - applyContrast(col, CONTRAST); - - gl_FragColor.rgb = clamp(int8Dither(col,texcoord),0.0,1.0); - //gl_FragColor.rgb = vec3(contrast); -} +#include "/dimensions/final.fsh" \ No newline at end of file diff --git a/shaders/world1/final.vsh b/shaders/world1/final.vsh index 7b1c8e7..991e04c 100644 --- a/shaders/world1/final.vsh +++ b/shaders/world1/final.vsh @@ -1,21 +1,5 @@ #version 120 -//#extension GL_EXT_gpu_shader4 : disable -#include "/lib/settings.glsl" +#define END_SHADER -varying vec2 texcoord; -flat varying vec4 exposure; -uniform sampler2D colortex4; - -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// - -void main() { - - gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - exposure=vec4(texelFetch2D(colortex4,ivec2(10,37),0).r*vec3(FinalR,FinalG,FinalB),texelFetch2D(colortex4,ivec2(10,37),0).r); -} +#include "/dimensions/final.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_basic.fsh b/shaders/world1/gbuffers_basic.fsh index 7bb4bf0..3fe4392 100644 --- a/shaders/world1/gbuffers_basic.fsh +++ b/shaders/world1/gbuffers_basic.fsh @@ -3,4 +3,7 @@ // #define ENTITIES #define BLOCKENTITIES #define WORLD -#include "/programs/all_solid.fsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_basic.vsh b/shaders/world1/gbuffers_basic.vsh index 2577f65..ed45bd8 100644 --- a/shaders/world1/gbuffers_basic.vsh +++ b/shaders/world1/gbuffers_basic.vsh @@ -4,4 +4,7 @@ // #define LINE #define BLOCKENTITIES #define WORLD -#include "/programs/all_solid.vsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_block.fsh b/shaders/world1/gbuffers_block.fsh index 3397eab..f4c2b0b 100644 --- a/shaders/world1/gbuffers_block.fsh +++ b/shaders/world1/gbuffers_block.fsh @@ -2,4 +2,7 @@ #define WORLD #define BLOCKENTITIES -#include "/programs/all_solid.fsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_block.vsh b/shaders/world1/gbuffers_block.vsh index dd49c86..147c843 100644 --- a/shaders/world1/gbuffers_block.vsh +++ b/shaders/world1/gbuffers_block.vsh @@ -2,4 +2,7 @@ #define WORLD #define BLOCKENTITIES -#include "/programs/all_solid.vsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_entities.fsh b/shaders/world1/gbuffers_entities.fsh index 234213a..c23b809 100644 --- a/shaders/world1/gbuffers_entities.fsh +++ b/shaders/world1/gbuffers_entities.fsh @@ -3,4 +3,6 @@ #define WORLD #define ENTITIES -#include "/programs/all_solid.fsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_entities.vsh b/shaders/world1/gbuffers_entities.vsh index 460f566..9ea6da1 100644 --- a/shaders/world1/gbuffers_entities.vsh +++ b/shaders/world1/gbuffers_entities.vsh @@ -3,4 +3,7 @@ // #define WORLD #define ENTITIES -#include "/programs/all_solid.vsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand.fsh b/shaders/world1/gbuffers_hand.fsh index 7dc5524..fdd18e5 100644 --- a/shaders/world1/gbuffers_hand.fsh +++ b/shaders/world1/gbuffers_hand.fsh @@ -3,4 +3,6 @@ #define WORLD #define HAND -#include "/programs/all_solid.fsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand.vsh b/shaders/world1/gbuffers_hand.vsh index a2820e6..95a797e 100644 --- a/shaders/world1/gbuffers_hand.vsh +++ b/shaders/world1/gbuffers_hand.vsh @@ -3,4 +3,6 @@ #define WORLD #define HAND -#include "/programs/all_solid.vsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand_water.fsh b/shaders/world1/gbuffers_hand_water.fsh index 59a7bed..9b0ad76 100644 --- a/shaders/world1/gbuffers_hand_water.fsh +++ b/shaders/world1/gbuffers_hand_water.fsh @@ -1,3 +1,5 @@ #version 120 -#include "/programs/all_translucent.fsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand_water.vsh b/shaders/world1/gbuffers_hand_water.vsh index afcff5d..9a4a869 100644 --- a/shaders/world1/gbuffers_hand_water.vsh +++ b/shaders/world1/gbuffers_hand_water.vsh @@ -1,3 +1,5 @@ #version 120 -#include "/programs/all_translucent.vsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_terrain.fsh b/shaders/world1/gbuffers_terrain.fsh index d9afdd3..78c5b74 100644 --- a/shaders/world1/gbuffers_terrain.fsh +++ b/shaders/world1/gbuffers_terrain.fsh @@ -1,5 +1,7 @@ #version 120 +#define END_SHADER + #define WORLD -#include "/programs/all_solid.fsh" \ No newline at end of file +#include "/dimensions/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_terrain.vsh b/shaders/world1/gbuffers_terrain.vsh index d18fc18..565cb77 100644 --- a/shaders/world1/gbuffers_terrain.vsh +++ b/shaders/world1/gbuffers_terrain.vsh @@ -1,5 +1,7 @@ #version 120 +#define END_SHADER + #define WORLD -#include "/programs/all_solid.vsh" \ No newline at end of file +#include "/dimensions/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured.fsh b/shaders/world1/gbuffers_textured.fsh index 0f62590..8da7019 100644 --- a/shaders/world1/gbuffers_textured.fsh +++ b/shaders/world1/gbuffers_textured.fsh @@ -1,3 +1,6 @@ #version 120 -#include "/programs/all_particles.fsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured.vsh b/shaders/world1/gbuffers_textured.vsh index a6d1cbf..b28afd5 100644 --- a/shaders/world1/gbuffers_textured.vsh +++ b/shaders/world1/gbuffers_textured.vsh @@ -1,3 +1,6 @@ #version 120 -#include "/programs/all_particles.vsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured_lit.fsh b/shaders/world1/gbuffers_textured_lit.fsh index 0f62590..738ea03 100644 --- a/shaders/world1/gbuffers_textured_lit.fsh +++ b/shaders/world1/gbuffers_textured_lit.fsh @@ -1,3 +1,5 @@ #version 120 -#include "/programs/all_particles.fsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured_lit.vsh b/shaders/world1/gbuffers_textured_lit.vsh index c9e7eab..bb26d8f 100644 --- a/shaders/world1/gbuffers_textured_lit.vsh +++ b/shaders/world1/gbuffers_textured_lit.vsh @@ -2,4 +2,7 @@ // #define WEATHER #define PARTICLES -#include "/programs/all_particles.vsh" \ No newline at end of file + +#define END_SHADER + +#include "/dimensions/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_water.fsh b/shaders/world1/gbuffers_water.fsh index 1447217..9b0ad76 100644 --- a/shaders/world1/gbuffers_water.fsh +++ b/shaders/world1/gbuffers_water.fsh @@ -1,4 +1,5 @@ #version 120 -#define END -#include "/programs/all_translucent.fsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_water.vsh b/shaders/world1/gbuffers_water.vsh index afcff5d..9a4a869 100644 --- a/shaders/world1/gbuffers_water.vsh +++ b/shaders/world1/gbuffers_water.vsh @@ -1,3 +1,5 @@ #version 120 -#include "/programs/all_translucent.vsh" \ No newline at end of file +#define END_SHADER + +#include "/dimensions/all_translucent.vsh" \ No newline at end of file