Add the whole ass shader

it has begun
This commit is contained in:
Xonk
2023-01-12 15:00:14 -05:00
parent 9deb7413a6
commit f82426c609
279 changed files with 28484 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#if MC_VERSION >= 11300
block.10001= minecraft:acacia_sapling minecraft:birch_sapling minecraft:dark_oak_sapling minecraft:jungle_sapling minecraft:oak_sapling minecraft:spruce_sapling minecraft:grass minecraft:dead_bush minecraft:fern minecraft:dandelion minecraft:poppy minecraft:blue_orchid minecraft:allium minecraft:azure_bluet minecraft:orange_tulip minecraft:pink_tulip minecraft:red_tulip minecraft:white_tulip minecraft:oxeye_daisy minecraft:brown_mushroom minecraft:red_mushroom minecraft:wheat minecraft:nether_wart minecraft:carrot minecraft:potato minecraft:beetroot_seeds
block.10003 = minecraft:acacia_leaves minecraft:birch_leaves minecraft:dark_oak_leaves minecraft:jungle_leaves minecraft:oak_leaves minecraft:spruce_leaves minecraft:vine
block.10004 = minecraft:cobweb minecraft:sugar_cane minecraft:pumpkin_seeds minecraft:lily_pad minecraft:lilac minecraft:sunflower minecraft:tall_grass minecraft:rose_bush minecraft:peony minecraft:large_fern
block.10002= minecraft:black_stained_glass minecraft:black_stained_glass_pane minecraft:blue_stained_glass minecraft:blue_stained_glass_pane minecraft:brown_stained_glass minecraft:brown_stained_glass_pane minecraft:cyan_stained_glass minecraft:cyan_stained_glass_pane minecraft:gray_stained_glass minecraft:gray_stained_glass_pane minecraft:green_stained_glass minecraft:green_stained_glass_pane minecraft:light_blue_stained_glass minecraft:light_blue_stained_glass_pane minecraft:light_gray_stained_glass minecraft:light_gray_stained_glass_pane minecraft:lime_stained_glass minecraft:lime_stained_glass_pane minecraft:magenta_stained_glass minecraft:magenta_stained_glass_pane minecraft:orange_stained_glass minecraft:orange_stained_glass_pane minecraft:pink_stained_glass minecraft:pink_stained_glass_pane minecraft:purple_stained_glass minecraft:purple_stained_glass_pane minecraft:red_stained_glass minecraft:red_stained_glass_pane minecraft:white_stained_glass minecraft:white_stained_glass_pane minecraft:yellow_stained_glass minecraft:yellow_stained_glass_pane minecraft:glass_pane minecraft:glass
block.8 = minecraft:water minecraft:flowing_water
block.79 = minecraft:ice
block.10005 = minecraft:glowstone minecraft:torch minecraft:wall_torch minecraft:lava minecraft:fire minecraft:redstone_torch minecraft:redstone_wall_torch minecraft:jack_o_lantern minecraft:magma_block minecraft:redstone_lamp:lit=true minecraft:lantern minecraft:campfire:lit=true minecraft:shroomlight minecraft:nether_portal minecraft:soul_torch minecraft:soul_wall_torch minecraft:soul_fire minecraft:end_rod minecraft:sea_lantern minecraft:soul_lantern minecraft:end_gateway minecraft:soul_campfire:lit=true minecraft:lava minecraft:fire
#else
#wavy plants, translucent, bottom vertices not moving
block.10001= 6 31 32 37 38 39 40 59 115 141 142 207
#wavy plants (blocks)
block.10003 = 18 106 161
#translucent
block.10004 = 30 83 104 105 111 175 176 177
#reflective surfaces (not including water and ice)
block.10002=95 160
#endif
layer.translucent=minecraft:glass_pane minecraft:glass

View File

@ -0,0 +1,45 @@
#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//////////////////////////////
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.);
}

View File

@ -0,0 +1,17 @@
#version 120
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.26/clampedRes*vec2(1920.0,1080.)*2-1.0;
}

View File

@ -0,0 +1,61 @@
#version 120
//6 Horizontal gaussian blurs and horizontal downsampling
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<maxIT+1;i++){
float weight = exp(-i*i*alpha*4.0);
//here we take advantage of bilinear filtering for 2x less sample, as a side effect the gaussian won't be totally centered for small blurs
vec2 spCoord = coord+dir*texelSize*(2.0*i+0.5);
tot += vec4(texture2D(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.x > 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.);
}

View File

@ -0,0 +1,20 @@
#version 120
uniform float viewWidth;
uniform float viewHeight;
varying vec2 texcoord;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
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.);
}

View File

@ -0,0 +1,61 @@
#version 120
//6 Vertical gaussian blurs and vertical downsampling
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<maxIT+1;i++){
float weight = exp(-i*i*alpha*4.0);
vec2 spCoord = coord+dir*texelSize*(2.0*i+0.5);
tot += vec4(texture2D(colortex6,spCoord).rgb,1.0)*weight*float(spCoord.y > 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.);
}

View File

@ -0,0 +1,21 @@
#version 120
uniform float viewWidth;
uniform float viewHeight;
varying vec2 texcoord;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
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.);
}

View File

@ -0,0 +1,103 @@
#version 120
//Merge and upsample the blurs into a 1/4 res bloom buffer
uniform sampler2D colortex3;
uniform sampler2D colortex6;
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.);
}

View File

@ -0,0 +1,17 @@
#version 120
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;
}

View File

@ -0,0 +1,512 @@
#version 120
//Vignetting, applies bloom, applies exposure and tonemaps the final image
#extension GL_EXT_gpu_shader4 : enable
#define Fake_purkinje
#define BLOOMY_FOG 2.0 //[0.0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 3.0 4.0 6.0 10.0 15.0 20.0]
#define BLOOM_STRENGTH 4.0 //[0.0 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 3.0 4.0]
#define TONEMAP ToneMap_Hejl2015 // Tonemapping operator [Tonemap_Uchimura HableTonemap reinhard Tonemap_Lottes ACESFilm ToneMap_Hejl2015]
//#define USE_ACES_COLORSPACE_APPROXIMATION // Do the tonemap in another colorspace
#define Purkinje_strength 1.0 // Simulates how the eye is unable to see colors at low light intensities. 0 = No purkinje effect at low exposures [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define Purkinje_R 0.4 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define Purkinje_G 0.7 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define Purkinje_B 1.0 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define Purkinje_Multiplier 5.0 // How much the purkinje effect increases brightness [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0 4.05 4.1 4.15 4.2 4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4.7 4.75 4.8 4.85 4.9 4.95 5.0 5.05 5.1 5.15 5.2 5.25 5.3 5.35 5.4 5.45 5.5 5.55 5.6 5.65 5.7 5.75 5.8 5.85 5.9 5.95 6.0 6.05 6.1 6.15 6.2 6.25 6.3 6.35 6.4 6.45 6.5 6.55 6.6 6.65 6.7 6.75 6.8 6.85 6.9 6.95 7.0 7.05 7.1 7.15 7.2 7.25 7.3 7.35 7.4 7.45 7.5 7.55 7.6 7.65 7.7 7.75 7.8 7.85 7.9 7.95 8.0 8.05 8.1 8.15 8.2 8.25 8.3 8.35 8.4 8.45 8.5 8.55 8.6 8.65 8.7 8.75 8.8 8.85 8.9 8.95 9.0 9.05 9.1 9.15 9.2 9.25 9.3 9.35 9.4 9.45 9.5 9.55 9.6 9.65 9.7 9.75 9.8 9.85 9.9 9.95 ]
//#define DOF //enable depth of field (blur on non-focused objects)
//#define HQ_DOF //Slow! Forces circular bokeh! Uses 4 times more samples with noise in order to remove sampling artifacts at great blur sizes.
//#define HEXAGONAL_BOKEH //disabled : circular blur shape - enabled : hexagonal blur shape
#define AUTOFOCUS
//#define FAR_BLUR_ONLY // Removes DoF on objects closer to the camera than the focus point
//lens properties
#define focal 2.4 // Centimeters [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0 4.05 4.1 4.15 4.2 4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4.7 4.75 4.8 4.85 4.9 4.95 5.0 5.05 5.1 5.15 5.2 5.25 5.3 5.35 5.4 5.45 5.5 5.55 5.6 5.65 5.7 5.75 5.8 5.85 5.9 5.95 6.0 6.05 6.1 6.15 6.2 6.25 6.3 6.35 6.4 6.45 6.5 6.55 6.6 6.65 6.7 6.75 6.8 6.85 6.9 6.95 7.0 7.05 7.1 7.15 7.2 7.25 7.3 7.35 7.4 7.45 7.5 7.55 7.6 7.65 7.7 7.75 7.8 7.85 7.9 7.95 8.0 8.05 8.1 8.15 8.2 8.25 8.3 8.35 8.4 8.45 8.5 8.55 8.6 8.65 8.7 8.75 8.8 8.85 8.9 8.95 9.0 9.05 9.1 9.15 9.2 9.25 9.3 9.35 9.4 9.45 9.5 9.55 9.6 9.65 9.7 9.75 9.8 9.85 9.9 9.95 ]
#define aperture 0.8 // Centimeters [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.05 1.1 1.15 1.2 1.25 1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.8 1.85 1.9 1.95 2.0 2.05 2.1 2.15 2.2 2.25 2.3 2.35 2.4 2.45 2.5 2.55 2.6 2.65 2.7 2.75 2.8 2.85 2.9 2.95 3.0 3.05 3.1 3.15 3.2 3.25 3.3 3.35 3.4 3.45 3.5 3.55 3.6 3.65 3.7 3.75 3.8 3.85 3.9 3.95 4.0 4.05 4.1 4.15 4.2 4.25 4.3 4.35 4.4 4.45 4.5 4.55 4.6 4.65 4.7 4.75 4.8 4.85 4.9 4.95 5.0 5.05 5.1 5.15 5.2 5.25 5.3 5.35 5.4 5.45 5.5 5.55 5.6 5.65 5.7 5.75 5.8 5.85 5.9 5.95 6.0 6.05 6.1 6.15 6.2 6.25 6.3 6.35 6.4 6.45 6.5 6.55 6.6 6.65 6.7 6.75 6.8 6.85 6.9 6.95 7.0 7.05 7.1 7.15 7.2 7.25 7.3 7.35 7.4 7.45 7.5 7.55 7.6 7.65 7.7 7.75 7.8 7.85 7.9 7.95 8.0 8.05 8.1 8.15 8.2 8.25 8.3 8.35 8.4 8.45 8.5 8.55 8.6 8.65 8.7 8.75 8.8 8.85 8.9 8.95 9.0 9.05 9.1 9.15 9.2 9.25 9.3 9.35 9.4 9.45 9.5 9.55 9.6 9.65 9.7 9.75 9.8 9.85 9.9 9.95 ]
#define MANUAL_FOCUS 48.0 // If autofocus is turned off, sets the focus point (meters) [0.06948345122280154 0.07243975703425146 0.07552184450877376 0.07873506526686186 0.0820849986238988 0.08557746127787037 0.08921851740926011 0.09301448921066349 0.09697196786440505 0.10109782498721881 0.10539922456186433 0.10988363537639657 0.11455884399268773 0.11943296826671962 0.12451447144412296 0.129812176855438 0.1353352832366127 0.1410933807013415 0.1470964673929768 0.15335496684492847 0.1598797460796939 0.16668213447794653 0.17377394345044514 0.18116748694692214 0.18887560283756183 0.19691167520419406 0.20528965757990927 0.21402409717744744 0.22313016014842982 0.2326236579172927 0.2425210746356487 0.25283959580474646 0.26359713811572677 0.27481238055948964 0.2865047968601901 0.29869468928867837 0.3114032239145977 0.32465246735834974 0.3384654251067422 0.3528660814588489 0.36787944117144233 0.3835315728763107 0.39984965434484737 0.4168620196785084 0.4345982085070782 0.453089017280169 0.4723665527410147 0.49246428767540973 0.513417119032592 0.5352614285189903 0.5580351457700471 0.5817778142098083 0.6065306597126334 0.6323366621862497 0.6592406302004438 0.6872892787909722 0.7165313105737893 0.7470175003104326 0.7788007830714049 0.8119363461506349 0.8464817248906141 0.8824969025845955 0.9200444146293233 0.9591894571091382 1.0 1.0425469051899914 1.086904049521229 1.1331484530668263 1.1813604128656459 1.2316236423470497 1.2840254166877414 1.338656724353094 1.3956124250860895 1.4549914146182013 1.5168967963882134 1.5814360605671443 1.6487212707001282 1.7188692582893286 1.7920018256557555 1.8682459574322223 1.9477340410546757 2.030604096634748 2.117000016612675 2.2070718156067044 2.300975890892825 2.398875293967098 2.5009400136621287 2.6073472713092674 2.718281828459045 2.833936307694169 2.9545115270921065 3.080216848918031 3.211270543153561 3.347900166492527 3.4903429574618414 3.638846248353525 3.7936678946831774 3.955076722920577 4.123352997269821 4.298788906309526 4.4816890703380645 4.672371070304759 4.871165999245474 5.0784190371800815 5.29449005047003 5.51975421667673 5.754602676005731 5.999443210467818 6.254700951936329 6.5208191203301125 6.798259793203881 7.087504708082256 7.38905609893065 7.703437568215379 8.031194996067258 8.372897488127265 8.72913836372013 9.10053618607165 9.487735836358526 9.891409633455755 10.312258501325767 10.751013186076355 11.208435524800691 11.685319768402522 12.182493960703473 12.700821376227164 13.241202019156521 13.804574186067095 14.391916095149892 15.00424758475255 15.642631884188171 16.30817745988666 17.00203994009402 17.725424121461643 18.479586061009854 19.265835257097933 20.085536923187668 20.940114358348602 21.831051418620845 22.75989509352673 23.728258192205157 24.737822143832553 25.790339917193062 26.88763906446752 28.03162489452614 29.22428378123494 30.46768661252054 31.763992386181833 33.11545195869231 34.52441195350251 35.99331883562839 37.524723159600995 39.12128399815321 40.78577355933337 42.52108200006278 44.3302224444953 46.21633621589248 48.182698291098816 50.23272298708815 52.36996988945491 54.598150033144236 56.92113234615337 59.34295036739207 61.867809250367884 64.50009306485578 67.24437240923179 70.10541234668786 73.08818067910767 76.19785657297057 79.43983955226133 82.81975887399955 86.3434833026695 90.01713130052181 93.84708165144015 97.83998453682129 102.00277308269969 106.34267539816554 110.86722712598126 115.58428452718766 120.50203812241894 125.62902691361414 130.9741532108186 136.54669808981876 142.35633750745257 148.4131591025766 154.72767971186107 161.3108636308289 168.17414165184545 175.32943091211476 182.78915558614753 190.56626845863 198.67427341514983 ]
#ifdef DOF
//hexagon pattern
const vec2 hex_offsets[60] = vec2[60] ( vec2( 0.2165, 0.1250 ),
vec2( 0.0000, 0.2500 ),
vec2( -0.2165, 0.1250 ),
vec2( -0.2165, -0.1250 ),
vec2( -0.0000, -0.2500 ),
vec2( 0.2165, -0.1250 ),
vec2( 0.4330, 0.2500 ),
vec2( 0.0000, 0.5000 ),
vec2( -0.4330, 0.2500 ),
vec2( -0.4330, -0.2500 ),
vec2( -0.0000, -0.5000 ),
vec2( 0.4330, -0.2500 ),
vec2( 0.6495, 0.3750 ),
vec2( 0.0000, 0.7500 ),
vec2( -0.6495, 0.3750 ),
vec2( -0.6495, -0.3750 ),
vec2( -0.0000, -0.7500 ),
vec2( 0.6495, -0.3750 ),
vec2( 0.8660, 0.5000 ),
vec2( 0.0000, 1.0000 ),
vec2( -0.8660, 0.5000 ),
vec2( -0.8660, -0.5000 ),
vec2( -0.0000, -1.0000 ),
vec2( 0.8660, -0.5000 ),
vec2( 0.2163, 0.3754 ),
vec2( -0.2170, 0.3750 ),
vec2( -0.4333, -0.0004 ),
vec2( -0.2163, -0.3754 ),
vec2( 0.2170, -0.3750 ),
vec2( 0.4333, 0.0004 ),
vec2( 0.4328, 0.5004 ),
vec2( -0.2170, 0.6250 ),
vec2( -0.6498, 0.1246 ),
vec2( -0.4328, -0.5004 ),
vec2( 0.2170, -0.6250 ),
vec2( 0.6498, -0.1246 ),
vec2( 0.6493, 0.6254 ),
vec2( -0.2170, 0.8750 ),
vec2( -0.8663, 0.2496 ),
vec2( -0.6493, -0.6254 ),
vec2( 0.2170, -0.8750 ),
vec2( 0.8663, -0.2496 ),
vec2( 0.2160, 0.6259 ),
vec2( -0.4340, 0.5000 ),
vec2( -0.6500, -0.1259 ),
vec2( -0.2160, -0.6259 ),
vec2( 0.4340, -0.5000 ),
vec2( 0.6500, 0.1259 ),
vec2( 0.4325, 0.7509 ),
vec2( -0.4340, 0.7500 ),
vec2( -0.8665, -0.0009 ),
vec2( -0.4325, -0.7509 ),
vec2( 0.4340, -0.7500 ),
vec2( 0.8665, 0.0009 ),
vec2( 0.2158, 0.8763 ),
vec2( -0.6510, 0.6250 ),
vec2( -0.8668, -0.2513 ),
vec2( -0.2158, -0.8763 ),
vec2( 0.6510, -0.6250 ),
vec2( 0.8668, 0.2513 ));
const vec2 offsets[60] = vec2[60] ( vec2( 0.0000, 0.2500 ),
vec2( -0.2165, 0.1250 ),
vec2( -0.2165, -0.1250 ),
vec2( -0.0000, -0.2500 ),
vec2( 0.2165, -0.1250 ),
vec2( 0.2165, 0.1250 ),
vec2( 0.0000, 0.5000 ),
vec2( -0.2500, 0.4330 ),
vec2( -0.4330, 0.2500 ),
vec2( -0.5000, 0.0000 ),
vec2( -0.4330, -0.2500 ),
vec2( -0.2500, -0.4330 ),
vec2( -0.0000, -0.5000 ),
vec2( 0.2500, -0.4330 ),
vec2( 0.4330, -0.2500 ),
vec2( 0.5000, -0.0000 ),
vec2( 0.4330, 0.2500 ),
vec2( 0.2500, 0.4330 ),
vec2( 0.0000, 0.7500 ),
vec2( -0.2565, 0.7048 ),
vec2( -0.4821, 0.5745 ),
vec2( -0.6495, 0.3750 ),
vec2( -0.7386, 0.1302 ),
vec2( -0.7386, -0.1302 ),
vec2( -0.6495, -0.3750 ),
vec2( -0.4821, -0.5745 ),
vec2( -0.2565, -0.7048 ),
vec2( -0.0000, -0.7500 ),
vec2( 0.2565, -0.7048 ),
vec2( 0.4821, -0.5745 ),
vec2( 0.6495, -0.3750 ),
vec2( 0.7386, -0.1302 ),
vec2( 0.7386, 0.1302 ),
vec2( 0.6495, 0.3750 ),
vec2( 0.4821, 0.5745 ),
vec2( 0.2565, 0.7048 ),
vec2( 0.0000, 1.0000 ),
vec2( -0.2588, 0.9659 ),
vec2( -0.5000, 0.8660 ),
vec2( -0.7071, 0.7071 ),
vec2( -0.8660, 0.5000 ),
vec2( -0.9659, 0.2588 ),
vec2( -1.0000, 0.0000 ),
vec2( -0.9659, -0.2588 ),
vec2( -0.8660, -0.5000 ),
vec2( -0.7071, -0.7071 ),
vec2( -0.5000, -0.8660 ),
vec2( -0.2588, -0.9659 ),
vec2( -0.0000, -1.0000 ),
vec2( 0.2588, -0.9659 ),
vec2( 0.5000, -0.8660 ),
vec2( 0.7071, -0.7071 ),
vec2( 0.8660, -0.5000 ),
vec2( 0.9659, -0.2588 ),
vec2( 1.0000, -0.0000 ),
vec2( 0.9659, 0.2588 ),
vec2( 0.8660, 0.5000 ),
vec2( 0.7071, 0.7071 ),
vec2( 0.5000, 0.8660 ),
vec2( 0.2588, 0.9659 ));
const vec2 shadow_offsets[209] = vec2[209](vec2(0.8886414f , 0.07936136f),
vec2(0.8190064f , 0.1900164f),
vec2(0.8614115f , -0.06991258f),
vec2(0.7685533f , 0.03792081f),
vec2(0.9970094f , 0.02585129f),
vec2(0.9686818f , 0.1570935f),
vec2(0.9854341f , -0.09172997f),
vec2(0.9330608f , 0.3326486f),
vec2(0.8329557f , -0.2438523f),
vec2(0.664771f , -0.0837701f),
vec2(0.7429124f , -0.1530652f),
vec2(0.9506453f , -0.2174281f),
vec2(0.8192949f , 0.3485171f),
vec2(0.6851269f , 0.2711877f),
vec2(0.7665657f , 0.5014166f),
vec2(0.673241f , 0.3793408f),
vec2(0.6981376f , 0.1465924f),
vec2(0.6521665f , -0.2384985f),
vec2(0.5145761f , -0.05752508f),
vec2(0.5641244f , -0.169443f),
vec2(0.5916035f , 0.06004957f),
vec2(0.57079f , 0.234188f),
vec2(0.509311f , 0.1523665f),
vec2(0.4204576f , 0.05759521f),
vec2(0.8200846f , -0.3601041f),
vec2(0.6893264f , -0.3473432f),
vec2(0.4775535f , -0.3062558f),
vec2(0.438106f , -0.1796866f),
vec2(0.4056528f , -0.08251233f),
vec2(0.5771964f , 0.5502692f),
vec2(0.5094061f , 0.4025192f),
vec2(0.6908483f , 0.572951f),
vec2(0.5379036f , -0.4542191f),
vec2(0.8167359f , -0.4793735f),
vec2(0.6829269f , -0.4557574f),
vec2(0.5725697f , -0.3477072f),
vec2(0.5767449f , -0.5782524f),
vec2(0.3979413f , -0.4172934f),
vec2(0.4282598f , -0.5145645f),
vec2(0.938814f , -0.3239739f),
vec2(0.702452f , -0.5662871f),
vec2(0.2832307f , -0.1285671f),
vec2(0.3230537f , -0.2691054f),
vec2(0.2921676f , -0.3734582f),
vec2(0.2534037f , -0.4906001f),
vec2(0.4343273f , 0.5223463f),
vec2(0.3605334f , 0.3151571f),
vec2(0.3498518f , 0.451428f),
vec2(0.3230703f , 0.00287089f),
vec2(0.1049206f , -0.1476725f),
vec2(0.2063161f , -0.2608192f),
vec2(0.7266634f , 0.6725333f),
vec2(0.4027067f , -0.6185485f),
vec2(0.2655533f , -0.5912259f),
vec2(0.4947965f , 0.3025357f),
vec2(0.5760762f , 0.68844f),
vec2(0.4909205f , -0.6975324f),
vec2(0.8609334f , 0.4559f),
vec2(0.1836646f , 0.03724086f),
vec2(0.2878554f , 0.178938f),
vec2(0.3948484f , 0.1618928f),
vec2(0.3519658f , -0.7628763f),
vec2(0.6338583f , -0.673193f),
vec2(0.5511802f , -0.8283072f),
vec2(0.4090595f , -0.8717521f),
vec2(0.1482169f , -0.374728f),
vec2(0.1050598f , -0.2613987f),
vec2(0.4210334f , 0.6578422f),
vec2(0.2430464f , 0.4383665f),
vec2(0.3329675f , 0.5512741f),
vec2(0.2147711f , 0.3245511f),
vec2(0.1227196f , 0.2529026f),
vec2(-0.03937457f , 0.156439f),
vec2(0.05618772f , 0.06690486f),
vec2(0.06519571f , 0.3974038f),
vec2(0.1360903f , 0.1466078f),
vec2(-0.00170609f , 0.3089452f),
vec2(0.1357622f , -0.5088975f),
vec2(0.1604694f , -0.7453476f),
vec2(0.1245694f , -0.6337074f),
vec2(0.02542936f , -0.3728781f),
vec2(0.02222222f , -0.649554f),
vec2(0.09870815f , 0.5357338f),
vec2(0.2073958f , 0.5452989f),
vec2(0.216654f , -0.8935689f),
vec2(0.2422334f , 0.665805f),
vec2(0.0574713f , 0.6742729f),
vec2(0.2021346f , 0.8144029f),
vec2(0.3086587f , 0.7504997f),
vec2(0.02122174f , -0.7498575f),
vec2(-0.1551729f , 0.1809731f),
vec2(-0.1947583f , 0.06246066f),
vec2(-0.05754202f , -0.03901273f),
vec2(-0.1083095f , 0.2952235f),
vec2(-0.03259534f , -0.492394f),
vec2(-0.02488567f , -0.2081116f),
vec2(-0.1820729f , -0.1829884f),
vec2(-0.1674413f , -0.04529009f),
vec2(0.04342153f , -0.0368562f),
vec2(0.801399f , -0.5845526f),
vec2(0.3158276f , -0.9124843f),
vec2(-0.05945269f , 0.6727523f),
vec2(0.07701834f , 0.8579889f),
vec2(-0.05778154f , 0.5699022f),
vec2(0.1191713f , 0.7542591f),
vec2(-0.2578296f , 0.3630984f),
vec2(-0.1428598f , 0.4557526f),
vec2(-0.3304029f , 0.5055485f),
vec2(-0.3227198f , 0.1847367f),
vec2(-0.4183801f , 0.3412776f),
vec2(0.2538475f , 0.9317476f),
vec2(0.406249f , 0.8423664f),
vec2(0.4718862f , 0.7592828f),
vec2(0.168472f , -0.06605823f),
vec2(0.2632498f , -0.7084918f),
vec2(-0.2816192f , -0.1023492f),
vec2(-0.3161443f , 0.02489911f),
vec2(-0.4677814f , 0.08450397f),
vec2(-0.4156994f , 0.2408664f),
vec2(-0.237449f , 0.2605326f),
vec2(-0.0912179f , 0.06491816f),
vec2(0.01475127f , 0.7670643f),
vec2(0.1216858f , -0.9368939f),
vec2(0.07010741f , -0.841011f),
vec2(-0.1708607f , -0.4152923f),
vec2(-0.1345006f , -0.5842513f),
vec2(-0.09419055f , -0.3213732f),
vec2(-0.2149337f , 0.730642f),
vec2(-0.1102187f , 0.8425013f),
vec2(-0.1808572f , 0.6244397f),
vec2(-0.2414505f , -0.7063725f),
vec2(-0.2410318f , -0.537854f),
vec2(-0.1005938f , -0.7635075f),
vec2(0.1053517f , 0.9678772f),
vec2(-0.3340288f , 0.6926677f),
vec2(-0.2363931f , 0.8464488f),
vec2(-0.4057773f , 0.7786722f),
vec2(-0.5484858f , 0.1686208f),
vec2(-0.64842f , 0.02256887f),
vec2(-0.5544513f , -0.02348978f),
vec2(-0.492855f , -0.1083694f),
vec2(-0.4248196f , 0.4674786f),
vec2(-0.5873146f , 0.4072608f),
vec2(-0.6439911f , 0.3038489f),
vec2(-0.6419188f , 0.1293737f),
vec2(-0.005880734f , 0.4699725f),
vec2(-0.4239455f , 0.6250131f),
vec2(-0.1701273f , 0.9506347f),
vec2(7.665656E-05f , 0.9941212f),
vec2(-0.7070159f , 0.4426281f),
vec2(-0.7481344f , 0.3139496f),
vec2(-0.8330062f , 0.2472693f),
vec2(-0.7271438f , 0.2024286f),
vec2(-0.5179888f , 0.3149576f),
vec2(-0.8258062f , 0.3779382f),
vec2(-0.8063191f , 0.1262931f),
vec2(-0.2690676f , -0.4360798f),
vec2(-0.3714577f , -0.5887412f),
vec2(-0.3736085f , -0.4018324f),
vec2(-0.3228985f , -0.2063406f),
vec2(-0.2414576f , -0.2875458f),
vec2(-0.4720859f , -0.3823904f),
vec2(-0.4937642f , -0.2686005f),
vec2(-0.01500604f , -0.9587054f),
vec2(-0.08535925f , -0.8820614f),
vec2(-0.6436375f , -0.3157263f),
vec2(-0.5736347f , -0.4224878f),
vec2(-0.5026127f , -0.5516239f),
vec2(-0.8200902f , 0.5370023f),
vec2(-0.7196413f , 0.57133f),
vec2(-0.5849072f , 0.5917885f),
vec2(-0.1598758f , -0.9739854f),
vec2(-0.4230629f , -0.01858409f),
vec2(-0.9403627f , 0.2213769f),
vec2(-0.685889f , -0.2192711f),
vec2(-0.6693704f , -0.4884708f),
vec2(-0.7967147f , -0.3078234f),
vec2(-0.596441f , -0.1686891f),
vec2(-0.7366468f , -0.3939891f),
vec2(-0.7963406f , 0.02246814f),
vec2(-0.9177913f , 0.0929693f),
vec2(-0.9284672f , 0.3329005f),
vec2(-0.6497722f , 0.6851863f),
vec2(-0.496019f , 0.7013303f),
vec2(-0.3930301f , -0.6892192f),
vec2(-0.2122009f , -0.8777389f),
vec2(-0.3660335f , -0.801644f),
vec2(-0.386839f , -0.1191898f),
vec2(-0.7020127f , -0.0776734f),
vec2(-0.7760845f , -0.1566844f),
vec2(-0.5444778f , -0.6516482f),
vec2(-0.5331346f , 0.4946506f),
vec2(-0.3288236f , 0.9408244f),
vec2(0.5819826f , 0.8101937f),
vec2(-0.4894184f , -0.8290837f),
vec2(-0.5183194f , 0.8454953f),
vec2(-0.7665774f , -0.5223897f),
vec2(-0.6703191f , -0.6217513f),
vec2(-0.8902924f , -0.2446688f),
vec2(-0.8574848f , -0.09174173f),
vec2(-0.3544409f , -0.9239591f),
vec2(-0.969833f , -0.1172272f),
vec2(-0.8968207f , -0.4079512f),
vec2(-0.5891477f , 0.7724466f),
vec2(-0.2146262f , 0.5286855f),
vec2(-0.3762444f , -0.3014335f),
vec2(-0.9466863f , -0.008970681f),
vec2(-0.596356f , -0.7976127f),
vec2(-0.8877738f , 0.4569088f));
#endif
flat varying vec4 exposure;
flat varying float rodExposure;
varying vec2 texcoord;
uniform sampler2D colortex4;
uniform sampler2D colortex5;
uniform sampler2D colortex3;
uniform sampler2D colortex7;
uniform sampler2D depthtex0;
uniform sampler2D noisetex;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform int isEyeInWater;
uniform float near;
uniform float aspectRatio;
uniform float far;
uniform float screenBrightness;
uniform float isWastes;
uniform float isWarpedForest;
uniform float isCrimsonForest;
uniform float isSoulValley;
uniform float isBasaltDelta;
#include "lib/color_transforms.glsl"
#include "lib/color_dither.glsl"
float cdist(vec2 coord) {
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float ld(float depth) {
return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
vec3 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;
}
void main() {
/* DRAWBUFFERS:7 */
float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.5);
vec3 col = texture2D(colortex5,texcoord).rgb;
#ifdef DOF
/*--------------------------------*/
float z = ld(texture2D(depthtex0, texcoord.st).r)*far;
#ifdef AUTOFOCUS
float focus = ld(texture2D(depthtex0, vec2(0.5)).r)*far;
#else
float focus = MANUAL_FOCUS*screenBrightness;
#endif
float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0);
#ifdef FAR_BLUR_ONLY
pcoc *= float(z > focus);
#endif
float noise = blueNoise()*6.28318530718;
mat2 noiseM = mat2( cos( noise ), -sin( noise ),
sin( noise ), cos( noise )
);
vec3 bcolor = vec3(0.);
float nb = 0.0;
vec2 bcoord = vec2(0.0);
/*--------------------------------*/
#ifndef HQ_DOF
bcolor = col;
#ifdef HEXAGONAL_BOKEH
for ( int i = 0; i < 60; i++) {
bcolor += texture2D(colortex5, texcoord.xy + hex_offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
}
col = bcolor/61.0;
#else
for ( int i = 0; i < 60; i++) {
bcolor += texture2D(colortex5, texcoord.xy + offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
}
/*--------------------------------*/
col = bcolor/61.0;
#endif
#endif
#ifdef HQ_DOF
for ( int i = 0; i < 209; i++) {
bcolor += texture2D(colortex5, texcoord.xy + noiseM*shadow_offsets[i]*pcoc*vec2(1.0,aspectRatio)).rgb;
}
col = bcolor/209.0;
#endif
#endif
vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.));
float BiomeParams = isWastes + isWarpedForest*10 + isCrimsonForest*10 + isSoulValley*5 + isBasaltDelta*0 ;
vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5).rgb/2./7.0;
float lightScat = clamp(4 * 0.05 * pow(exposure.a ,0.2) ,0.0,1.0)*vignette;
float VL_abs = texture2D(colortex7,texcoord).r;
VL_abs = clamp((1.0-VL_abs*1.05)*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
col = col * ACESInputMat;
col = TONEMAP(col);
col = LinearTosRGB(clamp(col * ACESOutputMat, 0.0, 1.0));
#endif
//col = ACESFitted(texture2D(colortex4,texcoord/3.).rgb/500.);
gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0);
//if (nightMode < 0.99 && texcoord.x < 0.5) gl_FragData[0].rgb =vec3(0.0,1.0,0.0);
}

