diff --git a/shaders/block.properties b/shaders/block.properties new file mode 100644 index 0000000..72c8ec7 --- /dev/null +++ b/shaders/block.properties @@ -0,0 +1,68 @@ + +#if MC_VERSION >= 11300 + + ####### ----- SSS and waving ----- ####### + + ##ground waving + block.10001 = minecraft:beetroots minecraft:potatoes minecraft:carrots minecraft:wheat minecraft:nether_wart minecraft:kelp minecraft:large_fern:half=upper minecraft:peony:half=upper minecraft:rose_bush:half=upper minecraft:lilac:half=upper minecraft:crimson_roots minecraft:nether_sprouts minecraft:warped_roots minecraft:seagrass minecraft:tall_seagrass:half=upper minecraft:sunflower:half=upper minecraft:tall_grass:half=upper minecraft:wither_rose minecraft:lily_of_the_valley minecraft:cornflower minecraft:sweet_berry_bush minecraft:oxeye_daisy minecraft:pink_tulip minecraft:white_tulip minecraft:orange_tulip minecraft:red_tulip minecraft:azure_bluet minecraft:allium minecraft:blue_orchid minecraft:poppy minecraft:dandelion minecraft:grass minecraft:dead_bush minecraft:oak_sapling minecraft:spruce_sapling minecraft:birch_sapling minecraft:jungle_sapling minecraft:acacia_sapling minecraft:dark_oak_sapling minecraft:fern + + ##air waving + block.10003 = minecraft:mangrove_leaves minecraft:vine minecraft:oak_leaves minecraft:spruce_leaves minecraft:birch_leaves minecraft:jungle_leaves minecraft:acacia_leaves minecraft:dark_oak_leaves + + ####### ----- SSS ----- ####### + + ## strong + block.10004 = minecraft:fern minecraft:packed_ice minecraft:blue_ice minecraft:melon_stem minecraft:pumpkin_stem minecraft:attached_melon_stem minecraft:attached_pumpkin_stem minecraft:lily_pad minecraft:azalea_leaves minecraft:flowering_azalea_leaves minecraft:azalea minecraft:flowering_azalea + + ## weak + block.10006 = weeping_vines weeping_vines_plant twisting_vines twisting_vines_plant vine tube_coral tube_coral_block tube_coral_fan tube_coral_wall_fan horn_coral horn_coral_block horn_coral_fan horn_coral_wall_fan fire_coral fire_coral_block fire_coral_fan fire_coral_wall_fan dead_brain_coral dead_brain_coral_block dead_brain_coral_fan dead_brain_coral_wall_fan dead_bubble_coral dead_bubble_coral_block dead_bubble_coral_fan dead_bubble_coral_wall_fan dead_bush dead_fire_coral dead_fire_coral_block dead_fire_coral_fan dead_fire_coral_wall_fan dead_horn_coral dead_horn_coral_block dead_horn_coral_fan dead_horn_coral_wall_fan dead_tube_coral dead_tube_coral_block dead_tube_coral_fan dead_tube_coral_wall_fan bubble_coral bubble_coral_block bubble_coral_fan bubble_coral_wall_fan brain_coral brain_coral_block brain_coral_fan brain_coral_wall_fan bamboo bamboo_sapling minecraft:tall_seagrass minecraft:seagrass minecraft:kelp minecraft:large_fern minecraft:tall_grass minecraft:tall_seagrass minecraft:kelp_plant minecraft:peony minecraft:rose_bush minecraft:lilac minecraft:sunflower minecraft:spore_blossom minecraft:cave_vines minecraft:cave_vines_plant minecraft:glow_lichen minecraft:melon minecraft:pumpkin minecraft:big_dripleaf minecraft:big_dripleaf_stem minecraft:cactus minecraft:hay_block minecraft:brown_mushroom minecraft:mushroom_stem minecraft:sugar_cane minecraft:crimson_fungus minecraft:warped_fungus minecraft:sea_pickle minecraft:cobweb minecraft:honeycomb_block + + block.200 = minecraft:white_wool minecraft:orange_wool minecraft:magenta_wool minecraft:light_blue_wool minecraft:yellow_wool minecraft:lime_wool minecraft:pink_wool minecraft:gray_wool minecraft:light_gray_wool minecraft:cyan_wool minecraft:purple_wool minecraft:blue_wool minecraft:brown_wool minecraft:green_wool minecraft:red_wool minecraft:black_wool minecraft:orange_carpet minecraft:magenta_carpet minecraft:light_blue_carpet minecraft:yellow_carpet minecraft:lime_carpet minecraft:pink_carpet minecraft:gray_carpet minecraft:light_gray_carpet minecraft:cyan_carpet minecraft:purple_carpet minecraft:blue_carpet minecraft:brown_carpet minecraft:green_carpet minecraft:red_carpet minecraft:black_carpet + + # block.201 = + + + + block.10010 = minecraft:white_wall_banner minecraft:orange_wall_banner minecraft:magenta_wall_banner minecraft:light_blue_wall_banner minecraft:yellow_wall_banner minecraft:lime_wall_banner minecraft:pink_wall_banner minecraft:gray_wall_banner minecraft:light_gray_wall_banner minecraft:cyan_wall_banner minecraft:purple_wall_banner minecraft:blue_wall_banner minecraft:brown_wall_banner minecraft:green_wall_banner minecraft:red_wall_banner minecraft:black_wall_banner minecraft:white_banner minecraft:orange_banner minecraft:magenta_banner minecraft:light_blue_banner minecraft:yellow_banner minecraft:lime_banner minecraft:pink_banner minecraft:gray_banner minecraft:light_gray_banner minecraft:cyan_banner minecraft:purple_banner minecraft:blue_banner minecraft:brown_banner minecraft:green_banner minecraft:red_banner minecraft:black_banner + + + ## weird blocks + block.10007 = minecraft:grass_block:snowy=false minecraft:sand minecraft:red_sand minecraft:snow_block minecraft:snow powder_snow minecraft:grass_block:snowy=true + + ####### ----- lightsources ----- ####### + + block.10005 = minecraft:sculk_sensor minecraft:soul_fire minecraft:soul_campfire:lit=true minecraft:cave_vines_plant:berries=true minecraft:soul_lantern minecraft:soul_torch minecraft:soul_wall_torch minecraft:conduit minecraft:beacon minecraft:sea_pickle minecraft:respawn_anchor:charges=4 minecraft:smoker:lit=true minecraft:blast_furnace:lit=true minecraft:furnace:lit=true minecraft:lava_cauldron minecraft:sea_lantern minecraft:cave_vines:berries=true 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:end_rod minecraft:end_gateway minecraft:lava minecraft:fire + + ####### ----- reflective translucents / glass ----- ####### + + block.10002 = minecraft:slime_block minecraft:nether_portal minecraft:honey_block ice minecraft:frosted_ice 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 + + ####### ----- misc ----- ####### + + block.222 = end_portal end_gateway end_portal_frame + + block.8 = minecraft:water minecraft:flowing_water + + #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 + +# layer.solid = minecraft:tripwire minecraft:slime_block minecraft:nether_portal minecraft:honey_block minecraft:ice 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 \ No newline at end of file diff --git a/shaders/composite.fsh b/shaders/composite.fsh new file mode 100644 index 0000000..3b5166d --- /dev/null +++ b/shaders/composite.fsh @@ -0,0 +1,276 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + +#define TAA + +// #define LabPBR_subsurface_scattering +flat varying vec3 WsunVec; +flat varying vec2 TAA_Offset; +#include "/lib/res_params.glsl" +#include "lib/Shadow_Params.glsl" +uniform sampler2D depthtex1; +uniform sampler2D colortex1; +uniform sampler2D colortex6; // Noise +uniform sampler2D colortex8; // Noise +uniform sampler2D colortex15; // Noise +uniform sampler2D shadow; +uniform sampler2D noisetex; +uniform vec3 sunVec; +uniform vec2 texelSize; +uniform float frameTimeCounter; +uniform float rainStrength; +uniform int frameCounter; +uniform mat4 gbufferProjection; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferModelView; + +uniform mat4 shadowModelView; +uniform mat4 shadowProjection; +uniform vec3 cameraPosition; +uniform float viewWidth; +uniform float aspectRatio; +uniform float viewHeight; +uniform float far; +uniform float near; + +#define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0) +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) +vec3 toScreenSpace(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 p3 = p * 2. - 1.; + vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} +vec3 worldToView(vec3 worldPos) { + vec4 pos = vec4(worldPos, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; +} + +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)*alpha; +} +// float interleaved_gradientNoise(){ +// vec2 coord = gl_FragCoord.xy; +// float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+ 1.0/1.6180339887 * frameCounter) ; +// return noise; +// } +// float interleaved_gradientNoise2(){ +// 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 interleaved_gradientNoise(){ + vec2 coord = gl_FragCoord.xy + (frameCounter%40000); + // vec2 coord = gl_FragCoord.xy + frameTimeCounter; + // vec2 coord = gl_FragCoord.xy; + float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); + return noise ; +} +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 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 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); +} + +vec2 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n); +} +vec2 tapLocation_alternate( + int sampleNumber, + float spinAngle, + int nb, + float nbRot, + float r0 +){ + float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb))); + float angle = alpha * (nbRot * 3.14) ; + + float ssR = alpha + spinAngle*3.14; + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + return vec2(cos_v, sin_v)*ssR; +} +vec3 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} + + +// Emin's and Gri's combined ideas to stop peter panning and light leaking, also has little shadowacne so thats nice +// https://www.complementary.dev/reimagined +// https://github.com/gri573 +void GriAndEminShadowFix( + inout vec3 WorldPos, + vec3 FlatNormal, + float VanillaAO, + float SkyLightmap, + bool Entities +){ + float DistanceOffset = clamp(0.1 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ; + vec3 Bias = FlatNormal * DistanceOffset; // adjust the bias thingy's strength as it gets farther away. + + // stop lightleaking + if(SkyLightmap < 0.1 && !Entities) { + WorldPos += mix(Bias, 0.5 * (0.5 - fract(WorldPos + cameraPosition + FlatNormal*0.01 ) ), VanillaAO) ; + }else{ + WorldPos += Bias; + } +} + +void main() { +/* DRAWBUFFERS:3 */ + vec2 texcoord = gl_FragCoord.xy*texelSize; + + + float z = texture2D(depthtex1,texcoord).x; + + vec2 tempOffset=TAA_Offset; + + vec4 data = texture2D(colortex1,texcoord); + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + vec3 normal = mat3(gbufferModelViewInverse) * clamp(worldToView( decode(dataUnpacked0.yw) ),-1.,1.); + vec2 lightmap = dataUnpacked1.yz; + + + bool translucent = abs(dataUnpacked1.w-0.5) <0.01; + bool translucent2 = abs(dataUnpacked1.w-0.6) <0.01; // Weak translucency + bool translucent3 = abs(dataUnpacked1.w-0.55) <0.01; // Weak translucency + bool translucent4 = abs(dataUnpacked1.w-0.65) <0.01; // Weak translucency + bool entities = abs(dataUnpacked1.w-0.45) <0.01; // Weak translucency + bool hand = abs(dataUnpacked1.w-0.75) <0.01; + + float minshadowfilt = Min_Shadow_Filter_Radius; + float maxshadowfilt = Max_Shadow_Filter_Radius; + + float vanillAO = clamp(pow(1-texture2D(colortex15,texcoord).a*2,4),0,1) ; + + if(lightmap.y < 0.1 && !entities){ + // minshadowfilt *= vanillAO; + maxshadowfilt = mix(minshadowfilt ,maxshadowfilt, vanillAO); + } + + + #ifdef LabPBR_subsurface_scattering + float SpecularTex = texture2D(colortex8,texcoord).z; + float LabSSS = clamp((-65.0 + SpecularTex * 255.0) / 190.0 ,0.0,1.0); + #else + float LabSSS = 0.0; + #endif + + + #ifndef Variable_Penumbra_Shadows + if (translucent && !hand) minshadowfilt += 25; + #endif + + + gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0); + + + + if (z < 1.0){ + + // if( translucent || translucent2) + + if (!hand){ + + float NdotL = clamp(dot(normal,WsunVec),0.0,1.0); + + vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); + + #ifdef Variable_Penumbra_Shadows + + if (NdotL > 0.000 || LabSSS > 0.0 || translucent || translucent2 || translucent3 || translucent4) { + + 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 && abs(projectedShadowPosition.z) < 6.0){ + const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95); + float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+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); + + float mult = maxshadowfilt; + float avgBlockerDepth = 0.0; + vec2 scales = vec2(0.0,Max_Filter_Depth); + float blockerCount = 0.0; + float rdMul = distortFactor*(1.0+mult)*d0*k/shadowMapResolution; + float diffthreshM = diffthresh*mult*d0*k/20.; + float avgDepth = 0.0; + + int seed = (frameCounter%40000) + (1+frameCounter); + float randomDir = fract(R2_samples(seed).y + blueNoise(gl_FragCoord.xy).g) * 1.61803398874 ; + + for(int i = 0; i < VPS_Search_Samples; i++){ + + // vec2 offsetS = tapLocation(i,VPS_Search_Samples,1.61803398874 , blueNoise(),0.0); + + vec2 offsetS = tapLocation_alternate(i, 0.0, 7, 20, randomDir); + + float weight = 3.0 + (i+blueNoise() ) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7; + float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x; + float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d); + + blockerCount += b; + avgDepth += max(projectedShadowPosition.z - d, 0.0)*1000.; + avgBlockerDepth += d * b; + } + + gl_FragData[0].g = avgDepth / VPS_Search_Samples; + gl_FragData[0].b = blockerCount / VPS_Search_Samples; + if (blockerCount >= 0.9){ + avgBlockerDepth /= blockerCount; + float ssample = max(projectedShadowPosition.z - avgBlockerDepth,0.0)*1500.0; + gl_FragData[0].r = clamp(ssample, scales.x, scales.y)/(scales.y)*(mult-minshadowfilt)+minshadowfilt; + } + } + } + #endif + } + +} + +} diff --git a/shaders/composite.vsh b/shaders/composite.vsh new file mode 100644 index 0000000..934a139 --- /dev/null +++ b/shaders/composite.vsh @@ -0,0 +1,35 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#define TAA +flat varying vec2 TAA_Offset; +flat varying vec3 WsunVec; + +uniform sampler2D colortex4; + +uniform int frameCounter; +uniform float sunElevation; +uniform vec3 sunPosition; +uniform mat4 gbufferModelViewInverse; +#include "/lib/util.glsl" +#include "/lib/res_params.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.); +void main() { + TAA_Offset = offsets[frameCounter%8]; + #ifndef TAA + TAA_Offset = vec2(0.0); + #endif + gl_Position = ftransform(); + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif + + WsunVec = (float(sunElevation > 1e-5)*2-1.)*normalize(mat3(gbufferModelViewInverse) * sunPosition); + +} diff --git a/shaders/composite10.fsh b/shaders/composite10.fsh new file mode 100644 index 0000000..139ceb4 --- /dev/null +++ b/shaders/composite10.fsh @@ -0,0 +1,43 @@ +#version 120 +//downsample 1st pass (half res) for bloom +#include "lib/res_params.glsl" +uniform sampler2D colortex3; +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:6 */ +vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); +vec2 quarterResTC = gl_FragCoord.xy*texelSize*2.; + + //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.); +} diff --git a/shaders/composite10.vsh b/shaders/composite10.vsh new file mode 100644 index 0000000..0bb9b19 --- /dev/null +++ b/shaders/composite10.vsh @@ -0,0 +1,17 @@ +#version 120 +#include "lib/res_params.glsl" +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*BLOOM_QUALITY/clampedRes*vec2(1920.0,1080.)*2-1.0; +} diff --git a/shaders/composite11.fsh b/shaders/composite11.fsh new file mode 100644 index 0000000..63d77d7 --- /dev/null +++ b/shaders/composite11.fsh @@ -0,0 +1,61 @@ +#version 120 +//6 Horizontal gaussian blurs and horizontal downsampling +#include "lib/res_params.glsl" + +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.))*BLOOM_QUALITY; +vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ + vec4 tot = vec4(0.); + float maxTC = 0.25*resScale.x; + float minTC = 0.; + for (int i = -maxIT;i minTC && spCoord.x < maxTC); + } + return tot.rgb/max(1.0,tot.a); +} + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:6 */ + +vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; +vec2 gaussDir = vec2(1.0,0.0); +gl_FragData[0].rgb = vec3(0.0); +vec2 tc2 = texcoord*vec2(2.0,1.)/2.; +if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc2/2,gaussDir,0.16,0); + +vec2 tc4 = texcoord*vec2(4.0,1.)/2.-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*2.0; +if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc4/2,gaussDir,0.16,3); + +vec2 tc8 = texcoord*vec2(8.0,1.)/2.-vec2(0.75*resScale.x+8.*texelSize.x,0.)*4.0; +if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc8/2,gaussDir,0.035,6); + +vec2 tc16 = texcoord*vec2(8.0,1./2.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*8.0; +if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc16/2,gaussDir,0.0085,12); + +vec2 tc32 = texcoord*vec2(16.0,1./2.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*16.0; +if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc32/2,gaussDir,0.002,28); + +vec2 tc64 = texcoord*vec2(32.0,1./2.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*32.0; +if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc64/2,gaussDir,0.0005,60); + +gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); +} diff --git a/shaders/composite11.vsh b/shaders/composite11.vsh new file mode 100644 index 0000000..ceede8d --- /dev/null +++ b/shaders/composite11.vsh @@ -0,0 +1,20 @@ +#version 120 +#include "lib/res_params.glsl" +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))/BLOOM_QUALITY; + 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.); +} diff --git a/shaders/composite12.fsh b/shaders/composite12.fsh new file mode 100644 index 0000000..46c64db --- /dev/null +++ b/shaders/composite12.fsh @@ -0,0 +1,61 @@ +#version 120 +//6 Vertical gaussian blurs and vertical downsampling +#include "lib/res_params.glsl" + + +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.))*BLOOM_QUALITY; +vec3 gauss1D(vec2 coord,vec2 dir,float alpha,int maxIT){ + vec4 tot = vec4(0.); + float maxTC = 0.25*resScale.y; + float minTC = 0.; + for (int i = -maxIT;i minTC && spCoord.y < maxTC); + } + return tot.rgb/max(1.0,tot.a); +} + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:6 */ +vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; + +vec2 gaussDir = vec2(0.0,1.0); +gl_FragData[0].rgb = vec3(0.0); +vec2 tc2 = texcoord*vec2(2.0,1.); +if (tc2.x < 1.0*resScale.x && tc2.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,4.0),gaussDir,0.16,0); + +vec2 tc4 = texcoord*vec2(4.0,2.)-vec2(0.5*resScale.x+4.0*texelSize.x,0.)*4.0; +if (tc4.x > 0.0 && tc4.y > 0.0 && tc4.x < 1.0*resScale.x && tc4.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord/vec2(2.0,2.0),gaussDir,0.16,3); + +vec2 tc8 = texcoord*vec2(8.0,4.)-vec2(0.75*resScale.x+8.*texelSize.x,0.)*8.0; +if (tc8.x > 0.0 && tc8.y > 0.0 && tc8.x < 1.0*resScale.x && tc8.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,2.0)/vec2(2.0,2.0),gaussDir,0.035,6); + +vec2 tc16 = texcoord*vec2(16.0,8.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*16.0; +if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,4.0)/vec2(2.0,2.0),gaussDir,0.0085,12); + +vec2 tc32 = texcoord*vec2(32.0,16.)-vec2(0.9375*resScale.x+16.*texelSize.x,0.)*32.0; +if (tc32.x > 0.0 && tc32.y > 0.0 && tc32.x < 1.0*resScale.x && tc32.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,8.0)/vec2(2.0,2.0),gaussDir,0.002,30); + +vec2 tc64 = texcoord*vec2(64.0,32.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*64.0; +if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(texcoord*vec2(1.0,16.0)/vec2(2.0,2.0),gaussDir,0.0005,60); + +gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); +} diff --git a/shaders/composite12.vsh b/shaders/composite12.vsh new file mode 100644 index 0000000..7a82ef6 --- /dev/null +++ b/shaders/composite12.vsh @@ -0,0 +1,21 @@ +#version 120 +#include "lib/res_params.glsl" +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))/BLOOM_QUALITY; + 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.); + +} diff --git a/shaders/composite14.fsh b/shaders/composite14.fsh new file mode 100644 index 0000000..bea104b --- /dev/null +++ b/shaders/composite14.fsh @@ -0,0 +1,103 @@ +#version 120 +//Merge and upsample the blurs into a 1/4 res bloom buffer +#include "lib/res_params.glsl" +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.))/BLOOM_QUALITY); +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.); +} diff --git a/shaders/composite14.vsh b/shaders/composite14.vsh new file mode 100644 index 0000000..f98ccfe --- /dev/null +++ b/shaders/composite14.vsh @@ -0,0 +1,17 @@ +#version 120 +#include "lib/res_params.glsl" +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*BLOOM_QUALITY/clampedRes*vec2(1920.0,1080.)*2.0-1.0; +} diff --git a/shaders/composite15.fsh b/shaders/composite15.fsh new file mode 100644 index 0000000..777118b --- /dev/null +++ b/shaders/composite15.fsh @@ -0,0 +1,497 @@ +#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] +//#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 // THE BRIGHTNESS SLIDER CAN CONTROL THE MANUAL FOCUS DISTANCE +//#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 ] + +#include "/lib/res_params.glsl" + +#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 vec2 rodExposureDepth; +varying vec2 texcoord; +uniform sampler2D colortex4; +uniform sampler2D colortex5; +uniform sampler2D colortex3; +uniform sampler2D colortex6; +uniform sampler2D colortex7; +uniform sampler2D colortex8; // specular +// uniform sampler2D colortex9; // specular +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; +uniform sampler2D noisetex; +uniform vec2 texelSize; + +uniform ivec2 eyeBrightnessSmooth; +uniform float viewWidth; +uniform float viewHeight; +uniform float frameTimeCounter; +uniform int frameCounter; +uniform int isEyeInWater; +uniform float near; +uniform float aspectRatio; +uniform float far; +uniform float rainStrength; +uniform float screenBrightness; +uniform vec4 Moon_Weather_properties; // R = cloud coverage G = fog density + +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferProjectionInverse; +vec4 Weather_properties = Moon_Weather_properties; + +#include "lib/color_transforms.glsl" +#include "lib/color_dither.glsl" +// #include "lib/biome_specifics.glsl" + +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 +} + +// blindness fogs +uniform float blindness; +uniform float darknessFactor; + +void main() { + /* DRAWBUFFERS:7 */ + float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.); + vec3 col = texture2D(colortex5,texcoord).rgb; + + #ifdef DOF + /*--------------------------------*/ + float z = ld(texture2D(depthtex0, texcoord.st*RENDER_SCALE).r)*far; + #ifdef AUTOFOCUS + float focus = rodExposureDepth.y*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(0.3,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.)); + + + vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5*BLOOM_QUALITY).rgb/2./7.0; + + float lightScat = clamp(BLOOM_STRENGTH * 0.05 * pow(exposure.a ,0.2) ,0.0,1.0)*vignette; + + float VL_abs = texture2D(colortex7,texcoord*RENDER_SCALE).r; + float purkinje = rodExposureDepth.x/(1.0+rodExposureDepth.x)*Purkinje_strength; + + VL_abs = clamp( (1.0-VL_abs)*BLOOMY_FOG*0.75*(1.0-purkinje),0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0); + + float lightleakfix = clamp(eyeBrightnessSmooth.y/240.0,0.0,1.0); + col = (mix(col,bloom,VL_abs)+bloom*lightScat)* mix(exposure.rgb,min(exposure.rgb,0.01), 0); + + //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*400.; + float rodCurve = mix(1.0, rodLum/(2.5+rodLum), purkinje); + col = mix(clamp(lum,0.0,0.05)*Purkinje_Multiplier*vec3(Purkinje_R, Purkinje_G, Purkinje_B)+1.5e-3, 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 + gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0); + + + + + +} \ No newline at end of file diff --git a/shaders/composite15.vsh b/shaders/composite15.vsh new file mode 100644 index 0000000..51cbbf6 --- /dev/null +++ b/shaders/composite15.vsh @@ -0,0 +1,26 @@ +#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 vec2 rodExposureDepth; +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); + rodExposureDepth = texelFetch2D(colortex4,ivec2(14,37),0).rg; + rodExposureDepth.y = sqrt(rodExposureDepth.y/65000.0); +} diff --git a/shaders/composite2.fsh b/shaders/composite2.fsh new file mode 100644 index 0000000..2d87b09 --- /dev/null +++ b/shaders/composite2.fsh @@ -0,0 +1,1090 @@ +#version 120 +//Render sky, volumetric clouds, direct lighting +#extension GL_EXT_gpu_shader4 : enable + +#define Moon_temp 15000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000] +#define CAVE_LIGHT_LEAK_FIX // Hackish way to remove sunlight incorrectly leaking into the caves. Can inacurrately create shadows in some places +#define CLOUDS_SHADOWS +#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 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 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 ambient_brightness 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ] +#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 Sub_surface_scattering // (place the flashlight on your hand example here) +// #define LabPBR_subsurface_scattering +#define LabSSS_Curve 1.0 // i just really like how it looks at 2.0, so i made it an option. [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 Strong_SSS_strength 45 // [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2 3 4 5 6 7 8 9 10 15 20 30 35 40 45 50] +#define Medium_SSS_strength 30 // [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2 3 4 5 6 7 8 9 10 15 20 30 35 40 45 50] + +#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 HQ_SSGI + + +// #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 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 + + +// #define Allow_Vanilla_sky // allow the vanilla sky to appear. may appear broken with some resourcepacks. + +// #define WhiteWorld // THIS IS A DEBUG VIEW. uses to see AO easier. used to see fake GI better (green light) +// #define ambientLight_only // THIS IS A DEBUG VIEW. turn the sunlight off. DOES NOT increase performance, the shadows are still working in the background +#define MIN_LIGHT_AMOUNT 1.0 //[0.0 0.5 1.0 1.5 2.0 3.0 4.0 5.0] + + +// #define Glass_Tint // multiply the background through glass by the color of the glass for a strong tint. + +// #define Horrible_slope_normals // awful + +const bool shadowHardwareFiltering = true; +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; + + +/* +const int colortex12Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +const int colortex11Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +const int colortex15Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +*/ + + +uniform sampler2D colortex0;//clouds +uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16 +// uniform sampler2D colortex4;//Skybox +uniform sampler2D colortex3; +uniform sampler2D colortex5; +uniform sampler2D colortex7; // normal +uniform sampler2D colortex6; // Noise +uniform sampler2D colortex8; // specular +// uniform sampler2D colortex9; // specular +uniform sampler2D colortex10; // specular +uniform sampler2D colortex11; // specular +uniform sampler2D colortex12; // specular +uniform sampler2D colortex13; // specular +uniform sampler2D colortex14; // specular +uniform sampler2D colortex15; // specular +uniform sampler2D colortex16; // specular +uniform sampler2D depthtex1;//depth +uniform sampler2D depthtex0;//depth +uniform sampler2D noisetex;//depth +uniform sampler2DShadow shadow; +varying vec4 normalMat; +uniform int heldBlockLightValue; +uniform int frameCounter; +uniform int isEyeInWater; +uniform float far; +uniform float nightVision; +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 float viewWidth; +// uniform float viewHeight; +uniform float aspectRatio; +uniform vec2 texelSize; +uniform vec3 cameraPosition; +uniform vec3 sunVec; +uniform ivec2 eyeBrightnessSmooth; +uniform ivec2 eyeBrightness; + +// uniform int worldTime; + +#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 toScreenSpacePrev(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 p3 = p * 2. - 1.; + vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} +vec3 worldToView(vec3 p3) { + vec4 pos = vec4(p3, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; +} + + +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)); +} +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); +} + +// #include "lib/settings.glsl" +// #include "lib/biome_specifics.glsl" +#include "lib/res_params.glsl" +#include "lib/waterOptions.glsl" +#include "lib/Shadow_Params.glsl" +#include "lib/color_transforms.glsl" +#include "lib/sky_gradient.glsl" +#include "lib/stars.glsl" +#include "lib/volumetricClouds.glsl" +#include "lib/waterBump.glsl" +#include "lib/specular.glsl" +// #include "/lib/climate_settings.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(){ + // vec2 coord = gl_FragCoord.xy + (frameCounter%40000); + vec2 coord = gl_FragCoord.xy + frameTimeCounter; + // vec2 coord = gl_FragCoord.xy; + float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); + return noise ; +} + +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); +} +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); +} + +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 ; +} + + +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 * 84.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 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 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n); +} + +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 * 3.14) + spinAngle*3.14; + + float ssR = alpha; + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + + return vec2(cos_v, sin_v)*ssR; +} + +vec3 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} +void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ + inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value + int spCount = rayMarchSampleCount; + vec3 start = toShadowSpaceProjected(rayStart); + vec3 end = toShadowSpaceProjected(rayEnd); + vec3 dV = (end-start); + //limit ray length at 32 blocks for performance and reducing integration error + //you can't see above this anyway + float maxZ = min(rayLength,32.0)/(1e-8+rayLength); + dV *= maxZ; + vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; + rayLength *= maxZ; + float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; + estEndDepth *= maxZ; + estSunDepth *= maxZ; + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); + float phase = 2*mix(phaseg(VdotL, 0.4),phaseg(VdotL, 0.8),0.5); + float expFactor = 11.0; + vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; + for (int i=0;i -near) ? + (-near -position.z) / dir.z : far*sqrt(3.) ; + vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space + direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size + vec3 stepv = direction *3. * clamp(MC_RENDER_QUALITY,1.,2.0)*vec3(RENDER_SCALE,1.0); + + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0); + spos.xy += (TAA_Offset*(texelSize/4))*RENDER_SCALE ; + spos += stepv; + + for (int i = 0; i < int(quality); i++) { + spos += stepv*(dither*0.2 +0.8) *0.5; + // spos += stepv; + + float sp = texture2D(depthtex1,spos.xy).x; + + if( sp < spos.z) { + float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z); + if (dist < 0.015 ) return 0.0; + } + } + return 1.0; +} + + +vec2 tapLocation_alternate( + int sampleNumber, + float spinAngle, + int nb, + float nbRot, + float r0 +){ + float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb))); + float angle = alpha * (nbRot * 3.14) ; + + float ssR = alpha + spinAngle*3.14; + 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, vec2 texcoord, vec3 ambientCoefs, vec2 lightmap, float sunlight){ + + ivec2 pos = ivec2(gl_FragCoord.xy); + const float tan70 = tan(70.*3.14/180.); + + float dist = 1.0 + clamp(fragpos.z*fragpos.z/50.0,0,2); // shrink sample size as distance increases + + float mulfov2 = gbufferProjection[1][1]/(tan70 * dist); + float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*5/50.0; + + + float rd = mulfov2 * 0.1 ; + //pre-rotate direction + float n = 0.0; + + float occlusion = 0.0; + + vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ; + + int seed = (frameCounter%40000)*2 + (1+frameCounter); + float randomDir = fract(R2_samples(seed).y + noise.x ) * 1.61803398874 ; + vec3 NormalSpecific = viewToWorld(normal); + for (int j = 0; j < 7 ;j++) { + + vec2 sp = tapLocation_alternate(j, 0.0, 7, 20, randomDir); + float thing = sp.y < 0.0 && clamp(floor(abs(NormalSpecific.y)*2.0),0.0,1.0) < 1.0 ? rd * 10: rd; + + + vec2 sampleOffset = sp*thing; + vec2 sampleOffset2 = sp*rd ; + sampleOffset = min(sampleOffset, sampleOffset2); + + ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE); + + if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) { + vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x) * vec3(1.0/RENDER_SCALE, 1.0) ); + 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); + + // float NdotV2 = clamp(dot(vec*inversesqrt(dsquared), normalize(RPnormal)),0.,1.); + // occlusion.y += NdotV2 * clamp(1.0-dsquared/maxR2,0.0,1.0); + } + n += 1; + } + } + } + + occlusion *= mix(2.5, 2.0 , clamp(floor(abs(NormalSpecific.y)*2.0),0.0,1.0)); + occlusion = max(1.0 - occlusion/n, 0.0); + // float skylight = clamp(abs(ambientCoefs.y+1),0.5,1.25) * clamp(abs(ambientCoefs.y+0.5),1.0,1.25); + float skylight = clamp(abs(ambientCoefs.y+1),0.5,2.0) ; + // lighting *= 0.5; + lighting *= mix(1.0,skylight,1); + + lighting = lighting*max(occlusion,pow(lightmap.x,4)); +} + +vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){ + float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + + float stepSize = stepsizes / dist; + int maxSteps = STEPS; + vec3 clipPosition = toClipSpace3(position); + float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ? + (-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far; + vec3 end = toClipSpace3(position+dir*rayLength) ; + vec3 direction = end-clipPosition ; //convert to clip space + + float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize; + //get at which length the ray intersects with the edge of the screen + vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; + + float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0; + + vec3 stepv = direction/len; + + int iterations = min(int(min(len, mult*len)-2), maxSteps); + + //Do one iteration for closest texel (good contact shadows) + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; + spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; + spos += stepv/(stepSize/2); + + for(int i = 0; i < iterations; i++){ + if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1); + spos += stepv*noise; + + float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0); + float currZ = linZ(spos.z); + + if( sp < currZ) { + float dist = abs(sp-currZ)/currZ; + if (dist <= 0.075) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); + } + } + return vec3(1.1); +} + +vec3 cosineHemisphereSample(vec2 Xi, float roughness){ + float r = sqrt(Xi.x); + float theta = 2.0 * 3.14159265359 * Xi.y; + + float x = r * cos(theta); + float y = r * sin(theta); + + return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); +} +vec3 TangentToWorld(vec3 N, vec3 H, float roughness){ + vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); + vec3 T = normalize(cross(UpVector, N)); + vec3 B = cross(N, T); + + return vec3((T * H.x) + (B * H.y) + (N * H.z)); +} + +void rtAO(inout vec3 lighting, vec3 normal, vec2 noise, vec3 fragpos, float lightmap, float inShadow){ + int nrays = 4; + float occlude = 0.0; + + float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength); + + for (int i = 0; i < nrays; i++){ + int seed = (frameCounter%40000)*nrays+i; + vec2 ij = fract(R2_samples(seed) + noise.rg); + + + vec3 rayDir = TangentToWorld( normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0) ; + + #ifdef HQ_SSGI + vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 30.); // ssr rt + #else + vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 24.); // choc sspt + #endif + + // vec3 lightDir = normalize(vec3(0.2,0.8,0.2)); + // float skyLightDir = dot(rayDir,lightDir); // the positons where the occlusion happens + + float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens + if (rayHit.z > 1.0) occlude += max(rayDir.y,1-AO_Strength); + + + } + // occlude = mix( occlude,1, inShadow); + // occlude = occlude*0.5 + 0.5; + lighting *= 2.5; + lighting *= mix(occlude/nrays,1.0,0) ; +} +void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmap, vec3 albedo, float inShadow){ + int nrays = RAY_COUNT; + vec3 intRadiance = vec3(0.0); + vec3 occlude = vec3(0.0); + + lighting *= 1.50; + float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength); + + for (int i = 0; i < nrays; i++){ + int seed = (frameCounter%40000)*nrays+i; + vec2 ij = fract(R2_samples(seed) + noise ); + + vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0); + + #ifdef HQ_SSGI + vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt + #else + vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt + #endif + + float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens + + if (rayHit.z < 1.){ + vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; + previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; + previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; + if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0) + intRadiance = 0 + texture2D(colortex5,previousPosition.xy).rgb * GI_Strength ; + else + intRadiance += lighting*skyLightDir; // make sure ambient light exists but at screen edges when you turn + + }else{ + intRadiance += lighting*skyLightDir; + } + } + lighting = intRadiance/nrays; +} +float GetCloudShadow(vec3 eyePlayerPos){ + vec3 p3 = (eyePlayerPos + cameraPosition) - Cloud_Height; + vec3 cloudPos = p3*Cloud_Size + WsunVec/abs(WsunVec.y) * ((3250 - 3250*0.35) - p3.y*Cloud_Size) ; + float shadow = getCloudDensity(cloudPos, 1); + // float shadow = (getCloudDensity(cloudPos, 1) + HighAltitudeClouds(cloudPos)) / 2.0; + + shadow = clamp(exp(-shadow*6),0.0,1.0); + + // float timething = (worldTime%24000)*1.0; + // float fadestart_evening = clamp(1.0 - clamp(timething-11500.0 ,0.0,2000.0)/1000. ,0.0,1.0); + // float fadeend_evening = clamp( clamp(14000.0-timething ,0.0,2000.0)/1000. ,0.0,1.0); + + // float fadestart_morning = clamp(clamp(23500.0-timething ,0.0,2000.0)/1000. ,0.0,1.0); + // float fadeend_morning = clamp(1.0 - clamp(timething-200.0 ,0.0,2000.0)/1000. ,0.0,1.0); + + // float TheSettingSun = fadeend_morning; + + return shadow ; +} + +void SubsurfaceScattering(inout float SSS, float Scattering, float Density, float LabDenisty){ + #ifdef LabPBR_subsurface_scattering + float labcurve = pow(LabDenisty,LabSSS_Curve); + SSS = clamp(exp( -(10 - LabDenisty*7) * sqrt(Scattering) ), 0.0, labcurve); + if (abs(Scattering-0.1) < 0.0004 ) SSS = labcurve; + #else + SSS = clamp(exp( -Density * sqrt(Scattering) ), 0.0, 1.0); + if (abs(Scattering-0.1) < 0.0004 ) SSS = 1.0; + #endif +} + + +float densityAtPosSNOW(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); +} + +// Emin's and Gri's combined ideas to stop peter panning and light leaking, also has little shadowacne so thats nice +// https://www.complementary.dev/reimagined +// https://github.com/gri573 +void GriAndEminShadowFix( + inout vec3 WorldPos, + vec3 FlatNormal, + float VanillaAO, + float SkyLightmap, + bool Entities +){ + float DistanceOffset = clamp(0.1 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ; + vec3 Bias = FlatNormal * DistanceOffset; // adjust the bias thingy's strength as it gets farther away. + + // stop lightleaking + if(SkyLightmap < 0.1 && !Entities) { + WorldPos += mix(Bias, 0.5 * (0.5 - fract(WorldPos + cameraPosition + FlatNormal*0.01 ) ), VanillaAO) ; + }else{ + WorldPos += Bias; + } +} + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +void main() { + + vec2 texcoord = gl_FragCoord.xy*texelSize; + 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 tempOffset=TAA_Offset; + + float noise = blueNoise(); + + float z0 = texture2D(depthtex0,texcoord).x; + float z = texture2D(depthtex1,texcoord).x; + + vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; + vec3 np3 = normVec(p3); + + float iswaterstuff = texture2D(colortex7,texcoord).a ; + bool iswater = iswaterstuff > 0.99; + vec4 SpecularTex = texture2D(colortex8,texcoord); + + vec4 data = texture2D(colortex1,texcoord); // terraom + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + vec4 dataUnpacked2 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); + + vec4 translucentCol = texture2D(colortex13,texcoord); // translucents + + + vec3 normal = decode(dataUnpacked0.yw); + + vec4 normalAndAO = texture2D(colortex15,texcoord); + float vanilla_AO = normalAndAO.a; + + normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1); + vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; + + vec3 geometryNormal = normalize(cross(dFdx(p3), dFdy(p3))); + #ifdef Horrible_slope_normals + vec3 slope_normal = normalize(clamp(normal, geometryNormal*2.0 - 1.0,geometryNormal*2.0 + 1.0)); + #else + vec3 slope_normal = normal; + #endif + + + + vec2 lightmap = dataUnpacked1.yz; + + bool translucent = abs(dataUnpacked1.w-0.5) <0.01; // Strong translucency + bool translucent2 = abs(dataUnpacked1.w-0.6) <0.01; // Weak translucency + bool translucent3 = abs(dataUnpacked1.w-0.55) <0.01; // all blocks + bool translucent4 = abs(dataUnpacked1.w-0.65) <0.01; // Weak translucency + bool entities = abs(dataUnpacked1.w-0.45) <0.01; + + bool hand = abs(dataUnpacked1.w-0.75) < 0.01; + bool blocklights = abs(dataUnpacked1.w-0.8) <0.01; + + vec3 filtered = vec3(1.412,1.0,0.0); + if (!hand) filtered = texture2D(colortex3,texcoord).rgb; + + #ifdef WhiteWorld + albedo = vec3(1); + #endif + + float Diffuse_final = 1.0; + + vec3 ambientCoefs = slope_normal/dot(abs(slope_normal),vec3(1.)); + + float cloudShadow = 1.0; + + vec3 color = vec3(0.0); + + vec3 skyTEX = skyFromTex(np3,colortex4)/150. ; + + float lightleakfix = clamp(eyeBrightness.y/240.0 + lightmap.y,0.0,1.0); + + if ( z >= 1.) { //sky + vec4 cloud = texture2D_bicubic(colortex0,texcoord*CLOUDS_QUALITY); + + color += stars(np3); + + #ifndef ambientLight_only + // #ifdef Allow_Vanilla_sky + // vec3 SkyTextured = toLinear(texture2D(colortex12,texcoord).rgb); + // color += SkyTextured * (lightCol.a == 1 ? lightCol.rgb : 0.75 + blackbody2(Moon_temp)) * sqrt(luma(SkyTextured)); + // #else + color += drawSun(dot(lightCol.a * WsunVec, np3),0, lightCol.rgb/150.,vec3(0.0)) ; // sun + color += drawSun(dot(lightCol.a * -WsunVec, np3),0, blackbody2(Moon_temp)/500.,vec3(0.0)); // moon + // #endif + #endif + + color *= clamp(normalize(np3-0.02).y*5.0,0.0,1.0); // fade from the approximated base of the cloud plane, so it doesnt peek under it. + + color += skyTEX; + color = color*cloud.a+cloud.rgb; + + gl_FragData[0].rgb = clamp(fp10Dither(color * 5.0,triangularize(noise)),0.0,65000.); + + }else{//land + + + + ////// ----- direct ----- ////// + + vec3 Direct_lighting = vec3(1.0); + vec3 directLightCol = lightCol.rgb; + + float NdotL = dot(slope_normal,WsunVec); + float diffuseSun = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); + + float shading = clamp(1.0 - filtered.b,0.0,1.0); + if (abs(filtered.y-0.1) < 0.0004 && !iswater) shading = clamp((lightmap.y-0.85)*25,0,1); + + float SSS = 0.0; + float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0); + float SSS_strength = 0.0; + float scattering = 0.0; + + + if (diffuseSun > 0.001) { + + GriAndEminShadowFix(p3, viewToWorld(FlatNormals), normalAndAO.a, lightmap.y, entities); + // p3 += getShadowBias(p3,FlatNormals, diffuseSun, lightmap.y, normalAndAO.a); + + 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 && abs(projectedShadowPosition.z) < 6.0){ + + float diffthresh = 0.0; + if(hand && eyeBrightness.y/240. > 0.0) diffthresh = 0.0003; + + projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5); + shading = 0.0; + + float rdMul = filtered.x*distortFactor*d0*k/shadowMapResolution; + + for(int i = 0; i < SHADOW_FILTER_SAMPLE_COUNT; i++){ + if(hand) noise = 0.0; + vec2 offsetS = tapLocation(i,SHADOW_FILTER_SAMPLE_COUNT,1.618,noise,0.0); + float weight = 1.0+(i+noise)*rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution; + float isShadow = shadow2D(shadow,vec3(projectedShadowPosition + vec3(rdMul*offsetS,-diffthresh*weight))).x; + + shading += isShadow/SHADOW_FILTER_SAMPLE_COUNT; + } + } + } + + #ifdef CAVE_LIGHT_LEAK_FIX + if (isEyeInWater == 0 || (iswater && isEyeInWater == 1) ) shading = mix(0.0, shading, lightleakfix); + #endif + + #ifdef Sub_surface_scattering + #ifdef Variable_Penumbra_Shadows + + if (translucent) SSS_strength = 3; // strong sss + else if (translucent2) SSS_strength = 5; /// weak sss + else if (translucent3) SSS_strength = 5; // misc sss + else if (translucent4) SSS_strength = 10; // mob sss + else SSS_strength = -1; // anything less than zero is no SSS + + bool hasSSS = SSS_strength > 0.0 || LabSSS > 0.0 ; + + if(hasSSS) SubsurfaceScattering(SSS, filtered.y, SSS_strength, LabSSS) ; + + if (isEyeInWater == 0) SSS *= lightleakfix; // light leak fix + #endif + + + + if (!hand){ + + if (abs(filtered.y-0.1) < 0.0004 && ( !translucent || !translucent2 || !translucent3 || !translucent4 ) ) SSS = 0.0; + + #ifndef SCREENSPACE_CONTACT_SHADOWS + + if (abs(filtered.y-0.1) < 0.0004 && ( translucent || translucent2 || translucent4 ) ) SSS = clamp((lightmap.y-0.87)*25,0,1) * clamp(pow(1+dot(WsunVec,normal),25),0,1); + + #else + vec3 vec = lightCol.a*sunVec; + float screenShadow = rayTraceShadow(vec, fragpos, interleaved_gradientNoise()); + + #ifdef Variable_Penumbra_Shadows + shading = min(screenShadow, shading); + if (abs(filtered.y-0.1) < 0.0004 && ( translucent || translucent2 ) ) SSS = shading; + // #else + + #endif + + + #endif + } + + #ifdef Variable_Penumbra_Shadows + SSS = clamp(SSS, diffuseSun*shading, 1.0); + SSS = (phaseg(clamp(dot(np3, WsunVec),0.0,1.0), 0.5) * 10.0 + 0.25 ) * SSS ; + #endif + #else + SSS = 0.0; + #endif + + + #ifdef VOLUMETRIC_CLOUDS + #ifdef CLOUDS_SHADOWS + cloudShadow = GetCloudShadow(p3); + shading *= cloudShadow; + SSS *= cloudShadow; + #endif + #endif + + Diffuse_final = diffuseSun * shading ; + + ////// ----- indirect ----- ////// + + vec3 Indirect_lighting = vec3(1.0); + + // vec3 ambientLight = vec3(0.0); + vec3 ambientLight = avgAmbient * 2.0; + 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 + + custom_lightmap.x = max(custom_lightmap.x, Diffuse_final * 8./150./3. ); // make it so that sunlight color is the same even where ambient light is dark + + // apply ambient light to the sky lightmap and do adjustments + ambientLight = ambientLight * custom_lightmap.x + custom_lightmap.z; + if( (isEyeInWater == 1 && !iswater) ) ambientLight = avgAmbient * 8./150./3.; + ambientLight *= ambient_brightness; + + // add torch lightmap to ambientlight and do adjustments + vec3 Lightsources = custom_lightmap.y * vec3(TORCH_R,TORCH_G,TORCH_B); + if(hand) Lightsources *= 0.15; + + // if(blocklights) Lightsources *= 0.3; + + if(custom_lightmap.y > 10.0) Lightsources *= 0.3; + // Lightsources *= 0.0; + + + ambientLight += Lightsources; + + // debug for direct or ambient + #ifdef ambientLight_only + directLightCol = vec3(0); + #endif + #ifdef ambientLight_only + Indirect_lighting = vec3(0); + #endif + + + + #if indirect_effect == 0 + ambientLight *= 1.0 - exp2(-5 * pow(1-vanilla_AO,3)) ; + float skylight = clamp(abs(ambientCoefs.y+1),0.35,2.0) ; + ambientLight *= skylight; + #endif + #if indirect_effect == 1 + ambientLight *= mix(1.0 - exp2(-5 * pow(1-vanilla_AO,2)), 1.0, diffuseSun*shading) ; + if (!hand) ssAO(ambientLight, fragpos, 1.0, blueNoise(gl_FragCoord.xy).rg, FlatNormals , texcoord, ambientCoefs, lightmap.xy, diffuseSun*shading ) ; + #endif + #if indirect_effect == 2 + if (!hand) rtAO(ambientLight, slope_normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.y, diffuseSun*shading); + #endif + #if indirect_effect == 3 + if (!hand) rtGI(ambientLight, slope_normal, blueNoise(gl_FragCoord.xy).rg, fragpos, lightmap.y, albedo, diffuseSun*shading); + #endif + + Indirect_lighting = ambientLight; + + vec3 waterabsorb_speculars = vec3(1); + + if ((iswater && isEyeInWater == 0) || (!iswater && isEyeInWater == 1) || iswaterstuff == 1.0){ + + vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z0)); + float Vdiff = distance(fragpos,fragpos0); + float VdotU = np3.y; + float estimatedDepth = Vdiff * abs(VdotU); //assuming water plane + float estimatedDepth2 = Vdiff * abs(VdotU); //assuming water plane + if (isEyeInWater == 1){ + Vdiff = length(fragpos); + estimatedDepth = clamp((15.5-lightmap.y*16.0)/15.5,0.,1.0); + estimatedDepth *= estimatedDepth*estimatedDepth*32.0; + + #ifndef lightMapDepthEstimation + estimatedDepth = max(Water_Top_Layer - (cameraPosition.y+p3.y),0.0); + #endif + + estimatedDepth2 = clamp((15.5-lightmap.y*16.0)/15.5,0.,1.0); + estimatedDepth2 *= estimatedDepth2*estimatedDepth2*32.0; + } + + float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane + vec3 thething = exp2(-totEpsilon*estimatedSunDepth); + + float estimatedSunDepth2 = estimatedDepth2/abs(WsunVec.y); //assuming water plane + vec3 thething2 = max(exp2(-totEpsilon*estimatedSunDepth2),0.01); + // water absorbtion for the sunlight. when this isnt active, the water fog is + if (isEyeInWater == 1) directLightCol *= thething*(0.91-pow(1.0-WsunVec.y,5.0)*0.86); + + // allow the sun specular reflection to have water absorbtion when looking at it from outside the water + // waterabsorb_speculars.rgb = (iswater && isEyeInWater == 0) ? waterabsorb_speculars.rgb * thething*(0.91-pow(1.0-WsunVec.y,5.0)*0.86) : waterabsorb_speculars.rgb; + waterabsorb_speculars.rgb = waterabsorb_speculars.rgb*thething; + // caustics... + float Direct_caustics = waterCaustics(mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition, WsunVec); + float Ambient_Caustics = waterCaustics(mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition, vec3(0.5, 1.0, 0.5)); + + // apply caustics to the sunlight + directLightCol *= 0.5 + max(pow(Direct_caustics*2,2),0.0); + + + // interpolate between normal ambient light to a different ambient light with caustics and water absorbtion + Ambient_Caustics = 0.5 + max(pow(Ambient_Caustics,2),0.0); + // vec3 underwater_ambient = max(Ambient_Caustics ,0.0) ; + + + // if( (isEyeInWater == 1 && iswater) || (isEyeInWater == 1 && !iswater) ) Indirect_lighting *= 8./150./3.*0.5; + if( isEyeInWater == 1 && !iswater ) Indirect_lighting = Indirect_lighting*thething + Indirect_lighting*Ambient_Caustics*thething2 + Lightsources ; + + + //combine all light sources + // Direct_lighting = max(Diffuse_final ,SSS) * (directLightCol/127.0); + // gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo; + + } + #ifdef Seasons + #ifdef Snowy_Winter + float SnowPatches = densityAtPosSNOW(vec3(p3.x,p3.y/48.,p3.z)*250); + SnowPatches = 1.0 - clamp( exp(pow(SnowPatches,3.5) * -100.0) ,0,1); + SnowPatches *= clamp(sqrt(normal.y),0,1) * clamp(pow(lightmap.y,25)*25,0,1); + + if(!hand && !iswater){ + albedo = mix(albedo, vec3(0.8,0.9,1.0), SnowPatches); + SpecularTex.rg = mix(SpecularTex.rg, vec2(1,0.05), SnowPatches); + } + #endif + #endif + + //combine all light sources + // Direct_lighting = max(Diffuse_final ,SSS) * (directLightCol/127.0) ; + Direct_lighting = max(Diffuse_final ,SSS) * (directLightCol/127.0) ; + gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo; + + // do this after water and stuff is done because yea + #ifdef Specular_Reflections + MaterialReflections(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, WsunVec, lightCol.rgb * waterabsorb_speculars, Diffuse_final , lightmap.y, slope_normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise()), hand); + #endif + + #ifdef LabPBR_Emissives + gl_FragData[0].rgb = SpecularTex.a < 255.0/255.0 ? mix(gl_FragData[0].rgb, albedo * Emissive_Brightness , SpecularTex.a) + Direct_lighting*albedo : gl_FragData[0].rgb; + #endif + } + + + #ifdef Glass_Tint + // glass tint. + vec4 glassColor = texture2D(colortex13,texcoord); + + #ifdef BorderFog + float fog = 1.0 - clamp( exp2(-pow(length(fragpos / far),10.)*4.0) ,0.0,1.0); + if(z < 1.0 && isEyeInWater == 0 && glassColor.a > 0.0) gl_FragData[0].rgb = mix(gl_FragData[0].rgb, skyTEX * 5.0, fog*lightleakfix ) ; + #endif + + float colorstrength = 0.75; + glassColor.rgb *= 5.; + if(glassColor.a > 0.0 && !iswater && (iswaterstuff < 0.1 && iswaterstuff > 0.0 )) gl_FragData[0].rgb = gl_FragData[0].rgb*glassColor.rgb + gl_FragData[0].rgb * clamp(pow(1.0-luma(glassColor.rgb),5.),0,1); + #endif + + + if (iswater){ + vec3 fragpos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z0)); + float Vdiff = distance(fragpos,fragpos0); + float VdotU = np3.y; + float estimatedDepth = Vdiff * abs(VdotU); //assuming water plane + float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane + + float custom_lightmap_T = texture2D(colortex14, texcoord).x; // y = torch + + vec3 ambientColVol = avgAmbient * 8./150./1.5 * max(custom_lightmap_T,0.0025); + vec3 lightColVol = lightCol.rgb * 8./127. * max(lightleakfix,0.0); + + if (isEyeInWater == 0) waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth, estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(np3, WsunVec)); + } + + + // gl_FragData[0].rgb = vec3(1) * viewToWorld(FlatNormals); + + + + /* RENDERTARGETS:3 */ +} \ No newline at end of file diff --git a/shaders/composite2.vsh b/shaders/composite2.vsh new file mode 100644 index 0000000..074231c --- /dev/null +++ b/shaders/composite2.vsh @@ -0,0 +1,75 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#define TAA +#define SEPARATE_AO +flat varying vec3 WsunVec; +flat varying vec3 avgAmbient; +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 vec4 lightCol; +flat varying float tempOffsets; +flat varying vec2 TAA_Offset; +flat varying vec3 zMults; + +attribute vec4 mc_Entity; +uniform sampler2D colortex4; +varying vec4 lmtexcoord; +// varying float vanilla_ao; + +uniform float far; +uniform float near; +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +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" +#include "/lib/res_params.glsl" +void main() { + gl_Position = ftransform(); + + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif + + 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(0,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); + + + +} diff --git a/shaders/composite3.fsh b/shaders/composite3.fsh new file mode 100644 index 0000000..32a8481 --- /dev/null +++ b/shaders/composite3.fsh @@ -0,0 +1,89 @@ +#version 120 +//Render sky, volumetric clouds, direct lighting +#extension GL_EXT_gpu_shader4 : enable + +// #define BorderFog // aaaaaaaaaaaaaaaaaaaaaaa + +#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] + +uniform vec2 texelSize; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; +uniform sampler2D colortex3; +uniform sampler2D colortex13; +uniform sampler2D colortex4; + +uniform int frameCounter; +uniform float frameTimeCounter; + +uniform vec3 cameraPosition; + +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelViewInverse; +flat varying vec2 TAA_Offset; +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) + +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) + +uniform float far; +uniform float near; + +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 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} + +uniform int isEyeInWater; +uniform ivec2 eyeBrightnessSmooth; +uniform float blindness; +uniform float darknessFactor; + +#include "lib/sky_gradient.glsl" + +void main() { + /* DRAWBUFFERS:3 */ + + vec2 texcoord = gl_FragCoord.xy*texelSize; + gl_FragData[0].rgb = texture2D(colortex3, texcoord).rgb; + + ///////////////// border fog + +#ifdef BorderFog + vec2 tempOffset = TAA_Offset; + float z = texture2D(depthtex0,texcoord).x; + + vec3 fragpos = toScreenSpace(vec3(texcoord -vec2(tempOffset)*texelSize*0.5,z)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + vec3 worldpos = p3 + (gbufferModelViewInverse[3].xyz+cameraPosition) ; + + + vec3 sky = skyFromTex(np3,colortex4) / 150. * 5.; + + float fog = 1.0 - clamp( exp(-pow(length(fragpos / far),10.)*4.0) ,0.0,1.0); + + + float lightleakfix = clamp(eyeBrightnessSmooth.y/240.0,0.0,1.0); + float heightFalloff = clamp( pow(abs(np3.y-1.01),10) ,0,1) ; + // if(z < 1.0 && isEyeInWater == 0) + + if(z < 1.0 && isEyeInWater == 0) gl_FragData[0].rgb = mix(gl_FragData[0].rgb, sky, fog*lightleakfix*heightFalloff ) ; + + +#endif + + + +} \ No newline at end of file diff --git a/shaders/composite3.vsh b/shaders/composite3.vsh new file mode 100644 index 0000000..b2da16c --- /dev/null +++ b/shaders/composite3.vsh @@ -0,0 +1,29 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + +flat varying float tempOffsets; +uniform int frameCounter; +flat varying vec2 TAA_Offset; + +#include "/lib/util.glsl" +#include "/lib/res_params.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.); + +void main() { + gl_Position = ftransform(); + + + TAA_Offset = offsets[frameCounter%8]; + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif + +} diff --git a/shaders/composite5.fsh b/shaders/composite5.fsh new file mode 100644 index 0000000..1f2fe6d --- /dev/null +++ b/shaders/composite5.fsh @@ -0,0 +1,414 @@ +#version 120 +//Volumetric fog rendering +#extension GL_EXT_gpu_shader4 : enable +#define CLOUDS_SHADOWS +#define VL_CLOUDS_SHADOWS // Casts shadows from clouds on VL (slow) +#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 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 Cloudy_Fog_Density 5.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 Uniform_Fog_Density 1.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 uniformfog_fade 10 // does not change rain or cave fog [5 10 20 30 40 50 60 70 80 90 100] +#define cloudyfog_fade 10 // does not change rain or cave fog [5 10 20 30 40 50 60 70 80 90 100] + +#define RainFog_amount 5 // [0 1 2 3 4 5 6 7 8 9 10 15 20 25] +#define CaveFog_amount 5 // [0 1 2 3 4 5 6 7 8 9 10 15 20 25] +#define cloudray_amount 0.2 // rain boost this [0.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] + +#define UniformFog_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] +#define CloudyFog_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 20 30 40 50 100 500 10000] +#define TimeOfDayFog_multiplier 1.0 // Influence of time of day on fog amount [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 Haze_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_selfShadowing // make the fog cast a shadow onto itself + + + +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 vec3 avgAmbient; +flat varying float tempOffsets; +flat varying float fogAmount; +flat varying float VFAmount; +flat varying float FogSchedule; +uniform sampler2D noisetex; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; +uniform sampler2DShadow shadow; +flat varying vec3 refractedSunVec; +flat varying vec3 WsunVec; + +uniform sampler2D colortex1; +uniform sampler2D colortex2; +uniform sampler2D colortex3; +// uniform sampler2D colortex4; + +uniform vec3 sunVec; +uniform float far; +uniform float near; +uniform int frameCounter; +uniform float rainStrength; +uniform float sunElevation; +uniform ivec2 eyeBrightnessSmooth; +uniform float frameTimeCounter; +uniform int isEyeInWater; +uniform vec2 texelSize; + + +#include "lib/waterOptions.glsl" +#include "lib/Shadow_Params.glsl" +#include "lib/color_transforms.glsl" +#include "lib/color_dither.glsl" +#include "lib/projections.glsl" +#include "lib/sky_gradient.glsl" +#include "/lib/res_params.glsl" +// #include "lib/biome_specifics.glsl" + +#define TIMEOFDAYFOG +#include "lib/volumetricClouds.glsl" + + +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) ; +} +float R2_dither2(){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha.x *(1- gl_FragCoord.x) + alpha.y * (1-gl_FragCoord.y) + 1.0/1.6180339887 * frameCounter) ; +} +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 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 GetCloudShadow(vec3 eyePlayerPos){ + vec3 worldPos = (eyePlayerPos + cameraPosition) - Cloud_Height; + vec3 cloudPos = worldPos*Cloud_Size + WsunVec/abs(WsunVec.y) * ((3250 - 3250*0.35) - worldPos.y*Cloud_Size) ; + float shadow = getCloudDensity(cloudPos, 1); + + shadow = clamp(exp(-shadow*5),0.0,1.0); + + return shadow ; +} + +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 fog_densities_atmospheric = 24 * Haze_amount; // this is seperate from the cloudy and uniform fog. + +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); + + + float mult = exp( -max((pos.y - SEA_LEVEL) / 35.,0.0)); + + float fog_shape = 1-densityAtPosFog(samplePos * 24.0); + float fog_eroded = 1-densityAtPosFog( samplePos2 * 200.0); + + float CloudyFog = max( (fog_shape*2.0 - fog_eroded*0.5) - 1.2, 0.0) * mult; + float UniformFog = exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)); + + float RainFog = max(fog_shape*10. - 7.,0.5) * exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)) * 5. * rainStrength; + + TimeOfDayFog(UniformFog, CloudyFog); + + return CloudyFog + UniformFog + RainFog; +} + +mat2x3 getVolumetricRays( + float dither, + vec3 fragpos, + float dither2 +){ + //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*5)/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 = phaseg(SdotV,0.7)*5.0 + 1.0; + float rayL = phaseRayleigh(SdotV); + + // Makes fog more white idk how to simulate it correctly + vec3 sunColor = lightCol.rgb / 127.0; + vec3 skyCol0 = (ambientUp / 150. * 5.); // * max(abs(WsunVec.y)/150.0,0.); + + 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 = mu; + vec3 absorbance = vec3(1.0); + float expFactor = 11.0; + vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; + + float cloudShadow = 1.0; + + for (int i=0;i 1e-5)*2-1.; + lightCol.rgb = sc; + + TAA_Offset = offsets[frameCounter%8]; + #ifndef TAA + TAA_Offset = vec2(0.0); + #endif + + #ifndef VL_Clouds_Shadows + lightCol.rgb *= (1.0-rainStrength*0.9); + #endif + // float Time = worldTime%24000; + + // FogSchedule = clamp( (Time - 9000)/9000 ,0,1); + // // float fogAmount0 = 1/3000.+FOG_TOD_MULTIPLIER*(1/100.*(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/120.*clamp(modWT-13000.,0.,1000.0)/1000.*(1.0-clamp(modWT-23000.,0.,1000.0)/1000.)); + + // float fogAmount0 = TimeOfDayFog; + + // // VFAmount = CLOUDY_FOG_AMOUNT*(fogAmount0*fogAmount0+FOG_RAIN_MULTIPLIER*1.0/20000.*rainStrength); + // VFAmount = fogAmount0; + // fogAmount = BASE_FOG_AMOUNT*(fogAmount0+max(FOG_RAIN_MULTIPLIER*1/10.*rainStrength , FOG_TOD_MULTIPLIER*1/50.*clamp(modWT-13000.,0.,1000.0)/1000.*(1.0-clamp(modWT-23000.,0.,1000.0)/1000.))); + + + + + WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) *sunPosition); + refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333); +} diff --git a/shaders/composite6.fsh b/shaders/composite6.fsh new file mode 100644 index 0000000..5d16df1 --- /dev/null +++ b/shaders/composite6.fsh @@ -0,0 +1,325 @@ +#version 120 +//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog +#extension GL_EXT_gpu_shader4 : enable + +#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 Refraction + + +#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 +flat varying vec3 zMults; +flat varying vec2 TAA_Offset; + + +/* +const int colortex11Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +*/ + + +uniform sampler2D noisetex; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; +uniform sampler2D colortex0; +uniform sampler2D colortex1; +uniform sampler2D colortex2; +uniform sampler2D colortex3; +// uniform sampler2D colortex4; +uniform sampler2D colortex5; +uniform sampler2D colortex6; +uniform sampler2D colortex7; +uniform sampler2D colortex8; +uniform sampler2D colortex9; +uniform sampler2D colortex11; +uniform sampler2D colortex13; +uniform sampler2D colortex15; +uniform vec2 texelSize; + +flat varying vec3 noooormal; +flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +flat varying vec3 WsunVec; + +uniform vec3 sunVec; +uniform float frameTimeCounter; +uniform int frameCounter; +uniform float far; +uniform float near; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferModelView; +uniform mat4 gbufferPreviousModelView; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferProjection; +uniform mat4 gbufferPreviousProjection; +uniform vec3 cameraPosition; +uniform vec3 previousCameraPosition; + +uniform int 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/res_params.glsl" + +#include "lib/sky_gradient.glsl" +#include "lib/volumetricClouds.glsl" +// #include "lib/biome_specifics.glsl" + + + +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) + +float ld(float depth) { + return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near +} +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} +vec3 toLinear(vec3 sRGB){ + return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); +} +vec3 toScreenSpace(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 p3 = p * 2. - 1.; + vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} + + +#include "lib/specular.glsl" + + + + +vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){ + coord = coord; + vec4 vl = vec4(0.0); + float sum = 0.0; + mat3x3 weights; + const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION); + ivec2 posD = ivec2(coord*VL_RENDER_RESOLUTION)*scaling; + ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION); + float dz = zMults.x; + ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2; + + ivec2 tcDepth = posD + ivec2(-2,-2) * scaling + pos * scaling; + 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(-2,0) * scaling + pos * scaling; + 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 * scaling; + 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) * scaling + pos * scaling; + 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; +} + +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 ; +} + +vec3 worldToView(vec3 worldPos) { + vec4 pos = vec4(worldPos, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; +} +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); +} +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} + +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 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} + +void main() { + vec2 texcoord = gl_FragCoord.xy*texelSize; + /* DRAWBUFFERS:73 */ + + vec4 transparencies = texture2D(colortex2,texcoord); + vec4 trpData = texture2D(colortex7,texcoord); + + vec4 speculartex = texture2D(colortex8,texcoord); // translucents + float sunlight = speculartex.b; + + bool iswater = trpData.a > 0.99; + float translucentAlpha = trpData.a; + + //3x3 bilateral upscale from half resolution + float z = texture2D(depthtex0,texcoord).x; + float z2 = texture2D(depthtex1,texcoord).x; + float frDepth = ld(z2); + vec4 vl = BilateralUpscale(colortex0,depthtex1,gl_FragCoord.xy,frDepth); + // vec4 vl = texture2D(colortex0,texcoord * 0.5); + + + vec4 data = texture2D(colortex11,texcoord); // translucents + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + + vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) ); + + vec4 data_terrain = texture2D(colortex1,texcoord); // terraom + vec4 dataUnpacked1_terrain = vec4(decodeVec2(data_terrain.z),decodeVec2(data_terrain.w)); + + bool hand = (abs(dataUnpacked1_terrain.w-0.75) < 0.01); + + + vec2 refractedCoord = texcoord; + + float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); // bloomy rain effect + + + + vec2 tempOffset = TAA_Offset; + vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); + vec3 fragpos2 = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z2)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + #ifdef Refraction + vec3 worldPos = p3 + cameraPosition; + + // thank you sixthsurge, though i may be doing stuff weirdly with the tangent, it works... as far as i can tell. + vec3 geometryNormal = normalize(cross(dFdx(worldPos), dFdy(worldPos))); + + vec3 geometryNormal2 = geometryNormal; + vec3 tangent = geometryNormal2.y > 0.50 || geometryNormal2.y < -0.50 ? normalize(cross(vec3(0,0,1),geometryNormal)) : normalize(cross(vec3(0.0, 1.0, 0.0), geometryNormal)); + + // vec3 tangent = normalize(cross(vec3(1.0, 1.0, 1.0), geometryNormal)) ; + vec3 bitangent = normalize(cross(tangent, geometryNormal)) ; + mat3 tbn = mat3(tangent, bitangent, geometryNormal); + vec3 tangentSpaceNormal = normals * tbn; + + float dist = clamp(ld(fragpos.z)*100,0,0.15); // shrink as distance increases + + if( translucentAlpha > 0.0) refractedCoord += (tangentSpaceNormal.xy * dist ) * RENDER_SCALE; + + bool glass = texture2D(colortex7,refractedCoord).a > 0.0 && texture2D(colortex13,texcoord).a > 0.0; + if(!glass) refractedCoord = texcoord; + #endif + + // underwater squiggles + // if(isEyeInWater == 1 && !iswater) refractedCoord = texcoord + pow(texture2D(noisetex,texcoord - vec2(0,frameTimeCounter/25)).b - 0.5, 2.0)*0.05; + + + vec3 color = texture2D(colortex3,refractedCoord).rgb; + + if (frDepth > 2.5/far || transparencies.a < 0.99 || !hand) color = color * (1.0-transparencies.a) + transparencies.rgb*10.; // Discount fix for transparencies through hand + + + + 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 ; + + if(rainDrops > 0.0) { + // refractedCoord = mix(refractedCoord, vec2(texcoord.x,texcoord.y * 0.9 + 0.05), rainStrength) ; + vl.a *= clamp(exp2(-rainDrops*5),0.,1.); // bloomy rain effect + } + + + float lightleakfix = clamp((eyeBrightnessSmooth.y )/240.0,0.0,1.0); + + //cave fog + #ifdef Cave_fog + if (isEyeInWater == 0){ + float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0); + float fogfade = clamp( exp(clamp( np3.y*0.5 +0.5,0,1) * -6.0) ,0.0,1.0); + + color.rgb = mix(color.rgb, vec3(CaveFogColor_R,CaveFogColor_G,CaveFogColor_B)*fogfade, fogdistfade * (1.0-lightleakfix) * (1.0-darknessFactor)* clamp( 1.5 - np3.y,0.,1)) ; + // color.rgb = mix(color.rgb, vec3(CaveFogColor_R,CaveFogColor_G,CaveFogColor_B)*fogfade, fogdistfade) ; + } + #endif + + // underwater fog + if (isEyeInWater == 1){ + float fogfade = clamp(exp(-length(fragpos) /9. ) ,0.0,1.0); + color.rgb *= fogfade; + vl.a *= fogfade*0.70+0.3 ; + } + + color += vl.rgb; + gl_FragData[0].r = vl.a; + + /// 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); + color.rgb *= mix(1.0, clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -5),0.,1.) , blindness); + + // darkness effect + color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); + + + gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); + + #ifdef display_LUT + gl_FragData[1].rgb = texture2D(colortex4,texcoord/2.5).rgb *0.035; + #endif + + // gl_FragData[1].rgb =mix(vec3(0.2,0.5,1), vec3(0,0,0), clamp( exp2(pow(clamp(0.5-np3.y,0,1) ,2)* -0.5) ,0,1)); +} \ No newline at end of file diff --git a/shaders/composite6.vsh b/shaders/composite6.vsh new file mode 100644 index 0000000..be43d51 --- /dev/null +++ b/shaders/composite6.vsh @@ -0,0 +1,53 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + +flat varying vec4 lightCol; +flat varying vec3 WsunVec; + +uniform mat4 gbufferModelViewInverse; +uniform int frameCounter; +uniform vec3 sunPosition; +uniform float sunElevation; + +flat varying vec2 TAA_Offset; +uniform sampler2D colortex4; +flat varying vec3 zMults; +uniform float far; +uniform float near; +#include "/lib/res_params.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.); + + +flat varying vec3 noooormal; +//////////////////////////////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(); + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif + + TAA_Offset = offsets[frameCounter%8]; + #ifndef TAA + TAA_Offset = vec2(0.0); + #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); + + vec3 noooormal = normalize(gl_NormalMatrix * gl_Normal); +} diff --git a/shaders/composite7.fsh b/shaders/composite7.fsh new file mode 100644 index 0000000..cc57f47 --- /dev/null +++ b/shaders/composite7.fsh @@ -0,0 +1,44 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +uniform sampler2D colortex3; +// Compute 3x3 min max for TAA + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:06 */ + ivec2 center = ivec2(gl_FragCoord.xy); + vec3 current = texelFetch2D(colortex3, center, 0).rgb; + vec3 cMin = current; + vec3 cMax = current; + current = texelFetch2D(colortex3, center + ivec2(-1, -1), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(-1, 0), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(-1, 1), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(0, -1), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(0, 1), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(1, -1), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(1, 0), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + current = texelFetch2D(colortex3, center + ivec2(1, 1), 0).rgb; + cMin = min(cMin, current); + cMax = max(cMax, current); + gl_FragData[0].rgb = cMax; + gl_FragData[1].rgb = cMin; +} diff --git a/shaders/composite7.vsh b/shaders/composite7.vsh new file mode 100644 index 0000000..060ffeb --- /dev/null +++ b/shaders/composite7.vsh @@ -0,0 +1,17 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + + +#include "/lib/res_params.glsl" +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { + gl_Position = ftransform(); + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif +} diff --git a/shaders/composite8.fsh b/shaders/composite8.fsh new file mode 100644 index 0000000..f7989d9 --- /dev/null +++ b/shaders/composite8.fsh @@ -0,0 +1,458 @@ +#version 120 +//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader) + +#extension GL_EXT_gpu_shader4 : enable + +#include "lib/res_params.glsl" + + +//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.0 //[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 0.0 //[0.0 0.25 0.5 0.75 1.0] High values reduce ghosting but may create flickering +#define FLICKER_REDUCTION 0.5 //[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 + +// #define SCREENSHOT_MODE // go render mode and accumulate frames for as long as you want for max image quality. +// #define SPLIT_RENDER // AAAAAAAAAAAAAAAA + +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) + +#ifdef SCREENSHOT_MODE + const int colortex5Format = RGBA32F; //TAA buffer (everything) +#else + const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) +#endif + +const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final) +const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) +const int colortex8Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +const int colortex9Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) +const int colortex10Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +const int colortex13Format = RGBA16F; //Final output, transparencies id (gbuffer->composite4) +// const int colortex15Format = RGBA16F; // flat normals and vanilla +*/ +//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 colortex0; +uniform sampler2D colortex6; +uniform sampler2D colortex7; +uniform sampler2D colortex1; +uniform sampler2D colortex10; +uniform sampler2D colortex13; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; + +uniform vec2 texelSize; +uniform float frameTimeCounter; +uniform float viewHeight; +uniform float viewWidth; +uniform int frameCounter; +uniform int framemod8; +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 closestToCamera5taps(vec2 texcoord, sampler2D depth) +{ + vec2 du = vec2(texelSize.x*2., 0.0); + vec2 dv = vec2(0.0, texelSize.y*2.); + + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x); + + vec3 dmin = dmc; + dmin = dmin.z > dtr.z? dtr : dmin; + dmin = dmin.z > dtl.z? dtl : dmin; + dmin = dmin.z > dbl.z? dbl : dmin; + dmin = dmin.z > dbr.z? dbr : dmin; + #ifdef TAA_UPSCALING + dmin.xy = dmin.xy/RENDER_SCALE; + #endif + 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 ); + uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0); + 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; +} +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); +} +//approximation from SMAA presentation from siggraph 2016 +vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount) +{ + vec2 position = rtMetrics.zw * texcoord; + vec2 centerPosition = floor(position - 0.5) + 0.5; + vec2 f = position - centerPosition; + vec2 f2 = f * f; + vec2 f3 = f * f2; + + float c = sharpenAmount; + vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f; + vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0; + vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f; + vec2 w3 = c * f3 - c * f2; + + vec2 w12 = w1 + w2; + vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12); + vec3 centerColor = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb; + + vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); + vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); + vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + + vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + + vec4(centerColor, 1.0) * (w12.x * w12.y) + + vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + + vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); + return color.rgb/color.a; + +} + +vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max) + { + vec3 p_clip = 0.5 * (aabb_max + aabb_min); + vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001; + + vec3 v_clip = q - vec3(p_clip); + vec3 v_unit = v_clip.xyz / e_clip; + vec3 a_unit = abs(v_unit); + float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); + + if (ma_unit > 1.0) + return vec3(p_clip) + v_clip / ma_unit; + else + return q; + } +vec3 toClipSpace3Prev(vec3 viewSpacePosition) { + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +} + +vec3 tonemap(vec3 col){ + return col/(1+luma(col)); +} +vec3 invTonemap(vec3 col){ + return col/(1-luma(col)); +} +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); +vec3 TAA_hq(bool hand, bool istranslucent){ + #ifdef TAA_UPSCALING + vec2 adjTC = clamp(texcoord*RENDER_SCALE, vec2(0.0),RENDER_SCALE-texelSize*2.); + #else + vec2 adjTC = texcoord; + #endif + + //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion + #ifdef CLOSEST_VELOCITY + vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); + #endif + + #ifndef CLOSEST_VELOCITY + vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x); + #endif + + //reproject previous frame + vec3 fragposition = toScreenSpace(closestToCamera); + fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz; + previousPosition = toClipSpace3Prev(previousPosition); + vec2 velocity = previousPosition.xy - closestToCamera.xy; + previousPosition.xy = texcoord + velocity; + + //reject history if off-screen and early exit + if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) + return smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz; + + #ifdef TAA_UPSCALING + vec3 albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz; + // Interpolating neighboorhood clampling boundaries between pixels + vec3 cMax = texture2D(colortex0, adjTC).rgb; + vec3 cMin = texture2D(colortex6, adjTC).rgb; + #else + vec3 albedoCurrent0 = texture2D(colortex3, adjTC).rgb; + vec3 albedoCurrent1 = texture2D(colortex3, adjTC + vec2(texelSize.x,texelSize.y)).rgb; + vec3 albedoCurrent2 = texture2D(colortex3, adjTC + vec2(texelSize.x,-texelSize.y)).rgb; + vec3 albedoCurrent3 = texture2D(colortex3, adjTC + vec2(-texelSize.x,-texelSize.y)).rgb; + vec3 albedoCurrent4 = texture2D(colortex3, adjTC + vec2(-texelSize.x,texelSize.y)).rgb; + vec3 albedoCurrent5 = texture2D(colortex3, adjTC + vec2(0.0,texelSize.y)).rgb; + vec3 albedoCurrent6 = texture2D(colortex3, adjTC + vec2(0.0,-texelSize.y)).rgb; + vec3 albedoCurrent7 = texture2D(colortex3, adjTC + vec2(-texelSize.x,0.0)).rgb; + vec3 albedoCurrent8 = texture2D(colortex3, adjTC + vec2(texelSize.x,0.0)).rgb; + //Assuming the history color is a blend of the 3x3 neighborhood, we clamp the history to the min and max of each channel in the 3x3 neighborhood + vec3 cMax = max(max(max(albedoCurrent0,albedoCurrent1),albedoCurrent2),max(albedoCurrent3,max(albedoCurrent4,max(albedoCurrent5,max(albedoCurrent6,max(albedoCurrent7,albedoCurrent8)))))); + vec3 cMin = min(min(min(albedoCurrent0,albedoCurrent1),albedoCurrent2),min(albedoCurrent3,min(albedoCurrent4,min(albedoCurrent5,min(albedoCurrent6,min(albedoCurrent7,albedoCurrent8)))))); + albedoCurrent0 = smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).rgb; + #endif + + #ifndef NO_CLIP + vec3 albedoPrev = max(FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.75).xyz, 0.0); + vec3 finalcAcc = clamp(albedoPrev,cMin,cMax); + + //Increases blending factor when far from AABB and in motion, reduces ghosting + float isclamped = distance(albedoPrev,finalcAcc)/luma(albedoPrev) * 0.5; + float movementRejection = (0.12+isclamped)*clamp(length(velocity/texelSize),0.0,1.0); + + float test = 0.05; + if(hand) movementRejection *= 5; + if(istranslucent) test = 0.1; + + //Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering + // vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.))); + + vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.))); + #endif + + + #ifdef NO_CLIP + vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz; + vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.)); + #endif + + //De-tonemap + return supersampled; +} + + +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 ; +} +vec2 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n)*2.-1.0; +} +vec4 TAA_hq_render(){ + #ifdef TAA_UPSCALING + vec2 adjTC = clamp(texcoord*RENDER_SCALE, vec2(0.0),RENDER_SCALE-texelSize*2.); + #else + vec2 adjTC = texcoord; + #endif + + //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion + #ifdef CLOSEST_VELOCITY + vec3 closestToCamera = closestToCamera5taps(adjTC,depthtex0); + #endif + + #ifndef CLOSEST_VELOCITY + vec3 closestToCamera = vec3(texcoord,texture2D(depthtex0,adjTC).x); + #endif + + //reproject previous frame + vec3 fragposition = toScreenSpace(closestToCamera); + fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz; + previousPosition = toClipSpace3Prev(previousPosition); + vec2 velocity = previousPosition.xy - closestToCamera.xy; + previousPosition.xy = texcoord + velocity; + + // //reject history if off-screen and early exit + if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) + return vec4(smoothfilter(colortex3, adjTC + R2_samples(frameCounter)*texelSize*0.5).xyz, 1.0); + + vec3 albedoCurrent0 = smoothfilter(colortex3, adjTC + R2_samples(frameCounter)*texelSize*0.5).xyz; + + float rej = 0.0; + vec4 albedoPrev = texture2D(colortex5, previousPosition.xy); + vec3 supersampled = albedoPrev.rgb * albedoPrev.a + albedoCurrent0; + + if (length(velocity) > 1e-6) return vec4(albedoCurrent0,1.0); + return vec4(supersampled/(albedoPrev.a+1.0), albedoPrev.a+1.0); +} + +void main() { + +/* DRAWBUFFERS:5 */ + + // vec3 motionVector = texture2D(colortex10,texcoord).xyz ; + + // vec3 viewpos = motionVector; + // vec3 eyepos = mat3(gbufferModelViewInverse) * viewpos; + // vec3 worldPos = eyepos + (cameraPosition + gbufferModelViewInverse[3].xyz); + // vec3 feetPos = worldPos - cameraPosition; + + // vec4 clippos = gbufferProjection * vec4(viewpos,1.0); + + // vec3 ndcPos = projectAndDivide(gbufferProjectionInverse, viewpos); + // vec3 screenPos = ndcPos * 0.5 + 0.5; + + // vec3 movement = ( cameraPosition - previousCameraPosition); + + + gl_FragData[0].a = 1.0; +#ifndef SPLIT_RENDER + #ifdef SCREENSHOT_MODE + + + vec4 color = TAA_hq_render(); + gl_FragData[0] = color; + + + #else + #ifdef TAA + vec4 data = texture2D(colortex1,texcoord* RENDER_SCALE); // terraom + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + bool hand = abs(dataUnpacked1.w-0.75) < 0.01; + bool translucentCol = texture2D(colortex13,texcoord * RENDER_SCALE).a > 0.0; // translucents + + + + vec3 color = TAA_hq(hand, translucentCol); + gl_FragData[0].rgb = clamp(fp10Dither(color ,triangularize(R2_dither())),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 + #endif +#endif +#ifdef SPLIT_RENDER + if(texcoord.x > 0.5){ + + vec4 color = TAA_hq_render(); + gl_FragData[0] = color; + + }else{ + vec4 data = texture2D(colortex1,texcoord* RENDER_SCALE); // terraom + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + bool hand = abs(dataUnpacked1.w-0.75) < 0.01; + bool translucentCol = texture2D(colortex13,texcoord * RENDER_SCALE).a > 0.0; // translucents + + + + vec3 color = TAA_hq(hand, translucentCol); + gl_FragData[0].rgb = clamp(fp10Dither(color ,triangularize(R2_dither())),6.11*1e-5,65000.0); + + } +#endif +} diff --git a/shaders/composite8.vsh b/shaders/composite8.vsh new file mode 100644 index 0000000..24ef8ce --- /dev/null +++ b/shaders/composite8.vsh @@ -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; +} diff --git a/shaders/composite9.fsh b/shaders/composite9.fsh new file mode 100644 index 0000000..50d2602 --- /dev/null +++ b/shaders/composite9.fsh @@ -0,0 +1,49 @@ +#version 120 +//downsample 1st pass (half res) for bloom + +uniform sampler2D colortex5; +// uniform sampler2D colortex8; +uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; + +#include "lib/res_params.glsl" + + +void main() { +/* DRAWBUFFERS:3 */ + + +vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); +vec2 quarterResTC = gl_FragCoord.xy*texelSize*2.*resScale/BLOOM_QUALITY; + +// float emissives1 = texture2D(colortex8,quarterResTC).a; +// float emissives2 = emissives1 < 1.0 ? emissives1 : 0.0; + + // 0.5 + gl_FragData[0] = texture2D(colortex5,quarterResTC-1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture2D(colortex5,quarterResTC+1.0*vec2(texelSize.x,texelSize.y))/4.*0.5; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-1.0*texelSize.x,1.0*texelSize.y))/4.*0.5; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(1.0*texelSize.x,-1.0*texelSize.y))/4.*0.5; + + //0.25 + gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,0.0))/2.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0.0,texelSize.y))/2.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(0,-texelSize.y))/2*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(-texelSize.x,0.0))/2*0.125; + + //0.125 + gl_FragData[0] += texture2D(colortex5,quarterResTC-2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+2.0*vec2(texelSize.x,texelSize.y))/4.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(-2.0*texelSize.x,2.0*texelSize.y))/4.*0.125; + gl_FragData[0] += texture2D(colortex5,quarterResTC+vec2(2.0*texelSize.x,-2.0*texelSize.y))/4.*0.125; + + //0.125 + gl_FragData[0] += texture2D(colortex5,quarterResTC)*0.125; + + + gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); + if (quarterResTC.x > 1.0 - 3.5*texelSize.x || quarterResTC.y > 1.0 -3.5*texelSize.y || quarterResTC.x < 3.5*texelSize.x || quarterResTC.y < 3.5*texelSize.y) gl_FragData[0].rgb = vec3(0.0); + + +} diff --git a/shaders/composite9.vsh b/shaders/composite9.vsh new file mode 100644 index 0000000..f98ccfe --- /dev/null +++ b/shaders/composite9.vsh @@ -0,0 +1,17 @@ +#version 120 +#include "lib/res_params.glsl" +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*BLOOM_QUALITY/clampedRes*vec2(1920.0,1080.)*2.0-1.0; +} diff --git a/shaders/deferred.fsh b/shaders/deferred.fsh new file mode 100644 index 0000000..b17e3a3 --- /dev/null +++ b/shaders/deferred.fsh @@ -0,0 +1,196 @@ +#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] +#define ambient_temp 9000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 15000 50000] + + +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 avgL2; +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; +flat varying float centerDepth; + +// uniform sampler2D colortex4; +uniform sampler2D noisetex; +uniform sampler2DShadow shadow; + +uniform int frameCounter; +uniform float rainStrength; +uniform float eyeAltitude; +uniform float nightVision; +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/Shadow_Params.glsl" +#include "/lib/util.glsl" +#include "/lib/ROBOBO_sky.glsl" +#include "lib/sky_gradient.glsl" + +#define TIMEOFDAYFOG +#include "lib/volumetricClouds.glsl" + +// #include "lib/biome_specifics.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 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 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.); +#include "lib/volumetricFog.glsl" +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); +float minLight = (MIN_LIGHT_AMOUNT + nightVision*5) * 0.007/ (exposure + rodExposure/(rodExposure+1.0)*exposure*1.); +// vec3 minLight_col = MIN_LIGHT_AMOUNT * 0.007/ (exposure + rodExposure/(rodExposure+1.0)*exposure*1.) * vec3(0.8,0.9,1.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.; + +// avgAmbient *= blackbody(ambient_temp); + +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/17.212/17.212,0.0); + torch_lightmap = pow(torch_lightmap*2.5,1.5)*TORCH_AMOUNT*10.; + float sky_lightmap = (Slightmap[int(gl_FragCoord.y)]-14.0)/235.; + sky_lightmap = pow(sky_lightmap,1.4); + vec3 ambient = (ambientUp * blackbody(ambient_temp))*sky_lightmap+torch_lightmap*vec3(TORCH_R,TORCH_G,TORCH_B)*TORCH_AMOUNT; + + gl_FragData[0] = vec4(max(ambient*Ambient_Mult,minLight/5),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/17.212/17.212,0.0); + float ambient = pow(torch_lightmap*2.5,1.5)*TORCH_AMOUNT*10.; + float sky_lightmap = (Slightmap[int(gl_FragCoord.y-19.0)]-14.0)/235./150.; + + gl_FragData[0] = vec4(sky_lightmap,ambient,minLight,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 * blackbody(ambient_temp),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(ambientUp,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); +if (gl_FragCoord.x > 8. && gl_FragCoord.x < 9. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(sunColor,1.0); +if (gl_FragCoord.x > 9. && gl_FragCoord.x < 10. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(moonColor,1.0); +if (gl_FragCoord.x > 11. && gl_FragCoord.x < 12. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(avgSky,1.0); +if (gl_FragCoord.x > 12. && gl_FragCoord.x < 13. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(sunColorCloud,1.0); +if (gl_FragCoord.x > 13. && gl_FragCoord.x < 14. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(moonColorCloud,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){ + vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.,1.))/256.+tempOffsets/256.,0.0,1.0); + vec3 viewVector = cartToSphere(p); + + vec2 planetSphere = vec2(0.0); + vec3 sky = vec3(0.0); + vec3 skyAbsorb = vec3(0.0); + vec3 WsunVec = mat3(gbufferModelViewInverse)*sunVec; + sky = calculateAtmosphere(avgSky*4000./2.0, viewVector, vec3(0.0,1.0,0.0), WsunVec, -WsunVec, planetSphere, skyAbsorb, 10, blueNoise()); + + sky = mix(sky, vec3(0.5,0.5,0.5)*avgSky * 4000., clamp(1 - viewVector.y,0.0,1.0) * rainStrength ); + // sky *= max(abs(viewVector.y+0.05),0.25); + gl_FragData[0] = vec4(sky/4000.*Sky_Brightness,1.0); +} + +//Sky gradient with clouds +if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+257.){ + vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0); + vec3 viewVector = cartToSphere(p); + vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024.,vec3(0.), blueNoise(),sunColorCloud,moonColor,ambientUp,blueNoise()); + mat2x3 vL = getVolumetricRays(fract(frameCounter/1.6180339887),mat3(gbufferModelView)*viewVector*1024.); + float absorbance = dot(vL[1],vec3(0.22,0.71,0.07)); + vec3 skytex = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy)-ivec2(257,0),0).rgb/150.; + + if(viewVector.y < -0.025) skytex = skytex * clamp( exp(viewVector.y - 1.0),0.,1.) ; + + skytex = skytex*clouds.a + clouds.rgb; + + // gl_FragData[0] = vec4(skytex,1.0); + gl_FragData[0] = vec4(skytex*absorbance+vL[0].rgb,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,avgL2,1.0); +if (gl_FragCoord.x > 14. && gl_FragCoord.x < 15. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) +gl_FragData[0] = vec4(rodExposure,centerDepth,0.0, 1.0); + +} diff --git a/shaders/deferred.vsh b/shaders/deferred.vsh new file mode 100644 index 0000000..dd4356e --- /dev/null +++ b/shaders/deferred.vsh @@ -0,0 +1,261 @@ +#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 DoF_Adaptation_Speed 1.00 // [0.20 0.21 0.23 0.24 0.25 0.27 0.29 0.30 0.32 0.34 0.36 0.39 0.41 0.43 0.46 0.49 0.52 0.55 0.59 0.62 0.66 0.70 0.74 0.79 0.84 0.89 0.94 1.00 1.06 1.13 1.20 1.27 1.35 1.43 1.52 1.61 1.71 1.82 1.93 2.05 2.18 2.31 2.45 2.60 2.76 2.93 3.11 3.30 3.51 3.72 3.95 4.19 4.45 4.73 5.02 5.33 5.65 6.00] +#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 +#include "lib/res_params.glsl" +flat varying vec3 ambientUp; +flat varying vec3 ambientLeft; +flat varying vec3 ambientRight; +flat varying vec3 ambientB; +flat varying vec3 ambientF; +flat varying vec3 ambientDown; +flat varying vec3 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; +flat varying float avgL2; +flat varying float centerDepth; + +uniform sampler2D colortex4; +uniform sampler2D colortex6; +uniform sampler2D depthtex0; + + +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform vec2 texelSize; +uniform float rainStrength; +uniform float sunElevation; +uniform float nightVision; +uniform float near; +uniform float far; +uniform float frameTime; +uniform float eyeAltitude; +uniform int frameCounter; +uniform int worldTime; +vec3 sunVec = normalize(mat3(gbufferModelViewInverse) *sunPosition); + + + +#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); +} +float tanh(float x){ + return (exp(x) - exp(-x))/(exp(x) + exp(-x)); +} +float ld(float depth) { + return (2.0 * near) / (far + near - depth * (far - near)); // (-depth * (far - near)) = (2.0 * near)/ld - far - near +} +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); + //Integrate sky light for each block side + int maxIT = 20; + for (int i = 0; i < maxIT; i++) { + vec2 ij = R2_samples((frameCounter%1000)*maxIT+i); + vec3 pos = normalize(rodSample(ij)); + + + vec3 samplee = 1.72*skyFromTex(pos,colortex4).rgb/maxIT/150.; + avgSky += samplee/1.72; + ambientUp += samplee*(pos.y+abs(pos.x)/7.+abs(pos.z)/7.); + ambientLeft += samplee*(clamp(-pos.x,0.0,1.0)+clamp(pos.y/7.,0.0,1.0)+abs(pos.z)/7.); + ambientRight += samplee*(clamp(pos.x,0.0,1.0)+clamp(pos.y/7.,0.0,1.0)+abs(pos.z)/7.); + ambientB += samplee*(clamp(pos.z,0.0,1.0)+abs(pos.x)/7.+clamp(pos.y/7.,0.0,1.0)); + ambientF += samplee*(clamp(-pos.z,0.0,1.0)+abs(pos.x)/7.+clamp(pos.y/7.,0.0,1.0)); + ambientDown += samplee*(clamp(pos.y/6.,0.0,1.0)+abs(pos.x)/7.+abs(pos.z)/7.); + + /* + ambientUp += samplee*(pos.y); + ambientLeft += samplee*(clamp(-pos.x,0.0,1.0)); + ambientRight += samplee*(clamp(pos.x,0.0,1.0)); + ambientB += samplee*(clamp(pos.z,0.0,1.0)); + ambientF += samplee*(clamp(-pos.z,0.0,1.0)); + ambientDown += samplee*(clamp(pos.y/6.,0.0,1.0))*0; + */ + + } + + + vec2 planetSphere = vec2(0.0); + vec3 sky = vec3(0.0); + vec3 skyAbsorb = vec3(0.0); + + float sunVis = clamp(sunElevation,0.0,0.05)/0.05*clamp(sunElevation,0.0,0.05)/0.05; + float moonVis = clamp(-sunElevation,0.0,0.05)/0.05*clamp(-sunElevation,0.0,0.05)/0.05; + + zenithColor = calculateAtmosphere(vec3(0.0), vec3(0.0,1.0,0.0), vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,tempOffsets.x); + skyAbsorb = vec3(0.0); + vec3 absorb = vec3(0.0); + sunColor = calculateAtmosphere(vec3(0.0), sunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.0); + sunColor = sunColorBase/4000. * skyAbsorb; + + skyAbsorb = vec3(1.0); + float dSun = 0.03; + vec3 modSunVec = sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0); + vec3 modSunVec2 = sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0); + if (modSunVec2.y > modSunVec.y) modSunVec = modSunVec2; + sunColorCloud = calculateAtmosphere(vec3(0.0), modSunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.); + sunColorCloud = sunColorBase/4000. * skyAbsorb ; + + skyAbsorb = vec3(1.0); + moonColor = calculateAtmosphere(vec3(0.0), -sunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.5); + moonColor = moonColorBase/4000.0*skyAbsorb; + + skyAbsorb = vec3(1.0); + modSunVec = -sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0); + modSunVec2 = -sunVec*(1.0-dSun)+vec3(0.0,dSun,0.0); + if (modSunVec2.y > modSunVec.y) modSunVec = modSunVec2; + moonColorCloud = calculateAtmosphere(vec3(0.0), modSunVec, vec3(0.0,1.0,0.0), sunVec, -sunVec, planetSphere, skyAbsorb, 25,0.5); + + moonColorCloud = moonColorBase/4000.0*0.55; + #ifndef CLOUDS_SHADOWS + sunColor *= (1.0-rainStrength*vec3(0.96,0.95,0.94)); + moonColor *= (1.0-rainStrength*vec3(0.96,0.95,0.94)); + #endif + lightSourceColor = sunVis >= 1e-5 ? sunColor * sunVis : moonColor * moonVis; + + float lightDir = float( sunVis >= 1e-5)*2.0-1.0; + + + //Fake bounced sunlight + vec3 bouncedSun = lightSourceColor*0.1/5.0*0.5*clamp(lightDir*sunVec.y,0.0,1.0)*clamp(lightDir*sunVec.y,0.0,1.0); + vec3 cloudAmbientSun = (sunColorCloud)*0.007; + vec3 cloudAmbientMoon = (moonColorCloud)*0.007; + ambientUp += bouncedSun*clamp(-lightDir*sunVec.y+4.,0.,4.0) + cloudAmbientSun*clamp(sunVec.y+2.,0.,4.0) + cloudAmbientMoon*clamp(-sunVec.y+2.,0.,4.0); + ambientLeft += bouncedSun*clamp(lightDir*sunVec.x+4.,0.0,4.) + cloudAmbientSun*clamp(-sunVec.x+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(sunVec.x+2.,0.0,4.)*0.7; + ambientRight += bouncedSun*clamp(-lightDir*sunVec.x+4.,0.0,4.) + cloudAmbientSun*clamp(sunVec.x+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(-sunVec.x+2.,0.0,4.)*0.7; + ambientB += bouncedSun*clamp(-lightDir*sunVec.z+4.,0.0,4.) + cloudAmbientSun*clamp(sunVec.z+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(-sunVec.z+2.,0.0,4.)*0.7; + ambientF += bouncedSun*clamp(lightDir*sunVec.z+4.,0.0,4.) + cloudAmbientSun*clamp(-sunVec.z+2.,0.0,4.)*0.7 + cloudAmbientMoon*clamp(sunVec.z+2.,0.0,4.)*0.7; + ambientDown += bouncedSun*clamp(lightDir*sunVec.y+4.,0.0,4.)*0.7 + cloudAmbientSun*clamp(-sunVec.y+2.,0.0,4.)*0.5 + cloudAmbientMoon*clamp(sunVec.y+2.,0.0,4.)*0.5; + avgSky += bouncedSun*5.; + + vec3 rainNightBoost = moonColorCloud*rainStrength*0.005; + ambientUp += rainNightBoost; + ambientLeft += rainNightBoost; + ambientRight += rainNightBoost; + ambientB += rainNightBoost; + ambientF += rainNightBoost; + ambientDown += rainNightBoost; + avgSky += rainNightBoost; + + float avgLuma = 0.0; + float m2 = 0.0; + int n=100; + vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.)); + float avgExp = 0.0; + float avgB = 0.0; + vec2 resScale = vec2(1920.,1080.)/clampedRes*BLOOM_QUALITY; + const int maxITexp = 50; + float w = 0.0; + for (int i = 0; i < maxITexp; i++){ + vec2 ij = R2_samples((frameCounter%2000)*maxITexp+i); + vec2 tc = 0.5 + (ij-0.5) * 0.7; + vec3 sp = texture2D(colortex6,tc/16. * resScale+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; + avgExp += log(luma(sp)); + avgB += log(min(dot(sp,vec3(0.07,0.22,0.71)),8e-2)); + } + + avgExp = exp(avgExp/maxITexp); + avgB = exp(avgB/maxITexp); + + avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0); + + float L = max(avgBrightness,1e-8); + float keyVal = 1.03-2.0/(log(L*4000/150.*8./3.0+1.0)/log(10.0)+2.0); + float expFunc = 0.5+0.5*tanh(log(L)); + float targetExposure = 0.18/log2(L*2.5+1.045)*0.62; + + avgL2 = clamp(mix(avgB,texelFetch2D(colortex4,ivec2(10,37),0).b,0.985),0.00003051757,65000.0); + float targetrodExposure = max(0.012/log2(avgL2+1.002)-0.1,0.0)*1.2; + + + exposure=max(targetExposure*EXPOSURE_MULTIPLIER, 0); + float currCenterDepth = ld(texture2D(depthtex0, vec2(0.5)*RENDER_SCALE).r); + centerDepth = mix(sqrt(texelFetch2D(colortex4,ivec2(14,37),0).g/65000.0), currCenterDepth, clamp(DoF_Adaptation_Speed*exp(-0.016/frameTime+1.0)/(6.0+currCenterDepth*far),0.0,1.0)); + centerDepth = centerDepth * centerDepth * 65000.0; + + rodExposure = targetrodExposure; + + #ifndef AUTO_EXPOSURE + exposure = Manual_exposure_value; + rodExposure = clamp(log(Manual_exposure_value*2.0+1.0)-0.1,0.0,2.0); + #endif + float modWT = (worldTime%24000)*1.0; + + float fogAmount0 = 1/3000.+FOG_TOD_MULTIPLIER*(1/100.*(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/120.*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.0/20000.*rainStrength); + fogAmount = BASE_FOG_AMOUNT*(fogAmount0+max(FOG_RAIN_MULTIPLIER*1/10.*rainStrength , FOG_TOD_MULTIPLIER*1/50.*clamp(modWT-13000.,0.,1000.0)/1000.*(1.0-clamp(modWT-23000.,0.,1000.0)/1000.))); +} diff --git a/shaders/deferred1.fsh b/shaders/deferred1.fsh new file mode 100644 index 0000000..9e513aa --- /dev/null +++ b/shaders/deferred1.fsh @@ -0,0 +1,101 @@ +#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 colortex4; +uniform sampler2D noisetex; + +uniform vec3 sunVec; +uniform vec2 texelSize; +uniform float frameTimeCounter; +uniform float rainStrength; +uniform int frameCounter; +uniform int framemod8; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelViewInverse; +uniform vec3 cameraPosition; + +uniform mat4 gbufferModelView; +// flat varying vec2 TAA_Offset; + + +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 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); +} +float interleaved_gradientNoise(){ + vec2 alpha = vec2(0.75487765, 0.56984026); + vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter; + float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); + return noise; +} +#include "lib/sky_gradient.glsl" +#include "lib/volumetricClouds.glsl" +#include "/lib/res_params.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 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); +} + +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:0 */ +float phi = 2 * 3.14159265359; +float noise = fract(fract(frameCounter * (1.0 / phi)) + interleaved_gradientNoise() ) ; + + + #ifdef VOLUMETRIC_CLOUDS + vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY/RENDER_SCALE+0.5+(vec2(tempOffsets)*(texelSize/4))*CLOUDS_QUALITY*RENDER_SCALE*0.5); + + vec3 fragpos = toScreenSpace(vec3(halfResTC*texelSize,1.0)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + + vec4 currentClouds = renderClouds(fragpos,vec3(0.), R2_dither(),sunColor/150.,moonColor/150.,avgAmbient/150.,blueNoise2()); + gl_FragData[0] = currentClouds ; + + + #else + gl_FragData[0] = vec4(0.0,0.0,0.0,1.0); + #endif + +} diff --git a/shaders/deferred1.vsh b/shaders/deferred1.vsh new file mode 100644 index 0000000..6f8f89d --- /dev/null +++ b/shaders/deferred1.vsh @@ -0,0 +1,46 @@ +#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; + +flat varying vec3 ambientUp; +flat varying vec3 ambientLeft; +flat varying vec3 ambientRight; +flat varying vec3 ambientB; +flat varying vec3 ambientF; +flat varying vec3 ambientDown; + +uniform sampler2D colortex4; +uniform int frameCounter; +#include "/lib/util.glsl" +#include "/lib/res_params.glsl" +void main() { + + // TAA_Offset = offsets[frameCounter%8]; + // #ifndef TAA + // TAA_Offset = vec2(0.0); + // #endif + + 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; + #ifdef TAA_UPSCALING + gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; + #endif + sunColor = texelFetch2D(colortex4,ivec2(12,37),0).rgb; + moonColor = texelFetch2D(colortex4,ivec2(13,37),0).rgb; + // 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; + + avgAmbient = texelFetch2D(colortex4,ivec2(1,37),0).rgb; +} diff --git a/shaders/deferred2.fsh b/shaders/deferred2.fsh new file mode 100644 index 0000000..b8932e7 --- /dev/null +++ b/shaders/deferred2.fsh @@ -0,0 +1,27 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +uniform sampler2D colortex4; +uniform sampler2D depthtex1; + +uniform float near; +uniform float far; + + +float linZ(float depth) { + return (2.0 * near) / (far + near - depth * (far - near)); +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:4 */ + vec3 oldTex = texelFetch2D(colortex4, ivec2(gl_FragCoord.xy), 0).xyz; + float newTex = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x; + if (newTex < 1.0) + gl_FragData[0] = vec4(oldTex, linZ(newTex)*linZ(newTex)*65000.0); + else + gl_FragData[0] = vec4(oldTex, 2.0); +} diff --git a/shaders/deferred2.vsh b/shaders/deferred2.vsh new file mode 100644 index 0000000..942c20e --- /dev/null +++ b/shaders/deferred2.vsh @@ -0,0 +1,9 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +uniform vec2 texelSize; +#include "/lib/res_params.glsl" +void main() { + gl_Position = ftransform(); + vec2 scaleRatio = max(vec2(0.25), vec2(18.+258*2,258.)*texelSize); + gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(scaleRatio+0.01,0.0,1.0)*2.0-1.0; +} diff --git a/shaders/entity.properties b/shaders/entity.properties new file mode 100644 index 0000000..c57aaa6 --- /dev/null +++ b/shaders/entity.properties @@ -0,0 +1,13 @@ +#if MC_VERSION >= 11300 + + +### all the different strengths of subsurface scattering and what entities to put them on. +#medium sss (same as strong sss for blocks) +entity.1100 = slime giant ender_dragon ghast + +#weak sss (same as weak sss for blocks) +entity.1200 = frog sheep chicken snow_golem polar_bear zombie_horse armor_stand arrow squid bat cat cod cow donkey fox horse mooshroom mule ocelot parrot pig piglin polar_bear pufferfish rabbit salmon strider tropical_fish turtle villager wandering_trader bee cave_spider dolphin enderman llama panda spider wolf zombified_piglin blaze creeper drowned elder_gaurdian endermite evoker guardian hoglin husk magma_cube phantom piglin_brute pillager ravager silverfish stray vex vindicator witch zoglin zombie zombie_villager wither player trader_llama + +# entity.5000 = minecraft:lightning_bolt +entity.9001 = minecraft:boat +layer.translucent=slime diff --git a/shaders/final.fsh b/shaders/final.fsh new file mode 100644 index 0000000..78adec1 --- /dev/null +++ b/shaders/final.fsh @@ -0,0 +1,101 @@ +#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 sampler2D noisetex; +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); + + gl_FragColor.rgb = clamp(int8Dither(col,texcoord),0.0,1.0); +} diff --git a/shaders/final.vsh b/shaders/final.vsh new file mode 100644 index 0000000..7aeb51b --- /dev/null +++ b/shaders/final.vsh @@ -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); +} diff --git a/shaders/gbuffers_all_particles.fsh b/shaders/gbuffers_all_particles.fsh new file mode 100644 index 0000000..d1cc609 --- /dev/null +++ b/shaders/gbuffers_all_particles.fsh @@ -0,0 +1,149 @@ +// #version 120 +varying vec4 lmtexcoord; +varying vec4 color; + +uniform sampler2D texture; +uniform sampler2DShadow shadow; +uniform sampler2D gaux1; +uniform sampler2D noisetex; +uniform vec3 sunVec; +flat varying vec3 WsunVec; +uniform float frameTimeCounter; +uniform ivec2 eyeBrightnessSmooth; + +uniform vec2 texelSize; +uniform float rainStrength; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferModelView; +uniform mat4 shadowModelView; +uniform mat4 shadowProjection; +uniform vec3 cameraPosition; + +#include "lib/Shadow_Params.glsl" +#include "/lib/res_params.glsl" +#include "lib/sky_gradient.glsl" +#include "lib/volumetricClouds.glsl" + +//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; +} + +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.); + +float shadow2D_bicubic(sampler2DShadow tex, vec3 sc) +{ + vec2 uv = sc.xy*shadowMapResolution; + 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)/shadowMapResolution - 0.5/shadowMapResolution; + vec2 p1 = vec2(iuv.x + h1x, iuv.y + h0y)/shadowMapResolution - 0.5/shadowMapResolution; + vec2 p2 = vec2(iuv.x + h0x, iuv.y + h1y)/shadowMapResolution - 0.5/shadowMapResolution; + vec2 p3 = vec2(iuv.x + h1x, iuv.y + h1y)/shadowMapResolution - 0.5/shadowMapResolution; + + return g0(fuv.y) * (g0x * shadow2D(tex, vec3(p0,sc.z)).x + + g1x * shadow2D(tex, vec3(p1,sc.z)).x) + + g1(fuv.y) * (g0x * shadow2D(tex, vec3(p2,sc.z)).x + + g1x * shadow2D(tex, vec3(p3,sc.z)).x); +} +float luma(vec3 color) { + return dot(color,vec3(0.299, 0.587, 0.114)); +} +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} + +float GetCloudShadow(vec3 eyePlayerPos){ + vec3 worldPos = (eyePlayerPos + cameraPosition) - Cloud_Height; + vec3 cloudPos = worldPos*Cloud_Size + WsunVec/abs(WsunVec.y) * ((3250 - 3250*0.35) - worldPos.y*Cloud_Size) ; + float shadow = getCloudDensity(cloudPos, 1); + // float shadow = (getCloudDensity(cloudPos, 1) + HighAltitudeClouds(cloudPos)) / 2.0; + + shadow = clamp(exp(-shadow*15),0.0,1.0); + + return shadow ; +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +/* DRAWBUFFERS:29 */ +void main() { + + vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color; + +#ifndef WEATHER + gl_FragData[0] = TEXTURE; + vec2 tempOffset = offsets[framemod8]; + 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); + + vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + vec3 DirectLightCol = texelFetch2D(gaux1,ivec2(6,37),0).rgb / 127.0; + DirectLightCol *= GetCloudShadow(p3); + + vec3 AmbientLight = texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb * 8.0/150.0/3.0; + + //compute shadows only if not backface + float diffuseSun = 0.712; + 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){ + + float diffthresh = 0.0002; + + projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5,0.5,0.5); + + float shading = shadow2D_bicubic(shadow,vec3(projectedShadowPosition + vec3(0.0,0.0,-diffthresh*1.2))); + DirectLightCol *= shading; + } + } + + float phase = phaseg(clamp(dot(np3, WsunVec),0.0,1.0), 0.7) + 0.05 ; + float lightleakfix = clamp(eyeBrightnessSmooth.y/240.0,0.0,1.0); + vec3 DirectLight = DirectLightCol * phase * lightleakfix; + + gl_FragData[0].rgb = (AmbientLight + DirectLight) * albedo; +#endif + + gl_FragData[1].a = TEXTURE.a; // for bloomy rain + // gl_FragData[1].a = 1; +} \ No newline at end of file diff --git a/shaders/gbuffers_all_particles.vsh b/shaders/gbuffers_all_particles.vsh new file mode 100644 index 0000000..2424506 --- /dev/null +++ b/shaders/gbuffers_all_particles.vsh @@ -0,0 +1,74 @@ +// #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; + +#ifdef MC_NORMAL_MAP + varying vec4 tangent; + attribute vec4 at_tangent; + varying vec3 FlatNormals; +#endif + +flat varying vec3 WsunVec; +flat varying vec4 lightCol; +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform float sunElevation; +uniform sampler2D colortex4; + + +uniform vec2 texelSize; +uniform int framemod8; + const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////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; + + 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); + + + FlatNormals = normalize(gl_NormalMatrix *gl_Normal); + #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_UPSCALING + gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; + #endif + #ifdef TAA + gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; + #endif +} diff --git a/shaders/gbuffers_all_solid.fsh b/shaders/gbuffers_all_solid.fsh new file mode 100644 index 0000000..705a9bd --- /dev/null +++ b/shaders/gbuffers_all_solid.fsh @@ -0,0 +1,465 @@ +#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 + + +varying float VanillaAO; + +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; +varying vec4 NoSeasonCol; +varying vec4 seasonColor; +uniform float far; +varying vec4 normalMat; +#ifdef MC_NORMAL_MAP +varying vec4 tangent; +uniform float wetness; +uniform sampler2D normals; +uniform sampler2D specular; +varying vec3 FlatNormals; +#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.); +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 densityAtPosSNOW(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); +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +/* RENDERTARGETS: 1,7,8,13,15 */ +void main() { + + + 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.25,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) { + + float depthmap = readNormal(vtexcoord.st).a; + + if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) { + + // vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH; + vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0) ; + + vec3 coord = vec3(vtexcoord.st, 1.0); + coord += interval; + + float sumVec = 0.5; + 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; + } + + 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, adjustedTexCoord.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 + + + // float Snow = texture2D(noisetex, worldpos.xz/100, Texture_MipMap_Bias).r; + // Snow = clamp( exp(pow(Snow,2) * -25) ,0,1) ; + // Snow *= clamp(pow(lmtexcoord.w,25)*5 ,0,1); + + // #ifdef ENTITIES + // Snow = 0; + // #endif + // #ifdef HAND + // Snow = 0; + // #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 + + // Snow *= clamp(viewToWorld(normal).y,0.0,1.0); + + + + // 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); + + // gl_FragData[2].rg = mix(gl_FragData[2].rg, vec2(0.8,0.3), Snow); + + + // color + vec4 data0 = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color ; + // data0.rgb *= pow(VanillaAO.r,25); + + #ifdef Puddles + + float porosity = specular.z >= 64.5/255.0 ? 0.0 : (specular.z*255.0/64.0)*0.65; + #ifndef Porosity + porosity = 0.5; + #endif + + data0.rgb = mix(data0.rgb, vec3(0), puddle_shiny*porosity*rainfall); + #endif + + 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 + + gl_FragData[4] = vec4(FlatNormals* 0.5 + 0.5,VanillaAO); + + + // #ifdef ENTITIES + // #ifdef WORLD + // gl_FragData[3].xyz = test_motionVectors; + // #endif + // #endif +// gl_FragData[0].rgb = vec3(0,255,0); +} \ No newline at end of file diff --git a/shaders/gbuffers_all_solid.vsh b/shaders/gbuffers_all_solid.vsh new file mode 100644 index 0000000..291c26a --- /dev/null +++ b/shaders/gbuffers_all_solid.vsh @@ -0,0 +1,271 @@ +#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 // 0 = none. 1 = SSAO. 2 = RTAO. 3 = SSGI. [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 +#define misc_block_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 !! +*/ +uniform int worldDay; +varying vec4 lmtexcoord; +varying vec4 color; +varying float VanillaAO; +varying vec4 NoSeasonCol; +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; + varying vec3 FlatNormals; +#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; +} +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 luma(vec3 color) { +// return dot(color,vec3(0.21, 0.72, 0.07)); +// } + + #define SEASONS_VSH + #include "/lib/climate_settings.glsl" + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { + lmtexcoord.xy = (gl_MultiTexCoord0).xy; + FlatNormals = normalize(gl_NormalMatrix * gl_Normal); + 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; + VanillaAO = 1.0 - clamp(color.a,0,1); + if (color.a < 0.3) color.a = 1.0; // fix vanilla ao on some custom block models. + + 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 ? 0.65 : normalMat.a; + normalMat.a = entityId == 1200 ? 0.65 : normalMat.a; + #endif + #endif + + normalMat.a = 0.45; + + 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 || mc_Entity.x == 200 ? 0.6 : normalMat.a; // 0.6 weak SSS + normalMat.a = blockEntityId == 10010 ? 0.65 : normalMat.a; // banners + + #ifdef misc_block_SSS + normalMat.a = mc_Entity.x == 10007 ? 0.55 : normalMat.a; // 0.55 abnormal block strong sss + #endif + + normalMat.a = mc_Entity.x == 10005 ? 0.8 : 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); + + + + + #ifdef SEPARATE_AO + + // #if indirect_effect == 1 || indirect_effect == 0 + // lmtexcoord.zw *= sqrt(color.a); + // #endif + + #else + color.rgb *= color.a; + #endif + + // if (mc_Entity.x == 10099 ) seasonColor.rgb = (gl_Color.rgb * blackbody2(sin(frameTimeCounter)*12000 + 14000)) * (1.0 - floor(luma(gl_Color.rgb)+(1.0/255.))); + +#endif + + // seasonColor = color; + NoSeasonCol.rgb = gl_Color.rgb; + #ifdef Seasons + #ifndef BLOCKENTITIES + #ifndef ENTITIES + YearCycleColor(color.rgb, gl_Color.rgb); + #endif + #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 + + +} diff --git a/shaders/gbuffers_all_translucent.fsh b/shaders/gbuffers_all_translucent.fsh new file mode 100644 index 0000000..f8627ee --- /dev/null +++ b/shaders/gbuffers_all_translucent.fsh @@ -0,0 +1,610 @@ +// #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 // 0 = temperature. 1 = rgb sliders [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 BorderFog // aaaaaaaaaaaaaaaaaaaaaaa + +#define MIN_LIGHT_AMOUNT 1.0 //[0.0 0.5 1.0 1.5 2.0 3.0 4.0 5.0] + + +// #define Glass_Tint // multiply the background through glass by the color of the glass for a strong tint. + +// #define ambientLight_only // THIS IS A DEBUG VIEW. turn the sunlight off. DOES NOT increase performance, the shadows are still working in the background +//#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; + + float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + 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); + #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); + + + #endif + + spos += stepv; + //small bias + minZ = maxZ-(0.0001/dist)/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 0.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) ; +} +float interleaved_gradientNoise(){ + vec2 coord = gl_FragCoord.xy + (frameCounter%40000); + // vec2 coord = gl_FragCoord.xy + frameTimeCounter; + // vec2 coord = gl_FragCoord.xy; + float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) ); + return noise ; +} +//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 fresnel) { + + float roughness = r; + + float alpha = square(roughness) + 1e-4; // when roughness is zero it fucks up + + vec3 h = normalize(l + v) * mix(1.000, 1.0025, pow(fresnel,2) ); + + 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 / (0.0541592653589793*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,13,14 */ +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,-5)*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(1.0); + gl_FragData[0] = vec4(0.42,0.6,0.7,0.7); + } + if (iswater > 0.9) { + gl_FragData[0] = vec4(vec3(0.0),1./255.); + } + #endif + + #ifdef Vanilla_like_water + if (iswater > 0.5) { + gl_FragData[0].a = luma(albedo.rgb); + albedo = color.rgb; + } + #endif + + gl_FragData[4] = vec4(albedo, gl_FragData[0].a); + + + 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.; + vec3 posxz = p3+cameraPosition; + posxz.xz-=posxz.y; + 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[5] = vec4(encodeVec2(lmtexcoord.a,lmtexcoord.a), encodeVec2(lmtexcoord.a,lmtexcoord.a), encodeVec2(lmtexcoord.a,lmtexcoord.a), encodeVec2(lmtexcoord.a,lmtexcoord.a)); + + float NdotL = lightSign*dot(normal,sunVec); + float NdotU = dot(upVec,normal); + float diffuseSun = clamp(NdotL,0.0f,1.0f); + diffuseSun = clamp((-15 + diffuseSun*255.0) / 240.0 ,0.0,1.0); + + vec3 direct = texelFetch2D(gaux1,ivec2(6,37),0).rgb/127.0; + #ifdef ambientLight_only + direct = vec3(0); + #endif + + + 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 + } + + + vec3 ambientLight = (texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb * 2.0) * 8./150./3.; + + direct *= (iswater > 0.9 ? 0.2: 1.0)*diffuseSun*lmtexcoord.w; + + vec3 directLight = direct; + + vec3 color = vec3(0); + + + color += ambientLight ; + color += directLight; + + #ifdef Glass_Tint + float alphashit = min(pow(gl_FragData[0].a,2.0),1.0); + color *= alphashit; + #endif + + color *= albedo; + + vec2 specularstuff = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg; + specularstuff = iswater > 0.0 && specularstuff.r > 0.0 && specularstuff.g < 0.9 ? specularstuff : vec2(1.0,0.02); + + if (iswater > 0.0){ + + float roughness = pow(1.0-specularstuff.r,2.0); + float f0 = 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); + + // 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); + float indoors = clamp((lmtexcoord.w-0.6)*5.0, 0.0,1.0); + vec3 wrefl = mat3(gbufferModelViewInverse)*reflectedVector; + + vec3 sky_c = skyCloudsFromTex(wrefl,gaux1).rgb / 150. * 5. ; + sky_c.rgb *= indoors; + + float visibilityFactor = clamp(exp2((pow(roughness,3.0) / F0) * -4),0,1); + + sky_c = mix(sky_c,color,(1.0-indoors)) ; + + vec4 reflection = vec4(0.); + #ifdef SCREENSPACE_REFLECTIONS + vec3 rtPos = rayTrace(reflectedVector,fragpos.xyz, interleaved_gradientNoise(), fresnel, isEyeInWater == 1); + 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.w; + + reflection.rgb = mix(sky_c.rgb, reflection.rgb, reflection.a); + + vec3 sunSpec = shading*directLight * GGX2(normal, -normalize(fragpos), lightSign*sunVec, roughness, vec3(f0), fresnel) ; + + sunSpec *= max(cloudShadow-0.5,0.0); + + vec3 reflected = reflection.rgb*fresnel + sunSpec ; + + // reflected = vec3(0); + + 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.); + + #ifdef BorderFog + float fog = 1.0 - clamp( exp2(-pow(length(fragpos / far),10.)*3.0) ,0.0,1.0); + gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, fog); + #endif + + } + else + gl_FragData[0].rgb = color*.1; + + gl_FragData[1] = vec4(albedo,iswater); + + } +} diff --git a/shaders/gbuffers_all_translucent.vsh b/shaders/gbuffers_all_translucent.vsh new file mode 100644 index 0000000..dbae161 --- /dev/null +++ b/shaders/gbuffers_all_translucent.vsh @@ -0,0 +1,116 @@ +// #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; + +flat varying int glass; + +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); +} diff --git a/shaders/gbuffers_armor_glint.fsh b/shaders/gbuffers_armor_glint.fsh new file mode 100644 index 0000000..d2a0cfd --- /dev/null +++ b/shaders/gbuffers_armor_glint.fsh @@ -0,0 +1,81 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + + +varying vec4 lmtexcoord; +varying vec4 color; +varying vec4 normalMat; + + +uniform sampler2D texture; +uniform sampler2D gaux1; +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); + + float exposure = texelFetch2D(gaux1,ivec2(10,37),0).r; + + vec3 col = albedo*exp(-exposure*3.); + + + gl_FragData[0].rgb = col*color.a; + gl_FragData[0].a = gl_FragData[0].a*0.1; + + + +} diff --git a/shaders/gbuffers_armor_glint.vsh b/shaders/gbuffers_armor_glint.vsh new file mode 100644 index 0000000..ab59388 --- /dev/null +++ b/shaders/gbuffers_armor_glint.vsh @@ -0,0 +1,63 @@ +#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; +#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.); +#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_TextureMatrix[0] * gl_MultiTexCoord0).st; + + vec2 lmcoord = gl_MultiTexCoord1.xy/255.; + lmtexcoord.zw = lmcoord*lmcoord; + + vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; + color = gl_Color; + gl_Position = toClipSpace3(position); + + + #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_UPSCALING + gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; + #endif + #ifdef TAA + gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; + #endif +} diff --git a/shaders/gbuffers_basic.fsh b/shaders/gbuffers_basic.fsh new file mode 100644 index 0000000..7748265 --- /dev/null +++ b/shaders/gbuffers_basic.fsh @@ -0,0 +1,6 @@ +#version 120 + +// #define ENTITIES +#define BLOCKENTITIES +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_basic.vsh b/shaders/gbuffers_basic.vsh new file mode 100644 index 0000000..068cbd8 --- /dev/null +++ b/shaders/gbuffers_basic.vsh @@ -0,0 +1,7 @@ +#version 120 + +// #define ENTITIES +// #define LINE +#define BLOCKENTITIES +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_beaconbeam.fsh b/shaders/gbuffers_beaconbeam.fsh new file mode 100644 index 0000000..631cdf1 --- /dev/null +++ b/shaders/gbuffers_beaconbeam.fsh @@ -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 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(){ + 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; + float exposure = texelFetch2D(gaux1,ivec2(10,37),0).r; + vec3 diffuseLight = torch_lightmap*vec3(20.,30.,50.)*2./10. ; + + vec3 color = diffuseLight*albedo/exposure*5.0; + + + gl_FragData[0].rgb = clamp(color*0.01,0,1); + + + + +} diff --git a/shaders/gbuffers_beaconbeam.vsh b/shaders/gbuffers_beaconbeam.vsh new file mode 100644 index 0000000..ad085e1 --- /dev/null +++ b/shaders/gbuffers_beaconbeam.vsh @@ -0,0 +1,57 @@ +#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; +#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_UPSCALING + gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; + #endif + #ifdef TAA + gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; + #endif +} diff --git a/shaders/gbuffers_block.fsh b/shaders/gbuffers_block.fsh new file mode 100644 index 0000000..c7c36b4 --- /dev/null +++ b/shaders/gbuffers_block.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define BLOCKENTITIES +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_block.vsh b/shaders/gbuffers_block.vsh new file mode 100644 index 0000000..5decf09 --- /dev/null +++ b/shaders/gbuffers_block.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define BLOCKENTITIES +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_damagedblock.fsh b/shaders/gbuffers_damagedblock.fsh new file mode 100644 index 0000000..b13b1ed --- /dev/null +++ b/shaders/gbuffers_damagedblock.fsh @@ -0,0 +1,553 @@ +#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); +} +float square(float x){ + return x*x; +} + +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 alpha = square(r); + + 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, r) * gSimple(dotNL, r); + vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH); + + return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7)); +} + + 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) ; +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +/* DRAWBUFFERS:271 */ +void main() { +if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize.y < RENDER_SCALE.y ) { + + vec2 specularstuff = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg; + + // color + 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)); + + vec3 np3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition; + + 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 + + + // normals + 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); + } + + /// Direct light + + 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; + vec3 directlightcol = direct; + 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; + } + + + vec3 campos = (p3 + cameraPosition)-319 ; + #ifdef VOLUMETRIC_CLOUDS + #ifdef CLOUDS_SHADOWS + // 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); + + // 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; + + directlightcol *= (iswater > 0.9 ? 0.2: 1.0)*diffuseSun*lmtexcoord.w; + + + vec3 diffuseLight = (directlightcol + ambientLight)/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 || specularstuff.g > 0.9 ? 0.02 : specularstuff.g; + 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; + // roughness = 1.; + 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); + + // 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 + // direct = mix(direct, (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 = 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); + vec3 sunSpec = GGX2(normal, -normalize(fragpos), lightSign*sunVec, roughness+0.005, vec3(f0)) ; + #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 + + sunSpec *= max(cloudShadow-0.5,0.0); + // direct = mix(direct, direct*sunSpec, sunSpec); + vec3 reflected = reflection.rgb*fresnel + shading*sunSpec*directlightcol; + float alpha0 = gl_FragData[0].a; + + vec4 nice_colors = mix(gl_FragData[0], vec4(gl_FragData[0].rgb*2 - 0.5, 1.0-gl_FragData[0].a), 1.0-gl_FragData[0].a) ; + + nice_colors.rgb *= (ambientLight + shading*diffuseSun*directlightcol * max(sunSpec,0.15))/25.; + gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel; // correct alpha channel with fresnel + gl_FragData[0].rgb = clamp(nice_colors.rgb/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].a > 0) gl_FragData[0] = max(nice_colors, 0.0); + + }else + gl_FragData[0].rgb = color*.1; + + gl_FragData[1] = vec4(albedo, iswater); + // vec4 nice_colors = vec4(gl_FragData[0].rgb, gl_FragData[0].a*gl_FragData[0].a) + (vec4(gl_FragData[0].rgb -0.5 , 1 - gl_FragData[0].a)*(1.0-gl_FragData[0].a) ) ; + // gl_FragData[0].rgb = color; + + + + + + + // 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)) ; +} +} \ No newline at end of file diff --git a/shaders/gbuffers_damagedblock.vsh b/shaders/gbuffers_damagedblock.vsh new file mode 100644 index 0000000..cb9ec6f --- /dev/null +++ b/shaders/gbuffers_damagedblock.vsh @@ -0,0 +1,111 @@ +#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; + + 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); +} diff --git a/shaders/gbuffers_entities.fsh b/shaders/gbuffers_entities.fsh new file mode 100644 index 0000000..0cd3e0d --- /dev/null +++ b/shaders/gbuffers_entities.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define ENTITIES +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_entities.vsh b/shaders/gbuffers_entities.vsh new file mode 100644 index 0000000..f4f07a4 --- /dev/null +++ b/shaders/gbuffers_entities.vsh @@ -0,0 +1,6 @@ +#version 120 + + +// #define WORLD +#define ENTITIES +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_hand.fsh b/shaders/gbuffers_hand.fsh new file mode 100644 index 0000000..21ac244 --- /dev/null +++ b/shaders/gbuffers_hand.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define HAND +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_hand.vsh b/shaders/gbuffers_hand.vsh new file mode 100644 index 0000000..39504ed --- /dev/null +++ b/shaders/gbuffers_hand.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define HAND +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_hand_water.fsh b/shaders/gbuffers_hand_water.fsh new file mode 100644 index 0000000..16b241a --- /dev/null +++ b/shaders/gbuffers_hand_water.fsh @@ -0,0 +1,271 @@ +#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 ] + +uniform sampler2D texture; +uniform sampler2D noisetex; +uniform sampler2DShadow shadow; +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; +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 blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); +} +float ld(float dist) { + return (2.0 * near) / (far + near - dist * (far - near)); +} +float cdist(vec2 coord) { + return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0; +} +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); +} +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); +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +/* RENDERTARGETS:2,7,13 */ +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)); + + // color n stuff + 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); + + + gl_FragData[2] = vec4(albedo, gl_FragData[0].a); + + // specular + vec2 specularstuff = texture2D(specular, lmtexcoord.xy, -1).rg; + + // normals + 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); + + vec3 normalTex = texture2D(normals, lmtexcoord.xy, -1).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); + + + //other shit + float NdotL = lightSign*dot(normal,sunVec); + 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; + } + // vec3 campos = (p3 + cameraPosition)-319 ; + // #ifdef VOLUMETRIC_CLOUDS + // #ifdef CLOUDS_SHADOWS + // // 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); + + // // make these turn to zero when occluded by the cloud shadow + // direct *= cloudShadow; + // #endif + // #endif + } + + + direct *= (iswater > 0.9 ? 0.2: 1.0)*diffuseSun*lmtexcoord.w; + + vec3 diffuseLight = direct + texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb; + vec3 color = diffuseLight*albedo*8./150./3.; + + 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; + + 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); + + + 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.); + reflection.rgb = mix(sky_c.rgb, reflection.rgb, reflection.a); + + #ifdef SUN_MICROFACET_SPECULAR + 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; + + vec3 reflected = reflection.rgb*fresnel+shading*sunSpec; + + 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); + } +} diff --git a/shaders/gbuffers_hand_water.vsh b/shaders/gbuffers_hand_water.vsh new file mode 100644 index 0000000..0c5e6a1 --- /dev/null +++ b/shaders/gbuffers_hand_water.vsh @@ -0,0 +1,107 @@ +#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 !! +*/ +//#define Vanilla_like_water // vanilla water texture along with shader water stuff + +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 vec4 lightCol; +flat varying vec3 WsunVec; +uniform float sunElevation; + +varying vec4 tangent_other; +#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 == 10002) mat = 0.01; + if (mc_Entity.x == 72) mat = 0.5; + + 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); +} diff --git a/shaders/gbuffers_skybasic.fsh b/shaders/gbuffers_skybasic.fsh new file mode 100644 index 0000000..563a191 --- /dev/null +++ b/shaders/gbuffers_skybasic.fsh @@ -0,0 +1,9 @@ +#version 120 + +/* DRAWBUFFERS:3 */ + + + +void main() { + +} diff --git a/shaders/gbuffers_skybasic.vsh b/shaders/gbuffers_skybasic.vsh new file mode 100644 index 0000000..90c4b9e --- /dev/null +++ b/shaders/gbuffers_skybasic.vsh @@ -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; +} diff --git a/shaders/gbuffers_skytextured.fsh b/shaders/gbuffers_skytextured.fsh new file mode 100644 index 0000000..2852cff --- /dev/null +++ b/shaders/gbuffers_skytextured.fsh @@ -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 !! +*/ + +/* RENDERTARGETS:12 */ + +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; +} diff --git a/shaders/gbuffers_skytextured.vsh b/shaders/gbuffers_skytextured.vsh new file mode 100644 index 0000000..4722357 --- /dev/null +++ b/shaders/gbuffers_skytextured.vsh @@ -0,0 +1,38 @@ +#version 120 +#include "/lib/res_params.glsl" + +/* +!! DO NOT REMOVE !! +This code is from Chocapic13' shaders +Read the terms of modification and sharing before changing something below please ! +!! DO NOT REMOVE !! +*/ + +varying vec4 color; +varying vec2 texcoord; + +uniform vec2 texelSize; +uniform int framemod8; + const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); +void main() { + texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st; + + + + color = gl_Color; + + gl_Position = ftransform(); + #ifdef TAA_UPSCALING + gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; + #endif + #ifdef TAA + gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; + #endif +} diff --git a/shaders/gbuffers_spidereyes.fsh b/shaders/gbuffers_spidereyes.fsh new file mode 100644 index 0000000..aa3de8b --- /dev/null +++ b/shaders/gbuffers_spidereyes.fsh @@ -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; + +} diff --git a/shaders/gbuffers_spidereyes.vsh b/shaders/gbuffers_spidereyes.vsh new file mode 100644 index 0000000..cfe2b7d --- /dev/null +++ b/shaders/gbuffers_spidereyes.vsh @@ -0,0 +1,37 @@ +#version 120 +#include "/lib/res_params.glsl" +/* +!! DO NOT REMOVE !! +This code is from Chocapic13' shaders +Read the terms of modification and sharing before changing something below please ! +!! DO NOT REMOVE !! +*/ + +varying vec4 color; +varying vec2 texcoord; + +uniform vec2 texelSize; +uniform int framemod8; + const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); +void main() { + + + texcoord = (gl_MultiTexCoord0).xy; + color = gl_Color; + + gl_Position = ftransform(); + #ifdef TAA_UPSCALING + gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; + #endif + #ifdef TAA + gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; + #endif + +} diff --git a/shaders/gbuffers_terrain.fsh b/shaders/gbuffers_terrain.fsh new file mode 100644 index 0000000..97072f6 --- /dev/null +++ b/shaders/gbuffers_terrain.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_terrain.vsh b/shaders/gbuffers_terrain.vsh new file mode 100644 index 0000000..5078151 --- /dev/null +++ b/shaders/gbuffers_terrain.vsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_textured.fsh b/shaders/gbuffers_textured.fsh new file mode 100644 index 0000000..0e4abca --- /dev/null +++ b/shaders/gbuffers_textured.fsh @@ -0,0 +1,352 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#extension GL_ARB_shader_texture_lod : enable + +//#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 + + +#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; +#ifdef POM +varying vec4 vtexcoordam; // .st for add, .pq for mul +varying vec4 vtexcoord; + +uniform int framemod8; +#endif +#include "/lib/res_params.glsl" +varying vec4 lmtexcoord; +varying vec4 color; +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 +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 sampler2D noisetex;//depth + +float interleaved_gradientNoise(){ + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521); +} +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)); +} + +//encode normal in two channels (xy),torch(z) and sky lightmap (w) +// vec4 encode_old (vec3 n){ +// return vec4(n.xy*inversesqrt(n.z*8.0+8.0) + 0.5,vec2(lmtexcoord.z,lmtexcoord.w)); +// } +// vec4 encode_old (vec3 n, vec2 lightmaps){ +// return vec4(n.xy*inversesqrt(n.z*8.0+8.0) + 0.5,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); +} +#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.); +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +/* DRAWBUFFERS:178 */ +void main() { + // float noise = interleaved_gradientNoise(); + + + float phi = 2 * 3.14159265359; + float noise = fract(fract(frameCounter * (1.0 / phi)) + interleaved_gradientNoise() ) ; + // float noise = 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 + + #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); + + // #ifdef Depth_Write_POM + gl_FragDepth = gl_FragCoord.z; + // #endif + + 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 + + } + } + + 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 + if (data0.a > 0.1) data0.a = normalMat.a; + else data0.a = 0.0; + + + // normal = applyBump(tbnMatrix,texture2DGradARB(normals,adjustedTexCoord.xy,dcdx,dcdy).xyz*2.-1.); + // data0.rgb*=color.rgb; + // vec4 data1 = clamp(noise*exp2(-8.)+encode_old(normal),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)); + + + vec2 lm = lmtexcoord.zw; + + // vec3 normalTex = texture2DGradARB(normals,adjustedTexCoord.xy,dcdx,dcdy).xyz; + // normal = applyBump(tbnMatrix,texture2DGradARB(normals,adjustedTexCoord.xy,dcdx,dcdy).xyz*2.0-1.0); + + // #ifdef MC_NORMAL_MAP + vec3 normalTex = texture2DGradARB(normals, adjustedTexCoord.xy, dcdx,dcdy).rgb; + #ifndef SSAO + #ifdef texture_ao + lm *= clamp( pow(normalTex.b,0.4) ,0,1); // texture ao? i think? i dont know + // lm *= clamp(0.5 + pow(normalTex.b,0.1) - max(normalTex.g,0),0,1) ; // texture ao? i think? i dont know + #endif + #endif + normalTex.xy = normalTex.xy*2.0-1.0; + normalTex.z = sqrt(1.0 - dot(normalTex.xy, normalTex.xy)); + normal = applyBump(tbnMatrix,normalTex); + // #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); + + vec4 data1 = clamp(encode(viewToWorld(normal), lm),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] = texture2DGradARB(specular, adjustedTexCoord.xy,dcdx,dcdy); + gl_FragData[1].a = 0.0; + + #else + + vec4 data0 = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias); + + vec4 specularMap = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias); + gl_FragData[2].rgba = specularMap; + + data0.rgb *= color.rgb + vec3(0,255,0); + + 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 DISABLE_ALPHA_MIPMAPS + data0.a = texture2DLod(texture,lmtexcoord.xy,0).a; + #endif + + + if (data0.a > 0.1) data0.a = normalMat.a; + else data0.a = 0.0; + + vec2 lm = lmtexcoord.zw; + + #ifdef MC_NORMAL_MAP + vec3 normalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgb; + // #ifndef SSAO + // #ifdef texture_ao + // lm *= clamp( pow(normalTex.b,0.4) ,0,1); // texture ao? i think? i dont know + // // lm *= clamp(0.5 + pow(normalTex.b,0.1) - max(normalTex.g,0),0,1) ; // texture ao? i think? i dont know + // #endif + // #endif + 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); + #endif + + // #ifdef MC_NORMAL_MAP + // normal =clamp( applyBump(tbnMatrix,texture2D(normals, lmtexcoord.xy,Texture_MipMap_Bias).rgb*2.0-1.0),-1.,1.); + // #endif + + // vec4 data1 = clamp(noise/256.+encode(normal, lm),0.,1.0); + vec4 data1 = clamp(encode(viewToWorld(normal), lm),0.,1.0); + + vec2 texcoord = gl_FragCoord.xy*lmtexcoord.xy; + vec4 data = texture2D(colortex1,texcoord); + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + + 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; + + + // float emissionMat = specularMap.a < 1.0 ? specularMap.a * specularMap.a : 0.0; + // gl_FragData[0].rgb = mix(gl_FragData[0].rgb, vec3(emissionMat) ,1); + + #endif + +} \ No newline at end of file diff --git a/shaders/gbuffers_textured.vsh b/shaders/gbuffers_textured.vsh new file mode 100644 index 0000000..a1358ce --- /dev/null +++ b/shaders/gbuffers_textured.vsh @@ -0,0 +1,165 @@ +#version 120 +#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 SSS_mode 1 // [1 2] + + +#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 + +uniform float frameTimeCounter; +const float PI48 = 150.796447372*WAVY_SPEED; +float pi2wt = PI48*frameTimeCounter; +attribute vec4 mc_Entity; +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; + #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),mc_Entity.x == 10004 || mc_Entity.x == 10003 || mc_Entity.x == 10001 ? 0.5: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.9 : normalMat.a; + normalMat.a = mc_Entity.x == 10009 ? 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); + #ifdef SEPARATE_AO + lmtexcoord.z *= sqrt(color.a); + lmtexcoord.w *= color.a; + #else + color.rgb*=color.a; + #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 +} diff --git a/shaders/gbuffers_textured_lit.fsh b/shaders/gbuffers_textured_lit.fsh new file mode 100644 index 0000000..bcc6769 --- /dev/null +++ b/shaders/gbuffers_textured_lit.fsh @@ -0,0 +1,5 @@ +#version 120 + +// #define WEATHER +#define PARTICLES +#include "gbuffers_all_particles.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_textured_lit.vsh b/shaders/gbuffers_textured_lit.vsh new file mode 100644 index 0000000..1381905 --- /dev/null +++ b/shaders/gbuffers_textured_lit.vsh @@ -0,0 +1,5 @@ +#version 120 + +// #define WEATHER +#define PARTICLES +#include "gbuffers_all_particles.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_water.fsh b/shaders/gbuffers_water.fsh new file mode 100644 index 0000000..9208bed --- /dev/null +++ b/shaders/gbuffers_water.fsh @@ -0,0 +1,4 @@ +#version 120 + +// #define WORLD +#include "gbuffers_all_translucent.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_water.vsh b/shaders/gbuffers_water.vsh new file mode 100644 index 0000000..5228fab --- /dev/null +++ b/shaders/gbuffers_water.vsh @@ -0,0 +1,4 @@ +#version 120 + +// #define WORLD +#include "gbuffers_all_translucent.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_weather.fsh b/shaders/gbuffers_weather.fsh new file mode 100644 index 0000000..eba2476 --- /dev/null +++ b/shaders/gbuffers_weather.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define WEATHER +#define PARTICLES +#include "gbuffers_all_particles.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_weather.vsh b/shaders/gbuffers_weather.vsh new file mode 100644 index 0000000..b63e120 --- /dev/null +++ b/shaders/gbuffers_weather.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define WEATHER +#define PARTICLES +#include "gbuffers_all_particles.vsh" \ No newline at end of file diff --git a/shaders/lang/en_us.lang b/shaders/lang/en_us.lang new file mode 100644 index 0000000..cba6470 --- /dev/null +++ b/shaders/lang/en_us.lang @@ -0,0 +1,9 @@ +option.indirect_effect = Indirect Lighting +value.indirect_effect.0 = Vanilla AO +value.indirect_effect.1 = SSAO +value.indirect_effect.2 = RTAO +value.indirect_effect.3 = SSGI + +option.ambient_colortype = Coloring Type +value.ambient_colortype.0 = Temperature +value.ambient_colortype.1 = RGB \ No newline at end of file diff --git a/shaders/lib/ROBOBO_sky.glsl b/shaders/lib/ROBOBO_sky.glsl new file mode 100644 index 0000000..0ed71f6 --- /dev/null +++ b/shaders/lib/ROBOBO_sky.glsl @@ -0,0 +1,182 @@ +// uniform float LowCoverage; + +// uniform float isDeserts; +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 * 0.2e-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, 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 200.0 //[0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0 150.0 200.0 300.0 400.0 500.0 600.0 700.0 800.0 900.0 1000.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.91 //[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 colortype 2 // 1 = RGB sliders for sun/moon color. 2 = blackbody. [1 2] +#define Sun_temp 7000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000] +#define Moon_temp 15000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000] + +// #define sunColorBase mix( vec3(sunColorR,sunColorG,sunColorB), blackbody(50000), LowCoverage) * sun_illuminance + + + + +#define moonColorR 0.9080 //[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.9121 //[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.8948 //[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 ] + +#if colortype == 1 + #define sunColorBase vec3(sunColorR,sunColorG,sunColorB) * sun_illuminance + #define moonColorBase vec3(moonColorR,moonColorG,moonColorB) * moon_illuminance //Fake Purkinje effect +#else + #define sunColorBase blackbody(Sun_temp) * sun_illuminance + #define moonColorBase blackbody(Moon_temp) * moon_illuminance //Fake Purkinje effect +#endif + + +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); + + + // float low_sun = clamp(pow(1.0-sunVector.y,10.0) + 1.0,1.0, 2.0); + + float high_sun = clamp(pow(sunVector.y+0.6,5),0.0,1.0) * 3.0; // make sunrise less blue, and allow sunset to be bluer + float low_sun = clamp(((1.0-abs(sunVector.y))*3.) - high_sun,1.0,2.5) ; + + 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*0.5+0.1, 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 * low_sun); + + transmittance *= stepTransmittance; + } + + vec3 scattering = scatteringSun * sunColorBase + (scatteringAmbient) * background + scatteringMoon*moonColorBase ; + // scattering = vec3(0,high_sun*255.,0); + return scattering; +} diff --git a/shaders/lib/Shadow_Params.glsl b/shaders/lib/Shadow_Params.glsl new file mode 100644 index 0000000..ba81659 --- /dev/null +++ b/shaders/lib/Shadow_Params.glsl @@ -0,0 +1,44 @@ + + +const float ambientOcclusionLevel = 0.15; //[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 = 2048; //Will probably crash at 16 384 [512 768 1024 1536 2048 3172 4096 8192 16384] +const float shadowDistance = 69.; //[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 + +#define Variable_Penumbra_Shadows //Makes the shadows more blurry the more distant they are to objects (costs fps) +#define VPS_Search_Samples 4 //The number of samples used to find occluders [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 Min_Shadow_Filter_Radius 5.0 //If Variable_Penumbra_Shadows are not used, will be used as shadow filter size. [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0 91.0 92.0 93.0 94.0 95.0 96.0 97.0 98.0 99.0 100.0 101.0 102.0 103.0 104.0 105.0 106.0 107.0 108.0 109.0 110.0 111.0 112.0 113.0 114.0 115.0 116.0 117.0 118.0 119.0 ] +#define Max_Shadow_Filter_Radius 30.0 //Not used if Variable_Penumbra_Shadows are not used. Will cause issues at too high values [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0 91.0 92.0 93.0 94.0 95.0 96.0 97.0 98.0 99.0 100.0 101.0 102.0 103.0 104.0 105.0 106.0 107.0 108.0 109.0 110.0 111.0 112.0 113.0 114.0 115.0 116.0 117.0 118.0 119.0 ] +#define Max_Filter_Depth 20.0 //Distance to the occluder at which the shadow filter size reaches its maximum. [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0 91.0 92.0 93.0 94.0 95.0 96.0 97.0 98.0 99.0 100.0 101.0 102.0 103.0 104.0 105.0 106.0 107.0 108.0 109.0 110.0 111.0 112.0 113.0 114.0 115.0 116.0 117.0 118.0 119.0 ] +#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 13 // 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 SSGI +#define RAY_COUNT 4 // [1 2 3 4 5 6 7 8 9 10 12 14 16 18 21 24 28 32 37 43 49 57 65 75 86 100] +#define STEPS 8 // [ 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] +#define STEP_LENGTH 12. // [ 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.] +#define SubSurfaceScattering + +const float k = 1.8; +const float d0 = 0.04; +const float d1 = 0.61; +float a = exp(d0); +float b = (exp(d1)-a)*150./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); +} diff --git a/shaders/lib/biome_specifics.glsl b/shaders/lib/biome_specifics.glsl new file mode 100644 index 0000000..41be98a --- /dev/null +++ b/shaders/lib/biome_specifics.glsl @@ -0,0 +1,100 @@ +// #define Biome_specific_environment // makes the fog density and color look unique in certain biomes. (swamps, jungles, lush caves, giant pines, dark forests) +// #define Jungle_fog_strength 1.0 // how strong the fog gets there. set to zero to have normal fog [0.0 0.25 0.50 0.75 1.0] +// #define Swamp_fog_strength 1.0 // how strong the fog gets there. set to zero to have normal fog [0.0 0.25 0.50 0.75 1.0] +// #define Lush_fog_strength 1.0 // how strong the fog gets there. set to zero to have normal fog [0.0 0.25 0.50 0.75 1.0] + +// #define Time_of_day_fog // fog starts closer to you at sunrise/sunset + night +// #define Rain_fog // rain fog. +// #define Lightmap_based_fog // fog that changes lighting based on the light from the sky. so if you're in a cave, it changes. if you go to the surface, its mostly normal + +// #define Swamp_R 0.9 // the color of the fog. only effects this specific biome [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 Swamp_G 1.0 // the color of the fog. only effects this specific biome [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 Swamp_B 0.35 // the color of the fog. only effects this specific biome [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 Jungle_R 0.5 // the color of the fog. only effects this specific biome [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 Jungle_G 1.0 // the color of the fog. only effects this specific biome [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 Jungle_B 0.8 // the color of the fog. only effects this specific biome [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 override_R 0.5 // the color of the fog. only effects this specific biome [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 override_G 1.0 // the color of the fog. only effects this specific biome [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 override_B 0.8 // the color of the fog. only effects this specific biome [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 Swamp_cloudyfog_Density 25. // how dense or thick the cloudy fog is. only effects this specific biome [0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.] +// #define Jungle_Cloudy_Fog_Density 10. // how dense or thick the cloudy fog is. only effects this specific biome [0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.] +// #define override_Cloudy_Fog_Density 1. // how dense or thick the cloudy fog is. only effects this specific biome [0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.] + +// #define Swamp_UniformFog_Density 15. // how dense or thick the uniform fog is. only effects this specific biome [0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.] +// #define Jungle_Uniform_Fog_Density 10. //how dense or thick the uniform fog is. only effects this specific biome [0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.] +// #define override_Uniform_Fog_Density 1. //how dense or thick the uniform fog is. only effects this specific biome [0. 5. 10. 15. 20. 25. 30. 35. 40. 45. 50. 55. 60. 65. 70. 75. 80. 85. 90. 95. 100.] + +// #define Swamp_Mie 0.75 // control the size of the peak of light around the sun in the fog. only effects this specific biome [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 Jungle_Mie 0.75 // control the size of the peak of light around the sun in the fog. only effects this specific biome [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 override_Mie 1.0 // control the size of the peak of light around the sun in the fog. only effects this specific biome [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 Swamp_Sun_Strength 1.0 // control how strong the sun shines through fog. only effects this specific biome [0.0 0.25 0.50 0.75 1.0 1.25 1.50 1.75 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0] +// #define Jungle_Sun_Strength 1.0 // control how strong the sun shines through fog. only effects this specific biome [0.0 0.25 0.50 0.75 1.0 1.25 1.50 1.75 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0] +// #define override_Sun_Strength 1.0 // control how strong the sun shines through fog. only effects this specific biome [0.0 0.25 0.50 0.75 1.0 1.25 1.50 1.75 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0] + +// #define Swamp_Bloomy_Fog 2.0 // control how bloomy the fog looks. only effects this specific biome [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0] +// #define Jungle_Bloomy_Fog 3.0 // control how bloomy the fog looks. only effects this specific biome [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0] +// #define override_Bloomy_Fog 1.0 // control how bloomy the fog looks. only effects this specific biome [0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0] + +// #define Swamp_cloudyfog_height 30 // controll the fade away at the top of the fog [5 10 20 30 40 50 60 70 80 90 100] +// #define Jungle_cloudyfog_fade 30 // controll the fade away at the top of the fog [5 10 20 30 40 50 60 70 80 90 100] +// #define override_cloudyfog_fade 50 // controll the fade away at the top of the fog [5 10 20 30 40 50 60 70 80 90 100] + +// #define Swamp_uniformfog_height 10 // controll the fade away at the top of the fog [5 10 20 30 40 50 60 70 80 90 100] +// #define Jungle_uniformfog_fade 10 // controll the fade away at the top of the fog [5 10 20 30 40 50 60 70 80 90 100] +// #define override_uniformfog_fade 50 // controll the fade away at the top of the fog [5 10 20 30 40 50 60 70 80 90 100] + + +// #define override_fog 0 // override the fog that exists everywhere with your own [0 1] + +// // uniform int isEyeInWater; +// // uniform float blindness; +// // uniform float rainStrength; +// // uniform ivec2 eyeBrightnessSmooth; +// // uniform float eyeAltitude; +// // uniform int worldTime; + +// uniform float isJungles; +// uniform float isSwamps; +// uniform float isLush; +// uniform float isDeserts; + +// // float timething = (worldTime%24000)*1.0; +// // float TimeOfDayFog = clamp((1.0 - clamp( timething-11000,0.0,2000.0)/2000.) * (clamp(timething,0.0,2000.0)/2000.) ,0.0,1.0); + +// // fuck you +// #ifdef Biome_specific_environment +// float SWAMPS = isSwamps; +// float JUNGLES = isJungles; +// float LUSHCAVE = isLush; +// float DESERTS = isDeserts; +// float OVERRIDE = max(override_fog - (SWAMPS + JUNGLES),0); +// #else +// float OVERRIDE = 0; +// float SWAMPS = 0; +// float JUNGLES = 0; +// float LUSHCAVE = 0; +// float DESERTS = 0; +// #endif + +// // all the fog settings that do various things. +// float[8] Biome_Fog_Properties = float[8]( +// /*[0] biome check*/ SWAMPS*Swamp_fog_strength + JUNGLES*Jungle_fog_strength + OVERRIDE +// /*[1] cloudy fog density*/ ,SWAMPS*Swamp_cloudyfog_Density + JUNGLES*Jungle_Cloudy_Fog_Density + OVERRIDE*override_cloudyfog_fade +// /*[2] uniform fog density*/ ,SWAMPS*Swamp_UniformFog_Density + JUNGLES*Jungle_Uniform_Fog_Density + OVERRIDE*override_Uniform_Fog_Density +// /*[3] sunlight strength*/ ,SWAMPS*Swamp_Sun_Strength + JUNGLES*Jungle_Sun_Strength + OVERRIDE*override_Sun_Strength +// /*[4] bloomy fog strength*/ ,SWAMPS*Swamp_Bloomy_Fog + JUNGLES*Jungle_Bloomy_Fog + OVERRIDE*override_Bloomy_Fog +// /*[5] fog mie size */ ,SWAMPS*Swamp_Mie + JUNGLES*Jungle_Mie + OVERRIDE*override_Mie +// /*[6] cloudy fog fade */ ,SWAMPS*Swamp_cloudyfog_height + JUNGLES*Jungle_cloudyfog_fade + OVERRIDE*override_Cloudy_Fog_Density +// /*[7] uniform fog fade */ ,SWAMPS*Swamp_uniformfog_height + JUNGLES*Jungle_uniformfog_fade + OVERRIDE*override_uniformfog_fade +// ); + +// // ??? ive no clue what this one does ngl +// vec3 Biome_FogColor = vec3( +// SWAMPS*Swamp_R + JUNGLES*Jungle_R + OVERRIDE*override_R +// ,SWAMPS*Swamp_G + JUNGLES*Jungle_G + OVERRIDE*override_G +// ,SWAMPS*Swamp_B + JUNGLES*Jungle_B + OVERRIDE*override_B +// ); \ No newline at end of file diff --git a/shaders/lib/climate_settings.glsl b/shaders/lib/climate_settings.glsl new file mode 100644 index 0000000..3aff8e3 --- /dev/null +++ b/shaders/lib/climate_settings.glsl @@ -0,0 +1,273 @@ +// this file contains all things for seasons, weather, and biome specific settings. +// i gotta start centralizing shit someday. + +#define Seasons +#define Season_Length 24 // how long each season lasts in minecraft days. 91 is roughly how long each season is in reality. 1 will make a year last 4 days [ 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 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] +// #define Snowy_Winter // snow in the winter, yes or no? + +#define Summer_R 1.0 // the color of the plants during this season [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] +#define Summer_G 1.0 // the color of the plants during this season [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] +#define Summer_B 1.0 // the color of the plants during this season [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] +#define Summer_Leaf_R 1.0 // the color of the plants during this season [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] +#define Summer_Leaf_G 1.0 // the color of the plants during this season [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] +#define Summer_Leaf_B 1.0 // the color of the plants during this season [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] + +#define Fall_R 1.5 // the color of the plants during this season [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] +#define Fall_G 1.0 // the color of the plants during this season [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] +#define Fall_B 1.0 // the color of the plants during this season [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] +#define Fall_Leaf_R 1.8 // the color of the plants during this season [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] +#define Fall_Leaf_G 0.8 // the color of the plants during this season [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] +#define Fall_Leaf_B 0.0 // the color of the plants during this season [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] + +#define Winter_R 1.2 // the color of the plants during this season [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] +#define Winter_G 0.8 // the color of the plants during this season [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] +#define Winter_B 1.0 // the color of the plants during this season [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] +#define Winter_Leaf_R 1.2 // the color of the plants during this season [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] +#define Winter_Leaf_G 0.5 // the color of the plants during this season [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] +#define Winter_Leaf_B 1.0 // the color of the plants during this season [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] + +#define Spring_R 1.0 // the color of the plants during this season [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] +#define Spring_G 0.9 // the color of the plants during this season [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] +#define Spring_B 1.1 // the color of the plants during this season [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] +#define Spring_Leaf_R 1.0 // the color of the plants during this season [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] +#define Spring_Leaf_G 0.8 // the color of the plants during this season [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] +#define Spring_Leaf_B 0.8 // the color of the plants during this season [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] + + +#define Daily_Weather // different skies for different days, and fog. +#define WeatherDay -1 // [-1 0 1 2 3 4 5 6 7] + +#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.6 // 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] + +#define Biome_specific_environment // makes the fog density and color look unique in certain biomes. (swamps, jungles, lush caves, giant pines, dark forests) + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +///////////////////////////////// SEASONS ///////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// VERTEX SHADER +#ifdef Seasons + #ifdef SEASONS_VSH + varying vec4 seasonColor; + void YearCycleColor ( + inout vec3 FinalColor, + vec3 glcolor + ){ + // colors for things that arent leaves and using the tint index. + vec3 SummerCol = vec3(Summer_R, Summer_G, Summer_B) * glcolor; + vec3 AutumnCol = vec3(Fall_R, Fall_G, Fall_B) * glcolor; + vec3 WinterCol = vec3(Winter_R, Winter_G, Winter_B) ; + vec3 SpringCol = vec3(Spring_R, Spring_G, Spring_B) * glcolor; + + // do leaf colors different because thats cool and i like it + if(mc_Entity.x == 10003){ + SummerCol = vec3(Summer_Leaf_R, Summer_Leaf_G, Summer_Leaf_B) * glcolor; + AutumnCol = vec3(Fall_Leaf_R, Fall_Leaf_G, Fall_Leaf_B) * glcolor; + WinterCol = vec3(Winter_Leaf_R, Winter_Leaf_G, Winter_Leaf_B) ; + SpringCol = vec3(Spring_Leaf_R, Spring_Leaf_G, Spring_Leaf_B)* glcolor; + } + + // length of each season in minecraft days + int SeasonLength = Season_Length; + + // loop the year. multiply the season length by the 4 seasons to create a years time. + float YearLoop = mod(worldDay, SeasonLength * 4); + + // the time schedule for each season + float SummerTime = clamp(YearLoop ,0, SeasonLength) / SeasonLength; + float AutumnTime = clamp(YearLoop - SeasonLength ,0, SeasonLength) / SeasonLength; + float WinterTime = clamp(YearLoop - SeasonLength*2 ,0, SeasonLength) / SeasonLength; + float SpringTime = clamp(YearLoop - SeasonLength*3 ,0, SeasonLength) / SeasonLength; + + // lerp all season colors together + vec3 SummerToFall = mix(SummerCol, AutumnCol, SummerTime); + vec3 FallToWinter = mix(SummerToFall, WinterCol, AutumnTime); + vec3 WinterToSpring = mix(FallToWinter, SpringCol, WinterTime); + vec3 SpringToSummer = mix(WinterToSpring, SummerCol, SpringTime); + + // make it so that you only have access to parts of the texture that use the tint index + bool IsTintIndex = floor(dot(glcolor,vec3(0.5))) < 1.0; + + // multiply final color by the final lerped color, because it contains all the other colors. + if (IsTintIndex && mc_Entity.x != 200) FinalColor = SpringToSummer; + } + #endif +#endif + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +////////////////////////////// DAILY WEATHER ////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +#ifdef WEATHERCLOUDS + uniform float CumulusCoverage; + uniform float CirrusCoverage; + uniform float CirrusThickness; + + float DailyWeather_LowAltitude( + float Coverage + ){ + + #ifdef Daily_Weather + int W_DAY = WeatherDay; + + if(W_DAY > -1) { + if(W_DAY == 0) Coverage += 0.1; + if(W_DAY == 1) Coverage += 0.5; + if(W_DAY == 2) Coverage += 0.2; + if(W_DAY == 3) Coverage += 0.8; + if(W_DAY == 4) Coverage += 0.1; + if(W_DAY == 5) Coverage += 0.6; + if(W_DAY == 6) Coverage += 0.0; + if(W_DAY == 7) Coverage += 1.0; + }else{ + Coverage += mix(CumulusCoverage, Rain_coverage, rainStrength); + } + #else + Coverage += mix(cloudCoverage, Rain_coverage, rainStrength); + #endif + + return Coverage; + } + + void DailyWeather_HighAltitude( + inout float Coverage, + inout float Thickness + ){ + + #ifdef Daily_Weather + float W_DAY = WeatherDay; + + if(W_DAY > -1) { + if(W_DAY == 0){ Coverage = 0.8; Thickness = 0.5; } + if(W_DAY == 1){ Coverage = 0.8; Thickness = 0.5; } + if(W_DAY == 2){ Coverage = 0.0; Thickness = 0.5; } + if(W_DAY == 3){ Coverage = 0.0; Thickness = 0.5; } + if(W_DAY == 4){ Coverage = 0.0; Thickness = 0.5; } + if(W_DAY == 5){ Coverage = 0.0; Thickness = 0.5; } + if(W_DAY == 6){ Coverage = 0.0; Thickness = 0.5; } + if(W_DAY == 7){ Coverage = 0.0; Thickness = 0.5; } + }else{ + Coverage = CirrusCoverage; + Thickness = CirrusThickness; + } + #else + Coverage = 0.5; + Thickness = 0.05; + #endif + + Coverage = pow(1.0-Coverage,3) * 50; + Thickness = Thickness * 10; + } +#endif + +#ifdef Daily_Weather + uniform float Day; + + void DailyWeather_FogDensity( + inout vec4 UniformDensity, + inout vec4 CloudyDensity + ){ + // it's so symmetrical~ + float day0 = clamp(clamp(Day, 0.0,1.0)*clamp(2-Day, 0.0,1.0),0.0,1.0); + float day1 = clamp(clamp(Day-1, 0.0,1.0)*clamp(3-Day, 0.0,1.0),0.0,1.0); + float day2 = clamp(clamp(Day-2, 0.0,1.0)*clamp(4-Day, 0.0,1.0),0.0,1.0); + float day3 = clamp(clamp(Day-3, 0.0,1.0)*clamp(5-Day, 0.0,1.0),0.0,1.0); + float day4 = clamp(clamp(Day-4, 0.0,1.0)*clamp(6-Day, 0.0,1.0),0.0,1.0); + float day5 = clamp(clamp(Day-5, 0.0,1.0)*clamp(7-Day, 0.0,1.0),0.0,1.0); + float day6 = clamp(clamp(Day-6, 0.0,1.0)*clamp(8-Day, 0.0,1.0),0.0,1.0); + float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); + + // set fog Profiles for each of the 8 days in the cycle. + // U = uniform fog || C = cloudy fog + vec4 MistyDay_U = vec4(5); + + vec4 FoggyDay_U = vec4(5); + vec4 FoggyDay_C = vec4(25); + + + UniformDensity += FoggyDay_U*day1 + MistyDay_U*day4; + CloudyDensity += FoggyDay_C*day1; + } +#endif + +/////////////////////////////////////////////////////////////////////////////// +///////////////////////////// BIOME SPECIFICS ///////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +#ifdef Biome_specific_environment + uniform float isJungles; + uniform float isSwamps; + uniform float isLush; + uniform float isDeserts; + + void BiomeFogColor( + inout vec3 FinalFogColor + ){ + // this is a little complicated? lmao + vec3 BiomeColors; + BiomeColors.r = isSwamps*0.7 + isJungles*0.5; + BiomeColors.g = isSwamps*1.0 + isJungles*1.0; + BiomeColors.b = isSwamps*0.35 + isJungles*0.8; + + // insure the biome colors are locked to the fog shape and lighting, but not its orignal color. + BiomeColors *= dot(FinalFogColor,vec3(0.5)); + + // these range 0.0-1.0. they will never overlap. + float Inbiome = isJungles+isSwamps; + + // interpoloate between normal fog colors and biome colors. the transition speeds are conrolled by the biome uniforms. + FinalFogColor = mix(FinalFogColor, BiomeColors, Inbiome); + } + + void BiomeFogDensity( + inout vec4 UniformDensity, + inout vec4 CloudyDensity + ){ + // these range 0.0-1.0. they will never overlap. + float Inbiome = isJungles+isSwamps; + + vec2 BiomeFogDensity; // x = uniform || y = cloudy + BiomeFogDensity.x = isSwamps*5 + isJungles*5; + BiomeFogDensity.y = isSwamps*50 + isJungles*2; + + UniformDensity = mix(UniformDensity, vec4(BiomeFogDensity.x), Inbiome); + CloudyDensity = mix(CloudyDensity, vec4(BiomeFogDensity.y), Inbiome); + } +#endif + +/////////////////////////////////////////////////////////////////////////////// +////////////////////////////// FOG CONTROLLER ///////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +#ifdef TIMEOFDAYFOG + uniform int worldTime; + void TimeOfDayFog(inout float Uniform, inout float Cloudy) { + + float Time = (worldTime%24000)*1.0; + + // set schedules for fog to appear at specific ranges of time in the day. + float Morning = clamp((Time-22000)/2000,0,1) + clamp((2000-Time)/2000,0,1); + float Noon = clamp(Time/2000,0,1) * clamp((12000-Time)/2000,0,1); + float Evening = clamp((Time-10000)/2000,0,1) * clamp((14000-Time)/2000,0,1) ; + float Night = clamp((Time-13000)/2000,0,1) * clamp((23000-Time)/2000,0,1) ; + + // set densities. morn, noon, even, night + vec4 UniformDensity = vec4(1.0, 0.0, 1.0, 10.0); + vec4 CloudyDensity = vec4(5.0, 0.0, 5.0, 25.0); + + #ifdef Daily_Weather + DailyWeather_FogDensity(UniformDensity, CloudyDensity); // let daily weather influence fog densities. + #endif + + #ifdef Biome_specific_environment + BiomeFogDensity(UniformDensity, CloudyDensity); // let biome fog hijack to control densities, and overrride any other density controller... + #endif + + Uniform *= Morning*UniformDensity.r + Noon*UniformDensity.g + Evening*UniformDensity.b + Night*UniformDensity.a; + Cloudy *= Morning*CloudyDensity.r + Noon*CloudyDensity.g + Evening*CloudyDensity.b + Night*CloudyDensity.a; + } +#endif diff --git a/shaders/lib/clouds.glsl b/shaders/lib/clouds.glsl new file mode 100644 index 0000000..abd35ef --- /dev/null +++ b/shaders/lib/clouds.glsl @@ -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.))); + +} \ No newline at end of file diff --git a/shaders/lib/color_dither.glsl b/shaders/lib/color_dither.glsl new file mode 100644 index 0000000..73c4960 --- /dev/null +++ b/shaders/lib/color_dither.glsl @@ -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); +} \ No newline at end of file diff --git a/shaders/lib/color_transforms.glsl b/shaders/lib/color_transforms.glsl new file mode 100644 index 0000000..b016657 --- /dev/null +++ b/shaders/lib/color_transforms.glsl @@ -0,0 +1,157 @@ +//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)); +} + +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 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; +} +vec3 HableTonemap(vec3 linearColor) { + // A = shoulder strength + const float A = 0.45; + // B = linear strength + const float B = 0.28; + // C = linear angle + const float C = 0.1; + // D = toe strength + const float D = 0.5; + // E = toe numerator + const float E = 0.01; + // F = toe denominator + const float F = 0.3; + // Note: E / F = toe angle + // linearWhite = linear white point value + + vec3 x = linearColor*2.0; + vec3 color = ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F; + + const float W = 11.0; + 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.9; + 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.6; + const float d = 0.977; + const float hdrMax = 8.0; + const float midIn = 0.23; + 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); +} +vec3 curve(vec3 x){ + return 1.0 - x/(1.0+x); +} +vec3 Tonemap_Uchimura_Modified(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(x, vec3(0.0), vec3(m)); + 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) * curve(CP * (x - S0)); + vec3 L = m + a * (x - m); + + return clamp(T * w0 + L * w1 + S * w2,0.0,1.0); +} +// 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(x, vec3(0.0), vec3(m)); + 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 clamp(T * w0 + L * w1 + S * w2,0.0,1.0); +} + +vec3 Tonemap_Uchimura(vec3 x) { + const float P = 1.0; // max display brightness 1.0 + const float a = 1.0; // contrast 1.0 + const float m = 0.12; // linear section start 0.22 + const float l = 0.22; // linear section length 0.4 + const float c = 1.5; // black 1.33 + const float b = 0.0; // pedestal 0.0 + return Tonemap_Uchimura_Modified(x, P, a, m, l, c, b); +} diff --git a/shaders/lib/projections.glsl b/shaders/lib/projections.glsl new file mode 100644 index 0000000..72ab381 --- /dev/null +++ b/shaders/lib/projections.glsl @@ -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; +} diff --git a/shaders/lib/res_params.glsl b/shaders/lib/res_params.glsl new file mode 100644 index 0000000..f2c3322 --- /dev/null +++ b/shaders/lib/res_params.glsl @@ -0,0 +1,20 @@ +#define TAA +// #define TAA_UPSCALING // Lowers render resolution and uses TAA to combine several lower resolution images (greatly improves performance). USE THIS INSTEAD OF SHADER RENDER QUALITY OPTION IF YOU WANT TO INCREASE FPS (Leave it to 1). IF YOU WANT TO INCREASE QUALITY DISABLE THIS AND INCREASE SHADER RENDER QUALITY +#ifndef TAA + #undef TAA_UPSCALING +#endif + + + +#ifdef TAA_UPSCALING + #define RENDER_SCALE_X 0.7 // X axis render resolution multiplier [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. ] + #define RENDER_SCALE_Y 0.7 // Y axis render resolution multiplier [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. ] + #define RENDER_SCALE vec2(RENDER_SCALE_X, RENDER_SCALE_Y) + #define UPSCALING_SHARPNENING 2.0 - RENDER_SCALE_X - RENDER_SCALE_Y +#else + #define RENDER_SCALE vec2(1.0, 1.0) + #define UPSCALING_SHARPNENING 0.0 +#endif + +#define BLOOM_QUALITY 0.5 // Reduces the resolution at which bloom is computed. (0.5 = half of default resolution) [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. ] +#define VL_RENDER_RESOLUTION 0.5 // Reduces the resolution at which volumetric fog is computed. (0.5 = half of default resolution) [0.25 0.5 1.0] diff --git a/shaders/lib/settings.glsl b/shaders/lib/settings.glsl new file mode 100644 index 0000000..828447b --- /dev/null +++ b/shaders/lib/settings.glsl @@ -0,0 +1,45 @@ +#define Moon_temp 15000 // [1000 2000 3000 4000 5000 6000 7000 8000 9000 10000] + + + +#define CAVE_LIGHT_LEAK_FIX // Hackish way to remove sunlight incorrectly leaking into the caves. Can inacurrately create shadows in some places +#define CLOUDS_SHADOWS +#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 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 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 ambient_brightness 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ] +#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 Sub_surface_scattering // (place the flashlight on your hand example here) +// #define LabPBR_subsurface_scattering +#define LabSSS_Curve 1.0 // i just really like how it looks at 2.0, so i made it an option. [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 Strong_SSS_strength 45 // [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2 3 4 5 6 7 8 9 10 15 20 30 35 40 45 50] +#define Medium_SSS_strength 30 // [ 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2 3 4 5 6 7 8 9 10 15 20 30 35 40 45 50] + +#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 HQ_SSGI + + +// #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 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] +#define Puddles // yes +// #define Porosity + + +// #define Allow_Vanilla_sky // allow the vanilla sky to appear. may appear broken with some resourcepacks. + +// #define WhiteWorld // THIS IS A DEBUG VIEW. uses to see AO easier. used to see fake GI better (green light) +// #define ambientLight_only // THIS IS A DEBUG VIEW. turn the sunlight off. DOES NOT increase performance, the shadows are still working in the background +#define MIN_LIGHT_AMOUNT 1.0 //[0.0 0.5 1.0 1.5 2.0 3.0 4.0 5.0] diff --git a/shaders/lib/sky_gradient.glsl b/shaders/lib/sky_gradient.glsl new file mode 100644 index 0000000..559faf3 --- /dev/null +++ b/shaders/lib/sky_gradient.glsl @@ -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); +} diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl new file mode 100644 index 0000000..415467a --- /dev/null +++ b/shaders/lib/specular.glsl @@ -0,0 +1,349 @@ +//#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-5; + + 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) + +} +// vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){ + +// vec3 clipPosition = toClipSpace3(position); +// float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? +// (-near -position.z) / dir.z : far*sqrt(3.); +// vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space +// direction.xy = normalize(direction.xy); + +// //get at which length the ray intersects with the edge of the screen +// vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; +// float mult = 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) ; + +// float minZ = spos.z+stepv.z; +// float maxZ = spos.z+stepv.z; + +// spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; +// spos += stepv*dither ; + +// for(int i = 0; i < int(quality); i++){ +// float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0); +// float currZ = linZ(spos.z); +// if( sp < currZ) { +// float dist = abs(sp-currZ)/currZ; +// if (dist <= 0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); +// } +// spos += stepv ; +// } +// return vec3(1.1); +// } +vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){ + + vec3 clipPosition = toClipSpace3(position); + float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? + (-near -position.z) / dir.z : far*sqrt(3.); + vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space + direction.xy = normalize(direction.xy); + + //get at which length the ray intersects with the edge of the screen + vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; + float mult = maxLengths.y; + + vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither; + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; + + spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; + + float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases + + for(int i = 0; i < int(quality); i++){ + spos += stepv; + float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0); + float currZ = linZ(spos.z); + + if( sp < currZ) { + float dist = abs(sp-currZ)/currZ; + if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); + } + spos += stepv; + } + return vec3(1.1); +} + +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 roughness, float U1, float U2){ + // stretch view + vec3 V = normalize(vec3(roughness * V_.x, roughness * 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*0.25); + float phi = (U2 -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 = spos.z+stepv.z; + float maxZ = spos.z+stepv.z; + + spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; + + float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + 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(testthing),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; + + //small bias + float biasamount = 0.0002 / dist; + if(hand) biasamount = 0.01; + 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; +} + + +// 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 = clamp((lightmap-0.6)*5.0, 0.0,1.0); + // float Outdoors = clamp((lightmap-0.5) * , 0.0,1.0); + + roughness = unpackRoughness(roughness); + f0 = f0.y == 0.0 ? vec3(0.04) : f0; + + // roughness = 0.0; + // f0 = vec3(0.9); + + 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;} + + if (!hasReflections || NdotV > 0.0 ) Outdoors = 0.0; + + // SSR, Sky, and Sun reflections + vec4 Reflections = vec4(0.0); + vec3 SkyReflection = skyCloudsFromTex(L, colortex4).rgb / 150. * 5.; + vec3 SunReflection = diffuse * GGX2(clamp(normal,-1,1), -np3, sunPos, roughness, f0) * 8./150./3. * sunCol * Sun_specular_Strength; + + #ifndef Sky_reflection + SkyReflection = Reflections_Final; + #endif + + #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); + 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; + SunReflection *= Metals; + #ifdef Sky_reflection + SkyReflection *= Metals; + #endif + float lumaRayContrib = luma(rayContrib); + // darken albedos, and stop darkening where the sky gets occluded indoors + Reflections_Final *= mix_float(1.0 - (Reflections.a*lumaRayContrib), 1.0 - lumaRayContrib, Outdoors); + + // apply all reflections to the lighting + Reflections_Final += Reflections.rgb * lumaRayContrib; + Reflections_Final += SkyReflection * lumaRayContrib * (1.0-Reflections.a) * Outdoors ; + + 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 ; +} \ No newline at end of file diff --git a/shaders/lib/stars.glsl b/shaders/lib/stars.glsl new file mode 100644 index 0000000..c018c07 --- /dev/null +++ b/shaders/lib/stars.glsl @@ -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.5+elevation); + + return StableStarField(uv*1500.,0.999)*0.5*(0.3-0.3*rainStrength); +} diff --git a/shaders/lib/texFiltering.glsl b/shaders/lib/texFiltering.glsl new file mode 100644 index 0000000..7d58676 --- /dev/null +++ b/shaders/lib/texFiltering.glsl @@ -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; +} diff --git a/shaders/lib/util.glsl b/shaders/lib/util.glsl new file mode 100644 index 0000000..f701920 --- /dev/null +++ b/shaders/lib/util.glsl @@ -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; + } diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl new file mode 100644 index 0000000..ffc6b35 --- /dev/null +++ b/shaders/lib/volumetricClouds.glsl @@ -0,0 +1,436 @@ +#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 + +/////// 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 fbmAmount 0.50 // 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.] + +#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] + +/////// 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 15 20 30 40 50] + + +#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 +#define Cumulus_Clouds + + +/////// other +#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 float viewHeight; +uniform float viewWidth; +uniform sampler2D colortex4;//Skybox +// uniform float lightningFlash; + +// uniform vec4 Moon_Weather_properties; +// float highCov = Dynamic_sky_day == 0 ? 0.4 : Dynamic_sky_day == 1 ? 0.6 : Dynamic_sky_day == 2 ? 0.4 : Dynamic_sky_day == 3 ? -1000 : Dynamic_sky_day == 4 ? 1 : Dynamic_sky_day == 5 ? -1000 : Dynamic_sky_day == 6 ? 0.6 : 0.4; +// float lowCov = Dynamic_sky_day == 0 ? 0.4 : Dynamic_sky_day == 1 ? 0.9 : Dynamic_sky_day == 2 ? 0.0 : Dynamic_sky_day == 3 ? 0.5 : Dynamic_sky_day == 4 ? 0 : Dynamic_sky_day == 5 ? -1000 : Dynamic_sky_day == 6 ? -1000 : 0.8; +// float FogDen = Dynamic_sky_day == 0 ? 0 : Dynamic_sky_day == 1 ? 0 : Dynamic_sky_day == 2 ? 0 : Dynamic_sky_day == 3 ? 0 : Dynamic_sky_day == 4 ? 0 : Dynamic_sky_day == 5 ? 0 : Dynamic_sky_day == 6 ? 0 : 0; +// float CloudyFogden = Dynamic_sky_day == 0 ? 0 : Dynamic_sky_day == 1 ? 0 : Dynamic_sky_day == 2 ? 0 : Dynamic_sky_day == 3 ? 0 : Dynamic_sky_day == 4 ? 0 : Dynamic_sky_day == 5 ? 0 : Dynamic_sky_day == 6 ? 0 : 0; +// vec4 custom_day = vec4(highCov, lowCov, FogDen, CloudyFogden); + + +// #ifdef Dynamic_Sky + +// #if Dynamic_sky_day < 0 +// vec4 Weather_properties = Moon_Weather_properties; +// #endif + +// #if Dynamic_sky_day >= 0 +// vec4 Weather_properties = custom_day; +// #endif + +// #else +// vec4 Weather_properties = vec4(0); +// #endif + +#define WEATHERCLOUDS +#include "/lib/climate_settings.glsl" + + + +float maxHeight = 5000.; +float cloud_height = 1500.; + +// quick variables +float rainCloudwetness = rainStrength ; +float rainClouds = rainCloudwetness; + +float cloud_movement1 = frameTimeCounter * cloud_speed * 0.001; + + +//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; + + //The 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 cloudshape = 0.0; + +float cloudCov(in vec3 pos,vec3 samplePos){ + + float CloudLarge = texture2D(noisetex, samplePos.xz/150000 + cloud_movement1).b; + float CloudSmall = texture2D(noisetex, samplePos.xz/15000 - cloud_movement1 + vec2(1-CloudLarge,-CloudLarge)/5).r; + + float coverage = CloudSmall-CloudLarge; + + float mult = max( abs(pos.y-1750) / 5000, 0); + + // #ifdef Dynamic_Sky + // cloudshape = ( coverage + (-0.35+mix(Weather_properties.r, Rain_coverage, rainCloudwetness)*1.5) ) - mult; + // // cloudshape = coverage - mult; + // #else + // cloudshape = ( coverage + (-0.35+mix(cloudCoverage, Rain_coverage, rainCloudwetness)*1.5) ) - mult ; + // #endif + + cloudshape = DailyWeather_LowAltitude(coverage) - mult; + + return max(cloudshape,0.0); +} +//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); + + // samplePos.xyz -= cloud_movement1.xyz*400; + + for (int i = 0; i <= LoD; i++){ + float weight = exp(-i*pw2); + + noise += weight - densityAtPos(samplePos * 8 * exp(i*pw) )*weight ; + totalWeights += weight ; + } + + noise *= clamp(1.0-cloudshape,0.0,1.0); + noise /= totalWeights; + noise = noise*noise; + float cloud = max(cov-noise*noise*fbmAmount,0.0); + + return cloud; +} + +float getCloudDensity(in vec3 pos, in int LoD){ + + + vec3 samplePos = pos*vec3(1.0,1./48.,1.0)/4 ; + float coverageSP = cloudCov(pos,samplePos); + + if (coverageSP > 0.001) { + if (LoD < 0) return max(coverageSP - 0.27*fbmAmount,0.0); + return cloudVol(pos,samplePos,coverageSP, LoD); + } else return 0.0; +} + +float HighAltitudeClouds(vec3 pos){ + vec2 pos2d = pos.xz/100000.0 ; + + float cloudLarge = texture2D(noisetex, pos2d/5. ).b; + float cloudSmall = texture2D(noisetex, pos2d + vec2(-cloudLarge,cloudLarge)/10).b; + + + // #ifdef Dynamic_Sky + // coverage = max(10.3 - Weather_properties.g*10.,0.0); + // // thickness = Weather_properties.g*3 ; + // #endif + + float coverage = 1; + float thickness = 1; + DailyWeather_HighAltitude(coverage, thickness); + + float cirrusFinal = exp(pow((cloudSmall + cloudLarge),thickness) * -coverage ); + return max(cirrusFinal,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; +} + +// random magic number bullshit go! +vec3 Cloud_lighting( + vec3 Pos, + float CloudShape, + float SkyShadowing, + float SunShadowing, + float MoonShadowing, + vec3 SkyColors, + vec3 sunContribution, + vec3 sunContributionMulti, + vec3 moonContribution, + vec3 moonContributionMulti, + int cloudType +){ + + // low altitude + float powder = max(1.0 - exp2(-CloudShape*100.0),0.0); + float ambientShading = (powder*0.8+0.2) * exp2(-SkyShadowing * 50.); + vec3 ambientLighting = SkyColors * 4.0 * ambientShading; + + if(cloudType == 1) ambientLighting = SkyColors * (1.0-powder/2); + + vec3 sunLighting = ( exp2(-SunShadowing * 2.0 )*sunContribution + exp(-SunShadowing * 0.2 )*sunContributionMulti ) * powder; + vec3 moonLighting = ( exp2(-MoonShadowing * 2.0 )*moonContribution + exp(-MoonShadowing * 0.2 )*moonContributionMulti ) * powder; + + // if(cloudType == 0) sunLighting *= clamp((1.05-CirrusCoverage),0,1); // less sunlight hits low clouds if high clouds have alot of coverage + + return ambientLighting + sunLighting + moonLighting; +} + +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 + + float vL = 0.0; + float total_extinction = 1.0; + color = vec3(0.0); + + //project pixel position into projected shadowmap space + vec4 fragposition = gbufferModelViewInverse*vec4(fragpositi,1.0); + + vec3 worldV = normalize(fragposition.rgb); + float VdotU = worldV.y; + + //project view origin into projected shadowmap space + vec4 start = (gbufferModelViewInverse*vec4(0.0,0.0,0.,1.)); + + // vec3 dV_view = worldV; + + // cloud plane curvature + float curvature = 0.05; + worldV.y += curvature; + vec3 dV_view = worldV; + worldV.y -= curvature; + vec3 dV_view2 = worldV; + + + + maxIT_clouds = int(clamp( maxIT_clouds / sqrt(exp2(VdotU)),0.0, maxIT)); + + worldV = normalize(worldV)*100000. + cameraPosition; //makes max cloud distance not dependant of render distance + dV_view = normalize(dV_view); + + float height = Cloud_Height; + int flipClouds = 1; + // if (worldV.y < cloud_height){ + // flipClouds = -1; + // }; + + if (worldV.y < cloud_height || cameraPosition.y > 390. ) return vec4(0.,0.,0.,1.); //don't trace if no intersection is possible + // if (worldV.y < cloud_height && flipClouds == -1) return vec4(0.,0.,0.,1.); //don't trace if no intersection is possible + + //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*dither; + + vec3 camPos = ((cameraPosition*flipClouds)-height)*Cloud_Size; + + vec3 progress_view = startOffset + camPos + dV_view*(cloud_height-camPos.y)/dV_view.y; + + float shadowStep = 200.; + vec3 dV_Sun = flipClouds * normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep; + float mult = length(dV_view); + + float SdotV = dot(sunVec,normalize(fragpositi)); + + float spinX = sin(frameTimeCounter *3.14); + float spinZ = sin(1.57 + frameTimeCounter*3.14); + float SdotV_custom = dot(mat3(gbufferModelView) * normalize(vec3(0,0.1,0)),normalize(fragpositi)); + + float phaseLightning = phaseg(SdotV_custom, 0.7); + + // direct light colors and shit for clouds + // multiply everything by ~pi just for good luck :D + float mieDayMulti = phaseg(SdotV, 0.35)*3.14; + float mieDay = mix(phaseg(SdotV,0.75), mieDayMulti,0.8)*3.14; + + float mieNightMulti = phaseg(-SdotV, 0.35)*3.14; + float mieNight = mix(phaseg(-SdotV,0.9), mieNightMulti,0.5)*3.14; + + vec3 sunContribution = mieDay*sunColor*6.14; + vec3 sunContributionMulti = mieDayMulti*sunColor*3.14; + + vec3 moonContribution = mieNight*moonColor*3.14; + vec3 moonContributionMulti = mieNightMulti*moonColor*3.14; + + float ambientMult = 1.0; + vec3 skyCol0 = (avgAmbient * ambientMult) ; + + vec3 progress_view_high = progress_view + (20000.0-progress_view.y) * dV_view / dV_view.y; + float muEshD_high = 0.0; + float muEshN_high = 0.0; + + float cirrusShadowStep = 7.; + float cirrusDensity = 0.03; + + + float cloud = 0.0; + for(int i=0;i= 0.0){ + float muS = cloud*densityofclouds; + float muE = cloud*densityofclouds; + + float muEshD = 0.0; + if (sunContribution.g > 1e-5){ + for (int j=0; j < self_shadow_samples; j++){ + float sample = j+dither2; + + #ifdef Cumulus_Clouds + // low altitude clouds shadows + vec3 shadowSamplePos = progress_view + dV_Sun * (sample + sample*2.0); + + if (shadowSamplePos.y < maxHeight){ + float cloudS = getCloudDensity(vec3(shadowSamplePos), cloudShadowLoD); + muEshD += cloudS*cloudDensity*shadowStep; + } + #endif + + #ifdef High_Altitude_Clouds + // high altitude clouds shadows + vec3 shadowSamplePos_high = progress_view_high + dV_Sun * (sample + sample*2.0); + float highAlt_cloudS = HighAltitudeClouds(shadowSamplePos_high); + muEshD_high += highAlt_cloudS*cirrusDensity*cirrusShadowStep; + #endif + } + } + + float muEshN = 0.0; + if (moonContribution.g > 1e-5){ + for (int j=0; j= 0.0){ + float muS = cirrus*cirrusDensity; + float muE = cirrus*cirrusDensity; + + float muEshA_high = cirrus*cirrusDensity; + + vec3 S = Cloud_lighting(progress_view, muE, muEshA_high, muEshD_high, muEshN_high, skyCol0 * max(abs(dV_Sun.y)/150.0,0.5) , sunContribution, sunContributionMulti, moonContribution, moonContributionMulti, 1); + + vec3 Sint = (S - S * exp(-mult*muE)) / muE; + color += max(muS*Sint*total_extinction,0.0); + total_extinction *= max(exp(-muE*mult),0); + } + #endif + + vec3 normView = normalize(dV_view2)*flipClouds; + // Assume fog color = sky gradient at long distance + vec3 fogColor = skyFromTex(normView, colortex4)/150.; + float dist = (cloud_height - (cameraPosition.y))/normalize(dV_view2).y; + float fog = exp(-dist/15000.0*(1.0+rainCloudwetness*8.)); + return mix(vec4(fogColor,0.0), vec4(color,total_extinction), fog); + // return vec4(color,total_extinction); +} diff --git a/shaders/lib/volumetricFog.glsl b/shaders/lib/volumetricFog.glsl new file mode 100644 index 0000000..6324a7b --- /dev/null +++ b/shaders/lib/volumetricFog.glsl @@ -0,0 +1,184 @@ +#define VL_CLOUDS_SHADOWS +#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 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 Cloudy_Fog_Density 5.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 Uniform_Fog_Density 1.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 uniformfog_fade 10 // [5 10 20 30 40 50 60 70 80 90 100] +// #define cloudyfog_fade 10 // [5 10 20 30 40 50 60 70 80 90 100] + +float luma(vec3 color) { + return dot(color,vec3(0.299, 0.587, 0.114)); +} + +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 +} + + +// #define TIMEOFDAYFOG +// #include "/lib/climate_settings.glsl" + // uniform int worldTime; + + // void TimeOfDayFog( inout float Uniform, inout float Cloudy) { + + // float Time = (worldTime%24000)*1.0; + + // // set schedules for fog to appear at specific ranges of time in the day. + // float Morning = clamp((Time-22000)/2000,0,1) + clamp((2000-Time)/2000,0,1); + // float Noon = clamp(Time/2000,0,1) * clamp((12000-Time)/2000,0,1); + // float Evening = clamp((Time-10000)/2000,0,1) * clamp((14000-Time)/2000,0,1) ; + // float Night = clamp((Time-12000)/2000,0,1) * clamp((23000-Time)/2000,0,1) ; + + // vec4 UniformDensity = vec4(0, 55, 0, 0); + // vec4 CloudyDensity = vec4(0, 0, 0, 0); + + + // Uniform *= Morning*UniformDensity.r + Noon*UniformDensity.g + Evening*UniformDensity.b + Night*UniformDensity.a; + // Cloudy *= Morning*CloudyDensity.r + Noon*CloudyDensity.g + Evening*CloudyDensity.b + Night*CloudyDensity.a; + // } + +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); + + + float mult = exp2( -max((pos.y - SEA_LEVEL) / 35.,0.0)); + + float fog_shape = 1-densityAtPos(samplePos * 24.0); + float fog_eroded = densityAtPos( samplePos2 * 150.0); + + float CloudyFog = max( (fog_shape*2.0 - fog_eroded*0.5) - 1.4, 0.0) * mult; + float UniformFog = exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)); + + float RainFog = max(fog_shape*10. - 7.,0.5) * exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)) * 5. * rainStrength; + + TimeOfDayFog(UniformFog, CloudyFog); + + return RainFog + CloudyFog + UniformFog; +} + +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),far)/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 = phaseg(SdotV,0.7)*5.0 + 1.0; + float rayL = phaseRayleigh(SdotV); + + // Makes fog more white idk how to simulate it correctly + vec3 sunColor = lightCol.rgb / 5.0; + vec3 skyCol0 = (ambientUp / 5.0 * 5.); // * max(abs(WsunVec.y)/150.0,0.); + + 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 = mu; + vec3 absorbance = vec3(1.0); + float expFactor = 11.0; + vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; + + float cloudShadow = 1.0; + + for (int i=0;i [Filtering] shadowMapResolution shadowDistance shadowDistanceRenderMul + + screen.Subsurface_Scattering.columns=1 + screen.Subsurface_Scattering = Variable_Penumbra_Shadows Strong_SSS_strength Medium_SSS_strength LabPBR_subsurface_scattering LabSSS_Curve mob_SSS misc_block_SSS + + screen.Filtering.columns=1 + screen.Filtering = Variable_Penumbra_Shadows VPS_Search_Samples Min_Shadow_Filter_Radius Max_Shadow_Filter_Radius Max_Filter_Depth SHADOW_FILTER_SAMPLE_COUNT + + ### AMBIENT LIGHT + screen.Ambient_light.columns=1 + screen.Ambient_light = [Torch] [Ambient] [ambientlight_colors] indirect_effect HQ_SSGI AO_Strength GI_Strength + + screen.ambientlight_colors.columns=1 + screen.ambientlight_colors = ambient_brightness ambient_colortype ambient_temp AmbientLight_R AmbientLight_G AmbientLight_B + + screen.Torch.columns=1 + screen.Torch = TORCH_AMOUNT Emissive_Brightness Emissive_Curve TORCH_R TORCH_G TORCH_B + + screen.Ambient.columns=1 + screen.Ambient = ambientOcclusionLevel MIN_LIGHT_AMOUNT Ambient_Mult SEPARATE_AO + + +######## WORLD + screen.World.columns=1 + screen.World = [LabPBR] [Waving_Stuff] [Water] + ### SPECULARS + screen.Reflections.columns=2 + screen.Reflections = Specular_Reflections Sun_specular_Strength Screen_Space_Reflections reflection_quality Rough_reflections Roughness_Threshold Sky_reflection + ### WAVING STUFF + screen.Waving_Stuff.columns=1 + screen.Waving_Stuff = WAVY_STRENGTH WAVY_SPEED WAVY_PLANTS + ## POM + screen.POM.columns=1 + screen.POM = POM MAX_ITERATIONS POM_DEPTH MAX_DIST Horrible_slope_normals + + + +######## CLIMATE + screen.Climate.columns=1 + screen.Climate = [Seasons] [Weather] [Biome_Fog] + + ## SEASONS + screen.Seasons.columns=1 + screen.Seasons = Seasons Season_Length Snowy_Winter [Summer_colors] [Fall_colors] [Winter_colors] [Spring_colors] + + screen.Summer_colors.columns=1 + screen.Summer_colors = Summer_R Summer_G Summer_B Summer_Leaf_R Summer_Leaf_G Summer_Leaf_B + + screen.Fall_colors.columns=1 + screen.Fall_colors = Fall_R Fall_G Fall_B Fall_Leaf_R Fall_Leaf_G Fall_Leaf_B + + screen.Winter_colors.columns=1 + screen.Winter_colors = Winter_R Winter_G Winter_B Winter_Leaf_R Winter_Leaf_G Winter_Leaf_B + + screen.Spring_colors.columns=1 + screen.Spring_colors = Spring_R Spring_G Spring_B Spring_Leaf_R Spring_Leaf_G Spring_Leaf_B + + ## DAILY WEATHER + screen.Weather.columns=1 + screen.Weather = Daily_Weather WeatherDay + + ## BIOME SPECIFICS + screen.Biome_Fog.columns=1 + screen.Biome_Fog = Biome_specific_environment Jungle_fog_strength [Jungle_Settings] Swamp_fog_strength [Swamp_Settings] override_fog [Override_Settings] + + screen.Jungle_Settings.columns=1 + screen.Jungle_Settings = Jungle_R Jungle_G Jungle_B Jungle_Cloudy_Fog_Density Jungle_cloudyfog_fade Jungle_Uniform_Fog_Density Jungle_uniformfog_fade Jungle_Bloomy_Fog Jungle_Sun_Strength + + screen.Swamp_Settings.columns=1 + screen.Swamp_Settings = Swamp_R Swamp_G Swamp_B Swamp_cloudyfog_Density Swamp_cloudyfog_height Swamp_UniformFog_Density Swamp_uniformfog_height Swamp_Bloomy_Fog Swamp_Sun_Strength + + screen.Override_Settings.columns=1 + screen.Override_Settings = override_R override_G override_B override_Cloudy_Fog_Density override_cloudyfog_fade override_Uniform_Fog_Density override_uniformfog_fade override_Bloomy_Fog override_Sun_Strength + + +######## ATMOSPHERICS + screen.Atmospherics.columns=1 + screen.Atmospherics = [Sky] [Fog] [Biome_Fog] [Clouds] High_Altitude_Clouds Cumulus_Clouds Allow_Vanilla_sky CLOUDS_SHADOWS VL_CLOUDS_SHADOWS + ### SKY + screen.Sky.columns=1 + screen.Sky = [Sky_coefficients] [Sun_and_Moon_Colors] sunPathRotation + + screen.Sky_coefficients.columns=1 + screen.Sky_coefficients = Sky_Brightness sky_mieg sky_coefficientRayleighR sky_coefficientRayleighG sky_coefficientRayleighB sky_coefficientMieR sky_coefficientMieG sky_coefficientMieB + + ### CLOUDS + screen.Clouds.columns=2 + screen.Clouds = VOLUMETRIC_CLOUDS Dynamic_Sky cloud_LevelOfDetail cloud_ShadowLevelOfDetail CLOUDS_QUALITY cloudDensity cloudCoverage Rain_coverage cloud_speed fbmAmount fbmPower1 fbmPower2 Cloud_top_cutoff Cloud_base_cutoff Shadow_brightness self_shadow_samples + + ### FOG + screen.Fog.columns=1 + screen.Fog = [Biome_Fog] [cave_fog] [Fog_Densities] VL_RENDER_RESOLUTION VL_SAMPLES BLOOMY_FOG VL_Clouds_Shadows fog_selfShadowing + + screen.Fog_Densities.columns=1 + screen.Fog_Densities = Haze_amount UniformFog_amount CloudyFog_amount TimeOfDayFog_multiplier RainFog_amount CaveFog_amount uniformfog_fade cloudyfog_fade + + screen.Fog_Color.columns=1 + screen.Fog_Color = fog_mieg1 fog_mieg2 fog_coefficientRayleighR fog_coefficientRayleighG fog_coefficientRayleighB fog_coefficientMieR fog_coefficientMieG fog_coefficientMieB + ### WATER + screen.Water.columns=1 + screen.Water = Refraction Vanilla_like_water Dirt_Amount Dirt_Mie_Phase rayMarchSampleCount SCREENSPACE_REFLECTIONS SSR_STEPS USE_QUARTER_RES_DEPTH SUN_MICROFACET_SPECULAR Water_Top_Layer lightMapDepthEstimation [Water_fog_color] + + screen.Water_fog_color.columns=1 + screen.Water_fog_color = 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 + +######## POST + screen.Post_Processing.columns=1 + screen.Post_Processing = [TAA_OPTIONS] [Purkinje_effect] [Tonemapping] [Exposure] [DepthOfField] SHARPENING BLOOM_STRENGTH BLOOM_QUALITY + ### TAA + screen.TAA_OPTIONS.columns = 1 + screen.TAA_OPTIONS= SCREENSHOT_MODE SPLIT_RENDER TAA BLEND_FACTOR TAA_UPSCALING RENDER_SCALE_X RENDER_SCALE_Y + ### DOF + screen.DepthOfField.columns = 1 + screen.DepthOfField = DOF HEXAGONAL_BOKEH AUTOFOCUS focal aperture MANUAL_FOCUS DoF_Adaptation_Speed FAR_BLUR_ONLY + ### EXPOSURE + screen.Exposure.columns = 1 + screen.Exposure = AUTO_EXPOSURE EXPOSURE_MULTIPLIER Exposure_Speed Manual_exposure_value + ### TONEMAPS + screen.Tonemapping.columns = 1 + screen.Tonemapping = TONEMAP USE_ACES_COLORSPACE_APPROXIMATION SATURATION CROSSTALK FinalR FinalG FinalB + ### PURKINJE + screen.Purkinje_effect.columns = 1 + screen.Purkinje_effect = Purkinje_strength Purkinje_strength Purkinje_R Purkinje_G Purkinje_B Purkinje_Multiplier + +######## MISC SETTINGS + screen.Misc_Settings.columns=1 + screen.Misc_Settings =end_shadows WhiteWorld ambientLight_only Cloud_Size Cloud_Height BorderFog Texture_MipMap_Bias Glass_Tint display_LUT DISABLE_ALPHA_MIPMAPS + + screen.LabPBR.columns = 1 + screen.LabPBR = [Reflections] [Subsurface_Scattering] [Emissives] [POM] [Porosity] + + screen.Emissives.columns = 1 + screen.Emissives = LabPBR_Emissives Emissive_Brightness Emissive_Curve + + screen.Porosity.columns = 1 + screen.Porosity = Puddles Puddle_Size Porosity + + screen.Sun_and_Moon_Colors.columns = 1 + screen.Sun_and_Moon_Colors = sunColorR sunColorG sunColorB moonColorR moonColorG moonColorB colortype Sun_temp Moon_temp + + 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.cave_fog = Cave_fog CaveFogFallOff CaveFogColor_R CaveFogColor_G CaveFogColor_B + +######## moonphase based weather + +uniform.float.CumulusCoverage = smooth(1, if( \ + moonPhase == 0, 0.3, \ + moonPhase == 1, 0.8, \ + moonPhase == 2, 0.2, \ + moonPhase == 3, 0.0, \ + moonPhase == 4, 0.8, \ + moonPhase == 5, 0.5, \ + moonPhase == 6, -0.5, \ + 0.6 ), 60, 60) + +uniform.float.CirrusCoverage = smooth(2, if( \ + moonPhase == 0, 0.5, \ + moonPhase == 1, 0.65, \ + moonPhase == 2, 0.6, \ + moonPhase == 3, 0.0, \ + moonPhase == 4, 0.5, \ + moonPhase == 5, 0.5, \ + moonPhase == 6, 0.6, \ + 0.5 ), 60, 60) + +uniform.float.CirrusThickness = smooth(3, if( \ + moonPhase == 0, 0.05, \ + moonPhase == 1, 0.2, \ + moonPhase == 2, 0.2, \ + moonPhase == 3, 0.0, \ + moonPhase == 4, 0.0, \ + moonPhase == 5, 0.05, \ + moonPhase == 6, 0.2, \ + 0.1 ), 60, 60) + + + +uniform.float.Day = smooth(4, if( \ + moonPhase == 0, 1, \ + moonPhase == 1, 2, \ + moonPhase == 2, 3, \ + moonPhase == 3, 4, \ + moonPhase == 4, 5, \ + moonPhase == 5, 6, \ + moonPhase == 6, 7, \ + 8 ), 5, 5) + + +# Biome uniforms +uniform.float.isJungles = smooth(6, if(in(biome,23,24,25), 1,0), 25,25) +uniform.float.isSwamps = smooth(7, if(in(biome,6,7), 1,0), 25,25) + + +uniform.float.isLush = smooth(8, if(in(biome,10,50), 1,0), 25,25) +uniform.float.isDeserts = smooth(9, if(in(biome,5), 1,0), 25,25) + +uniform.float.isWastes = smooth(10, if(in(biome,51), 1,0), 5, 5) +uniform.float.isWarpedForest = smooth(11, if(in(biome,52), 1,0), 5, 5) +uniform.float.isCrimsonForest = smooth(12, if(in(biome,53), 1,0), 5, 5) +uniform.float.isSoulValley = smooth(13, if(in(biome,54), 1,0), 5, 5) +uniform.float.isBasaltDelta = smooth(14, if(in(biome,55), 1,0), 5, 5) + +# uniform.float.Winter = smooth(14, if( worldDay > 0 && worldDay < 10), 5, 5) + + +# thank you sixthsurge! +uniform.float.lightningFlash = smooth(if(equals(skyColor.r, skyColor.g, 0.01) && skyColor.r > 0.3, 1.0, 0.0), 0, 0.5) + +texture.noise=texture/noises.png +texture.composite.colortex6=texture/blueNoise.png +separateAo=true +alphaTest.shadow= GREATER 0.1 +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) diff --git a/shaders/shadow.fsh b/shaders/shadow.fsh new file mode 100644 index 0000000..1d0c7a2 --- /dev/null +++ b/shaders/shadow.fsh @@ -0,0 +1,30 @@ +#version 120 +#extension GL_ARB_shader_texture_lod : enable +#extension GL_EXT_gpu_shader4 : enable +#define SHADOW_DISABLE_ALPHA_MIPMAPS // Disables mipmaps on the transparency of alpha-tested things like foliage, may cost a few fps in some cases +#define Stochastic_Transparent_Shadows // Highly recommanded to enable SHADOW_DISABLE_ALPHA_MIPMAPS with it. Uses noise to simulate transparent objects' shadows (not colored). It is also recommended to increase Min_Shadow_Filter_Radius with this. +varying vec2 texcoord; +uniform sampler2D tex; +uniform sampler2D noisetex; +uniform int frameCounter; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +// float blueNoise(){ +// return texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a; +// } +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 ) ; +} +void main() { + gl_FragData[0] = texture2D(tex,texcoord.xy); + #ifdef SHADOW_DISABLE_ALPHA_MIPMAPS + gl_FragData[0].a = texture2DLod(tex,texcoord.xy,0).a; + #endif + #ifdef Stochastic_Transparent_Shadows + gl_FragData[0].a = float(gl_FragData[0].a >= R2_dither()); + #endif +} diff --git a/shaders/shadow.vsh b/shaders/shadow.vsh new file mode 100644 index 0000000..403a3cb --- /dev/null +++ b/shaders/shadow.vsh @@ -0,0 +1,138 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +/* +!! DO NOT REMOVE !! +This code is from Chocapic13' shaders +Read the terms of modification and sharing before changing something below please ! +!! DO NOT REMOVE !! +*/ +//#define SHADOW_FRUSTRUM_CULLING // BROKEN IN 1.17+. If enabled, removes most of the blocks during shadow rendering that would not cast shadows on the player field of view. Improves performance but can be sometimes incorrect and causes flickering shadows on distant occluders +#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] +#include "lib/Shadow_Params.glsl" + +#define SHADOW_MAP_BIAS 0.5 +const float PI = 3.1415927; +varying vec2 texcoord; +uniform mat4 shadowProjectionInverse; +uniform mat4 shadowProjection; +uniform mat4 shadowModelViewInverse; +uniform mat4 shadowModelView; +uniform mat4 gbufferModelView; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferProjection; +uniform vec3 cameraPosition; +uniform float frameTimeCounter; +uniform vec3 sunVec; +uniform float aspectRatio; +uniform float sunElevation; +uniform float lightSign; +uniform float cosFov; +uniform vec3 shadowViewDir; +uniform vec3 shadowCamera; +uniform vec3 shadowLightVec; +uniform float shadowMaxProj; +attribute vec4 mc_Entity; +attribute vec4 mc_midTexCoord; +varying vec4 glcolor; + +const float PI48 = 150.796447372*WAVY_SPEED; +float pi2wt = PI48*frameTimeCounter; + +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/255.0; +} + +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/255.; +} +bool intersectCone(float coneHalfAngle, vec3 coneTip , vec3 coneAxis, vec3 rayOrig, vec3 rayDir, float maxZ) +{ + vec3 co = rayOrig - coneTip; + float prod = dot(normalize(co),coneAxis); + if (prod <= -coneHalfAngle) return true; //In view frustrum + + float a = dot(rayDir,coneAxis)*dot(rayDir,coneAxis) - coneHalfAngle*coneHalfAngle; + float b = 2. * (dot(rayDir,coneAxis)*dot(co,coneAxis) - dot(rayDir,co)*coneHalfAngle*coneHalfAngle); + float c = dot(co,coneAxis)*dot(co,coneAxis) - dot(co,co)*coneHalfAngle*coneHalfAngle; + + float det = b*b - 4.*a*c; + if (det < 0.) return false; // No intersection with either forward cone and backward cone + + det = sqrt(det); + float t2 = (-b + det) / (2. * a); + if (t2 <= 0.0 || t2 >= maxZ) return false; //Idk why it works + + return true; +} +#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),1.0); +} +void main() { + + + vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz; + + + //Check if the vertice is going to cast shadows + // #ifdef SHADOW_FRUSTRUM_CULLING + // if (intersectCone(cosFov, shadowCamera, shadowViewDir, position, -shadowLightVec, shadowMaxProj)) { + // #endif + // #ifdef WAVY_PLANTS + // bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t; + // if ((mc_Entity.x == 10001&&istopv) && length(position.xy) < 24.0) { + // vec3 worldpos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; + // worldpos.xyz += calcMovePlants(worldpos.xyz + cameraPosition)*gl_MultiTexCoord1.y; + // position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz ; + // } + + // if ((mc_Entity.x == 10003) && length(position.xy) < 24.0) { + // vec3 worldpos = mat3(shadowModelViewInverse) * position + shadowModelViewInverse[3].xyz; + // worldpos.xyz += calcMoveLeaves(worldpos.xyz + cameraPosition, 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))*gl_MultiTexCoord1.y; + // position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz ; + // } + // #endif + + + + // gl_Position = BiasShadowProjection_altered(toClipSpace3(position),mat3(shadowProjection),mat3(shadowModelView), gl_NormalMatrix * gl_Normal); + + gl_Position = BiasShadowProjection(toClipSpace3(position)); + + gl_Position.z /= 6.0; + + + texcoord.xy = gl_MultiTexCoord0.xy; + + + if(mc_Entity.x == 8 || mc_Entity.x == 9) gl_Position.w = -1.0; + + + #ifdef SHADOW_FRUSTRUM_CULLING + } + else + gl_Position.xyzw = vec4(0.0,0.0,1e30,0.0); //Degenerates the triangle + #endif +} diff --git a/shaders/texture/blueNoise.png b/shaders/texture/blueNoise.png new file mode 100644 index 0000000..87bd792 Binary files /dev/null and b/shaders/texture/blueNoise.png differ diff --git a/shaders/texture/blueNoise.png.mcmeta b/shaders/texture/blueNoise.png.mcmeta new file mode 100644 index 0000000..33f3199 --- /dev/null +++ b/shaders/texture/blueNoise.png.mcmeta @@ -0,0 +1,7 @@ +{ + "texture": + { + "blur": true, + "clamp": false + } +} \ No newline at end of file diff --git a/shaders/texture/noises.png b/shaders/texture/noises.png new file mode 100644 index 0000000..6236ff1 Binary files /dev/null and b/shaders/texture/noises.png differ diff --git a/shaders/texture/noises.png.mcmeta b/shaders/texture/noises.png.mcmeta new file mode 100644 index 0000000..33f3199 --- /dev/null +++ b/shaders/texture/noises.png.mcmeta @@ -0,0 +1,7 @@ +{ + "texture": + { + "blur": true, + "clamp": false + } +} \ No newline at end of file diff --git a/shaders/world-1/block.properties b/shaders/world-1/block.properties new file mode 100644 index 0000000..73045f4 --- /dev/null +++ b/shaders/world-1/block.properties @@ -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 diff --git a/shaders/world-1/composite10.fsh b/shaders/world-1/composite10.fsh new file mode 100644 index 0000000..25c81c0 --- /dev/null +++ b/shaders/world-1/composite10.fsh @@ -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.); + + + +} diff --git a/shaders/world-1/composite10.vsh b/shaders/world-1/composite10.vsh new file mode 100644 index 0000000..8d47d5c --- /dev/null +++ b/shaders/world-1/composite10.vsh @@ -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; +} diff --git a/shaders/world-1/composite11.fsh b/shaders/world-1/composite11.fsh new file mode 100644 index 0000000..1320222 --- /dev/null +++ b/shaders/world-1/composite11.fsh @@ -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 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.); +} diff --git a/shaders/world-1/composite11.vsh b/shaders/world-1/composite11.vsh new file mode 100644 index 0000000..b299614 --- /dev/null +++ b/shaders/world-1/composite11.vsh @@ -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.); +} diff --git a/shaders/world-1/composite12.fsh b/shaders/world-1/composite12.fsh new file mode 100644 index 0000000..dd63b74 --- /dev/null +++ b/shaders/world-1/composite12.fsh @@ -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 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.); +} diff --git a/shaders/world-1/composite12.vsh b/shaders/world-1/composite12.vsh new file mode 100644 index 0000000..56683b4 --- /dev/null +++ b/shaders/world-1/composite12.vsh @@ -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.); + +} diff --git a/shaders/world-1/composite14.fsh b/shaders/world-1/composite14.fsh new file mode 100644 index 0000000..6bfa802 --- /dev/null +++ b/shaders/world-1/composite14.fsh @@ -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.); +} diff --git a/shaders/world-1/composite14.vsh b/shaders/world-1/composite14.vsh new file mode 100644 index 0000000..386f006 --- /dev/null +++ b/shaders/world-1/composite14.vsh @@ -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; +} diff --git a/shaders/world-1/composite15.fsh b/shaders/world-1/composite15.fsh new file mode 100644 index 0000000..74136a6 --- /dev/null +++ b/shaders/world-1/composite15.fsh @@ -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); + +} diff --git a/shaders/world-1/composite15.vsh b/shaders/world-1/composite15.vsh new file mode 100644 index 0000000..5099bbb --- /dev/null +++ b/shaders/world-1/composite15.vsh @@ -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; +} diff --git a/shaders/world-1/composite2.fsh b/shaders/world-1/composite2.fsh new file mode 100644 index 0000000..5e1f176 --- /dev/null +++ b/shaders/world-1/composite2.fsh @@ -0,0 +1,433 @@ +#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 HQ_SSGI + +//////////// 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 n_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 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 ; +} + +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); +} +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; +} + + +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; +} + +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 z = texture2D(depthtex1,texcoord).x; + vec2 tempOffset=TAA_Offset; + + 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; + + vec3 lightSource = normalize(vec3(0.0, -1.0,0.0)); + vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource; + + vec3 WsunVec = normalize(mat3(gbufferModelViewInverse) * viewspace_sunvec); + float LightDir = max(dot(normal, WsunVec),0.0); + + + vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.)); + + #ifdef WhiteWorld + albedo = vec3(1.0); + #endif + +////// ----- 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 = ((ambientUp + ambientDown + ambientRight + ambientLeft + ambientB + ambientF) ) * (abs(ambientCoefs.y * 0.5) + 0.5) ; + + + 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.3; + + //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)), lightmap.x) ; + #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; + +////// ----- finalize ----- ////// + + gl_FragData[0].rgb = Indirect_lighting * albedo ; + + #ifdef LabPBR_Emissives + gl_FragData[0].rgb = SpecularTex.a < 255.0/255.0 ? mix(gl_FragData[0].rgb, albedo * Emissive_Brightness*0.5 , 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, vec3(0), 0.0 , lightmap.y, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,blueNoise()), hand); + #endif + +/* DRAWBUFFERS:3 */ +} diff --git a/shaders/world-1/composite2.vsh b/shaders/world-1/composite2.vsh new file mode 100644 index 0000000..b1cf351 --- /dev/null +++ b/shaders/world-1/composite2.vsh @@ -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); + + +} diff --git a/shaders/world-1/composite5.fsh b/shaders/world-1/composite5.fsh new file mode 100644 index 0000000..5444e90 --- /dev/null +++ b/shaders/world-1/composite5.fsh @@ -0,0 +1,271 @@ +#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" +#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 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; +} +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 densityAtPos(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./32.,1.0)*5.0+frameTimeCounter*vec3(0.5,0.,0.5)*1.; +// float noise = densityAtPos(samplePos*12.); +// float unifCov = exp2(-max(pos.y-SEA_LEVEL,0.0)/50.); + +// float cloud = pow(clamp(1.0-noise-0.76,0.0,1.0),2.)+0.005; + +// return cloud; +// } + +float cloudVol(in vec3 pos){ + + // float[4] BiomeParams = float[4]( + // /*[0] Cloudy amount */ isWastes*5 + isWarpedForest*0 + isCrimsonForest*0 + isSoulValley + isBasaltDelta*2 + // /*[1] uniform amount*/ ,isWastes*0 + isWarpedForest*0.005 + isCrimsonForest*0.005 + isSoulValley*0.5 + isBasaltDelta*0 + // /*[2] uniform height*/ ,isWastes*3 + isWarpedForest*100 + isCrimsonForest*100 + isSoulValley*2 + isBasaltDelta + // /*[3] cloudy height*/ ,isWastes*20 + isWarpedForest + isCrimsonForest + isSoulValley*100 + isBasaltDelta*100 + // ); + + // cloudy fog shapes + vec3 samplePos = pos*vec3(1.0,1./48.,1.0); + + samplePos.x += frameTimeCounter*2.0; + float cloudy_fog_erosion = densityAtPos(samplePos * 200.0); + + samplePos += cloudy_fog_erosion; + + samplePos.y -= frameTimeCounter*0.2; + float main_cloudy_fog = densityAtPos(samplePos * 50.0); + + float final = main_cloudy_fog/100.0; + return final; +} + +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),far)/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; + ambientLight += ambientDown; + ambientLight += ambientRight; + ambientLight += ambientLeft; + ambientLight += ambientB; + ambientLight += ambientF; + + vec3 skyCol0 = ambientLight*8.*2./150./3.*Ambient_Mult*3.1415; + + float mu = 1.0; + float muS = 1.05; + vec3 absorbance = vec3(1.0); + float expFactor = 11.0; + + vec3 fogColor = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.05; + + // float testcolor = clamp(exp2(-max(progressW.y-25,0.0)/5) ,0,1); + // fogColor = mix(fogColor, vec3(0,1,0), testcolor); + + for (int i=0;i 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; + + //cave fog + if (isEyeInWater == 0){ + vec3 fogColor = clamp(gl_Fog.color.rgb,0.0,1.0) * 8. * (1.0-vl.a); + + float fogdistfade = clamp(length(fragpos)/far, 0.0, 1.0); + + float fogfade = clamp(exp((1.0 - np3.y)*4 - 8),0.0,1.0); + + // float fog = 1.0 - clamp( exp2(-pow(length(fragpos / far),10.)*4.0) ,0.0,1.0); + + float fog = clamp( pow(length(fragpos / far),0.5) ,0.0,1.0); + + color.rgb = mix(color.rgb, fogColor * fogfade , fog ) ; + vl.a *= 1.0 - fogdistfade; + } + // 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 ; + + gl_FragData[0] = vec4(vl.a, 0.0, 0.0, 0.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 +} diff --git a/shaders/world-1/composite6.vsh b/shaders/world-1/composite6.vsh new file mode 100644 index 0000000..05cecb7 --- /dev/null +++ b/shaders/world-1/composite6.vsh @@ -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; + +} diff --git a/shaders/world-1/composite8.fsh b/shaders/world-1/composite8.fsh new file mode 100644 index 0000000..dd85629 --- /dev/null +++ b/shaders/world-1/composite8.fsh @@ -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 + + + + + +} diff --git a/shaders/world-1/composite8.vsh b/shaders/world-1/composite8.vsh new file mode 100644 index 0000000..24ef8ce --- /dev/null +++ b/shaders/world-1/composite8.vsh @@ -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; +} diff --git a/shaders/world-1/composite9.fsh b/shaders/world-1/composite9.fsh new file mode 100644 index 0000000..517bfe5 --- /dev/null +++ b/shaders/world-1/composite9.fsh @@ -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); + + +} diff --git a/shaders/world-1/composite9.vsh b/shaders/world-1/composite9.vsh new file mode 100644 index 0000000..386f006 --- /dev/null +++ b/shaders/world-1/composite9.vsh @@ -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; +} diff --git a/shaders/world-1/deferred.fsh b/shaders/world-1/deferred.fsh new file mode 100644 index 0000000..5745d9d --- /dev/null +++ b/shaders/world-1/deferred.fsh @@ -0,0 +1,141 @@ +#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); +float minLight = MIN_LIGHT_AMOUNT * 0.007/ (exposure + rodExposure/(rodExposure+1.0)*exposure*1.); +vec3 minLight_col = MIN_LIGHT_AMOUNT * 0.007/ (exposure + rodExposure/(rodExposure+1.0)*exposure*1.) * vec3(0.8,0.9,1.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/17.212/17.212,0.0); + torch_lightmap = pow(torch_lightmap*2.5,1.5)*TORCH_AMOUNT*10.; + float sky_lightmap = (Slightmap[int(gl_FragCoord.y)]-14.0)/235.; + sky_lightmap = pow(sky_lightmap,1.4); + vec3 ambient = avgAmbient*sky_lightmap+torch_lightmap*vec3(TORCH_R,TORCH_G,TORCH_B)*TORCH_AMOUNT; + + 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/17.212/17.212,0.0); + float ambient = pow(torch_lightmap*2.5,1.5)*TORCH_AMOUNT*10.; + float sky_lightmap = (Slightmap[int(gl_FragCoord.y-19.0)]-14.0)/235./150.; + + gl_FragData[0] = vec4(sky_lightmap,ambient,minLight,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); + +} diff --git a/shaders/world-1/deferred.vsh b/shaders/world-1/deferred.vsh new file mode 100644 index 0000000..2c5b20a --- /dev/null +++ b/shaders/world-1/deferred.vsh @@ -0,0 +1,206 @@ +#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 = vec3(0.0,1.0,0.0); + + + +#include "lib/sky_gradient.glsl" +#include "/lib/util.glsl" +#include "/lib/ROBOBO_sky.glsl" +vec3 rodSample(vec2 Xi) +{ + float r = sqrt(1.0f - Xi.x*Xi.y); + float phi = 2 * 3.14159265359 * Xi.y; + + return normalize(vec3(cos(phi) * r, sin(phi) * r, Xi.x)).xzy; +} +vec3 cosineHemisphereSample(vec2 Xi) +{ + float r = sqrt(Xi.x); + float theta = 2.0 * 3.14159265359 * Xi.y; + + float x = r * cos(theta); + float y = r * sin(theta); + + return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); +} + +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} +vec3 toLinear(vec3 sRGB){ + return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); +} + + +vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter) +{ + float alpha = float(sampleNumber+jitter)/nb; + float angle = (jitter+alpha) * (nbRot * 6.28); + + float ssR = alpha; + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + + return vec2(cos_v, sin_v)*ssR; +} +//Low discrepancy 2D sequence, integration error is as low as sobol but easier to compute : http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ +vec2 R2_samples(int n){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return fract(alpha * n); +} +void main() { + + gl_Position = ftransform()*0.5+0.5; + gl_Position.xy = gl_Position.xy*vec2(18.+258*2,258.)*texelSize; + gl_Position.xy = gl_Position.xy*2.-1.0; + + tempOffsets = R2_samples(frameCounter%10000); + + ambientUp = vec3(0.0); + ambientDown = vec3(0.0); + ambientLeft = vec3(0.0); + ambientRight = vec3(0.0); + ambientB = vec3(0.0); + ambientF = vec3(0.0); + avgSky = vec3(0.0); + + + + //Fake bounced sunlight + vec3 bouncedSun = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)/4000.*0.08; + ambientUp += bouncedSun*clamp(-sunVec.y+5.,0.,6.0); + ambientLeft += bouncedSun*clamp(sunVec.x+5.,0.0,6.); + ambientRight += bouncedSun*clamp(-sunVec.x+5.,0.0,6.); + ambientB += bouncedSun*clamp(-sunVec.z+5.,0.0,6.); + ambientF += bouncedSun*clamp(sunVec.z+5.,0.0,6.); + ambientDown += bouncedSun*clamp(sunVec.y+5.,0.0,6.); + + + float avgLuma = 0.0; + float m2 = 0.0; + int n=100; + vec2 clampedRes = max(1.0/texelSize,vec2(1920.0,1080.)); + float avgExp = 0.0; + vec2 resScale = vec2(1920.,1080.)/clampedRes; + float v[25]; + float temp; + // 5x5 Median filter by morgan mcguire + // We take the median value of the most blurred bloom buffer + #define s2(a, b) temp = a; a = min(a, b); b = max(temp, b); + #define t2(a, b) s2(v[a], v[b]); + #define t24(a, b, c, d, e, f, g, h) t2(a, b); t2(c, d); t2(e, f); t2(g, h); + #define t25(a, b, c, d, e, f, g, h, i, j) t24(a, b, c, d, e, f, g, h); t2(i, j); + for (int i = 0; i < 5; i++){ + for (int j = 0; j < 5; j++){ + vec2 tc = 0.5 + vec2(i-2,j-2)/2.0 * 0.35; + v[i+j*5] = luma(texture2D(colortex6,tc/128. * resScale+vec2(0.484375*resScale.x+10.5*texelSize.x,.0)).rgb); + } + } + t25(0, 1, 3, 4, 2, 4, 2, 3, 6, 7); + t25(5, 7, 5, 6, 9, 7, 1, 7, 1, 4); + t25(12, 13, 11, 13, 11, 12, 15, 16, 14, 16); + t25(14, 15, 18, 19, 17, 19, 17, 18, 21, 22); + t25(20, 22, 20, 21, 23, 24, 2, 5, 3, 6); + t25(0, 6, 0, 3, 4, 7, 1, 7, 1, 4); + t25(11, 14, 8, 14, 8, 11, 12, 15, 9, 15); + t25(9, 12, 13, 16, 10, 16, 10, 13, 20, 23); + t25(17, 23, 17, 20, 21, 24, 18, 24, 18, 21); + t25(19, 22, 8, 17, 9, 18, 0, 18, 0, 9); + t25(10, 19, 1, 19, 1, 10, 11, 20, 2, 20); + t25(2, 11, 12, 21, 3, 21, 3, 12, 13, 22); + t25(4, 22, 4, 13, 14, 23, 5, 23, 5, 14); + t25(15, 24, 6, 24, 6, 15, 7, 16, 7, 19); + t25(3, 11, 5, 17, 11, 17, 9, 17, 4, 10); + t25(6, 12, 7, 14, 4, 6, 4, 7, 12, 14); + t25(10, 14, 6, 7, 10, 12, 6, 10, 6, 17); + t25(12, 17, 7, 17, 7, 10, 12, 18, 7, 12); + t24(10, 18, 12, 20, 10, 20, 10, 12); + avgExp = v[12]; // Median value + + + avgBrightness = clamp(mix(avgExp,texelFetch2D(colortex4,ivec2(10,37),0).g,0.95),0.00003051757,65000.0); + + float currentExposure = texelFetch2D(colortex4,ivec2(10,37),0).b; + float L = max(avgBrightness,1e-8); + float keyVal = 1.03-2.0/(log(L+1.0)/log(10.0)+2.0); + float targetExposure = 1.0*keyVal/L; + + float targetrodExposure = clamp(log(targetExposure*2.0+1.0)-0.1,0.0,2.0); + float currentrodExposure = texelFetch2D(colortex4,ivec2(14,37),0).r; + + targetExposure = clamp(targetExposure,2.0,3.0); + float rad = sqrt(currentExposure); + float rtarget = sqrt(targetExposure); + float dir = sign(rtarget-rad); + float dist = abs(rtarget-rad); + float maxApertureChange = 0.0032*frameTime/0.016666*(Exposure_Speed*2) * 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*2) * 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.))); +} diff --git a/shaders/world-1/final.fsh b/shaders/world-1/final.fsh new file mode 100644 index 0000000..2388d11 --- /dev/null +++ b/shaders/world-1/final.fsh @@ -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); +} diff --git a/shaders/world-1/final.vsh b/shaders/world-1/final.vsh new file mode 100644 index 0000000..7aeb51b --- /dev/null +++ b/shaders/world-1/final.vsh @@ -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); +} diff --git a/shaders/world-1/gbuffers_all_solid.fsh b/shaders/world-1/gbuffers_all_solid.fsh new file mode 100644 index 0000000..76e3e6c --- /dev/null +++ b/shaders/world-1/gbuffers_all_solid.fsh @@ -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)) ; + + + +} \ No newline at end of file diff --git a/shaders/world-1/gbuffers_all_solid.vsh b/shaders/world-1/gbuffers_all_solid.vsh new file mode 100644 index 0000000..aba1be6 --- /dev/null +++ b/shaders/world-1/gbuffers_all_solid.vsh @@ -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.zw *= sqrt(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 +} diff --git a/shaders/world-1/gbuffers_all_translucent.fsh b/shaders/world-1/gbuffers_all_translucent.fsh new file mode 100644 index 0000000..d89e204 --- /dev/null +++ b/shaders/world-1/gbuffers_all_translucent.fsh @@ -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.); + + } +} diff --git a/shaders/world-1/gbuffers_all_translucent.vsh b/shaders/world-1/gbuffers_all_translucent.vsh new file mode 100644 index 0000000..13986e0 --- /dev/null +++ b/shaders/world-1/gbuffers_all_translucent.vsh @@ -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); +} diff --git a/shaders/world-1/gbuffers_armor_glint.fsh b/shaders/world-1/gbuffers_armor_glint.fsh new file mode 100644 index 0000000..c931e5f --- /dev/null +++ b/shaders/world-1/gbuffers_armor_glint.fsh @@ -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; + + + +} diff --git a/shaders/world-1/gbuffers_armor_glint.vsh b/shaders/world-1/gbuffers_armor_glint.vsh new file mode 100644 index 0000000..40823aa --- /dev/null +++ b/shaders/world-1/gbuffers_armor_glint.vsh @@ -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 +} \ No newline at end of file diff --git a/shaders/world-1/gbuffers_basic.fsh b/shaders/world-1/gbuffers_basic.fsh new file mode 100644 index 0000000..97072f6 --- /dev/null +++ b/shaders/world-1/gbuffers_basic.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_basic.vsh b/shaders/world-1/gbuffers_basic.vsh new file mode 100644 index 0000000..5078151 --- /dev/null +++ b/shaders/world-1/gbuffers_basic.vsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_beaconbeam.fsh b/shaders/world-1/gbuffers_beaconbeam.fsh new file mode 100644 index 0000000..f4e7cfb --- /dev/null +++ b/shaders/world-1/gbuffers_beaconbeam.fsh @@ -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; + + + + +} diff --git a/shaders/world-1/gbuffers_beaconbeam.vsh b/shaders/world-1/gbuffers_beaconbeam.vsh new file mode 100644 index 0000000..704f4ea --- /dev/null +++ b/shaders/world-1/gbuffers_beaconbeam.vsh @@ -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 +} \ No newline at end of file diff --git a/shaders/world-1/gbuffers_block.fsh b/shaders/world-1/gbuffers_block.fsh new file mode 100644 index 0000000..95943b4 --- /dev/null +++ b/shaders/world-1/gbuffers_block.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define BLOCK_ENT +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_block.vsh b/shaders/world-1/gbuffers_block.vsh new file mode 100644 index 0000000..9974256 --- /dev/null +++ b/shaders/world-1/gbuffers_block.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define BLOCK_ENT +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_clouds.fsh b/shaders/world-1/gbuffers_clouds.fsh new file mode 100644 index 0000000..563a191 --- /dev/null +++ b/shaders/world-1/gbuffers_clouds.fsh @@ -0,0 +1,9 @@ +#version 120 + +/* DRAWBUFFERS:3 */ + + + +void main() { + +} diff --git a/shaders/world-1/gbuffers_clouds.vsh b/shaders/world-1/gbuffers_clouds.vsh new file mode 100644 index 0000000..90c4b9e --- /dev/null +++ b/shaders/world-1/gbuffers_clouds.vsh @@ -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; +} diff --git a/shaders/world-1/gbuffers_damagedblock.fsh b/shaders/world-1/gbuffers_damagedblock.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world-1/gbuffers_damagedblock.fsh @@ -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; + } + + + +} diff --git a/shaders/world-1/gbuffers_damagedblock.vsh b/shaders/world-1/gbuffers_damagedblock.vsh new file mode 100644 index 0000000..4ced627 --- /dev/null +++ b/shaders/world-1/gbuffers_damagedblock.vsh @@ -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 +} diff --git a/shaders/world-1/gbuffers_entities.fsh b/shaders/world-1/gbuffers_entities.fsh new file mode 100644 index 0000000..0cd3e0d --- /dev/null +++ b/shaders/world-1/gbuffers_entities.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define ENTITIES +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_entities.vsh b/shaders/world-1/gbuffers_entities.vsh new file mode 100644 index 0000000..f4f07a4 --- /dev/null +++ b/shaders/world-1/gbuffers_entities.vsh @@ -0,0 +1,6 @@ +#version 120 + + +// #define WORLD +#define ENTITIES +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand.fsh b/shaders/world-1/gbuffers_hand.fsh new file mode 100644 index 0000000..21ac244 --- /dev/null +++ b/shaders/world-1/gbuffers_hand.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define HAND +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand.vsh b/shaders/world-1/gbuffers_hand.vsh new file mode 100644 index 0000000..39504ed --- /dev/null +++ b/shaders/world-1/gbuffers_hand.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define HAND +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand_water.fsh b/shaders/world-1/gbuffers_hand_water.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world-1/gbuffers_hand_water.fsh @@ -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; + } + + + +} diff --git a/shaders/world-1/gbuffers_hand_water.vsh b/shaders/world-1/gbuffers_hand_water.vsh new file mode 100644 index 0000000..68dc1b7 --- /dev/null +++ b/shaders/world-1/gbuffers_hand_water.vsh @@ -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 +} diff --git a/shaders/world-1/gbuffers_skybasic.fsh b/shaders/world-1/gbuffers_skybasic.fsh new file mode 100644 index 0000000..563a191 --- /dev/null +++ b/shaders/world-1/gbuffers_skybasic.fsh @@ -0,0 +1,9 @@ +#version 120 + +/* DRAWBUFFERS:3 */ + + + +void main() { + +} diff --git a/shaders/world-1/gbuffers_skybasic.vsh b/shaders/world-1/gbuffers_skybasic.vsh new file mode 100644 index 0000000..90c4b9e --- /dev/null +++ b/shaders/world-1/gbuffers_skybasic.vsh @@ -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; +} diff --git a/shaders/world-1/gbuffers_skytextured.fsh b/shaders/world-1/gbuffers_skytextured.fsh new file mode 100644 index 0000000..8ad1592 --- /dev/null +++ b/shaders/world-1/gbuffers_skytextured.fsh @@ -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; +} diff --git a/shaders/world-1/gbuffers_skytextured.vsh b/shaders/world-1/gbuffers_skytextured.vsh new file mode 100644 index 0000000..2c401c5 --- /dev/null +++ b/shaders/world-1/gbuffers_skytextured.vsh @@ -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 +} + diff --git a/shaders/world-1/gbuffers_spidereyes.fsh b/shaders/world-1/gbuffers_spidereyes.fsh new file mode 100644 index 0000000..aa3de8b --- /dev/null +++ b/shaders/world-1/gbuffers_spidereyes.fsh @@ -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; + +} diff --git a/shaders/world-1/gbuffers_spidereyes.vsh b/shaders/world-1/gbuffers_spidereyes.vsh new file mode 100644 index 0000000..cdc23a4 --- /dev/null +++ b/shaders/world-1/gbuffers_spidereyes.vsh @@ -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 + +} \ No newline at end of file diff --git a/shaders/world-1/gbuffers_terrain.fsh b/shaders/world-1/gbuffers_terrain.fsh new file mode 100644 index 0000000..97072f6 --- /dev/null +++ b/shaders/world-1/gbuffers_terrain.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_terrain.vsh b/shaders/world-1/gbuffers_terrain.vsh new file mode 100644 index 0000000..5078151 --- /dev/null +++ b/shaders/world-1/gbuffers_terrain.vsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured.fsh b/shaders/world-1/gbuffers_textured.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world-1/gbuffers_textured.fsh @@ -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; + } + + + +} diff --git a/shaders/world-1/gbuffers_textured.vsh b/shaders/world-1/gbuffers_textured.vsh new file mode 100644 index 0000000..51f3fd7 --- /dev/null +++ b/shaders/world-1/gbuffers_textured.vsh @@ -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 +} diff --git a/shaders/world-1/gbuffers_textured_lit.fsh b/shaders/world-1/gbuffers_textured_lit.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world-1/gbuffers_textured_lit.fsh @@ -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; + } + + + +} diff --git a/shaders/world-1/gbuffers_textured_lit.vsh b/shaders/world-1/gbuffers_textured_lit.vsh new file mode 100644 index 0000000..68dc1b7 --- /dev/null +++ b/shaders/world-1/gbuffers_textured_lit.vsh @@ -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 +} diff --git a/shaders/world-1/gbuffers_water.fsh b/shaders/world-1/gbuffers_water.fsh new file mode 100644 index 0000000..5d6f344 --- /dev/null +++ b/shaders/world-1/gbuffers_water.fsh @@ -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); + +} diff --git a/shaders/world-1/gbuffers_water.vsh b/shaders/world-1/gbuffers_water.vsh new file mode 100644 index 0000000..ec64b46 --- /dev/null +++ b/shaders/world-1/gbuffers_water.vsh @@ -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 + +} diff --git a/shaders/world-1/gbuffers_weather.fsh b/shaders/world-1/gbuffers_weather.fsh new file mode 100644 index 0000000..f169e8b --- /dev/null +++ b/shaders/world-1/gbuffers_weather.fsh @@ -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; + + + +} diff --git a/shaders/world-1/gbuffers_weather.vsh b/shaders/world-1/gbuffers_weather.vsh new file mode 100644 index 0000000..b7c44aa --- /dev/null +++ b/shaders/world-1/gbuffers_weather.vsh @@ -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 +} \ No newline at end of file diff --git a/shaders/world-1/lib/ACES.glsl b/shaders/world-1/lib/ACES.glsl new file mode 100644 index 0000000..d9d6ce7 --- /dev/null +++ b/shaders/world-1/lib/ACES.glsl @@ -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) + ); +} diff --git a/shaders/world-1/lib/ACESSPL.glsl b/shaders/world-1/lib/ACESSPL.glsl new file mode 100644 index 0000000..81c4ffd --- /dev/null +++ b/shaders/world-1/lib/ACESSPL.glsl @@ -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); +} \ No newline at end of file diff --git a/shaders/world-1/lib/ACEST.glsl b/shaders/world-1/lib/ACEST.glsl new file mode 100644 index 0000000..f8693d7 --- /dev/null +++ b/shaders/world-1/lib/ACEST.glsl @@ -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; \ No newline at end of file diff --git a/shaders/world-1/lib/ROBOBO_sky.glsl b/shaders/world-1/lib/ROBOBO_sky.glsl new file mode 100644 index 0000000..ef8fcfd --- /dev/null +++ b/shaders/world-1/lib/ROBOBO_sky.glsl @@ -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; +} diff --git a/shaders/world-1/lib/Shadow_Params.glsl b/shaders/world-1/lib/Shadow_Params.glsl new file mode 100644 index 0000000..7556167 --- /dev/null +++ b/shaders/world-1/lib/Shadow_Params.glsl @@ -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); +} diff --git a/shaders/world-1/lib/clouds.glsl b/shaders/world-1/lib/clouds.glsl new file mode 100644 index 0000000..abd35ef --- /dev/null +++ b/shaders/world-1/lib/clouds.glsl @@ -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.))); + +} \ No newline at end of file diff --git a/shaders/world-1/lib/color_dither.glsl b/shaders/world-1/lib/color_dither.glsl new file mode 100644 index 0000000..73c4960 --- /dev/null +++ b/shaders/world-1/lib/color_dither.glsl @@ -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); +} \ No newline at end of file diff --git a/shaders/world-1/lib/color_transforms.glsl b/shaders/world-1/lib/color_transforms.glsl new file mode 100644 index 0000000..4813ff4 --- /dev/null +++ b/shaders/world-1/lib/color_transforms.glsl @@ -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); +} diff --git a/shaders/world-1/lib/composite3.fsh b/shaders/world-1/lib/composite3.fsh new file mode 100644 index 0000000..cb2a2ba --- /dev/null +++ b/shaders/world-1/lib/composite3.fsh @@ -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; +} diff --git a/shaders/world-1/lib/composite3.vsh b/shaders/world-1/lib/composite3.vsh new file mode 100644 index 0000000..05cecb7 --- /dev/null +++ b/shaders/world-1/lib/composite3.vsh @@ -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; + +} diff --git a/shaders/world-1/lib/projections.glsl b/shaders/world-1/lib/projections.glsl new file mode 100644 index 0000000..72ab381 --- /dev/null +++ b/shaders/world-1/lib/projections.glsl @@ -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; +} diff --git a/shaders/world-1/lib/sky_gradient.glsl b/shaders/world-1/lib/sky_gradient.glsl new file mode 100644 index 0000000..559faf3 --- /dev/null +++ b/shaders/world-1/lib/sky_gradient.glsl @@ -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); +} diff --git a/shaders/world-1/lib/specular.glsl b/shaders/world-1/lib/specular.glsl new file mode 100644 index 0000000..40a8df9 --- /dev/null +++ b/shaders/world-1/lib/specular.glsl @@ -0,0 +1,410 @@ +//#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 roughness, float U1, float U2){ + // stretch view + vec3 V = normalize(vec3(roughness * V_.x, roughness * 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*0.25); + float phi = (U2 -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 0.02; + +// vec4 Reflections = vec4(0.0); +// // SSR +// #ifdef Screen_Space_Reflections +// if ( hasReflections && NdotV < 0.00001) { // Skip SSR if ray contribution is low +// // float rayQuality = reflection_quality; +// float rayQuality = mix_float(reflection_quality,0.0,sqrt(roughness)); // Scale quality with ray contribution + +// 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 >= 230.0/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0); +// Reflections.rgb *= Metals; + +// // darken albedos, and stop darkening where the sky gets occluded indoors +// Reflections_Final *= 1.0 - Reflections.a*luma(rayContrib); + +// // apply all reflections to the lighting +// Reflections_Final += Reflections.rgb * luma(rayContrib); + +// #ifdef Rough_reflections +// Output = Reflections_Final; +// #else +// // interpolate between the albedos and reflections using the roughness value instead of the sampling. +// Output = mix_vec3(Reflections_Final, Output, sqrt(roughness)); +// #endif +// } + +// 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;} + + + // SSR, Sky, and Sun reflections + 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 +} \ No newline at end of file diff --git a/shaders/world-1/lib/stars.glsl b/shaders/world-1/lib/stars.glsl new file mode 100644 index 0000000..38d3cbf --- /dev/null +++ b/shaders/world-1/lib/stars.glsl @@ -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); +} diff --git a/shaders/world-1/lib/texFiltering.glsl b/shaders/world-1/lib/texFiltering.glsl new file mode 100644 index 0000000..7d58676 --- /dev/null +++ b/shaders/world-1/lib/texFiltering.glsl @@ -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; +} diff --git a/shaders/world-1/lib/util.glsl b/shaders/world-1/lib/util.glsl new file mode 100644 index 0000000..f701920 --- /dev/null +++ b/shaders/world-1/lib/util.glsl @@ -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; + } diff --git a/shaders/world-1/lib/volumetricClouds.glsl b/shaders/world-1/lib/volumetricClouds.glsl new file mode 100644 index 0000000..b5cc4e5 --- /dev/null +++ b/shaders/world-1/lib/volumetricClouds.glsl @@ -0,0 +1,282 @@ +#define VOLUMETRIC_CLOUDS + +float cloud_height = 1500.; +float maxHeight = 3200.; +#ifdef HQ_CLOUDS +int maxIT_clouds = 20; +int maxIT = 60; +#else +int maxIT_clouds = 9; +int maxIT = 27; +#endif + +float cdensity = 0.015; + + +//3D noise from 2d texture +float densityAtPos(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; + //The 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); +} +vec4 smoothfilter(in sampler2D tex, in vec2 uv) +{ + uv = uv*512.0 + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + uv = iuv + (fuv*fuv)*(3.0-2.0*fuv); + uv = uv/512.0 - 0.5/512.0; + return texture2D( tex, uv); +} +//Cloud without 3D noise, is used to exit early lighting calculations if there is no cloud +float cloudCov(in vec3 pos,vec3 samplePos){ + float mult = max(pos.y-2000.0,0.0)/2000.0; + float mult2 = max(-pos.y+2000.0,0.0)/500.0; + float coverage = clamp(texture2D(noisetex,samplePos.xz/12500.).r-0.2+0.4*rainStrength,0.0,1.0)/(1.0-0.2+0.4*rainStrength); + float cloud = coverage*coverage*4.0 - mult*mult*mult*3.0 - mult2*mult2; + return max(cloud, 0.0); +} +//Erode cloud with 3d Perlin-worley noise, actual cloud value +#ifdef HQ_CLOUDS + float cloudVol(in vec3 pos,in vec3 samplePos,in float cov){ + //Less erosion on bottom of the cloud + float mult2 = (pos.y-1500)/2500.0+rainStrength*0.4; + float noise = 1.0-densityAtPos(samplePos*15.); + noise += 0.5-densityAtPos(samplePos*30.)*0.5; + noise /= 1.5; + noise = noise*noise; + float cloud = clamp(cov-noise*noise*0.33*(0.2+mult2),0.0,1.0); + //float cloud = clamp(cov-0.1*(0.2+mult2),0.0,1.0); + return cloud; +} + //Low quality cloud, noise is replaced by the average noise value, used for shadowing + float cloudVolLQ(in vec3 pos){ + float mult = max(pos.y-2000.0,0.0)/2000.0; + float mult2 = max(-pos.y+2000.0,0.0)/500.0; + float mult3 = (pos.y-1500)/2500.0+rainStrength*0.4; + vec3 samplePos = pos*vec3(1.0,1./32.,1.0)/4+frameTimeCounter*vec3(0.5,0.,0.5)*25.; + float coverage = clamp(texture2D(noisetex,samplePos.xz/12500.).r-0.2+0.4*rainStrength,0.0,1.0)/(1.0-0.2+0.4*rainStrength); + float cloud = coverage*coverage*4.0 - mult*mult*mult*3.0 - mult2*mult2 - 0.11 * (0.2 + mult3); + return max(cloud, 0.0); + } +#else + float cloudVol(in vec3 pos,in vec3 samplePos,in float cov){ + float mult2 = (pos.y-1500)/2500.0+rainStrength*0.4; + float cloud = clamp(cov-0.11*(0.2+mult2),0.0,1.0); + return cloud; + + } + //Low quality cloud, noise is replaced by the average noise value, used for shadowing + float cloudVolLQ(in vec3 pos){ + float mult = max(pos.y-2000.0,0.0)/2000.0; + float mult2 = max(-pos.y+2000.0,0.0)/500.0; + float mult3 = (pos.y-1500)/2500.0+rainStrength*0.4; + vec3 samplePos = pos*vec3(1.0,1./32.,1.0)/4+frameTimeCounter*vec3(0.5,0.,0.5)*25.; + float coverage = clamp(texture2D(noisetex,samplePos.xz/12500.).r-0.2+0.4*rainStrength,0.0,1.0)/(1.0-0.2+0.4*rainStrength); + float cloud = coverage*coverage*4.0 - mult*mult*mult*3.0 - mult2*mult2 - 0.11 * (0.2 + mult3); + return max(cloud, 0.0); + } +#endif + + +//Mie phase function +float phaseg(float x, float g){ + float gg = g * g; + return (gg * -0.25 /3.14 + 0.25 /3.14) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5); +} + +float calcShadow(vec3 pos, vec3 ray){ + float shadowStep = length(ray); + float d = 0.0; + for (int j=1;j<6;j++){ + float cloudS=cloudVolLQ(vec3(pos+ray*j)); + d += cloudS*cdensity; + + } + return max(exp(-shadowStep*d),exp(-0.25*shadowStep*d)*0.7); +} +float cirrusClouds(vec3 pos){ + vec2 pos2D = pos.xz/50000.0 + frameTimeCounter/200.; + float cirrusMap = clamp(texture2D(noisetex,pos2D.yx/6. ).b-0.7+0.7*rainStrength,0.0,1.0); + float cloud = texture2D(noisetex, pos2D).r; + float weights = 1.0; + vec2 posMult = vec2(2.0,1.5); + for (int i = 1; i < 4; i++){ + pos2D *= posMult; + float weight =exp2(-i*1.0); + cloud += texture2D(noisetex, pos2D).r*weight; + + weights += weight; + } + cloud = clamp(cloud*cirrusMap*0.25,0.0,1.0); + return cloud/weights * float(abs(pos.y - 5500.0) < 200.0); +} + +vec4 renderClouds(vec3 fragpositi, vec3 color,float dither,vec3 sunColor,vec3 moonColor,vec3 avgAmbient) { + #ifndef VOLUMETRIC_CLOUDS + return vec4(0.0,0.0,0.0,1.0); + #endif + //setup ray in projected shadow map space + bool land = false; + + float SdotU = dot(normalize(fragpositi.xyz),sunVec); + float z2 = length(fragpositi); + float z = -fragpositi.z; + + + //project pixel position into projected shadowmap space + vec4 fragposition = gbufferModelViewInverse*vec4(fragpositi,1.0); + + vec3 worldV = normalize(fragposition.rgb); + float VdotU = worldV.y; + maxIT_clouds = int(clamp(maxIT_clouds/sqrt(VdotU),0.0,maxIT*1.0)); + //worldV.y -= -length(worldV.xz)/sqrt(-length(worldV.xz/earthRad)*length(worldV.xz/earthRad)+earthRad); + + //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 vL = 0.0; + float total_extinction = 1.0; + + + float distW = length(worldV); + worldV = normalize(worldV)*300000. + cameraPosition; //makes max cloud distance not dependant of render distance + dV_view = normalize(dV_view); + + //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; + vec3 startOffset = dV_view*dither; + + progress_view = startOffset + cameraPosition + dV_view*(cloud_height-cameraPosition.y)/(dV_view.y); + + + if (worldV.y < cloud_height) return vec4(0.,0.,0.,1.); //don't trace if no intersection is possible + + + + float shadowStep = 240.; + vec3 dV_Sun = normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep; + + float mult = length(dV_view); + + + color = vec3(0.0); + + total_extinction = 1.0; + float SdotV = dot(sunVec,normalize(fragpositi)); + //fake multiple scattering approx 1 (from horizon zero down clouds) + float mieDay = max(phaseg(SdotV,0.7),phaseg(SdotV,0.2)); + float mieNight = max(phaseg(-SdotV,0.7),phaseg(-SdotV,0.2)); + + vec3 sunContribution = mieDay*sunColor*3.14; + vec3 moonContribution = mieNight*moonColor*3.14; + vec3 skyCol0 = avgAmbient*(1.0-rainStrength*0.8); + + float powderMulMoon = 1.0; + float powderMulSun = 1.0; + + for (int i=0;i0.00){ + float cloud = cloudVol(curvedPos,samplePos,coverageSP); + if (cloud > 0.0005){ + float muS = cloud*cdensity; + float muE = cloud*cdensity; + float muEshD = 0.0; + if (sunContribution.g > 1e-5){ + for (int j=1;j<8;j++){ + vec3 shadowSamplePos = curvedPos+dV_Sun*j; + if (shadowSamplePos.y < maxHeight) + { + float cloudS=cloudVolLQ(vec3(shadowSamplePos)); + muEshD += cloudS*cdensity; + } + } + } + float muEshN = 0.0; + if (moonContribution.g > 1e-5){ + for (int j=1;j<8;j++){ + vec3 shadowSamplePos = curvedPos-dV_Sun*j; + if (shadowSamplePos.y < maxHeight) + { + float cloudS=cloudVolLQ(vec3(shadowSamplePos)); + muEshN += cloudS*cdensity; + } + } + } + //fake multiple scattering approx 2 (from horizon zero down clouds) + float sunShadow = max(exp2(-shadowStep*muEshD),exp2(-0.25*shadowStep*muEshD))*(1.0-exp(-muE*100.0*2.0)); + float moonShadow = max(exp2(-shadowStep*muEshN),exp2(-0.25*shadowStep*muEshN))*(1.0-exp(-muE*100.0*2.0)); + float h = 0.5-0.5*clamp(curvedPos.y/4000.-1500./4000.,0.0,1.0); + float ambientPowder = (1.0-h*exp2(-muE*100.0*2.0)); + vec3 S = vec3(sunContribution*sunShadow+moonShadow*moonContribution+skyCol0*ambientPowder); + + + vec3 Sint=(S - S * exp2(-mult*muE)) / (muE); + color += muS*Sint*total_extinction; + total_extinction *= exp2(-muE*mult); + + + if (total_extinction < 1/250.) break; + } + } + + progress_view += dV_view; + } + + //high altitude clouds + progress_view = progress_view + (5500.0-progress_view.y) * dV_view / dV_view.y; + mult = 400.0 * inversesqrt(abs(normalize(dV_view).y)); + float cirrus = cirrusClouds(vec3(progress_view.x,5500.0,progress_view.z))*cdensity*2.0; + if (cirrus > 1e-5){ + float muEshD = 0.0; + if (sunContribution.g > 1e-5){ + for (int j=1;j<8;j++){ + float cloudS=cirrusClouds(vec3(progress_view+dV_Sun*j)); + muEshD += cloudS*cdensity*2.; + } + } + float muEshN = 0.0; + if (moonContribution.g > 1e-5){ + for (int j=1;j<8;j++){ + float cloudS=cirrusClouds(vec3(progress_view-dV_Sun*j)); + muEshN += cloudS*cdensity*2.0; + } + } + float sunShadow = max(exp(-shadowStep*muEshD),exp(-0.25*shadowStep*muEshD)*0.4)*(1.0-exp(-cirrus*mult*2.0)); + float moonShadow = max(exp(-shadowStep*muEshN),exp(-0.25*shadowStep*muEshN)*0.4)*(1.0-exp(-cirrus*mult*2.0)); + float ambientPowder = (1.0-exp(-cirrus*mult*2.0)); + vec3 S = vec3(sunContribution*sunShadow+moonShadow*moonContribution+skyCol0*ambientPowder*0.5); + vec3 Sint=(S - S * exp(-mult*cirrus)) / (cirrus); + color += Sint * cirrus * total_extinction; + total_extinction *= exp(-mult*cirrus); + } + 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)); + +} diff --git a/shaders/world-1/lib/volumetricFog.glsl b/shaders/world-1/lib/volumetricFog.glsl new file mode 100644 index 0000000..83212d0 --- /dev/null +++ b/shaders/world-1/lib/volumetricFog.glsl @@ -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 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) diff --git a/shaders/world-1/texture/composite4.fsh b/shaders/world-1/texture/composite4.fsh new file mode 100644 index 0000000..fccda4b --- /dev/null +++ b/shaders/world-1/texture/composite4.fsh @@ -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); +} diff --git a/shaders/world-1/texture/composite4.vsh b/shaders/world-1/texture/composite4.vsh new file mode 100644 index 0000000..e6e3e92 --- /dev/null +++ b/shaders/world-1/texture/composite4.vsh @@ -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; + +} diff --git a/shaders/world-1/texture/noises.png b/shaders/world-1/texture/noises.png new file mode 100644 index 0000000..6236ff1 Binary files /dev/null and b/shaders/world-1/texture/noises.png differ diff --git a/shaders/world-1/texture/noises.png.mcmeta b/shaders/world-1/texture/noises.png.mcmeta new file mode 100644 index 0000000..33f3199 --- /dev/null +++ b/shaders/world-1/texture/noises.png.mcmeta @@ -0,0 +1,7 @@ +{ + "texture": + { + "blur": true, + "clamp": false + } +} \ No newline at end of file diff --git a/shaders/world1/block.properties b/shaders/world1/block.properties new file mode 100644 index 0000000..73045f4 --- /dev/null +++ b/shaders/world1/block.properties @@ -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 diff --git a/shaders/world1/composite10.fsh b/shaders/world1/composite10.fsh new file mode 100644 index 0000000..25c81c0 --- /dev/null +++ b/shaders/world1/composite10.fsh @@ -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.); + + + +} diff --git a/shaders/world1/composite10.vsh b/shaders/world1/composite10.vsh new file mode 100644 index 0000000..8d47d5c --- /dev/null +++ b/shaders/world1/composite10.vsh @@ -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; +} diff --git a/shaders/world1/composite11.fsh b/shaders/world1/composite11.fsh new file mode 100644 index 0000000..1320222 --- /dev/null +++ b/shaders/world1/composite11.fsh @@ -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 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.); +} diff --git a/shaders/world1/composite11.vsh b/shaders/world1/composite11.vsh new file mode 100644 index 0000000..b299614 --- /dev/null +++ b/shaders/world1/composite11.vsh @@ -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.); +} diff --git a/shaders/world1/composite12.fsh b/shaders/world1/composite12.fsh new file mode 100644 index 0000000..dd63b74 --- /dev/null +++ b/shaders/world1/composite12.fsh @@ -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 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.); +} diff --git a/shaders/world1/composite12.vsh b/shaders/world1/composite12.vsh new file mode 100644 index 0000000..56683b4 --- /dev/null +++ b/shaders/world1/composite12.vsh @@ -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.); + +} diff --git a/shaders/world1/composite14.fsh b/shaders/world1/composite14.fsh new file mode 100644 index 0000000..6bfa802 --- /dev/null +++ b/shaders/world1/composite14.fsh @@ -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.); +} diff --git a/shaders/world1/composite14.vsh b/shaders/world1/composite14.vsh new file mode 100644 index 0000000..386f006 --- /dev/null +++ b/shaders/world1/composite14.vsh @@ -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; +} diff --git a/shaders/world1/composite15.fsh b/shaders/world1/composite15.fsh new file mode 100644 index 0000000..74136a6 --- /dev/null +++ b/shaders/world1/composite15.fsh @@ -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); + +} diff --git a/shaders/world1/composite15.vsh b/shaders/world1/composite15.vsh new file mode 100644 index 0000000..5099bbb --- /dev/null +++ b/shaders/world1/composite15.vsh @@ -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; +} diff --git a/shaders/world1/composite2.fsh b/shaders/world1/composite2.fsh new file mode 100644 index 0000000..85987c4 --- /dev/null +++ b/shaders/world1/composite2.fsh @@ -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 */ +} diff --git a/shaders/world1/composite2.vsh b/shaders/world1/composite2.vsh new file mode 100644 index 0000000..b1cf351 --- /dev/null +++ b/shaders/world1/composite2.vsh @@ -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); + + +} diff --git a/shaders/world1/composite5.fsh b/shaders/world1/composite5.fsh new file mode 100644 index 0000000..48345fb --- /dev/null +++ b/shaders/world1/composite5.fsh @@ -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 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 +} diff --git a/shaders/world1/composite6.vsh b/shaders/world1/composite6.vsh new file mode 100644 index 0000000..05cecb7 --- /dev/null +++ b/shaders/world1/composite6.vsh @@ -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; + +} diff --git a/shaders/world1/composite8.fsh b/shaders/world1/composite8.fsh new file mode 100644 index 0000000..dd85629 --- /dev/null +++ b/shaders/world1/composite8.fsh @@ -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 + + + + + +} diff --git a/shaders/world1/composite8.vsh b/shaders/world1/composite8.vsh new file mode 100644 index 0000000..24ef8ce --- /dev/null +++ b/shaders/world1/composite8.vsh @@ -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; +} diff --git a/shaders/world1/composite9.fsh b/shaders/world1/composite9.fsh new file mode 100644 index 0000000..517bfe5 --- /dev/null +++ b/shaders/world1/composite9.fsh @@ -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); + + +} diff --git a/shaders/world1/composite9.vsh b/shaders/world1/composite9.vsh new file mode 100644 index 0000000..386f006 --- /dev/null +++ b/shaders/world1/composite9.vsh @@ -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; +} diff --git a/shaders/world1/deferred.fsh b/shaders/world1/deferred.fsh new file mode 100644 index 0000000..34b9358 --- /dev/null +++ b/shaders/world1/deferred.fsh @@ -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); + +} diff --git a/shaders/world1/deferred.vsh b/shaders/world1/deferred.vsh new file mode 100644 index 0000000..2ff914b --- /dev/null +++ b/shaders/world1/deferred.vsh @@ -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.))); +} diff --git a/shaders/world1/deferred1.fsh b/shaders/world1/deferred1.fsh new file mode 100644 index 0000000..24db38d --- /dev/null +++ b/shaders/world1/deferred1.fsh @@ -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 + +} diff --git a/shaders/world1/deferred1.vsh b/shaders/world1/deferred1.vsh new file mode 100644 index 0000000..1afd63f --- /dev/null +++ b/shaders/world1/deferred1.vsh @@ -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; + +} diff --git a/shaders/world1/final.fsh b/shaders/world1/final.fsh new file mode 100644 index 0000000..2388d11 --- /dev/null +++ b/shaders/world1/final.fsh @@ -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); +} diff --git a/shaders/world1/final.vsh b/shaders/world1/final.vsh new file mode 100644 index 0000000..7aeb51b --- /dev/null +++ b/shaders/world1/final.vsh @@ -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); +} diff --git a/shaders/world1/gbuffers_all_solid.fsh b/shaders/world1/gbuffers_all_solid.fsh new file mode 100644 index 0000000..76e3e6c --- /dev/null +++ b/shaders/world1/gbuffers_all_solid.fsh @@ -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)) ; + + + +} \ No newline at end of file diff --git a/shaders/world1/gbuffers_all_solid.vsh b/shaders/world1/gbuffers_all_solid.vsh new file mode 100644 index 0000000..1c0032e --- /dev/null +++ b/shaders/world1/gbuffers_all_solid.vsh @@ -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 +} diff --git a/shaders/world1/gbuffers_all_translucent.fsh b/shaders/world1/gbuffers_all_translucent.fsh new file mode 100644 index 0000000..d89e204 --- /dev/null +++ b/shaders/world1/gbuffers_all_translucent.fsh @@ -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.); + + } +} diff --git a/shaders/world1/gbuffers_all_translucent.vsh b/shaders/world1/gbuffers_all_translucent.vsh new file mode 100644 index 0000000..13986e0 --- /dev/null +++ b/shaders/world1/gbuffers_all_translucent.vsh @@ -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); +} diff --git a/shaders/world1/gbuffers_armor_glint.fsh b/shaders/world1/gbuffers_armor_glint.fsh new file mode 100644 index 0000000..c931e5f --- /dev/null +++ b/shaders/world1/gbuffers_armor_glint.fsh @@ -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; + + + +} diff --git a/shaders/world1/gbuffers_armor_glint.vsh b/shaders/world1/gbuffers_armor_glint.vsh new file mode 100644 index 0000000..40823aa --- /dev/null +++ b/shaders/world1/gbuffers_armor_glint.vsh @@ -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 +} \ No newline at end of file diff --git a/shaders/world1/gbuffers_basic.fsh b/shaders/world1/gbuffers_basic.fsh new file mode 100644 index 0000000..97072f6 --- /dev/null +++ b/shaders/world1/gbuffers_basic.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_basic.vsh b/shaders/world1/gbuffers_basic.vsh new file mode 100644 index 0000000..5078151 --- /dev/null +++ b/shaders/world1/gbuffers_basic.vsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_beaconbeam.fsh b/shaders/world1/gbuffers_beaconbeam.fsh new file mode 100644 index 0000000..f4e7cfb --- /dev/null +++ b/shaders/world1/gbuffers_beaconbeam.fsh @@ -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; + + + + +} diff --git a/shaders/world1/gbuffers_beaconbeam.vsh b/shaders/world1/gbuffers_beaconbeam.vsh new file mode 100644 index 0000000..704f4ea --- /dev/null +++ b/shaders/world1/gbuffers_beaconbeam.vsh @@ -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 +} \ No newline at end of file diff --git a/shaders/world1/gbuffers_block.fsh b/shaders/world1/gbuffers_block.fsh new file mode 100644 index 0000000..95943b4 --- /dev/null +++ b/shaders/world1/gbuffers_block.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define BLOCK_ENT +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_block.vsh b/shaders/world1/gbuffers_block.vsh new file mode 100644 index 0000000..9974256 --- /dev/null +++ b/shaders/world1/gbuffers_block.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define BLOCK_ENT +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_clouds.fsh b/shaders/world1/gbuffers_clouds.fsh new file mode 100644 index 0000000..563a191 --- /dev/null +++ b/shaders/world1/gbuffers_clouds.fsh @@ -0,0 +1,9 @@ +#version 120 + +/* DRAWBUFFERS:3 */ + + + +void main() { + +} diff --git a/shaders/world1/gbuffers_clouds.vsh b/shaders/world1/gbuffers_clouds.vsh new file mode 100644 index 0000000..90c4b9e --- /dev/null +++ b/shaders/world1/gbuffers_clouds.vsh @@ -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; +} diff --git a/shaders/world1/gbuffers_damagedblock.fsh b/shaders/world1/gbuffers_damagedblock.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world1/gbuffers_damagedblock.fsh @@ -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; + } + + + +} diff --git a/shaders/world1/gbuffers_damagedblock.vsh b/shaders/world1/gbuffers_damagedblock.vsh new file mode 100644 index 0000000..4ced627 --- /dev/null +++ b/shaders/world1/gbuffers_damagedblock.vsh @@ -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 +} diff --git a/shaders/world1/gbuffers_entities.fsh b/shaders/world1/gbuffers_entities.fsh new file mode 100644 index 0000000..0cd3e0d --- /dev/null +++ b/shaders/world1/gbuffers_entities.fsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define ENTITIES +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_entities.vsh b/shaders/world1/gbuffers_entities.vsh new file mode 100644 index 0000000..f4f07a4 --- /dev/null +++ b/shaders/world1/gbuffers_entities.vsh @@ -0,0 +1,6 @@ +#version 120 + + +// #define WORLD +#define ENTITIES +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand.fsh b/shaders/world1/gbuffers_hand.fsh new file mode 100644 index 0000000..21ac244 --- /dev/null +++ b/shaders/world1/gbuffers_hand.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define HAND +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand.vsh b/shaders/world1/gbuffers_hand.vsh new file mode 100644 index 0000000..39504ed --- /dev/null +++ b/shaders/world1/gbuffers_hand.vsh @@ -0,0 +1,5 @@ +#version 120 + +#define WORLD +#define HAND +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand_water.fsh b/shaders/world1/gbuffers_hand_water.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world1/gbuffers_hand_water.fsh @@ -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; + } + + + +} diff --git a/shaders/world1/gbuffers_hand_water.vsh b/shaders/world1/gbuffers_hand_water.vsh new file mode 100644 index 0000000..68dc1b7 --- /dev/null +++ b/shaders/world1/gbuffers_hand_water.vsh @@ -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 +} diff --git a/shaders/world1/gbuffers_skybasic.fsh b/shaders/world1/gbuffers_skybasic.fsh new file mode 100644 index 0000000..563a191 --- /dev/null +++ b/shaders/world1/gbuffers_skybasic.fsh @@ -0,0 +1,9 @@ +#version 120 + +/* DRAWBUFFERS:3 */ + + + +void main() { + +} diff --git a/shaders/world1/gbuffers_skybasic.vsh b/shaders/world1/gbuffers_skybasic.vsh new file mode 100644 index 0000000..90c4b9e --- /dev/null +++ b/shaders/world1/gbuffers_skybasic.vsh @@ -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; +} diff --git a/shaders/world1/gbuffers_skytextured.fsh b/shaders/world1/gbuffers_skytextured.fsh new file mode 100644 index 0000000..8ad1592 --- /dev/null +++ b/shaders/world1/gbuffers_skytextured.fsh @@ -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; +} diff --git a/shaders/world1/gbuffers_skytextured.vsh b/shaders/world1/gbuffers_skytextured.vsh new file mode 100644 index 0000000..2c401c5 --- /dev/null +++ b/shaders/world1/gbuffers_skytextured.vsh @@ -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 +} + diff --git a/shaders/world1/gbuffers_spidereyes.fsh b/shaders/world1/gbuffers_spidereyes.fsh new file mode 100644 index 0000000..aa3de8b --- /dev/null +++ b/shaders/world1/gbuffers_spidereyes.fsh @@ -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; + +} diff --git a/shaders/world1/gbuffers_spidereyes.vsh b/shaders/world1/gbuffers_spidereyes.vsh new file mode 100644 index 0000000..cdc23a4 --- /dev/null +++ b/shaders/world1/gbuffers_spidereyes.vsh @@ -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 + +} \ No newline at end of file diff --git a/shaders/world1/gbuffers_terrain.fsh b/shaders/world1/gbuffers_terrain.fsh new file mode 100644 index 0000000..97072f6 --- /dev/null +++ b/shaders/world1/gbuffers_terrain.fsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_terrain.vsh b/shaders/world1/gbuffers_terrain.vsh new file mode 100644 index 0000000..5078151 --- /dev/null +++ b/shaders/world1/gbuffers_terrain.vsh @@ -0,0 +1,4 @@ +#version 120 + +#define WORLD +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured.fsh b/shaders/world1/gbuffers_textured.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world1/gbuffers_textured.fsh @@ -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; + } + + + +} diff --git a/shaders/world1/gbuffers_textured.vsh b/shaders/world1/gbuffers_textured.vsh new file mode 100644 index 0000000..51f3fd7 --- /dev/null +++ b/shaders/world1/gbuffers_textured.vsh @@ -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 +} diff --git a/shaders/world1/gbuffers_textured_lit.fsh b/shaders/world1/gbuffers_textured_lit.fsh new file mode 100644 index 0000000..2225473 --- /dev/null +++ b/shaders/world1/gbuffers_textured_lit.fsh @@ -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; + } + + + +} diff --git a/shaders/world1/gbuffers_textured_lit.vsh b/shaders/world1/gbuffers_textured_lit.vsh new file mode 100644 index 0000000..68dc1b7 --- /dev/null +++ b/shaders/world1/gbuffers_textured_lit.vsh @@ -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 +} diff --git a/shaders/world1/gbuffers_water.fsh b/shaders/world1/gbuffers_water.fsh new file mode 100644 index 0000000..5d6f344 --- /dev/null +++ b/shaders/world1/gbuffers_water.fsh @@ -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); + +} diff --git a/shaders/world1/gbuffers_water.vsh b/shaders/world1/gbuffers_water.vsh new file mode 100644 index 0000000..ec64b46 --- /dev/null +++ b/shaders/world1/gbuffers_water.vsh @@ -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 + +} diff --git a/shaders/world1/gbuffers_weather.fsh b/shaders/world1/gbuffers_weather.fsh new file mode 100644 index 0000000..f169e8b --- /dev/null +++ b/shaders/world1/gbuffers_weather.fsh @@ -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; + + + +} diff --git a/shaders/world1/gbuffers_weather.vsh b/shaders/world1/gbuffers_weather.vsh new file mode 100644 index 0000000..b7c44aa --- /dev/null +++ b/shaders/world1/gbuffers_weather.vsh @@ -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 +} \ No newline at end of file diff --git a/shaders/world1/lib/ACES.glsl b/shaders/world1/lib/ACES.glsl new file mode 100644 index 0000000..d9d6ce7 --- /dev/null +++ b/shaders/world1/lib/ACES.glsl @@ -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) + ); +} diff --git a/shaders/world1/lib/ACESSPL.glsl b/shaders/world1/lib/ACESSPL.glsl new file mode 100644 index 0000000..81c4ffd --- /dev/null +++ b/shaders/world1/lib/ACESSPL.glsl @@ -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); +} \ No newline at end of file diff --git a/shaders/world1/lib/ACEST.glsl b/shaders/world1/lib/ACEST.glsl new file mode 100644 index 0000000..f8693d7 --- /dev/null +++ b/shaders/world1/lib/ACEST.glsl @@ -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; \ No newline at end of file diff --git a/shaders/world1/lib/ROBOBO_sky.glsl b/shaders/world1/lib/ROBOBO_sky.glsl new file mode 100644 index 0000000..ef8fcfd --- /dev/null +++ b/shaders/world1/lib/ROBOBO_sky.glsl @@ -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; +} diff --git a/shaders/world1/lib/Shadow_Params.glsl b/shaders/world1/lib/Shadow_Params.glsl new file mode 100644 index 0000000..7556167 --- /dev/null +++ b/shaders/world1/lib/Shadow_Params.glsl @@ -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); +} diff --git a/shaders/world1/lib/clouds.glsl b/shaders/world1/lib/clouds.glsl new file mode 100644 index 0000000..abd35ef --- /dev/null +++ b/shaders/world1/lib/clouds.glsl @@ -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.))); + +} \ No newline at end of file diff --git a/shaders/world1/lib/color_dither.glsl b/shaders/world1/lib/color_dither.glsl new file mode 100644 index 0000000..73c4960 --- /dev/null +++ b/shaders/world1/lib/color_dither.glsl @@ -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); +} \ No newline at end of file diff --git a/shaders/world1/lib/color_transforms.glsl b/shaders/world1/lib/color_transforms.glsl new file mode 100644 index 0000000..4813ff4 --- /dev/null +++ b/shaders/world1/lib/color_transforms.glsl @@ -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); +} diff --git a/shaders/world1/lib/composite3.fsh b/shaders/world1/lib/composite3.fsh new file mode 100644 index 0000000..cb2a2ba --- /dev/null +++ b/shaders/world1/lib/composite3.fsh @@ -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; +} diff --git a/shaders/world1/lib/composite3.vsh b/shaders/world1/lib/composite3.vsh new file mode 100644 index 0000000..05cecb7 --- /dev/null +++ b/shaders/world1/lib/composite3.vsh @@ -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; + +} diff --git a/shaders/world1/lib/projections.glsl b/shaders/world1/lib/projections.glsl new file mode 100644 index 0000000..72ab381 --- /dev/null +++ b/shaders/world1/lib/projections.glsl @@ -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; +} diff --git a/shaders/world1/lib/sky_gradient.glsl b/shaders/world1/lib/sky_gradient.glsl new file mode 100644 index 0000000..559faf3 --- /dev/null +++ b/shaders/world1/lib/sky_gradient.glsl @@ -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); +} diff --git a/shaders/world1/lib/specular.glsl b/shaders/world1/lib/specular.glsl new file mode 100644 index 0000000..2ee4cdb --- /dev/null +++ b/shaders/world1/lib/specular.glsl @@ -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 -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 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; +} \ No newline at end of file diff --git a/shaders/world1/lib/stars.glsl b/shaders/world1/lib/stars.glsl new file mode 100644 index 0000000..38d3cbf --- /dev/null +++ b/shaders/world1/lib/stars.glsl @@ -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); +} diff --git a/shaders/world1/lib/texFiltering.glsl b/shaders/world1/lib/texFiltering.glsl new file mode 100644 index 0000000..7d58676 --- /dev/null +++ b/shaders/world1/lib/texFiltering.glsl @@ -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; +} diff --git a/shaders/world1/lib/util.glsl b/shaders/world1/lib/util.glsl new file mode 100644 index 0000000..f701920 --- /dev/null +++ b/shaders/world1/lib/util.glsl @@ -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; + } diff --git a/shaders/world1/lib/volumetricClouds.glsl b/shaders/world1/lib/volumetricClouds.glsl new file mode 100644 index 0000000..0f538e2 --- /dev/null +++ b/shaders/world1/lib/volumetricClouds.glsl @@ -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 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)); +} diff --git a/shaders/world1/lib/volumetricFog.glsl b/shaders/world1/lib/volumetricFog.glsl new file mode 100644 index 0000000..83212d0 --- /dev/null +++ b/shaders/world1/lib/volumetricFog.glsl @@ -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 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) diff --git a/shaders/world1/texture/composite4.fsh b/shaders/world1/texture/composite4.fsh new file mode 100644 index 0000000..fccda4b --- /dev/null +++ b/shaders/world1/texture/composite4.fsh @@ -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); +} diff --git a/shaders/world1/texture/composite4.vsh b/shaders/world1/texture/composite4.vsh new file mode 100644 index 0000000..e6e3e92 --- /dev/null +++ b/shaders/world1/texture/composite4.vsh @@ -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; + +} diff --git a/shaders/world1/texture/noises.png b/shaders/world1/texture/noises.png new file mode 100644 index 0000000..6236ff1 Binary files /dev/null and b/shaders/world1/texture/noises.png differ diff --git a/shaders/world1/texture/noises.png.mcmeta b/shaders/world1/texture/noises.png.mcmeta new file mode 100644 index 0000000..33f3199 --- /dev/null +++ b/shaders/world1/texture/noises.png.mcmeta @@ -0,0 +1,7 @@ +{ + "texture": + { + "blur": true, + "clamp": false + } +} \ No newline at end of file