View File

@ -0,0 +1,25 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define FinalR 1.0 //[0.0 0.025315 0.051271 0.077884 0.105170 0.133148 0.161834 0.191246 0.221402 0.252322 0.284025 0.316530 0.349858 0.384030 0.419067 0.454991 0.491824 0.529590 0.568312 0.608014 0.648721 0.690458 0.733253 0.777130 0.822118 0.868245 0.915540 0.964032 1.013752 1.064731 1.117000 1.170592 1.225540 1.281880 1.339646 1.398875 1.459603 1.521868 1.585709 1.651167 1.718281 1.787095 1.857651 1.929992 2.004166 2.080216 2.158192 2.238142 2.320116 2.404166 2.490342 2.578701 2.669296 2.762185 2.857425 2.955076 3.055199 3.157857 3.263114 3.371035 3.481689 3.595143 3.711470 3.830741 3.953032 4.078419 4.206979 4.338795 4.473947 4.612521 4.754602 4.900281 5.049647 5.202795 5.359819 5.520819 5.685894 5.855148 6.028687 6.206619 6.389056 6.576110 6.767901 6.964546 7.166169 7.372897 7.584858 7.802185 8.025013 8.253482 8.487735 8.727919 8.974182 9.226680 9.485569 9.751013 10.02317 10.30222 10.58834 10.88170 11.18249 ]
#define FinalG 1.0 //[0.0 0.025315 0.051271 0.077884 0.105170 0.133148 0.161834 0.191246 0.221402 0.252322 0.284025 0.316530 0.349858 0.384030 0.419067 0.454991 0.491824 0.529590 0.568312 0.608014 0.648721 0.690458 0.733253 0.777130 0.822118 0.868245 0.915540 0.964032 1.013752 1.064731 1.117000 1.170592 1.225540 1.281880 1.339646 1.398875 1.459603 1.521868 1.585709 1.651167 1.718281 1.787095 1.857651 1.929992 2.004166 2.080216 2.158192 2.238142 2.320116 2.404166 2.490342 2.578701 2.669296 2.762185 2.857425 2.955076 3.055199 3.157857 3.263114 3.371035 3.481689 3.595143 3.711470 3.830741 3.953032 4.078419 4.206979 4.338795 4.473947 4.612521 4.754602 4.900281 5.049647 5.202795 5.359819 5.520819 5.685894 5.855148 6.028687 6.206619 6.389056 6.576110 6.767901 6.964546 7.166169 7.372897 7.584858 7.802185 8.025013 8.253482 8.487735 8.727919 8.974182 9.226680 9.485569 9.751013 10.02317 10.30222 10.58834 10.88170 11.18249 ]
#define FinalB 1.0 //[0.0 0.025315 0.051271 0.077884 0.105170 0.133148 0.161834 0.191246 0.221402 0.252322 0.284025 0.316530 0.349858 0.384030 0.419067 0.454991 0.491824 0.529590 0.568312 0.608014 0.648721 0.690458 0.733253 0.777130 0.822118 0.868245 0.915540 0.964032 1.013752 1.064731 1.117000 1.170592 1.225540 1.281880 1.339646 1.398875 1.459603 1.521868 1.585709 1.651167 1.718281 1.787095 1.857651 1.929992 2.004166 2.080216 2.158192 2.238142 2.320116 2.404166 2.490342 2.578701 2.669296 2.762185 2.857425 2.955076 3.055199 3.157857 3.263114 3.371035 3.481689 3.595143 3.711470 3.830741 3.953032 4.078419 4.206979 4.338795 4.473947 4.612521 4.754602 4.900281 5.049647 5.202795 5.359819 5.520819 5.685894 5.855148 6.028687 6.206619 6.389056 6.576110 6.767901 6.964546 7.166169 7.372897 7.584858 7.802185 8.025013 8.253482 8.487735 8.727919 8.974182 9.226680 9.485569 9.751013 10.02317 10.30222 10.58834 10.88170 11.18249 ]
varying vec2 texcoord;
flat varying vec4 exposure;
flat varying float rodExposure;
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);
rodExposure = texelFetch2D(colortex4,ivec2(14,37),0).r;
}

View File

@ -0,0 +1,592 @@
#version 120
//Render sky, volumetric clouds, direct lighting
#extension GL_EXT_gpu_shader4 : enable
#define SCREENSPACE_CONTACT_SHADOWS //Raymarch towards the sun in screen-space, in order to cast shadows outside of the shadow map or at the contact of objects. Can get really expensive at high resolutions.
#define SHADOW_FILTER_SAMPLE_COUNT 9 // Number of samples used to filter the actual shadows [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 ]
#define CAVE_LIGHT_LEAK_FIX // Hackish way to remove sunlight incorrectly leaking into the caves. Can inacurrately remove shadows in some places
#define CLOUDS_SHADOWS
#define CLOUDS_SHADOWS_STRENGTH 1.0 //[0.1 0.125 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.9 1.0]
#define CLOUDS_QUALITY 0.5 //[0.1 0.125 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.9 1.0]
#define SSAO //It is also recommended to reduce the ambientOcclusionLevel value with this enabled
#define SSAO_SAMPLES 7 //[4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32]
#define TORCH_R 1.0 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define TORCH_G 0.75 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define TORCH_B 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define indirect_effect 1 // Choose what effect is applied to indirect light. [0 1 2 3]
#define AO_Strength 0.8 // strength of shadowed areas [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
#define GI_Strength 5.0 // strength of bounced light areas [ 1 2 3 4 5 6 7 8 9 10]
// #define Glass_Tint // multiply the background through glass by the color of the glass for a strong tint.
// #define HQ_SSGI
// #define end_shadows
//////////// misc settings
// #define WhiteWorld // THIS IS A DEBUG VIEW. uses to see AO easier. used to see fake GI better (green light)
// #define LabPBR_Emissives
#define Emissive_Brightness 10.0 // [1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 15. 20. 25. 30. 35. 40. 45. 50. 100.]
#define Emissive_Curve 2.0 // yes i blatantly copied kappa here. [1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
#define MIN_LIGHT_AMOUNT 1.0 //[0.0 0.5 1.0 1.5 2.0 3.0 4.0 5.0]
const bool shadowHardwareFiltering = true;
varying vec2 texcoord;
uniform float nightVision;
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
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 avgAmbient;
// flat varying vec3 WsunVec;
flat varying vec2 TAA_Offset;
flat varying float tempOffsets;
uniform sampler2D colortex0;//clouds
uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16
uniform sampler2D colortex3;
// uniform sampler2D colortex4;//Skybox
uniform sampler2D colortex5;
uniform sampler2D colortex6;//Skybox
uniform sampler2D colortex7;
uniform sampler2D colortex13;
uniform sampler2D colortex8;
uniform sampler2D depthtex1;//depth
uniform sampler2D depthtex0;//depth
uniform sampler2D noisetex;//depth
uniform float isWastes;
uniform float isWarpedForest;
uniform float isCrimsonForest;
uniform float isSoulValley;
uniform float isBasaltDelta;
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 gbufferPreviousModelView;
uniform mat4 gbufferPreviousProjection;
uniform vec3 previousCameraPosition;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform mat4 gbufferModelView;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
uniform float aspectRatio;
uniform vec3 cameraPosition;
// uniform int framemod8;
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/waterOptions.glsl"
#include "lib/color_transforms.glsl"
#include "lib/sky_gradient.glsl"
#include "lib/stars.glsl"
#include "lib/volumetricClouds.glsl"
#include "lib/waterBump.glsl"
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec3 ld(vec3 dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
#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);
}
float interleaved_gradientNoise(float temp){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+temp);
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
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);
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
return sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}
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;
// }
float bayer2(vec2 a){
a = floor(a);
return fract(dot(a,vec2(0.5,a.y*0.75)));
}
#define bayer4(a) (bayer2( .5*(a))*.25+bayer2(a))
#define bayer8(a) (bayer4( .5*(a))*.25+bayer2(a))
#define bayer16(a) (bayer8( .5*(a))*.25+bayer2(a))
#define bayer32(a) (bayer16(.5*(a))*.25+bayer2(a))
#define bayer64(a) (bayer32(.5*(a))*.25+bayer2(a))
#define bayer128(a) fract(bayer64(.5*(a))*.25+bayer2(a)+tempOffsets)
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 blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
}
float R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y);
}
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;
}
// void ssAO(inout vec3 lighting,vec3 fragpos,float mulfov, vec2 noise, vec3 normal, float lightmap){
// ivec2 pos = ivec2(gl_FragCoord.xy);
// const float tan70 = tan(70.*3.14/240.);
// float mulfov2 = gbufferProjection[1][1]/tan70;
// float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*1.412/50.0;
// float rd = mulfov2 * 0.04 ;
// //pre-rotate direction
// float n = 0.0;
// float occlusion = 0.0;
// vec2 acc = -(TAA_Offset*(texelSize/2)) ;
// int seed = (frameCounter%40000)*2 + frameCounter;
// vec2 ij = fract(R2_samples(seed) + noise.rg );
// vec2 v = ij;
// for (int j = 0; j < 7 ;j++) {
// vec2 sp = tapLocation(j,v.x,7,1.682,v.y);
// vec2 sampleOffset = sp*rd ;
// ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio));
// 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 < maxR2){
// float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal) ),0.,1.);
// occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0);
// }
// n += 1.0 ;
// }
// }
// }
// occlusion *= mix(2.25,0.0,clamp(pow(lightmap,2),0,1));
// occlusion = max(1.0 - occlusion/n, 0.0);
// lighting = lighting * occlusion;
// }
void ssAO(inout vec3 lighting,vec3 fragpos,float mulfov, vec2 noise, vec3 normal, vec2 texcoord, vec3 ambientCoefs, vec2 lightmap){
float skyLightDir = dot(WsunVec, ambientCoefs);
// float skyLightDir = dot(normal, sunVec);
ivec2 pos = ivec2(gl_FragCoord.xy);
const float tan70 = tan(70.*3.14/240.);
float mulfov2 = gbufferProjection[1][1]/tan70;
float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*1.412/50.0;
float rd = mulfov2 * 0.04 ;
//pre-rotate direction
float n = 0.0;
float occlusion = 0.0;
vec2 acc = -(TAA_Offset*(texelSize/2)) ;
int seed = (frameCounter%40000)*2 + frameCounter;
vec2 ij = fract(R2_samples(seed) + noise.rg );
// vec2 ij = fract(R2_samples(-1) + 0.5 * blueNoise() );
vec2 v = ij;
for (int j = 0; j < 7 ;j++) {
vec2 sp = tapLocation(j,v.x,7,1.682,v.y) ;
vec2 sampleOffset = sp*rd ;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio));
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 < maxR2){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal) ),0.,1.);
occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0);
}
n += 1.0 ;
}
}
}
// occlusion += max(skyLightDir, 0.0);
occlusion *= mix(2.25,0.0,clamp(pow(lightmap.x,2),0,1));
occlusion = max(1.0 - occlusion/n, 0.0);
lighting *=clamp(0.75+ambientCoefs.y*0.5,0.0,1.0);
lighting *= max(occlusion + luma(normal/dot(abs(normal),vec3(1))* mat3(gbufferModelView)), occlusion); // multiply ambient light by this effect
// lighting *= occlusion;
}
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));
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
float stepSize = stepsizes;
int maxSteps = 12;
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 ;
spos.xy += TAA_Offset*texelSize*0.5;
spos += stepv/(stepSize/2);
for(int i = 0; i < iterations; i++){
spos += stepv*noise;
float sp=texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).x;
float currZ = (spos.z);
if( sp < currZ) {
// float dist = abs(sp-currZ)/currZ;
return vec3(spos.xy, invLinZ(sp));
}
}
return vec3(1.1);
}
void rtAO(inout vec3 lighting, vec3 normal, vec2 noise, vec3 fragpos){
int nrays = 4;
float occlude = 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) ;
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 12.); // choc sspt
float skyLightDir = rayDir.y < 0.0 ? 1.0 : 1.0 ; // the positons where the occlusion happens
if (rayHit.z > 1.0) occlude += skyLightDir;
}
lighting *= occlude/nrays;
}
float rayTraceShadow(vec3 dir,vec3 position,float dither){
const float quality = 32.;
vec3 clipPosition = toClipSpace3(position);
//prevents the ray from going behind the camera
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -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. * clamp(MC_RENDER_QUALITY,1.,2.0);
vec3 spos = clipPosition;
spos.xy += (TAA_Offset*(texelSize/4)) ;
spos += stepv*dither;
for (int i = 0; i < int(quality); i++) {
spos += stepv ;
spos += stepv * dither;
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.1 ) return 0.0;
}
}
return 1.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) / pi;
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);
vec4 SpecularTex = texture2D(colortex8,texcoord);
// for a thing
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float dL = length(dVWorld);
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + dVWorld;
p3 += gbufferModelViewInverse[3].xyz;
bool iswater = texture2D(colortex7,texcoord).a > 0.99;
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w));
vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x));
vec3 normal = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw));
vec2 lightmap = dataUnpacked1.yz;
bool translucent = abs(dataUnpacked1.w-0.5) <0.01;
bool hand = abs(dataUnpacked1.w-0.75) <0.01;
bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
float LightDir = clamp((-15 + max(dot(normal, WsunVec),0.0)*255.0) / 240.0 ,0.0,1.0);
vec3 lightSource = normalize(WsunVec);
vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos));
float lightning_shine = clamp(phaseg(SdotV, 0.8),0,3);
vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.));
#ifdef WhiteWorld
albedo = vec3(1.0);
#endif
if ( z >= 1.) {
vec3 color = vec3(1.0,0.75,0.9)/4000.0*150.0*0.1;
vec4 cloud = texture2D_bicubic(colortex0,texcoord*CLOUDS_QUALITY);
color = color*cloud.a+cloud.rgb;
gl_FragData[0].rgb = clamp(fp10Dither(color*8./3. * (1.0-rainStrength*0.4),triangularize(blueNoise())),0.0,65000.);
}else{
////// ----- indirect ----- //////
vec3 custom_lightmap = texture2D(colortex4, (vec2(lightmap.x, pow(lightmap.y,2))*15.0+0.5+vec2(0.0,19.))*texelSize).rgb*8./150./3.; // y = torch
// vec3 ambientLight = vec3(1.0) / 30;
vec3 ambientLight = gl_Fog.color.rgb * 0.2;
// lightmap.x = trpData.a < 255.0/255.0 ? mix( trpData.a, lightmap.x ,pow(trpData.a,Emissive_Curve)): lightmap.x ;
// vec3 Lightsources = (vec3(1.0)/5) * (pow(lightmap.x,2.0) + pow(lightmap.x,10.0));
vec3 Lightsources = custom_lightmap.y * vec3(TORCH_R,TORCH_G,TORCH_B) * 0.5;
if(hand) Lightsources *= 0.15;
if(blocklights) Lightsources *= 0.3;
if(custom_lightmap.y > 10.) Lightsources *= 0.25;
//apply a curve for the torch light so it doesnt mix with lab emissive colors too much
#ifdef LabPBR_Emissives
if(blocklights && (SpecularTex.a > 0.0 && SpecularTex.a < 1.0)) Lightsources = mix(vec3(0.0), Lightsources, SpecularTex.a);
#endif
ambientLight += Lightsources;
#if indirect_effect == 1
if (!hand) ssAO(ambientLight, fragpos, 1.0, blueNoise(gl_FragCoord.xy).rg, worldToView(decode(dataUnpacked0.yw)), texcoord, ambientCoefs, lightmap.xy ) ;
#endif
// #if indirect_effect == 2
// if (!hand ) rtAO(ambientLight, normal, blueNoise(gl_FragCoord.xy).rg, fragpos);
// #endif
// #if indirect_effect == 3
// if (!hand) rtGI(ambientLight, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, 1, albedo);
// #endif
vec3 Indirect_lighting = ambientLight;
////// ----- direct ----- //////
float screenShadow = 1;
vec3 Direct_lighting = SunCol * (lightning_shine*10) * LightDir;
#ifdef end_shadows
vec3 vec = -lightCol.a*viewspace_sunvec;
screenShadow = rayTraceShadow(vec, fragpos, interleaved_gradientNoise());
if (!hand) Direct_lighting *= screenShadow;
#endif
////// ----- finalize ----- //////
gl_FragData[0].rgb = (Indirect_lighting+Direct_lighting) * albedo ;
#ifdef LabPBR_Emissives
gl_FragData[0].rgb = SpecularTex.a < 255.0/255.0 ? mix(gl_FragData[0].rgb, albedo * Emissive_Brightness , SpecularTex.a): gl_FragData[0].rgb;
#endif
// do this after water and stuff is done because yea
#ifdef Specular_Reflections
MaterialReflections(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, WsunVec, SunCol, screenShadow*LightDir , 0.0, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,blueNoise()), hand);
#endif
}
// / lightnign flashes fog
if (isEyeInWater == 0){
// vec3 lightSource = normalize(WsunVec);
// vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
// float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos));
// float lightning_shine = clamp(phaseg(SdotV, 0.35) ,0,1);
vec3 flashingfogCol = SunCol * 0.25;
float flashingfogdist = clamp(pow(length(fragpos)/far,5.), 0.0, 1.0) ;
gl_FragData[0].rgb += flashingfogCol * lightning_shine * flashingfogdist;
// vl.a *= 1.0 - sqrt(flashingfogdist);
}
/* DRAWBUFFERS:3 */
}

View File

@ -0,0 +1,68 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define TAA
varying vec2 texcoord;
flat varying vec3 WsunVec;
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 avgAmbient;
flat varying vec4 lightCol;
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
vec3 sc = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
ambientUp = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
ambientDown = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
ambientLeft = texelFetch2D(colortex4,ivec2(2,37),0).rgb;
ambientRight = texelFetch2D(colortex4,ivec2(3,37),0).rgb;
ambientB = texelFetch2D(colortex4,ivec2(4,37),0).rgb;
ambientF = texelFetch2D(colortex4,ivec2(5,37),0).rgb;
avgAmbient = texelFetch2D(colortex4,ivec2(11,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2-1.;
lightCol.rgb = sc;
WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) *sunPosition);
zMults = vec3((far * near)*2.0,far+near,far-near);
}

View File

@ -0,0 +1,259 @@
#version 120
//Volumetric fog rendering
#extension GL_EXT_gpu_shader4 : enable
#define VL_SAMPLES 8 //[4 6 8 10 12 14 16 20 24 30 40 50]
#define Ambient_Mult 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0 5.0 6.0 10.0]
#define SEA_LEVEL 70 //[0 10 20 30 40 50 60 70 80 90 100 110 120 130 150 170 190] //The volumetric light uses an altitude-based fog density, this is where fog density is the highest, adjust this value according to your world.
#define ATMOSPHERIC_DENSITY 1.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 4.0 5.0 7.5 10.0 12.5 15.0 20.]
#define fog_mieg1 0.40 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
#define fog_mieg2 0.10 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
#define fog_coefficientRayleighR 5.8 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientRayleighG 1.35 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientRayleighB 3.31 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientMieR 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientMieG 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientMieB 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define Underwater_Fog_Density 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0]
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 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;
uniform float isWastes;
uniform float isWarpedForest;
uniform float isCrimsonForest;
uniform float isSoulValley;
uniform float isBasaltDelta;
#include "lib/waterOptions.glsl"
#include "lib/color_transforms.glsl"
#include "lib/color_dither.glsl"
#include "lib/projections.glsl"
#include "lib/sky_gradient.glsl"
#include "lib/volumetricClouds.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 densityAtPosFog(in vec3 pos){
pos /= 18.;
pos.xz *= 0.5;
vec3 p = floor(pos);
vec3 f = fract(pos);
f = (f*f) * (3.-2.*f);
vec2 uv = p.xz + f.xz + p.y * vec2(0.0,193.0);
vec2 coord = uv / 512.0;
vec2 xy = texture2D(noisetex, coord).yx;
return mix(xy.r,xy.g, f.y);
}
float cloudVol(in vec3 pos){
vec3 samplePos = pos*vec3(1.0,1./24.,1.0) ;
vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0) + vec3(frameTimeCounter,0,frameTimeCounter);
float fog_shape = 1-densityAtPosFog(samplePos * 16.0 );
float fog_eroded = densityAtPosFog( samplePos2 * 255.0 );
return max( (fog_shape*2.0 - fog_eroded*0.2) - 1.5, 0.0) * 255*255 ;
}
float phaseRayleigh(float cosTheta) {
const vec2 mul_add = vec2(0.1, 0.28) /acos(-1.0);
return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation
}
mat2x3 getVolumetricRays(float dither,vec3 fragpos, vec3 fragpos_ALT) {
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
//project view origin into projected shadowmap space
vec3 start = toShadowSpaceProjected(vec3(0.));
//rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step
vec3 dV = (fragposition-start);
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),far*4)/length(dVWorld);
dV *= maxLength;
dVWorld *= maxLength;
//apply dither
vec3 progress = start.xyz;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 vL = vec3(0.);
float dL = length(dVWorld);
vec3 lightSource = normalize(WsunVec);
vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos));
float mie = phaseg(SdotV,0.8);
float rayL = phaseRayleigh(SdotV);
float mu = 1.0;
vec3 absorbance = vec3(1.0);
float expFactor = 11.0;
vec3 fogColor = gl_Fog.color.rgb * 0.5 ;
vec3 lightning = SunCol ;
vec3 rC = vec3(fogColor.r*1e-6, fogColor.g*1e-5, fogColor.b*1e-5);
vec3 mC = vec3(fogColor.r*1e-6, fogColor.g*1e-6, fogColor.b*1e-6);
for (int i=0;i<VL_SAMPLES+10;i++) {
float d = (pow(expFactor, float(i+dither)/float(VL_SAMPLES+10))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(VL_SAMPLES+10)) * log(expFactor) / float(VL_SAMPLES+10)/(expFactor-1.0);
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
float densityVol = cloudVol(progressW);
float density = densityVol*mu*300.;
float CastLight = 0;
for (int j=0; j < 3; j++){
vec3 shadowSamplePos = progressW + WsunVec * (5+j*10 ) ;
float densityVol2 = cloudVol(shadowSamplePos);
CastLight += densityVol2/255;
}
//Just air
vec2 airCoef = exp(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0)) * 24;
//Pbr for air, yolo mix between mie and rayleigh for water droplets
vec3 rL = rC*airCoef.x;
vec3 m = (airCoef.y+density)*mC;
vec3 DirectLight = lightning * (rayL*rL+m*mie) * exp(CastLight/25) * 1e-5 * mie ;
vec3 DirectLight2 = lightning * (rayL*rL+m*mie) * exp(CastLight / -25) ;
vec3 AmbientLight = fogColor * max(1 - exp(dot(m,vec3(1)) * -25 ),0.05) / 150 ;
vec3 vL0 = AmbientLight + clamp( DirectLight+DirectLight2 ,0,255) ;
// vL += (vL0 - vL0 * exp(-density*mu*dd*dL)) / (density*mu+0.00000001)*absorbance;
// absorbance *= clamp(exp(-(density)*mu*dd*dL),0.0,1.0);
vL += (vL0 - vL0 * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*absorbance;
absorbance *= clamp(exp(-(rL+m)*dd*dL),0.0,1.0);
}
return mat2x3(vL,absorbance);
}
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = 16;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,32.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float phase = phaseg(VdotL, Dirt_Mie_Phase);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
vec3 spPos = start.xyz + dV*d;
vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs * 1.1);
vec3 light = (ambientMul*ambient )*scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
varying vec2 texcoord;
void main() {
/* DRAWBUFFERS:0 */
if (isEyeInWater == 0){
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
float z = texture2D(depthtex0,tc).x;
vec3 fragpos = toScreenSpace(vec3(tc,z));
vec3 fragpos_ALT = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
float noise = blueNoise();
mat2x3 vl = getVolumetricRays(noise,fragpos,fragpos_ALT);
float absorbance = dot(vl[1],vec3(0.22,0.71,0.07));
gl_FragData[0] = clamp(vec4(vl[0],absorbance),0.000001,65000.);
}
else {
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) / pi;
vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize;
float z = texture2D(depthtex0,tc).x;
vec3 fragpos = toScreenSpace(vec3(tc,z));
float noise=blueNoise();
vec3 vl = vec3(0.0);
float estEyeDepth = clamp((14.0-eyeBrightnessSmooth.y/255.0*16.0)/14.0,0.,1.0);
estEyeDepth *= estEyeDepth*estEyeDepth*34.0;
#ifndef lightMapDepthEstimation
estEyeDepth = max(Water_Top_Layer - cameraPosition.y,0.0);
#endif
waterVolumetrics(vl, vec3(0.0), fragpos, estEyeDepth, estEyeDepth, length(fragpos), noise, totEpsilon, scatterCoef, ambientUp*8./150./3.*0.84*2.0/pi, lightCol.rgb*8./150./3.0*(0.91-pow(1.0-sunElevation,5.0)*0.86), dot(normalize(fragpos), normalize(sunVec)));
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
}
}

View File

@ -0,0 +1,49 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define BASE_FOG_AMOUNT 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0 10.0 20.0 30.0 50.0 100.0 150.0 200.0] Base fog amount amount (does not change the "cloudy" fog)
#define CLOUDY_FOG_AMOUNT 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0]
#define FOG_TOD_MULTIPLIER 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] //Influence of time of day on fog amount
#define FOG_RAIN_MULTIPLIER 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] //Influence of rain on fog amount
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 float tempOffsets;
flat varying float fogAmount;
flat varying float VFAmount;
uniform sampler2D colortex4;
uniform float sunElevation;
uniform float rainStrength;
uniform int isEyeInWater;
uniform int frameCounter;
uniform int worldTime;
#include "/lib/util.glsl"
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
tempOffsets = HaltonSeq2(frameCounter%10000);
gl_Position = ftransform();
gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
vec3 avgAmbient = texelFetch2D(colortex4,ivec2(11,37),0).rgb;
ambientUp = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
ambientDown = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
ambientLeft = texelFetch2D(colortex4,ivec2(2,37),0).rgb;
ambientRight = texelFetch2D(colortex4,ivec2(3,37),0).rgb;
ambientB = texelFetch2D(colortex4,ivec2(4,37),0).rgb;
ambientF = texelFetch2D(colortex4,ivec2(5,37),0).rgb;
}

View File

@ -0,0 +1,210 @@
#version 120
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
#extension GL_EXT_gpu_shader4 : enable
#define Cave_fog // cave fog....
#define CaveFogFallOff 1.3 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
#define CaveFogColor_R 0.1 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define CaveFogColor_G 0.2 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define CaveFogColor_B 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
// #define display_LUT // aaaaaaaaaaaaaaaaaaaaaaa
varying vec2 texcoord;
flat varying vec3 zMults;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D colortex7;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex2;
uniform sampler2D colortex0;
uniform sampler2D noisetex;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferProjectionInverse;
uniform vec2 texelSize;
uniform vec3 cameraPosition;
uniform mat4 gbufferModelView;
uniform float isWastes;
uniform float isWarpedForest;
uniform float isCrimsonForest;
uniform float isSoulValley;
uniform float isBasaltDelta;
uniform int isEyeInWater;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
uniform float blindness;
uniform float darknessFactor;
uniform float darknessLightFactor;
uniform float nightVision;
#include "lib/waterBump.glsl"
#include "lib/waterOptions.glsl"
#include "lib/volumetricClouds.glsl"
float ld(float depth) {
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){
vec4 vl = vec4(0.0);
float sum = 0.0;
mat3x3 weights;
ivec2 posD = ivec2(coord/2.0)*2;
ivec2 posVl = ivec2(coord/2.0);
float dz = zMults.x;
ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2;
//pos = ivec2(1,-1);
ivec2 tcDepth = posD + ivec2(-4,-4) + pos*2;
float dsample = ld(texelFetch2D(depth,tcDepth,0).r);
float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(-4,0) + pos*2;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-2,0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0) + pos*2;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0,-4) + pos*2;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0,-2)+pos,0)*w;
sum += w;
return vl/sum;
}
float luma(vec3 color) {
return dot(color,vec3(0.21, 0.72, 0.07));
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
void main() {
/* DRAWBUFFERS:73 */
//3x3 bilateral upscale from half resolution
float z = texture2D(depthtex0,texcoord).x;
float z2 = texture2D(depthtex1,texcoord).x;
float frDepth = ld(z);
vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
vec4 transparencies = texture2D(colortex2,texcoord);
vec4 trpData = texture2D(colortex7,texcoord);
bool iswater = trpData.a > 0.99;
vec2 refractedCoord = texcoord;
vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z));
vec3 fragpos2 = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z2));
// vec3 np3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos;
vec3 np3 = normVec(p3);
if (iswater){
float norm = getWaterHeightmap(np3.xz*1.71, 4.0, 0.25, 1.0);
float displ = norm/(length(fragpos)/far)/35.;
refractedCoord += displ;
if (texture2D(colortex7,refractedCoord).a < 0.99)
refractedCoord = texcoord;
}
vec3 color = texture2D(colortex3,refractedCoord).rgb;
if (frDepth > 2.5/far || transparencies.a < 0.99) // Discount fix for transparencies through hand
color = color*(1.0-transparencies.a)+transparencies.rgb*10.;
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;
color *= vl.a;
// vec3 fogColor = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.05;
/// lightnign flashes fog
// if (isEyeInWater == 0){
// vec3 lightSource = normalize(WsunVec);
// vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
// float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos));
// float lightning_shine = clamp(phaseg(SdotV, 0.35) ,0,1);
// vec3 flashingfogCol = SunCol * 0.25;
// float flashingfogdist = clamp(pow(length(fragpos)/far,5.), 0.0, 1.0) ;
// color.rgb += flashingfogCol * lightning_shine * flashingfogdist;
// // vl.a *= 1.0 - sqrt(flashingfogdist);
// }
// underwater fog
if (isEyeInWater == 1){
// color.rgb *= exp(-length(fragpos)/2*totEpsilon);
// vl.a *= (dot(exp(-length(fragpos)/1.2*totEpsilon),vec3(0.2,0.7,0.1)))*0.5+0.5;
float fogfade = clamp(exp(-length(fragpos) /12 ) ,0.0,1.0);
float fogcolfade = clamp(exp(np3.y*1.5 - 1.5),0.0,1.0);
color.rgb *= fogfade;
color.rgb = color.rgb * (1.0 + vec3(0.0,0.1,0.2) * 12 * (1.0 - fogfade)) + (vec3(0.0,0.1,0.2) * 0.5 * (1.0 - fogfade))*fogcolfade;
vl.a *= fogfade*0.75 +0.25;
}
/// 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.));
vl.a = 0.0;
}
// blidnesss
color.rgb *= mix(1.0, clamp(1.5-pow(length(fragpos2)*(blindness*0.2),2.0),0.0,1.0), 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);
// float BiomeParams = isWastes + isWarpedForest + isCrimsonForest + isSoulValley + isBasaltDelta ;
color += vl.rgb;
gl_FragData[0].r = vl.a;
gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0);
gl_FragData[1].rgb = clamp(color,6.11*1e-5,65000.0);
#ifdef display_LUT
gl_FragData[1].rgb = texture2D(colortex4,texcoord*0.45).rgb * 0.000035;
#endif
}

View File

@ -0,0 +1,19 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
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;
}

View File

@ -0,0 +1,320 @@
#version 120
//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader)
#extension GL_EXT_gpu_shader4 : enable
#define TAA //if disabled you should increase most samples counts as I rely on TAA to filter noise
//#define FAST_TAA //disables bicubic resampling and closest velocity, improves fps especially at high resolutions
//TAA OPTIONS
//#define NO_CLIP //Removes all anti-ghosting techniques used and creates a sharp image (good for still screenshots)
#define BLEND_FACTOR 0.05 //[0.01 0.02 0.03 0.04 0.05 0.06 0.08 0.1 0.12 0.14 0.16] higher values = more flickering but sharper image, lower values = less flickering but the image will be blurrier
#define MOTION_REJECTION 0.5 //[0.0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.5] //Higher values=sharper image in motion at the cost of flickering
#define ANTI_GHOSTING 1.0 //[0.0 0.25 0.5 0.75 1.0] High values reduce ghosting but may create flickering
#define FLICKER_REDUCTION 0.75 //[0.0 0.25 0.5 0.75 1.0] High values reduce flickering but may reduce sharpness
#define CLOSEST_VELOCITY //improves edge quality in motion at the cost of performance
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 depthtex0;
uniform vec2 texelSize;
uniform float frameTimeCounter;
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 TAA_hq(){
//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 = closestToCamera3x3();
#endif
#ifndef CLOSEST_VELOCITY
vec3 closestToCamera = vec3(texcoord,texture2D(depthtex0,texcoord).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;
//to reduce error propagation caused by interpolation during history resampling, we will introduce back some aliasing in motion
vec2 d = 0.5-abs(fract(previousPosition.xy*vec2(viewWidth,viewHeight)-texcoord*vec2(viewWidth,viewHeight))-0.5);
float mixFactor = dot(d,d);
float rej = mixFactor*MOTION_REJECTION;
//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 texture2D(colortex3, texcoord).rgb;
//Samples current frame 3x3 neighboorhood
vec3 albedoCurrent0 = texture2D(colortex3, texcoord).rgb;
vec3 albedoCurrent1 = texture2D(colortex3, texcoord + vec2(texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent2 = texture2D(colortex3, texcoord + vec2(texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent3 = texture2D(colortex3, texcoord + vec2(-texelSize.x,-texelSize.y)).rgb;
vec3 albedoCurrent4 = texture2D(colortex3, texcoord + vec2(-texelSize.x,texelSize.y)).rgb;
vec3 albedoCurrent5 = texture2D(colortex3, texcoord + vec2(0.0,texelSize.y)).rgb;
vec3 albedoCurrent6 = texture2D(colortex3, texcoord + vec2(0.0,-texelSize.y)).rgb;
vec3 albedoCurrent7 = texture2D(colortex3, texcoord + vec2(-texelSize.x,0.0)).rgb;
vec3 albedoCurrent8 = texture2D(colortex3, texcoord + vec2(texelSize.x,0.0)).rgb;
#ifndef NO_CLIP
//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))))));
vec3 albedoPrev = FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.82).xyz;
vec3 finalcAcc = clamp(albedoPrev,cMin,cMax);
//increases blending factor if history is far away from aabb, reduces ghosting at the cost of some flickering
float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev);
//reduces blending factor if current texel is far from history, reduces flickering
float lumDiff2 = distance(albedoPrev,albedoCurrent0)/luma(albedoPrev);
lumDiff2 = 1.0-clamp(lumDiff2*lumDiff2,0.,1.)*FLICKER_REDUCTION;
//Blend current pixel with clamped history
vec3 supersampled = mix(finalcAcc,albedoCurrent0,clamp(BLEND_FACTOR*lumDiff2+rej+isclamped*ANTI_GHOSTING+0.01,0.,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
}

View File

@ -0,0 +1,17 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
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;
}

View File

@ -0,0 +1,53 @@
#version 120
//downsample 1st pass (half res) for bloom
uniform sampler2D colortex5;
uniform sampler2D colortex8;
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;
float emissives = texture2D(colortex8,quarterResTC).a;
if(emissives == 1.0) emissives = 0.0;
emissives *= 5;
//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.);
// gl_FragData[0].rgb += gl_FragData[0].rgb*emissives;
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);
}

View File

@ -0,0 +1,17 @@
#version 120
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;
}

136
shaders/world1/deferred.fsh Normal file
View File

@ -0,0 +1,136 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
//Prepares sky textures (2 * 256 * 256), computes light values and custom lightmaps
#define Ambient_Mult 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0 5.0 6.0 10.0]
#define Sky_Brightness 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0 5.0 6.0 10.0]
#define MIN_LIGHT_AMOUNT 1.0 //[0.0 0.5 1.0 1.5 2.0 3.0 4.0 5.0]
#define TORCH_AMOUNT 1.0 //[0.0 0.5 0.75 1. 1.2 1.4 1.6 1.8 2.0]
#define TORCH_R 1.0 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define TORCH_G 0.75 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define TORCH_B 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
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);
void main() {
/* DRAWBUFFERS:4 */
gl_FragData[0] = vec4(0.0);
//Lightmap for forward shading (contains average integrated sky color across all faces + torch + min ambient)
vec3 avgAmbient = (ambientUp + ambientLeft + ambientRight + ambientB + ambientF + ambientDown)/6.;
if (gl_FragCoord.x < 17. && gl_FragCoord.y < 17.){
float torchLut = clamp(16.0-gl_FragCoord.x,0.5,15.5);
torchLut = torchLut+0.712;
float torch_lightmap = max(1.0/torchLut/torchLut - 1/16.21/16.21,0.0);
torch_lightmap = torch_lightmap*TORCH_AMOUNT*5.0;
float sky_lightmap = 0.5*150.0;
vec3 ambient = avgAmbient*sky_lightmap+torch_lightmap*vec3(TORCH_R,TORCH_G,TORCH_B)*TORCH_AMOUNT+MIN_LIGHT_AMOUNT*0.005/(exposureF+clamp(rodExposure*exposureF/10.,0.0,10000.0));
gl_FragData[0] = vec4(ambient*Ambient_Mult,1.0);
}
//Lightmap for deferred shading (contains only torch + min ambient)
if (gl_FragCoord.x < 17. && gl_FragCoord.y > 19. && gl_FragCoord.y < 19.+17. ){
float torchLut = clamp(16.0-gl_FragCoord.x,0.5,15.5);
torchLut = torchLut+0.712;
float torch_lightmap = max(1.0/torchLut/torchLut - 1/16.21/16.21,0.0);
float ambient = torch_lightmap*TORCH_AMOUNT*5.;
float sky_lightmap = 0.5;
gl_FragData[0] = vec4(sky_lightmap,ambient,MIN_LIGHT_AMOUNT*0.005/(exposureF+clamp(rodExposure*exposureF/10.,0.0,10000.0)),1.0)*Ambient_Mult;
}
//Save light values
if (gl_FragCoord.x < 1. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(ambientUp,1.0);
if (gl_FragCoord.x > 1. && gl_FragCoord.x < 2. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(ambientDown,1.0);
if (gl_FragCoord.x > 2. && gl_FragCoord.x < 3. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(ambientLeft,1.0);
if (gl_FragCoord.x > 3. && gl_FragCoord.x < 4. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(ambientRight,1.0);
if (gl_FragCoord.x > 4. && gl_FragCoord.x < 5. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(ambientB,1.0);
if (gl_FragCoord.x > 5. && gl_FragCoord.x < 6. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(ambientF,1.0);
if (gl_FragCoord.x > 6. && gl_FragCoord.x < 7. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(lightSourceColor,1.0);
if (gl_FragCoord.x > 7. && gl_FragCoord.x < 8. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(avgAmbient,1.0);
//Sky gradient (no clouds)
const float pi = 3.141592653589793238462643383279502884197169;
if (gl_FragCoord.x > 18. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257){
gl_FragData[0] = vec4(vec3(1.0,0.4,0.12)*100.,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.06),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);
}

201
shaders/world1/deferred.vsh Normal file
View File

@ -0,0 +1,201 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define EXPOSURE_MULTIPLIER 1.0 //[0.25 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.1 1.2 1.3 1.4 1.5 2.0 3.0 4.0]
#define AUTO_EXPOSURE //Highly recommended to keep it on unless you want to take screenshots
#define Manual_exposure_value 1.0 // [0.000553 0.000581 0.000611 0.000642 0.000675 0.000710 0.000746 0.000784 0.000825 0.000867 0.000911 0.000958 0.001007 0.001059 0.001113 0.001170 0.001230 0.001294 0.001360 0.001430 0.001503 0.001580 0.001661 0.001746 0.001836 0.001930 0.002029 0.002133 0.002242 0.002357 0.002478 0.002605 0.002739 0.002879 0.003027 0.003182 0.003345 0.003517 0.003697 0.003887 0.004086 0.004296 0.004516 0.004748 0.004991 0.005247 0.005516 0.005799 0.006096 0.006409 0.006737 0.007083 0.007446 0.007828 0.008229 0.008651 0.009095 0.009561 0.010051 0.010567 0.011108 0.011678 0.012277 0.012906 0.013568 0.014264 0.014995 0.015764 0.016572 0.017422 0.018315 0.019254 0.020241 0.021279 0.022370 0.023517 0.024723 0.025991 0.027323 0.028724 0.030197 0.031745 0.033373 0.035084 0.036883 0.038774 0.040762 0.042852 0.045049 0.047358 0.049787 0.052339 0.055023 0.057844 0.060810 0.063927 0.067205 0.070651 0.074273 0.078081 0.082084 0.086293 0.090717 0.095369 0.100258 0.105399 0.110803 0.116484 0.122456 0.128734 0.135335 0.142274 0.149568 0.157237 0.165298 0.173773 0.182683 0.192049 0.201896 0.212247 0.223130 0.234570 0.246596 0.259240 0.272531 0.286504 0.301194 0.316636 0.332871 0.349937 0.367879 0.386741 0.406569 0.427414 0.449328 0.472366 0.496585 0.522045 0.548811 0.576949 0.606530 0.637628 0.670320 0.704688 0.740818 0.778800 0.818730 0.860707 0.904837 0.951229 1.0 1.051271 1.105170 1.161834 1.221402 1.284025 1.349858 1.419067 1.491824 1.568312 1.648721 1.733253 1.822118 1.915540 2.013752 2.117000 2.225540 2.339646 2.459603 2.585709 2.718281 2.857651 3.004166 3.158192 3.320116 3.490342 3.669296 3.857425 4.055199 4.263114 4.481689 4.711470 4.953032 5.206979 5.473947 5.754602 6.049647 6.359819 6.685894 7.028687 7.389056 7.767901 8.166169 8.584858 9.025013 9.487735 9.974182 10.48556 11.02317 11.58834 12.18249 ]
#define Exposure_Speed 1.0 //[0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0 2.25 2.5 2.75 3.0 4.0 5.0]
#define CLOUDS_SHADOWS
#define BASE_FOG_AMOUNT 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0 10.0 20.0 30.0 50.0 100.0 150.0 200.0] Base fog amount amount (does not change the "cloudy" fog)
#define CLOUDY_FOG_AMOUNT 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0]
#define FOG_TOD_MULTIPLIER 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] //Influence of time of day on fog amount
#define FOG_RAIN_MULTIPLIER 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] //Influence of rain on fog amount
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 = -normalize(vec3(0.8,0.8,0.2));
#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));
}
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 = 0.3 * vec3(1.0,0.7,0.85)/4000;
ambientUp += bouncedSun*clamp(-sunVec.y+1.,0.,4.0);
ambientLeft += bouncedSun*clamp(sunVec.x+1.,0.0,4.);
ambientRight += bouncedSun*clamp(-sunVec.x+1.,0.0,4.);
ambientB += bouncedSun*clamp(-sunVec.z+1.,0.0,4.);
ambientF += bouncedSun*clamp(sunVec.z+1.,0.0,4.);
ambientDown += bouncedSun*clamp(sunVec.y+1.,0.0,4.);
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);
#ifndef AUTO_EXPOSURE
exposure = Manual_exposure_value;
rodExposure = clamp(log(Manual_exposure_value*2.0+1.0)-0.1,0.0,2.0);
#endif
float modWT = (worldTime%24000)*1.0;
float fogAmount0 = 1/3000.+FOG_TOD_MULTIPLIER*(1/180.*(clamp(modWT-11000.,0.,2000.0)/2000.+(1.0-clamp(modWT,0.,3000.0)/3000.))*(clamp(modWT-11000.,0.,2000.0)/2000.+(1.0-clamp(modWT,0.,3000.0)/3000.)) + 1/200.*clamp(modWT-13000.,0.,1000.0)/1000.*(1.0-clamp(modWT-23000.,0.,1000.0)/1000.));
VFAmount = CLOUDY_FOG_AMOUNT*(fogAmount0*fogAmount0+FOG_RAIN_MULTIPLIER*1.8/20000.*rainStrength);
fogAmount = BASE_FOG_AMOUNT*(fogAmount0+max(FOG_RAIN_MULTIPLIER*1/15.*rainStrength , FOG_TOD_MULTIPLIER*1/50.*clamp(modWT-13000.,0.,1000.0)/1000.*(1.0-clamp(modWT-23000.,0.,1000.0)/1000.)));
}

View File

@ -0,0 +1,87 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
//Computes volumetric clouds at variable resolution (default 1/4 res)
#define HQ_CLOUDS //Renders detailled clouds for viewport
#define CLOUDS_QUALITY 0.5 //[0.1 0.125 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.9 1.0]
#define TAA
flat varying vec3 sunColor;
flat varying vec3 moonColor;
flat varying vec3 avgAmbient;
flat varying float tempOffsets;
uniform sampler2D depthtex0;
uniform sampler2D noisetex;
// uniform vec3 sunVec;
// uniform vec3 sunPosition;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform int frameCounter;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform vec3 cameraPosition;
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/volumetricClouds.glsl"
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 interleaved_gradientNoise2(){
vec2 coord = gl_FragCoord.xy;
float noise = 1-fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+frameCounter/1.6180339887);
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(1.0-gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float blueNoise2(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter);
}
float R2_dither2(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * (1.0-gl_FragCoord.x) + alpha.y * (1.0-gl_FragCoord.y) + 1.0/1.6180339887 * frameCounter);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* DRAWBUFFERS:0 */
#ifdef VOLUMETRIC_CLOUDS
vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY+0.5);
vec3 fragpos = toScreenSpace(vec3(halfResTC*texelSize,1.0));
// vec4 currentClouds = renderClouds(fragpos,vec3(0.),R2_dither(),sunColor/150.,moonColor/150.,avgAmbient/150., blueNoise());
// gl_FragData[0] = currentClouds;
#else
gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
#endif
}

View File

@ -0,0 +1,21 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define CLOUDS_QUALITY 0.5 //[0.1 0.125 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.9 1.0]
flat varying vec3 sunColor;
flat varying vec3 moonColor;
flat varying vec3 avgAmbient;
flat varying float tempOffsets;
uniform sampler2D colortex4;
uniform int frameCounter;
#include "/lib/util.glsl"
void main() {
tempOffsets = HaltonSeq2(frameCounter%10000);
gl_Position = ftransform();
gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(CLOUDS_QUALITY+0.01,0.0,1.0)*2.0-1.0;
avgAmbient = texelFetch2D(colortex4,ivec2(7,37),0).rgb;
}

100
shaders/world1/final.fsh Normal file
View File

@ -0,0 +1,100 @@
#version 120
//Vignetting, applies bloom, applies exposure and tonemaps the final image
#extension GL_EXT_gpu_shader4 : enable
//#define BICUBIC_UPSCALING //Provides a better interpolation when using a render quality different of 1.0, slower
#define CONTRAST_ADAPTATIVE_SHARPENING
#define SHARPENING 0.35 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define SATURATION 0.00 // Negative values desaturates colors, Positive values saturates color, 0 is no change [-1.0 -0.98 -0.96 -0.94 -0.92 -0.9 -0.88 -0.86 -0.84 -0.82 -0.8 -0.78 -0.76 -0.74 -0.72 -0.7 -0.68 -0.66 -0.64 -0.62 -0.6 -0.58 -0.56 -0.54 -0.52 -0.5 -0.48 -0.46 -0.44 -0.42 -0.4 -0.38 -0.36 -0.34 -0.32 -0.3 -0.28 -0.26 -0.24 -0.22 -0.2 -0.18 -0.16 -0.14 -0.12 -0.1 -0.08 -0.06 -0.04 -0.02 0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 ]
#define CROSSTALK 0.0 // Desaturates bright colors and preserves saturation in darker areas (inverted if negative). Helps avoiding almsost fluorescent colors [-1.0 -0.98 -0.96 -0.94 -0.92 -0.9 -0.88 -0.86 -0.84 -0.82 -0.8 -0.78 -0.76 -0.74 -0.72 -0.7 -0.68 -0.66 -0.64 -0.62 -0.6 -0.58 -0.56 -0.54 -0.52 -0.5 -0.48 -0.46 -0.44 -0.42 -0.4 -0.38 -0.36 -0.34 -0.32 -0.3 -0.28 -0.26 -0.24 -0.22 -0.2 -0.18 -0.16 -0.14 -0.12 -0.1 -0.08 -0.06 -0.04 -0.02 0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 ]
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;
}
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);
//col = -vec3(-lum*CROSSFADING + SATURATION);
gl_FragColor.rgb = clamp(int8Dither(col,texcoord),0.0,1.0);
//gl_FragColor.rgb = vec3(contrast);
}

23
shaders/world1/final.vsh Normal file
View File

@ -0,0 +1,23 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define FinalR 1.0 //[0.0 0.025315 0.051271 0.077884 0.105170 0.133148 0.161834 0.191246 0.221402 0.252322 0.284025 0.316530 0.349858 0.384030 0.419067 0.454991 0.491824 0.529590 0.568312 0.608014 0.648721 0.690458 0.733253 0.777130 0.822118 0.868245 0.915540 0.964032 1.013752 1.064731 1.117000 1.170592 1.225540 1.281880 1.339646 1.398875 1.459603 1.521868 1.585709 1.651167 1.718281 1.787095 1.857651 1.929992 2.004166 2.080216 2.158192 2.238142 2.320116 2.404166 2.490342 2.578701 2.669296 2.762185 2.857425 2.955076 3.055199 3.157857 3.263114 3.371035 3.481689 3.595143 3.711470 3.830741 3.953032 4.078419 4.206979 4.338795 4.473947 4.612521 4.754602 4.900281 5.049647 5.202795 5.359819 5.520819 5.685894 5.855148 6.028687 6.206619 6.389056 6.576110 6.767901 6.964546 7.166169 7.372897 7.584858 7.802185 8.025013 8.253482 8.487735 8.727919 8.974182 9.226680 9.485569 9.751013 10.02317 10.30222 10.58834 10.88170 11.18249 ]
#define FinalG 1.0 //[0.0 0.025315 0.051271 0.077884 0.105170 0.133148 0.161834 0.191246 0.221402 0.252322 0.284025 0.316530 0.349858 0.384030 0.419067 0.454991 0.491824 0.529590 0.568312 0.608014 0.648721 0.690458 0.733253 0.777130 0.822118 0.868245 0.915540 0.964032 1.013752 1.064731 1.117000 1.170592 1.225540 1.281880 1.339646 1.398875 1.459603 1.521868 1.585709 1.651167 1.718281 1.787095 1.857651 1.929992 2.004166 2.080216 2.158192 2.238142 2.320116 2.404166 2.490342 2.578701 2.669296 2.762185 2.857425 2.955076 3.055199 3.157857 3.263114 3.371035 3.481689 3.595143 3.711470 3.830741 3.953032 4.078419 4.206979 4.338795 4.473947 4.612521 4.754602 4.900281 5.049647 5.202795 5.359819 5.520819 5.685894 5.855148 6.028687 6.206619 6.389056 6.576110 6.767901 6.964546 7.166169 7.372897 7.584858 7.802185 8.025013 8.253482 8.487735 8.727919 8.974182 9.226680 9.485569 9.751013 10.02317 10.30222 10.58834 10.88170 11.18249 ]
#define FinalB 1.0 //[0.0 0.025315 0.051271 0.077884 0.105170 0.133148 0.161834 0.191246 0.221402 0.252322 0.284025 0.316530 0.349858 0.384030 0.419067 0.454991 0.491824 0.529590 0.568312 0.608014 0.648721 0.690458 0.733253 0.777130 0.822118 0.868245 0.915540 0.964032 1.013752 1.064731 1.117000 1.170592 1.225540 1.281880 1.339646 1.398875 1.459603 1.521868 1.585709 1.651167 1.718281 1.787095 1.857651 1.929992 2.004166 2.080216 2.158192 2.238142 2.320116 2.404166 2.490342 2.578701 2.669296 2.762185 2.857425 2.955076 3.055199 3.157857 3.263114 3.371035 3.481689 3.595143 3.711470 3.830741 3.953032 4.078419 4.206979 4.338795 4.473947 4.612521 4.754602 4.900281 5.049647 5.202795 5.359819 5.520819 5.685894 5.855148 6.028687 6.206619 6.389056 6.576110 6.767901 6.964546 7.166169 7.372897 7.584858 7.802185 8.025013 8.253482 8.487735 8.727919 8.974182 9.226680 9.485569 9.751013 10.02317 10.30222 10.58834 10.88170 11.18249 ]
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);
}

View File

@ -0,0 +1,411 @@
#extension GL_EXT_gpu_shader4 : enable
#extension GL_ARB_shader_texture_lod : enable
//#define Specular_Reflections // reflections on blocks. REQUIRES A PBR RESOURCEPACK.
//#define POM
#define POM_MAP_RES 128.0 // [16.0 32.0 64.0 128.0 256.0 512.0 1024.0] Increase to improve POM quality
#define POM_DEPTH 0.1 // [0.025 0.05 0.075 0.1 0.125 0.15 0.20 0.25 0.30 0.50 0.75 1.0] //Increase to increase POM strength
#define MAX_ITERATIONS 50 // [5 10 15 20 25 30 40 50 60 70 80 90 100 125 150 200 400] //Improves quality at grazing angles (reduces performance)
#define MAX_DIST 25.0 // [5.0 10.0 15.0 20.0 25.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 125.0 150.0 200.0 400.0] //Increases distance at which POM is calculated
//#define USE_LUMINANCE_AS_HEIGHTMAP //Can generate POM on any texturepack (may look weird in some cases)
#define Texture_MipMap_Bias -1.00 // Uses a another mip level for textures. When reduced will increase texture detail but may induce a lot of shimmering. [-5.00 -4.75 -4.50 -4.25 -4.00 -3.75 -3.50 -3.25 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00]
#define DISABLE_ALPHA_MIPMAPS //Disables mipmaps on the transparency of alpha-tested things like foliage, may cost a few fps in some cases
#define SSAO // screen-space ambient occlusion.
#define texture_ao // ambient occlusion on the texture
#define Puddle_Size 1.0 // [0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5]
#ifdef Specular_Reflections
#define Puddles // yes
#else
// #define Puddles // yes
#endif
// #define Porosity
#ifndef USE_LUMINANCE_AS_HEIGHTMAP
#ifndef MC_NORMAL_MAP
#undef POM
#endif
#endif
#ifdef POM
#define MC_NORMAL_MAP
#endif
const float mincoord = 1.0/4096.0;
const float maxcoord = 1.0-mincoord;
const vec3 intervalMult = vec3(1.0, 1.0, 1.0/POM_DEPTH)/POM_MAP_RES * 1.0;
const float MAX_OCCLUSION_DISTANCE = MAX_DIST;
const float MIX_OCCLUSION_DISTANCE = MAX_DIST*0.9;
const int MAX_OCCLUSION_POINTS = MAX_ITERATIONS;
uniform vec2 texelSize;
uniform int framemod8;
#ifdef POM
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec4 vtexcoord;
#endif
#include "/lib/res_params.glsl"
varying vec4 lmtexcoord;
varying vec4 color;
uniform float far;
varying vec4 normalMat;
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
uniform float wetness;
uniform sampler2D normals;
uniform sampler2D specular;
#endif
#ifdef POM
vec2 dcdx = dFdx(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
vec2 dcdy = dFdy(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
#endif
flat varying int lightningBolt;
uniform sampler2D texture;
uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16
uniform float frameTimeCounter;
uniform int frameCounter;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelView;
uniform mat4 gbufferProjection;
uniform mat4 gbufferModelViewInverse;
uniform vec3 cameraPosition;
uniform float rainStrength;
uniform sampler2D noisetex;//depth
uniform sampler2D depthtex0;
in vec3 test_motionVectors;
varying vec4 materialMask;
flat varying vec4 TESTMASK;
// float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
// }
float interleaved_gradientNoise(){
vec2 alpha = vec2(0.75487765, 0.56984026);
vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
}
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
mat3 inverse(mat3 m) {
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
float b01 = a22 * a11 - a12 * a21;
float b11 = -a22 * a10 + a12 * a20;
float b21 = a21 * a10 - a11 * a20;
float det = a00 * b01 + a01 * b11 + a02 * b21;
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
}
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;
}
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));
}
#ifdef MC_NORMAL_MAP
// vec3 applyBump(mat3 tbnMatrix, vec3 bump){
// float bumpmult = 1.0;
// bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
// return normalize(bump*tbnMatrix);
// }
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
float bumpmult = clamp(puddle_values,0.0,1.0);
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
return normalize(bump*tbnMatrix);
}
#endif
//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));
}
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
vec3 toClipSpace3(vec3 viewSpacePosition) {
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
#ifdef POM
vec4 readNormal(in vec2 coord)
{
return texture2DGradARB(normals,fract(coord)*vtexcoordam.pq+vtexcoordam.st,dcdx,dcdy);
}
vec4 readTexture(in vec2 coord)
{
return texture2DGradARB(texture,fract(coord)*vtexcoordam.pq+vtexcoordam.st,dcdx,dcdy);
}
#endif
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);
}
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.);
// float getPuddleCoverage(vec3 samplePos){
// float puddle = texture2D(noisetex, samplePos.xz/25000).b ;
// return max(puddle,0.0);
// }
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* RENDERTARGETS: 1,7,8,13 */
void main() {
#ifdef BLOCK_ENT
gl_FragData[3] = TESTMASK;
#endif
float phi = 2 * 3.14159265359;
float noise = fract(fract(frameCounter * (1.0 / phi)) + interleaved_gradientNoise() ) ;
vec3 normal = normalMat.xyz;
#ifdef MC_NORMAL_MAP
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
mat3 tbnMatrix = mat3(tangent.x, tangent2.x, normal.x,
tangent.y, tangent2.y, normal.y,
tangent.z, tangent2.z, normal.z);
#endif
vec2 tempOffset=offsets[framemod8];
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
float lightmap = clamp( (lmtexcoord.w-0.66) * 5.0,0.,1.);
float rainfall = 0. ;
float Puddle_shape = 0.;
float puddle_shiny = 1.;
float puddle_normal = 0.;
#ifndef ENTITIES
#ifdef WORLD
#ifdef Puddles
rainfall = rainStrength ;
Puddle_shape = 1.0 - max(texture2D(noisetex, worldpos.xz * (0.015 * Puddle_Size)).b - (1.0-lightmap) ,0.0);
puddle_shiny = clamp( pow(1.0-Puddle_shape,2.0)*2,0.5,1.) ;
puddle_normal = clamp( pow(Puddle_shape,5.0) * 50. ,0.,1.) ;
#endif
#endif
#endif
#ifdef POM
// vec2 tempOffset=offsets[framemod8];
vec2 adjustedTexCoord = fract(vtexcoord.st)*vtexcoordam.pq+vtexcoordam.st;
// vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
vec3 viewVector = normalize(tbnMatrix*fragpos);
float dist = length(fragpos);
gl_FragDepth = gl_FragCoord.z;
#ifdef WORLD
if (dist < MAX_OCCLUSION_DISTANCE) {
if ( viewVector.z < 0.0 && readNormal(vtexcoord.st).a < 0.9999 && readNormal(vtexcoord.st).a > 0.00001) {
vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH;
vec3 coord = vec3(vtexcoord.st, 1.0);
coord += noise*interval;
float sumVec = noise;
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH*readNormal(coord.st).a < coord.p) && coord.p >= 0.0; ++loopCount) { coord = coord+interval; sumVec += 1.0; }
if (coord.t < mincoord) {
if (readTexture(vec2(coord.s,mincoord)).a == 0.0) {
coord.t = mincoord;
discard;
}
}
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
vec3 truePos = fragpos + sumVec*inverse(tbnMatrix)*interval;
// #ifdef Depth_Write_POM
gl_FragDepth = toClipSpace3(truePos).z;
// #endif
}
}
#endif
// color
vec4 data0 = texture2DGradARB(texture, adjustedTexCoord.xy,dcdx,dcdy);
#ifdef DISABLE_ALPHA_MIPMAPS
data0.a = texture2DGradARB(texture, adjustedTexCoord.xy,vec2(0.),vec2(0.0)).a;
#endif
data0.rgb *= color.rgb;
float avgBlockLum = luma(texture2DLod(texture, lmtexcoord.xy,128).rgb*color.rgb);
data0.rgb = clamp(data0.rgb*pow(avgBlockLum,-0.33)*0.85,0.0,1.0);
#ifdef WORLD
if (data0.a > 0.1) data0.a = normalMat.a;
else data0.a = 0.0;
#endif
#ifdef HAND
if (data0.a > 0.1) data0.a = 0.75;
else data0.a = 0.0;
#endif
// normal
#ifdef MC_NORMAL_MAP
vec3 normalTex = texture2DGradARB(normals, adjustedTexCoord.xy, dcdx,dcdy).rgb;
normalTex.xy = normalTex.xy*2.0-1.0;
normalTex.z = clamp(sqrt(1.0 - dot(normalTex.xy, normalTex.xy)),0.0,1.0);
normal = applyBump(tbnMatrix,normalTex, mix(1.0,puddle_normal,rainfall));
#endif
// specular
gl_FragData[2] = texture2DGradARB(specular, adjustedTexCoord.xy,dcdx,dcdy);
// finalize
vec4 data1 = clamp(encode(viewToWorld(normal), lmtexcoord.zw),0.,1.0);
gl_FragData[0] = vec4(encodeVec2(data0.x,data1.x),encodeVec2(data0.y,data1.y),encodeVec2(data0.z,data1.z),encodeVec2(data1.w,data0.w));
gl_FragData[1].a = 0.0;
#else
// specular
vec4 specular = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
vec4 specular_modded = vec4( max(specular.r,puddle_shiny), max(specular.g, puddle_shiny*0.1),specular.ba);
gl_FragData[2].rgba = mix(specular, specular_modded, rainfall);
float porosity = specular.z >= 64.5/255.0 ? 0.0 : (specular.z*255.0/64.0)*0.65;
#ifndef Porosity
porosity = 0.4;
#endif
// normal
#ifdef MC_NORMAL_MAP
vec4 normalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
normalTex.xy = normalTex.xy*2.0-1.0;
normalTex.z = clamp(sqrt(1.0 - dot(normalTex.xy, normalTex.xy)),0.0,1.0) ;
normal = applyBump(tbnMatrix, normalTex.xyz, mix(1.0,puddle_normal, rainfall) );
#endif
// color
vec4 data0 = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) ;
data0.rgb *= mix(color.rgb, vec3(0.0), max((puddle_shiny*porosity)*0.5,0) * rainfall );
float avgBlockLum = luma(texture2DLod(texture, lmtexcoord.xy,128).rgb*color.rgb);
data0.rgb = clamp(data0.rgb*pow(avgBlockLum,-0.33)*0.85,0.0,1.0);
#ifndef ENTITIES
if(TESTMASK.r==255) data0.rgb = vec3(0);
#endif
#ifdef DISABLE_ALPHA_MIPMAPS
data0.a = texture2DLod(texture,lmtexcoord.xy,0).a;
#endif
#ifdef WORLD
if (data0.a > 0.1) data0.a = normalMat.a;
else data0.a = 0.0;
#endif
#ifdef HAND
if (data0.a > 0.1) data0.a = 0.75;
else data0.a = 0.0;
#endif
// finalize
vec4 data1 = clamp(blueNoise()/255.0 + encode(viewToWorld(normal), lmtexcoord.zw),0.0,1.0);
gl_FragData[0] = vec4(encodeVec2(data0.x,data1.x), encodeVec2(data0.y,data1.y), encodeVec2(data0.z,data1.z), encodeVec2(data1.w,data0.w));
#ifdef WORLD
gl_FragData[1].a = 0.0;
#endif
#endif
#ifdef ENTITIES
#ifdef WORLD
gl_FragData[3].xyz = test_motionVectors;
#endif
#endif
// float z = texture2D(depthtex0,texcoord).x;
// vec3 fragpos = toScreenSpace(vec3(texcoord,z));
// gl_FragData[0].rgb *= vec3(1- clamp( pow( length(fragpos)/far, 1), 0, 1)) ;
}

View File

@ -0,0 +1,213 @@
#extension GL_EXT_gpu_shader4 : enable
#include "/lib/res_params.glsl"
#define WAVY_PLANTS
#define WAVY_STRENGTH 1.0 //[0.1 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0]
#define WAVY_SPEED 1.0 //[0.001 0.01 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.0 1.25 1.5 2.0 3.0 4.0]
#define SEPARATE_AO
//#define POM
//#define USE_LUMINANCE_AS_HEIGHTMAP //Can generate POM on any texturepack (may look weird in some cases)
// #define RTAO // I recommend turning ambientOcclusionLevel to zero with this on. like ssao, but rt, nicer, noiser, and slower. SSAO will turn OFF when this is ON
#define indirect_effect 1 // Choose what effect is applied to indirect light. [0 1 2 3]
#define Variable_Penumbra_Shadows //Makes the shadows more blurry the more distant they are to objects (costs fps)
#define mob_SSS
#ifndef USE_LUMINANCE_AS_HEIGHTMAP
#ifndef MC_NORMAL_MAP
#undef POM
#endif
#endif
#ifdef POM
#define MC_NORMAL_MAP
#endif
/*
!! 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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#ifdef POM
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec4 vtexcoord;
#endif
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
attribute vec4 at_tangent;
#endif
out vec3 test_motionVectors;
in vec3 at_velocity;
uniform float frameTimeCounter;
const float PI48 = 150.796447372*WAVY_SPEED;
float pi2wt = PI48*frameTimeCounter;
attribute vec4 mc_Entity;
uniform int blockEntityId;
uniform int entityId;
varying vec4 materialMask;
flat varying vec4 TESTMASK;
flat varying int lightningBolt;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
attribute vec4 mc_midTexCoord;
uniform vec3 cameraPosition;
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.);
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
vec2 calcWave(in vec3 pos) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec2 ret = (sin(pi2wt*vec2(0.0063,0.0015)*4. - pos.xz + pos.y*0.05)+0.1)*magnitude;
return ret;
}
vec3 calcMovePlants(in vec3 pos) {
vec2 move1 = calcWave(pos );
float move1y = -length(move1);
return vec3(move1.x,move1y,move1.y)*5.*WAVY_STRENGTH;
}
vec3 calcWaveLeaves(in vec3 pos, in float fm, in float mm, in float ma, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec3 ret = (sin(pi2wt*vec3(0.0063,0.0224,0.0015)*1.5 - pos))*magnitude;
return ret;
}
vec3 calcMoveLeaves(in vec3 pos, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5, in vec3 amp1, in vec3 amp2) {
vec3 move1 = calcWaveLeaves(pos , 0.0054, 0.0400, 0.0400, 0.0127, 0.0089, 0.0114, 0.0063, 0.0224, 0.0015) * amp1;
return move1*5.*WAVY_STRENGTH;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
TESTMASK = vec4(normalize(gl_NormalMatrix * gl_Normal), 1.0);
TESTMASK.r = blockEntityId == 222 ? 255 : TESTMASK.r;
#ifdef ENTITIES
test_motionVectors = at_velocity;
#endif
#ifdef POM
vec2 midcoord = (gl_TextureMatrix[0] * mc_midTexCoord).st;
vec2 texcoordminusmid = lmtexcoord.xy-midcoord;
vtexcoordam.pq = abs(texcoordminusmid)*2;
vtexcoordam.st = min(lmtexcoord.xy,midcoord-texcoordminusmid);
vtexcoord.xy = sign(texcoordminusmid)*0.5+0.5;
#endif
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
color = gl_Color;
bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t;
#ifdef MC_NORMAL_MAP
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
#endif
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal), 1.0);
#ifdef ENTITIES
#ifdef mob_SSS
#ifdef Variable_Penumbra_Shadows
normalMat.a = entityId == 1100 ? 1.0 : normalMat.a;
normalMat.a = entityId == 1200 ? 1.0 : normalMat.a;
normalMat.a = entityId == 1400 ? 1.0 : normalMat.a;
#endif
#endif
gl_Position = ftransform();
#endif
#ifdef WORLD
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),mc_Entity.x == 10004 || mc_Entity.x == 10003 ? 0.5 : mc_Entity.x == 10001 ? 0.6 : 1.0);
normalMat.a = mc_Entity.x == 10006 ? 0.6 : normalMat.a;
normalMat.a = mc_Entity.x == 10007 ? 0.55 : normalMat.a;
normalMat.a = mc_Entity.x == 10005 ? 0.8 : normalMat.a;
normalMat.a = mc_Entity.x == 99 ? 0.65 : normalMat.a;
#ifdef WAVY_PLANTS
if ((mc_Entity.x == 10001 && istopv) && abs(position.z) < 64.0) {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
worldpos.xyz += calcMovePlants(worldpos.xyz)*lmtexcoord.w - cameraPosition;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
}
if (mc_Entity.x == 10003 && abs(position.z) < 64.0) {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
worldpos.xyz += calcMoveLeaves(worldpos.xyz, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))*lmtexcoord.w - cameraPosition;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
}
#endif
if (mc_Entity.x == 100 ){
color.rgb = normalize(color.rgb)*sqrt(3.0);
normalMat.a = 0.9;
}
gl_Position = toClipSpace3(position);
if (color.a < 0.3) color.a = 1.0;
#ifdef SEPARATE_AO
#if indirect_effect == 1 || indirect_effect == 0
lmtexcoord.z *= sqrt(color.a);
lmtexcoord.w *= color.a;
#endif
#else
color.rgb *= color.a;
#endif
#endif
#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
}

View File

@ -0,0 +1,624 @@
// #version 120
#extension GL_EXT_gpu_shader4 : enable
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
varying vec3 binormal;
uniform sampler2D normals;
varying vec3 tangent;
varying vec4 tangent_other;
varying vec3 viewVector;
varying float dist;
#include "/lib/res_params.glsl"
#define CLOUDS_SHADOWS
#define VL_CLOUDS_SHADOWS // Casts shadows from clouds on VL (slow)
#define SCREENSPACE_REFLECTIONS //can be really expensive at high resolutions/render quality, especially on ice
#define SSR_STEPS 30 //[10 15 20 25 30 35 40 50 100 200 400]
#define SUN_MICROFACET_SPECULAR // If enabled will use realistic rough microfacet model, else will just reflect the sun. No performance impact.
#define USE_QUARTER_RES_DEPTH // Uses a quarter resolution depth buffer to raymarch screen space reflections, improves performance but may introduce artifacts
#define saturate(x) clamp(x,0.0,1.0)
#define Dirt_Amount 0.14 //How much dirt there is in water [0.0 0.04 0.08 0.12 0.16 0.2 0.24 0.28 0.32 0.36 0.4 0.44 0.48 0.52 0.56 0.6 0.64 0.68 0.72 0.76 0.8 0.84 0.88 0.92 0.96 1.0 1.04 1.08 1.12 1.16 1.2 1.24 1.28 1.32 1.36 1.4 1.44 1.48 1.52 1.56 1.6 1.64 1.68 1.72 1.76 1.8 1.84 1.88 1.92 1.96 2.0 ]
#define Dirt_Scatter_R 0.6 //How much dirt diffuses red [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Dirt_Scatter_G 0.6 //How much dirt diffuses green [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Dirt_Scatter_B 0.6 //How much dirt diffuses blue [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Dirt_Absorb_R 1.65 //How much dirt absorbs red [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
#define Dirt_Absorb_G 1.85 //How much dirt absorbs green [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
#define Dirt_Absorb_B 2.05 //How much dirt absorbs blue [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
#define Water_Absorb_R 0.2629 //How much water absorbs red [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
#define Water_Absorb_G 0.0565 //How much water absorbs green [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
#define Water_Absorb_B 0.01011 //How much water absorbs blue [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
#define Texture_MipMap_Bias -1.00 // Uses a another mip level for textures. When reduced will increase texture detail but may induce a lot of shimmering. [-5.00 -4.75 -4.50 -4.25 -4.00 -3.75 -3.50 -3.25 -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00]
#define ambient_colortype 0 // Toggle which method you want to change the color of ambient light with. [0 1]
#define ambient_temp 9000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 15000 50000]
#define AmbientLight_R 0.91 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define AmbientLight_G 0.86 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define AmbientLight_B 1.0 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
#define MIN_LIGHT_AMOUNT 1.0 //[0.0 0.5 1.0 1.5 2.0 3.0 4.0 5.0]
//#define Vanilla_like_water // vanilla water texture along with shader water stuff
uniform sampler2D texture;
uniform sampler2D noisetex;
uniform sampler2DShadow shadow;
uniform sampler2D gaux2;
uniform sampler2D gaux1;
uniform sampler2D depthtex1;
uniform vec4 lightCol;
uniform float nightVision;
uniform vec3 sunVec;
uniform float frameTimeCounter;
uniform float lightSign;
uniform float near;
uniform float far;
uniform float moonIntensity;
uniform float sunIntensity;
uniform vec3 sunColor;
uniform vec3 nsunColor;
uniform vec3 upVec;
uniform float sunElevation;
uniform float fogAmount;
uniform vec2 texelSize;
uniform float rainStrength;
uniform float skyIntensityNight;
uniform float skyIntensity;
flat varying vec3 WsunVec;
uniform mat4 gbufferPreviousModelView;
uniform vec3 previousCameraPosition;
uniform int framemod8;
uniform sampler2D specular;
uniform int frameCounter;
uniform int isEyeInWater;
#include "lib/Shadow_Params.glsl"
#include "lib/color_transforms.glsl"
#include "lib/projections.glsl"
#include "lib/sky_gradient.glsl"
#include "lib/waterBump.glsl"
#include "lib/clouds.glsl"
#include "lib/stars.glsl"
#include "lib/volumetricClouds.glsl"
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.);
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
return noise;
}
vec3 srgbToLinear2(vec3 srgb){
return mix(
srgb / 12.92,
pow(.947867 * srgb + .0521327, vec3(2.4) ),
step( .04045, srgb )
);
}
vec3 blackbody2(float Temp)
{
float t = pow(Temp, -1.5);
float lt = log(Temp);
vec3 col = vec3(0.0);
col.x = 220000.0 * t + 0.58039215686;
col.y = 0.39231372549 * lt - 2.44549019608;
col.y = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : col.y;
col.z = 0.76078431372 * lt - 5.68078431373;
col = clamp(col,0.0,1.0);
col = Temp < 1000. ? col * Temp * 0.001 : col;
return srgbToLinear2(col);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec3 nvec3(vec4 pos){
return pos.xyz/pos.w;
}
vec4 nvec4(vec3 pos){
return vec4(pos.xyz, 1.0);
}
vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel, bool inwater){
float quality = mix(15,SSR_STEPS,fresnel);
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 = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
float minZ = clipPosition.z;
float maxZ = spos.z+stepv.z*0.5;
spos.xy += offsets[framemod8]*texelSize*0.5/RENDER_SCALE;
for (int i = 0; i <= int(quality); i++) {
#ifdef USE_QUARTER_RES_DEPTH
// decode depth buffer
float sp = sqrt(texelFetch2D(gaux1,ivec2(spos.xy/texelSize/4),0).w/65000.0);
sp = invLinZ(sp);
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)){
return vec3(spos.xy/RENDER_SCALE,sp);
}
spos += stepv;
#else
float sp = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).r;
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)){
return vec3(spos.xy/RENDER_SCALE,sp);
}
spos += stepv;
#endif
//small bias
minZ = maxZ-0.00004/ld(spos.z);
if(inwater) minZ = maxZ-0.0004/ld(spos.z);
maxZ += stepv.z;
}
return vec3(1.1);
}
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : pi - a;
}
float bayer2(vec2 a){
a = floor(a);
return fract(dot(a,vec2(0.5,a.y*0.75)));
}
float cdist(vec2 coord) {
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
}
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
#define PW_POINTS 1 //[2 4 6 8 16 32]
#define bayer4(a) (bayer2( .5*(a))*.25+bayer2(a))
#define bayer8(a) (bayer4( .5*(a))*.25+bayer2(a))
#define bayer16(a) (bayer8( .5*(a))*.25+bayer2(a))
#define bayer32(a) (bayer16(.5*(a))*.25+bayer2(a))
#define bayer64(a) (bayer32(.5*(a))*.25+bayer2(a))
#define bayer128(a) fract(bayer64(.5*(a))*.25+bayer2(a))
vec3 getParallaxDisplacement(vec3 posxz, float iswater,float bumpmult,vec3 viewVec) {
float waveZ = mix(20.0,0.25,iswater);
float waveM = mix(0.0,4.0,iswater);
vec3 parallaxPos = posxz;
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
float waterHeight = getWaterHeightmap(posxz.xz, waveM, waveZ, iswater) ;
parallaxPos.xz += waterHeight * vec;
return parallaxPos;
}
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
{
float alpha = (sampleNumber+jitter)/nb;
float angle = jitter*6.28 + alpha * nbRot * 6.28;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*sqrt(alpha);
}
//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);
}
vec4 hash44(vec4 p4)
{
p4 = fract(p4 * vec4(.1031, .1030, .0973, .1099));
p4 += dot(p4, p4.wzxy+33.33);
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
}
vec3 TangentToWorld(vec3 N, vec3 H)
{
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));
}
float GGX (vec3 n, vec3 v, vec3 l, float r, float F0) {
r*=r;r*=r;
vec3 h = l + v;
float hn = inversesqrt(dot(h, h));
float dotLH = clamp(dot(h,l)*hn,0.,1.);
float dotNH = clamp(dot(h,n)*hn,0.,1.);
float dotNL = clamp(dot(n,l),0.,1.);
float dotNHsq = dotNH*dotNH;
float denom = dotNHsq * r - dotNHsq + 1.;
float D = r / (3.141592653589793 * denom * denom);
float F = F0 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float k2 = .25 * r;
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
}
vec3 applyBump(mat3 tbnMatrix, vec3 bump){
float bumpmult = 1.0;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
return normalize(bump*tbnMatrix);
}
#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 R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
vec3 viewToWorld(vec3 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;
}
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));
}
float square(float x){
return x*x;
}
float g(float NdotL, float roughness){
float alpha = square(max(roughness, 0.02));
return 2.0 * NdotL / (NdotL + sqrt(square(alpha) + (1.0 - square(alpha)) * square(NdotL)));
}
float gSimple(float dp, float roughness){
float k = roughness + 1;
k *= k/8.0;
return dp / (dp * (1.0-k) + k);
}
vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
float roughness = r + 1.0/255.0; // when roughness is zero it fucks up
float alpha = square(roughness);
vec3 h = normalize(l + v);
float dotLH = clamp(dot(h,l),0.,1.);
float dotNH = clamp(dot(h,n),0.,1.);
float dotNL = clamp(dot(n,l),0.,1.);
float dotNV = clamp(dot(n,v),0.,1.);
float dotVH = clamp(dot(h,v),0.,1.);
float D = alpha / (3.141592653589793*square(square(dotNH) * (alpha - 1.0) + 1.0));
float G = gSimple(dotNV, roughness) * gSimple(dotNL, roughness);
vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH);
return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* RENDERTARGETS:2,7,1,11 */
void main() {
if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize.y < RENDER_SCALE.y ) {
vec2 tempOffset=offsets[framemod8];
float iswater = normalMat.w;
vec3 fragC = gl_FragCoord.xyz*vec3(texelSize,1.0);
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
float avgBlockLum = luma(texture2DLod(texture, lmtexcoord.xy,128).rgb*color.rgb);
gl_FragData[0].rgb = clamp((gl_FragData[0].rgb)*pow(avgBlockLum,-0.33)*0.85,0.0,1.0);
vec3 albedo = toLinear(gl_FragData[0].rgb);
#ifndef Vanilla_like_water
if (iswater > 0.4) {
albedo = vec3(0.42,0.6,0.7);
gl_FragData[0] = vec4(0.42,0.6,0.7,0.7);
}
if (iswater > 0.9) {
gl_FragData[0] = vec4(0.0);
}
#endif
#ifdef Vanilla_like_water
if (iswater > 0.5) {
gl_FragData[0].a = luma(albedo.rgb);
albedo = color.rgb;
}
#endif
vec2 specularstuff = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
vec3 normal = normalMat.xyz;
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z);
if (iswater > 0.4){
float bumpmult = 1.;
if (iswater > 0.9)
bumpmult = 1.;
float parallaxMult = bumpmult;
vec3 posxz = p3+cameraPosition;
posxz.xz-=posxz.y;
if (iswater < 0.9)
posxz.xz *= 3.0;
vec3 bump;
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos));
bump = normalize(getWaveHeight(posxz.xz,iswater));
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
normal = normalize(bump * tbnMatrix);
}else {
vec3 normalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgb;
normalTex.xy = normalTex.xy*2.0-1.0;
normalTex.z = clamp(sqrt(1.0 - dot(normalTex.xy, normalTex.xy)),0.0,1.0);
normal = applyBump(tbnMatrix,normalTex);
}
vec4 data0 = vec4(1);
vec4 data1 = clamp( encode(viewToWorld(normal), lmtexcoord.zw),0.0,1.0);
gl_FragData[3] = vec4(encodeVec2(data0.x,data1.x), encodeVec2(data0.y,data1.y), encodeVec2(data0.z,data1.z), encodeVec2(data1.w,data0.w));
// gl_FragData[3].a = 0.0;
float NdotL = lightSign*dot(normal,sunVec);
float NdotU = dot(upVec,normal);
float diffuseSun = clamp(NdotL,0.0f,1.0f);
vec3 direct = texelFetch2D(gaux1,ivec2(6,37),0).rgb/3.1415;
float shading = 1.0;
float cloudShadow = 1.0;
//compute shadows only if not backface
if (diffuseSun > 0.001) {
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
//apply distortion
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
//do shadows only if on shadow map
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
float distortThresh = (sqrt(1.0-diffuseSun*diffuseSun)/diffuseSun+0.7)/distortFactor;
float diffthresh = distortThresh/6000.0*threshMul;
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5,0.5,0.5);
shading = 0.0;
float noise = blueNoise();
float rdMul = 4.0/shadowMapResolution;
for(int i = 0; i < 9; i++){
vec2 offsetS = tapLocation(i,9, 1.618,noise,0.0);
float weight = 1.0+(i+noise)*rdMul/9.0*shadowMapResolution;
shading += shadow2D(shadow,vec3(projectedShadowPosition + vec3(rdMul*offsetS,-diffthresh*weight))).x/9.0;
}
direct *= shading;
}
#ifdef VOLUMETRIC_CLOUDS
#ifdef CLOUDS_SHADOWS
vec3 campos = (p3 + cameraPosition)-319 ;
// get cloud position
vec3 cloudPos = campos*Cloud_Size + WsunVec/abs(WsunVec.y) * (2250 - campos.y*Cloud_Size);
// get the cloud density and apply it
cloudShadow = getCloudDensity(cloudPos, 1);
// cloudShadow = exp(-cloudShadow*sqrt(cloudDensity)*25);
cloudShadow = clamp(exp(-cloudShadow*10),0,1);
// make these turn to zero when occluded by the cloud shadow
direct *= cloudShadow;
#endif
#endif
}
#if ambient_colortype == 0
vec3 colortype = blackbody2(ambient_temp);
#else
vec3 colortype = vec3(AmbientLight_R,AmbientLight_G,AmbientLight_B) ;
#endif
vec3 ambientLight = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb * colortype;
direct *= (iswater > 0.9 ? 0.2: 1.0)*diffuseSun*lmtexcoord.w;
vec3 diffuseLight = (direct*1.5) + (ambientLight*2.5);
vec3 color = diffuseLight * albedo * 8./150./3.0 ;
if (iswater > 0.0){
float roughness = iswater > 0.4 ? 0.0 : specularstuff.r > 0.0 ? pow(1.0-specularstuff.r,2.0) : 0.05*(1.0-gl_FragData[0].a );
float f0 = iswater > 0.4 ? 0.02 : specularstuff.g;
if(f0 > 0.9) f0 = 0.02;
float F0 = f0;
// float f0 = iswater > 0.1 ? 0.02 : 0.05*(1.0-gl_FragData[0].a);
// float roughness = 0.02;
// float F0 = f0;
vec3 reflectedVector = reflect(normalize(fragpos), normal);
float normalDotEye = dot(normal, normalize(fragpos));
float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 5.0);
float fresnel2 = pow(clamp(1.0 + normalDotEye,0.0,1.0), 1.0);
// gl_FragData[3].a = fresnel2;
// snells window looking thing
if(isEyeInWater == 1 && iswater > 0.99) fresnel = clamp(pow(1.66 + normalDotEye,25),0.02,1.0);
fresnel = mix(F0,1.0,fresnel);
// adjust the amount of sunlight based on f0. max f0 should
color = mix(color, (ambientLight*2.5) * albedo * 8./150./3.0 , mix(1.0-roughness, F0, 0.5));
vec3 wrefl = mat3(gbufferModelViewInverse)*reflectedVector;
vec3 sky_c = mix(skyCloudsFromTex(wrefl,gaux1).rgb,texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb*0.5,isEyeInWater);
sky_c.rgb *= lmtexcoord.w*lmtexcoord.w*255*255/240./240./150.*8./3.;
vec4 reflection = vec4(sky_c.rgb,0.);
#ifdef SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector,fragpos.xyz, blueNoise(), fresnel, isEyeInWater == 0);
if (rtPos.z <1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + 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) {
reflection.a = 1.0;
reflection.rgb = texture2D(gaux2,previousPosition.xy).rgb;
}
}
#endif
if(isEyeInWater ==1 ) sky_c.rgb = color.rgb*lmtexcoord.y;
reflection.rgb = mix(sky_c.rgb, reflection.rgb, reflection.a);
#ifdef SUN_MICROFACET_SPECULAR
vec3 sunSpec = GGX2(normal, -normalize(fragpos), lightSign*sunVec ,roughness, vec3(f0)) * direct;
// vec3 sunSpec = GGX(normal,-normalize(fragpos), lightSign*sunVec, rainStrength*0.2+roughness+0.05+clamp(-lightSign*0.15,0.0,1.0), f0) * texelFetch2D(gaux1,ivec2(6,37),0).rgb*8./3./150.0/3.1415 * (1.0-rainStrength*0.9);
#else
vec3 sunSpec = drawSun(dot(lightSign * sunVec,reflectedVector), 0.0,texelFetch2D(gaux1,ivec2(6,37),0).rgb,vec3(0.0))*8./3./150.0*fresnel/3.1415 * (1.0-rainStrength*0.9);
#endif
// vec3 albedoTint = F0 >= (230.0/255.0) ? clamp(color.rgb + fresnel,0.0,1.0) : vec3(1.0);
// reflection.rgb *= albedoTint;
// sunSpec.rgb *= albedoTint;
sunSpec *= max(cloudShadow-0.5,0.0);
vec3 reflected = reflection.rgb*fresnel+shading*sunSpec;
float alpha0 = gl_FragData[0].a;
vec3 np3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
float borderfog = clamp( pow( length(fragpos)/far, 5), 0, 1);
vec3 bordercolor = skyFromTex(np3,colortex4)/150.;
vec3 finalborderfog = clamp(fp10Dither(bordercolor*8./3.,triangularize(R2_dither())),0.0,65000.);
// alpha0 = mix(0.0, alpha0, borderfog);
//correct alpha channel with fresnel
gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel;
gl_FragData[0].rgb = clamp(color/gl_FragData[0].a*alpha0*(1.0-fresnel)*0.1+reflected/gl_FragData[0].a*0.1,0.0,65100.0);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.);
}
else
gl_FragData[0].rgb = color*.1;
gl_FragData[1] = vec4(albedo,iswater);
// vec3 np3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
// float borderfog = clamp( pow( length(fragpos)/far, 5), 0, 1);
// vec3 bordercolor = skyFromTex(np3,colortex4)/150.;
// vec3 finalborderfog = clamp(fp10Dither(bordercolor*8./3.,triangularize(R2_dither())),0.0,65000.);
}
}

View File

@ -0,0 +1,112 @@
// #version 120
#extension GL_EXT_gpu_shader4 : enable
#include "/lib/res_params.glsl"
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
varying vec3 binormal;
varying vec3 tangent;
varying float dist;
uniform mat4 gbufferModelViewInverse;
varying vec3 viewVector;
attribute vec4 at_tangent;
attribute vec4 mc_Entity;
uniform sampler2D colortex4;
uniform vec3 sunPosition;
flat varying vec3 WsunVec;
uniform float sunElevation;
varying vec4 tangent_other;
#define SHADOW_MAP_BIAS 0.8
flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon)
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.);
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
gl_Position = toClipSpace3(position);
color = gl_Color;
float mat = 0.0;
if(mc_Entity.x == 8.0 || mc_Entity.x == 9.0) {
mat = 1.0;
gl_Position.z -= 1e-4;
}
if (mc_Entity.x == 10002) mat = 0.01;
if (mc_Entity.x == 72) mat = 0.5;
// if (mc_Entity.x == 8) mat = 0.1;
normalMat = vec4(normalize( gl_NormalMatrix*gl_Normal),mat);
tangent_other = vec4(normalize(gl_NormalMatrix * at_tangent.rgb),normalMat.a);
tangent = normalize( gl_NormalMatrix *at_tangent.rgb);
binormal = normalize(cross(tangent.rgb,normalMat.xyz)*at_tangent.w);
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normalMat.x,
tangent.y, binormal.y, normalMat.y,
tangent.z, binormal.z, normalMat.z);
dist = length(gl_ModelViewMatrix * gl_Vertex);
viewVector = ( gl_ModelViewMatrix * gl_Vertex).xyz;
viewVector = normalize(tbnMatrix * viewVector);
#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
vec3 sc = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2-1.;
lightCol.rgb = sc;
WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) *sunPosition);
}

View File

@ -0,0 +1,100 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
uniform sampler2D texture;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float sunElevation;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#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;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : 3.14159265359 - a;
}
#define SHADOW_MAP_BIAS 0.8
float calcDistort(vec2 worlpos){
vec2 pos = worlpos * 1.165;
vec2 posSQ = pos*pos;
float distb = pow(posSQ.x*posSQ.x*posSQ.x + posSQ.y*posSQ.y*posSQ.y, 1.0 / 6.0);
return 1.08695652/((1.0 - SHADOW_MAP_BIAS) + distb * SHADOW_MAP_BIAS);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
gl_FragData[0] = texture2D(texture, lmtexcoord.xy);
vec3 albedo = toLinear(gl_FragData[0].rgb*color.rgb);
vec3 normal = normalMat.xyz;
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0));
float NdotL = lightCol.a*dot(normal,sunVec);
float diffuseSun = clamp(NdotL,0.0f,1.0f);
vec3 direct = lightCol.rgb;
direct *= (diffuseSun*lmtexcoord.w)*10.;
float torch_lightmap = ((lmtexcoord.z*lmtexcoord.z)*(lmtexcoord.z*lmtexcoord.z))*(lmtexcoord.z*20.)+lmtexcoord.z;
vec3 ambient = (lightCol.a*sunElevation)*(-NdotL*0.45+0.9)*lightCol.rgb*0.6 + (1.2*skyIntensity)*vec3(0.65,0.7,1.)*30. + skyIntensityNight*vec3(0.09,0.1,0.15)/1.5;
vec3 diffuseLight = (lmtexcoord.w)*ambient + vec3(1.,0.4,0.1)*torch_lightmap*0.08*1.0 + 0.0006;
vec3 col = dot(diffuseLight,vec3(1.0/3))*albedo;
gl_FragData[0].rgb = col*color.a;
gl_FragData[0].a = 0.0;
}

View File

@ -0,0 +1,53 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
attribute vec4 at_tangent;
#endif
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord*lmcoord;
gl_Position = ftransform();
color = gl_Color;
#ifdef MC_NORMAL_MAP
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
#endif
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),1.0);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,4 @@
#version 120
#define WORLD
#include "gbuffers_all_solid.fsh"

View File

@ -0,0 +1,4 @@
#version 120
#define WORLD
#include "gbuffers_all_solid.vsh"

View File

@ -0,0 +1,90 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#define SHADOW_MAP_BIAS 0.8
uniform sampler2D texture;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec3 upVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float sunElevation;
uniform float rainStrength;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#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;
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : 3.14159265359 - a;
}
#define SHADOW_MAP_BIAS 0.8
float calcDistort(vec2 worlpos){
vec2 pos = worlpos * 1.165;
vec2 posSQ = pos*pos;
float distb = pow(posSQ.x*posSQ.x*posSQ.x + posSQ.y*posSQ.y*posSQ.y, 1.0 / 6.0);
return 1.08695652/((1.0 - SHADOW_MAP_BIAS) + distb * SHADOW_MAP_BIAS);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
gl_FragData[0].a = 1.0;
vec3 albedo = toLinear(gl_FragData[0].rgb);
float torch_lightmap = lmtexcoord.z;
vec3 diffuseLight = torch_lightmap*vec3(20.,30.,50.)*2./10. ;
vec3 color = diffuseLight*albedo;
gl_FragData[0].rgb = color*0.01;
}

View File

@ -0,0 +1,54 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
attribute vec4 at_tangent;
#endif
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
gl_Position = ftransform();
color = gl_Color;
#ifdef MC_NORMAL_MAP
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
#endif
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),1.0);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,5 @@
#version 120
#define BLOCK_ENT
#define WORLD
#include "gbuffers_all_solid.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define BLOCK_ENT
#define WORLD
#include "gbuffers_all_solid.vsh"

View File

@ -0,0 +1,9 @@
#version 120
/* DRAWBUFFERS:3 */
void main() {
}

View File

@ -0,0 +1,14 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position.w = -1.0;
}

View File

@ -0,0 +1,116 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define PCF
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
uniform sampler2D texture;
uniform sampler2D gaux1;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec3 upVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float sunElevation;
uniform float rainStrength;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#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;
}
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
return noise;
}
#ifdef PCF
const vec2 shadowOffsets[4] = vec2[4](vec2( 0.1250, 0.0000 ),
vec2( -0.1768, -0.1768 ),
vec2( -0.0000, 0.3750 ),
vec2( 0.3536, -0.3536 )
);
#endif
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : 3.14159265359 - a;
}
vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot)
{
float startJitter = (spinAngle/6.28);
float alpha = sqrt(sampleNumber + startJitter/nb );
float angle = alpha * (nbRot * 6.28) + spinAngle*2.;
float ssR = alpha;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
uniform int framemod8;
uniform int framecouter;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
vec2 tempOffset=offsets[framemod8];
if (gl_FragData[0].a>0.1){
vec3 albedo = toLinear(gl_FragData[0].rgb);
vec3 normal = normalMat.xyz;
vec3 ambient = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb;
vec3 diffuseLight = ambient;
gl_FragData[0].rgb = diffuseLight*albedo*8./1500.*0.1;
}
}

View File

@ -0,0 +1,54 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
attribute vec4 at_tangent;
#endif
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
gl_Position = ftransform();
color = gl_Color;
#ifdef MC_NORMAL_MAP
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
#endif
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),1.0);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,5 @@
#version 120
#define WORLD
#define ENTITIES
#include "gbuffers_all_solid.fsh"

View File

@ -0,0 +1,6 @@
#version 120
// #define WORLD
#define ENTITIES
#include "gbuffers_all_solid.vsh"

View File

@ -0,0 +1,4 @@
#version 120
#define HAND
#include "gbuffers_all_solid.fsh"

View File

@ -0,0 +1,5 @@
#version 120
#define WORLD
#define HAND
#include "gbuffers_all_solid.vsh"

View File

@ -0,0 +1,116 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define PCF
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
uniform sampler2D texture;
uniform sampler2D gaux1;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec3 upVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float sunElevation;
uniform float rainStrength;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#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;
}
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
return noise;
}
#ifdef PCF
const vec2 shadowOffsets[4] = vec2[4](vec2( 0.1250, 0.0000 ),
vec2( -0.1768, -0.1768 ),
vec2( -0.0000, 0.3750 ),
vec2( 0.3536, -0.3536 )
);
#endif
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : 3.14159265359 - a;
}
vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot)
{
float startJitter = (spinAngle/6.28);
float alpha = sqrt(sampleNumber + startJitter/nb );
float angle = alpha * (nbRot * 6.28) + spinAngle*2.;
float ssR = alpha;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
uniform int framemod8;
uniform int framecouter;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
vec2 tempOffset=offsets[framemod8];
if (gl_FragData[0].a>0.1){
vec3 albedo = toLinear(gl_FragData[0].rgb);
vec3 normal = normalMat.xyz;
vec3 ambient = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb;
vec3 diffuseLight = ambient;
gl_FragData[0].rgb = diffuseLight*albedo*8./1500.*0.1;
}
}

View File

@ -0,0 +1,56 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
attribute vec4 at_tangent;
#endif
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
gl_Position = ftransform();
color = gl_Color;
#ifdef MC_NORMAL_MAP
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
#endif
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),1.0);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,9 @@
#version 120
/* DRAWBUFFERS:3 */
void main() {
}

View File

@ -0,0 +1,14 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position.w = -1.0;
}

View File

@ -0,0 +1,24 @@
#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 !!
*/
/* 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;
}

View File

@ -0,0 +1,36 @@
#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
}

View File

@ -0,0 +1,32 @@
#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 !!
*/
varying vec4 color;
varying vec2 texcoord;
uniform sampler2D texture;
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
vec4 albedo = texture2D(texture, texcoord);
albedo *= color;
albedo.rgb = toLinear(albedo.rgb)*0.33;
/* DRAWBUFFERS:2 */
gl_FragData[0] = albedo;
}

View File

@ -0,0 +1,36 @@
#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_MultiTexCoord0).xy;
color = gl_Color;
gl_Position = ftransform();
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,4 @@
#version 120
#define WORLD
#include "gbuffers_all_solid.fsh"

View File

@ -0,0 +1,4 @@
#version 120
#define WORLD
#include "gbuffers_all_solid.vsh"

View File

@ -0,0 +1,116 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define PCF
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
uniform sampler2D texture;
uniform sampler2D gaux1;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec3 upVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float sunElevation;
uniform float rainStrength;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#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;
}
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
return noise;
}
#ifdef PCF
const vec2 shadowOffsets[4] = vec2[4](vec2( 0.1250, 0.0000 ),
vec2( -0.1768, -0.1768 ),
vec2( -0.0000, 0.3750 ),
vec2( 0.3536, -0.3536 )
);
#endif
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : 3.14159265359 - a;
}
vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot)
{
float startJitter = (spinAngle/6.28);
float alpha = sqrt(sampleNumber + startJitter/nb );
float angle = alpha * (nbRot * 6.28) + spinAngle*2.;
float ssR = alpha;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
uniform int framemod8;
uniform int framecouter;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
vec2 tempOffset=offsets[framemod8];
if (gl_FragData[0].a>0.1){
vec3 albedo = toLinear(gl_FragData[0].rgb);
vec3 normal = normalMat.xyz;
vec3 ambient = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb;
vec3 diffuseLight = ambient;
gl_FragData[0].rgb = diffuseLight*albedo*8./1500.*0.1;
}
}

View File

@ -0,0 +1,74 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define TAA
#define WAVY_PLANTS
#define WAVY_STRENGTH 1.0 //[0.1 0.25 0.5 0.75 1.0 1.25 1.5 1.75 2.0]
#define WAVY_SPEED 1.0 //[0.001 0.01 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.0 1.25 1.5 2.0 3.0 4.0]
#define SEPARATE_AO
//#define POM
//#define USE_LUMINANCE_AS_HEIGHTMAP //Can generate POM on any texturepack (may look weird in some cases)
#ifndef USE_LUMINANCE_AS_HEIGHTMAP
#ifndef MC_NORMAL_MAP
#undef POM
#endif
#endif
#ifdef POM
#define MC_NORMAL_MAP
#endif
/*
!! 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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
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.);
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
color = gl_Color;
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),0.0);
gl_Position = toClipSpace3(position);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,116 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define PCF
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
uniform sampler2D texture;
uniform sampler2D gaux1;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec3 upVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float sunElevation;
uniform float rainStrength;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#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;
}
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
return noise;
}
#ifdef PCF
const vec2 shadowOffsets[4] = vec2[4](vec2( 0.1250, 0.0000 ),
vec2( -0.1768, -0.1768 ),
vec2( -0.0000, 0.3750 ),
vec2( 0.3536, -0.3536 )
);
#endif
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : 3.14159265359 - a;
}
vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot)
{
float startJitter = (spinAngle/6.28);
float alpha = sqrt(sampleNumber + startJitter/nb );
float angle = alpha * (nbRot * 6.28) + spinAngle*2.;
float ssR = alpha;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
uniform int framemod8;
uniform int framecouter;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:2 */
void main() {
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
vec2 tempOffset=offsets[framemod8];
if (gl_FragData[0].a>0.1){
vec3 albedo = toLinear(gl_FragData[0].rgb);
vec3 normal = normalMat.xyz;
vec3 ambient = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb;
vec3 diffuseLight = ambient;
gl_FragData[0].rgb = diffuseLight*albedo*8./1500.*0.1;
}
}

View File

@ -0,0 +1,56 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
#ifdef MC_NORMAL_MAP
varying vec4 tangent;
attribute vec4 at_tangent;
#endif
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
gl_Position = ftransform();
color = gl_Color;
#ifdef MC_NORMAL_MAP
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
#endif
normalMat = vec4(normalize(gl_NormalMatrix *gl_Normal),1.0);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,334 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
varying vec4 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
varying vec3 binormal;
varying vec3 tangent;
varying vec3 viewVector;
varying float dist;
#define SCREENSPACE_REFLECTIONS //can be really expensive at high resolutions/render quality, especially on ice
#define SSR_STEPS 30 //[10 15 20 25 30 35 40 50 100 200 400]
#define SUN_MICROFACET_SPECULAR // If enabled will use realistic rough microfacet model, else will just reflect the sun. No performance impact.
#define saturate(x) clamp(x,0.0,1.0)
uniform sampler2D texture;
uniform sampler2D noisetex;
uniform sampler2D gaux2;
uniform sampler2D gaux1;
uniform sampler2D depthtex1;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform float frameTimeCounter;
uniform float lightSign;
uniform float near;
uniform float far;
uniform float moonIntensity;
uniform float sunIntensity;
uniform vec3 sunColor;
uniform vec3 nsunColor;
uniform vec3 upVec;
uniform float sunElevation;
uniform float fogAmount;
uniform vec2 texelSize;
uniform float rainStrength;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform mat4 gbufferPreviousModelView;
uniform vec3 previousCameraPosition;
uniform int framemod8;
uniform int frameCounter;
uniform int isEyeInWater;
#include "lib/color_transforms.glsl"
#include "lib/projections.glsl"
#include "lib/sky_gradient.glsl"
#include "lib/waterBump.glsl"
#include "lib/clouds.glsl"
#include "lib/stars.glsl"
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.);
float interleaved_gradientNoise(float temporal){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
return noise;
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
vec3 nvec3(vec4 pos){
return pos.xyz/pos.w;
}
vec4 nvec4(vec3 pos){
return vec4(pos.xyz, 1.0);
}
vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel){
float quality = mix(15,SSR_STEPS,fresnel);
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 = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality;
vec3 spos = clipPosition + stepv*dither;
float minZ = clipPosition.z;
float maxZ = spos.z+stepv.z*0.5;
spos.xy+=offsets[framemod8]*texelSize*0.5;
//raymarch on a quarter res depth buffer for improved cache coherency
for (int i = 0; i < int(quality+1); i++) {
float sp=texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).x;
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)){
return vec3(spos.xy,sp);
}
spos += stepv;
//small bias
minZ = maxZ-0.00004/ld(spos.z);
maxZ += stepv.z;
}
return vec3(1.1);
}
float facos(float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : pi - a;
}
float bayer2(vec2 a){
a = floor(a);
return fract(dot(a,vec2(0.5,a.y*0.75)));
}
float cdist(vec2 coord) {
return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0;
}
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
#define PW_POINTS 1 //[2 4 6 8 16 32]
#define bayer4(a) (bayer2( .5*(a))*.25+bayer2(a))
#define bayer8(a) (bayer4( .5*(a))*.25+bayer2(a))
#define bayer16(a) (bayer8( .5*(a))*.25+bayer2(a))
#define bayer32(a) (bayer16(.5*(a))*.25+bayer2(a))
#define bayer64(a) (bayer32(.5*(a))*.25+bayer2(a))
#define bayer128(a) fract(bayer64(.5*(a))*.25+bayer2(a))
vec3 getParallaxDisplacement(vec3 posxz, float iswater,float bumpmult,vec3 viewVec) {
float waveZ = mix(20.0,0.25,iswater);
float waveM = mix(0.0,4.0,iswater);
vec3 parallaxPos = posxz;
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
float waterHeight = getWaterHeightmap(posxz.xz, waveM, waveZ, iswater) * 0.5;
parallaxPos.xz += waterHeight * vec;
return parallaxPos;
}
vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
{
float alpha = (sampleNumber+jitter)/nb;
float angle = jitter*6.28 + alpha * nbRot * 6.28;
float sin_v, cos_v;
sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*sqrt(alpha);
}
//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);
}
vec4 hash44(vec4 p4)
{
p4 = fract(p4 * vec4(.1031, .1030, .0973, .1099));
p4 += dot(p4, p4.wzxy+33.33);
return fract((p4.xxyz+p4.yzzw)*p4.zywx);
}
vec3 TangentToWorld(vec3 N, vec3 H)
{
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));
}
float GGX (vec3 n, vec3 v, vec3 l, float r, float F0) {
r*=r;r*=r;
vec3 h = l + v;
float hn = inversesqrt(dot(h, h));
float dotLH = clamp(dot(h,l)*hn,0.,1.);
float dotNH = clamp(dot(h,n)*hn,0.,1.);
float dotNL = clamp(dot(n,l),0.,1.);
float dotNHsq = dotNH*dotNH;
float denom = dotNHsq * r - dotNHsq + 1.;
float D = r / (3.141592653589793 * denom * denom);
float F = F0 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float k2 = .25 * r;
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:27 */
void main() {
vec2 tempOffset=offsets[framemod8];
float iswater = normalMat.w;
vec3 fragC = gl_FragCoord.xyz*vec3(texelSize,1.0);
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
vec3 albedo = toLinear(gl_FragData[0].rgb);
if (iswater > 0.4) {
albedo = vec3(0.42,0.6,0.7);
gl_FragData[0] = vec4(0.42,0.6,0.7,0.7);
}
if (iswater > 0.9) {
gl_FragData[0] = vec4(0.0);
}
vec3 normal = normalMat.xyz;
vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z);
if (iswater > 0.4){
float bumpmult = 1.;
if (iswater > 0.9)
bumpmult = 1.;
float parallaxMult = bumpmult;
vec3 posxz = p3+cameraPosition;
posxz.xz-=posxz.y;
if (iswater < 0.9)
posxz.xz *= 3.0;
vec3 bump;
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos));
bump = normalize(getWaveHeight(posxz.xz,iswater));
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
normal = normalize(bump * tbnMatrix);
}
vec3 diffuseLight = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb;
vec3 color = diffuseLight*albedo*8./150./3.;
if (iswater > 0.0){
float f0 = iswater > 0.1? 0.02 : 0.05*(1.0-gl_FragData[0].a);
float roughness = 0.02;
float emissive = 0.0;
float F0 = f0;
vec3 reflectedVector = reflect(normalize(fragpos), normal);
float normalDotEye = dot(normal, normalize(fragpos));
float fresnel = pow(clamp(1.0 + normalDotEye,0.0,1.0), 5.0);
fresnel = mix(F0,1.0,fresnel);
if (iswater > 0.4){
fresnel = fresnel*0.87+0.04; //faking additionnal roughness to the water
roughness = 0.1;
}
vec3 wrefl = mat3(gbufferModelViewInverse)*reflectedVector;
vec4 sky_c = skyCloudsFromTex(wrefl,gaux1)*(1.0-isEyeInWater);
sky_c.rgb *= lmtexcoord.w*lmtexcoord.w*255*255/240./240./150.*8./3.;
vec4 reflection = vec4(sky_c.rgb,0.);
#ifdef SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector,fragpos.xyz,blueNoise(), fresnel);
if (rtPos.z <1.){
vec4 fragpositionPrev = gbufferProjectionInverse * vec4(rtPos*2.-1.,1.);
fragpositionPrev /= fragpositionPrev.w;
vec3 sampleP = fragpositionPrev.xyz;
fragpositionPrev = gbufferModelViewInverse * fragpositionPrev;
vec4 previousPosition = fragpositionPrev + vec4(cameraPosition-previousCameraPosition,0.);
previousPosition = gbufferPreviousModelView * previousPosition;
previousPosition = gbufferPreviousProjection * previousPosition;
previousPosition.xy = previousPosition.xy/previousPosition.w*0.5+0.5;
reflection.a = 1.0;
reflection.rgb = texture2D(gaux2,previousPosition.xy).rgb;
}
#endif
reflection.rgb = mix(sky_c.rgb, reflection.rgb, reflection.a);
vec3 reflected= reflection.rgb*fresnel;
float alpha0 = gl_FragData[0].a;
//correct alpha channel with fresnel
gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel;
gl_FragData[0].rgb =clamp(color/gl_FragData[0].a*alpha0*(1.0-fresnel)*0.1+reflected/gl_FragData[0].a*0.1,0.0,65100.0);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.);
}
else
gl_FragData[0].rgb = color*0.1;
gl_FragData[1] = vec4(albedo,iswater);
}

View File

@ -0,0 +1,89 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#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 lmtexcoord;
varying vec4 color;
varying vec4 normalMat;
varying vec3 binormal;
varying vec3 tangent;
varying float dist;
uniform mat4 gbufferModelViewInverse;
varying vec3 viewVector;
attribute vec4 at_tangent;
attribute vec4 mc_Entity;
#define SHADOW_MAP_BIAS 0.8
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.);
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
gl_Position = toClipSpace3(position);
color = gl_Color;
float mat = 0.0;
if(mc_Entity.x == 8.0 || mc_Entity.x == 9.0) {
mat = 1.0;
gl_Position.z -= 1e-4;
}
if(mc_Entity.x == 79.0) mat = 0.5;
if (mc_Entity.x == 10002) mat = 0.0001;
normalMat = vec4(normalize( gl_NormalMatrix*gl_Normal),mat);
tangent = normalize( gl_NormalMatrix *at_tangent.rgb);
binormal = normalize(cross(tangent.rgb,normalMat.xyz)*at_tangent.w);
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normalMat.x,
tangent.y, binormal.y, normalMat.y,
tangent.z, binormal.z, normalMat.z);
dist = length(gl_ModelViewMatrix * gl_Vertex);
viewVector = ( gl_ModelViewMatrix * gl_Vertex).xyz;
viewVector = normalize(tbnMatrix * viewVector);
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,49 @@
#version 120
varying vec4 lmtexcoord;
varying vec4 color;
uniform sampler2D texture;
uniform sampler2D gaux1;
uniform vec4 lightCol;
uniform vec3 sunVec;
uniform vec2 texelSize;
uniform float skyIntensityNight;
uniform float skyIntensity;
uniform float rainStrength;
uniform mat4 gbufferProjectionInverse;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
vec3 toScreenSpaceVector(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 normalize(fragposition.xyz);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* DRAWBUFFERS:2 */
gl_FragData[0] = texture2D(texture, lmtexcoord.xy)*color;
gl_FragData[0].a = clamp(gl_FragData[0].a -0.1,0.0,1.0)*0.5;
vec3 albedo = toLinear(gl_FragData[0].rgb*color.rgb);
vec3 ambient = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb;
gl_FragData[0].rgb = dot(albedo,vec3(1.0))*ambient*10./3.0/150.*0.1;
}

View File

@ -0,0 +1,44 @@
#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 lmtexcoord;
varying vec4 color;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord*lmcoord;
gl_Position = ftransform();
color = gl_Color;
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -0,0 +1,382 @@
#define log10(x) log(x) / log(10.0)
struct ColorCorrection {
float saturation;
float vibrance;
vec3 lum;
float contrast;
float contrastMidpoint;
vec3 gain;
vec3 lift;
vec3 InvGamma;
} m;
float sigmoid_shaper(float x) { // Sigmoid function in the range 0 to 1 spanning -2 to +2.
float t = max(1.0 - abs(0.5 * x), 0.0);
float y = 1.0 + sign(x) * (1.0 - t * t);
return 0.5 * y;
}
float rgb_2_saturation(vec3 rgb) {
float minrgb = min(min(rgb.r, rgb.g), rgb.b);
float maxrgb = max(max(rgb.r, rgb.g), rgb.b);
return (max(maxrgb, 1e-10) - max(minrgb, 1e-10)) / max(maxrgb, 1e-2);
}
float rgb_2_yc(vec3 rgb) { // Converts RGB to a luminance proxy, here called YC. YC is ~ Y + K * Chroma.
float ycRadiusWeight = 1.75;
float r = rgb[0]; float g = rgb[1]; float b = rgb[2];
float chroma = sqrt(b * (b - g) + g * (g - r) + r * (r - b));
return (b + g + r + ycRadiusWeight * chroma) / 3.0;
}
float glow_fwd(float ycIn, float glowGainIn, float glowMid) {
float glowGainOut;
if (ycIn <= 2.0 / 3.0 * glowMid) {
glowGainOut = glowGainIn;
} else if ( ycIn >= 2.0 * glowMid) {
glowGainOut = 0;
} else {
glowGainOut = glowGainIn * (glowMid / ycIn - 0.5);
}
return glowGainOut;
}
float rgb_2_hue(vec3 rgb) { // Returns a geometric hue angle in degrees (0-360) based on RGB values.
float hue;
if (rgb[0] == rgb[1] && rgb[1] == rgb[2]) { // For neutral colors, hue is undefined and the function will return a quiet NaN value.
hue = 0;
} else {
hue = (180.0 / 3.1415) * atan(2.0 * rgb[0] - rgb[1] - rgb[2], sqrt(3.0) * (rgb[1] - rgb[2])); // flip due to opengl spec compared to hlsl
}
if (hue < 0.0)
hue = hue + 360.0;
return clamp(hue, 0.0, 360.0);
}
float center_hue(float hue, float centerH) {
float hueCentered = hue - centerH;
if (hueCentered < -180.0) {
hueCentered += 360.0;
} else if (hueCentered > 180.0) {
hueCentered -= 360.0;
}
return hueCentered;
}
// Transformations between CIE XYZ tristimulus values and CIE x,y
// chromaticity coordinates
vec3 XYZ_2_xyY( vec3 XYZ ) {
float divisor = max(XYZ[0] + XYZ[1] + XYZ[2], 1e-10);
vec3 xyY = XYZ.xyy;
xyY.rg = XYZ.rg / divisor;
return xyY;
}
vec3 xyY_2_XYZ(vec3 xyY) {
vec3 XYZ = vec3(0.0);
XYZ.r = xyY.r * xyY.b / max(xyY.g, 1e-10);
XYZ.g = xyY.b;
XYZ.b = (1.0 - xyY.r - xyY.g) * xyY.b / max(xyY.g, 1e-10);
return XYZ;
}
mat3 ChromaticAdaptation( vec2 src_xy, vec2 dst_xy ) {
// Von Kries chromatic adaptation
// Bradford
const mat3 ConeResponse = mat3(
vec3(0.8951, 0.2664, -0.1614),
vec3(-0.7502, 1.7135, 0.0367),
vec3(0.0389, -0.0685, 1.0296)
);
const mat3 InvConeResponse = mat3(
vec3(0.9869929, -0.1470543, 0.1599627),
vec3(0.4323053, 0.5183603, 0.0492912),
vec3(-0.0085287, 0.0400428, 0.9684867)
);
vec3 src_XYZ = xyY_2_XYZ( vec3( src_xy, 1 ) );
vec3 dst_XYZ = xyY_2_XYZ( vec3( dst_xy, 1 ) );
vec3 src_coneResp = src_XYZ * ConeResponse;
vec3 dst_coneResp = dst_XYZ * ConeResponse;
mat3 VonKriesMat = mat3(
vec3(dst_coneResp[0] / src_coneResp[0], 0.0, 0.0),
vec3(0.0, dst_coneResp[1] / src_coneResp[1], 0.0),
vec3(0.0, 0.0, dst_coneResp[2] / src_coneResp[2])
);
return (ConeResponse * VonKriesMat) * InvConeResponse;
}
/*******************************************************************************
- Color CorrectionUE4 Style
******************************************************************************/
// Accurate for 1000K < Temp < 15000K
// [Krystek 1985, "An algorithm to calculate correlated colour temperature"]
vec2 PlanckianLocusChromaticity(float Temp) {
float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp );
float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp );
float x = 3.0*u / ( 2.0*u - 8.0*v + 4.0 );
float y = 2.0*v / ( 2.0*u - 8.0*v + 4.0 );
return vec2(x, y);
}
vec2 D_IlluminantChromaticity(float Temp) {
// Accurate for 4000K < Temp < 25000K
// in: correlated color temperature
// out: CIE 1931 chromaticity
// Correct for revision of Plank's law
// This makes 6500 == D65
Temp *= 1.4388 / 1.438;
float x = Temp <= 7000 ?
0.244063 + ( 0.09911e3 + ( 2.9678e6 - 4.6070e9 / Temp ) / Temp ) / Temp :
0.237040 + ( 0.24748e3 + ( 1.9018e6 - 2.0064e9 / Temp ) / Temp ) / Temp;
float y = -3 * x*x + 2.87 * x - 0.275;
return vec2(x,y);
}
vec2 PlanckianIsothermal( float Temp, float Tint ) {
float u = ( 0.860117757f + 1.54118254e-4f * Temp + 1.28641212e-7f * Temp*Temp ) / ( 1.0f + 8.42420235e-4f * Temp + 7.08145163e-7f * Temp*Temp );
float v = ( 0.317398726f + 4.22806245e-5f * Temp + 4.20481691e-8f * Temp*Temp ) / ( 1.0f - 2.89741816e-5f * Temp + 1.61456053e-7f * Temp*Temp );
float ud = ( -1.13758118e9f - 1.91615621e6f * Temp - 1.53177f * Temp*Temp ) / pow( 1.41213984e6f + 1189.62f * Temp + Temp*Temp, 2.0 );
float vd = ( 1.97471536e9f - 705674.0f * Temp - 308.607f * Temp*Temp ) / pow( 6.19363586e6f - 179.456f * Temp + Temp*Temp , 2.0); //don't pow2 this
vec2 uvd = normalize( vec2( u, v ) );
// Correlated color temperature is meaningful within +/- 0.05
u += -uvd.y * Tint * 0.05;
v += uvd.x * Tint * 0.05;
float x = 3*u / ( 2*u - 8*v + 4 );
float y = 2*v / ( 2*u - 8*v + 4 );
return vec2(x,y);
}
vec3 WhiteBalance(vec3 LinearColor) {
const float WhiteTemp = float(WHITE_BALANCE);
const float WhiteTint = 0.0;
vec2 SrcWhiteDaylight = D_IlluminantChromaticity( WhiteTemp );
vec2 SrcWhitePlankian = PlanckianLocusChromaticity( WhiteTemp );
vec2 SrcWhite = WhiteTemp < 4000 ? SrcWhitePlankian : SrcWhiteDaylight;
const vec2 D65White = vec2(0.31270, 0.32900);
// Offset along isotherm
vec2 Isothermal = PlanckianIsothermal( WhiteTemp, WhiteTint ) - SrcWhitePlankian;
SrcWhite += Isothermal;
mat3x3 WhiteBalanceMat = ChromaticAdaptation( SrcWhite, D65White );
WhiteBalanceMat = (sRGB_2_XYZ_MAT * WhiteBalanceMat) * XYZ_2_sRGB_MAT;
return LinearColor * WhiteBalanceMat * 1.0;
}
/*******************************************************************************
- ACES Fimic Curve Approx.
******************************************************************************/
// ACES settings
const float FilmSlope = Film_Slope; //0.90
const float FilmToe = Film_Toe; //0.55
const float FilmShoulder = Film_Shoulder; //0.25
const float FilmBlackClip = Black_Clip;
const float FilmWhiteClip = White_Clip;
const float BlueCorrection = Blue_Correction;
const float ExpandGamut = Gamut_Expansion;
vec3 FilmToneMap(vec3 LinearColor) {
const mat3 AP0_2_sRGB = (AP0_2_XYZ_MAT * D60_2_D65_CAT) * XYZ_2_sRGB_MAT;
const mat3 AP1_2_sRGB = (AP1_2_XYZ_MAT * D60_2_D65_CAT) * XYZ_2_sRGB_MAT;
const mat3 AP0_2_AP1 = AP0_2_XYZ_MAT * XYZ_2_AP1_MAT;
const mat3 AP1_2_AP0 = AP1_2_XYZ_MAT * XYZ_2_AP0_MAT;
vec3 ColorAP1 = LinearColor * AP0_2_AP1;
float LumaAP1 = dot( ColorAP1, AP1_RGB2Y );
vec3 ChromaAP1 = ColorAP1 / LumaAP1;
float ChromaDistSqr = dot( ChromaAP1 - 1, ChromaAP1 - 1 );
float ExpandAmount = ( 1 - exp2( -4 * ChromaDistSqr ) ) * ( 1 - exp2( -4 * ExpandGamut * LumaAP1*LumaAP1 ) );
const mat3 Wide_2_XYZ_MAT = mat3(
vec3(0.5441691, 0.2395926, 0.1666943),
vec3(0.2394656, 0.7021530, 0.0583814),
vec3(-0.0023439, 0.0361834, 1.0552183)
);
const mat3 Wide_2_AP1 = Wide_2_XYZ_MAT * XYZ_2_AP1_MAT;
const mat3 ExpandMat = AP1_2_sRGB * Wide_2_AP1;
vec3 ColorExpand = ColorAP1 * ExpandMat;
ColorAP1 = mix(ColorAP1, ColorExpand, ExpandAmount);
const mat3 BlueCorrect = mat3(
vec3(0.9404372683, -0.0183068787, 0.0778696104),
vec3(0.0083786969, 0.8286599939, 0.1629613092),
vec3(0.0005471261, -0.0008833746, 1.0003362486)
);
const mat3 BlueCorrectInv = mat3(
vec3(1.06318, 0.0233956, -0.0865726),
vec3(-0.0106337, 1.20632, -0.19569),
vec3(-0.000590887, 0.00105248, 0.999538)
);
const mat3 BlueCorrectAP1 = (AP1_2_AP0 * BlueCorrect) * AP0_2_AP1;
const mat3 BlueCorrectInvAP1 = (AP1_2_AP0 * BlueCorrectInv) * AP0_2_AP1;
// Blue correction
ColorAP1 = mix(ColorAP1, ColorAP1 * BlueCorrectAP1, BlueCorrection);
vec3 ColorAP0 = LinearColor * AP1_2_AP0;
// "Glow" module constants
const float RRT_GLOW_GAIN = 0.05;
const float RRT_GLOW_MID = 0.08;
float saturation = rgb_2_saturation(ColorAP0);
float ycIn = rgb_2_yc(ColorAP0);
float s = sigmoid_shaper((saturation - 0.4) * 5.0);
float addedGlow = 1.0 + glow_fwd(ycIn, RRT_GLOW_GAIN * s, RRT_GLOW_MID) * 3;
ColorAP0 *= addedGlow;
// --- Red modifier --- //
const float RRT_RED_SCALE = 0.99;
const float RRT_RED_PIVOT = 0.22;
const float RRT_RED_HUE = 0.15;
const float RRT_RED_WIDTH = 135.0;
float hue = rgb_2_hue(ColorAP0);
float centeredHue = center_hue(hue, RRT_RED_HUE);
float hueWeight = pow(smoothstep(0.0, 1.0, 1.0 - abs(2.0 * centeredHue / RRT_RED_WIDTH)), 2.0);
ColorAP0.r += hueWeight * saturation * (RRT_RED_PIVOT - ColorAP0.r) * (1.0 - RRT_RED_SCALE);
// Use ACEScg primaries as working space
vec3 WorkingColor = ColorAP0 * AP0_2_AP1_MAT * 1.2;
WorkingColor = max(vec3(0.0), WorkingColor) * 1.1;
WorkingColor = mix(vec3(dot(WorkingColor, AP1_RGB2Y)), WorkingColor, 0.96); // Pre desaturate
const float ToeScale = 1.0 + FilmBlackClip - FilmToe;
const float ShoulderScale = 1.0 + FilmWhiteClip - FilmShoulder;
const float InMatch = in_Match;
const float OutMatch = Out_Match;
float ToeMatch = 0.0;
if(FilmToe > 0.8) {
// 0.18 will be on straight segment
ToeMatch = (1.0 - FilmToe - OutMatch) / FilmSlope + log10(InMatch);
} else {
// 0.18 will be on toe segment
// Solve for ToeMatch such that input of InMatch gives output of OutMatch.
const float bt = (OutMatch + FilmBlackClip) / ToeScale - 1.0;
ToeMatch = log10(InMatch) - 0.5 * log((1.0 + bt) / (1.0 - bt)) * (ToeScale / FilmSlope);
}
float StraightMatch = (1.0 - FilmToe) / FilmSlope - ToeMatch;
float ShoulderMatch = FilmShoulder / FilmSlope - StraightMatch;
vec3 LogColor = log10(WorkingColor);
vec3 StraightColor = FilmSlope * (LogColor + StraightMatch);
vec3 ToeColor = (-FilmBlackClip) + (2.0 * ToeScale) / (1.0 + exp((-2.0 * FilmSlope / ToeScale) * (LogColor - ToeMatch)));
vec3 ShoulderColor = (1.0 + FilmWhiteClip) - (2.0 * ShoulderScale) / (1.0 + exp(( 2.0 * FilmSlope / ShoulderScale) * (LogColor - ShoulderMatch)));
for(int i = 0; i < 1; ++i) {
ToeColor[i] = LogColor[i] < ToeMatch ? ToeColor[i] : StraightColor[i];
ShoulderColor[i] = LogColor[i] > ShoulderMatch ? ShoulderColor[i] : StraightColor[i];
}
vec3 t = clamp((LogColor - ToeMatch) / (ShoulderMatch - ToeMatch), 0.0, 1.0);
t = ShoulderMatch < ToeMatch ? 1.0 - t : t;
t = (3.0 - 2.0 * t) * t * t;
vec3 ToneColor = mix(ToeColor, ShoulderColor, t);
ToneColor = mix(vec3(dot(ToneColor, AP1_RGB2Y)), ToneColor, 0.93); // Post desaturate
ToneColor = mix(ToneColor, ToneColor * BlueCorrectInvAP1, BlueCorrection);
// Returning positive AP1 values
return max(vec3(0.0), ToneColor * AP1_2_sRGB);
}
vec3 Saturation(vec3 color, ColorCorrection m) {
float grey = dot(color, m.lum);
return grey + m.saturation * (color - grey);
}
vec3 Vibrance(vec3 color, ColorCorrection m) {
float maxColor = max(color.r, max(color.g, color.b));
float minColor = min(color.r, min(color.g, color.b));
float colorSaturation = maxColor - minColor;
float grey = dot(color, m.lum);
color = mix(vec3(grey), color, 1.0 + m.vibrance * (1.0 - sign(m.vibrance) * colorSaturation));
return color;
}
vec3 LiftGammaGain(vec3 v, ColorCorrection m) {
vec3 lerpV = clamp(pow(v, m.InvGamma), 0.0, 1.0);
return m.gain * lerpV + m.lift * (1.0 - lerpV);
}
float LogContrast(float x, const float eps, float logMidpoint, float contrast) {
float logX = log2(x + eps);
float adjX = (logX - logMidpoint) / contrast + logMidpoint;
return max(exp2(adjX) - eps, 0.0);
}
vec3 Contrast(vec3 color, ColorCorrection m) {
const float contrastEpsilon = 1e-5;
vec3 ret;
ret.x = LogContrast(color.x, contrastEpsilon, log2(0.18), m.contrast);
ret.y = LogContrast(color.y, contrastEpsilon, log2(0.18), m.contrast);
ret.z = LogContrast(color.z, contrastEpsilon, log2(0.18), m.contrast);
return ret;
}
vec3 srgbToLinear(vec3 srgb) {
return mix(
srgb * 0.07739938080495356, // 1.0 / 12.92 = ~0.07739938080495356
pow(0.947867 * srgb + 0.0521327, vec3(2.4)),
step(0.04045, srgb)
);
}
vec3 linearToSrgb(vec3 linear) {
return mix(
linear * 12.92,
pow(linear, vec3(0.416666666667)) * 1.055 - 0.055, // 1.0 / 2.4 = ~0.416666666667
step(0.0031308, linear)
);
}

View File

@ -0,0 +1,115 @@
#define log10(x) log(x) / log(10.0)
struct SegmentedSplineParams_c5 {
float coefsLow[6]; // coefs for B-spline between minPoint and midPoint (units of log luminance)
float coefsHigh[6]; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
vec2 minPoint; // {luminance, luminance} linear extension below this
vec2 midPoint; // {luminance, luminance}
vec2 maxPoint; // {luminance, luminance} linear extension above this
float slopeLow; // log-log slope of low linear extension
float slopeHigh; // log-log slope of high linear extension
};
struct SegmentedSplineParams_c9 {
float coefsLow[10]; // coefs for B-spline between minPoint and midPoint (units of log luminance)
float coefsHigh[10]; // coefs for B-spline between midPoint and maxPoint (units of log luminance)
float slopeLow; // log-log slope of low linear extension
float slopeHigh; // log-log slope of high linear extension
};
const mat3 M = mat3(
0.5, -1.0, 0.5,
-1.0, 1.0, 0.5,
0.5, 0.0, 0.0
);
float segmented_spline_c5_fwd(float x) {
const SegmentedSplineParams_c5 C = SegmentedSplineParams_c5(
float[6] ( -4.0000000000, -4.0000000000, -3.1573765773, -0.4852499958, 1.8477324706, 1.8477324706 ),
float[6] ( -0.7185482425, 2.0810307172, 3.6681241237, 4.0000000000, 4.0000000000, 4.0000000000 ),
vec2(0.18*exp2(-15.0), 0.0001),
vec2(0.18, 4.8),
vec2(0.18*exp2(18.0), 10000.),
0.0,
0.0
);
const int N_KNOTS_LOW = 4;
const int N_KNOTS_HIGH = 4;
// Check for negatives or zero before taking the log. If negative or zero,
// set to ACESMIN.1
float xCheck = x <= 0 ? exp2(-14.0) : x;
float logx = log10( xCheck);
float logy;
if (logx <= log10(C.minPoint.x)) {
logy = logx * C.slopeLow + (log10(C.minPoint.y) - C.slopeLow * log10(C.minPoint.x));
} else if ((logx > log10(C.minPoint.x)) && (logx < log10(C.midPoint.x))) {
float knot_coord = (N_KNOTS_LOW-1) * (logx-log10(C.minPoint.x))/(log10(C.midPoint.x)-log10(C.minPoint.x));
int j = int(knot_coord);
float t = knot_coord - float(j);
vec3 cf = vec3( C.coefsLow[ j], C.coefsLow[ j + 1], C.coefsLow[ j + 2]);
vec3 monomials = vec3(t * t, t, 1.0);
logy = dot( monomials, M * cf);
} else if ((logx >= log10(C.midPoint.x)) && (logx < log10(C.maxPoint.x))) {
float knot_coord = (N_KNOTS_HIGH - 1) * (logx - log10(C.midPoint.x)) / (log10(C.maxPoint.x) - log10(C.midPoint.x));
int j = int(knot_coord);
float t = knot_coord - float(j);
vec3 cf = vec3(C.coefsHigh[j], C.coefsHigh[j + 1], C.coefsHigh[j + 2]);
vec3 monomials = vec3(t * t, t, 1.0);
logy = dot(monomials, M * cf);
} else {
logy = logx * C.slopeHigh + (log10(C.maxPoint.y) - C.slopeHigh * log10(C.maxPoint.x));
}
return pow(10.0, logy);
}
float segmented_spline_c9_fwd( float x, const SegmentedSplineParams_c9 C, const mat3x2 toningPoints) {
const int N_KNOTS_LOW = 8;
const int N_KNOTS_HIGH = 8;
// Check for negatives or zero before taking the log. If negative or zero,
// set to OCESMIN.
float xCheck = x <= 0 ? 1e-4 : x;
vec2 minPoint = toningPoints[0];
vec2 midPoint = toningPoints[1];
vec2 maxPoint = toningPoints[2];
float logx = log10(xCheck);
float logy;
if (logx <= log10(minPoint.x)) {
logy = logx * C.slopeLow + (log10(minPoint.y) - C.slopeLow * log10(minPoint.x));
} else if ((logx > log10(minPoint.x)) && (logx < log10(midPoint.x))) {
float knot_coord = (N_KNOTS_LOW - 1) * (logx - log10(minPoint.x)) / (log10(midPoint.x) - log10(minPoint.x));
int j = int(knot_coord);
float t = knot_coord - float(j);
vec3 cf = vec3(C.coefsLow[j], C.coefsLow[j + 1], C.coefsLow[j + 2]);
vec3 monomials = vec3(t * t, t, 1.0);
logy = dot(monomials, M * cf);
} else if ((logx >= log10(midPoint.x)) && (logx < log10(maxPoint.x))) {
float knot_coord = (N_KNOTS_HIGH - 1) * (logx - log10(midPoint.x)) / (log10(maxPoint.x) - log10(midPoint.x));
int j = int(knot_coord);
float t = knot_coord - float(j);
vec3 cf = vec3(C.coefsHigh[j], C.coefsHigh[j + 1], C.coefsHigh[j + 2]);
vec3 monomials = vec3(t * t, t, 1.0);
logy = dot(monomials, M * cf);
} else {
logy = logx * C.slopeHigh + (log10(maxPoint.y) - C.slopeHigh * log10(maxPoint.x));
}
return pow(10.0, logy);
}

View File

@ -0,0 +1,63 @@
const mat3 sRGB_2_XYZ_MAT = mat3( // Linear sRGB to XYZ color space
vec3(0.4124564, 0.3575761, 0.1804375),
vec3(0.2126729, 0.7151522, 0.0721750),
vec3(0.0193339, 0.1191920, 0.9503041)
);
const mat3 XYZ_2_sRGB_MAT = mat3( //XYZ to linear sRGB Color Space
vec3(3.2409699419, -1.5373831776, -0.4986107603),
vec3(-0.9692436363, 1.8759675015, 0.0415550574),
vec3(0.0556300797, -0.2039769589, 1.0569715142)
);
const mat3 D65_2_D60_CAT = mat3( // D65 to D60 White Point
vec3(1.01303, 0.00610531, -0.014971),
vec3(0.00769823, 0.998165, -0.00503203),
vec3(-0.00284131, 0.00468516, 0.924507)
);
const mat3 D60_2_D65_CAT = mat3( //D60 to D65 White Point
vec3(0.987224, -0.00611327, 0.0159533),
vec3(-0.00759836, 1.00186, 0.00533002),
vec3(0.00307257, -0.00509595, 1.08168)
);
const mat3 XYZ_2_AP0_MAT = mat3( // XYZ to ACEScg Color Space
vec3(1.0498110175, 0.0000000000,-0.0000974845),
vec3(-0.4959030231, 1.3733130458, 0.0982400361),
vec3(0.0000000000, 0.0000000000, 0.9912520182)
);
const mat3 AP0_2_XYZ_MAT = mat3( // ACEScg to XYZ Color Space
vec3(0.9525523959, 0.0000000000, 0.0000936786),
vec3(0.3439664498, 0.7281660966,-0.0721325464),
vec3(0.0000000000, 0.0000000000, 1.0088251844)
);
const mat3 XYZ_2_AP1_MAT = mat3( // XYZ to ACEStoning Color Space
vec3(1.6410233797, -0.3248032942, -0.2364246952),
vec3(-0.6636628587, 1.6153315917, 0.0167563477),
vec3(0.0117218943, -0.0082844420, 0.9883948585)
);
const mat3 AP1_2_XYZ_MAT = mat3( // ACEStoning to XYZ Color Space
vec3(0.6624541811, 0.1340042065, 0.1561876870),
vec3(0.2722287168, 0.6740817658, 0.0536895174),
vec3(-0.0055746495, 0.0040607335, 1.0103391003)
);
const mat3 AP0_2_AP1_MAT = mat3( // ACEScg to ACEStoneing Color Space
vec3(1.4514393161, -0.2365107469, -0.2149285693),
vec3(-0.0765537734, 1.1762296998, -0.0996759264),
vec3(0.0083161484, -0.0060324498, 0.9977163014)
);
const mat3 AP1_2_AP0_MAT = mat3( // ACEStoning to ACEScg Color Space
vec3(0.6954522414, 0.1406786965, 0.1638690622),
vec3(0.0447945634, 0.8596711185, 0.0955343182),
vec3(-0.0055258826, 0.0040252103, 1.0015006723)
);
const vec3 AP1_RGB2Y = vec3(0.2722287168, 0.6740817658, 0.0536895174); // Desaturation Coeff
const mat3 sRGB_2_AP0 = (sRGB_2_XYZ_MAT * D65_2_D60_CAT) * XYZ_2_AP0_MAT;

View File

@ -0,0 +1,157 @@
const float sunAngularSize = 0.533333;
const float moonAngularSize = 0.516667;
//Sky coefficients and heights
#define airNumberDensity 2.5035422e25
#define ozoneConcentrationPeak 8e-6
const float ozoneNumberDensity = airNumberDensity * ozoneConcentrationPeak;
#define ozoneCrossSection vec3(4.51103766177301e-21, 3.2854797958699e-21, 1.96774621921165e-22)
#define sky_planetRadius 6731e3
#define sky_atmosphereHeight 110e3
#define sky_scaleHeights vec2(8.0e3, 1.2e3)
#define sky_mieg 0.80 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define sky_coefficientRayleighR 5.8 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
#define sky_coefficientRayleighG 1.35 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
#define sky_coefficientRayleighB 3.31 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
#define sky_coefficientRayleigh vec3(sky_coefficientRayleighR*1e-6, sky_coefficientRayleighG*1e-5, sky_coefficientRayleighB*1e-5)
#define sky_coefficientMieR 3.0 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
#define sky_coefficientMieG 3.0 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
#define sky_coefficientMieB 3.0 //[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 ]
#define sky_coefficientMie vec3(sky_coefficientMieR*1e-6, sky_coefficientMieG*1e-6, sky_coefficientMieB*1e-6) // Should be >= 2e-6
const vec3 sky_coefficientOzone = (ozoneCrossSection * (ozoneNumberDensity * 1.e-6)); // ozone cross section * (ozone number density * (cm ^ 3))
const vec2 sky_inverseScaleHeights = 1.0 / sky_scaleHeights;
const vec2 sky_scaledPlanetRadius = sky_planetRadius * sky_inverseScaleHeights;
const float sky_atmosphereRadius = sky_planetRadius + sky_atmosphereHeight;
const float sky_atmosphereRadiusSquared = sky_atmosphereRadius * sky_atmosphereRadius;
#define sky_coefficientsScattering mat2x3(sky_coefficientRayleigh, sky_coefficientMie)
const mat3 sky_coefficientsAttenuation = mat3(sky_coefficientRayleigh, sky_coefficientMie * 1.11, sky_coefficientOzone); // commonly called the extinction coefficient
#define sun_illuminance 128000.0 //[10000.0 20000.0 30000.0 40000.0 50000.0 60000.0 70000.0 80000.0 90000.0 100000.0 110000.0 120000.0 130000.0 140000.0 160000.0]
#define moon_illuminance 60.0 //[0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 1000.0 10000.0 100000.0]
#define sunColorR 1.0 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define sunColorG 0.9 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define sunColorB 0.81 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define sunColorBase (vec3(sunColorR,sunColorG,sunColorB) * sun_illuminance)
//#define sunColorBase blackbody(5778) * sun_illuminance
#define moonColorR 1.0 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define moonColorG 0.9 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define moonColorB 0.81 //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
#define moonColorBase (vec3(moonColorR, moonColorG, moonColorB) * moon_illuminance ) //Fake Purkinje effect
float sky_rayleighPhase(float cosTheta) {
const vec2 mul_add = vec2(0.1, 0.28) * rPI;
return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation
}
float sky_miePhase(float cosTheta, const float g) {
float gg = g * g;
return (gg * -0.25 + 0.25) * rPI * pow(-(2.0 * g) * cosTheta + (gg + 1.0), -1.5);
}
vec2 sky_phase(float cosTheta, const float g) {
return vec2(sky_rayleighPhase(cosTheta), sky_miePhase(cosTheta, g));
}
vec3 sky_density(float centerDistance) {
vec2 rayleighMie = exp(centerDistance * -sky_inverseScaleHeights + sky_scaledPlanetRadius);
// Ozone distribution curve by Sergeant Sarcasm - https://www.desmos.com/calculator/j0wozszdwa
float ozone = exp(-max(0.0, (35000.0 - centerDistance) - sky_planetRadius) * (1.0 / 5000.0))
* exp(-max(0.0, (centerDistance - 35000.0) - sky_planetRadius) * (1.0 / 15000.0));
return vec3(rayleighMie, ozone);
}
vec3 sky_airmass(vec3 position, vec3 direction, float rayLength, const float steps) {
float stepSize = rayLength * (1.0 / steps);
vec3 increment = direction * stepSize;
position += increment * 0.5;
vec3 airmass = vec3(0.0);
for (int i = 0; i < steps; ++i, position += increment) {
airmass += sky_density(length(position));
}
return airmass * stepSize;
}
vec3 sky_airmass(vec3 position, vec3 direction, const float steps) {
float rayLength = dot(position, direction);
rayLength = rayLength * rayLength + sky_atmosphereRadiusSquared - dot(position, position);
if (rayLength < 0.0) return vec3(0.0);
rayLength = sqrt(rayLength) - dot(position, direction);
return sky_airmass(position, direction, rayLength, steps);
}
vec3 sky_opticalDepth(vec3 position, vec3 direction, float rayLength, const float steps) {
return sky_coefficientsAttenuation * sky_airmass(position, direction, rayLength, steps);
}
vec3 sky_opticalDepth(vec3 position, vec3 direction, const float steps) {
return sky_coefficientsAttenuation * sky_airmass(position, direction, steps);
}
vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
return exp2(-sky_opticalDepth(position, direction, steps) * rLOG2);
}
vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) {
const int jSteps = 4;
vec3 viewPosition = (sky_planetRadius + eyeAltitude) * upVector;
vec2 aid = rsi(viewPosition, viewVector, sky_atmosphereRadius);
if (aid.y < 0.0) {transmittance = vec3(1.0); return vec3(0.0);}
pid = rsi(viewPosition, viewVector, sky_planetRadius * 0.998);
bool planetIntersected = pid.y >= 0.0;
vec2 sd = vec2((planetIntersected && pid.x < 0.0) ? pid.y : max(aid.x, 0.0), (planetIntersected && pid.x > 0.0) ? pid.x : aid.y);
float stepSize = (sd.y - sd.x) * (1.0 / iSteps);
vec3 increment = viewVector * stepSize;
vec3 position = viewVector * sd.x + viewPosition;
position += increment * (0.34*noise);
vec2 phaseSun = sky_phase(dot(viewVector, sunVector ), sky_mieg);
vec2 phaseMoon = sky_phase(dot(viewVector, moonVector), sky_mieg);
vec3 scatteringSun = vec3(0.0);
vec3 scatteringMoon = vec3(0.0);
vec3 scatteringAmbient = vec3(0.0);
transmittance = vec3(1.0);
for (int i = 0; i < iSteps; ++i, position += increment) {
vec3 density = sky_density(length(position));
if (density.y > 1e35) break;
vec3 stepAirmass = density * stepSize;
vec3 stepOpticalDepth = sky_coefficientsAttenuation * stepAirmass;
vec3 stepTransmittance = exp2(-stepOpticalDepth * rLOG2);
vec3 stepTransmittedFraction = clamp01((stepTransmittance - 1.0) / -stepOpticalDepth);
vec3 stepScatteringVisible = transmittance * stepTransmittedFraction;
scatteringSun += sky_coefficientsScattering * (stepAirmass.xy * phaseSun ) * stepScatteringVisible * sky_transmittance(position, sunVector, jSteps);
scatteringMoon += sky_coefficientsScattering * (stepAirmass.xy * phaseMoon) * stepScatteringVisible * sky_transmittance(position, moonVector, jSteps);
// Nice way to fake multiple scattering.
scatteringAmbient += sky_coefficientsScattering * stepAirmass.xy * stepScatteringVisible;
transmittance *= stepTransmittance;
}
vec3 scattering = scatteringSun * sunColorBase + scatteringAmbient * background + scatteringMoon*moonColorBase;
return scattering;
}

View File

@ -0,0 +1,22 @@
const float ambientOcclusionLevel = 0.3; //[0.0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0 ]
const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 -78 -77 -76 -75 -74 -73 -72 -71 -70 -69 -68 -67 -66 -65 -64 -63 -62 -61 -60 -59 -58 -57 -56 -55 -54 -53 -52 -51 -50 -49 -48 -47 -46 -45 -44 -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33 -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 ]
const int shadowMapResolution = 3172; //Will probably crash at 16 384 [512 768 1024 1536 2048 3172 4096 8192 16384]
const float shadowDistance = 150; //[32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 ] Not linear at all when shadowDistanceRenderMul is set to -1.0, 175.0 is enough for 40 render distance
const float shadowDistanceRenderMul = -1.0; //[-1.0 1.0] Can help to increase shadow draw distance when set to -1.0, at the cost of performance
const float k = 1.8;
const float d0 = 0.04;
const float d1 = 0.61;
float a = exp(d0);
float b = (exp(d1)-a)*shadowDistance/128.0;
vec4 BiasShadowProjection(in vec4 projectedShadowSpacePosition) {
float distortFactor = log(length(projectedShadowSpacePosition.xy)*b+a)*k;
projectedShadowSpacePosition.xy /= distortFactor;
return projectedShadowSpacePosition;
}
float calcDistort(vec2 worldpos){
return 1.0/(log(length(worldpos)*b+a)*k);
}

View File

@ -0,0 +1,16 @@
vec3 cloud2D(vec3 fragpos,vec3 col){
vec3 wpos = fragpos;
float wind = frameTimeCounter/200.;
vec2 intersection = ((2000.0-cameraPosition.y)*wpos.xz*inversesqrt(wpos.y+cameraPosition.y/512.-50./512.) + cameraPosition.xz+wind)/40000.;
float phase = pow(clamp(dot(fragpos,sunVec),0.,1.),2.)*0.5+0.5;
float fbm = clamp((texture2D(noisetex,intersection*vec2(1.,1.5)).a + texture2D(noisetex,intersection*vec2(2.,7.)+wind*0.4).a/2.)-0.5*(1.0-rainStrength),0.,1.) ;
return mix(col,6.*(vec3(0.9,1.2,1.5)*skyIntensityNight*0.02*(1.0-rainStrength*0.9)+17.*phase*nsunColor*skyIntensity*0.7*(1.0-rainStrength*0.9)),0.0*(fbm*fbm)*(fbm*fbm)*(fbm*clamp(wpos.y*0.9,0.,1.)));
}

View File

@ -0,0 +1,46 @@
//using white noise for color dithering : gives a somewhat more "filmic" look when noise is visible
float nrand( vec2 n )
{
return fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
}
float triangWhiteNoise( vec2 n )
{
float t = fract( frameTimeCounter );
float rnd = nrand( n + 0.07*t );
float center = rnd*2.0-1.0;
rnd = center*inversesqrt(abs(center));
rnd = max(-1.0,rnd);
return rnd-sign(center);
}
vec3 fp10Dither(vec3 color,vec2 tc01){
float dither = triangWhiteNoise(tc01);
const vec3 mantissaBits = vec3(6.,6.,5.);
vec3 exponent = floor(log2(color));
return color + dither*exp2(-mantissaBits)*exp2(exponent);
}
vec3 fp16Dither(vec3 color,vec2 tc01){
float dither = triangWhiteNoise(tc01);
const vec3 mantissaBits = vec3(10.);
vec3 exponent = floor(log2(color));
return color + dither*exp2(-mantissaBits)*exp2(exponent);
}
vec3 int8Dither(vec3 color,vec2 tc01){
float dither = triangWhiteNoise(tc01);
return color + dither*exp2(-8.0);
}
vec3 int10Dither(vec3 color,vec2 tc01){
float dither = triangWhiteNoise(tc01);
return color + dither*exp2(-10.0);
}
vec3 int16Dither(vec3 color,vec2 tc01){
float dither = triangWhiteNoise(tc01);
return color + dither*exp2(-16.0);
}

View File

@ -0,0 +1,131 @@
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
float luma(vec3 color) {
return dot(color,vec3(0.299, 0.587, 0.114));
}
vec3 ToneMap_Hejl2015(in vec3 hdr)
{
vec4 vh = vec4(hdr*0.85, 3.0); //0
vec4 va = (1.75 * vh) + 0.05; //0.05
vec4 vf = ((vh * va + 0.004f) / ((vh * (va + 0.55f) + 0.0491f))) - 0.0821f+0.000633604888; //((0+0.004)/((0*(0.05+0.55)+0.0491)))-0.0821
return vf.xyz / vf.www;
}
const mat3 ACESInputMat =
mat3(0.59719, 0.35458, 0.04823,
0.07600, 0.90834, 0.01566,
0.02840, 0.13383, 0.83777
);
// ODT_SAT => XYZ => D60_2_D65 => sRGB
const mat3 ACESOutputMat =
mat3( 1.60475, -0.53108, -0.07367,
-0.10208, 1.10813, -0.00605,
-0.00327, -0.07276, 1.07602
);
vec3 LinearTosRGB(in vec3 color)
{
vec3 x = color * 12.92f;
vec3 y = 1.055f * pow(clamp(color,0.0,1.0), vec3(1.0f / 2.4f)) - 0.055f;
vec3 clr = color;
clr.r = color.r < 0.0031308f ? x.r : y.r;
clr.g = color.g < 0.0031308f ? x.g : y.g;
clr.b = color.b < 0.0031308f ? x.b : y.b;
return clr;
}
vec3 HableTonemap(vec3 linearColor) {
// A = shoulder strength
const float A = 0.22;
// B = linear strength
const float B = 0.3;
// C = linear angle
const float C = 0.1;
// D = toe strength
const float D = 0.4;
// E = toe numerator
const float E = 0.025;
// F = toe denominator
const float F = 0.30;
// Note: E / F = toe angle
// linearWhite = linear white point value
vec3 x = linearColor*2.8;
vec3 color = ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;
const float W = 11.2;
const float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F;
return color / white;
}
vec3 reinhard(vec3 x){
x *= 1.66;
return x/(1.0+x);
}
vec3 ACESFilm( vec3 x )
{
x *= 0.23/0.267;
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
return (x*(a*x+b))/(x*(c*x+d)+e);
}
// From https://www.shadertoy.com/view/WdjSW3
vec3 Tonemap_Lottes(vec3 x) {
// Lottes 2016, "Advanced Techniques and Optimization of HDR Color Pipelines"
const float a = 1.7;
const float d = 0.92;
const float hdrMax = 3.0;
const float midIn = 0.2475;
const float midOut = 0.267;
// Can be precomputed
const float b =
(-pow(midIn, a) + pow(hdrMax, a) * midOut) /
((pow(hdrMax, a * d) - pow(midIn, a * d)) * midOut);
const float c =
(pow(hdrMax, a * d) * pow(midIn, a) - pow(hdrMax, a) * pow(midIn, a * d) * midOut) /
((pow(hdrMax, a * d) - pow(midIn, a * d)) * midOut);
return pow(x,vec3(a)) / (pow(x, vec3(a * d)) * b + c);
}
// From https://www.shadertoy.com/view/WdjSW3
vec3 Tonemap_Uchimura(vec3 x, float P, float a, float m, float l, float c, float b) {
// Uchimura 2017, "HDR theory and practice"
// Math: https://www.desmos.com/calculator/gslcdxvipg
// Source: https://www.slideshare.net/nikuque/hdr-theory-and-practicce-jp
float l0 = ((P - m) * l) / a;
float L0 = m - m / a;
float L1 = m + (1.0 - m) / a;
float S0 = m + l0;
float S1 = m + a * l0;
float C2 = (a * P) / (P - S1);
float CP = -C2 / P;
vec3 w0 = 1.0 - smoothstep(0.0, m, x);
vec3 w2 = step(m + l0, x);
vec3 w1 = 1.0 - w0 - w2;
vec3 T = m * pow(x / m, vec3(c)) + b;
vec3 S = P - (P - S1) * exp(CP * (x - S0));
vec3 L = m + a * (x - m);
return T * w0 + L * w1 + S * w2;
}
vec3 Tonemap_Uchimura(vec3 x) {
const float P = 1.0; // max display brightness
const float a = 1.0; // contrast
const float m = 0.22; // linear section start
const float l = 0.4; // linear section length
const float c = 1.33; // black
const float b = 0.0; // pedestal
return Tonemap_Uchimura(x, P, a, m, l, c, b);
}

View File

@ -0,0 +1,78 @@
#version 120
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
#extension GL_EXT_gpu_shader4 : enable
varying vec2 texcoord;
flat varying vec3 zMults;
uniform sampler2D depthtex0;
uniform sampler2D colortex3;
uniform sampler2D colortex2;
uniform sampler2D colortex0;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform int isEyeInWater;
uniform vec2 texelSize;
float ld(float depth) {
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){
vec4 vl = vec4(0.0);
float sum = 0.0;
mat3x3 weights;
ivec2 posD = ivec2(coord/2.0)*2;
ivec2 posVl = ivec2(coord/2.0);
float dz = zMults.x;
ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 3 );
//pos = ivec2(1,-1);
ivec2 tcDepth = posD + ivec2(-2,-2) + pos*2;
float dsample = ld(texelFetch2D(depth,tcDepth,0).r);
float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-1)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(-2,0) + pos*2;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(-1,0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0) + pos*2;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w;
sum += w;
tcDepth = posD + ivec2(0,-2) + pos*2;
dsample = ld(texelFetch2D(depth,tcDepth,0).r);
w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5;
vl += texelFetch2D(tex,posVl+ivec2(0,-1)+pos,0)*w;
sum += w;
return vl/sum;
}
void main() {
/* DRAWBUFFERS:0 */
//3x3 bilateral upscale from half resolution
float frDepth = ld(texture2D(depthtex0,texcoord).x);
vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth);
vec3 color = texture2D(colortex3,texcoord).rgb;
vec4 transparencies = texture2D(colortex2,texcoord);
color = color*(1.0-transparencies.a)+transparencies.rgb*10.;
color *= vl.a;
color += vl.rgb;
gl_FragData[0].rgb = clamp(color,6.11*1e-5,65000.0);
gl_FragData[0].a = vl.a;
}

View File

@ -0,0 +1,19 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
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;
}

View File

@ -0,0 +1,55 @@
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform vec3 cameraPosition;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toClipSpace3(vec3 viewSpacePosition) {
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
vec3 toScreenSpaceVector(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 normalize(fragposition.xyz);
}
vec3 toWorldSpace(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
return p3;
}
vec3 toWorldSpaceCamera(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
return p3 + cameraPosition;
}
vec3 toShadowSpace(vec3 p3){
p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz;
p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
return p3;
}
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;
}

View File

@ -0,0 +1,84 @@
#define DRAW_SUN //if not using custom sky
#define SKY_BRIGHTNESS_DAY 1.0 //[0.0 0.5 0.75 1. 1.2 1.4 1.6 1.8 2.0]
#define SKY_BRIGHTNESS_NIGHT 1.0 //[0.0 0.5 0.75 1. 1.2 1.4 1.6 1.8 2.0]
#define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0)
vec3 drawSun(float cosY, float sunInt,vec3 nsunlight,vec3 inColor){
return inColor+nsunlight/0.0008821203*pow(smoothstep(cos(0.0093084168595*3.2),cos(0.0093084168595*1.8),cosY),3.)*0.62;
}
const float pi = 3.141592653589793238462643383279502884197169;
vec2 sphereToCarte(vec3 dir) {
float lonlat = atan(-dir.x, -dir.z);
return vec2(lonlat * (0.5/pi) +0.5,0.5*dir.y+0.5);
}
vec3 skyFromTex(vec3 pos,sampler2D sampler){
vec2 p = sphereToCarte(pos);
return texture2D(sampler,p*texelSize*256.+vec2(18.5,1.5)*texelSize).rgb;
}
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));
}
vec4 skyCloudsFromTex(vec3 pos,sampler2D sampler){
vec2 p = sphereToCarte(pos);
return texture2D(sampler,p*texelSize*256.+vec2(18.5+257.,1.5)*texelSize);
}

View File

@ -0,0 +1,334 @@
//#define Specular_Reflections // reflections on blocks. REQUIRES A PBR RESOURCEPACK.
#define Screen_Space_Reflections // toggle screenspace reflections. if you want normal performance but still want a bit of shiny, the sun reflection stays on when this is turned off.
#define Sky_reflection // just in case you dont want it i guess
// #define Rough_reflections // turns the roughness GGXVNDF ON. sizable performance impact, and introduces alot of noise.
#define Sun_specular_Strength 3 // increase for more sparkles [1 2 3 4 5 6 7 8 9 10]
#define reflection_quality 30 // adjust the quality of the screenspace reflections. [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 ]
#define Roughness_Threshold 1.5 // using a curve on the roughness, make the reflections more or less visible on rough surfaces. good for hiding noise on rough materials [1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
// #define SCREENSHOT_MODE // go render mode and accumulate frames for as long as you want for max image quality.
uniform sampler2D gaux1;
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.);
// sun specular stuff
float square(float x){
return x*x;
}
float g(float NdotL, float roughness){
float alpha = square(max(roughness, 0.02));
return 2.0 * NdotL / (NdotL + sqrt(square(alpha) + (1.0 - square(alpha)) * square(NdotL)));
}
float gSimple(float dp, float roughness){
float k = roughness + 1;
k *= k/8.0;
return dp / (dp * (1.0-k) + k);
}
vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
float roughness = r; // when roughness is zero it fucks up
float alpha = square(roughness) + 1e-4;
vec3 h = normalize(l + v);
float dotLH = clamp(dot(h,l),0.,1.);
float dotNH = clamp(dot(h,n),0.,1.);
float dotNL = clamp(dot(n,l),0.,1.);
float dotNV = clamp(dot(n,v),0.,1.);
float dotVH = clamp(dot(h,v),0.,1.);
float D = alpha / (3.141592653589793*square(square(dotNH) * (alpha - 1.0) + 1.0));
float G = gSimple(dotNV, roughness) * gSimple(dotNL, roughness);
vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH);
return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7));
}
// other shit
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;
}
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)
}
void frisvad(in vec3 n, out vec3 f, out vec3 r){
if(n.z < -0.9) {
f = vec3(0.,-1,0);
r = vec3(-1, 0, 0);
} else {
float a = 1./(1.+n.z);
float b = -n.x*n.y*a;
f = vec3(1. - n.x*n.x*a, b, -n.x) ;
r = vec3(b, 1. - n.y*n.y*a , -n.y);
}
}
mat3 CoordBase(vec3 n){
vec3 x,y;
frisvad(n,x,y);
return mat3(x,y,n);
}
float unpackRoughness(float x){
float r = 1.0 - x;
return clamp(r*r,0,1);
}
vec2 R2_samples_spec(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
vec3 sampleGGXVNDF(vec3 V_, float alpha_x, float alpha_y, float U1, float U2, bool ishand){
// stretch view
vec3 V = normalize(vec3(alpha_x * V_.x, alpha_y * V_.y, V_.z));
// orthonormal basis
vec3 T1 = (V.z < 0.9999) ? normalize(cross(V, vec3(0,0,1))) : vec3(1,0,0);
vec3 T2 = cross(T1, V);
// sample point with polar coordinates (r, phi)
float a = 1.0 / (1.0 + V.z);
float r = sqrt(U1);
float phi = (U2<a) ? U2/a * 3.141592653589793 : 3.141592653589793 + (U2-a)/(1.0-a) * 3.141592653589793;
float P1 = r*cos(phi);
float P2 = r*sin(phi)*((U2<a) ? 1.0 : V.z);
// compute normal
vec3 N = P1*T1 + P2*T2 + sqrt(max(0.0, 1.0 - P1*P1 - P2*P2))*V;
// unstretch
N = normalize(vec3(alpha_x*N.x, alpha_y*N.y, max(0.0, N.z)));
return N;
}
// idk where this is from
vec3 generateUnitVector_spec(vec2 xy, float r) {
float roughness = 1.0 / (r + 0.0001);
const float TAU = 2.0*3.14159265; //
xy.x *= TAU; xy.y = xy.y * 2.0 - 1.0 ;
return vec3( max(vec2(sin(xy.x), cos(xy.x)) * sqrt(1.0 - xy.y*xy.y) ,-1.0 + (1.0-r)), roughness);
}
vec3 generateCosineVector_spec(vec3 normal, vec2 xy, float r) {
return normalize(normal + generateUnitVector_spec(xy, r));
}
vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool hand, float fres){
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 = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality*vec3(1,1,1.0);
// if(hand) dither *= 0.1 ;
vec3 spos = clipPosition*vec3(1,1,1.0) + stepv*dither;
float minZ = spos.z+stepv.z;
float maxZ = spos.z+stepv.z;
spos.xy += TAA_Offset*texelSize*0.5/1;
// for (int i = 0; i <= int(quality); i++) {
// // decode depth buffer
// vec2 testthing = hand ? spos.xy*texelSize : spos.xy/texelSize/4.0; // fix for ssr on hand
// float sp = sqrt(texelFetch2D(gaux1,ivec2(spos.xy/texelSize/4.0),0).w/65000.0);
// sp = invLinZ(sp);
// if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/1,sp);
// spos += stepv;
// //small bias
// float biasamount = 0.00015;
// if(hand) biasamount = 0.01;
// // minZ = maxZ-clamp(fres*0.0004 ,0.00004,0.0004) / ld(spos.z);
// minZ = maxZ-biasamount / ld(spos.z);
// maxZ += stepv.z;
// }
for (int i = 0; i < int(quality+1); i++) {
vec2 testthing = hand ? spos.xy : spos.xy/texelSize; // fix for ssr on hand
float sp=texelFetch2D(depthtex1,ivec2(testthing),0).x;
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)){
return vec3(spos.xy,sp);
}
spos += stepv;
//small bias
float biasamount = 0.00015;
if(hand) biasamount = 0.01;
// minZ = maxZ-clamp(fres*0.0004 ,0.00004,0.0004) / ld(spos.z);
minZ = maxZ-biasamount / ld(spos.z);
maxZ += stepv.z;
}
return vec3(1.1);
}
vec3 mix_vec3(vec3 X, vec3 Y, float A){
return X * (1.0 - A) + Y * A;
}
float mix_float(float X, float Y, float A){
return X * (1.0 - A) + Y * A;
}
// vec3 gaussblur( vec4 colorout, vec2 texcoord )
// {
// float Pi = 6.28318530718; // Pi*2
// // GAUSSIAN BLUR SETTINGS {{{
// float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
// float Quality = 3.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
// float Size = 50.0; // BLUR SIZE (Radius)
// // GAUSSIAN BLUR SETTINGS }}}
// vec2 Radius = Size/vec2(1920,1080);
// // Normalized pixel coordinates (from 0 to 1)
// vec2 uv = texcoord/vec2(1920,1080);
// // Pixel colour
// vec4 Color = texture2D(colortex3, texcoord);
// // Blur calculations
// for( float d=0.0; d<Pi; d+=Pi/Directions)
// {
// for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality)
// {
// Color += texture2D( colortex3, texcoord+vec2(cos(d),sin(d))*Radius*i);
// }
// }
// // Output to screen
// Color /= Quality * Directions - 15.0;
// colorout = Color;
// return colorout.rgb;
// }
// pain
void MaterialReflections(
inout vec3 Output,
float roughness,
vec3 f0,
vec3 albedo,
vec3 sunPos,
vec3 sunCol,
float diffuse,
float lightmap,
vec3 normal,
vec3 np3,
vec3 fragpos,
vec3 noise,
bool hand
){
vec3 Reflections_Final = Output;
float Outdoors = 0.0;
// float Outdoors = clamp((lightmap-0.5) * , 0.0,1.0);
roughness = unpackRoughness(roughness);
f0 = f0.y == 0.0 ? vec3(0.04) : f0;
mat3 basis = CoordBase(normal);
vec3 normSpaceView = -np3*basis ;
// roughness stuff
#ifdef Rough_reflections
int seed = (frameCounter%40000);
vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ;
vec3 H = sampleGGXVNDF(normSpaceView, roughness, ij.x, ij.y);
if(hand) H = normalize(vec3(0.0,0.0,1.0));
#else
vec3 H = normalize(vec3(0.0,0.0,1.0));
#endif
vec3 Ln = reflect(-normSpaceView, clamp(H,-1.0,1.0));
vec3 L = basis * Ln;
// fresnel stuff
float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0);
// vec3 F = f0 + (1.0 - f0) * fresnel;
vec3 F = mix(f0, vec3(1.0), fresnel);
vec3 rayContrib = F;
float NdotV = clamp(normalize(dot(np3, normal))*10000.,0.,1.);
bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) > 0.01;
if (Roughness_Threshold == 1.0){ hasReflections = roughness > -1; NdotV = -1.0;}
vec3 SunReflection = diffuse * GGX2(normal, -np3, sunPos, roughness, f0) * sunCol;
vec4 Reflections = vec4(0.0);
#ifdef Screen_Space_Reflections
if ( hasReflections && NdotV <= 0.0) { // Skip SSR if ray contribution is low
#ifdef SCREENSHOT_MODE
float rayQuality = reflection_quality;
#else
float rayQuality = mix_float(reflection_quality,0.0,sqrt(roughness)); // Scale quality with ray contribution
#endif
vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, rayQuality, hand, fresnel);
if (rtPos.z < 1. ){ // Reproject on previous frame
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + 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) {
Reflections.a = 1.0;
Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb;
}
}
}
#endif
// check if the f0 is within the metal ranges, then tint by albedo if it's true.
vec3 Metals = f0.y > 229.5/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0);
Reflections.rgb *= Metals;
// apply all reflections to the lighting
Reflections_Final += Reflections.rgb * luma(rayContrib);
// interpolate between the albedos and reflections using the roughness value instead of the sampling.
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0.y) * -4),0,1);
#ifdef Rough_reflections
Output = hand ? mix_vec3(Output, Reflections_Final, visibilityFactor) : Reflections_Final;
#else
Output = mix_vec3(Output, Reflections_Final, visibilityFactor);
#endif
Output += SunReflection;
}

View File

@ -0,0 +1,48 @@
//Original star code : https://www.shadertoy.com/view/Md2SR3 , optimised
// Return random noise in the range [0.0, 1.0], as a function of x.
float hash12(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
}
// Convert Noise2d() into a "star field" by stomping everthing below fThreshhold to zero.
float NoisyStarField( in vec2 vSamplePos, float fThreshhold )
{
float StarVal = hash12( vSamplePos );
StarVal = clamp(StarVal/(1.0 - fThreshhold) - fThreshhold/(1.0 - fThreshhold),0.0,1.0);
return StarVal;
}
// Stabilize NoisyStarField() by only sampling at integer values.
float StableStarField( in vec2 vSamplePos, float fThreshhold )
{
// Linear interpolation between four samples.
// Note: This approach has some visual artifacts.
// There must be a better way to "anti alias" the star field.
float fractX = fract( vSamplePos.x );
float fractY = fract( vSamplePos.y );
vec2 floorSample = floor( vSamplePos );
float v1 = NoisyStarField( floorSample, fThreshhold );
float v2 = NoisyStarField( floorSample + vec2( 0.0, 1.0 ), fThreshhold );
float v3 = NoisyStarField( floorSample + vec2( 1.0, 0.0 ), fThreshhold );
float v4 = NoisyStarField( floorSample + vec2( 1.0, 1.0 ), fThreshhold );
float StarVal = v1 * ( 1.0 - fractX ) * ( 1.0 - fractY )
+ v2 * ( 1.0 - fractX ) * fractY
+ v3 * fractX * ( 1.0 - fractY )
+ v4 * fractX * fractY;
return StarVal;
}
float stars(vec3 fragpos){
float elevation = clamp(fragpos.y,0.,1.);
vec2 uv = fragpos.xz/(1.+elevation);
return StableStarField(uv*700.,0.999)/4.*(0.3-0.3*rainStrength);
}

View File

@ -0,0 +1,19 @@
vec4 smoothfilter(in sampler2D tex, in vec2 uv, in vec2 textureResolution)
{
uv = uv*textureResolution + 0.5;
vec2 iuv = floor( uv );
vec2 fuv = fract( uv );
uv = iuv + (fuv*fuv)*(3.0-2.0*fuv);
uv = uv/textureResolution - 0.5/textureResolution;
return texture2D( tex, uv);
}
float shadowsmoothfilter(in sampler2DShadow tex, in vec3 uv,in float textureResolution)
{
uv.xy = uv.xy*textureResolution + 0.5;
vec2 iuv = floor( uv.xy );
vec2 fuv = fract( uv.xy );
uv.xy = iuv + (fuv*fuv)*(3.0-2.0*fuv);
uv.xy = uv.xy/textureResolution - 0.5/textureResolution;
return shadow2D( tex, uv).x;
}

View File

@ -0,0 +1,196 @@
#define TIME_MULT 1.0
#define TIME (frameTimeCounter * TIME_MULT)
const float PI = acos(-1.0);
const float TAU = PI * 2.0;
const float hPI = PI * 0.5;
const float rPI = 1.0 / PI;
const float rTAU = 1.0 / TAU;
const float PHI = sqrt(5.0) * 0.5 + 0.5;
const float rLOG2 = 1.0 / log(2.0);
const float goldenAngle = TAU / PHI / PHI;
#define clamp01(x) clamp(x, 0.0, 1.0)
#define max0(x) max(x, 0.0)
#define min0(x) min(x, 0.0)
#define max3(a) max(max(a.x, a.y), a.z)
#define min3(a) min(min(a.x, a.y), a.z)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define fsign(x) (clamp01(x * 1e35) * 2.0 - 1.0)
#define fstep(x,y) clamp01((y - x) * 1e35)
#define diagonal2(m) vec2((m)[0].x, (m)[1].y)
#define diagonal3(m) vec3(diagonal2(m), m[2].z)
#define diagonal4(m) vec4(diagonal3(m), m[2].w)
#define transMAD(mat, v) (mat3(mat) * (v) + (mat)[3].xyz)
#define projMAD(mat, v) (diagonal3(mat) * (v) + (mat)[3].xyz)
#define encodeColor(x) (x * 0.00005)
#define decodeColor(x) (x * 20000.0)
#define cubeSmooth(x) (x * x * (3.0 - 2.0 * x))
#define lumCoeff vec3(0.2125, 0.7154, 0.0721)
float facos(const float sx){
float x = clamp(abs( sx ),0.,1.);
float a = sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 );
return sx > 0. ? a : PI - a;
//float c = clamp(-sx * 1e35, 0., 1.);
//return c * pi + a * -(c * 2. - 1.); //no conditional version
}
vec2 sincos(float x){
return vec2(sin(x), cos(x));
}
vec2 circlemap(float i, float n){
return sincos(i * n * goldenAngle) * sqrt(i);
}
vec3 circlemapL(float i, float n){
return vec3(sincos(i * n * goldenAngle), sqrt(i));
}
vec3 calculateRoughSpecular(const float i, const float alpha2, const int steps) {
float x = (alpha2 * i) / (1.0 - i);
float y = i * float(steps) * 64.0 * 64.0 * goldenAngle;
float c = inversesqrt(x + 1.0);
float s = sqrt(x) * c;
return vec3(cos(y) * s, sin(y) * s, c);
}
vec3 clampNormal(vec3 n, vec3 v){
float NoV = clamp( dot(n, -v), 0., 1. );
return normalize( NoV * v + n );
}
vec3 srgbToLinear(vec3 srgb){
return mix(
srgb / 12.92,
pow(.947867 * srgb + .0521327, vec3(2.4) ),
step( .04045, srgb )
);
}
vec3 linearToSRGB(vec3 linear){
return mix(
linear * 12.92,
pow(linear, vec3(1./2.4) ) * 1.055 - .055,
step( .0031308, linear )
);
}
vec3 blackbody(float Temp)
{
float t = pow(Temp, -1.5);
float lt = log(Temp);
vec3 col = vec3(0.0);
col.x = 220000.0 * t + 0.58039215686;
col.y = 0.39231372549 * lt - 2.44549019608;
col.y = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : col.y;
col.z = 0.76078431372 * lt - 5.68078431373;
col = clamp01(col);
col = Temp < 1000. ? col * Temp * 0.001 : col;
return srgbToLinear(col);
}
float calculateHardShadows(float shadowDepth, vec3 shadowPosition, float bias) {
if(shadowPosition.z >= 1.0) return 1.0;
return 1.0 - fstep(shadowDepth, shadowPosition.z - bias);
}
vec3 genUnitVector(vec2 xy) {
xy.x *= TAU; xy.y = xy.y * 2.0 - 1.0;
return vec3(sincos(xy.x) * sqrt(1.0 - xy.y * xy.y), xy.y);
}
vec2 rotate(vec2 x, float r){
vec2 sc = sincos(r);
return mat2(sc.x, -sc.y, sc.y, sc.x) * x;
}
vec3 cartToSphere(vec2 coord) {
coord *= vec2(TAU, PI);
vec2 lon = sincos(coord.x) * sin(coord.y);
return vec3(lon.x, 2.0/PI*coord.y-1.0, lon.y);
}
vec2 sphereToCart(vec3 dir) {
float lonlat = atan(-dir.x, -dir.z);
return vec2(lonlat * rTAU +0.5,0.5*dir.y+0.5);
}
mat3 getRotMat(vec3 x,vec3 y){
float d = dot(x,y);
vec3 cr = cross(y,x);
float s = length(cr);
float id = 1.-d;
vec3 m = cr/s;
vec3 m2 = m*m*id+d;
vec3 sm = s*m;
vec3 w = (m.xy*id).xxy*m.yzz;
return mat3(
m2.x, w.x-sm.z, w.y+sm.y,
w.x+sm.z, m2.y, w.z-sm.x,
w.y-sm.y, w.z+sm.x, m2.z
);
}
// No intersection if returned y component is < 0.0
vec2 rsi(vec3 position, vec3 direction, float radius) {
float PoD = dot(position, direction);
float radiusSquared = radius * radius;
float delta = PoD * PoD + radiusSquared - dot(position, position);
if (delta < 0.0) return vec2(-1.0);
delta = sqrt(delta);
return -PoD + vec2(-delta, delta);
}
float HaltonSeq3(int index)
{
float r = 0.;
float f = 1.;
int i = index;
while (i > 0)
{
f /= 3.0;
r += f * (i % 3);
i = int(i / 3.0);
}
return r;
}
float HaltonSeq2(int index)
{
float r = 0.;
float f = 1.;
int i = index;
while (i > 0)
{
f /= 2.0;
r += f * (i % 2);
i = int(i / 2.0);
}
return r;
}

View File

@ -0,0 +1,342 @@
#define VOLUMETRIC_CLOUDS// if you don't like the noise on the default cloud settings, turn up the cloud samples. if that hurts performance too much, turn down the clouds quality.
#define cloud_LevelOfDetail 1 // Number of fbm noise iterations for on-screen clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
#define cloud_ShadowLevelOfDetail 0 // Number of fbm noise iterations for the shadowing of on-screen clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
#define cloud_LevelOfDetailLQ 1 // Number of fbm noise iterations for reflected clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
#define cloud_ShadowLevelOfDetailLQ 0 // Number of fbm noise iterations for the shadowing of reflected clouds (-1 is no fbm) [-1 0 1 2 3 4 5 6 7 8]
#define minRayMarchSteps 20 // Number of ray march steps towards zenith for on-screen clouds [20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
#define maxRayMarchSteps 30 // Number of ray march steps towards horizon for on-screen clouds [5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200]
#define minRayMarchStepsLQ 10 // Number of ray march steps towards zenith for reflected clouds [5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100]
#define maxRayMarchStepsLQ 30 // Number of ray march steps towards horizon for reflected clouds [ 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100]
#define cloudMieG 0.5 // Values close to 1 will create a strong peak of luminance around the sun and weak elsewhere, values close to 0 means uniform fog. [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define cloudMieG2 0.9 // Multiple scattering approximation. Values close to 1 will create a strong peak of luminance around the sun and weak elsewhere, values close to 0 means uniform fog. [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define cloudMie2Multiplier 0.7 // Multiplier for multiple scattering approximation [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Cloud_top_cutoff 1.0 // the cutoff point on the top part of the cloud. [ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.5 3.0 4 5 6 7 8 9]
#define Cloud_base_cutoff 5.0 // the cutoff point on the base of the cloud. [0.1 1 2 4 6 8 10 12 14 16 18 20]
#ifdef HQ_CLOUDS
int maxIT_clouds = minRayMarchSteps;
int maxIT = maxRayMarchSteps;
#else
int maxIT_clouds = minRayMarchStepsLQ;
int maxIT = maxRayMarchStepsLQ;
#endif
uniform vec3 sunPosition;
#define cloudCoverage 0.4 // Cloud coverage [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0]
// #define Rain_coverage 0.8 // how much the coverage of the clouds change during rain [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 3.0 4.0 5.0]
/////// shape
#define cloudDensity 0.0514 // Cloud Density, 0.04-0.06 is around irl values [0.0010 0.0011 0.0013 0.0015 0.0017 0.0020 0.0023 0.0026 0.0030 0.0034 0.0039 0.0045 0.0051 0.0058 0.0067 0.0077 0.0088 0.0101 0.0115 0.0132 0.0151 0.0173 0.0199 0.0228 0.0261 0.0299 0.0342 0.0392 0.0449 0.0514 0.0589 0.0675 0.0773 0.0885 0.1014 0.1162 0.1331 0.1524 0.1746 0.2000 0.3 0.35 0.4 0.45 0.5 0.6 0.7 0.8 0.9 1.0]
#define fbmAmount2 1 // Amount of noise added to the cloud shape [0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 1.02 1.04 1.06 1.08 1.10 1.12 1.14 1.16 1.18 1.20 1.22 1.24 1.26 1.28 1.30 1.32 1.34 1.36 1.38 1.40 1.42 1.44 1.46 1.48 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00]
#define fbmPower1 3.00 // Higher values increases high frequency details of the cloud shape [1.0 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 3.02 3.04 3.06 3.08 3.10 3.12 3.14 3.16 3.18 3.20 3.22 3.24 3.26 3.28 3.30 3.32 3.34 3.36 3.38 3.40 3.42 3.44 3.46 3.48 3.50 3.52 3.54 3.56 3.58 3.60 3.62 3.64 3.66 3.68 3.70 3.72 3.74 3.76 3.78 3.80 3.82 3.84 3.86 3.88 3.90 3.92 3.94 3.96 3.98 4.00 5. 6. 7. 8. 9. 10.]
#define fbmPower2 1.50 // Lower values increases high frequency details of the cloud shape [1.00 1.50 1.52 1.54 1.56 1.58 1.60 1.62 1.64 1.66 1.68 1.70 1.72 1.74 1.76 1.78 1.80 1.82 1.84 1.86 1.88 1.90 1.92 1.94 1.96 1.98 2.00 2.02 2.04 2.06 2.08 2.10 2.12 2.14 2.16 2.18 2.20 2.22 2.24 2.26 2.28 2.30 2.32 2.34 2.36 2.38 2.40 2.42 2.44 2.46 2.48 2.50 2.52 2.54 2.56 2.58 2.60 2.62 2.64 2.66 2.68 2.70 2.72 2.74 2.76 2.78 2.80 2.82 2.84 2.86 2.88 2.90 2.92 2.94 2.96 2.98 3.00 3.02 3.04 3.06 3.08 3.10 3.12 3.14 3.16 3.18 3.20 3.22 3.24 3.26 3.28 3.30 3.32 3.34 3.36 3.38 3.40 3.42 3.44 3.46 3.48 3.50 3.52 3.54 3.56 3.58 3.60 3.62 3.64 3.66 3.68 3.70 3.72 3.74 3.76 3.78 3.80 3.82 3.84 3.86 3.88 3.90 3.92 3.94 3.96 3.98 4.00 5. 6. 7. 8. 9. 10.]
/////// lighting
#define Shadow_brightness 0.5 // how dark / bright you want the shadowed part of the clouds to be. low values can look weird. [ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 3.0 4.0 5.0 6.0]
#define self_shadow_samples 3.0 // amount of interations for cloud self shadows. longer/shorter cloud self shadows. [ 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0]
#define Cloud_Size 35 // [1 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100]
#define Cloud_Height 319 // [-300 -290 -280 -270 -260 -250 -240 -230 -220 -210 -200 -190 -180 -170 -160 -150 -140 -130 -120 -110 -100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 319 320]
// #define Dynamic_weather // a
#define Dynamic_sky_day -1 // -1 MEANS THIS IS OFF. select which day of the 8 to the clouds should take shape in [0 1 2 3 4 5 6 7 ]
#define Dynamic_Sky // day 1: partly cloudy. day 2: really cloudy, misty. day 3: mostly clear. day 4: cloudy. day 5: cloudy again. day 6: scattered clouds. day 7: partly cloudy. day 8: clear
#define High_Altitude_Clouds // a layer of clouds way up yonder
/////// other
#define Puddle_size 5 // size of puddles [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191 20 21 22 23 24 25]
#define Puddle_Coverage 0.7 // the amount of cround the puddles cover [ 0.50 0.49 0.48 0.47 0.46 0.45 0.44 0.44 0.43 0.42 0.41 0.40 0.39 0.38 0.37 0.36 0.35 0.34 0.33 0.32 0.31 0.30 0.29 0.28 0.27 0.26 0.25 0.24 0.23 0.22 0.21 0.20 0.19 0.18 0.17 0.16 0.15 0.14 0.13 0.12 0.11 0.10 0.09 0.08 0.07 0.06 0.05 0.04 0.03 0.02 0.01 0.0]
#define flip_the_clouds 1 // what was once above is now below [1 -1]
#define cloud_speed 1 // how [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2.0 3.0 5.0 10.0 25.0 50.0 100.0 200.0]
#ifdef HQ_CLOUDS
const int cloudLoD = cloud_LevelOfDetail;
const int cloudShadowLoD = cloud_ShadowLevelOfDetail;
#else
const int cloudLoD = cloud_LevelOfDetailLQ;
const int cloudShadowLoD = cloud_ShadowLevelOfDetailLQ;
#endif
uniform sampler2D colortex4;//Skybox
uniform float wetness;
uniform vec4 Moon_Weather_properties;
// David Hoskins' Hash without Sine https://www.shadertoy.com/view/4djSRW
vec3 hash31(float p)
{
vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973));
p3 += dot(p3, p3.yzx+33.33);
return fract((p3.xxy+p3.yzz)*p3.zyx);
}
float speed = floor(frameTimeCounter);
vec3 rand_pos = hash31(speed) * 6.28;
vec3 lighting_pos = vec3(sin(1.57 + rand_pos.x), sin(rand_pos.y), sin(rand_pos.z));
// vec3 lighting_pos = vec3(1,3 , 1);
vec3 lightSource = normalize(lighting_pos);
vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource;
vec3 WsunVec = normalize(mat3(gbufferModelViewInverse) * viewspace_sunvec);
float timing = dot(lighting_pos, vec3(1.0));
float flash = max(sin(frameTimeCounter*5) * timing,0.0);
vec3 srgbToLinear(vec3 srgb){
return mix(
srgb / 12.92,
pow(.947867 * srgb + .0521327, vec3(2.4) ),
step( .04045, srgb )
);
}
vec3 blackbody(float Temp)
{
float t = pow(Temp, -1.5);
float lt = log(Temp);
vec3 col = vec3(0.0);
col.x = 220000.0 * t + 0.58039215686;
col.y = 0.39231372549 * lt - 2.44549019608;
col.y = Temp > 6500. ? 138039.215686 * t + 0.72156862745 : col.y;
col.z = 0.76078431372 * lt - 5.68078431373;
col = clamp(col,0,1);
col = Temp < 1000. ? col * Temp * 0.001 : col;
return srgbToLinear(col);
}
// vec3 SunCol = vec3(1 ,0.3 ,0.8) ;
vec3 SunCol = vec3(0.25 ,0.5 ,1.0)*flash * blackbody( rand_pos.y* 2000);
// vec3 SunCol = vec3(0.0);
float cloud_height = 1500.;
float maxHeight = 4000.;
//3D noise from 2d texture
float densityAtPos(in vec3 pos){
pos /= 18.;
pos.xz *= 0.5;
vec3 p = floor(pos);
vec3 f = fract(pos);
vec2 uv = p.xz + f.xz + p.y * vec2(0.0,193.0);
vec2 coord = uv / 512.0;
//Te y channel has an offset to avoid using two textures fetches
vec2 xy = texture2D(noisetex, coord).yx;
return mix(xy.r,xy.g, f.y);
}
float CloudLarge = 1.0;
float CloudSmall = 1.0;
float coverage = 1.0;
float cloudshape = 0;
// vec2 cloud_movement = vec2( sin(frameTimeCounter/2000)*2 ,-cos(frameTimeCounter/2000)*2) * MOVEMENT;
vec3 cloud_movement1 = vec3(frameTimeCounter)*0.1 ;
//Cloud without 3D noise, is used to exit early lighting calculations if there is no cloud
float cloudCov(in vec3 pos,vec3 samplePos){
CloudLarge = texture2D(noisetex, samplePos.xz/22500 + frameTimeCounter/500. ).b*2.0;
coverage = CloudLarge +0.5;
float mult = max( (4000.0-pos.y) / 1000, 0);
cloudshape = coverage - mult ;
return cloudshape;
}
//Erode cloud with 3d Perlin-worley noise, actual cloud value
float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD){
float noise = 0.0 ;
float totalWeights = 0.0;
float pw = log(fbmPower1);
float pw2 = log(fbmPower2);
float swirl = (1-texture2D(noisetex, samplePos.xz/5000 ).b)*8;
for (int i = 0; i <= LoD; i++){
float weight = exp(-i*pw2);
noise += weight - densityAtPos(samplePos *(8. )* exp(i*pw) )*weight ;
totalWeights += weight ;
}
noise /= totalWeights;
noise = noise*noise;
noise *= clamp(1.0 - cloudshape,0.0,1.0);
float cloud = max(cov-noise*noise*(1.)*fbmAmount2,0.0);
return cloud;
}
float getCloudDensity(in vec3 pos, in int LoD){
vec3 samplePos = pos*vec3(1.0,1./48.,1.0)/4 - frameTimeCounter/2;
float coverageSP = cloudCov(pos,samplePos);
if (coverageSP > 0.001) {
if (LoD < 0) return max(coverageSP - 0.27*fbmAmount2,0.0);
return cloudVol(pos,samplePos,coverageSP, LoD);
} else return 0.0;
}
//Mie phase function
float phaseg(float x, float g){
float gg = g * g;
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) /3.14;
}
vec3 startOffset = vec3(0);
vec4 renderClouds(vec3 fragpositi, vec3 color,float dither,vec3 sunColor,vec3 moonColor,vec3 avgAmbient,float dither2) {
#ifndef VOLUMETRIC_CLOUDS
return vec4(0.0,0.0,0.0,1.0);
#endif
//project pixel position into projected shadowmap space
vec4 fragposition = gbufferModelViewInverse*vec4(fragpositi,1.0);
vec3 worldV = normalize(fragposition.rgb);
float VdotU = worldV.y;
// worldV.y += 0.1 ;
//project view origin into projected shadowmap space
vec4 start = (gbufferModelViewInverse*vec4(0.0,0.0,0.,1.));
vec3 dV_view = worldV;
vec3 progress_view = dV_view*dither+cameraPosition;
float testdither = dither ;
float vL = 0.0;
float total_extinction = 1.0;
maxIT_clouds = int(clamp( maxIT_clouds /sqrt(exp2(VdotU)),0.0, maxIT*1.0));
float distW = length(worldV);
worldV = normalize(worldV)*100000. + cameraPosition; //makes max cloud distance not dependant of render distance
dV_view = normalize(dV_view);
// maxHeight = maxHeight * (1+testCloudheight_variation);
int Flip_clouds = 1;
if (worldV.y < cloud_height) Flip_clouds = -1;
//setup ray to start at the start of the cloud plane and end at the end of the cloud plane
dV_view *= max(maxHeight - cloud_height, 0.0)/dV_view.y/(maxIT_clouds);
startOffset = dV_view*testdither;
vec3 camPos = Flip_clouds*(cameraPosition);
progress_view = (startOffset) + camPos + dV_view*((cloud_height)-camPos.y)/dV_view.y ;
float shadowStep = 240.;
vec3 dV_Sun = Flip_clouds * normalize( mat3(gbufferModelViewInverse) * viewspace_sunvec ) * shadowStep;
float mult = length(dV_view);
color = vec3(0.0);
total_extinction = 1.0;
float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpositi));
float mieDay = phaseg(SdotV, 0.8);
float mie2 = phaseg(SdotV, 0.5);
// vec3 SunCol = vec3(1.0,0.5,0.5) * flashing ;
vec3 sunContribution = mieDay*SunCol*3.14;
// float darkness = texture2D(noisetex, progress_view.xz/120500).b;
// vec3 skyCol0 = (avgAmbient*4.0*3.1415*8/3.0 ) ;
vec3 skyCol0 = gl_Fog.color.rgb * 0.01;
for(int i=0;i<maxIT_clouds;i++) {
float cloud = getCloudDensity(progress_view, cloudLoD);
float densityofclouds = max(cloudDensity,0.) ;
if(cloud > 0.0001){
float muS = cloud*densityofclouds;
float muE = cloud*densityofclouds;
float muEshD = 0.0;
if (sunContribution.g > 1e-5){
for (int j=0; j < 3; j++){
vec3 shadowSamplePos = progress_view + dV_Sun * ((j+0.5) + (j *2)) ;
// get the cloud density and apply it
if (shadowSamplePos.y < maxHeight){
float cloudS = getCloudDensity(shadowSamplePos, cloudShadowLoD);
muEshD += cloudS*densityofclouds*shadowStep;
}
}
}
float powder = muE * 100; // powder....
float sunShadow = exp(-muEshD*0.25); // this simulates the direct light, and the scattering of it
float front_lit = sunShadow;
float back_lit = pow(muS*(cloud+muE), max(1-cloud*2,0.0)*2);
float innerSeams = mix(front_lit, back_lit*0.5, clamp(mie2,0.,1.) ) ;
vec3 SunCloud_lighting = sunContribution * innerSeams * mie2;
vec3 AmbientCloud_Lighting = skyCol0 * powder ;
vec3 S = SunCloud_lighting + AmbientCloud_Lighting ; // combine all the combined
vec3 Sint= (S - S * exp(-mult*muE)) / muE;
color += max(muS*Sint*total_extinction,0.0);
total_extinction *= max(exp(-muE*mult),0);
if (total_extinction < 1e-5) break;
}
progress_view += dV_view;
}
// vec3 normView = normalize(dV_view);
// // Assume fog color = sky gradient at long distance
// vec3 fogColor = skyFromTex(normView, colortex4)/150.;
// float dist = (cloud_height - cameraPosition.y)/normalize(dV_view).y;
// float fog = exp(-dist/15000.0*(1.0+rainCloudwetness*8.));
float cosY = normalize(dV_view).y;
return mix(vec4(color,clamp(total_extinction*(1.0+1/250.)-1/250.,0.0,1.0)),vec4(0.0,0.0,0.0,1.0), 1-smoothstep(0.02,0.15,cosY));
}

View File

@ -0,0 +1,118 @@
#define VL_SAMPLES2 6 //[4 6 8 10 12 14 16 20 24 30 40 50]
#define Ambient_Mult 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0 5.0 6.0 10.0]
#define SEA_LEVEL 70 //[0 10 20 30 40 50 60 70 80 90 100 110 120 130 150 170 190] //The volumetric light uses an altitude-based fog density, this is where fog density is the highest, adjust this value according to your world.
#define ATMOSPHERIC_DENSITY 1.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 4.0 5.0 7.5 10.0 12.5 15.0 20.]
#define fog_mieg1 0.40 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
#define fog_mieg2 0.10 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0]
#define fog_coefficientRayleighR 5.8 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientRayleighG 1.35 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientRayleighB 3.31 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientMieR 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientMieG 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define fog_coefficientMieB 3.0 //[0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0]
#define Underwater_Fog_Density 1.0 //[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.75 0.8 0.85 0.9 0.95 1.0 1.5 2.0 3.0 4.0]
float phaseRayleigh(float cosTheta) {
const vec2 mul_add = vec2(0.1, 0.28) /acos(-1.0);
return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation
}
float cloudVol2(in vec3 pos){
vec3 samplePos = pos*vec3(1.0,1./16.,1.0)+frameTimeCounter*vec3(0.5,0.,0.5)*5.;
float coverage = mix(exp2(-(pos.y-SEA_LEVEL)*(pos.y-SEA_LEVEL)/10000.),1.0,rainStrength*0.5);
float noise = densityAtPos(samplePos*12.);
float unifCov = exp2(-max(pos.y-SEA_LEVEL,0.0)/50.);
float cloud = pow(clamp(coverage-noise-0.76,0.0,1.0),2.)*1200./0.23/(coverage+0.01)*VFAmount*600+unifCov*60.*fogAmount;
return cloud;
}
mat2x3 getVolumetricRays(float dither,vec3 fragpos) {
//project pixel position into projected shadowmap space
vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
//project view origin into projected shadowmap space
vec3 start = toShadowSpaceProjected(vec3(0.));
//rayvector into projected shadow map space
//we can use a projected vector because its orthographic projection
//however we still have to send it to curved shadow map space every step
vec3 dV = (fragposition-start);
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
float maxLength = min(length(dVWorld),256.0)/length(dVWorld);
dV *= maxLength;
dVWorld *= maxLength;
//apply dither
vec3 progress = start.xyz;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
vec3 vL = vec3(0.);
float SdotV = dot(sunVec,normalize(fragpos))*lightCol.a;
float dL = length(dVWorld);
//Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx)
float mie = max(phaseg(SdotV,fog_mieg1),1.0/13.0);
float rayL = phaseRayleigh(SdotV);
// wpos.y = clamp(wpos.y,0.0,1.0);
vec3 ambientCoefs = dVWorld/dot(abs(dVWorld),vec3(1.));
vec3 ambientLight = ambientUp*clamp(ambientCoefs.y,0.,1.);
ambientLight += ambientDown*clamp(-ambientCoefs.y,0.,1.);
ambientLight += ambientRight*clamp(ambientCoefs.x,0.,1.);
ambientLight += ambientLeft*clamp(-ambientCoefs.x,0.,1.);
ambientLight += ambientB*clamp(ambientCoefs.z,0.,1.);
ambientLight += ambientF*clamp(-ambientCoefs.z,0.,1.);
vec3 skyCol0 = ambientLight*2.*eyeBrightnessSmooth.y/vec3(240.)*Ambient_Mult*2.0/PI;
vec3 sunColor = lightCol.rgb;
vec3 rC = vec3(fog_coefficientRayleighR*1e-6, fog_coefficientRayleighG*1e-5, fog_coefficientRayleighB*1e-5);
vec3 mC = vec3(fog_coefficientMieR*1e-6, fog_coefficientMieG*1e-6, fog_coefficientMieB*1e-6);
float mu = 1.0;
float muS = 1.0*mu;
vec3 absorbance = vec3(1.0);
float expFactor = 11.0;
for (int i=0;i<VL_SAMPLES2;i++) {
float d = (pow(expFactor, float(i+dither)/float(VL_SAMPLES2))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(VL_SAMPLES2)) * log(expFactor) / float(VL_SAMPLES2)/(expFactor-1.0);
progress = start.xyz + d*dV;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
//project into biased shadowmap space
float distortFactor = calcDistort(progress.xy);
vec3 pos = vec3(progress.xy*distortFactor, progress.z);
float densityVol = cloudVol2(progressW);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
//Water droplets(fog)
float density = densityVol*ATMOSPHERIC_DENSITY*mu*200.;
//Just air
vec2 airCoef = exp2(-max(progressW.y-SEA_LEVEL,0.0)/vec2(8.0e3, 1.2e3)*vec2(6.,7.0))*6.0;
//Pbr for air, yolo mix between mie and rayleigh for water droplets
vec3 rL = rC*(airCoef.x+density*0.15);
vec3 m = (airCoef.y+density*1.85)*mC;
vec3 vL0 = sunColor*sh*(rayL*rL+m*mie) + skyCol0*(rL+m);
vL += (vL0 - vL0 * exp(-dot(rL+m, vec3(0.22,0.71,0.07))*dd*dL)) / (dot(rL+m, vec3(0.22,0.71,0.07))+0.00000001)*absorbance;
absorbance *= clamp(exp(-dot(rL+m, vec3(0.22,0.71,0.07))*dd*dL),0.0,1.0);
}
return mat2x3(vL,absorbance);
}

View File

@ -0,0 +1,38 @@
float getWaterHeightmap(vec2 posxz, float waveM, float waveZ, float iswater) {
vec2 pos = posxz*4.0;
float moving = clamp(iswater*2.-1.0,0.0,1.0);
vec2 movement = vec2(-0.02*frameTimeCounter*moving);
float caustic = 0.0;
float weightSum = 0.0;
float radiance = 2.39996;
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
for (int i = 0; i < 4; i++){
vec2 displ = texture2D(noisetex, pos/32.0/1.74/1.74 + movement).bb*2.0-1.0;
pos = rotationMatrix * pos;
caustic += sin(dot((pos+vec2(moving*frameTimeCounter))/1.74/1.74 * exp2(0.8*i) + displ*2.0,vec2(0.5)))*exp2(-0.8*i);
weightSum += exp2(-i);
}
return caustic * weightSum / 300.;
}
vec3 getWaveHeight(vec2 posxz, float iswater){
vec2 coord = posxz;
float deltaPos = 0.25;
float waveZ = mix(20.0,0.25,iswater);
float waveM = mix(0.0,4.0,iswater);
float h0 = getWaterHeightmap(coord, waveM, waveZ, iswater);
float h1 = getWaterHeightmap(coord + vec2(deltaPos,0.0), waveM, waveZ, iswater);
float h3 = getWaterHeightmap(coord + vec2(0.0,deltaPos), waveM, waveZ, iswater);
float xDelta = ((h1-h0))/deltaPos*2.;
float yDelta = ((h3-h0))/deltaPos*2.;
vec3 wave = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0)));
return wave;
}

View File

@ -0,0 +1,21 @@
#define Dirt_Amount 0.14 //How much dirt there is in water [0.0 0.04 0.08 0.12 0.16 0.2 0.24 0.28 0.32 0.36 0.4 0.44 0.48 0.52 0.56 0.6 0.64 0.68 0.72 0.76 0.8 0.84 0.88 0.92 0.96 1.0 1.04 1.08 1.12 1.16 1.2 1.24 1.28 1.32 1.36 1.4 1.44 1.48 1.52 1.56 1.6 1.64 1.68 1.72 1.76 1.8 1.84 1.88 1.92 1.96 2.0 ]
#define Dirt_Scatter_R 0.6 //How much dirt diffuses red [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Dirt_Scatter_G 0.6 //How much dirt diffuses green [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Dirt_Scatter_B 0.6 //How much dirt diffuses blue [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define Dirt_Absorb_R 1.65 //How much dirt absorbs red [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
#define Dirt_Absorb_G 1.85 //How much dirt absorbs green [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
#define Dirt_Absorb_B 2.05 //How much dirt absorbs blue [0.0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.32 0.34 0.36 0.38 0.4 0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.58 0.6 0.62 0.64 0.66 0.68 0.7 0.72 0.74 0.76 0.78 0.8 0.82 0.84 0.86 0.88 0.9 0.92 0.94 0.96 0.98 1.0 1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2 1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4 1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6 1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8 1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2.0 ]
#define Water_Absorb_R 0.2629 //How much water absorbs red [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
#define Water_Absorb_G 0.0565 //How much water absorbs green [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
#define Water_Absorb_B 0.01011 //How much water absorbs blue [0.0 0.0025 0.005 0.0075 0.01 0.0125 0.015 0.0175 0.02 0.0225 0.025 0.0275 0.03 0.0325 0.035 0.0375 0.04 0.0425 0.045 0.0475 0.05 0.0525 0.055 0.0575 0.06 0.0625 0.065 0.0675 0.07 0.0725 0.075 0.0775 0.08 0.0825 0.085 0.0875 0.09 0.0925 0.095 0.0975 0.1 0.1025 0.105 0.1075 0.11 0.1125 0.115 0.1175 0.12 0.1225 0.125 0.1275 0.13 0.1325 0.135 0.1375 0.14 0.1425 0.145 0.1475 0.15 0.1525 0.155 0.1575 0.16 0.1625 0.165 0.1675 0.17 0.1725 0.175 0.1775 0.18 0.1825 0.185 0.1875 0.19 0.1925 0.195 0.1975 0.2 0.2025 0.205 0.2075 0.21 0.2125 0.215 0.2175 0.22 0.2225 0.225 0.2275 0.23 0.2325 0.235 0.2375 0.24 0.2425 0.245 0.2475 0.25 ]
#define Dirt_Mie_Phase 0.4 //Values close to 1 will create a strong peak around the sun and weak elsewhere, values close to 0 means uniform fog. [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 ]
#define rayMarchSampleCount 2 //Number of samples used for the volumetric underwater fog [1 2 3 4 6 8 12 16 32 64]
#define Water_Top_Layer 62.90 // When under water and when lightMapDepthEstimate is turned off. Assumes the top layer of the water is at this height (minecraft y position) for underwater lighting calculations. If not set correctly, underwater will look incorrect.[0.90 1.90 2.90 3.90 4.90 5.90 6.90 7.90 8.90 9.90 10.90 11.90 12.90 13.90 14.90 15.90 16.90 17.90 18.90 19.90 20.90 21.90 22.90 23.90 24.90 25.90 26.90 27.90 28.90 29.90 30.90 31.90 32.90 33.90 34.90 35.90 36.90 37.90 38.90 39.90 40.90 41.90 42.90 43.90 44.90 45.90 46.90 47.90 48.90 49.90 50.90 51.90 52.90 53.90 54.90 55.90 56.90 57.90 58.90 59.90 60.90 61.90 62.90 63.90 64.90 65.90 66.90 67.90 68.90 69.90 70.90 71.90 72.90 73.90 74.90 75.90 76.90 77.90 78.90 79.90 80.90 81.90 82.90 83.90 84.90 85.90 86.90 87.90 88.90 89.90 90.90 91.90 92.90 93.90 94.90 95.90 96.90 97.90 98.90 99.90 100.90 101.90 102.90 103.90 104.90 105.90 106.90 107.90 108.90 109.90 110.90 111.90 112.90 113.90 114.90 115.90 116.90 117.90 118.90 119.90 120.90 121.90 122.90 123.90 124.90 125.90 126.90 127.90 128.90 129.90 130.90 131.90 132.90 133.90 134.90 135.90 136.90 137.90 138.90 139.90 140.90 141.90 142.90 143.90 144.90 145.90 146.90 147.90 148.90 149.90 150.90 151.90 152.90 153.90 154.90 155.90 156.90 157.90 158.90 159.90 160.90 161.90 162.90 163.90 164.90 165.90 166.90 167.90 168.90 169.90 170.90 171.90 172.90 173.90 174.90 175.90 176.90 177.90 178.90 179.90 180.90 181.90 182.90 183.90 184.90 185.90 186.90 187.90 188.90 189.90 190.90 191.90 192.90 193.90 194.90 195.90 196.90 197.90 198.90 199.90]
//#define lightMapDepthEstimation // If turned off, will use the player eye position and the Water_Top_Layer option to determine how deep the player is in water. It can look wrong in a lot of cases, and using minecraft light levels instead improves this but will look worse in oceans, lakes and rivers.

View File

@ -0,0 +1,121 @@
#shaders/shaders.properties
#Minecraft Settings
oldLighting=false
underwaterOverlay = false
sun=false
moon=true
stars=false
vignette=false
dynamicHandLight=true
#Get the correct alpha value : S_A*(1-DST_A)+DST_A
blend.gbuffers_terrain=off
blend.gbuffers_textured= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_textured_lit= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_weather= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_water= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_hand_water= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_entities = off
blend.gbuffers_hand = off
blend.gbuffers_block= off
blend.gbuffers_basic= off
blend.gbuffers_damagedblock= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_skytextured=off
alphaTest.gbuffers_entities=GREATER 0.1
alphaTest.gbuffers_weather=false
alphaTest.gbuffers_water=false
alphaTest.gbuffers_skybasic=false
alphaTest.gbuffers_skytextured=false
sliders=BLOOMY_FOG FOG_RAIN_MULTIPLIER FOG_TOD_MULTIPLIER CLOUDY_FOG_AMOUNT BASE_FOG_AMOUNT WAVY_SPEED WAVY_STRENGTH ANTI_GHOSTING BLOOM_STRENGTH Underwater_Fog_Density shadowDistance shadowDistanceRenderMul FinalR FinalG FinalB Ambient_Mult Sky_Brightness fog_coefficientMieR fog_coefficientMieG fog_coefficientMieB sun_illuminance sunColorG sunColorB sunColorR sky_mieg sky_coefficientMieB sky_coefficientMieG sky_coefficientMieR sky_coefficientRayleighB sky_coefficientRayleighG sky_coefficientRayleighR CLOUDS_QUALITY EXPOSURE_MULTIPLIER MIN_LIGHT_AMOUNT TORCH_R TORCH_G TORCH_B TORCH_AMOUNT shadowMapResolution sunPathRotation SKY_BRIGHTNESS_DAY SKY_BRIGHTNESS_NIGHT BLEND_FACTOR FLICKER_REDUCTION MOTION_REJECTION VL_SAMPLES Exposure_Speed POM_MAP_RES POM_DEPTH MAX_ITERATIONS MAX_DIST SSR_STEPS ambientOcclusionLevel SEA_LEVEL ATMOSPHERIC_DENSITY CLOUDS_SHADOWS_STRENGTH moon_illuminance moonColorR moonColorG moonColorB fog_mieg1 fog_mieg2 fog_coefficientRayleighR fog_coefficientRayleighG SATURATION Manual_exposure_value focal aperture MANUAL_FOCUS SHADOW_FILTER_SAMPLE_COUNT Max_Filter_Depth VPS_Search_Samples Min_Shadow_Filter_Radius Max_Shadow_Filter_Radius SSAO_SAMPLES Water_Top_Layer fog_coefficientRayleighB SHARPENING rayMarchSampleCount Dirt_Mie_Phase Dirt_Amount Dirt_Scatter_R Dirt_Scatter_G Dirt_Scatter_B Dirt_Absorb_R Dirt_Absorb_G Dirt_Absorb_B Water_Absorb_R Water_Absorb_G Water_Absorb_B Purkinje_strength Purkinje_strength Purkinje_R Purkinje_G Purkinje_B Purkinje_Multiplier CROSSTALK
screen=[Atmospherics] [TAA_OPTIONS] [Lighting] [Camera] [Shading] [Wavy_stuff] [Water_and_transparencies]
screen.Wavy_stuff = WAVY_STRENGTH WAVY_SPEED WAVY_PLANTS
screen.Atmospherics= SEA_LEVEL VL_SAMPLES CLOUDS_QUALITY VOLUMETRIC_CLOUDS [Fog_Color] [Fog_Densities] BLOOMY_FOG
screen.Fog_Densities = FOG_RAIN_MULTIPLIER FOG_TOD_MULTIPLIER CLOUDY_FOG_AMOUNT BASE_FOG_AMOUNT ATMOSPHERIC_DENSITY Underwater_Fog_Density
screen.Fog_Color = fog_mieg1 fog_mieg2 fog_coefficientRayleighR fog_coefficientRayleighG fog_coefficientRayleighB fog_coefficientMieR fog_coefficientMieG fog_coefficientMieB
screen.Water_and_transparencies = Dirt_Amount Dirt_Mie_Phase rayMarchSampleCount SCREENSPACE_REFLECTIONS SSR_STEPS SUN_MICROFACET_SPECULAR Water_Top_Layer lightMapDepthEstimation [Advanced]
screen.Advanced = Dirt_Scatter_R Dirt_Scatter_G Dirt_Scatter_B Dirt_Absorb_R Dirt_Absorb_G Dirt_Absorb_B Water_Absorb_R Water_Absorb_G Water_Absorb_B
screen.TAA_OPTIONS= TAA <empty> FLICKER_REDUCTION BLEND_FACTOR ANTI_GHOSTING MOTION_REJECTION CLOSEST_VELOCITY NO_CLIP
screen.Lighting= [Torch] [Sky] [Ambient]
screen.Torch = TORCH_R TORCH_G TORCH_B TORCH_AMOUNT
screen.Sky=[Sky_coefficients] [Sun_and_Moon_Colors] sunPathRotation
screen.Sky_coefficients = Sky_Brightness sky_mieg sky_coefficientRayleighR sky_coefficientRayleighG sky_coefficientRayleighB sky_coefficientMieR sky_coefficientMieG sky_coefficientMieB
screen.Sun_and_Moon_Colors = sunColorR sunColorG sunColorB sun_illuminance moonColorR moonColorG moonColorB moon_illuminance
screen.Ambient = MIN_LIGHT_AMOUNT SEPARATE_AO ambientOcclusionLevel Ambient_Mult
screen.Shading = DISABLE_ALPHA_MIPMAPS [Shadows] [POM] BICUBIC_UPSCALING CONTRAST_ADAPTATIVE_SHARPENING SHARPENING
screen.Shadows = [Filtering] SCREENSPACE_CONTACT_SHADOWS shadowMapResolution CLOUDS_SHADOWS CLOUDS_SHADOWS_STRENGTH shadowDistanceRenderMul shadowDistance SHADOW_FRUSTRUM_CULLING CAVE_LIGHT_LEAK_FIX SSAO SSAO_SAMPLES SHADOW_DISABLE_ALPHA_MIPMAPS Stochastic_Transparent_Shadows
screen.Filtering = Variable_Penumbra_Shadows VPS_Search_Samples Min_Shadow_Filter_Radius Max_Shadow_Filter_Radius Max_Filter_Depth SHADOW_FILTER_SAMPLE_COUNT
screen.POM = POM_MAP_RES POM POM_DEPTH MAX_ITERATIONS MAX_DIST USE_LUMINANCE_AS_HEIGHTMAP
screen.Camera = EXPOSURE_MULTIPLIER Exposure_Speed AUTO_EXPOSURE Manual_exposure_value BLOOM_STRENGTH FinalR FinalG FinalB [Tonemapping] [DepthOfField] [Purkinje_effect]
screen.Purkinje_effect = Purkinje_strength Purkinje_strength Purkinje_R Purkinje_G Purkinje_B Purkinje_Multiplier
screen.Tonemapping = TONEMAP USE_ACES_COLORSPACE_APPROXIMATION SATURATION CROSSTALK
screen.DepthOfField = DOF HQ_DOF HEXAGONAL_BOKEH AUTOFOCUS focal aperture MANUAL_FOCUS FAR_BLUR_ONLY
texture.noise=texture/noises.png
separateAo=true
beacon.beam.depth=true
rain.depth=false
variable.float.texelSizeX = 1.0/viewWidth
variable.float.texelSizeY = 1.0/viewHeight
uniform.vec2.texelSize=vec2(texelSizeX,texelSizeY)
uniform.int.framemod8 = frameCounter%8
variable.float.normSunVec = sqrt(sunPosition.x*sunPosition.x+sunPosition.y*sunPosition.y+sunPosition.z*sunPosition.z)
variable.float.normUpVec = sqrt(upPosition.x*upPosition.x+upPosition.y*upPosition.y+upPosition.z*upPosition.z)
variable.float.sunPosX = sunPosition.x/normSunVec
variable.float.sunPosY = sunPosition.y/normSunVec
variable.float.sunPosZ = sunPosition.z/normSunVec
uniform.vec3.sunVec=vec3(sunPosX,sunPosY,sunPosZ)
variable.float.upPosX = upPosition.x/normUpVec
variable.float.upPosY = upPosition.y/normUpVec
variable.float.upPosZ = upPosition.z/normUpVec
uniform.vec3.upVec=vec3(upPosX,upPosY,upPosZ)
uniform.float.sunElevation = sunPosX*upPosX+sunPosY*upPosY+sunPosZ*upPosZ
uniform.float.lightSign = clamp(sunElevation * 1000000000000000000, 0.0, 1.0) * 2.0 - 1.0
#Max angle at frustrum diagonal
variable.float.maxAngle = atan(1.0 / gbufferProjection.1.1 * sqrt(1.0+(aspectRatio * aspectRatio)))
uniform.float.cosFov = cos(maxAngle)
variable.float.viewDirX = gbufferModelViewInverse.2.0
variable.float.viewDirY = gbufferModelViewInverse.2.1
variable.float.viewDirZ = gbufferModelViewInverse.2.2
variable.float.normView = sqrt(viewDirX*viewDirX + viewDirY*viewDirY + viewDirZ*viewDirZ)
variable.float.shViewDirX = (shadowModelView.0.0 * viewDirX + shadowModelView.1.0 * viewDirY + shadowModelView.2.0 * viewDirZ)/normView
variable.float.shViewDirY = (shadowModelView.0.1 * viewDirX + shadowModelView.1.1 * viewDirY + shadowModelView.2.1 * viewDirZ)/normView
variable.float.shViewDirZ = (shadowModelView.0.2 * viewDirX + shadowModelView.1.2 * viewDirY + shadowModelView.2.2 * viewDirZ)/normView
uniform.vec3.shadowViewDir = vec3(shViewDirX, shViewDirY, shViewDirZ)
variable.float.shStartX = (shadowModelView.0.0 * gbufferModelViewInverse.3.0 + shadowModelView.1.0 * gbufferModelViewInverse.3.1 + shadowModelView.2.0 * gbufferModelViewInverse.3.2)
variable.float.shStartY = (shadowModelView.0.1 * gbufferModelViewInverse.3.0 + shadowModelView.1.1 * gbufferModelViewInverse.3.1 + shadowModelView.2.1 * gbufferModelViewInverse.3.2)
variable.float.shStartZ = (shadowModelView.0.2 * gbufferModelViewInverse.3.0 + shadowModelView.1.2 * gbufferModelViewInverse.3.1 + shadowModelView.2.2 * gbufferModelViewInverse.3.2)
uniform.vec3.shadowCamera = vec3(shStartX + shadowModelView.3.0 + shViewDirX*2., shStartY + shadowModelView.3.1 + shViewDirY*2., shStartZ + shadowModelView.3.2 + shViewDirZ*2.0)
variable.float.wSunX = (gbufferModelViewInverse.0.0 * sunPosX + gbufferModelViewInverse.1.0 * sunPosY + gbufferModelViewInverse.2.0 * sunPosZ)
variable.float.wSunY = (gbufferModelViewInverse.0.1 * sunPosX + gbufferModelViewInverse.1.1 * sunPosY + gbufferModelViewInverse.2.1 * sunPosZ)
variable.float.wSunZ = (gbufferModelViewInverse.0.2 * sunPosX + gbufferModelViewInverse.1.2 * sunPosY + gbufferModelViewInverse.2.2 * sunPosZ)
variable.float.shSunX = (shadowModelView.0.0 * wSunX + shadowModelView.1.0 * wSunY + shadowModelView.2.0 * wSunZ)
variable.float.shSunY = (shadowModelView.0.1 * wSunX + shadowModelView.1.1 * wSunY + shadowModelView.2.1 * wSunZ)
variable.float.shSunZ = (shadowModelView.0.2 * wSunX + shadowModelView.1.2 * wSunY + shadowModelView.2.2 * wSunZ)
uniform.vec3.shadowLightVec = vec3(lightSign*shSunX, lightSign*shSunY, lightSign*shSunZ)
uniform.float.shadowMaxProj = 150.0/abs(sunPosY)

View File

@ -0,0 +1,37 @@
#version 120
//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog
#extension GL_EXT_gpu_shader4 : enable
varying vec2 texcoord;
flat varying vec3 zMults;
uniform sampler2D depthtex0;
uniform sampler2D colortex3;
uniform sampler2D colortex2;
uniform sampler2D colortex0;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform int isEyeInWater;
uniform vec2 texelSize;
float ld(float depth) {
return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near
}
void main() {
/* DRAWBUFFERS:3 */
vec3 color = texture2D(colortex3,texcoord).rgb;
vec4 transparencies = texture2D(colortex2,texcoord);
color = color*(1.0-transparencies.a)+transparencies.rgb*10.;
vec4 vl = texture2D(colortex0,texcoord);
color *= vl.a;
color += vl.rgb;
gl_FragData[0].rgb = clamp(color,6.11*1e-5,65000.0);
}

View File

@ -0,0 +1,19 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
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((far * near)*2.0,far+near,far-near);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 KiB

View File

@ -0,0 +1,7 @@
{
"texture":
{
"blur": true,
"clamp": false
}
}