diff --git a/shaders/block.properties b/shaders/block.properties index 626537e..515ad75 100644 --- a/shaders/block.properties +++ b/shaders/block.properties @@ -7,7 +7,7 @@ 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 + block.10003 = minecraft:cherry_leaves 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 ----- ####### diff --git a/shaders/composite.fsh b/shaders/composite.fsh index a18c18e..96d2a24 100644 --- a/shaders/composite.fsh +++ b/shaders/composite.fsh @@ -195,7 +195,6 @@ void main() { float LabSSS = 0.0; #endif - #ifndef Variable_Penumbra_Shadows if (translucent && !hand) minshadowfilt += 25; #endif @@ -217,7 +216,7 @@ void main() { #ifdef Variable_Penumbra_Shadows - if (NdotL > 0.000 || LabSSS > 0.0 || translucent || translucent2 || translucent3 || translucent4) { + if (NdotL > 0.0 || LabSSS >= 0.0) { vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh new file mode 100644 index 0000000..be26cf4 --- /dev/null +++ b/shaders/composite1.fsh @@ -0,0 +1,1267 @@ +#version 120 +//Render sky, volumetric clouds, direct lighting +#extension GL_EXT_gpu_shader4 : enable + +#include "lib/settings.glsl" + +const bool colortex5MipmapEnabled = true; +const bool colortex12MipmapEnabled = true; +// const bool colortex4MipmapEnabled = true; + +const bool shadowHardwareFiltering = true; +flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +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 vec3 WsunVec; +flat varying vec2 TAA_Offset; +flat varying float tempOffsets; + + +uniform float eyeAltitude; +/* +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) +*/ + + +flat varying vec3 zMults; +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 near; +uniform float nightVision; +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); +} + +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} +vec3 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} +#include "lib/res_params.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/diffuse_lighting.glsl" + +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 ; +} + +vec2 R2_dither(){ + vec2 alpha = vec2(0.75487765, 0.56984026); + return vec2(fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter), fract((1.0-alpha.x) * gl_FragCoord.x + (1.0-alpha.y) * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter)); +} +float blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * (frameCounter*0.5+0.5) ); +} +vec4 blueNoise(vec2 coord){ + return texelFetch2D(colortex6, ivec2(coord )%512, 0) ; +} +vec3 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; +} + + +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,12.0)/(1e-8+rayLength); + dV *= 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 = phaseg(VdotL,0.7) * 1.5 + 0.1; + + vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz; + vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz); + // vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; + + float expFactor = 11.0; + for (int i=0;i -near) ? + (-near -position.z) / dir.z : far*sqrt(3.) ; + vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space + direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size + vec3 stepv = direction * 3.0 * clamp(MC_RENDER_QUALITY,1.,2.0)*vec3(RENDER_SCALE,1.0); + + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0); + // spos.xy += (TAA_Offset*(texelSize/4))*RENDER_SCALE ; + spos += stepv*dither ; + + for (int i = 0; i < int(quality); i++) { + spos += stepv; + + float sp = texture2D(depthtex1,spos.xy).x; + + if( sp < spos.z) { + float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z); + if (dist < 0.015 ) return i / quality; + } + } + return 1.0; +} + +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){ + + 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); + // vec2 sp = vogel_disk_7[j]; + 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); + // vec2 sampleOffset = sp*rd; + + 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); + + lighting = lighting*max(occlusion,pow(lightmap.x,4)); +} +vec3 DoContrast(vec3 Color, float strength){ + + float Contrast = log(strength); + + return clamp(mix(vec3(0.5), Color, Contrast) ,0,255); +} + + +void ssDO(inout vec3 lighting, vec3 fragpos,float mulfov, vec2 noise, vec3 normal, vec3 RPnormal, vec2 texcoord, vec3 ambientCoefs, vec2 lightmap, float sunlight){ + const int Samples = 7; + vec3 Radiance = vec3(0); + float occlusion = 0.0; + + 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 ); + float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*5/50.0; + + + float rd = mulfov2 * 0.1 ; + + + vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ; + + vec3 NormalSpecific = viewToWorld(normal); + + + for (int j = 0; j < Samples ;j++) { + + vec2 sp = tapLocation_alternate(j, 0.0, 7, 20, blueNoise()); + 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 = 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); + + float NdotV2 = clamp(dot(vec*inversesqrt(dsquared), normalize(RPnormal)),0.,1.); + + 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); + + + vec3 previousPosition = mat3(gbufferModelViewInverse) * t0 + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; + previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; + previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; + + if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ + Radiance += NdotV2*texture2D(colortex5,previousPosition.xy).rgb ; + } + + } + } + } + + lighting = vec3(1) + Radiance/Samples; +} + +vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){ + float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + + float stepSize = stepsizes / dist; + int maxSteps = STEPS; + vec3 clipPosition = toClipSpace3(position); + float rayLength = ((position.z + dir.z * sqrt(3.0)*far) > -sqrt(3.0)*near) ? + (-sqrt(3.0)*near -position.z) / dir.z : sqrt(3.0)*far; + vec3 end = toClipSpace3(position+dir*rayLength) ; + vec3 direction = end-clipPosition ; //convert to clip space + + float len = max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y)/stepSize; + //get at which length the ray intersects with the edge of the screen + vec3 maxLengths = (step(0.,direction)-clipPosition) / direction; + + float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z)*2000.0; + + vec3 stepv = direction/len; + + int iterations = min(int(min(len, mult*len)-2), maxSteps); + + //Do one iteration for closest texel (good contact shadows) + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ; + spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; + spos += stepv/(stepSize/2); + + float distancered = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases + + for(int i = 0; i < iterations; i++){ + if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1); + spos += stepv*noise; + + float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/ texelSize/4),0).w/65000.0); + float currZ = linZ(spos.z); + + if( sp < currZ) { + float dist = abs(sp-currZ)/currZ; + if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0); + } + } + return vec3(1.1); +} + +vec3 cosineHemisphereSample(vec2 Xi, float roughness){ + float r = sqrt(Xi.x); + float theta = 2.0 * 3.14159265359 * Xi.y; + + float x = r * cos(theta); + float y = r * sin(theta); + + return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.))); +} +vec3 TangentToWorld(vec3 N, vec3 H, float roughness){ + vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); + vec3 T = normalize(cross(UpVector, N)); + vec3 B = cross(N, T); + + return vec3((T * H.x) + (B * H.y) + (N * H.z)); +} + + +// 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 += skyLightDir; + +// occlude += normalize(rayHit.z - 1.0) / (1.1-rayDir.y); + + +// } +// // occlude = mix( occlude,1, inShadow); +// // occlude = occlude*0.5 + 0.5; +// // lighting *= 2.5; +// lighting *= occlude/nrays; +// } + + +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 = DoContrast(texture2D(colortex5,previousPosition.xy).rgb) ; +// else +// intRadiance += lighting*skyLightDir; // make sure ambient light exists but at screen edges when you turn + + +// }else{ +// intRadiance += lighting*skyLightDir; +// } +// } +// lighting = intRadiance/nrays; +// } + + +void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmap, vec3 albedo){ + int nrays = RAY_COUNT; + vec3 intRadiance = vec3(0.0); + float occlusion = 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 ? 0.0 : 0.0; // the positons where the occlusion happens + + // vec3 AO = lighting * (normalize(rayHit.z - 1.0) / (1.1-rayDir.y)); + 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 = DoContrast(texture2DLod(colortex5,previousPosition.xy,0).rgb, 55.0 ) * GI_Strength ; + intRadiance = texture2DLod(colortex5,previousPosition.xy,0).rgb * GI_Strength ; + } + + + occlusion += 1.0; + } + + } + lighting = lighting * (1.0-occlusion/nrays) + intRadiance/nrays; +} + + + + + +void SubsurfaceScattering(inout float SSS, float Scattering, float Density, float LabDenisty){ + #ifdef LabPBR_subsurface_scattering + float labcurve = pow(LabDenisty,LabSSS_Curve); + // beers law + SSS = clamp(exp( Scattering * -(10 - LabDenisty*7)), 0.0, labcurve); + if (abs(Scattering-0.1) < 0.0004 ) SSS = labcurve; + #else + // beers law + SSS = clamp(exp(Scattering * -Density), 0.0, 1.0); + if (abs(Scattering-0.1) < 0.0004 ) SSS = 1.0; + #endif +} + + + + +vec3 SubsurfaceScattering_2(vec3 albedo, float Scattering, float Density, float LabDenisty, float lightPos, bool yeSSS){ + if(!yeSSS) return vec3(0.0); + + float density = Density; + + #ifdef LabPBR_subsurface_scattering + float labcurve = pow(LabDenisty,LabSSS_Curve); + density = sqrt(30 - labcurve*15); + #endif + + vec3 absorbed = max(1.0 - albedo,0.0) * density; + // absorbed = vec3(1.); + + vec3 scatter = exp(-sqrt(Scattering * absorbed)) * exp(Scattering * -density); + // float gloop = (1.0-exp(sqrt(Scattering) * -density)); + // vec3 scatter = mix(vec3(1.0), max(albedo - gloop * (1-labcurve),0.0), gloop) * exp(Scattering * -density); + + #ifdef LabPBR_subsurface_scattering + scatter *= labcurve; + #endif + + scatter *= 0.5 + CustomPhase(lightPos, 1.0,30.0)*20; + + return scatter; +} + +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 LabEmission( + inout vec3 Lighting, + vec3 Albedo, + float Emission +){ + // if( Emission < 255.0/255.0 ) Lighting = mix(Lighting, Albedo * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why + if( Emission < 255.0/255.0 ) Lighting += (Albedo * Emissive_Brightness) * pow(Emission, Emissive_Curve); +} + + + + + +#include "lib/PhotonGTAO.glsl" + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +void main() { + + vec2 texcoord = gl_FragCoord.xy*texelSize; + + + + + float z0 = texture2D(depthtex0,texcoord).x; + float z = texture2D(depthtex1,texcoord).x; + float TranslucentDepth = clamp( ld(z0)-ld(z0) ,0.0,1.0); + + vec2 tempOffset=TAA_Offset; + vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z)); + vec3 fragpos_rtshadow = toScreenSpace(vec3(texcoord/RENDER_SCALE,z)); + vec3 fragpos_handfix = fragpos; + + if ( z < 0.56) fragpos_handfix.z /= MC_HAND_DEPTH; // fix lighting on hand + + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + p3 += gbufferModelViewInverse[3].xyz; + + + 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; + + + #ifdef AEROCHROME_MODE + totEpsilon *= 10.0; + scatterCoef *= 0.1; + #endif + + float noise = blueNoise(); + + + float iswaterstuff = texture2D(colortex7,texcoord).a ; + bool iswater = iswaterstuff > 0.99; + + 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 normal = decode(dataUnpacked0.yw); + // Color // + vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); + vec4 translucentCol = texture2D(colortex13,texcoord); // translucents + + // Specular // + vec4 SpecularTex = texture2D(colortex8,texcoord); + + // Normal // + vec4 normalAndAO = texture2D(colortex15,texcoord); + vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; + vec3 slopednormal = normal; + + #ifdef POM + #ifdef Horrible_slope_normals + vec3 ApproximatedFlatNormal = normalize(cross(dFdx(p3), dFdy(p3))); // it uses depth that has POM written to it. + slopednormal = normalize(clamp(normal, ApproximatedFlatNormal*2.0 - 1.0, ApproximatedFlatNormal*2.0 + 1.0) ); + #endif + #endif + + float vanilla_AO = normalAndAO.a; + normalAndAO.a = clamp(pow(normalAndAO.a*5,4),0,1); + + + 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; + vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.)); + + float lightleakfix = clamp(eyeBrightness.y/240.0 + lightmap.y,0.0,1.0); + + vec3 DirectLightColor = (lightCol.rgb/80.0); + DirectLightColor *= clamp(abs(WsunVec.y)*2,0.,1.); + + float cloudShadow = 1.0; + + if ( z >= 1.) { //sky + vec3 background = vec3(0.0); + background += stars(vec3(np3.x,abs(np3.y),np3.z)) * 5.0; + + #ifndef ambientLight_only + background += drawSun(dot(lightCol.a * WsunVec, np3),0, DirectLightColor,vec3(0.0)) ; // sun + background += drawSun(dot(lightCol.a * -WsunVec, np3),0, blackbody2(Moon_temp)/500.,vec3(0.0)); // moon + #endif + + background *= clamp( (np3.y+ 0.02)*5.0 + (eyeAltitude - 319)/800000 ,0.0,1.0); + + vec3 skyTEX = skyFromTex(np3,colortex4)/150.0 * 5.0; + background += skyTEX; + // eclipse + // color *=max(1.0 - drawSun(dot(lightCol.a * WsunVec, (np3-0.0002)*1.001),0, vec3(1),vec3(0.0)),0.0); + + + vec4 cloud = texture2D_bicubic(colortex0,texcoord*CLOUDS_QUALITY); + background = background*cloud.a + cloud.rgb; + + gl_FragData[0].rgb = clamp(fp10Dither(background ,triangularize(noise)),0.0,65000.); + + }else{//land + + ////// ----- direct ----- ////// + + vec3 Direct_lighting = vec3(1.0); + + float NdotL = dot(slopednormal,WsunVec); + NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); + float Shadows = clamp(1.0 - filtered.b,0.0,1.0); + + if (abs(filtered.y-0.1) < 0.0004 && !iswater) Shadows = clamp((lightmap.y-0.85)*25,0,1); + + vec3 SSS; + float SSS_strength; + float LabSSS = clamp((-65.0 + SpecularTex.z * 255.0) / 190.0 ,0.0,1.0); + + if (NdotL > 0.001) { + + vec3 p3_shadow = mat3(gbufferModelViewInverse) * fragpos_handfix + gbufferModelViewInverse[3].xyz; + + GriAndEminShadowFix(p3_shadow, viewToWorld(FlatNormals), normalAndAO.a, lightmap.y, entities); + + + vec3 projectedShadowPosition = mat3(shadowModelView) * p3_shadow + 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); + Shadows = 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; + + Shadows += isShadow/SHADOW_FILTER_SAMPLE_COUNT; + } + } + } + + #ifdef Sub_surface_scattering + #ifdef Variable_Penumbra_Shadows + SSS_strength = 1000; + if (translucent) SSS_strength = 2; // low Density + else if (translucent2) SSS_strength = 5; /// medium Density + else if (translucent3) SSS_strength = 10; // misc Desnity + else if (translucent4) SSS_strength = 10; // mob Debsity + + bool hasSSS = SSS_strength < 1000 || LabSSS > 0.0; + + // if(hasSSS) SubsurfaceScattering(SSS, filtered.y, SSS_strength, LabSSS) ; + + SSS = SubsurfaceScattering_2(albedo, filtered.y, SSS_strength, LabSSS, clamp(dot(np3, WsunVec),0.0,1.0), hasSSS) ; + + + // if (isEyeInWater == 0) SSS *= lightleakfix; // light leak fix + #endif + + + + if (!hand){ + + if (abs(filtered.y-0.1) < 0.0004 && ( !translucent || !translucent2 || !translucent3 || !translucent4 ) ) SSS = vec3(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) * vec3(1); + + #else + vec3 vec = lightCol.a*sunVec; + float screenShadow = rayTraceShadow(vec, fragpos_rtshadow, interleaved_gradientNoise()); + screenShadow *= screenShadow ; + + #ifdef Variable_Penumbra_Shadows + Shadows = min(screenShadow, Shadows); + if (abs(filtered.y-0.1) < 0.0004 && ( translucent || translucent2 ) ) SSS = vec3(Shadows); + // #else + + #endif + + + #endif + } + + #ifdef Variable_Penumbra_Shadows + SSS *= 1.0-NdotL*Shadows; + #endif + #else + SSS = 0.0; + #endif + + #ifdef VOLUMETRIC_CLOUDS + #ifdef CLOUDS_SHADOWS + cloudShadow = GetCloudShadow(p3); + Shadows *= cloudShadow; + SSS *= cloudShadow; + #endif + #endif + + ////// ----- indirect ----- ////// + + vec3 Indirect_lighting = vec3(1.0); + + // float skylight = clamp(abs(normal.y+1),0.0,1.0); + float skylight = clamp(abs(ambientCoefs.y+1.0),0.35,2.0); + + + #if indirect_effect == 2 || indirect_effect == 3 || indirect_effect == 4 + if (!hand) skylight = 1.0; + #endif + + // do this to make underwater shading easier. + vec2 newLightmap = lightmap.xy; + if((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)) newLightmap.y = min(newLightmap.y+0.1,1.0); + + + // vec3 LavaGlow = vec3(TORCH_R,TORCH_G,TORCH_B); + // float thething = pow(clamp(2.0 + dot(viewToWorld(FlatNormals),np3),0.0,2.0),3.0); + // // LavaGlow *= thething*0.25+0.75; + // LavaGlow *= mix((2.0-thething)*0.5+0.5, thething*0.25+0.75, sqrt(lightmap.x)); + + Indirect_lighting = DoAmbientLighting(avgAmbient, vec3(TORCH_R,TORCH_G,TORCH_B), newLightmap.xy, skylight); + + + + + vec3 AO = vec3(1.0); + vec3 debug = vec3(0.0); + + // vanilla AO + #if indirect_effect == 0 + // AO = vec3(mix(1.0 - exp2(-5 * pow(1-vanilla_AO,3)), 1.0, pow(newLightmap.x,4))) ; + AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ; + #endif + + // SSAO + vanilla AO + #if indirect_effect == 1 + // AO *= mix(1.0 - exp2(-5 * pow(1-vanilla_AO,3)),1.0, pow(newLightmap.x,4)); + + AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) ) ; + if (!hand) ssAO(AO, fragpos, 1.0, blueNoise(gl_FragCoord.xy).rg, FlatNormals , texcoord, ambientCoefs, newLightmap.xy); + #endif + + // GTAO + #if indirect_effect == 2 + int seed = (frameCounter%40000); + vec2 r2 = fract(R2_samples(seed) + blueNoise(gl_FragCoord.xy).rg); + if (!hand) AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z), fragpos, worldToView(slopednormal), r2, debug) * vec3(1.0); + #endif + + // RTAO + #if indirect_effect == 3 + if (!hand) rtAO(AO, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, newLightmap.y, NdotL*Shadows); + #endif + + // SSGI + #if indirect_effect == 4 + if (!hand) rtGI(gl_FragData[0].rgb, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, newLightmap.y, albedo); + #endif + + #ifndef AO_in_sunlight + AO = mix(AO,vec3(1.0), min(NdotL*Shadows,1.0)); + #endif + + Indirect_lighting *= AO; + + ////// ----- Under Water Shading ----- ////// + + vec3 waterabsorb_speculars = vec3(1); + if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !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 + estimatedDepth = estimatedDepth; + // make it such that the estimated depth flips to be correct when entering water. + + if (isEyeInWater == 1) estimatedDepth = (1.0-lightmap.y)*16.0; + + float estimatedSunDepth = Vdiff; //assuming water plane + vec3 Absorbtion = exp2(-totEpsilon*estimatedDepth); + + // 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 lightting + DirectLightColor *= 0.5 + max(pow(Direct_caustics*2,2),0.0); + Indirect_lighting *= 0.5 + max(pow(Ambient_Caustics,2),0.0); + + // directLightCol *= Direct_caustics; + // Indirect_lighting *= Ambient_Caustics*0.5+0.5; + + // apply water absorbtion to the lighting + // waterabsorb_speculars.rgb *= Absorbtion; + + DirectLightColor *= Absorbtion; + // Indirect_lighting *= Absorbtion; + + } + + + + ////// ----- Finalize ----- ////// + + #ifdef Seasons + #ifdef Snowy_Winter + vec3 snow_p3 = p3 + cameraPosition; + float SnowPatches = densityAtPosSNOW(vec3(snow_p3.x,snow_p3.y/48.,snow_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 + + Direct_lighting = DoDirectLighting(DirectLightColor, Shadows, NdotL, 0.0); + + + #ifdef ambientLight_only + Direct_lighting = vec3(0.0); + #endif + + + //combine all light sources + vec3 FINAL_COLOR = Direct_lighting + Indirect_lighting; + + #ifdef Variable_Penumbra_Shadows + FINAL_COLOR += SSS*DirectLightColor; + #endif + + FINAL_COLOR *= albedo; + + #ifdef Specular_Reflections + MaterialReflections(FINAL_COLOR, SpecularTex.r, SpecularTex.ggg, albedo, WsunVec, (Shadows*NdotL)*DirectLightColor, lightmap.y, slopednormal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg, interleaved_gradientNoise()), hand, entities); + #endif + + // #ifdef LabPBR_Emissives + LabEmission(FINAL_COLOR, albedo, SpecularTex.a); + // #endif + + gl_FragData[0].rgb = FINAL_COLOR; + } + + ////// ----- Apply Clouds ----- ////// + // gl_FragData[0].rgb = gl_FragData[0].rgb *cloud.a + cloud.rgb; + + ////// ----- Under Water Fog ----- ////// + + 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.005); + vec3 lightColVol = (lightCol.rgb / 80.) ; + + if (isEyeInWater == 0) waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(np3, WsunVec)); + } + + // phasefunc = phaseg(clamp(dot(np3, WsunVec),0.0,1.0), 0.5)*10; + + // gl_FragData[0].rgb = vec3(1.0); + // if(z < 1) gl_FragData[0].rgb = Custom_GGX(normal, -np3, WsunVec, SpecularTex.r, SpecularTex.g) * vec3(1.0); + + + /* DRAWBUFFERS:3 */ +} \ No newline at end of file diff --git a/shaders/composite1.vsh b/shaders/composite1.vsh new file mode 100644 index 0000000..eb0bb24 --- /dev/null +++ b/shaders/composite1.vsh @@ -0,0 +1,70 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#include "lib/settings.glsl" + +flat varying vec3 WsunVec; +flat varying vec3 avgAmbient; +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; + + + + 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); + zMults = vec3((far * near)*2.0,far+near,far-near); + + + +} diff --git a/shaders/composite10.fsh b/shaders/composite10.fsh index 3cf27fe..06b5762 100644 --- a/shaders/composite10.fsh +++ b/shaders/composite10.fsh @@ -1,12 +1,80 @@ #version 120 + #include "lib/settings.glsl" -//downsample 1st pass (half res) for bloom +//Merge and upsample the blurs into a 1/4 res bloom buffer #include "lib/res_params.glsl" uniform sampler2D colortex3; -uniform sampler2D colortex8; +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////////////////////////////// @@ -14,31 +82,24 @@ uniform float viewHeight; //////////////////////////////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 -/* DRAWBUFFERS:6 */ -vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*texelSize*2.; +bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res - //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; +bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res - //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; +bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res - //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; +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 - //0.125 - gl_FragData[0] += texture2D(colortex3,quarterResTC)*0.125; +//bloom = texture2D_bicubic(colortex6,texcoord).rgb*6.; //1/8 res - gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); +gl_FragData[0].rgb = bloom*2.; + +gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); } diff --git a/shaders/composite10.vsh b/shaders/composite10.vsh index 23439b2..97113b9 100644 --- a/shaders/composite10.vsh +++ b/shaders/composite10.vsh @@ -14,5 +14,5 @@ void main() { vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); gl_Position = ftransform(); //*0.51 to avoid errors when sampling outside since clearing is disabled - gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.26*BLOOM_QUALITY/clampedRes*vec2(1920.0,1080.)*2-1.0; + 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/composite11.fsh b/shaders/composite11.fsh index 513baa1..4b457bd 100644 --- a/shaders/composite11.fsh +++ b/shaders/composite11.fsh @@ -1,62 +1,149 @@ #version 120 -#include "lib/settings.glsl" -//6 Horizontal gaussian blurs and horizontal downsampling -#include "lib/res_params.glsl" +//Vignetting, applies bloom, applies exposure and tonemaps the final image +#extension GL_EXT_gpu_shader4 : enable -uniform sampler2D colortex6; -uniform vec2 texelSize; +#include "/lib/settings.glsl" + +#include "/lib/res_params.glsl" + + +flat varying vec4 exposure; +flat varying vec2 rodExposureDepth; varying vec2 texcoord; + +const bool colortex5MipmapEnabled = true; +// uniform sampler2D colortex4; +uniform sampler2D colortex5; +uniform sampler2D colortex3; +// uniform sampler2D colortex6; +uniform sampler2D colortex7; +// uniform sampler2D colortex10; +// 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; -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); +uniform float frameTimeCounter; +uniform int frameCounter; +uniform int isEyeInWater; +uniform float near; +uniform float aspectRatio; +uniform float far; +uniform float rainStrength; +uniform float screenBrightness; +uniform vec4 Moon_Weather_properties; // R = cloud coverage G = fog density + +uniform int 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.); + +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferProjectionInverse; +vec4 Weather_properties = Moon_Weather_properties; + +#include "/lib/color_transforms.glsl" +#include "/lib/color_dither.glsl" +// #include "lib/biome_specifics.glsl" +#include "/lib/bokeh.glsl" + +float cdist(vec2 coord) { + return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0; +} +float blueNoise(){ + return fract(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 } -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +// blindness fogs +uniform float blindness; +uniform float darknessFactor; void main() { -/* DRAWBUFFERS:6 */ + /* DRAWBUFFERS:7 */ + float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.); + vec3 col = texture2D(colortex5,texcoord).rgb; -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); + #if DOF_QUALITY >= 0 + /*--------------------------------*/ + 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); + /*--------------------------------*/ + float dofLodLevel = pcoc * 200.0; + for ( int i = 0; i < BOKEH_SAMPLES; i++) { + bcolor += texture2DLod(colortex5, texcoord.xy + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).rgb; + } + col = bcolor/BOKEH_SAMPLES; + #endif -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 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); -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); + vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5*BLOOM_QUALITY).rgb/2./7.0; -vec2 tc64 = texcoord*vec2(32.0,1./2.)-vec2(0.96875*resScale.x+20.*texelSize.x,0.)*32.0; -if (tc64.x > 0.0 && tc64.y > 0.0 && tc64.x < 1.0*resScale.x && tc64.y <1.0*resScale.y) -gl_FragData[0].xyz = gauss1D(tc64/2,gaussDir,0.0005,60); + float lightScat = clamp(BLOOM_STRENGTH * 0.05 * pow(exposure.a ,0.2) ,0.0,1.0)*vignette; -gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); -} + 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); + +// #ifdef display_LUT +// vec2 movedTC = texcoord ; +// if(movedTC.x < 0.4 ) col.rgb = texture2D(colortex4,movedTC/2).rgb * 0.001; +// #endif + + + + + #ifndef USE_ACES_COLORSPACE_APPROXIMATION + col = LinearTosRGB(TONEMAP(col)); + #else + col = col * ACESInputMat; + col = TONEMAP(col); + + col = LinearTosRGB(clamp(col * ACESOutputMat, 0.0, 1.0)); + #endif + + + gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0); +} \ No newline at end of file diff --git a/shaders/composite11.vsh b/shaders/composite11.vsh index 568bb90..fb9777e 100644 --- a/shaders/composite11.vsh +++ b/shaders/composite11.vsh @@ -1,9 +1,24 @@ #version 120 +#extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" -#include "lib/res_params.glsl" -uniform float viewWidth; -uniform float viewHeight; + + varying vec2 texcoord; +flat varying vec4 exposure; +flat varying vec2 rodExposureDepth; +uniform sampler2D colortex4; + +uniform vec2 texelSize; +uniform int framemod8; +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -11,11 +26,13 @@ varying vec2 texcoord; //////////////////////////////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.); + + + 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/composite12.fsh b/shaders/composite12.fsh deleted file mode 100644 index da17b54..0000000 --- a/shaders/composite12.fsh +++ /dev/null @@ -1,62 +0,0 @@ -#version 120 -#include "lib/settings.glsl" -//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 deleted file mode 100644 index 82dc7ae..0000000 --- a/shaders/composite12.vsh +++ /dev/null @@ -1,23 +0,0 @@ -#version 120 - -#include "lib/settings.glsl" -#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 deleted file mode 100644 index 06b5762..0000000 --- a/shaders/composite14.fsh +++ /dev/null @@ -1,105 +0,0 @@ -#version 120 - -#include "lib/settings.glsl" -//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 deleted file mode 100644 index 97113b9..0000000 --- a/shaders/composite14.vsh +++ /dev/null @@ -1,18 +0,0 @@ -#version 120 -#include "lib/settings.glsl" -#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 deleted file mode 100644 index 60ebfb3..0000000 --- a/shaders/composite15.fsh +++ /dev/null @@ -1,129 +0,0 @@ -#version 120 -//Vignetting, applies bloom, applies exposure and tonemaps the final image -#extension GL_EXT_gpu_shader4 : enable - -#include "/lib/settings.glsl" - -#include "/lib/res_params.glsl" - - -flat varying vec4 exposure; -flat varying vec2 rodExposureDepth; -varying vec2 texcoord; -uniform sampler2D colortex4; -const bool colortex5MipmapEnabled = true; -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" -#include "/lib/bokeh.glsl" - -float cdist(vec2 coord) { - return max(abs(coord.s-0.5),abs(coord.t-0.5))*2.0; -} -float blueNoise(){ - return fract(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; - - #if DOF_QUALITY >= 0 - /*--------------------------------*/ - 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); - /*--------------------------------*/ - float dofLodLevel = pcoc * 200.0; - for ( int i = 0; i < BOKEH_SAMPLES; i++) { - bcolor += texture2DLod(colortex5, texcoord.xy + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).rgb; - } - col = bcolor/BOKEH_SAMPLES; - #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 deleted file mode 100644 index d9072cb..0000000 --- a/shaders/composite15.vsh +++ /dev/null @@ -1,24 +0,0 @@ -#version 120 -#extension GL_EXT_gpu_shader4 : enable -#include "lib/settings.glsl" - - -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 index 7b36d1f..4e85ee2 100644 --- a/shaders/composite2.fsh +++ b/shaders/composite2.fsh @@ -1,14 +1,14 @@ #version 120 -//Render sky, volumetric clouds, direct lighting +//Volumetric fog rendering #extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" -const bool colortex5MipmapEnabled = true; -// const bool colortex4MipmapEnabled = true; -\ -const bool shadowHardwareFiltering = true; -flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +flat varying vec3 sunColor; +flat varying vec3 moonColor; +flat varying vec3 avgAmbient2; + +flat varying vec4 lightCol; flat varying vec3 ambientUp; flat varying vec3 ambientLeft; flat varying vec3 ambientRight; @@ -16,291 +16,67 @@ 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 +flat varying float fogAmount; +flat varying float VFAmount; +flat varying float FogSchedule; +uniform sampler2D noisetex; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; 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; +flat varying vec3 refractedSunVec; +flat varying vec3 WsunVec; + +// uniform sampler2D colortex1; +// uniform sampler2D colortex3; +// // uniform sampler2D colortex0; +// uniform sampler2D colortex7; +// uniform sampler2D colortex13; +// 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 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) +uniform float frameTimeCounter; +uniform int isEyeInWater; +uniform vec2 texelSize; -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); -} - -vec3 normVec (vec3 vec){ - return vec*inversesqrt(dot(vec,vec)); -} -vec3 viewToWorld(vec3 viewPosition) { - vec4 pos; - pos.xyz = viewPosition; - pos.w = 0.0; - pos = gbufferModelViewInverse * pos; - return pos.xyz; -} -// #include "lib/settings.glsl" -// #include "lib/biome_specifics.glsl" -#include "lib/res_params.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/stars.glsl" +#include "/lib/res_params.glsl" +// #include "lib/biome_specifics.glsl" + +#define TIMEOFDAYFOG #include "lib/volumetricClouds.glsl" -#include "lib/waterBump.glsl" -#include "lib/specular.glsl" -// #include "/lib/climate_settings.glsl" -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){ +float R2_dither(){ vec2 alpha = vec2(0.75487765, 0.56984026); - return fract(alpha * n); + return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ; } - -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; +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; } -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; +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); } - -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; -} -vec2 hash21(float p) -{ - vec3 p3 = fract(vec3(p) * vec3(.1031, .1030, .0973)); - p3 += dot(p3, p3.yzx + 33.33); - return fract((p3.xx+p3.yz)*p3.zy); - -} - -vec2 vogel_disk_7[7] = vec2[]( - vec2(0.2506005557551467 , -0.08481388042204699) , - vec2(-0.3579961502930998 , 0.22787736539225004) , - vec2(0.035586177529474045, -0.6801399443380787) , - vec2(0.4135705583782951 , 0.4763465923710499) , - vec2(-0.8061879331972175 , -0.2244701335533563) , - vec2(0.7312484456783402 , -0.560572449689252) , - vec2(-0.26682165385093876, 0.8457724502394341) -); - -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); - // vec2 sp = vogel_disk_7[j]; - // 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); - vec2 sampleOffset = sp*rd; - - 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*2.0)/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 DoContrast(vec3 Color){ - - float Contrast = log(50.0); - - return clamp(mix(vec3(0.5), Color, Contrast) ,0,255); -} - - -void ssDO(inout vec3 lighting, vec3 fragpos,float mulfov, vec2 noise, vec3 normal, vec3 RPnormal, vec2 texcoord, vec3 ambientCoefs, vec2 lightmap, float sunlight){ - const int Samples = 7; - vec3 Radiance = vec3(0); - float occlusion = 0.0; - - 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 ); - float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*5/50.0; - - - float rd = mulfov2 * 0.1 ; - - - vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ; - - vec3 NormalSpecific = viewToWorld(normal); - - - for (int j = 0; j < Samples ;j++) { - - vec2 sp = tapLocation_alternate(j, 0.0, 7, 20, blueNoise()); - 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 = 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); - - float NdotV2 = clamp(dot(vec*inversesqrt(dsquared), normalize(RPnormal)),0.,1.); - - 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); - - - vec3 previousPosition = mat3(gbufferModelViewInverse) * t0 + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; - previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; - previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5; - - if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ - Radiance += NdotV2*texture2D(colortex5,previousPosition.xy).rgb ; - } - - } - } - } - - lighting = vec3(1) + Radiance/Samples; -} - -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 += skyLightDir; - - occlude += normalize(rayHit.z - 1.0) / (1.1-rayDir.y); - - - } - // occlude = mix( occlude,1, inShadow); - // occlude = occlude*0.5 + 0.5; - // lighting *= 2.5; - lighting *= occlude/nrays; -} - - - -// 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 = DoContrast(texture2D(colortex5,previousPosition.xy).rgb) ; -// else -// intRadiance += lighting*skyLightDir; // make sure ambient light exists but at screen edges when you turn - - -// }else{ -// intRadiance += lighting*skyLightDir; -// } -// } -// lighting = intRadiance/nrays; -// } - - -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 occlusion = vec3(0.0); - vec3 sunlight =vec3(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 - - // vec3 AO = lighting * (normalize(rayHit.z - 1.0) / (1.1-rayDir.y)); - 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 = DoContrast(texture2D(colortex5,previousPosition.xy).rgb ) ; +void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ + int spCount = 8; + + vec3 start = toShadowSpaceProjected(rayStart); + vec3 end = toShadowSpaceProjected(rayEnd); + vec3 dV = (end-start); + + //limit ray length at 32 blocks for performance and reducing integration error + //you can't see above this anyway + float maxZ = min(rayLength,32.0)/(1e-8+rayLength); + dV *= maxZ; + vec3 dVWorld = mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; + rayLength *= maxZ; + float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; + 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 phase = phaseg(VdotL,0.7) * 1.5 + 0.02; + float expFactor = 11.0; + vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; + vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; + float cloudShadow = 1; + for (int i=0;i 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){ - // intRadiance += DoContrast(texture2D(colortex5,previousPosition.xy).rgb) ; - // }else{ - // intRadiance += lighting; - // } - // // occlude += 1.0; - - // }else{ - // intRadiance += lighting; - // } - - // occlude = (lighting/nrays)*(normalize(rayHit.z - 1.0) / (1.1-rayDir.y)); - - } - lighting = occlusion + 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; - } + inColor += vL; } +#include "lib/volumetricFog.glsl" //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// + void main() { +/* DRAWBUFFERS:0 */ + float lightleakfix = max(eyeBrightnessSmooth.y,0)/240.; - 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; - - #ifdef AEROCHROME_MODE - totEpsilon *= 10.0; - scatterCoef *= 0.1; - #endif - - 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; - vec3 np3 = normVec(p3); - p3 += gbufferModelViewInverse[3].xyz; - - 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; - - 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; + vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize; + float z = texture2D(depthtex0,tc).x; - gl_FragData[0].rgb = clamp(fp10Dither(color * 5.0,triangularize(noise)),0.0,65000.); - - }else{//land + if (isEyeInWater == 0){ + vec3 fragpos = toScreenSpace(vec3(tc/RENDER_SCALE,z)); - ////// ----- 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); + vec4 VL_Fog = getVolumetricRays(fragpos,blueNoise(),avgAmbient); - 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; + gl_FragData[0] = clamp(VL_Fog,0.0,65000.); + } else { - if (diffuseSun > 0.001) { + 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); - 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); + #ifdef AEROCHROME_MODE + totEpsilon *= 2.0; + scatterCoef *= 10.0; #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 + vec3 fragpos = toScreenSpace(vec3(tc/RENDER_SCALE,z)); + float noise = R2_dither(); + vec3 vl = vec3(0.0); + float estEyeDepth = clamp((14.0-eyeBrightnessSmooth.y/255.0*16.0)/14.0,0.,1.0); + estEyeDepth *= estEyeDepth*estEyeDepth*34.0; - 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 + estEyeDepth = max(Water_Top_Layer - cameraPosition.y,0.0); - - 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 + 1.0 ) * 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, (directLightCol/127.0), diffuseSun*shading); - #endif - #if indirect_effect == 4 - if (!hand) ssDO(ambientLight, fragpos, 1.0, blueNoise(gl_FragCoord.xy).rg, FlatNormals, worldToView(slope_normal) , texcoord, ambientCoefs, lightmap.xy, diffuseSun*shading ) ; - #endif - - - 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 - // do this after water and stuff is done because yea - - Indirect_lighting = ambientLight; - //combine all light sources - Direct_lighting = (Diffuse_final + SSS) * (directLightCol/127.0) ; - // Direct_lighting = max(Diffuse_final ,SSS) * (directLightCol/127.0) ; - gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * albedo; - - #ifdef Specular_Reflections - vec3 fragpos_spec = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0)); - vec3 p3_spec = mat3(gbufferModelViewInverse) * fragpos_spec; - vec3 np3_spec = normVec(p3_spec); - - MaterialReflections(texcoord, 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 + waterVolumetrics(vl, vec3(0.0), fragpos, estEyeDepth, estEyeDepth, length(fragpos), noise, totEpsilon, scatterCoef, (ambientUp*8./150./3.*0.5) , lightCol.rgb*8./150./3.0*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)), dot(normalize(fragpos), normalize(sunVec) )); + gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.); } - - - #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)); - } - - /* RENDERTARGETS:3 */ -} \ No newline at end of file +} diff --git a/shaders/composite2.vsh b/shaders/composite2.vsh index f59ec90..6c1b5d7 100644 --- a/shaders/composite2.vsh +++ b/shaders/composite2.vsh @@ -1,32 +1,51 @@ #version 120 #extension GL_EXT_gpu_shader4 : enable + #include "lib/settings.glsl" -flat varying vec3 WsunVec; -flat varying vec3 avgAmbient; +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 vec4 lightCol; -flat varying float tempOffsets; + + +flat varying vec3 sunColor; +flat varying vec3 moonColor; +flat varying vec3 avgAmbient; + flat varying vec2 TAA_Offset; -flat varying vec3 zMults; -attribute vec4 mc_Entity; +flat varying float tempOffsets; + +flat varying float fogAmount; +flat varying float VFAmount; +flat varying float FogSchedule; + + +flat varying vec3 WsunVec; +flat varying vec3 refractedSunVec; + 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 float rainStrength; +uniform int isEyeInWater; uniform int frameCounter; +// uniform int worldTime; +uniform mat4 gbufferModelViewInverse; + +#include "/lib/util.glsl" +#include "/lib/res_params.glsl" +// #include "lib/biome_specifics.glsl" + + +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(-1.,3.)/8., vec2(5.0,1.)/8., @@ -35,24 +54,27 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(-7.,-1.)/8., vec2(3,7.)/8., vec2(7.,-7.)/8.); +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// - -#include "/lib/util.glsl" -#include "/lib/res_params.glsl" void main() { + tempOffsets = HaltonSeq2(frameCounter%10000); gl_Position = ftransform(); - + gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0; #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; + + sunColor = texelFetch2D(colortex4,ivec2(12,37),0).rgb; + moonColor = texelFetch2D(colortex4,ivec2(13,37),0).rgb; + avgAmbient = texelFetch2D(colortex4,ivec2(1,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; @@ -60,16 +82,32 @@ void main() { // 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; + 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); - zMults = vec3((far * near)*2.0,far+near,far-near); - - - + refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333); } diff --git a/shaders/composite3.fsh b/shaders/composite3.fsh index d8d05ab..c7be7d4 100644 --- a/shaders/composite3.fsh +++ b/shaders/composite3.fsh @@ -1,80 +1,305 @@ #version 120 -//Render sky, volumetric clouds, direct lighting +//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog #extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" -uniform vec2 texelSize; +flat varying vec3 zMults; +flat varying vec2 TAA_Offset; + + + +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 colortex4; +uniform sampler2D colortex15; +uniform vec2 texelSize; -uniform int frameCounter; +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 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 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; + +#include "lib/waterBump.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, vec2 distort){ + 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 + distort)*scaling; + ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION + distort); + 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)); } -uniform int isEyeInWater; -uniform ivec2 eyeBrightnessSmooth; -uniform float blindness; -uniform float darknessFactor; - -#include "lib/sky_gradient.glsl" +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() { - /* DRAWBUFFERS:3 */ + vec2 texcoord = gl_FragCoord.xy*texelSize; + /* DRAWBUFFERS:73 */ - vec2 texcoord = gl_FragCoord.xy*texelSize; - gl_FragData[0].rgb = texture2D(colortex3, texcoord).rgb; + vec4 trpData = texture2D(colortex7,texcoord); - ///////////////// border fog + bool iswater = trpData.a > 0.99; + float translucentAlpha = trpData.a; + + // vec4 speculartex = texture2D(colortex8,texcoord); // translucents + // float sunlight = speculartex.b; + + //3x3 bilateral upscale from half resolution + float z = texture2D(depthtex0,texcoord).x; + float z2 = texture2D(depthtex1,texcoord).x; + float frDepth = ld(z2); + + // vec4 vl = texture2D(colortex0,texcoord * 0.5); + + + 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); + + float lightleakfix = clamp((eyeBrightnessSmooth.y )/240.0,0.0,1.0); + + + float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); // bloomy rain effect + + + vec4 Translucent_Programs = texture2D(colortex2,texcoord); // the shader for all translucent progams. -#ifdef BorderFog vec2 tempOffset = TAA_Offset; - float z = texture2D(depthtex0,texcoord).x; - - vec3 fragpos = toScreenSpace(vec3(texcoord -vec2(tempOffset)*texelSize*0.5,z)); + 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); - vec3 worldpos = p3 + (gbufferModelViewInverse[3].xyz+cameraPosition) ; + + vec2 refractedCoord = texcoord; + float glassdepth = clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15); + + #ifdef Refraction + refractedCoord += (normals.xy * glassdepth) * RENDER_SCALE; + + float refractedalpha = texture2D(colortex13,refractedCoord).a; + if(refractedalpha <= 0.0) refractedCoord = texcoord; // remove refracted coords on solids + #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 sky = skyFromTex(np3,colortex4) / 150. * 5.; + vec3 color = texture2D(colortex3,refractedCoord).rgb; - float fog = 1.0 - clamp( exp(-pow(length(fragpos / far),10.)*4.0) ,0.0,1.0); - + #ifdef BorderFog + vec3 sky = skyFromTex(np3,colortex4) / 150. * 5.0; + float fog = 1.0 - clamp(exp(-pow(length(fragpos / far),10.)*4.0) ,0.0,1.0); + float heightFalloff = clamp( pow(abs(np3.y-1.01),5) ,0,1) ; - 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) color.rgb = mix(color.rgb, sky, fog*heightFalloff* lightleakfix); + #endif - if(z < 1.0 && isEyeInWater == 0) gl_FragData[0].rgb = mix(gl_FragData[0].rgb, sky, fog*lightleakfix*heightFalloff ) ; + vec4 vl = BilateralUpscale(colortex0,depthtex1,gl_FragCoord.xy,frDepth, vec2(0.0)); + + if (Translucent_Programs.a > 0.0){ + #ifdef Glass_Tint + vec3 GlassAlbedo = texture2D(colortex13,texcoord).rgb * 5.0; + color = color*GlassAlbedo.rgb + color * clamp(pow(1.0-luma(GlassAlbedo.rgb),10.),0.0,1.0); + #endif + + color = color*(1.0-Translucent_Programs.a) + Translucent_Programs.rgb; + + #ifdef BorderFog + if(z < 1.0 && isEyeInWater == 0) color.rgb = mix(color.rgb, sky, fog * heightFalloff * lightleakfix); + #endif + } -#endif + //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)) ; + } + #endif + + // underwater fog + if (isEyeInWater == 1){ + float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0); + color.rgb *= fogfade; + vl.a *= fogfade*0.70+0.3 ; + } + + + color *= vl.a; + color += vl.rgb; + + if(rainDrops > 0.0) vl.a *= clamp(exp2(-rainDrops*5),0.,1.); // bloomy rain effect + 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( 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); + + #ifdef display_LUT + vec2 movedTC = texcoord ; + if(texcoord.x < 0.45 ) color.rgb = texture2D(colortex4,movedTC).rgb / 150. * 5.0; + #endif + + gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); } \ No newline at end of file diff --git a/shaders/composite3.vsh b/shaders/composite3.vsh index a047572..bd893f8 100644 --- a/shaders/composite3.vsh +++ b/shaders/composite3.vsh @@ -2,13 +2,20 @@ #extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" -flat varying float tempOffsets; +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; - -#include "/lib/util.glsl" +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., @@ -18,13 +25,30 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(3,7.)/8., vec2(7.,-7.)/8.); -void main() { - gl_Position = ftransform(); - + +flat varying vec3 noooormal; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// - TAA_Offset = offsets[frameCounter%8]; +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/composite4.fsh b/shaders/composite4.fsh new file mode 100644 index 0000000..b9d938b --- /dev/null +++ b/shaders/composite4.fsh @@ -0,0 +1,46 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + +#include "lib/settings.glsl" +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/world1/texture/composite4.vsh b/shaders/composite4.vsh similarity index 72% rename from shaders/world1/texture/composite4.vsh rename to shaders/composite4.vsh index e6e3e92..09df2ce 100644 --- a/shaders/world1/texture/composite4.vsh +++ b/shaders/composite4.vsh @@ -1,10 +1,9 @@ #version 120 #extension GL_EXT_gpu_shader4 : enable -varying vec2 texcoord; -flat varying vec3 zMults; -uniform float far; -uniform float near; +#include "lib/settings.glsl" + +#include "/lib/res_params.glsl" //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -12,8 +11,8 @@ uniform float near; //////////////////////////////VOID MAIN////////////////////////////// void main() { - zMults = vec3((far * near)*2.0,far+near,far-near); gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - + #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 index add8ab3..4fc6450 100644 --- a/shaders/composite5.fsh +++ b/shaders/composite5.fsh @@ -1,388 +1,518 @@ #version 120 -//Volumetric fog rendering +//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader) + #extension GL_EXT_gpu_shader4 : enable #include "lib/settings.glsl" +#include "lib/res_params.glsl" -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; + +//TAA OPTIONS + +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 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; +*/ + + + +#ifdef SCREENSHOT_MODE + /* + const int colortex5Format = RGBA32F; //TAA buffer (everything) + */ +#else + /* + const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) + */ +#endif + +varying vec2 texcoord; +flat varying float exposureA; flat varying float tempOffsets; -flat varying float fogAmount; -flat varying float VFAmount; -flat varying float FogSchedule; -uniform sampler2D noisetex; + +uniform sampler2D colortex0; +uniform sampler2D colortex1; +uniform sampler2D colortex3; +uniform sampler2D colortex5; +uniform sampler2D colortex6; +// uniform sampler2D colortex10; +uniform sampler2D colortex13; + 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/Shadow_Params.glsl" -#include "lib/color_transforms.glsl" -#include "lib/color_dither.glsl" +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" -#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 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) ; + 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; +//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; + } -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 -} +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; -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)/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 1.0) + return vec3(p_clip) + v_clip / ma_unit; + else + return q; } - return mat2x3(vL,absorbance); +vec3 toClipSpace3Prev(vec3 viewSpacePosition) { + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; } -float waterCaustics(vec3 wPos, vec3 lightSource) { // water waves - - vec2 pos = wPos.xz + (lightSource.xz/lightSource.y*wPos.y); - if(isEyeInWater==1) pos = wPos.xz - (lightSource.xz/lightSource.y*wPos.y); // fix the fucky - vec2 movement = vec2(-0.035*frameTimeCounter); - float caustic = 0.0; - float weightSum = 0.0; - float radiance = 2.39996; - mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance))); - - const vec2 wave_size[4] = vec2[]( - vec2(64.), - vec2(32.,16.), - vec2(16.,32.), - vec2(48.) - ); - - for (int i = 0; i < 4; i++){ - pos = rotationMatrix * pos; - - vec2 speed = movement; - float waveStrength = 1.0; - - if( i == 0) { - speed *= 0.15; - waveStrength = 2.0; - } - - float small_wave = texture2D(noisetex, pos / wave_size[i] + speed ).b * waveStrength; - - caustic += max( 1.0-sin( 1.0-pow( 0.5+sin( small_wave*3.0 )*0.5, 25.0) ), 0); - - weightSum -= exp2(caustic*0.1); - } - return caustic / weightSum; +vec3 tonemap(vec3 col){ + return col/(1+luma(col)); } -vec3 normVec (vec3 vec){ - return vec*inversesqrt(dot(vec,vec)); +vec3 invTonemap(vec3 col){ + return col/(1-luma(col)); } -void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEyeDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){ - int spCount = 8; +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 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; - 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; - vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; - float cloudShadow = 1; - for (int i=0;i vec3(0.0) ) closestToCamera = closestToCamera - EntityVelocity; + + #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 ; + // previousPosition -= abs(EntityVelocity); + + DEBUG = previousPosition; + + //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:0 */ - float lightleakfix = max(eyeBrightnessSmooth.y,0)/240.; - if (isEyeInWater == 0){ +/* DRAWBUFFERS:5 */ - vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize; - float z = texture2D(depthtex0,tc).x; - vec3 fragpos = toScreenSpace(vec3(tc/RENDER_SCALE,z)); - float noise = blueNoise(); - mat2x3 vl = getVolumetricRays(noise,fragpos,blueNoise()); - float absorbance = dot(vl[1],vec3(0.22,0.71,0.07)); - gl_FragData[0] = clamp(vec4(vl[0],absorbance),0.000001,65000.); - } else { - float dirtAmount = Dirt_Amount; - vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); - vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B); - vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon; - vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B); - #ifdef AEROCHROME_MODE - totEpsilon *= 2.0; - scatterCoef *= 10.0; + 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 = vec3(0.0); + + // vec3 motionVector = texture2D(colortex10,texcoord).xyz ; + // vec3 motionVector = texelFetch(colortex10, ivec2(gl_FragCoord.xy), 0).xyz * 2 - 1; + + // if((motionVector.x+motionVector.y+motionVector.z) / 3 < 0.00001) motionVector = vec3(0.0); + // vec3 viewpos = motionVector; + // // vec3 eyepos = mat3(gbufferModelViewInverse) * viewpos; + // // vec3 worldPos = eyepos + (cameraPosition + gbufferModelViewInverse[3].xyz); + // // vec3 feetPos = worldPos - cameraPosition; + + // vec4 clippos = gbufferProjection * vec4(motionVector,1.0); + + // vec3 ndcPos = projectAndDivide(gbufferProjectionInverse, viewpos); + // vec3 screenPos = ndcPos * 0.5 + 0.5; + + + vec3 DEBUG = vec3(0.0); + color += TAA_hq(hand, translucentCol, vec3(0.0),DEBUG); + + + gl_FragData[0].rgb = clamp(fp10Dither(color ,triangularize(R2_dither())),6.11*1e-5,65000.0); + // gl_FragData[0].rgb = motionVector; #endif - vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize; - float z = texture2D(depthtex0,tc).x; - vec3 fragpos = toScreenSpace(vec3(tc/RENDER_SCALE,z)); - float noise = R2_dither(); - vec3 vl = vec3(0.0); - float estEyeDepth = clamp((14.0-eyeBrightnessSmooth.y/255.0*16.0)/14.0,0.,1.0); - estEyeDepth *= estEyeDepth*estEyeDepth*34.0; - - #ifndef lightMapDepthEstimation - estEyeDepth = max(Water_Top_Layer - cameraPosition.y,0.0); + #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); - waterVolumetrics(vl, vec3(0.0), fragpos, estEyeDepth, estEyeDepth, length(fragpos), noise, totEpsilon, scatterCoef, (ambientUp*8./150./3.*0.5) , lightCol.rgb*8./150./3.0*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)), dot(normalize(fragpos), normalize(sunVec) )); - gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.); } +#endif } diff --git a/shaders/composite5.vsh b/shaders/composite5.vsh index 568251e..3c77d0c 100644 --- a/shaders/composite5.vsh +++ b/shaders/composite5.vsh @@ -3,110 +3,16 @@ #include "lib/settings.glsl" -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 sunColor; -flat varying vec3 moonColor; -flat varying vec3 avgAmbient; - -flat varying vec2 TAA_Offset; - +varying vec2 texcoord; +flat varying float exposureA; flat varying float tempOffsets; - -flat varying float fogAmount; -flat varying float VFAmount; -flat varying float FogSchedule; - - -flat varying vec3 WsunVec; -flat varying vec3 refractedSunVec; - uniform sampler2D colortex4; -uniform vec3 sunPosition; -uniform float sunElevation; -uniform float rainStrength; -uniform int isEyeInWater; uniform int frameCounter; -// uniform int worldTime; -uniform mat4 gbufferModelViewInverse; - - #include "/lib/util.glsl" -#include "/lib/res_params.glsl" -// #include "lib/biome_specifics.glsl" - - -float luma(vec3 color) { - return dot(color,vec3(0.21, 0.72, 0.07)); -} -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() { + tempOffsets = HaltonSeq2(frameCounter%10000); gl_Position = ftransform(); - gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0; - #ifdef TAA_UPSCALING - gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; - #endif - vec3 sc = texelFetch2D(colortex4,ivec2(6,37),0).rgb; - - 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; - - - lightCol.a = float(sunElevation > 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); + texcoord = gl_MultiTexCoord0.xy; + exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r; } diff --git a/shaders/composite6.fsh b/shaders/composite6.fsh index 5f61ee9..937e315 100644 --- a/shaders/composite6.fsh +++ b/shaders/composite6.fsh @@ -1,313 +1,50 @@ #version 120 -//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog -#extension GL_EXT_gpu_shader4 : enable +//downsample 1st pass (half res) for bloom + #include "lib/settings.glsl" - -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 sampler2D colortex8; uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; -flat varying vec3 noooormal; -flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) -flat varying vec3 WsunVec; +#include "lib/res_params.glsl" -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/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); +/* DRAWBUFFERS:3 */ - vec4 data = texture2D(colortex11,texcoord); // translucents - vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); - vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); +vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); +vec2 quarterResTC = gl_FragCoord.xy*texelSize*2.*resScale/BLOOM_QUALITY; - vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) ); +// float emissives1 = texture2D(colortex8,quarterResTC).a; +// float emissives2 = emissives1 < 1.0 ? emissives1 : 0.0; - vec4 data_terrain = texture2D(colortex1,texcoord); // terraom - vec4 dataUnpacked1_terrain = vec4(decodeVec2(data_terrain.z),decodeVec2(data_terrain.w)); + // 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; - bool hand = (abs(dataUnpacked1_terrain.w-0.75) < 0.01); + //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; - vec2 refractedCoord = texcoord; - - float rainDrops = clamp(texture2D(colortex9,texcoord).a, 0.0,1.0); // bloomy rain effect + 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); - - 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 index bd893f8..97113b9 100644 --- a/shaders/composite6.vsh +++ b/shaders/composite6.vsh @@ -1,32 +1,8 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable - #include "lib/settings.glsl" -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; +#include "lib/res_params.glsl" +uniform float viewWidth; +uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -34,21 +10,9 @@ flat varying vec3 noooormal; //////////////////////////////VOID MAIN////////////////////////////// void main() { - zMults = vec3(1.0/(far * near),far+near,far-near); + //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(); - #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); + //*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/composite7.fsh b/shaders/composite7.fsh index b9d938b..600234b 100644 --- a/shaders/composite7.fsh +++ b/shaders/composite7.fsh @@ -1,10 +1,12 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable - #include "lib/settings.glsl" +//downsample 1st pass (half res) for bloom +#include "lib/res_params.glsl" uniform sampler2D colortex3; -// Compute 3x3 min max for TAA - +// uniform sampler2D colortex8; +uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -12,35 +14,31 @@ uniform sampler2D colortex3; //////////////////////////////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; + +/* 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/composite7.vsh b/shaders/composite7.vsh index 09df2ce..23439b2 100644 --- a/shaders/composite7.vsh +++ b/shaders/composite7.vsh @@ -1,9 +1,8 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable - #include "lib/settings.glsl" - -#include "/lib/res_params.glsl" +#include "lib/res_params.glsl" +uniform float viewWidth; +uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -11,8 +10,9 @@ //////////////////////////////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(); - #ifdef TAA_UPSCALING - gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0; - #endif + //*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/composite8.fsh b/shaders/composite8.fsh index 0461935..513baa1 100644 --- a/shaders/composite8.fsh +++ b/shaders/composite8.fsh @@ -1,452 +1,62 @@ #version 120 -//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader) - -#extension GL_EXT_gpu_shader4 : enable - #include "lib/settings.glsl" +//6 Horizontal gaussian blurs and horizontal downsampling #include "lib/res_params.glsl" - -//TAA OPTIONS - -const int noiseTextureResolution = 32; - -const int RGBA32F = 1; -const int R11F_G11F_B10F = 1; -#ifdef SCREENSHOT_MODE - const int colortex5Format = RGBA32F; //TAA buffer (everything) -#else - const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) -#endif - - -/* -const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2) + low res VL (composite5->composite15) -const int colortex1Format = RGBA16; //terrain gbuffer (gbuffer->composite2) -const int colortex2Format = RGBA16F; //forward + transparencies (gbuffer->composite4) -const int colortex3Format = R11F_G11F_B10F; //frame buffer + bloom (deferred6->final) -const int colortex4Format = RGBA16F; //light values and skyboxes (everything) - -const int colortex6Format = R11F_G11F_B10F; //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; +varying vec2 texcoord; 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; +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); } -vec3 toClipSpace3Prev(vec3 viewSpacePosition) { - return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + return tot.rgb/max(1.0,tot.a); } -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////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// void main() { +/* DRAWBUFFERS:6 */ -/* DRAWBUFFERS:5 */ +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); - // vec3 motionVector = texture2D(colortex10,texcoord).xyz ; +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); - // vec3 viewpos = motionVector; - // vec3 eyepos = mat3(gbufferModelViewInverse) * viewpos; - // vec3 worldPos = eyepos + (cameraPosition + gbufferModelViewInverse[3].xyz); - // vec3 feetPos = worldPos - cameraPosition; +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); - // vec4 clippos = gbufferProjection * vec4(viewpos,1.0); +vec2 tc16 = texcoord*vec2(8.0,1./2.)-vec2(0.875*resScale.x+12.*texelSize.x,0.)*8.0; +if (tc16.x > 0.0 && tc16.y > 0.0 && tc16.x < 1.0*resScale.x && tc16.y <1.0*resScale.y) +gl_FragData[0].xyz = gauss1D(tc16/2,gaussDir,0.0085,12); - // vec3 ndcPos = projectAndDivide(gbufferProjectionInverse, viewpos); - // vec3 screenPos = ndcPos * 0.5 + 0.5; +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); - // vec3 movement = ( cameraPosition - previousCameraPosition); +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].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 +gl_FragData[0].rgb = clamp(gl_FragData[0].rgb,0.0,65000.); } diff --git a/shaders/composite8.vsh b/shaders/composite8.vsh index 3c77d0c..568bb90 100644 --- a/shaders/composite8.vsh +++ b/shaders/composite8.vsh @@ -1,18 +1,21 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable - #include "lib/settings.glsl" - +#include "lib/res_params.glsl" +uniform float viewWidth; +uniform float viewHeight; varying vec2 texcoord; -flat varying float exposureA; -flat varying float tempOffsets; -uniform sampler2D colortex4; -uniform int frameCounter; -#include "/lib/util.glsl" -void main() { +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// - tempOffsets = HaltonSeq2(frameCounter%10000); +void main() { + vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0))/BLOOM_QUALITY; gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r; + //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/composite9.fsh b/shaders/composite9.fsh index 937e315..da17b54 100644 --- a/shaders/composite9.fsh +++ b/shaders/composite9.fsh @@ -1,50 +1,62 @@ #version 120 -//downsample 1st pass (half res) for bloom - #include "lib/settings.glsl" -uniform sampler2D colortex5; -// uniform sampler2D colortex8; -uniform vec2 texelSize; -uniform float viewWidth; -uniform float viewHeight; - +//6 Vertical gaussian blurs and vertical downsampling #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); - - +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/composite9.vsh b/shaders/composite9.vsh index 97113b9..82dc7ae 100644 --- a/shaders/composite9.vsh +++ b/shaders/composite9.vsh @@ -1,8 +1,10 @@ #version 120 + #include "lib/settings.glsl" #include "lib/res_params.glsl" uniform float viewWidth; uniform float viewHeight; +varying vec2 texcoord; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -10,9 +12,12 @@ uniform float viewHeight; //////////////////////////////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.)); + vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0))/BLOOM_QUALITY; 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; + //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/deferred.fsh b/shaders/deferred.fsh index 4b00706..95f7d50 100644 --- a/shaders/deferred.fsh +++ b/shaders/deferred.fsh @@ -36,6 +36,7 @@ uniform float rainStrength; uniform float eyeAltitude; uniform float nightVision; uniform vec3 sunVec; +flat varying vec3 WsunVec; uniform vec2 texelSize; uniform float frameTimeCounter; uniform mat4 gbufferProjection; @@ -74,10 +75,39 @@ float R2_dither(){ float blueNoise(){ return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); } +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; +} vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.); + +float luma(vec3 color) { + return dot(color,vec3(0.299, 0.587, 0.114)); +} #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); +uniform sampler2D depthtex1;//depth +// #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; +} +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() { /* DRAWBUFFERS:4 */ gl_FragData[0] = vec4(0.0); @@ -154,7 +184,7 @@ if (gl_FragCoord.x > 18. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257){ sky *= vec3(0.0, 0.18, 0.35); #endif - sky = mix(sky, vec3(0.5,0.5,0.5)*avgSky * 4000., clamp(1 - viewVector.y,0.0,1.0) * rainStrength ); + // 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); } @@ -163,23 +193,24 @@ if (gl_FragCoord.x > 18. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257){ 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)); + + vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024.,vec2(blueNoise(),R2_dither()), sunColorCloud, moonColor, ambientUp*5.0); + vec4 VL_Fog = getVolumetricRays(mat3(gbufferModelView)*viewVector*1024., fract(frameCounter/1.6180339887), ambientUp); + + 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.) ; + if(viewVector.y < -0.025) skytex = skytex * clamp( exp(viewVector.y) - 1.0,0.25,1.0) ; - skytex = skytex*clouds.a + clouds.rgb; + skytex = skytex*clouds.a + clouds.rgb/5.0; + skytex = skytex*VL_Fog.a + VL_Fog.rgb*20; - // gl_FragData[0] = vec4(skytex,1.0); - gl_FragData[0] = vec4(skytex*absorbance+vL[0].rgb,1.0); + gl_FragData[0] = vec4(skytex,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.); +gl_FragData[0].rgb = clamp(mix(temp,curr,0.07),0.0,65000.); //Exposure values if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) diff --git a/shaders/deferred.vsh b/shaders/deferred.vsh index a36b3ee..3dedc0d 100644 --- a/shaders/deferred.vsh +++ b/shaders/deferred.vsh @@ -32,6 +32,7 @@ uniform sampler2D colortex6; uniform sampler2D depthtex0; +flat varying vec3 WsunVec; uniform mat4 gbufferModelViewInverse; uniform vec3 sunPosition; uniform vec2 texelSize; @@ -246,9 +247,4 @@ void main() { 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.))); -} +} \ No newline at end of file diff --git a/shaders/deferred1.fsh b/shaders/deferred1.fsh index 306a476..4636f1e 100644 --- a/shaders/deferred1.fsh +++ b/shaders/deferred1.fsh @@ -4,6 +4,9 @@ //Computes volumetric clouds at variable resolution (default 1/4 res) +uniform float far; +uniform float near; +flat varying vec4 lightCol; flat varying vec3 sunColor; flat varying vec3 moonColor; flat varying vec3 avgAmbient; @@ -13,6 +16,7 @@ uniform sampler2D depthtex0; // uniform sampler2D colortex4; uniform sampler2D noisetex; +flat varying vec3 WsunVec; uniform vec3 sunVec; uniform vec2 texelSize; uniform float frameTimeCounter; @@ -74,26 +78,26 @@ vec3 normVec (vec3 vec){ //////////////////////////////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); + + vec2 halfResTC = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY/RENDER_SCALE+0.5+offsets[framemod8]*CLOUDS_QUALITY*RENDER_SCALE*0.5); + + float z = texture2D(depthtex0,halfResTC*texelSize).x; + + vec3 fragpos = toScreenSpace(vec3(halfResTC*texelSize,1)); - #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 + vec4 currentClouds = renderClouds(fragpos,vec2(R2_dither(),blueNoise2()), lightCol.rgb/80., moonColor/150., (avgAmbient*2.0)* 8./150./3.); + + 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 index ef88f75..a6c6771 100644 --- a/shaders/deferred1.vsh +++ b/shaders/deferred1.vsh @@ -5,15 +5,20 @@ flat varying vec3 sunColor; flat varying vec3 moonColor; +flat varying vec4 lightCol; flat varying vec3 avgAmbient; flat varying float tempOffsets; +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; +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform float sunElevation; uniform sampler2D colortex4; uniform int frameCounter; @@ -35,6 +40,12 @@ void main() { sunColor = texelFetch2D(colortex4,ivec2(12,37),0).rgb; moonColor = texelFetch2D(colortex4,ivec2(13,37),0).rgb; // avgAmbient = texelFetch2D(colortex4,ivec2(11,37),0).rgb; + + 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); // ambientUp = texelFetch2D(colortex4,ivec2(0,37),0).rgb; // ambientDown = texelFetch2D(colortex4,ivec2(1,37),0).rgb; diff --git a/shaders/entity.properties b/shaders/entity.properties index c57aaa6..fb27360 100644 --- a/shaders/entity.properties +++ b/shaders/entity.properties @@ -3,11 +3,11 @@ ### 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 +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.1200 = player 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 trader_llama # entity.5000 = minecraft:lightning_bolt -entity.9001 = minecraft:boat -layer.translucent=slime +# entity.9001 = minecraft:boat +# layer.translucent=slime diff --git a/shaders/final.fsh b/shaders/final.fsh index bbbdfa7..296a4a7 100644 --- a/shaders/final.fsh +++ b/shaders/final.fsh @@ -7,7 +7,7 @@ varying vec2 texcoord; uniform sampler2D colortex7; -uniform sampler2D noisetex; +// uniform sampler2D noisetex; uniform vec2 texelSize; uniform float viewWidth; uniform float viewHeight; @@ -94,6 +94,6 @@ void main() { 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/gbuffers_all_particles.fsh b/shaders/gbuffers_all_particles.fsh index 4612ee5..4fad8fc 100644 --- a/shaders/gbuffers_all_particles.fsh +++ b/shaders/gbuffers_all_particles.fsh @@ -2,15 +2,21 @@ varying vec4 lmtexcoord; varying vec4 color; +flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +flat varying vec3 avgAmbient; + +uniform vec3 sunVec; +flat varying vec3 WsunVec; + uniform sampler2D texture; uniform sampler2DShadow shadow; uniform sampler2D gaux1; uniform sampler2D noisetex; -uniform vec3 sunVec; -flat varying vec3 WsunVec; uniform float frameTimeCounter; uniform ivec2 eyeBrightnessSmooth; +uniform float far; +uniform float near; uniform vec2 texelSize; uniform float rainStrength; uniform mat4 gbufferProjectionInverse; @@ -19,12 +25,16 @@ uniform mat4 gbufferModelView; uniform mat4 shadowModelView; uniform mat4 shadowProjection; uniform vec3 cameraPosition; + + #include "lib/settings.glsl" #include "lib/Shadow_Params.glsl" #include "/lib/res_params.glsl" #include "lib/sky_gradient.glsl" #include "lib/volumetricClouds.glsl" +#include "lib/diffuse_lighting.glsl" + //faster and actually more precise than pow 2.2 vec3 toLinear(vec3 sRGB){ return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); @@ -72,23 +82,11 @@ float shadow2D_bicubic(sampler2DShadow tex, vec3 sc) 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////////////////////////////// @@ -104,50 +102,43 @@ void main() { #endif #ifndef WEATHER - gl_FragData[1].a = 0.0; // for bloomy rain 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 Albedo = toLinear(gl_FragData[0].rgb); + 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 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; + float Shadows = 0.0; + vec3 p3_shadow = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; + vec3 projectedShadowPosition = mat3(shadowModelView) * p3_shadow + shadowModelView[3].xyz; + projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz; - //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){ - //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 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; - } + Shadows += shadow2D_bicubic(shadow,vec3(projectedShadowPosition + vec3(0.0,0.0,-diffthresh*1.2))); + } + #ifdef CLOUDS_SHADOWS + Shadows *= GetCloudShadow(p3); + #endif - 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; + float phase = phaseg(clamp(dot(np3, WsunVec),0.0,1.0), 0.7) + 1.0 ; + vec3 Direct_lighting = DoDirectLighting(lightCol.rgb/80., Shadows, 1.0, 0.0) * phase * lightleakfix; + vec3 Indirect_lighting = DoAmbientLighting(avgAmbient, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.zw, 5.0); + + gl_FragData[0].rgb = (Direct_lighting + Indirect_lighting) * Albedo; #endif } \ No newline at end of file diff --git a/shaders/gbuffers_all_particles.vsh b/shaders/gbuffers_all_particles.vsh index 5b964e5..76e0d65 100644 --- a/shaders/gbuffers_all_particles.vsh +++ b/shaders/gbuffers_all_particles.vsh @@ -21,7 +21,9 @@ varying vec4 normalMat; #endif flat varying vec3 WsunVec; -flat varying vec4 lightCol; +flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +flat varying vec3 avgAmbient; + uniform mat4 gbufferModelViewInverse; uniform vec3 sunPosition; uniform float sunElevation; @@ -53,6 +55,7 @@ void main() { gl_Position = ftransform(); color = gl_Color; + avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; vec3 sc = texelFetch2D(colortex4,ivec2(6,37),0).rgb; lightCol.a = float(sunElevation > 1e-5)*2-1.; lightCol.rgb = sc; @@ -61,11 +64,13 @@ void main() { 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 diff --git a/shaders/gbuffers_all_solid.fsh b/shaders/gbuffers_all_solid.fsh index 008c48d..5c39cc1 100644 --- a/shaders/gbuffers_all_solid.fsh +++ b/shaders/gbuffers_all_solid.fsh @@ -5,6 +5,7 @@ +flat varying int NameTags; #ifndef USE_LUMINANCE_AS_HEIGHTMAP #ifndef MC_NORMAL_MAP @@ -41,14 +42,18 @@ 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 SPECULARTEX +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); @@ -67,22 +72,26 @@ uniform vec3 cameraPosition; uniform float rainStrength; uniform sampler2D noisetex;//depth uniform sampler2D depthtex0; -in vec3 test_motionVectors; + +in vec3 velocity; flat varying float blockID; - -flat varying vec4 TESTMASK; +flat varying int EMISSIVE; // 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 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; + vec2 coord = gl_FragCoord.xy; float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)); return noise; } - float blueNoise(){ return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); } @@ -133,11 +142,6 @@ vec4 encode (vec3 n, vec2 lightmaps){ #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); @@ -235,7 +239,7 @@ float densityAtPosSNOW(in vec3 pos){ //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// -/* RENDERTARGETS: 1,7,8,13,15 */ +/* RENDERTARGETS: 1,7,8,15 */ void main() { @@ -243,6 +247,7 @@ void main() { float noise = fract(fract(frameCounter * (1.0 / phi)) + interleaved_gradientNoise() ) ; vec3 normal = normalMat.xyz; + vec3 normal2 = normalMat.xyz; #ifdef MC_NORMAL_MAP vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w); @@ -250,6 +255,7 @@ void main() { 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)); @@ -293,19 +299,24 @@ void main() { if (dist < MAX_OCCLUSION_DISTANCE) { float depthmap = readNormal(vtexcoord.st).a; + float used_POM_DEPTH = 1.0; 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) ; - + #ifdef Adaptive_Step_length + vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0) ; + used_POM_DEPTH = 1.0; + #else + vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH; + #endif vec3 coord = vec3(vtexcoord.st, 1.0); - coord += interval; + + coord += interval * used_POM_DEPTH; 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; + coord = coord+interval * used_POM_DEPTH; + sumVec += 1.0 * used_POM_DEPTH; } if (coord.t < mincoord) { @@ -330,6 +341,10 @@ void main() { vec4 Albedo = texture2DGradARB(texture, adjustedTexCoord.xy,dcdx,dcdy) * color; + #ifdef ENTITIES + if(NameTags == 1) Albedo = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color; + #endif + #ifdef AEROCHROME_MODE vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631), AEROCHROME_PINKNESS); float gray = dot(Albedo.rgb, vec3(0.2, 01.0, 0.07)); @@ -354,6 +369,10 @@ void main() { Albedo.rgb = mix(Albedo.rgb, vec3(0.01, 0.08, 0.15), 0.5); } #endif + + #ifdef WhiteWorld + Albedo.rgb = vec3(1.0); + #endif #ifdef DISABLE_ALPHA_MIPMAPS Albedo.a = texture2DGradARB(texture, adjustedTexCoord.xy,vec2(0.),vec2(0.0)).a; @@ -379,6 +398,10 @@ void main() { NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0); normal = applyBump(tbnMatrix,NormalTex, mix(1.0,Puddle_shape,rainfall)); + + #ifdef ENTITIES + if(NameTags == 1) normal = vec3(1); + #endif #endif //////////////////////////////// @@ -393,20 +416,28 @@ void main() { vec4 data1 = clamp(encode(viewToWorld(normal), lmtexcoord.zw),0.,1.0); gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x),encodeVec2(Albedo.y,data1.y),encodeVec2(Albedo.z,data1.z),encodeVec2(data1.w,Albedo.w)); - gl_FragData[1].a = 0.0; - #else + #else + float bias = Texture_MipMap_Bias - blueNoise()*0.5; //////////////////////////////// //////////////////////////////// NORMAL //////////////////////////////// #ifdef MC_NORMAL_MAP - vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba; + vec4 NormalTex = texture2D(normals, lmtexcoord.xy, 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,1.0-Puddle_shape,rainfall) ); + + // #ifdef ENTITIES + // if(NameTags == 1 || NameTags == 2) normal = normal2; + // #endif + #ifdef ENTITIES + if(NameTags == 1) normal = vec3(1); + #endif + #endif @@ -414,19 +445,28 @@ void main() { //////////////////////////////// SPECULAR //////////////////////////////// - vec4 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rgba; + vec4 SpecularTex = texture2D(specular, lmtexcoord.xy, bias); SpecularTex.r = max(SpecularTex.r, Puddle_shape); SpecularTex.g = max(SpecularTex.g, Puddle_shape*0.04); + + #ifdef ENTITIES + if(NameTags == 1) SpecularTex = vec4(0.0); + #endif + gl_FragData[2] = SpecularTex; + if(EMISSIVE > 0) gl_FragData[2].a = 0.9; + //////////////////////////////// //////////////////////////////// ALBEDO //////////////////////////////// + + vec4 Albedo = texture2D(texture, lmtexcoord.xy, bias) * color; - vec4 Albedo = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color; - + // pain in my ass + #ifdef AEROCHROME_MODE vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631), AEROCHROME_PINKNESS); float gray = dot(Albedo.rgb, vec3(0.2, 01.0, 0.07)); @@ -473,6 +513,7 @@ void main() { else Albedo.a = 0.0; #endif + #ifdef HAND if (Albedo.a > 0.1) Albedo.a = 0.75; else Albedo.a = 0.0; @@ -482,18 +523,18 @@ void main() { //////////////////////////////// FINALIZE //////////////////////////////// - // #ifndef ENTITIES - // if(TESTMASK.r==255) Albedo.rgb = vec3(0); - // #endif - - vec4 data1 = clamp(blueNoise()/255.0 + encode(viewToWorld(normal), lmtexcoord.zw),0.0,1.0); - gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w)); + vec4 data1 = clamp( encode(viewToWorld(normal), (blueNoise()*lmtexcoord.zw/30.0) + lmtexcoord.zw), 0.0, 1.0); + gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w)); + + gl_FragData[1].a = 0.0; - #ifdef WORLD - gl_FragData[1].a = 0.0; - #endif - #endif - gl_FragData[4] = vec4(FlatNormals* 0.5 + 0.5,VanillaAO); + gl_FragData[5].x = 0; + + #ifdef ENTITIES + gl_FragData[5].xyz = velocity *0.5+0.5; + #endif + + gl_FragData[3] = vec4(FlatNormals * 0.5 + 0.5,VanillaAO); } \ No newline at end of file diff --git a/shaders/gbuffers_all_solid.vsh b/shaders/gbuffers_all_solid.vsh index 92ed9f7..092f5a6 100644 --- a/shaders/gbuffers_all_solid.vsh +++ b/shaders/gbuffers_all_solid.vsh @@ -2,6 +2,13 @@ #include "lib/settings.glsl" #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 !! +*/ + #ifndef USE_LUMINANCE_AS_HEIGHTMAP #ifndef MC_NORMAL_MAP @@ -13,23 +20,18 @@ #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 +varying vec4 color; +varying vec4 NoSeasonCol; +varying float VanillaAO; + +varying vec4 lmtexcoord; +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; @@ -37,9 +39,6 @@ varying vec4 vtexcoord; 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; @@ -47,12 +46,15 @@ float pi2wt = PI48*frameTimeCounter; attribute vec4 mc_Entity; uniform int blockEntityId; uniform int entityId; +flat varying int EMISSIVE; flat varying float blockID; -flat varying vec4 TESTMASK; flat varying int lightningBolt; +flat varying int NameTags; +in vec3 at_velocity; +out vec3 velocity; uniform mat4 gbufferModelView; uniform mat4 gbufferModelViewInverse; @@ -126,8 +128,8 @@ vec3 blackbody2(float Temp) // return dot(color,vec3(0.21, 0.72, 0.07)); // } - #define SEASONS_VSH - #include "/lib/climate_settings.glsl" +#define SEASONS_VSH +#include "/lib/climate_settings.glsl" //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -136,17 +138,31 @@ vec3 blackbody2(float Temp) //////////////////////////////VOID MAIN////////////////////////////// void main() { + + gl_Position = ftransform(); + + NameTags = 0; + + velocity = at_velocity; + + // emission and shit... + EMISSIVE = 0; + #ifndef LabPBR_Emissives + if(mc_Entity.x == 10005) EMISSIVE = 1; + #endif + + #ifdef SPIDEREYES + // gl_Position.xy = gl_Position.xy * 0.9 + 0.9 * gl_Position.w - gl_Position.w; + if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1); + EMISSIVE = 1; + #endif + + 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; - + blockID = mc_Entity.x; - #ifdef ENTITIES - test_motionVectors = at_velocity; - #endif #ifdef POM vec2 midcoord = (gl_TextureMatrix[0] * mc_midTexCoord).st; @@ -156,15 +172,17 @@ void main() { vtexcoord.xy = sign(texcoordminusmid)*0.5+0.5; #endif - vec2 lmcoord = gl_MultiTexCoord1.xy/255.; + vec2 lmcoord = gl_MultiTexCoord1.xy / 255.0; // is this even correct? lol + 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); @@ -180,15 +198,20 @@ void main() { normalMat.a = entityId == 1200 ? 0.65 : normalMat.a; #endif #endif + // normalMat.a = 0.45; - normalMat.a = 0.45; - gl_Position = ftransform(); + + + + // try and single out nametag text and then discard nametag background + if( dot(gl_Color.rgb, vec3(0.35)) < 1.0) NameTags = 1; + + if(gl_Color.a >= 0.24 && gl_Color.a <= 0.25 ) gl_Position = vec4(10,10,10,1); #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); @@ -200,20 +223,22 @@ void main() { normalMat.a = (mc_Entity.x == 10007 || mc_Entity.x == 10008) ? 0.55 : normalMat.a; // 0.55 abnormal block strong sss #endif - normalMat.a = mc_Entity.x == 10005 ? 0.8 : normalMat.a; + // normalMat.a = mc_Entity.x == 10005 ? 0.8 : normalMat.a; #ifdef WAVY_PLANTS + bool istopv = gl_MultiTexCoord0.t < mc_midTexCoord.t; + 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; + 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; + 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 @@ -223,33 +248,17 @@ void main() { } 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 + #endif #ifdef TAA_UPSCALING gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; diff --git a/shaders/gbuffers_all_translucent.fsh b/shaders/gbuffers_all_translucent.fsh index 4d31cc3..acf49e3 100644 --- a/shaders/gbuffers_all_translucent.fsh +++ b/shaders/gbuffers_all_translucent.fsh @@ -9,7 +9,6 @@ uniform sampler2D normals; varying vec3 tangent; varying vec4 tangent_other; varying vec3 viewVector; -varying float dist; #include "lib/settings.glsl" #include "/lib/res_params.glsl" @@ -18,11 +17,13 @@ varying float dist; uniform sampler2D texture; uniform sampler2D noisetex; uniform sampler2DShadow shadow; -uniform sampler2D gaux2; -uniform sampler2D gaux1; +// uniform sampler2D gaux2; +// uniform sampler2D gaux1; + +// uniform sampler2D colortex4; +uniform sampler2D colortex5; uniform sampler2D depthtex1; -uniform vec4 lightCol; uniform float nightVision; uniform vec3 sunVec; @@ -50,6 +51,8 @@ uniform int frameCounter; uniform int isEyeInWater; +flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +flat varying vec3 avgAmbient; @@ -62,6 +65,9 @@ uniform int isEyeInWater; #include "lib/stars.glsl" #include "lib/volumetricClouds.glsl" +#include "lib/diffuse_lighting.glsl" + + const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(-1.,3.)/8., vec2(5.0,1.)/8., @@ -141,7 +147,7 @@ vec3 rayTrace(vec3 dir,vec3 position,float dither, float fresnel, bool inwater){ 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); + float sp = sqrt(texelFetch2D(colortex4,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); @@ -181,14 +187,15 @@ 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 PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0] + #define PW_POINTS 2 //[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); @@ -316,19 +323,45 @@ vec4 encode (vec3 n, vec2 lightmaps){ 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_2(vec3 n, vec3 v, vec3 l, float r, vec3 F0) { -vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0,float fresnel) { + float alpha = square(r) + 1e-4; // when roughness is zero it fucks up + + vec3 h = normalize(l + v) ; + + float dotNH = clamp(dot(h,n),0.,1.); + float dotVH = clamp(dot(h,v),0.,1.); + + float D = alpha / (2.2 * square( (dotNH * alpha - 1.0) * square(dotNH) + 1.0) ); + + vec3 F = F0 + (1. - F0) * pow(clamp(1.0 - dotVH,0.0,1.0),5.0); + + return F * D; +} +// float SunGGX(vec3 n, vec3 v, vec3 l, float Roughness, float F0){ + +// vec3 h = normalize(l + v) ; + +// float dotNH = clamp(dot(h,n),0.,1.); +// float dotVH = clamp(dot(h,v),0.,1.); + +// float alpha =max(square(Roughness),1e-4) ; + +// float WallFresnel = F0 + (1. - F0) * pow(clamp(1.0 - dotVH,0.0,1.0),5.0); +// float Sun = square( dotNH - pow(alpha,1.5) - 1.0); + +// float Final = ((alpha / (10.0 * Sun + 1e-4)) * WallFresnel); + +// return Final ; +// } +float SunGGX(vec3 n, vec3 v, vec3 l, float roughness,float F0, float fresnel){ - float roughness = r; float alpha = square(roughness) + 1e-4; // when roughness is zero it fucks up @@ -343,11 +376,39 @@ vec3 GGX2(vec3 n, vec3 v, vec3 l, float r, vec3 F0,float fresnel) { 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); + float F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH); return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7)); } +vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) { + r = pow(r,2.5); +// 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); + vec3 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 pixelCoord (vec3 Coordinates, int Resolution){ + return floor(Coordinates / Resolution) * Resolution; +} +#define PHYSICSMOD_FRAGMENT +#include "/lib/oceans.glsl" + + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -360,32 +421,30 @@ void main() { 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); + gl_FragData[0] = texture2D(texture, lmtexcoord.xy,Texture_MipMap_Bias)*color; + float alphalabede = gl_FragData[0].a; + vec3 Albedo = toLinear(gl_FragData[0].rgb); +//pain + #ifdef HAND + iswater = 0.1; + #endif #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.); + Albedo = vec3(0.0); + gl_FragData[0] = vec4(vec3(0.0),1.0/255.0); } #endif #ifdef Vanilla_like_water if (iswater > 0.5) { - gl_FragData[0].a = luma(albedo.rgb); - albedo = color.rgb; + gl_FragData[0].a = luma(Albedo.rgb); + Albedo = color.rgb; } #endif - gl_FragData[4] = vec4(albedo, gl_FragData[0].a); - + gl_FragData[4] = vec4(Albedo, gl_FragData[0].a); vec3 normal = normalMat.xyz; @@ -393,47 +452,73 @@ void main() { mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x, tangent.y, binormal.y, normal.y, tangent.z, binormal.z, normal.z); + + vec3 WaterNormals; + vec3 TranslucentNormals; + if (iswater > 0.4){ - float bumpmult = 1.; - vec3 posxz = p3+cameraPosition; - posxz.xz-=posxz.y; - vec3 bump; + + if(physics_iterationsNormal < 1.0){ + float bumpmult = 1.; + + vec3 bump; + + vec3 posxz = p3+cameraPosition; + + posxz.xz -= posxz.y; - posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*fragpos)); + 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 { + + bump = normalize(getWaveHeight(posxz.xz,iswater)); + WaterNormals = bump; // tangent space normals for refraction + + bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult); + normal = normalize(bump * tbnMatrix); + + + }else{ + vec3 PhysicsMod_normal = physics_waveNormal(physics_localPosition.xz, physics_localWaviness, physics_gameTime); + + normal = normalize(worldToView(PhysicsMod_normal) + mix(normal, vec3(0.0), clamp(physics_localWaviness,0.0,1.0))); + + vec3 worldSpaceNormal = normal; + + vec3 bitangent = normalize(cross(tangent, worldSpaceNormal)); + mat3 tbn_new = mat3(tangent, binormal, worldSpaceNormal); + vec3 tangentSpaceNormal = (worldSpaceNormal * tbn_new); + + WaterNormals = tangentSpaceNormal ; + } + + }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); - } + TranslucentNormals = normalTex; + + normal = applyBump(tbnMatrix,normalTex); + + } + + TranslucentNormals += WaterNormals; vec4 data0 = vec4(1); - vec4 data1 = clamp( encode(viewToWorld(normal), lmtexcoord.zw),0.0,1.0); + vec4 data1 = clamp( encode(TranslucentNormals, 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 NdotL = clamp(lightSign*dot(normal,sunVec) ,0.0,1.0); + NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0); - float shading = 1.0; + + float Shadows = 1.0; float cloudShadow = 1.0; //compute shadows only if not backface - if (diffuseSun > 0.001) { + if (NdotL > 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; @@ -444,134 +529,127 @@ void main() { //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 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); - shading = 0.0; + Shadows = 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; + Shadows += shadow2D(shadow,vec3(projectedShadowPosition + vec3(rdMul*offsetS,-diffthresh*weight))).x/9.0; + } } - #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 + Shadows *= GetCloudShadow(p3); #endif } - vec3 ambientLight = (texture2D(gaux1,(lmtexcoord.zw*15.+0.5)*texelSize).rgb * 2.0) * 8./150./3.; + // 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; + // direct *= (iswater > 0.9 ? 0.2: 1.0)*NdotL*lmtexcoord.w; - vec3 directLight = direct; + // vec3 directLight = direct; + vec3 WS_normal = viewToWorld(normal); + vec3 ambientCoefs = WS_normal/dot(abs(WS_normal),vec3(1.)); + float skylight = clamp(abs(ambientCoefs.y+1),0.35,2.0) ; - vec3 color = vec3(0); + vec3 Indirect_lighting = DoAmbientLighting(avgAmbient, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.zw, skylight); + vec3 Direct_lighting = DoDirectLighting(lightCol.rgb/80.0, Shadows, NdotL, 0.0); - - color += ambientLight ; - color += directLight; + vec3 FinalColor = (Direct_lighting + Indirect_lighting) * Albedo; + + // if (iswater > 0.9) FinalColor = Albedo; #ifdef Glass_Tint float alphashit = min(pow(gl_FragData[0].a,2.0),1.0); - color *= alphashit; + FinalColor *= 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; + vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg; + SpecularTex = iswater > 0.0 && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02); + + if (iswater > 0.0 && (SpecularTex.g > 0.0 || SpecularTex.r > 0.0)){ + vec3 Reflections_Final = vec3(0.0); + float roughness = max(pow(1.0-SpecularTex.r,2.0),0.1); + float f0 = SpecularTex.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); + // float unchangedfresnel = fresnel; // 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); + if(isEyeInWater == 1 && physics_iterationsNormal > 0.0) fresnel = clamp( 1.0 - (pow( normalDotEye * 1.66 ,25)),0.02,1.0); + + // fresnel = mix(F0, 1.0, fresnel); + fresnel = F0 + (1.0 - F0) * 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; + // SSR, Sky, and Sun reflections + vec4 Reflections = vec4(0.0); + vec3 SkyReflection = skyCloudsFromTex(wrefl,colortex4).rgb / 150. * 5.; + vec3 SunReflection = Direct_lighting * GGX(normal, -normalize(fragpos), lightSign*sunVec, roughness, f0); + // vec3 SunReflection = Direct_lighting * SunGGX(normal, -normalize(fragpos), lightSign*sunVec, roughness, f0, fresnel); - 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; + if(iswater > 0.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) { + + Reflections.a = 1.0; + Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb; + } } - } - #endif + #endif + } + float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1); - if(isEyeInWater == 1 ) sky_c.rgb = color.rgb*lmtexcoord.w; + Reflections_Final = mix(SkyReflection*indoors, Reflections.rgb, Reflections.a); + Reflections_Final = mix(FinalColor, Reflections_Final, fresnel * visibilityFactor); + Reflections_Final += SunReflection; - 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); + gl_FragData[0].rgb = Reflections_Final; + //correct alpha channel with 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.); - #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 + // //suffering + // #ifdef SPIDEREYES + // gl_FragData[0].rgb = Albedo.rgb * 10; + // #endif - } - else - gl_FragData[0].rgb = color*.1; + } else { + gl_FragData[0].rgb = FinalColor; + } + + #ifndef HAND + gl_FragData[1] = vec4(Albedo,iswater); + #endif +// #endif - gl_FragData[1] = vec4(albedo,iswater); } } diff --git a/shaders/gbuffers_all_translucent.vsh b/shaders/gbuffers_all_translucent.vsh index 31eb0da..1a5d791 100644 --- a/shaders/gbuffers_all_translucent.vsh +++ b/shaders/gbuffers_all_translucent.vsh @@ -16,7 +16,6 @@ varying vec4 color; varying vec4 normalMat; varying vec3 binormal; varying vec3 tangent; -varying float dist; uniform mat4 gbufferModelViewInverse; varying vec3 viewVector; @@ -26,6 +25,7 @@ attribute vec4 at_tangent; attribute vec4 mc_Entity; uniform sampler2D colortex4; + uniform vec3 sunPosition; flat varying vec3 WsunVec; uniform float sunElevation; @@ -33,7 +33,7 @@ uniform float sunElevation; varying vec4 tangent_other; flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) - +flat varying vec3 avgAmbient; uniform vec2 texelSize; @@ -51,6 +51,17 @@ uniform int framemod8; vec4 toClipSpace3(vec3 viewSpacePosition) { return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z); } + + + + + + + + +#define PHYSICSMOD_VERTEX +#include "/lib/oceans.glsl" + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -58,25 +69,42 @@ vec4 toClipSpace3(vec3 viewSpacePosition) { //////////////////////////////VOID MAIN////////////////////////////// void main() { + + vec4 Swtich_gl_vertex = gl_Vertex; + + if(physics_iterationsNormal > 0.0){ + // basic texture to determine how shallow/far away from the shore the water is + physics_localWaviness = texelFetch(physics_waviness, ivec2(gl_Vertex.xz) - physics_textureOffset, 0).r; + // transform gl_Vertex (since it is the raw mesh, i.e. not transformed yet) + vec4 finalPosition = vec4(gl_Vertex.x, gl_Vertex.y + physics_waveHeight(gl_Vertex.xz, PHYSICS_ITERATIONS_OFFSET, physics_localWaviness, physics_gameTime), gl_Vertex.z, gl_Vertex.w); + // pass this to the fragment shader to fetch the texture there for per fragment normals + physics_localPosition = finalPosition.xyz; + + Swtich_gl_vertex.xyz = finalPosition.xyz ; + } + 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); + vec3 position = mat3(gl_ModelViewMatrix) * vec3(Swtich_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 == 10002) mat = 0.2; if (mc_Entity.x == 72) mat = 0.5; - - // if (mc_Entity.x == 8) mat = 0.1; + + #ifdef ENTITIES + mat = 0.2; + #endif + normalMat = vec4(normalize( gl_NormalMatrix*gl_Normal),mat); @@ -91,9 +119,7 @@ void main() { 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 = ( gl_ModelViewMatrix * Swtich_gl_vertex).xyz; viewVector = normalize(tbnMatrix * viewVector); @@ -112,4 +138,6 @@ void main() { lightCol.rgb = sc; WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) *sunPosition); + + avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; } diff --git a/shaders/gbuffers_beaconbeam.fsh b/shaders/gbuffers_beaconbeam.fsh index dcf4e65..21b42aa 100644 --- a/shaders/gbuffers_beaconbeam.fsh +++ b/shaders/gbuffers_beaconbeam.fsh @@ -1,35 +1,8 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable -#include "lib/settings.glsl" +// #define ENTITIES +// #define BLOCKENTITIES +// #define WORLD +#define SPIDEREYES -varying vec4 lmtexcoord; -varying vec4 color; - -uniform sampler2D texture; -uniform sampler2D gaux1; - -//faster and actually more precise than pow 2.2 -vec3 toLinear(vec3 sRGB){ - return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878); -} - -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -/* DRAWBUFFERS:2 */ -void main() { - - vec4 Albedo = texture2D(texture, lmtexcoord.xy)*color; - Albedo.a = 1.0; - - float exposure = texelFetch2D(gaux1,ivec2(10,37),0).r; - Albedo.rgb *= 25.0 ; - Albedo.rgb *= clamp(0.5-exposure,0.05,1.0); - - - gl_FragData[0] = Albedo; - -} \ No newline at end of file +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_beaconbeam.vsh b/shaders/gbuffers_beaconbeam.vsh index ad085e1..188ebaa 100644 --- a/shaders/gbuffers_beaconbeam.vsh +++ b/shaders/gbuffers_beaconbeam.vsh @@ -1,57 +1,8 @@ #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 ENTITIES +// #define BLOCKENTITIES +// #define WORLD +#define SPIDEREYES -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 -} +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_entities.vsh b/shaders/gbuffers_entities.vsh index f4f07a4..1600354 100644 --- a/shaders/gbuffers_entities.vsh +++ b/shaders/gbuffers_entities.vsh @@ -1,6 +1,6 @@ #version 120 -// #define WORLD +#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 index 21ac244..f7c09bc 100644 --- a/shaders/gbuffers_hand.fsh +++ b/shaders/gbuffers_hand.fsh @@ -1,4 +1,5 @@ #version 120 +#define WORLD #define HAND #include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_hand_water.fsh b/shaders/gbuffers_hand_water.fsh index 9208bed..ddf178d 100644 --- a/shaders/gbuffers_hand_water.fsh +++ b/shaders/gbuffers_hand_water.fsh @@ -1,4 +1,5 @@ #version 120 +#define HAND // #define WORLD #include "gbuffers_all_translucent.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_hand_water.vsh b/shaders/gbuffers_hand_water.vsh index 5228fab..05dca80 100644 --- a/shaders/gbuffers_hand_water.vsh +++ b/shaders/gbuffers_hand_water.vsh @@ -1,4 +1,5 @@ #version 120 +#define HAND // #define WORLD #include "gbuffers_all_translucent.vsh" \ No newline at end of file diff --git a/shaders/gbuffers_skytextured.fsh b/shaders/gbuffers_skytextured.fsh index 2852cff..21db346 100644 --- a/shaders/gbuffers_skytextured.fsh +++ b/shaders/gbuffers_skytextured.fsh @@ -1,24 +1,7 @@ #version 120 -/* -!! DO NOT REMOVE !! -This code is from Chocapic13' shaders -Read the terms of modification and sharing before changing something below please ! -!! DO NOT REMOVE !! -*/ +/* RENDERTARGETS:0 */ -/* 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; + discard; } diff --git a/shaders/gbuffers_skytextured.vsh b/shaders/gbuffers_skytextured.vsh index 4722357..0a2f94b 100644 --- a/shaders/gbuffers_skytextured.vsh +++ b/shaders/gbuffers_skytextured.vsh @@ -1,38 +1,5 @@ #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 index aa3de8b..21b42aa 100644 --- a/shaders/gbuffers_spidereyes.fsh +++ b/shaders/gbuffers_spidereyes.fsh @@ -1,32 +1,8 @@ #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 !! -*/ +// #define ENTITIES +// #define BLOCKENTITIES +// #define WORLD +#define SPIDEREYES - -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; - -} +#include "gbuffers_all_solid.fsh" \ No newline at end of file diff --git a/shaders/gbuffers_spidereyes.vsh b/shaders/gbuffers_spidereyes.vsh index cfe2b7d..188ebaa 100644 --- a/shaders/gbuffers_spidereyes.vsh +++ b/shaders/gbuffers_spidereyes.vsh @@ -1,37 +1,8 @@ #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; +// #define ENTITIES +// #define BLOCKENTITIES +// #define WORLD +#define SPIDEREYES -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 - -} +#include "gbuffers_all_solid.vsh" \ No newline at end of file diff --git a/shaders/lang/en_us.lang b/shaders/lang/en_us.lang index 21dfa02..7a0cfcb 100644 --- a/shaders/lang/en_us.lang +++ b/shaders/lang/en_us.lang @@ -1,9 +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 -value.indirect_effect.4 = SSDO +value.indirect_effect.2 = GTAO +value.indirect_effect.3 = RTAO +value.indirect_effect.4 = SSGI option.ambient_colortype = Coloring Type value.ambient_colortype.0 = Temperature diff --git a/shaders/lib/PhotonGTAO.glsl b/shaders/lib/PhotonGTAO.glsl new file mode 100644 index 0000000..8e6227c --- /dev/null +++ b/shaders/lib/PhotonGTAO.glsl @@ -0,0 +1,186 @@ + +// Common constants + +const float eps = 1e-6; +const float e = exp(1.0); +const float tau = 2.0 * pi; +const float half_pi = 0.5 * pi; +const float rcp_pi = 1.0 / pi; +const float degree = tau / 360.0; // Size of one degree in radians, useful because radians() is not a constant expression on all platforms +const float golden_ratio = 0.5 + 0.5 * sqrt(5.0); +const float golden_angle = tau / golden_ratio / golden_ratio; +const float hand_depth = 0.56; + +#if defined TAA && defined TAAU +const float taau_render_scale = TAAU_RENDER_SCALE; +#else +const float taau_render_scale = 1.0; +#endif + +// Helper functions + +#define rcp(x) (1.0 / (x)) +#define clamp01(x) clamp(x, 0.0, 1.0) // free on operation output +#define max0(x) max(x, 0.0) +#define min1(x) min(x, 1.0) + +float sqr(float x) { return x * x; } +vec2 sqr(vec2 v) { return v * v; } +vec3 sqr(vec3 v) { return v * v; } +vec4 sqr(vec4 v) { return v * v; } + +float cube(float x) { return x * x * x; } + +float max_of(vec2 v) { return max(v.x, v.y); } +float max_of(vec3 v) { return max(v.x, max(v.y, v.z)); } +float max_of(vec4 v) { return max(v.x, max(v.y, max(v.z, v.w))); } +float min_of(vec2 v) { return min(v.x, v.y); } +float min_of(vec3 v) { return min(v.x, min(v.y, v.z)); } +float min_of(vec4 v) { return min(v.x, min(v.y, min(v.z, v.w))); } + +float length_squared(vec2 v) { return dot(v, v); } +float length_squared(vec3 v) { return dot(v, v); } + +vec2 normalize_safe(vec2 v) { return v == vec2(0.0) ? v : normalize(v); } +vec3 normalize_safe(vec3 v) { return v == vec3(0.0) ? v : normalize(v); } + +float rcp_length(vec2 v) { return inversesqrt(dot(v, v)); } +float rcp_length(vec3 v) { return inversesqrt(dot(v, v)); } + +float fast_acos(float x) { + const float C0 = 1.57018; + const float C1 = -0.201877; + const float C2 = 0.0464619; + + float res = (C2 * abs(x) + C1) * abs(x) + C0; // p(x) + res *= sqrt(1.0 - abs(x)); + + return x >= 0 ? res : pi - res; // Undo range reduction +} +vec2 fast_acos(vec2 v) { return vec2(fast_acos(v.x), fast_acos(v.y)); } + +uniform vec2 view_res; +uniform vec2 view_pixel_size; + +float linear_step(float edge0, float edge1, float x) { + return clamp01((x - edge0) / (edge1 - edge0)); +} + +vec2 linear_step(vec2 edge0, vec2 edge1, vec2 x) { + return clamp01((x - edge0) / (edge1 - edge0)); +} + +vec4 project(mat4 m, vec3 pos) { + return vec4(m[0].x, m[1].y, m[2].zw) * pos.xyzz + m[3]; +} +vec3 project_and_divide(mat4 m, vec3 pos) { + vec4 homogenous = project(m, pos); + return homogenous.xyz / homogenous.w; +} + +vec3 screen_to_view_space(vec3 screen_pos, bool handle_jitter) { + vec3 ndc_pos = 2.0 * screen_pos - 1.0; + + return project_and_divide(gbufferProjectionInverse, ndc_pos); +} + +vec3 view_to_screen_space(vec3 view_pos, bool handle_jitter) { + vec3 ndc_pos = project_and_divide(gbufferProjection, view_pos); + + + return ndc_pos * 0.5 + 0.5; +} + + +// --------------------- +// ambient occlusion +// --------------------- + +#define GTAO_SLICES 2 +#define GTAO_HORIZON_STEPS 3 +#define GTAO_RADIUS 2.0 +#define GTAO_FALLOFF_START 0.75 + +float integrate_arc(vec2 h, float n, float cos_n) { + vec2 tmp = cos_n + 2.0 * h * sin(n) - cos(2.0 * h - n); + return 0.25 * (tmp.x + tmp.y); +} + +float calculate_maximum_horizon_angle( + vec3 view_slice_dir, + vec3 viewer_dir, + vec3 screen_pos, + vec3 view_pos, + float dither +) { + const float step_size = GTAO_RADIUS * rcp(float(GTAO_HORIZON_STEPS)); + + float max_cos_theta = -1.0; + + vec2 ray_step = (view_to_screen_space(view_pos + view_slice_dir * step_size, true) - screen_pos).xy; + vec2 ray_pos = screen_pos.xy + ray_step * (dither + max_of(view_pixel_size) * rcp_length(ray_step)); + + + for (int i = 0; i < GTAO_HORIZON_STEPS; ++i, ray_pos += ray_step) { + float depth = texelFetch(depthtex1, ivec2(clamp(ray_pos,0.0,1.0) * view_res * taau_render_scale - 0.5), 0).x; + + if (depth == 1.0 || depth < hand_depth || depth == screen_pos.z) continue; + + vec3 offset = screen_to_view_space(vec3(ray_pos, depth), true) - view_pos; + + float len_sq = length_squared(offset); + float norm = inversesqrt(len_sq); + + float distance_falloff = linear_step(GTAO_FALLOFF_START * GTAO_RADIUS, GTAO_RADIUS, len_sq * norm); + + float cos_theta = dot(viewer_dir, offset) * norm; + cos_theta = mix(cos_theta, -1.0, distance_falloff); + + max_cos_theta = max(cos_theta, max_cos_theta); + } + + return fast_acos(clamp(max_cos_theta, -1.0, 1.0)); +} + +float ambient_occlusion(vec3 screen_pos, vec3 view_pos, vec3 view_normal, vec2 dither , inout vec3 debug) { + float ao = 0.0; + vec3 bent_normal = vec3(0.0); + + // Construct local working space + vec3 viewer_dir = normalize(-view_pos); + vec3 viewer_right = normalize(cross(vec3(0.0, 1.0, 0.0), viewer_dir)); + vec3 viewer_up = cross(viewer_dir, viewer_right); + mat3 local_to_view = mat3(viewer_right, viewer_up, viewer_dir); + + for (int i = 0; i < GTAO_SLICES; ++i) { + float slice_angle = (i + dither.x) * (pi / float(GTAO_SLICES)); + + vec3 slice_dir = vec3(cos(slice_angle), sin(slice_angle), 0.0); + vec3 view_slice_dir = local_to_view * slice_dir; + + vec3 ortho_dir = slice_dir - dot(slice_dir, viewer_dir) * viewer_dir; + vec3 axis = cross(slice_dir, viewer_dir); + + vec3 projected_normal = view_normal - axis * dot(view_normal, axis); + + float len_sq = dot(projected_normal, projected_normal); + float norm = inversesqrt(len_sq); + + float sgn_gamma = sign(dot(ortho_dir, projected_normal)); + float cos_gamma = clamp01(dot(projected_normal, viewer_dir) * norm); + float gamma = sgn_gamma * fast_acos(cos_gamma); + + vec2 max_horizon_angles; + max_horizon_angles.x = calculate_maximum_horizon_angle(-view_slice_dir, viewer_dir, screen_pos, view_pos, dither.y); + max_horizon_angles.y = calculate_maximum_horizon_angle( view_slice_dir, viewer_dir, screen_pos, view_pos, dither.y); + + max_horizon_angles = gamma + clamp(vec2(-1.0, 1.0) * max_horizon_angles - gamma, -half_pi, half_pi); + + vec3 max_horizon_angles2 = mat3(gbufferModelViewInverse) * projected_normal; + + ao += integrate_arc(max_horizon_angles, gamma, cos_gamma) * len_sq * norm * max_horizon_angles.y; + } + + ao *= rcp(float(GTAO_SLICES)); + return ao; +} diff --git a/shaders/lib/climate_settings.glsl b/shaders/lib/climate_settings.glsl index a8ee8dd..7045ed4 100644 --- a/shaders/lib/climate_settings.glsl +++ b/shaders/lib/climate_settings.glsl @@ -3,8 +3,10 @@ uniform float Day; +uniform float worldDay; // 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); @@ -23,23 +25,36 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); /////////////////////////////////////////////////////////////////////////////// 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 SummerCol = vec3(Summer_R, Summer_G, Summer_B); + vec3 AutumnCol = vec3(Fall_R, Fall_G, Fall_B); vec3 WinterCol = vec3(Winter_R, Winter_G, Winter_B) ; - vec3 SpringCol = vec3(Spring_R, Spring_G, Spring_B) * glcolor; + vec3 SpringCol = vec3(Spring_R, Spring_G, Spring_B); + + // decide if you want to replace biome colors or tint them. + SummerCol *= glcolor; + AutumnCol *= glcolor; + WinterCol *= glcolor; + SpringCol *= 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; + SummerCol = vec3(Summer_Leaf_R, Summer_Leaf_G, Summer_Leaf_B); + AutumnCol = vec3(Fall_Leaf_R, Fall_Leaf_G, Fall_Leaf_B); + WinterCol = vec3(Winter_Leaf_R, Winter_Leaf_G, Winter_Leaf_B); + SpringCol = vec3(Spring_Leaf_R, Spring_Leaf_G, Spring_Leaf_B); + + SummerCol *= glcolor; + AutumnCol *= glcolor; + WinterCol *= glcolor; + SpringCol *= glcolor; } // length of each season in minecraft days @@ -64,7 +79,7 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); 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; + FinalColor = SpringToSummer; } #endif #endif @@ -107,7 +122,7 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); #ifdef Daily_Weather Coverage += day0 * 0.3 + day1 * 0.8 + day2 * 0.2 + day3 * 0.0 + day4 * 0.8 + day5 * 0.5 + day6 * -0.5 + day7 * 0.6; #else - Coverage += cloudCoverage; + Coverage += mix(Cumulus_coverage, Rain_coverage, rainStrength); // Coverage = mix(Coverage, Rain_coverage, rainStrength); #endif @@ -138,7 +153,7 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); Thickness = CirrusThickness; } #else - Coverage = 0.5; + Coverage = 0.7; Thickness = 0.05; #endif @@ -187,7 +202,7 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,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)); + BiomeColors *= dot(FinalFogColor,vec3(0.33)); // these range 0.0-1.0. they will never overlap. float Inbiome = isJungles+isSwamps; @@ -204,8 +219,8 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); float Inbiome = isJungles+isSwamps; vec2 BiomeFogDensity; // x = uniform || y = cloudy - BiomeFogDensity.x = isSwamps*5 + isJungles*5; - BiomeFogDensity.y = isSwamps*50 + isJungles*2; + BiomeFogDensity.x = isSwamps*1 + isJungles*5; + BiomeFogDensity.y = isSwamps*5 + isJungles*2; UniformDensity = mix(UniformDensity, vec4(BiomeFogDensity.x), Inbiome); CloudyDensity = mix(CloudyDensity, vec4(BiomeFogDensity.y), Inbiome); @@ -229,8 +244,9 @@ float day7 = clamp(clamp(Day-7, 0.0,1.0)*clamp(9-Day, 0.0,1.0),0.0,1.0); float Night = clamp((Time-13000)/2000,0,1) * clamp((23000-Time)/2000,0,1) ; // set densities. morn, noon, even, night - vec4 UniformDensity = vec4(0.0, 0.0, 0.0, 0.0); - vec4 CloudyDensity = vec4(0.0, 0.0, 0.0, 0.0); + vec4 UniformDensity = TOD_Fog_mult * vec4(Morning_Uniform_Fog, Noon_Uniform_Fog, Evening_Uniform_Fog, Night_Uniform_Fog); + vec4 CloudyDensity = TOD_Fog_mult * vec4(Morning_Cloudy_Fog, Noon_Cloudy_Fog, Evening_Cloudy_Fog, Night_Cloudy_Fog); + #ifdef Daily_Weather DailyWeather_FogDensity(UniformDensity, CloudyDensity); // let daily weather influence fog densities. diff --git a/shaders/lib/diffuse_lighting.glsl b/shaders/lib/diffuse_lighting.glsl new file mode 100644 index 0000000..b4166aa --- /dev/null +++ b/shaders/lib/diffuse_lighting.glsl @@ -0,0 +1,61 @@ +// in this here file im doing all the lighting for sunlight, ambient light, torches, for solids and translucents. + +//// OVERWORLD //// + +vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float skyLightDir){ + // Lightmap.x = 0.0; + // Lightmap.y = 1.0; + + SkyColor = SkyColor * 2.0 * ambient_brightness; + + + vec3 TorchLight = TorchColor * pow(1.0-pow(1.0-clamp(Lightmap.x,0.0,1.0) ,0.1),2); + TorchLight = exp(TorchLight * 30) - 1.0; + + + // vec3 SkyLight = max((SkyColor * 8./150./3.) * pow(Lightmap.y,3.0) , vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01)) ; + vec3 SkyLight = max((SkyColor * 8./150./3.) * pow(Lightmap.y,3.0),0.0) ; + + + return SkyLight * skyLightDir + TorchLight; +} + +vec3 DoDirectLighting(vec3 SunColor, float Shadow, float NdotL, float SubsurfaceScattering){ + + // vec3 SunLight = max(NdotL * Shadow, SubsurfaceScattering) * SunColor; + vec3 SunLight = NdotL * Shadow * SunColor; + + return SunLight; +} + + +//// NETHER //// +vec3 DoAmbientLighting_Nether(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3, vec3 WorldPos){ + + vec3 TorchLight = TorchColor * clamp(pow(Lightmap,3.0),0.0,1.0); + + + + vec3 LavaGlow = vec3(TORCH_R,TORCH_G,TORCH_B); + LavaGlow *= pow(clamp(1.0-max(Normal.y,0.0) + dot(Normal,np3),0.0,1.0),3.0); + LavaGlow *= clamp(exp2(-max((WorldPos.y - 50.0) / 5,0.0)),0.0,1.0); + LavaGlow *= pow(Lightmap,0.2); + + vec3 AmbientLight = vec3(0.1) + FogColor*clamp(1.1 + dot(Normal,np3),0.0,1.0); + + return AmbientLight + TorchLight + LavaGlow; +} +//// END //// +vec3 DoAmbientLighting_End(vec3 FogColor, vec3 TorchColor, float Lightmap, vec3 Normal, vec3 np3){ + + // vec3 TorchLight = TorchColor * clamp(pow(Lightmap,3.0),0.0,1.0); + vec3 TorchLight = TorchColor * pow(1.0-pow(1.0-clamp(Lightmap,0.0,1.0) ,0.1),2); + TorchLight = exp(TorchLight * 30) - 1.0; + + + FogColor = (FogColor / pow(0.00001 + dot(FogColor,vec3(0.3333)),1.0) ) * 0.1; + // vec3 AmbientLight = sqrt( clamp(1.25 + dot(Normal,np3),0.0,1.0)) * (vec3(0.5,0.75,1.0) * 0.05); + vec3 AmbientLight = sqrt( clamp(1.25 + dot(Normal,np3),0.0,1.0)*0.5) * FogColor; + + return TorchLight + AmbientLight; +} \ No newline at end of file diff --git a/shaders/lib/end_fog.glsl b/shaders/lib/end_fog.glsl new file mode 100644 index 0000000..4a4a193 --- /dev/null +++ b/shaders/lib/end_fog.glsl @@ -0,0 +1,346 @@ +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); +} + + +// Integer Hash - II +// - Inigo Quilez, Integer Hash - II, 2017 +// https://www.shadertoy.com/view/XlXcW4 +uvec3 iqint2(uvec3 x) +{ + const uint k = 1103515245u; + + x = ((x>>8U)^x.yzx)*k; + x = ((x>>8U)^x.yzx)*k; + x = ((x>>8U)^x.yzx)*k; + + return x; +} + +uvec3 hash(vec2 s) +{ + + uvec4 u = uvec4(s, uint(s.x) ^ uint(s.y), uint(s.x) + uint(s.y)); // Play with different values for 3rd and 4th params. Some hashes are okay with constants, most aren't. + + return iqint2(u.xyz); +} +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); +} + +// uniform float ifEndBoss; +// uniform float isSneaking; + +// uniform float EndSequence1; +// uniform float EndSequence2; + + +// position related stuff +// vec2 SEED = vec2(sin(frameTimeCounter*5) + 1); +// uvec3 HASH = hash(SEED); +// vec3 RandomPosition = clamp(vec3(HASH) * (1.0/float(0xffffffffu)), 0.0, 1.0); +vec3 RandomPosition = hash31(1); + + +// vec3 ManualLightPos = vec3(109.25, 128.73, 1189.4) ; +// vec3 ManualLightPos = vec3(307.96, 141.00, 1107.05) - vec3(sin(frameTimeCounter), 0, -cos(frameTimeCounter))*25; +// ManualLightPos -= vec3(sin(frameTimeCounter), 0, -cos(frameTimeCounter))*100; + +vec3 ManualLightPos = vec3(ORB_X, ORB_Y, ORB_Z); + +///////////////// POSITION +///////////////// POSITION +///////////////// POSITION +vec3 LightSourcePosition(vec3 WorldPos, vec3 CameraPos){ + + vec3 Origin = WorldPos ; + vec3 RandomPosition2 = hash31(Origin.y); + // make the swirl only happen within a radius + float SwirlBounds = clamp(sqrt(length(vec3(Origin.x,Origin.y-100,Origin.z)) / 150.0 - 1.0) ,0.0,1.0); + + if( SwirlBounds < 1.0) { + Origin.y -= 200; + } else { + Origin = WorldPos - cameraPosition - ManualLightPos ; + // Origin -= RandomPosition * 100; + } + + #ifdef THE_ORB + Origin = WorldPos - ManualLightPos; + #endif + + return Origin; +} + +///////////////// COLOR +///////////////// COLOR +///////////////// COLOR +vec3 LightSourceColor(float SwirlBounds){ + + vec3 Color = vec3(0.0); + + if( SwirlBounds < 1.0) { + + //////// STAGE 1 + Color = vec3(0.5, 0.5, 1.0); + + //////// STAGE 2 + + // Color = mix(Color, vec3(1.0,0.3,0.3), pow(EndSequence1,3.0)); + + // //////// STAGE 3 + // // yes rico, kaboom + // Color = mix(Color, vec3(1.0,0.0,1.0) * (1.0-EndSequence2), EndSequence2); + + } else { + + // Color = vec3(0.6, 0.8 ,1.0); + Color = vec3(ORB_R, ORB_G, ORB_B) * ORB_ColMult; + + // float Timing = dot(RandomPosition, vec3(1.0/3.0)); + + // float Flash = max(sin(frameTimeCounter*10) * Timing,0.0); + // Color *= blackbody2(RandomPosition.y*4000 + 1000); + // Color *= Flash; + + } + + #ifdef THE_ORB + Color = vec3(ORB_R, ORB_G, ORB_B) * ORB_ColMult; + #endif + + return Color; +} + +///////////////// SHAPE +///////////////// SHAPE +///////////////// SHAPE +vec3 LightSourceShape(vec3 WorldPos){ + + vec3 Shapes = vec3(0.0); + vec3 Origin = WorldPos ; + + // make the swirl only happen within a radius + float SwirlBounds = clamp(sqrt(length(Origin) / 200.0 - 1.0) ,0.0,1.0); + + if( SwirlBounds < 1.0) { + + // vec3 Origin = WorldPos; + Origin.y -= 200; + + vec3 Origin2 = Origin; + Origin2.y += 100 ; + Origin2.y *= 0.8; + + float Center = length(Origin); + float AltCenter = length(Origin2); + + //////// STAGE 1 + // when the ender dragon is alive, restrict the fog in this shape + // the max of a sphere is another smaller sphere. this creates a hollow sphere. + Shapes.r = max(1.0 - AltCenter / 75.0, max(AltCenter / 150.0 - 1.0, 0.0)); + + float radius = 200.0; + float thickness = 50.0 * radius; + Shapes.r = (thickness - clamp(pow(sqrt(pow(Origin2.x,2) + pow(Origin2.z,2)) - radius,2) + pow(Origin2.y*0.75,2.0) - radius,0,thickness)) / thickness ; + + Shapes.r = max(Shapes.r, max(1.0 - AltCenter / 75.0, 0.0)); + + radius = 50.0; + thickness = 5.0 * radius; + Shapes.b = (thickness - clamp(pow(sqrt(pow(Origin2.x,2) + pow(Origin2.y,2)) - radius,2) + pow(Origin2.z*0.75,2.0) - radius,0,thickness)) / thickness ; + } + + return Shapes; +} + + +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, int LOD){ + + + // THE OOOOOOOOOOOOOOOOOOOOOORB + vec3 Shapes = LightSourceShape(pos); + + vec3 samplePos = pos*vec3(1.0,1./32.,1.0); + vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0); + + // #ifndef THE_ORB + // ender dragon battle area swirling effect. + // if(EndSequence2 < 1.0){ + float radiance = 2.39996 + samplePos.y + frameTimeCounter/10; + mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance))); + + // make the swirl only happen within a radius + float SwirlBounds = clamp(sqrt(length(vec3(pos.x,pos.y-100,pos.z)) / 200.0 - 1.0) ,0.0,1.0); + + samplePos.xz = mix(samplePos.xz * rotationMatrix, samplePos.xz, SwirlBounds); + samplePos2.xz = mix(samplePos2.xz * rotationMatrix, samplePos2.xz, SwirlBounds); + // } + // #endif + + samplePos2.y -= frameTimeCounter/15; + + float finalfog = 0; + + finalfog += max(0.6-densityAtPosFog(samplePos * 16.0) * 2,0.0); + // finalfog = exp(finalfog*5)-1; + + float smallnoise = max(densityAtPosFog(samplePos2 * (160. - finalfog*3))-0.1,0.0); + finalfog -= ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.3; + + // make the eye of the swirl have no fog, so you can actually see. + finalfog = max(finalfog - Shapes.r, 0.0); + + // dragon death sequence + // finalfog = Shapes.b; + + + return finalfog; +} + + +mat2x3 getVolumetricRays(float dither,vec3 fragpos,float dither2) { + int SAMPLES = 16; + //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 = vec3(0.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),32.0 * 12.0)/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 absorbance = vec3(1.0); + float expFactor = 11.0; + + vec3 fogColor = (gl_Fog.color.rgb / pow(dot(gl_Fog.color.rgb,vec3(0.3333)),1.1) ) ; + + + for (int i=0;i -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+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++) { - - 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; - //small bias - minZ = maxZ-(0.0001/dist)/ld(spos.z); - maxZ += stepv.z; - } - - 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) { @@ -153,28 +68,44 @@ vec2 R2_samples_spec(int n){ 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 = clipPosition.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++) { + + 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; + //small bias + minZ = maxZ-(0.0001/dist)/ld(spos.z); + maxZ += stepv.z; + } + + return vec3(1.1); } +vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool hand, inout float reflectLength){ - -vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool hand){ vec3 clipPosition = toClipSpace3(position); float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? (-near -position.z) / dir.z : far*sqrt(3.); @@ -197,11 +128,10 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool 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); + float sp = sqrt((texelFetch2D(colortex4,ivec2(testthing),0).a+0.1)/65000.0); sp = invLinZ(sp); - + if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ) ) return vec3(spos.xy/RENDER_SCALE,sp); spos += stepv; @@ -209,58 +139,94 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool float biasamount = 0.0002 / dist; if(hand) biasamount = 0.01; minZ = maxZ-biasamount / ld(spos.z); - maxZ += stepv.z; + + reflectLength += 1.0 / quality; // for shit } + + 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 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 0.01; + float hasReflections2 = max(1.0 - roughness*1.75,0.0); + + + // // if (!hasReflections) Outdoors = 0.0; + // SunReflection = directlighting * SunGGX(normal, -np3, sunPos, roughness, f0.y) / 5.0; + SunReflection = directlighting * GGX(normal, -np3, sunPos, roughness, f0.yyy); +// + if (hasReflections) { // Skip sky reflection and SSR if its just not very visible anyway + #ifdef Sky_reflection + SkyReflection = skyCloudsFromTex(L, colortex4).rgb / 150. * 5.; + #endif + + #ifdef Screen_Space_Reflections + // #ifdef SCREENSHOT_MODE + // float rayQuality = reflection_quality; + // #else + float rayQuality = mix_float(reflection_quality,4,luma(rayContrib)); // Scale quality with ray contribution + // #endif + // float rayQuality = reflection_quality; + + vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, reflection_quality, hand, reflectLength); + + float LOD = clamp(reflectLength * 6.0, 0.0,6.0) ; + if(hand || isEntities) LOD = 6.0; + + 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 = texture2DLod(colortex5,previousPosition.xy,LOD).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); + + SunReflection *= Metals; + + #ifdef Sky_reflection + SkyReflection *= Metals; + #endif + #ifdef Screen_Space_Reflections + Reflections.rgb *= Metals; + #endif + + // background reflections + SkyReflection = mix_vec3(Output, SkyReflection, Outdoors); + + // composite background and SSR. + Reflections.rgb = mix_vec3(SkyReflection, Reflections.rgb, Reflections.a); + + // put reflections onto the scene + #ifdef Rough_reflections + Output = hand ? mix_vec3(Output, Reflections.rgb, VisibilityFactor) : mix_vec3(Output, Reflections.rgb, luma(rayContrib)); + #else + Output = mix_vec3(Output, Reflections.rgb, VisibilityFactor); + #endif + + Output += SunReflection; +} + +void MaterialReflections_N( + inout vec3 Output, + float roughness, + vec3 f0, + vec3 albedo, + vec3 normal, + vec3 np3, + vec3 fragpos, + vec3 noise, + bool hand +){ + vec3 Reflections_Final = Output; + float reflectLength = 0.0; + + roughness = unpackRoughness(roughness); + f0 = f0.y == 0.0 ? vec3(0.02) : f0; + + // roughness = 0.0; + // f0 = vec3(0.9); + + float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0.y) * -4),0,1); + + 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, H); + vec3 L = basis * Ln; + + // fresnel stuff + float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0); vec3 F = mix(f0, vec3(1.0), fresnel); vec3 rayContrib = F; - // float NdotV = clamp(normalize(dot(np3, L))*10000.,0.,1.); - bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) > 0.01; + bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) >= 0.0; + if (Roughness_Threshold == 1.0){ hasReflections = true; } - if (Roughness_Threshold == 1.0){ hasReflections = roughness > -1; } - - if (!hasReflections ) Outdoors = 0.0; - - - - // if(hand){ - // LOD_controller = 6; - // // noise.b = 0.5; - // } // SSR, Sky, and Sun reflections vec4 Reflections = vec4(0.0); - // vec3 SkyReflection = skyCloudsFromTex_Spec(L, colortex4,int(LOD_controller)).rgb / 150. * 5.; - vec3 SkyReflection = skyCloudsFromTex(L, colortex4).rgb / 150. * 5.; - - vec3 SunReflection = diffuse * GGX2(normal, -np3, sunPos, roughness, f0) * 8./150./3. * sunCol * Sun_specular_Strength; - - #ifndef Sky_reflection - SkyReflection = Reflections_Final; - #endif - - - - + vec3 FogReflection = vec3(0.0); #ifdef Screen_Space_Reflections if ( hasReflections ) { // Skip SSR if ray contribution is low - - #ifdef SCREENSHOT_MODE - float rayQuality = reflection_quality; - #else - float rayQuality = mix_float(reflection_quality,0.0,dot(rayContrib,vec3(0.33))); // Scale quality with ray contribution - #endif - - vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, reflection_quality, hand); - - // float test = dot(vec2(-rtPos.x,-rtPos.y), vec2(rtPos.x,rtPos.y)); - // float LOD_controller = clamp((1-pow(test*0.5+1.0,25)) * 10,0.0,6.0) ; - - // LOD_controller = 0; + float rayQuality = reflection_quality; + vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, reflection_quality, hand, reflectLength); + + float LOD = clamp( reflectLength * 6.0 ,0.0,6.0); if (rtPos.z < 1. ){ // Reproject on previous frame vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; @@ -331,39 +375,137 @@ void MaterialReflections( 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 = texture2DLod(colortex5,previousPosition.xy,0).rgb; + Reflections.rgb = texture2DLod(colortex5,previousPosition.xy,LOD).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 = pow(luma(rayContrib),1.0); - float oneminus_lumaRayContrib = pow(1.0-luma(rayContrib),1.0); - // darken albedos, and stop darkening where the sky gets occluded indoors - Reflections_Final *= mix_float(1.0 - (Reflections.a*lumaRayContrib), oneminus_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 Sky_reflection + // reflect nether fog color instead of a sky. + FogReflection = gl_Fog.color.rgb * 0.5 * NetherFog_brightness; + FogReflection *= 1.0 + sqrt(roughness) * 15.0; // brighten rough spots for some highlights that look neat + FogReflection *= Metals; + + FogReflection = mix(Output, FogReflection, pow(fresnel, 0.2)+0.1); // make sure the background contains the fog reflection. + #else + FogReflection = Output; + #endif + + Reflections.rgb = mix(FogReflection, Reflections.rgb, Reflections.a); // make background only where ssr is not. + Reflections_Final = mix(Output, Reflections.rgb, luma(rayContrib)); // apply reflections to final scene color. + #ifdef Rough_reflections Output = hand ? mix_vec3(Output, Reflections_Final, visibilityFactor) : Reflections_Final; #else Output = mix_vec3(Output, Reflections_Final, visibilityFactor); #endif - Output += SunReflection ; - // float aaaa = dot(vec2(-rtPos.x,-rtPos.y), vec2(rtPos.x,rtPos.y)); - // test = pow(test*0.5+1.0,2); - // Output = vec3(0,test,0) ; + // Output = vec3(reflectLength); +} + +void MaterialReflections_E( + inout vec3 Output, + float roughness, + vec3 f0, + vec3 albedo, + vec3 normal, + vec3 np3, + vec3 fragpos, + vec3 noise, + bool hand, + vec3 lightCol, + vec3 lightDir, + bool isEntities +){ + vec3 Reflections_Final = Output; + float reflectLength = 0.0; + + roughness = unpackRoughness(roughness); + f0 = f0.y == 0.0 ? vec3(0.02) : f0; + + // roughness = 0.0; + // f0 = vec3(0.9); + + float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0.y) * -4),0,1); + + 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, H); + vec3 L = basis * Ln; + + // fresnel stuff + float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0); + vec3 F = mix(f0, vec3(1.0), fresnel); + vec3 rayContrib = F; + + // float NdotV = clamp(normalize(dot(np3, L))*10000.,0.,1.); + bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) >= 0.0; + if (Roughness_Threshold == 1.0){ hasReflections = true; } + + + vec3 Ln_2 = reflect(-normSpaceView, normalize(vec3(0.0,0.0,1.0))); + vec3 L_2 = basis * Ln_2; + + vec3 FogReflection = skyCloudsFromTexLOD(L_2, colortex4, sqrt(roughness) * 9.0).rgb / 150.0; + FogReflection = mix(FogReflection, lightCol * 2 * clamp(dot(L_2, lightDir),0,1), roughness); + + + FogReflection *= 1.0 + roughness * 2.0; + vec4 Reflections = vec4(0.0); + + #ifdef Screen_Space_Reflections + if ( hasReflections ) { // Skip SSR if ray contribution is low + + float rayQuality = reflection_quality; + vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, reflection_quality, hand, reflectLength); + + float LOD = clamp( reflectLength * 6.0 ,0.0,6.0); + + if(hand) LOD = 6.0; + if(isEntities) LOD = 4.0; + + 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 = texture2DLod(colortex5,previousPosition.xy,LOD).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; + FogReflection *= Metals; + + Reflections.rgb = mix(FogReflection, Reflections.rgb, Reflections.a); // make background only where ssr is not. + Reflections_Final = mix(Output, Reflections.rgb, luma(rayContrib)); // apply reflections to final scene color. + + #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/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index dcfb4c5..068e465 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -1,5 +1,3 @@ - - #ifdef HQ_CLOUDS int maxIT_clouds = minRayMarchSteps; int maxIT = maxRayMarchSteps; @@ -19,21 +17,17 @@ uniform float viewHeight; uniform float viewWidth; uniform sampler2D colortex4;//Skybox -// uniform float lightningFlash; #define WEATHERCLOUDS #include "/lib/climate_settings.glsl" +float CumulusHeight = 250; +float MaxCumulusHeight = CumulusHeight + 100; -float maxHeight = 5000.; -float cloud_height = 1500.; - -// quick variables -float rainCloudwetness = rainStrength ; -float rainClouds = rainCloudwetness; - -float cloud_movement1 = frameTimeCounter * cloud_speed * 0.001; +float AltostratusHeight = 2000; +float rainCloudwetness = rainStrength; +float cloud_movement = 0; //3D noise from 2d texture float densityAtPos(in vec3 pos){ @@ -45,47 +39,33 @@ float densityAtPos(in vec3 pos){ 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 + cloud_movement) / 5000 ).b; + float CloudSmall = texture2D(noisetex, (samplePos.xz - cloud_movement) / 500 ).r; + + float coverage = abs(pow(CloudLarge,1)*2.0 - 1.2)*0.5 - (1.0-CloudSmall) + 0.3; + + float Topshape = max(pos.y - (MaxCumulusHeight + CumulusHeight)*0.46, 0.0) / 200; + + Topshape += max(exp((pos.y - MaxCumulusHeight) / 10.0 ), 0.0) ; + + float FinalShape = DailyWeather_LowAltitude(coverage) - Topshape; + + // cap the top and bottom for reasons + float capbase = sqrt(max(CumulusHeight*1.05 - pos.y, 0.0)/50) ; + float captop = max(pos.y - MaxCumulusHeight, 0.0); - // 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; + FinalShape = FinalShape - capbase - captop ; - - // float coverage = CloudSmall-CloudLarge; - - // // float mult = max( abs(pos.y - (maxHeight+cloud_height)*0.4 ) / 5000, 0); - - // float mult = max( abs(pos.y-1750) / 5000, 0); - - - // cloudshape = DailyWeather_LowAltitude(coverage) - mult ; - - // return max(cloudshape,0.0); - - - - - 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) - pow(CloudLarge*0.5+0.5,1.5); - - float mult = max( abs(pos.y - (maxHeight+cloud_height)*0.4 ) / 5000, 0); - // float mult = max( abs(pos.y-1750) / 5000, 0); - - cloudshape = DailyWeather_LowAltitude(coverage) - mult; - - return max(cloudshape,0.0); + return max(FinalShape,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 ; @@ -93,73 +73,48 @@ float cloudVol(in vec3 pos,in vec3 samplePos,in float cov, in int LoD){ 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); - - // // noise = (1.0 - densityAtPos(samplePos * 4.)); - // // samplePos = floor(samplePos*)/16; - // noise += ((1.0 - densityAtPos(samplePos * 16.))*0.5+0.5) * (1.0 - densityAtPos(samplePos * 4.)); - // // noise += (1.0 - densityAtPos(samplePos / 160 * 1000.)); - // noise *= clamp(pow(1.0-cloudshape,0.5),0.0,1.0); - - // float cloud = max(cov - noise*noise*noise,0.0) ; + samplePos.xz -= cloud_movement/4; + noise += 1.0-densityAtPos(samplePos * 200.) ; + float smallnoise = densityAtPos(samplePos * 600.); + if (LoD > 0) noise += ((1-smallnoise) - max(0.15 - abs(smallnoise * 2.0 - 0.55) * 0.5,0.0)*1.5) * 0.5; + + noise *= 1.0-cov; + + noise = noise*noise; + float cloud = max(cov - noise*noise*fbmAmount,0.0); + return cloud; } -float getCloudDensity(in vec3 pos, in int LoD){ +float GetCumulusDensity(in vec3 pos, in int LoD){ - - // vec3 samplePos = floor((pos*vec3(1.0,1./48.,1.0)/4 ) /512)*512 ; 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); + return cloudVol(pos,samplePos,coverageSP,LoD); } else return 0.0; } -float HighAltitudeClouds(vec3 pos){ - vec2 pos2d = pos.xz/100000.0 ; +float GetAltostratusDensity(vec3 pos){ - 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 large = texture2D(noisetex, pos.xz/100000. ).b; + float small = texture2D(noisetex, pos.xz/10000. - vec2(-large,1-large)/5).b; - float coverage = 1; - float thickness = 1; - DailyWeather_HighAltitude(coverage, thickness); + float shape = (small + pow((1.0-large),2.0))/2.0; - float cirrusFinal = exp(pow((cloudSmall + cloudLarge),thickness) * -coverage ); - return max(cirrusFinal,0.0); + shape = pow(max(shape + Alto_coverage - 0.5,0.0),2.0); + + return shape; } -//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, @@ -168,252 +123,229 @@ vec3 Cloud_lighting( vec3 sunContribution, vec3 sunContributionMulti, vec3 moonContribution, - vec3 moonContributionMulti, + float AmbientShadow, int cloudType ){ - // low altitude - float powder = 1.0 - exp(-CloudShape * 400.0); - float ambientShading = exp(-SkyShadowing * 50. + powder)*powder ; - vec3 ambientLighting = SkyColors * ambientShading; - - // if(cloudType == 1) ambientLighting = SkyColors * powder; + float coeeff = -30; + // float powder = 1.0 - exp((CloudShape*CloudShape) * -800); + float powder = 1.0 - exp(CloudShape * coeeff/3); + float lesspowder = powder*0.4+0.6; - vec3 sunLighting = exp(-SunShadowing)*sunContribution + exp(-SunShadowing * 0.2)*sunContributionMulti; - sunLighting *= powder; + vec3 skyLighting = SkyColors * exp(SkyShadowing * AmbientShadow * coeeff/2 ) * lesspowder ; - vec3 moonLighting = ( exp2(-MoonShadowing * 2.0 )*moonContribution + exp(-MoonShadowing * 0.2 )*moonContributionMulti ) * powder; + if(cloudType == 1){ + coeeff = -10; + skyLighting = SkyColors * exp(SkyShadowing * coeeff/15) * lesspowder; + } - return ambientLighting + sunLighting ; + vec3 sunLighting = exp(SunShadowing * coeeff + powder) * sunContribution; + sunLighting += exp(SunShadowing * coeeff/4 + powder*2) * sunContributionMulti; + vec3 moonLighting = exp(MoonShadowing * coeeff / 3) * moonContribution * powder; - - // 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; + return skyLighting + moonLighting + sunLighting ; } -vec3 pixelCoord (vec3 Coordinates, int Resolution){ - return floor(Coordinates / Resolution) * Resolution; +//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; +} + +float CustomPhase(float LightPos, float S_1, float S_2){ + float SCALE = S_2; // remember the epislons 0.001 is fine. + float N = S_1; + float N2 = N / SCALE; + + float R = 1; + float A = pow(1.0 - pow(max(R-LightPos,0.0), N2 ),N); + + return A; } -vec3 startOffset = vec3(0); vec4 renderClouds( - vec3 fragpositi, - vec3 color, - float dither, - vec3 sunColor, - vec3 moonColor, - vec3 avgAmbient, - float dither2 + vec3 FragPosition, + vec2 Dither, + vec3 SunColor, + vec3 MoonColor, + vec3 SkyColor ){ #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); + vec3 color = vec3(0.0); //project pixel position into projected shadowmap space - vec4 fragposition = gbufferModelViewInverse*vec4(fragpositi,1.0); + vec4 fragpos = normalize(gbufferModelViewInverse*vec4(FragPosition,1.0)); - vec3 worldV = normalize(fragposition.rgb); - float VdotU = worldV.y; + maxIT_clouds = int(clamp( maxIT_clouds / sqrt(exp2(fragpos.y)),0.0, maxIT)); - //project view origin into projected shadowmap space - vec4 start = (gbufferModelViewInverse*vec4(0.0,0.0,0.,1.)); + vec3 dV_view = normalize(fragpos.xyz); + + dV_view.y += 0.05; + + vec3 dV_view2 = dV_view; + float mult2 = length(dV_view2); - // 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); - - // dV_view = floor(dV_view/1000)*1000; - 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; - // progress_view = floor - float shadowStep = 200.; - vec3 dV_Sun = flipClouds * normalize(mat3(gbufferModelViewInverse)*sunVec)*shadowStep; + dV_view *= max(MaxCumulusHeight - CumulusHeight, 0.0)/abs(dV_view.y)/maxIT_clouds; float mult = length(dV_view); - float SdotV = dot(sunVec,normalize(fragpositi)); + // i want the samples to stay at one point in the world, but as the height coordinates go negative everything goes insideout, so this is a work around.... + float startFlip = mix(max(cameraPosition.y - MaxCumulusHeight,0.0), max(CumulusHeight-cameraPosition.y,0), clamp(dV_view.y,0,1)); + // vec3 progress_view = dV_view*Dither.x + cameraPosition + (dV_view/abs(dV_view.y))*startFlip; + vec3 progress_view = dV_view*Dither.x + cameraPosition + (dV_view/abs(dV_view.y))*startFlip; - 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 mieDayMulti = phaseg(SdotV, 0.35); - float mieDay = (phaseg(SdotV,0.75) + mieDayMulti)*2.0; - - float mieNightMulti = phaseg(-SdotV, 0.35)*3.14; - float mieNight = mix(phaseg(-SdotV,0.9), mieNightMulti,0.5)*3.14; - - vec3 sunContribution = mieDay*sunColor*3.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; - // progress_view = floor(progress_view/512)*512; - float cloud = 0.0; - for(int i=0;i= 0.0){ - float muS = cloud*densityofclouds; - float muE = cloud*densityofclouds; + float SdotV = dot(sunVec,normalize(FragPosition)); - float muEshD = 0.0; - if (sunContribution.g > 1e-5){ + SkyColor *= clamp(abs(dV_Sun.y)/100.,0.75,1.0); + SunColor = SunColor * clamp(dV_Sun.y ,0.0,1.0); + MoonColor *= clamp(-dV_Sun.y,0.0,1.0); + + if(dV_Sun.y/shadowStep < -0.1) dV_Sun = -dV_Sun; + + float mieDay = phaseg(SdotV, 0.75) * 2; + float mieDayMulti = phaseg(SdotV, 0.35) * 2; + + vec3 sunContribution = SunColor * mieDay; + vec3 sunContributionMulti = SunColor * mieDayMulti ; + + float mieNight = (phaseg(-SdotV,0.8) + phaseg(-SdotV, 0.35)*4) * 6.0; + vec3 moonContribution = MoonColor * mieNight; + + #ifdef Cumulus + for(int i=0;i lViewPosM; + // if(IntersecTerrain) break; + + float cumulus = GetCumulusDensity(progress_view, cloudLoD); + + float alteredDensity = Cumulus_density * clamp(exp( (progress_view.y - (MaxCumulusHeight + CumulusHeight)*0.455) / 9.0 ),0.0,1.0); + + if(cumulus > 1e-5){ + float muE = cumulus*alteredDensity; + + float Sunlight = 0.0; + float MoonLight = 0.0; + 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); + vec3 shadowSamplePos = progress_view + dV_Sun * (1+j+Dither.y/2)*0.15; + float shadow = GetCumulusDensity(shadowSamplePos, 0) * Cumulus_density; + + Sunlight += shadow; + MoonLight += shadow; - 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); + } + progress_view += dV_view; } #endif - - vec3 normView = normalize(dV_view2)*flipClouds; + + + #ifdef Altostratus + if (max(AltostratusHeight-cameraPosition.y,0.0)/max(normalize(dV_view).y,0.0) / 100000.0 < AltostratusHeight) { + + vec3 progress_view_high = dV_view2 + cameraPosition + dV_view2/dV_view2.y * max(AltostratusHeight-cameraPosition.y,0.0); + float altostratus = GetAltostratusDensity(progress_view_high) * Alto_density; + + float Sunlight = 0.0; + float MoonLight = 0.0; + + if(altostratus > 1e-5){ + for (int j = 0; j < 2; j++){ + vec3 shadowSamplePos_high = progress_view_high + dV_Sun * float(j+Dither.y); + float shadow = GetAltostratusDensity(shadowSamplePos_high) * Alto_density; + Sunlight += shadow; + } + vec3 S = Cloud_lighting(altostratus, altostratus, Sunlight, MoonLight, SkyColor, sunContribution, sunContributionMulti, moonContribution, 1, 1); + + vec3 Sint = (S - S * exp(-20*altostratus)) / altostratus; + color += max(altostratus*Sint*total_extinction,0.0); + total_extinction *= max(exp(-20*altostratus),0.0); + } + } + #endif + + 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_view2).y; - float fog = exp(-dist/15000.0*(1.0+rainCloudwetness*8.)); + vec3 fogColor = skyFromTex(normView, colortex4)/150. * 5.0; + float dist = max(cameraPosition.y+CumulusHeight,CumulusHeight)/abs(normView.y); + float fog = exp(dist / -5000.0 * (1.0+rainCloudwetness*8.)); + + // if(IntersecTerrain) fog = 1.0; + return mix(vec4(fogColor,0.0), vec4(color,total_extinction), fog); // return vec4(color,total_extinction); } + +float GetCloudShadow(vec3 eyePlayerPos){ + vec3 playerPos = eyePlayerPos + cameraPosition; + playerPos.y += 0.05; + float shadow; + + // assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud. + #ifdef Cumulus + vec3 lowShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight + CumulusHeight)*0.44 - playerPos.y,0.0) ; + shadow += GetCumulusDensity(lowShadowStart,1)*cloudDensity; + #endif + + #ifdef Altostratus + vec3 highShadowStart = playerPos + WsunVec/abs(WsunVec.y) * max(AltostratusHeight - playerPos.y,0.0); + shadow += GetAltostratusDensity(highShadowStart) * Alto_density; + #endif + + shadow = clamp(exp(-shadow*10.0),0.0,1.0); + + return shadow; +} +float GetCloudShadow_VLFOG(vec3 WorldPos){ + + float shadow; + + // assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud. + #ifdef Cumulus + vec3 lowShadowStart = WorldPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight + CumulusHeight)*0.435 - WorldPos.y,0.0) ; + shadow += GetCumulusDensity(lowShadowStart,0)*cloudDensity; + #endif + + #ifdef Altostratus + vec3 highShadowStart = WorldPos + WsunVec/abs(WsunVec.y) * max(AltostratusHeight - WorldPos.y,0.0); + shadow += GetAltostratusDensity(highShadowStart) * Alto_density; + #endif + + shadow = clamp(exp(-shadow*15.0),0.0,1.0); + + // do not allow it to exist above the lowest cloud plane + shadow *= clamp(((MaxCumulusHeight + CumulusHeight)*0.435 - WorldPos.y)/100,0.0,1.0) ; + + return shadow; +} \ No newline at end of file diff --git a/shaders/lib/volumetricFog.glsl b/shaders/lib/volumetricFog.glsl index 4b6573d..d7b37a1 100644 --- a/shaders/lib/volumetricFog.glsl +++ b/shaders/lib/volumetricFog.glsl @@ -1,35 +1,19 @@ - -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 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){ @@ -37,24 +21,28 @@ float cloudVol(in vec3 pos){ vec3 samplePos2 = pos*vec3(1.0,1./48.,1.0); - float mult = exp2( -max((pos.y - SEA_LEVEL) / 35.,0.0)); + float mult = exp( -max((pos.y - SEA_LEVEL) / 35.,0.0)); - float fog_shape = 1-densityAtPos(samplePos * 24.0); - float fog_eroded = densityAtPos( samplePos2 * 150.0); + float fog_shape = 1.0 - densityAtPosFog(samplePos * 24.0); + float fog_eroded = 1.0 - densityAtPosFog( samplePos2 * 200.0); + + // float CloudyFog = max( (fog_shape*2.0 - fog_eroded*0.5) - 1.2, max(fog_shape-0.8,0.0)) * mult; + + float CloudyFog = max((fog_shape*1.2 - fog_eroded*0.2) - 0.75,0.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; + float RainFog = max(fog_shape*10. - 7.,0.5) * exp2( -max((pos.y - SEA_LEVEL) / 25.,0.0)) * 5. * rainStrength * RainFog_amount; TimeOfDayFog(UniformFog, CloudyFog); - return RainFog + CloudyFog + UniformFog; + return CloudyFog + UniformFog + RainFog; } -mat2x3 getVolumetricRays( +vec4 getVolumetricRays( + vec3 fragpos, float dither, - vec3 fragpos + vec3 AmbientColor ){ //project pixel position into projected shadowmap space vec3 wpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; @@ -76,7 +64,6 @@ mat2x3 getVolumetricRays( //apply dither vec3 progress = start.xyz; - vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; vec3 vL = vec3(0.); @@ -88,23 +75,23 @@ mat2x3 getVolumetricRays( 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 sunColor = lightCol.rgb / 80.0; + vec3 skyCol0 = AmbientColor / 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 absorbance = 1.0; float expFactor = 11.0; vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a; - float cloudShadow = 1.0; + vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; - for (int i=0;i 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; - - -// float getPuddleCoverage(vec3 samplePos){ -// float puddle = texture2D(noisetex, samplePos.xz/25000).b ; - -// return max(puddle,0.0); -// } + 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////////////////////////////// @@ -222,17 +235,15 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// -/* RENDERTARGETS: 1,7,8,13 */ +/* RENDERTARGETS: 1,7,8,15,10 */ 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; + vec3 normal2 = normalMat.xyz; #ifdef MC_NORMAL_MAP vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w); @@ -240,30 +251,15 @@ void main() { 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 + + float lightmap = clamp( (lmtexcoord.w-0.8) * 10.0,0.,1.); + #ifdef POM // vec2 tempOffset=offsets[framemod8]; @@ -277,13 +273,26 @@ void main() { #ifdef WORLD if (dist < MAX_OCCLUSION_DISTANCE) { - if ( viewVector.z < 0.0 && readNormal(vtexcoord.st).a < 0.9999 && readNormal(vtexcoord.st).a > 0.00001) { + float depthmap = readNormal(vtexcoord.st).a; + float used_POM_DEPTH = 1.0; - 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 ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) { + + #ifdef Adaptive_Step_length + vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0) ; + used_POM_DEPTH = 1.0; + #else + vec3 interval = viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS*POM_DEPTH; + #endif + vec3 coord = vec3(vtexcoord.st, 1.0); + + coord += interval * used_POM_DEPTH; + + 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 * used_POM_DEPTH; + sumVec += 1.0 * used_POM_DEPTH; + } if (coord.t < mincoord) { if (readTexture(vec2(coord.s,mincoord)).a == 0.0) { @@ -301,93 +310,104 @@ void main() { } #endif - // color - vec4 data0 = texture2DGradARB(texture, adjustedTexCoord.xy,dcdx,dcdy); + //////////////////////////////// + //////////////////////////////// ALBEDO + //////////////////////////////// - #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); + vec4 Albedo = texture2DGradARB(texture, adjustedTexCoord.xy,dcdx,dcdy) * color; + + #ifdef ENTITIES + if(NameTags == 1) Albedo = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color; + #endif + #ifdef WORLD + if (Albedo.a > 0.1) Albedo.a = normalMat.a; + else Albedo.a = 0.0; + #endif - #ifdef WORLD - if (data0.a > 0.1) data0.a = normalMat.a; - else data0.a = 0.0; - #endif + #ifdef HAND + if (Albedo.a > 0.1) Albedo.a = 0.75; + else Albedo.a = 0.0; + #endif - #ifdef HAND - if (data0.a > 0.1) data0.a = 0.75; - else data0.a = 0.0; - #endif + //////////////////////////////// + //////////////////////////////// NORMAL + //////////////////////////////// - // 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 + #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); - // specular - gl_FragData[2] = texture2DGradARB(specular, adjustedTexCoord.xy,dcdx,dcdy); + normal = applyBump(tbnMatrix,NormalTex, 1.0); + #endif - // 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; + //////////////////////////////// + //////////////////////////////// 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(Albedo.x,data1.x),encodeVec2(Albedo.y,data1.y),encodeVec2(Albedo.z,data1.z),encodeVec2(data1.w,Albedo.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 + //////////////////////////////// + //////////////////////////////// NORMAL + //////////////////////////////// - // color - vec4 data0 = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) ; + #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) ; - data0.rgb *= mix(color.rgb, vec3(0.0), max((puddle_shiny*porosity)*0.5,0) * rainfall ); + normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0); + #endif + //////////////////////////////// + //////////////////////////////// SPECULAR + //////////////////////////////// - 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 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias); + gl_FragData[2] = SpecularTex; + + //////////////////////////////// + //////////////////////////////// ALBEDO + //////////////////////////////// - #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)); + vec4 Albedo = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color; + + + #ifdef WhiteWorld + Albedo.rgb = vec3(1.0); + #endif + + #ifdef WORLD + if (Albedo.a > 0.1) Albedo.a = normalMat.a; + else Albedo.a = 0.0; + #endif + + #ifdef HAND + if (Albedo.a > 0.1) Albedo.a = 0.75; + else Albedo.a = 0.0; + #endif + + //////////////////////////////// + //////////////////////////////// FINALIZE + //////////////////////////////// + + + vec4 data1 = clamp( encode(viewToWorld(normal), blueNoise()*lmtexcoord.zw/50.0+lmtexcoord.zw ),0.0,1.0); + + gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w)); #ifdef WORLD gl_FragData[1].a = 0.0; @@ -395,17 +415,12 @@ void main() { #endif + gl_FragData[3] = vec4(FlatNormals* 0.5 + 0.5,VanillaAO); + + + gl_FragData[4].x = 0; - #ifdef ENTITIES - #ifdef WORLD - gl_FragData[3].xyz = test_motionVectors; + gl_FragData[4].x = 1; #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/programs/all_solid.vsh b/shaders/programs/all_solid.vsh new file mode 100644 index 0000000..d0a9289 --- /dev/null +++ b/shaders/programs/all_solid.vsh @@ -0,0 +1,140 @@ +#extension GL_EXT_gpu_shader4 : enable +#include "/lib/settings.glsl" +#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 !! +*/ + + +#ifndef USE_LUMINANCE_AS_HEIGHTMAP +#ifndef MC_NORMAL_MAP + #undef POM +#endif +#endif + +#ifdef POM + #define MC_NORMAL_MAP +#endif + + +varying vec4 color; +varying float VanillaAO; + +varying vec4 lmtexcoord; +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 + + +attribute vec4 mc_Entity; +uniform int blockEntityId; +uniform int entityId; + +flat varying float blockID; + +flat varying int NameTags; + +attribute vec4 mc_midTexCoord; + +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() { + gl_Position = ftransform(); + lmtexcoord.xy = (gl_MultiTexCoord0).xy; + + FlatNormals = normalize(gl_NormalMatrix * gl_Normal); + + NameTags = 0; + blockID = mc_Entity.x; + + #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. + + + #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 + // try and single out nametag text and then discard nametag background + if( dot(gl_Color.rgb, vec3(0.35)) < 1.0) NameTags = 1; + + if(gl_Color.a >= 0.24 && gl_Color.a <= 0.25 ) gl_Position = vec4(10,10,10,1); +#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 == 10005 ? 0.8 : normalMat.a; + + if (mc_Entity.x == 100 ){ + color.rgb = normalize(color.rgb)*sqrt(3.0); + normalMat.a = 0.9; + } + + gl_Position = toClipSpace3(position); + +#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/programs/all_translucent.fsh b/shaders/programs/all_translucent.fsh new file mode 100644 index 0000000..dbd7368 --- /dev/null +++ b/shaders/programs/all_translucent.fsh @@ -0,0 +1,576 @@ +// #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; + +#include "/lib/settings.glsl" +#include "/lib/res_params.glsl" + + +uniform sampler2D texture; +uniform sampler2D noisetex; +uniform sampler2DShadow shadow; +// uniform sampler2D gaux2; +uniform sampler2D gaux1; +uniform sampler2D depthtex1; +uniform sampler2D colortex5; + +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; + + +flat varying vec4 lightCol; //main light source color (rgb),used light source(1=sun,-1=moon) +flat varying vec3 avgAmbient; + +#include "/lib/color_transforms.glsl" +#include "/lib/projections.glsl" +#include "/lib/sky_gradient.glsl" +#include "/lib/waterBump.glsl" + +#include "/lib/diffuse_lighting.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++) { + // decode depth buffer + float sp = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).x; + + + 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; + + minZ = maxZ-biasamount / 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) ; +} +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 gSimple(float dp, float roughness){ + float k = roughness + 1; + k *= k/8.0; + return dp / (dp * (1.0-k) + k); +} +vec3 GGX2_2(vec3 n, vec3 v, vec3 l, float r, vec3 F0) { + + float alpha = square(r) + 1e-4; // when roughness is zero it fucks up + + vec3 h = normalize(l + v) ; + + float dotNH = clamp(dot(h,n),0.,1.); + float dotVH = clamp(dot(h,v),0.,1.); + + float D = alpha / (2.2 * square( (dotNH * alpha - 1.0) * square(dotNH) + 1.0) ); + + vec3 F = F0 + (1. - F0) * pow(clamp(1.0 - dotVH,0.0,1.0),5.0); + + return F * D; +} +// float SunGGX(vec3 n, vec3 v, vec3 l, float Roughness, float F0){ + +// vec3 h = normalize(l + v) ; + +// float dotNH = clamp(dot(h,n),0.,1.); +// float dotVH = clamp(dot(h,v),0.,1.); + +// float alpha =max(square(Roughness),1e-4) ; + +// float WallFresnel = F0 + (1. - F0) * pow(clamp(1.0 - dotVH,0.0,1.0),5.0); +// float Sun = square( dotNH - pow(alpha,1.5) - 1.0); + +// float Final = ((alpha / (10.0 * Sun + 1e-4)) * WallFresnel); + +// return Final ; +// } +float SunGGX(vec3 n, vec3 v, vec3 l, float roughness,float F0, float fresnel){ + + + 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); + float F = F0 + (1. - F0) * exp2((-5.55473*dotVH-6.98316)*dotVH); + + return dotNL * F * (G * D / (4 * dotNV * dotNL + 1e-7)); +} + + +vec3 normVec (vec3 vec){ + return vec*inversesqrt(dot(vec,vec)); +} +float getWaterHeightmap_dimension(vec2 posxz, float waveM, float waveZ, float iswater) { // water waves + vec2 movement = vec2(frameTimeCounter*0.01); + vec2 pos = posxz ; + float caustic = 1.0; + float weightSum = 0.0; + + float radiance = 2.39996; + mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance))); + + for (int i = 0; i < 3; i++){ + pos = rotationMatrix * pos ; + + float Waves = texture2D(noisetex, pos / 64.0 + movement).b; + + + caustic += exp2(pow(Waves,3.0) * -5.0); + weightSum += exp2(-(3.0-caustic)); + } + return ((3.0-caustic) * weightSum / (30.0 * 3.0)); +} + +vec3 getWaveHeightmap_dimension(vec2 posxz, float iswater){ + + vec2 coord = posxz; + + float deltaPos = 0.25; + + float waveZ = mix(20.0,0.25,iswater); + float waveM = mix(0.0,4.0,iswater); + + float h0 = getWaterHeightmap_dimension(coord, waveM, waveZ, iswater); + float h1 = getWaterHeightmap_dimension(coord + vec2(deltaPos,0.0), waveM, waveZ, iswater); + float h3 = getWaterHeightmap_dimension(coord + vec2(0.0,deltaPos), waveM, waveZ, iswater); + + + float xDelta = ((h1-h0))/deltaPos*2.; + float yDelta = ((h3-h0))/deltaPos*2.; + + vec3 wave = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0))); + + return wave; +} + +//////////////////////////////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 ) { + + gl_FragData[0] = texture2D(texture, lmtexcoord.xy,Texture_MipMap_Bias)*color; + vec3 Albedo = toLinear(gl_FragData[0].rgb); + + float iswater = normalMat.w; + + #ifdef HAND + iswater = 0.1; + #endif + #ifndef Vanilla_like_water + if (iswater > 0.9) { + Albedo = vec3(0.0); + gl_FragData[0] = vec4(vec3(0.0),1.0/255.0); + } + #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); + + + vec2 tempOffset=offsets[framemod8]; + 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 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz; + vec3 np3 = normVec(p3); + + + vec3 normal = normalMat.xyz; + vec3 WaterNormals; + vec3 TranslucentNormals; + + 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(getWaveHeightmap_dimension(posxz.xz,iswater)); + WaterNormals = bump; // tangent space normals for refraction + + 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); + + TranslucentNormals = normalTex; + + normal = applyBump(tbnMatrix,normalTex); + } + + TranslucentNormals += WaterNormals; + + vec4 data0 = vec4(1); + vec4 data1 = clamp( encode(TranslucentNormals, 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)); + + + vec3 Indirect_lighting = DoAmbientLighting_Nether(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lmtexcoord.z, viewToWorld(normal), np3, p3 + cameraPosition); + vec3 FinalColor = Indirect_lighting * Albedo; + + #ifdef Glass_Tint + float alphashit = min(pow(gl_FragData[0].a,2.0),1.0); + FinalColor *= alphashit; + #endif + + vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg; + SpecularTex = iswater > 0.0 && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02); + + if (iswater > 0.0 || (SpecularTex.g > 0.0 || SpecularTex.r > 0.0)){ + vec3 Reflections_Final = vec3(0.0); + float roughness = pow(1.0-SpecularTex.r,2.0); + float f0 = SpecularTex.g; + float F0 = f0; + + float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,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 = F0 + (1.0 - F0) * fresnel; + + vec4 Reflections = vec4(0.0); + if(iswater > 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) { + Reflections.a = 1.0; + Reflections.rgb = texture2D(colortex5,previousPosition.xy).rgb; + } + } + #endif + } + + + Reflections_Final = mix(FinalColor, Reflections.rgb, Reflections.a * fresnel * visibilityFactor); + + + float F2 = pow(clamp(1.0 + normalDotEye,0.0,1.0),pow(1.0-roughness,2.0) * 1.5 + 0.5); + F2 = mix(f0, 1.0, F2); + + Reflections_Final += mix( gl_Fog.color.rgb * 0.25, vec3(0.0), Reflections.a * visibilityFactor) ; + + gl_FragData[0].rgb = Reflections_Final; + + //correct alpha channel with fresnel + float alpha0 = gl_FragData[0].a; + gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel; + + if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.); + + + } else { + gl_FragData[0].rgb = FinalColor; + } + + #ifndef HAND + gl_FragData[1] = vec4(Albedo,iswater); + #endif + } +} diff --git a/shaders/world-1/gbuffers_all_translucent.vsh b/shaders/programs/all_translucent.vsh similarity index 86% rename from shaders/world-1/gbuffers_all_translucent.vsh rename to shaders/programs/all_translucent.vsh index 13986e0..2ea0fdb 100644 --- a/shaders/world-1/gbuffers_all_translucent.vsh +++ b/shaders/programs/all_translucent.vsh @@ -1,6 +1,6 @@ // #version 120 #extension GL_EXT_gpu_shader4 : enable - +#include "/lib/settings.glsl" #include "/lib/res_params.glsl" @@ -16,22 +16,24 @@ 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) - +flat varying vec3 avgAmbient; uniform vec2 texelSize; @@ -49,6 +51,15 @@ uniform int framemod8; vec4 toClipSpace3(vec3 viewSpacePosition) { return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z); } + + + + + + + + + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -56,23 +67,27 @@ vec4 toClipSpace3(vec3 viewSpacePosition) { //////////////////////////////VOID MAIN////////////////////////////// void main() { + + vec4 Swtich_gl_vertex = gl_Vertex; + 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); + vec3 position = mat3(gl_ModelViewMatrix) * vec3(Swtich_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 == 10002) mat = 0.2; if (mc_Entity.x == 72) mat = 0.5; + // if (mc_Entity.x == 8) mat = 0.1; normalMat = vec4(normalize( gl_NormalMatrix*gl_Normal),mat); @@ -88,14 +103,12 @@ void main() { 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 = ( gl_ModelViewMatrix * Swtich_gl_vertex).xyz; viewVector = normalize(tbnMatrix * viewVector); - #ifdef TAA_UPSCALING + #ifdef TAA_UPSCALING gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w; #endif #ifdef TAA @@ -109,4 +122,6 @@ void main() { lightCol.rgb = sc; WsunVec = lightCol.a*normalize(mat3(gbufferModelViewInverse) *sunPosition); + + avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; } diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 0b6b8dc..2650327 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -8,7 +8,7 @@ clouds=off stars=true vignette=false dynamicHandLight=true -program.composite7.enabled=TAA_UPSCALING +program.composite4.enabled=TAA_UPSCALING #Get the correct alpha value : S_A*(1-DST_A)+DST_A blend.gbuffers_terrain = off @@ -38,19 +38,15 @@ alphaTest.gbuffers_skytextured=false alphaTest.gbuffers_hand=true -# profile.potato = shadowMapResolution=512 !Sub_surface_scattering !Variable_Penumbra_Shadows shadowDistance=32 VPS_Search_Samples=8 SHADOW_FILTER_SAMPLE_COUNT=8 !SCREENSPACE_CONTACT_SHADOWS !SSAO ambientOcclusionLevel=0.50 TAA_UPSCALING RENDER_SCALE_X=0.5 RENDER_SCALE_Y=0.5 SHARPENING= 1.0 !VOLUMETRIC_CLOUDS rain_clouds=1.0 cloudCoverage=0.36 cloud_LevelOfDetail=-1 cloud_ShadowLevelOfDetail=-1 CLOUDS_QUALITY=0.2 minRayMarchSteps=20 maxRayMarchSteps=20 !High_Altitude_Clouds reflection_quality=10 Roughness_Strength=0 !Screen_Space_Reflections !Sky_reflection -# profile.lower = shadowMapResolution=512 Sub_surface_scattering !Variable_Penumbra_Shadows shadowDistance=32 VPS_Search_Samples=8 SHADOW_FILTER_SAMPLE_COUNT=8 SCREENSPACE_CONTACT_SHADOWS !SSAO ambientOcclusionLevel=0.50 TAA_UPSCALING RENDER_SCALE_X=0.5 RENDER_SCALE_Y=0.5 SHARPENING= 1.0 !VOLUMETRIC_CLOUDS rain_clouds=1.0 cloudCoverage=0.36 cloud_LevelOfDetail=-1 cloud_ShadowLevelOfDetail=-1 CLOUDS_QUALITY=0.2 minRayMarchSteps=20 maxRayMarchSteps=20 !High_Altitude_Clouds reflection_quality=10 Roughness_Strength=0 !Screen_Space_Reflections !Sky_reflection -# profile.low = shadowMapResolution=512 Sub_surface_scattering Variable_Penumbra_Shadows shadowDistance=32 VPS_Search_Samples=8 SHADOW_FILTER_SAMPLE_COUNT=8 SCREENSPACE_CONTACT_SHADOWS !SSAO ambientOcclusionLevel=0.50 TAA_UPSCALING RENDER_SCALE_X=0.7 RENDER_SCALE_Y=0.7 SHARPENING= 0.5 VOLUMETRIC_CLOUDS rain_clouds=1.0 cloudCoverage=0.36 cloud_LevelOfDetail=0 cloud_ShadowLevelOfDetail=0 CLOUDS_QUALITY=0.35 minRayMarchSteps=20 maxRayMarchSteps=20 High_Altitude_Clouds reflection_quality=10 Roughness_Strength=1 !Screen_Space_Reflections !Sky_reflection -# profile.medium = shadowMapResolution=1024 Sub_surface_scattering Variable_Penumbra_Shadows shadowDistance=48 VPS_Search_Samples=15 SHADOW_FILTER_SAMPLE_COUNT=15 SCREENSPACE_CONTACT_SHADOWS SSAO ambientOcclusionLevel=0.15 TAA_UPSCALING RENDER_SCALE_X=0.7 RENDER_SCALE_Y=0.7 SHARPENING= 0.5 VOLUMETRIC_CLOUDS rain_clouds=1.0 cloudCoverage=0.36 cloud_LevelOfDetail=1 cloud_ShadowLevelOfDetail=0 CLOUDS_QUALITY=0.5 minRayMarchSteps=20 maxRayMarchSteps=30 High_Altitude_Clouds reflection_quality=16 Roughness_Strength=2 Screen_Space_Reflections Sky_reflection -# profile.high = shadowMapResolution=2048 Sub_surface_scattering Variable_Penumbra_Shadows shadowDistance=69. VPS_Search_Samples=15 SHADOW_FILTER_SAMPLE_COUNT=15 SCREENSPACE_CONTACT_SHADOWS SSAO ambientOcclusionLevel=0.15 !TAA_UPSCALING RENDER_SCALE_X=0.7 RENDER_SCALE_Y=0.7 SHARPENING= 0.35 VOLUMETRIC_CLOUDS rain_clouds=1.0 cloudCoverage=0.36 cloud_LevelOfDetail=1 cloud_ShadowLevelOfDetail=0 CLOUDS_QUALITY=0.5 minRayMarchSteps=20 maxRayMarchSteps=30 High_Altitude_Clouds reflection_quality=35 Roughness_Strength=3 Screen_Space_Reflections Sky_reflection -# profile.ultra = shadowMapResolution=4096 Sub_surface_scattering Variable_Penumbra_Shadows shadowDistance=80 VPS_Search_Samples=15 SHADOW_FILTER_SAMPLE_COUNT=25 SCREENSPACE_CONTACT_SHADOWS SSAO ambientOcclusionLevel=0.15 !TAA_UPSCALING RENDER_SCALE_X=0.7 RENDER_SCALE_Y=0.7 SHARPENING= 0.2 VOLUMETRIC_CLOUDS rain_clouds=1.0 cloudCoverage=0.36 cloud_LevelOfDetail=2 cloud_ShadowLevelOfDetail=2 CLOUDS_QUALITY=0.5 minRayMarchSteps=20 maxRayMarchSteps=50 High_Altitude_Clouds reflection_quality=35 Roughness_Strength=3 Screen_Space_Reflections Sky_reflection +sliders = Cumulus_coverage Cumulus_density Alto_coverage Alto_density ORB_ColMult ORB_X ORB_Y ORB_Z ORB_R ORB_G ORB_B TOD_Fog_mult Morning_Uniform_Fog Noon_Uniform_Fog Evening_Uniform_Fog Night_Uniform_Fog Morning_Cloudy_Fog Noon_Cloudy_Fog Evening_Cloudy_Fog Night_Cloudy_Fog NetherFog_brightness WeatherDay Summer_Leaf_R Summer_Leaf_G Summer_Leaf_B Fall_Leaf_R Fall_Leaf_G Fall_Leaf_B Winter_Leaf_R Winter_Leaf_G Winter_Leaf_B Spring_Leaf_R Spring_Leaf_G Spring_Leaf_B Summer_R Summer_G Summer_B Fall_R Fall_G Fall_B Winter_R Winter_G Winter_B Spring_R Spring_G Spring_B Season_Length CaveFogFallOff CaveFogColor_R CaveFogColor_G CaveFogColor_B indirect_effect GI_Strength Cloud_Height Dynamic_sky_day ambient_brightness AmbientLight_R AmbientLight_G AmbientLight_B cloud_speed Rain_coverage override_R override_G override_B override_Cloudy_Fog_Density override_cloudyfog_fade override_fog override_Uniform_Fog_Density override_uniformfog_fade override_Bloomy_Fog override_Sun_Strength Moon_temp Haze_amount UniformFog_amount CloudyFog_amount TimeOfDayFog_multiplier RainFog_amount CaveFog_amount uniformfog_fade cloudyfog_fade cloudray_amount Swamp_cloudyfog_height Jungle_cloudyfog_fade Swamp_uniformfog_height Jungle_uniformfog_fade noise_mode Distant_shadow_quality ambient_temp Sun_temp Puddle_Size Cloud_Size LabSSS_Curve Emissive_Curve Emissive_Brightness AO_Strength Swamp_Sun_Strength Jungle_Sun_Strength Swamp_Bloomy_Fog Jungle_Bloomy_Fog Swamp_Mie Jungle_Mie Swamp_cloudyfog_Density Jungle_Cloudy_Fog_Density Swamp_UniformFog_Density Jungle_Uniform_Fog_Density Swamp_Bloomy_Fog Jungle_Bloomy_Fog Swamp_Mie Jungle_Mie Swamp_R Swamp_G Swamp_B Jungle_R Jungle_G Jungle_B Jungle_fog_strength Swamp_fog_strength Lush_fog_strength Snells_Window_Width self_shadow_samples Shadow_brightness Cloud_top_cutoff Cloud_base_cutoff Cloud_fade_amount BLOOMY_FOG FOG_RAIN_MULTIPLIER FOG_TOD_MULTIPLIER CLOUDY_FOG_AMOUNT BASE_FOG_AMOUNT WAVY_SPEED WAVY_STRENGTH ANTI_GHOSTING BLOOM_STRENGTH shadowDistance shadowDistanceRenderMul FinalR FinalG FinalB Ambient_Mult Sky_Brightness fog_coefficientMieR fog_coefficientMieG fog_coefficientMieB sun_illuminance sunColorG sunColorB sunColorR sky_mieg sky_coefficientMieB sky_coefficientMieG sky_coefficientMieR sky_coefficientRayleighB sky_coefficientRayleighG sky_coefficientRayleighR CLOUDS_QUALITY EXPOSURE_MULTIPLIER MIN_LIGHT_AMOUNT TORCH_R TORCH_G TORCH_B TORCH_AMOUNT shadowMapResolution sunPathRotation SKY_BRIGHTNESS_DAY SKY_BRIGHTNESS_NIGHT BLEND_FACTOR FLICKER_REDUCTION MOTION_REJECTION VL_SAMPLES Exposure_Speed POM_MAP_RES POM_DEPTH MAX_ITERATIONS MAX_DIST SSR_STEPS ambientOcclusionLevel SEA_LEVEL ATMOSPHERIC_DENSITY CLOUDS_SHADOWS_STRENGTH moon_illuminance moonColorR moonColorG moonColorB fog_mieg1 fog_mieg2 fog_coefficientRayleighR fog_coefficientRayleighG SATURATION Manual_exposure_value focal aperture MANUAL_FOCUS SHADOW_FILTER_SAMPLE_COUNT Max_Filter_Depth VPS_Search_Samples Min_Shadow_Filter_Radius Max_Shadow_Filter_Radius SSAO_SAMPLES Water_Top_Layer fog_coefficientRayleighB SHARPENING rayMarchSampleCount Dirt_Mie_Phase Dirt_Amount Dirt_Scatter_R Dirt_Scatter_G Dirt_Scatter_B Dirt_Absorb_R Dirt_Absorb_G Dirt_Absorb_B Water_Absorb_R Water_Absorb_G Water_Absorb_B Purkinje_strength Purkinje_strength Purkinje_R Purkinje_G Purkinje_B Texture_MipMap_Bias DoF_Adaptation_Speed Purkinje_Multiplier CROSSTALK RENDER_SCALE_X RENDER_SCALE_Y VL_RENDER_RESOLUTION BLOOM_QUALITY VL_RENDER_RESOLUTION RAY_COUNT STEPS STEP_LENGTH cloud_LevelOfDetail cloud_ShadowLevelOfDetail cloud_LevelOfDetailLQ cloud_ShadowLevelOfDetailLQ minRayMarchSteps maxRayMarchSteps minRayMarchStepsLQ maxRayMarchStepsLQ cloudDensity cloudCoverage fbmAmount fbmPower1 fbmPower2 cloudMieG cloudMieG2 cloudMie2Multiplier Strong_SSS_strength Medium_SSS_strength Weak_SSS_strength Shadow_brightness Roughness_Threshold Sun_specular_Strength reflection_quality Roughness_Strength SSS_mode DOF_QUALITY DOF_ANAMORPHIC_RATIO AEROCHROME_PINKNESS -sliders = WeatherDay Summer_Leaf_R Summer_Leaf_G Summer_Leaf_B Fall_Leaf_R Fall_Leaf_G Fall_Leaf_B Winter_Leaf_R Winter_Leaf_G Winter_Leaf_B Spring_Leaf_R Spring_Leaf_G Spring_Leaf_B Summer_R Summer_G Summer_B Fall_R Fall_G Fall_B Winter_R Winter_G Winter_B Spring_R Spring_G Spring_B Season_Length CaveFogFallOff CaveFogColor_R CaveFogColor_G CaveFogColor_B indirect_effect GI_Strength Cloud_Height Dynamic_sky_day ambient_brightness AmbientLight_R AmbientLight_G AmbientLight_B cloud_speed Rain_coverage override_R override_G override_B override_Cloudy_Fog_Density override_cloudyfog_fade override_fog override_Uniform_Fog_Density override_uniformfog_fade override_Bloomy_Fog override_Sun_Strength Moon_temp Haze_amount UniformFog_amount CloudyFog_amount TimeOfDayFog_multiplier RainFog_amount CaveFog_amount uniformfog_fade cloudyfog_fade cloudray_amount Swamp_cloudyfog_height Jungle_cloudyfog_fade Swamp_uniformfog_height Jungle_uniformfog_fade noise_mode Distant_shadow_quality ambient_temp Sun_temp Puddle_Size Cloud_Size LabSSS_Curve Emissive_Curve Emissive_Brightness AO_Strength Swamp_Sun_Strength Jungle_Sun_Strength Swamp_Bloomy_Fog Jungle_Bloomy_Fog Swamp_Mie Jungle_Mie Swamp_cloudyfog_Density Jungle_Cloudy_Fog_Density Swamp_UniformFog_Density Jungle_Uniform_Fog_Density Swamp_Bloomy_Fog Jungle_Bloomy_Fog Swamp_Mie Jungle_Mie Swamp_R Swamp_G Swamp_B Jungle_R Jungle_G Jungle_B Jungle_fog_strength Swamp_fog_strength Lush_fog_strength Snells_Window_Width self_shadow_samples Shadow_brightness Cloud_top_cutoff Cloud_base_cutoff Cloud_fade_amount BLOOMY_FOG FOG_RAIN_MULTIPLIER FOG_TOD_MULTIPLIER CLOUDY_FOG_AMOUNT BASE_FOG_AMOUNT WAVY_SPEED WAVY_STRENGTH ANTI_GHOSTING BLOOM_STRENGTH shadowDistance shadowDistanceRenderMul FinalR FinalG FinalB Ambient_Mult Sky_Brightness fog_coefficientMieR fog_coefficientMieG fog_coefficientMieB sun_illuminance sunColorG sunColorB sunColorR sky_mieg sky_coefficientMieB sky_coefficientMieG sky_coefficientMieR sky_coefficientRayleighB sky_coefficientRayleighG sky_coefficientRayleighR CLOUDS_QUALITY EXPOSURE_MULTIPLIER MIN_LIGHT_AMOUNT TORCH_R TORCH_G TORCH_B TORCH_AMOUNT shadowMapResolution sunPathRotation SKY_BRIGHTNESS_DAY SKY_BRIGHTNESS_NIGHT BLEND_FACTOR FLICKER_REDUCTION MOTION_REJECTION VL_SAMPLES Exposure_Speed POM_MAP_RES POM_DEPTH MAX_ITERATIONS MAX_DIST SSR_STEPS ambientOcclusionLevel SEA_LEVEL ATMOSPHERIC_DENSITY CLOUDS_SHADOWS_STRENGTH moon_illuminance moonColorR moonColorG moonColorB fog_mieg1 fog_mieg2 fog_coefficientRayleighR fog_coefficientRayleighG SATURATION Manual_exposure_value focal aperture MANUAL_FOCUS SHADOW_FILTER_SAMPLE_COUNT Max_Filter_Depth VPS_Search_Samples Min_Shadow_Filter_Radius Max_Shadow_Filter_Radius SSAO_SAMPLES Water_Top_Layer fog_coefficientRayleighB SHARPENING rayMarchSampleCount Dirt_Mie_Phase Dirt_Amount Dirt_Scatter_R Dirt_Scatter_G Dirt_Scatter_B Dirt_Absorb_R Dirt_Absorb_G Dirt_Absorb_B Water_Absorb_R Water_Absorb_G Water_Absorb_B Purkinje_strength Purkinje_strength Purkinje_R Purkinje_G Purkinje_B Texture_MipMap_Bias DoF_Adaptation_Speed Purkinje_Multiplier CROSSTALK RENDER_SCALE_X RENDER_SCALE_Y VL_RENDER_RESOLUTION BLOOM_QUALITY VL_RENDER_RESOLUTION RAY_COUNT STEPS STEP_LENGTH cloud_LevelOfDetail cloud_ShadowLevelOfDetail cloud_LevelOfDetailLQ cloud_ShadowLevelOfDetailLQ minRayMarchSteps maxRayMarchSteps minRayMarchStepsLQ maxRayMarchStepsLQ cloudDensity cloudCoverage fbmAmount fbmPower1 fbmPower2 cloudMieG cloudMieG2 cloudMie2Multiplier Strong_SSS_strength Medium_SSS_strength Weak_SSS_strength Shadow_brightness Roughness_Threshold Sun_specular_Strength reflection_quality Roughness_Strength SSS_mode DOF_QUALITY DOF_ANAMORPHIC_RATIO AEROCHROME_PINKNESS -# screen=[Atmospherics] [TAA_OPTIONS] [Lighting] [Camera] [Shading] [Wavy_stuff] [Water_and_transparencies] [Xonk_settings] +screen.columns=2 +screen = [Direct_Light] [World] [Ambient_light] [Fog] [Post_Processing] [Clouds] [Misc_Settings] [Climate] - -screen.columns=1 -screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] [Climate] [Misc_Settings] +# screen = [Direct_Light] [World] +# [Ambient_light] [Fog] +# [Post_Processing] [Clouds] +# [Misc_Settings] [Climate] ######## LIGHTING ### DIRECT LIGHT @@ -68,7 +64,7 @@ screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] ### AMBIENT LIGHT screen.Ambient_light.columns=1 - screen.Ambient_light = [Torch] [Ambient] [ambientlight_colors] indirect_effect HQ_SSGI AO_Strength GI_Strength + screen.Ambient_light = [Torch] [Ambient] [ambientlight_colors] indirect_effect HQ_SSGI AO_Strength GI_Strength AO_in_sunlight screen.ambientlight_colors.columns=1 screen.ambientlight_colors = ambient_brightness ambient_colortype ambient_temp AmbientLight_R AmbientLight_G AmbientLight_B @@ -91,13 +87,22 @@ screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] 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 + screen.POM = POM MAX_ITERATIONS POM_DEPTH MAX_DIST Adaptive_Step_length Horrible_slope_normals ######## CLIMATE screen.Climate.columns=1 - screen.Climate = [Seasons] [Weather] [Biome_Fog] + screen.Climate = [Weather] [Biome_Fog] [Seasons] + + ## DAILY WEATHER + screen.Weather.columns=1 + screen.Weather = Daily_Weather WeatherDay + + ## BIOME SPECIFICS + screen.Biome_Fog.columns=1 + screen.Biome_Fog = Biome_specific_environment + ## SEASONS screen.Seasons.columns=1 @@ -115,27 +120,11 @@ screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] 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 + screen.Atmospherics = [Sky] [Fog] [Biome_Fog] [Clouds] Altostratus Cumulus_Clouds Allow_Vanilla_sky + ### SKY screen.Sky.columns=1 screen.Sky = [Sky_coefficients] [Sun_and_Moon_Colors] sunPathRotation @@ -145,17 +134,22 @@ screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] ### 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 + # screen.Clouds = VOLUMETRIC_CLOUDS Altostratus 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 CLOUDS_SHADOWS VL_CLOUDS_SHADOWS + screen.Clouds = VOLUMETRIC_CLOUDS CLOUDS_QUALITY Cumulus Altostratus Cumulus_coverage Alto_coverage Cumulus_density Alto_density CLOUDS_SHADOWS ### 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 = VL_RENDER_RESOLUTION VL_SAMPLES BLOOMY_FOG Haze_amount RainFog_amount [TOD_fog] [Biome_Fog] [Cave_Fog] BorderFog - 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.TOD_fog.columns=2 + screen.TOD_fog = TOD_Fog_mult Morning_Uniform_Fog Morning_Cloudy_Fog Noon_Uniform_Fog Noon_Cloudy_Fog Evening_Uniform_Fog Evening_Cloudy_Fog Night_Uniform_Fog Night_Cloudy_Fog + + screen.Cave_Fog.columns=1 + screen.Cave_Fog = Cave_fog CaveFog_amount CaveFogFallOff CaveFogColor_R CaveFogColor_G CaveFogColor_B 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] @@ -184,7 +178,10 @@ screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] ######## 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.Misc_Settings = [the_orb] WhiteWorld ambientLight_only Glass_Tint display_LUT DISABLE_ALPHA_MIPMAPS + + screen.the_orb.columns = 1 + screen.the_orb = THE_ORB ORB_X ORB_Y ORB_Z ORB_ColMult ORB_R ORB_G ORB_B screen.LabPBR.columns = 1 screen.LabPBR = [Reflections] [Subsurface_Scattering] [Emissives] [POM] [Porosity] @@ -199,7 +196,6 @@ screen = [Direct_Light] [Ambient_light] [World] [Atmospherics] [Post_Processing] 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 @@ -260,11 +256,19 @@ 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.ifEndBoss = smooth(if(bossBattle == 2, 1, 0 ), 1, 1) + +# uniform.float.EndSequence1 = smooth(if(hideGUI == 1, 1.0, 0.0), 30, 0) + +# uniform.float.EndSequence2 = smooth(if(EndSequence1 > 0.95, 1.0, 0.0), 1.25, 0) + # 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) +# 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 @@ -327,3 +331,11 @@ variable.float.shSunZ = (shadowModelView.0.2 * wSunX + shadowModelView.1.2 * wSu uniform.vec3.shadowLightVec = vec3(lightSign*shSunX, lightSign*shSunY, lightSign*shSunZ) uniform.float.shadowMaxProj = 150.0/abs(sunPosY) + + + + + +# photon shit +uniform.vec2.view_res = vec2(viewWidth, viewHeight) +uniform.vec2.view_pixel_size = vec2(1.0 / viewWidth, 1.0 / viewHeight) \ No newline at end of file diff --git a/shaders/shadow.fsh b/shaders/shadow.fsh index 9eb9359..b398e50 100644 --- a/shaders/shadow.fsh +++ b/shaders/shadow.fsh @@ -20,9 +20,11 @@ float R2_dither(){ } 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/world-1/block.properties b/shaders/world-1/block.properties deleted file mode 100644 index 73045f4..0000000 --- a/shaders/world-1/block.properties +++ /dev/null @@ -1,20 +0,0 @@ -#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/composite15.fsh b/shaders/world-1/composite15.fsh index 74136a6..298ca9a 100644 --- a/shaders/world-1/composite15.fsh +++ b/shaders/world-1/composite15.fsh @@ -1,28 +1,8 @@ #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 ] +#include "/lib/settings.glsl" #ifdef DOF //hexagon pattern @@ -379,15 +359,10 @@ 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" + -#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; @@ -440,7 +415,7 @@ void main() { #ifdef AUTOFOCUS float focus = ld(texture2D(depthtex0, vec2(0.5)).r)*far; #else - float focus = MANUAL_FOCUS*screenBrightness; + float focus = MANUAL_FOCUS; #endif float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0); #ifdef FAR_BLUR_ONLY @@ -478,18 +453,14 @@ void main() { #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 lightScat = clamp(BLOOM_STRENGTH * 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)*BLOOMY_FOG*0.5,0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0); - 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; + col = ( mix(col, bloom, VL_abs) + bloom*lightScat) * exposure.rgb; /* //Purkinje Effect float lum = dot(col,vec3(0.15,0.3,0.55)); diff --git a/shaders/world-1/composite15.vsh b/shaders/world-1/composite15.vsh index 5099bbb..634d9d3 100644 --- a/shaders/world-1/composite15.vsh +++ b/shaders/world-1/composite15.vsh @@ -1,9 +1,7 @@ #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 ] +#include "/lib/settings.glsl" varying vec2 texcoord; flat varying vec4 exposure; diff --git a/shaders/world-1/composite2.fsh b/shaders/world-1/composite2.fsh index e9506b3..8c8c4d9 100644 --- a/shaders/world-1/composite2.fsh +++ b/shaders/world-1/composite2.fsh @@ -1,70 +1,33 @@ #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 ] +#include "/lib/settings.glsl" +#include "/lib/diffuse_lighting.glsl" -#define GI_Strength 1.0 // strength of bounced light areas [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 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; +const bool colortex5MipmapEnabled = true; + 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 colortex3; uniform sampler2D colortex7; +uniform sampler2D colortex5; +uniform sampler2D colortex2; uniform sampler2D colortex8; +uniform sampler2D colortex15; +uniform sampler2D colortex6;//Skybox 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; @@ -77,45 +40,52 @@ 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 mat4 gbufferPreviousModelView; +uniform mat4 gbufferPreviousProjection; +uniform vec3 previousCameraPosition; + 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" + + +#include "/lib/color_transforms.glsl" +#include "/lib/waterBump.glsl" +#include "/lib/sky_gradient.glsl" + + float ld(float dist) { return (2.0 * near) / (far + near - dist * (far - near)); } -vec3 ld(vec3 dist) { - return (2.0 * near) / (far + near - dist * (far - near)); -} -#include "lib/specular.glsl" +vec2 RENDER_SCALE = vec2(1.0); + +#include "/lib/specular.glsl" +#include "/lib/nether_fog.glsl" + + + + vec3 normVec (vec3 vec){ return vec*inversesqrt(dot(vec,vec)); @@ -144,20 +114,12 @@ vec3 fp10Dither(vec3 color,float dither){ 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; @@ -171,6 +133,24 @@ vec2 decodeVec2(float a){ const float constant2 = 256. / 255.; return fract( a * constant1 ) * constant2 ; } +// float linZ(float depth) { +// return (2.0 * near) / (far + near - depth * (far - near)); +// // l = (2*n)/(f+n-d(f-n)) +// // f+n-d(f-n) = 2n/l +// // -d(f-n) = ((2n/l)-f-n) +// // d = -((2n/l)-f-n)/(f-n) + +// } +// float invLinZ (float lindepth){ +// return -((2.0*near/lindepth)-far-near)/(far-near); +// } + +// vec3 toClipSpace3(vec3 viewSpacePosition) { +// return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +// } + + + vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort) { @@ -185,12 +165,17 @@ vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort 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); @@ -215,123 +200,116 @@ vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot,float r0) return vec2(cos_v, sin_v)*ssR; } -void ssAO(inout vec3 lighting,vec3 fragpos,float mulfov, vec2 noise, vec3 normal, float lightmap){ + +float ssao(vec3 fragpos, float dither,vec3 normal) +{ + float mulfov = 1.0; ivec2 pos = ivec2(gl_FragCoord.xy); - const float tan70 = tan(70.*3.14/240.); + const float tan70 = tan(70.*3.14/180.); float mulfov2 = gbufferProjection[1][1]/tan70; - float maxR2 = fragpos.z*fragpos.z*mulfov2*2.*1.412/50.0; + const float PI = 3.14159265; + const float samplingRadius = 0.712; + float angle_thresh = 0.05; - float rd = mulfov2 * 0.04 ; + + + float rd = mulfov2*0.05; //pre-rotate direction - float n = 0.0; + float n = 0.; float occlusion = 0.0; - vec2 acc = -(TAA_Offset*(texelSize/2)) ; + vec2 acc = -vec2(TAA_Offset)*texelSize*0.5; + float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5; - 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); + vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026)); + for (int j = 0; j < 7+2 ;j++) { + vec2 sp = tapLocation(j,v.x,7+2,2.,v.y); + vec2 sampleOffset = sp*rd; + ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight)); + if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) { + vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x)); + vec3 vec = t0.xyz - fragpos; + float dsquared = dot(vec,vec); if (dsquared > 1e-5){ - if (dsquared < maxR2){ - float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal) ),0.,1.); - occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0); + if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){ + float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.); + occlusion += NdotV; } - n += 1.0 ; + 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; + + + + + return clamp(1.0-occlusion/n*2.0,0.,1.0); } - - -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 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; } -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 worldToView(vec3 worldPos) { + vec4 pos = vec4(worldPos, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; } +void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ + inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value + int spCount = rayMarchSampleCount; + vec3 start = toShadowSpaceProjected(rayStart); + vec3 end = toShadowSpaceProjected(rayEnd); + vec3 dV = (end-start); + //limit ray length at 32 blocks for performance and reducing integration error + //you can't see above this anyway + float maxZ = min(rayLength,12.0)/(1e-8+rayLength); + dV *= maxZ; + vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; + rayLength *= maxZ; + float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; + estEndDepth *= maxZ; + estSunDepth *= maxZ; + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); -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; + float expFactor = 11.0; + vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; + for (int i=0;i 1.0) occlude += skyLightDir; - } - lighting *= occlude/nrays; +void LabEmission( + inout vec3 Lighting, + vec3 Albedo, + float Emission +){ + // if( Emission < 255.0/255.0 ) Lighting = mix(Lighting, Albedo * Emissive_Brightness, pow(Emission, Emissive_Curve)); // old method.... idk why + if( Emission < 255.0/255.0 ) Lighting += (Albedo * Emissive_Brightness) * pow(Emission, Emissive_Curve); } void main() { @@ -339,97 +317,109 @@ void main() { 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; + vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; + + float z0 = texture2D(depthtex0,texcoord).x; float z = texture2D(depthtex1,texcoord).x; + vec2 tempOffset=TAA_Offset; + float noise = blueNoise(); vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z)); vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; vec3 np3 = normVec(p3); - + + + vec4 trpData = texture2D(colortex7,texcoord); + bool iswater = trpData.a > 0.99; 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 data = texture2D(colortex1,texcoord); // terraom vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + + float Translucent_Programs = texture2D(colortex2,texcoord).a; // the shader for all translucent progams. + // Normal // + vec3 normal = decode(dataUnpacked0.yw) ; + + vec4 normalAndAO = texture2D(colortex15,texcoord); + vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; + float vanilla_AO = 1.0 - exp2(-5 * pow(1-normalAndAO.a,3)) ; + 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; + if (z >=1.0) { + vec3 color = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.02; - vec3 WsunVec = normalize(mat3(gbufferModelViewInverse) * viewspace_sunvec); - float LightDir = max(dot(normal, WsunVec),0.0); + gl_FragData[0].rgb = clamp(fp10Dither(color*8./3. * (1.0-rainStrength*0.4),triangularize(noise)),0.0,65000.); + + } else { + + p3 += gbufferModelViewInverse[3].xyz + cameraPosition; + + // do all ambient lighting stuff + vec3 Indirect_lighting = DoAmbientLighting_Nether(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3, p3 ); + + + vec3 LightColor = LightSourceColor(); + + float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos)); + float OrbMie = max(exp((p3.y - 60) / -30.),0); + + // 0.5 added because lightsources are always high radius. + float NdotL = clamp( dot(normal,normalize(WsunVec)) + 0.25,0.0,1.0); + + vec3 LightSource = LightColor * NdotL * OrbMie ; + + // LightSource *= rayTraceShadow(worldToView(normalize(-LightPos)), fragpos, interleaved_gradientNoise()); + // LightSource *= GetCloudShadow(p3, WsunVec, blueNoise()); - vec3 ambientCoefs = normal/dot(abs(normal),vec3(1.)); + // finalize + gl_FragData[0].rgb = (Indirect_lighting) * albedo; + // gl_FragData[0].rgb = LightSource * albedo; - #ifdef WhiteWorld - albedo = vec3(1.0); - #endif + #ifdef Specular_Reflections + MaterialReflections_N(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand); + #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 + if(!hand) gl_FragData[0].rgb *= ssao(fragpos,noise,FlatNormals) * vanilla_AO; - // vec3 ambientLight = vec3(1.0) / 30; - vec3 ambientLight = ((ambientUp + ambientDown + ambientRight + ambientLeft + ambientB + ambientF) ) * (abs(ambientCoefs.y * 0.5) + 0.5) ; + #ifdef LabPBR_Emissives + LabEmission(gl_FragData[0].rgb, albedo, SpecularTex.a); + #endif + } + + // ////// border Fog + // if(Translucent_Programs > 0.0){ + // vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + // float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0); + + // gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ; + // } - 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; + ////// Water Fog + if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){ + vec3 fragpos0 = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z0)); + float Vdiff = distance(fragpos,fragpos0); - //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 + if(isEyeInWater == 1) Vdiff = (length(fragpos)); - ambientLight += Lightsources; + float VdotU = np3.y; + float estimatedDepth = Vdiff; //assuming water plane + float estimatedSunDepth = estimatedDepth; //assuming water plane - #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 ambientColVol = vec3(1.0,0.25,0.5) * 0.33 ; + waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol); + } - 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 index b1cf351..6d29816 100644 --- a/shaders/world-1/composite2.vsh +++ b/shaders/world-1/composite2.vsh @@ -1,17 +1,12 @@ #version 120 #extension GL_EXT_gpu_shader4 : enable -#define TAA + +#include "/lib/settings.glsl" + 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; @@ -43,26 +38,14 @@ void main() { texcoord = gl_MultiTexCoord0.xy; tempOffsets = HaltonSeq2(frameCounter%10000); + TAA_Offset = offsets[frameCounter%8]; + #ifndef TAA - TAA_Offset = vec2(0.0); + 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); + avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; zMults = vec3((far * near)*2.0,far+near,far-near); - - } diff --git a/shaders/world-1/composite3.fsh b/shaders/world-1/composite3.fsh new file mode 100644 index 0000000..f3fae99 --- /dev/null +++ b/shaders/world-1/composite3.fsh @@ -0,0 +1,79 @@ +#version 120 +//Volumetric fog rendering +#extension GL_EXT_gpu_shader4 : enable + +#include "/lib/settings.glsl" + +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; + + +#include "/lib/color_transforms.glsl" +#include "/lib/color_dither.glsl" +#include "/lib/projections.glsl" +#include "/lib/nether_fog.glsl" + + +#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) + +float interleaved_gradientNoise(){ + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); +} +float blueNoise(){ + return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); +} + +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +varying vec2 texcoord; + +void main() { +/* DRAWBUFFERS:0 */ + + // if (isEyeInWater == 0){ + // vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize; + // float z = texture2D(depthtex0,tc).x; + // vec3 fragpos = toScreenSpace(vec3(tc,z)); + + // vec3 fragpos_ALT = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + + // float noise = blueNoise(); + // mat2x3 vl = getVolumetricRays(noise,fragpos, interleaved_gradientNoise()); + + // float absorbance = dot(vl[1],vec3(0.22,0.71,0.07)); + + // gl_FragData[0] = clamp(vec4(vl[0],absorbance),0.000001,65000.); + + // } else { + // gl_FragData[0] = vec4(0.0); + // } +} diff --git a/shaders/world1/lib/composite3.vsh b/shaders/world-1/composite3.vsh similarity index 69% rename from shaders/world1/lib/composite3.vsh rename to shaders/world-1/composite3.vsh index 05cecb7..91f9f96 100644 --- a/shaders/world1/lib/composite3.vsh +++ b/shaders/world-1/composite3.vsh @@ -1,10 +1,12 @@ #version 120 #extension GL_EXT_gpu_shader4 : enable -varying vec2 texcoord; -flat varying vec3 zMults; -uniform float far; -uniform float near; +flat varying float tempOffsets; + +uniform int frameCounter; + +#include "/lib/util.glsl" + //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -12,8 +14,9 @@ uniform float near; //////////////////////////////VOID MAIN////////////////////////////// void main() { - zMults = vec3(1.0/(far * near),far+near,far-near); gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; + tempOffsets = HaltonSeq2(frameCounter%10000); + + gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0; } diff --git a/shaders/world-1/composite5.fsh b/shaders/world-1/composite5.fsh deleted file mode 100644 index 5444e90..0000000 --- a/shaders/world-1/composite5.fsh +++ /dev/null @@ -1,271 +0,0 @@ -#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; + vec2 data = texture2D(colortex11,texcoord).xy; // translucents + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); - if (texture2D(colortex7,refractedCoord).a < 0.99) - refractedCoord = texcoord; + vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) ); - } + // vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth); + + #ifdef Refraction + refractedCoord += normals.xy * glassdepth; + + float refractedalpha = texture2D(colortex13,refractedCoord).a; + if(refractedalpha <= 0.0) refractedCoord = texcoord; // remove refracted coords on solids + #endif - 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.; + + if (Translucent_Programs.a > 0.0){ + #ifdef Glass_Tint + vec3 GlassAlbedo = texture2D(colortex13,texcoord).rgb * 5.0; + color = color*GlassAlbedo.rgb + color * clamp(pow(1.0-luma(GlassAlbedo.rgb),10.),0.0,1.0); + #endif - 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 = color*(1.0-Translucent_Programs.a) + Translucent_Programs.rgb; + } - 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); + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0); + bloomyfogmult = 1.0 - fogdistfade*0.5 ; - 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; + color.rgb = mix(color.rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ; } + + // color *= vl.a; + // color += vl.rgb; + // bloomyfogmult *= pow(vl.a,0.1); + + + // 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; + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0); + bloomyfogmult *= fogfade*0.70+0.3 ; } /// lava. if (isEyeInWater == 2){ @@ -185,21 +176,21 @@ void main() { } /// powdered snow if (isEyeInWater == 3){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); - vl.a = 0.0; + bloomyfogmult = 0.0; } // blidnesss - color.rgb *= mix(1.0, clamp(1.5-pow(length(fragpos2)*(blindness*0.2),2.0),0.0,1.0), blindness); + if (blindness > 0.0){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + 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); + if(darknessFactor > 0.0){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z2)); + color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(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[0].r = bloomyfogmult; 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/composite8.fsh b/shaders/world-1/composite8.fsh index dd85629..4348131 100644 --- a/shaders/world-1/composite8.fsh +++ b/shaders/world-1/composite8.fsh @@ -1,20 +1,8 @@ #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 - +#include "/lib/settings.glsl" const int noiseTextureResolution = 32; @@ -48,12 +36,18 @@ uniform sampler2D depthtex0; uniform vec2 texelSize; uniform float frameTimeCounter; +uniform int framemod8; uniform float viewHeight; uniform float viewWidth; uniform vec3 previousCameraPosition; uniform mat4 gbufferPreviousModelView; + + + + #define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) -#include "lib/projections.glsl" + +#include "/lib/projections.glsl" float luma(vec3 color) { @@ -231,15 +225,54 @@ vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max) vec3 toClipSpace3Prev(vec3 viewSpacePosition) { return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; } +vec3 tonemap(vec3 col){ + return col/(1+luma(col)); +} +vec3 invTonemap(vec3 col){ + return col/(1-luma(col)); +} +vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth) +{ + vec2 du = vec2(texelSize.x*2., 0.0); + vec2 dv = vec2(0.0, texelSize.y*2.); + + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x); + + vec3 dmin = dmc; + dmin = dmin.z > dtr.z? dtr : dmin; + dmin = dmin.z > dtl.z? dtl : dmin; + dmin = dmin.z > dbl.z? dbl : dmin; + dmin = dmin.z > dbr.z? dbr : dmin; + #ifdef TAA_UPSCALING + dmin.xy = dmin.xy/RENDER_SCALE; + #endif + return dmin; +} +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); vec3 TAA_hq(){ + + vec2 adjTC = texcoord; + + //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion #ifdef CLOSEST_VELOCITY - vec3 closestToCamera = closestToCamera3x3(); + vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); #endif #ifndef CLOSEST_VELOCITY - vec3 closestToCamera = vec3(texcoord,texture2D(depthtex0,texcoord).x); + vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x); #endif //reproject previous frame @@ -250,50 +283,53 @@ vec3 TAA_hq(){ 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; + 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; - //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 + #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 - - vec3 albedoPrev = FastCatmulRom(colortex5, previousPosition.xy,vec4(texelSize, 1.0/texelSize), 0.82).xyz; + #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; - - //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.)); + //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.)); + vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz; + vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.)); #endif //De-tonemap @@ -303,14 +339,16 @@ vec3 TAA_hq(){ void main() { /* DRAWBUFFERS:5 */ -gl_FragData[0].a = 1.0; + 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); + 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; + 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 index 24ef8ce..372c136 100644 --- a/shaders/world-1/composite8.vsh +++ b/shaders/world-1/composite8.vsh @@ -7,7 +7,10 @@ flat varying float exposureA; flat varying float tempOffsets; uniform sampler2D colortex4; uniform int frameCounter; + + #include "/lib/util.glsl" + void main() { tempOffsets = HaltonSeq2(frameCounter%10000); diff --git a/shaders/world-1/composite9.fsh b/shaders/world-1/composite9.fsh index 517bfe5..a4b6244 100644 --- a/shaders/world-1/composite9.fsh +++ b/shaders/world-1/composite9.fsh @@ -2,7 +2,6 @@ //downsample 1st pass (half res) for bloom uniform sampler2D colortex5; -uniform sampler2D colortex8; uniform vec2 texelSize; uniform float viewWidth; uniform float viewHeight; @@ -18,9 +17,6 @@ void main() { 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; @@ -43,10 +39,6 @@ emissives *= 5; 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/deferred.fsh b/shaders/world-1/deferred.fsh index 5745d9d..2b3c2e5 100644 --- a/shaders/world-1/deferred.fsh +++ b/shaders/world-1/deferred.fsh @@ -2,14 +2,7 @@ #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] +#include "/lib/settings.glsl" flat varying vec3 ambientUp; @@ -53,8 +46,12 @@ 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; @@ -75,62 +72,8 @@ const float[17] Slightmap = float[17](14.0,17.,19.0,22.0,24.0,28.0,31.0,40.0,60. 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 ) diff --git a/shaders/world-1/deferred.vsh b/shaders/world-1/deferred.vsh index 2c5b20a..4fa6840 100644 --- a/shaders/world-1/deferred.vsh +++ b/shaders/world-1/deferred.vsh @@ -1,14 +1,8 @@ #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 + +#include "/lib/settings.glsl" + flat varying vec3 ambientUp; flat varying vec3 ambientLeft; flat varying vec3 ambientRight; @@ -47,9 +41,11 @@ vec3 sunVec = vec3(0.0,1.0,0.0); -#include "lib/sky_gradient.glsl" +#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); @@ -100,107 +96,101 @@ void main() { 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); +// 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); +// 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.); +// //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 +// 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); +// 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 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; +// 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); +// 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); +// maxApertureChange *= 1.0+nightVision*4.; +// rad = rad+dir*min(dist,maxApertureChange); - exposureF = rad*rad; - exposure=exposureF*EXPOSURE_MULTIPLIER; +// 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); +// 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); +// 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; + exposure = 1.0; + rodExposure = clamp(log(1.0*2.0+1.0)-0.1,0.0,2.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/deferred2.fsh b/shaders/world-1/deferred2.fsh new file mode 100644 index 0000000..f59c069 --- /dev/null +++ b/shaders/world-1/deferred2.fsh @@ -0,0 +1,30 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#include "/lib/settings.glsl" + +uniform sampler2D colortex4; +uniform sampler2D depthtex1; + +uniform float near; +uniform float far; + + +float linZ(float depth) { + return (2.0 * near) / (far + near - depth * (far - near)); +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:4 */ + vec3 oldTex = texelFetch2D(colortex4, ivec2(gl_FragCoord.xy), 0).xyz; + float newTex = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x; + + if (newTex < 1.0) + gl_FragData[0] = vec4(oldTex, linZ(newTex)*linZ(newTex)*65000.0); + else + gl_FragData[0] = vec4(oldTex, 2.0); +} diff --git a/shaders/world-1/deferred2.vsh b/shaders/world-1/deferred2.vsh new file mode 100644 index 0000000..8f06db4 --- /dev/null +++ b/shaders/world-1/deferred2.vsh @@ -0,0 +1,11 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#include "/lib/settings.glsl" + +uniform vec2 texelSize; +#include "/lib/res_params.glsl" +void main() { + gl_Position = ftransform(); + vec2 scaleRatio = max(vec2(0.25), vec2(18.+258*2,258.)*texelSize); + gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(scaleRatio+0.01,0.0,1.0)*2.0-1.0; +} diff --git a/shaders/world-1/final.fsh b/shaders/world-1/final.fsh index 2388d11..90041c9 100644 --- a/shaders/world-1/final.fsh +++ b/shaders/world-1/final.fsh @@ -1,11 +1,10 @@ #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 ] + +#include "/lib/settings.glsl" + + varying vec2 texcoord; uniform sampler2D colortex7; @@ -15,9 +14,11 @@ uniform float viewHeight; uniform float frameTimeCounter; uniform int frameCounter; uniform int isEyeInWater; -#include "lib/color_transforms.glsl" -#include "lib/color_dither.glsl" + +#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 diff --git a/shaders/world-1/final.vsh b/shaders/world-1/final.vsh index 7aeb51b..88b6076 100644 --- a/shaders/world-1/final.vsh +++ b/shaders/world-1/final.vsh @@ -1,9 +1,7 @@ #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 ] +#include "/lib/settings.glsl" varying vec2 texcoord; flat varying vec4 exposure; diff --git a/shaders/world-1/gbuffers_all_solid.vsh b/shaders/world-1/gbuffers_all_solid.vsh deleted file mode 100644 index 8cc9567..0000000 --- a/shaders/world-1/gbuffers_all_solid.vsh +++ /dev/null @@ -1,213 +0,0 @@ -#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 || mc_Entity == 100061) ? 0.6 : normalMat.a; - normalMat.a = (mc_Entity.x == 10007 || mc_Entity.x == 10008) ? 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 deleted file mode 100644 index d89e204..0000000 --- a/shaders/world-1/gbuffers_all_translucent.fsh +++ /dev/null @@ -1,624 +0,0 @@ -// #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_armor_glint.fsh b/shaders/world-1/gbuffers_armor_glint.fsh index c931e5f..d2a0cfd 100644 --- a/shaders/world-1/gbuffers_armor_glint.fsh +++ b/shaders/world-1/gbuffers_armor_glint.fsh @@ -8,7 +8,7 @@ varying vec4 normalMat; uniform sampler2D texture; - +uniform sampler2D gaux1; uniform vec4 lightCol; uniform vec3 sunVec; @@ -66,34 +66,15 @@ void main() { gl_FragData[0] = texture2D(texture, lmtexcoord.xy); + vec3 albedo = toLinear(gl_FragData[0].rgb*color.rgb); - vec3 albedo = toLinear(gl_FragData[0].rgb*color.rgb); + float exposure = texelFetch2D(gaux1,ivec2(10,37),0).r; - vec3 normal = normalMat.xyz; - vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)); + vec3 col = albedo*exp(-exposure*3.); - - 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; + gl_FragData[0].rgb = col*color.a; + gl_FragData[0].a = gl_FragData[0].a*0.1; diff --git a/shaders/world-1/gbuffers_armor_glint.vsh b/shaders/world-1/gbuffers_armor_glint.vsh index 40823aa..ab59388 100644 --- a/shaders/world-1/gbuffers_armor_glint.vsh +++ b/shaders/world-1/gbuffers_armor_glint.vsh @@ -1,6 +1,6 @@ #version 120 #extension GL_EXT_gpu_shader4 : enable -#define TAA +#include "/lib/res_params.glsl" /* !! DO NOT REMOVE !! @@ -14,7 +14,7 @@ varying vec4 color; varying vec4 normalMat; #ifdef MC_NORMAL_MAP varying vec4 tangent; -attribute vec4 at_tangent; +attribute vec4 at_tangent; #endif uniform vec2 texelSize; uniform int framemod8; @@ -26,6 +26,12 @@ uniform int framemod8; 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////////////////////////////// @@ -38,16 +44,20 @@ void main() { vec2 lmcoord = gl_MultiTexCoord1.xy/255.; lmtexcoord.zw = lmcoord*lmcoord; - gl_Position = ftransform(); - color = gl_Color; - - + 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); + 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 -} \ No newline at end of file +} diff --git a/shaders/world-1/gbuffers_basic.fsh b/shaders/world-1/gbuffers_basic.fsh index 97072f6..7bb4bf0 100644 --- a/shaders/world-1/gbuffers_basic.fsh +++ b/shaders/world-1/gbuffers_basic.fsh @@ -1,4 +1,6 @@ #version 120 +// #define ENTITIES +#define BLOCKENTITIES #define WORLD -#include "gbuffers_all_solid.fsh" \ No newline at end of file +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_basic.vsh b/shaders/world-1/gbuffers_basic.vsh index 5078151..2577f65 100644 --- a/shaders/world-1/gbuffers_basic.vsh +++ b/shaders/world-1/gbuffers_basic.vsh @@ -1,4 +1,7 @@ #version 120 +// #define ENTITIES +// #define LINE +#define BLOCKENTITIES #define WORLD -#include "gbuffers_all_solid.vsh" \ No newline at end of file +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_block.fsh b/shaders/world-1/gbuffers_block.fsh index 95943b4..34cbade 100644 --- a/shaders/world-1/gbuffers_block.fsh +++ b/shaders/world-1/gbuffers_block.fsh @@ -1,5 +1,5 @@ #version 120 -#define BLOCK_ENT #define WORLD -#include "gbuffers_all_solid.fsh" \ No newline at end of file +#define BLOCKENTITIES +#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 index 9974256..31749b9 100644 --- a/shaders/world-1/gbuffers_block.vsh +++ b/shaders/world-1/gbuffers_block.vsh @@ -1,5 +1,5 @@ #version 120 -#define BLOCK_ENT #define WORLD -#include "gbuffers_all_solid.vsh" \ No newline at end of file +#define BLOCKENTITIES +#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 deleted file mode 100644 index 563a191..0000000 --- a/shaders/world-1/gbuffers_clouds.fsh +++ /dev/null @@ -1,9 +0,0 @@ -#version 120 - -/* DRAWBUFFERS:3 */ - - - -void main() { - -} diff --git a/shaders/world-1/gbuffers_clouds.vsh b/shaders/world-1/gbuffers_clouds.vsh deleted file mode 100644 index 90c4b9e..0000000 --- a/shaders/world-1/gbuffers_clouds.vsh +++ /dev/null @@ -1,14 +0,0 @@ -#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_entities.fsh b/shaders/world-1/gbuffers_entities.fsh index 0cd3e0d..234213a 100644 --- a/shaders/world-1/gbuffers_entities.fsh +++ b/shaders/world-1/gbuffers_entities.fsh @@ -2,4 +2,5 @@ #define WORLD #define ENTITIES -#include "gbuffers_all_solid.fsh" \ No newline at end of file + +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_entities.vsh b/shaders/world-1/gbuffers_entities.vsh index f4f07a4..460f566 100644 --- a/shaders/world-1/gbuffers_entities.vsh +++ b/shaders/world-1/gbuffers_entities.vsh @@ -3,4 +3,4 @@ // #define WORLD #define ENTITIES -#include "gbuffers_all_solid.vsh" \ No newline at end of file +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand.fsh b/shaders/world-1/gbuffers_hand.fsh index 21ac244..8350290 100644 --- a/shaders/world-1/gbuffers_hand.fsh +++ b/shaders/world-1/gbuffers_hand.fsh @@ -1,4 +1,4 @@ #version 120 #define HAND -#include "gbuffers_all_solid.fsh" \ No newline at end of file +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand.vsh b/shaders/world-1/gbuffers_hand.vsh index 39504ed..a2820e6 100644 --- a/shaders/world-1/gbuffers_hand.vsh +++ b/shaders/world-1/gbuffers_hand.vsh @@ -2,4 +2,5 @@ #define WORLD #define HAND -#include "gbuffers_all_solid.vsh" \ No newline at end of file + +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand_water.fsh b/shaders/world-1/gbuffers_hand_water.fsh index 2225473..59a7bed 100644 --- a/shaders/world-1/gbuffers_hand_water.fsh +++ b/shaders/world-1/gbuffers_hand_water.fsh @@ -1,116 +1,3 @@ #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; - } - - - -} +#include "/programs/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_hand_water.vsh b/shaders/world-1/gbuffers_hand_water.vsh index 68dc1b7..afcff5d 100644 --- a/shaders/world-1/gbuffers_hand_water.vsh +++ b/shaders/world-1/gbuffers_hand_water.vsh @@ -1,56 +1,3 @@ #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 -} +#include "/programs/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_terrain.fsh b/shaders/world-1/gbuffers_terrain.fsh index 97072f6..d9afdd3 100644 --- a/shaders/world-1/gbuffers_terrain.fsh +++ b/shaders/world-1/gbuffers_terrain.fsh @@ -1,4 +1,5 @@ #version 120 #define WORLD -#include "gbuffers_all_solid.fsh" \ No newline at end of file + +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_terrain.vsh b/shaders/world-1/gbuffers_terrain.vsh index 5078151..d18fc18 100644 --- a/shaders/world-1/gbuffers_terrain.vsh +++ b/shaders/world-1/gbuffers_terrain.vsh @@ -1,4 +1,5 @@ #version 120 #define WORLD -#include "gbuffers_all_solid.vsh" \ No newline at end of file + +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured.fsh b/shaders/world-1/gbuffers_textured.fsh index 2225473..0f62590 100644 --- a/shaders/world-1/gbuffers_textured.fsh +++ b/shaders/world-1/gbuffers_textured.fsh @@ -1,116 +1,3 @@ #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; - } - - - -} +#include "/programs/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured.vsh b/shaders/world-1/gbuffers_textured.vsh index 51f3fd7..a6d1cbf 100644 --- a/shaders/world-1/gbuffers_textured.vsh +++ b/shaders/world-1/gbuffers_textured.vsh @@ -1,74 +1,3 @@ #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 -} +#include "/programs/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured_lit.fsh b/shaders/world-1/gbuffers_textured_lit.fsh index 2225473..0f62590 100644 --- a/shaders/world-1/gbuffers_textured_lit.fsh +++ b/shaders/world-1/gbuffers_textured_lit.fsh @@ -1,116 +1,3 @@ #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; - } - - - -} +#include "/programs/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_textured_lit.vsh b/shaders/world-1/gbuffers_textured_lit.vsh index 68dc1b7..c9e7eab 100644 --- a/shaders/world-1/gbuffers_textured_lit.vsh +++ b/shaders/world-1/gbuffers_textured_lit.vsh @@ -1,56 +1,5 @@ #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 -} +// #define WEATHER +#define PARTICLES +#include "/programs/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_water.fsh b/shaders/world-1/gbuffers_water.fsh index 5d6f344..59a7bed 100644 --- a/shaders/world-1/gbuffers_water.fsh +++ b/shaders/world-1/gbuffers_water.fsh @@ -1,334 +1,3 @@ #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); - -} +#include "/programs/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world-1/gbuffers_water.vsh b/shaders/world-1/gbuffers_water.vsh index ec64b46..afcff5d 100644 --- a/shaders/world-1/gbuffers_water.vsh +++ b/shaders/world-1/gbuffers_water.vsh @@ -1,89 +1,3 @@ #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 - -} +#include "/programs/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world-1/lib/ACES.glsl b/shaders/world-1/lib/ACES.glsl deleted file mode 100644 index d9d6ce7..0000000 --- a/shaders/world-1/lib/ACES.glsl +++ /dev/null @@ -1,382 +0,0 @@ -#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 deleted file mode 100644 index 81c4ffd..0000000 --- a/shaders/world-1/lib/ACESSPL.glsl +++ /dev/null @@ -1,115 +0,0 @@ -#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 deleted file mode 100644 index f8693d7..0000000 --- a/shaders/world-1/lib/ACEST.glsl +++ /dev/null @@ -1,63 +0,0 @@ - -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 deleted file mode 100644 index ef8fcfd..0000000 --- a/shaders/world-1/lib/ROBOBO_sky.glsl +++ /dev/null @@ -1,157 +0,0 @@ -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 deleted file mode 100644 index 7556167..0000000 --- a/shaders/world-1/lib/Shadow_Params.glsl +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index abd35ef..0000000 --- a/shaders/world-1/lib/clouds.glsl +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 73c4960..0000000 --- a/shaders/world-1/lib/color_dither.glsl +++ /dev/null @@ -1,46 +0,0 @@ -//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 deleted file mode 100644 index 4813ff4..0000000 --- a/shaders/world-1/lib/color_transforms.glsl +++ /dev/null @@ -1,131 +0,0 @@ -//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 deleted file mode 100644 index cb2a2ba..0000000 --- a/shaders/world-1/lib/composite3.fsh +++ /dev/null @@ -1,78 +0,0 @@ -#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/projections.glsl b/shaders/world-1/lib/projections.glsl deleted file mode 100644 index 72ab381..0000000 --- a/shaders/world-1/lib/projections.glsl +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index 559faf3..0000000 --- a/shaders/world-1/lib/sky_gradient.glsl +++ /dev/null @@ -1,84 +0,0 @@ -#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 deleted file mode 100644 index 40a8df9..0000000 --- a/shaders/world-1/lib/specular.glsl +++ /dev/null @@ -1,410 +0,0 @@ -//#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 deleted file mode 100644 index 38d3cbf..0000000 --- a/shaders/world-1/lib/stars.glsl +++ /dev/null @@ -1,48 +0,0 @@ -//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 deleted file mode 100644 index 7d58676..0000000 --- a/shaders/world-1/lib/texFiltering.glsl +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index f701920..0000000 --- a/shaders/world-1/lib/util.glsl +++ /dev/null @@ -1,196 +0,0 @@ -#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 deleted file mode 100644 index b5cc4e5..0000000 --- a/shaders/world-1/lib/volumetricClouds.glsl +++ /dev/null @@ -1,282 +0,0 @@ -#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 deleted file mode 100644 index 83212d0..0000000 --- a/shaders/world-1/lib/volumetricFog.glsl +++ /dev/null @@ -1,118 +0,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 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 deleted file mode 100644 index fccda4b..0000000 --- a/shaders/world-1/texture/composite4.fsh +++ /dev/null @@ -1,37 +0,0 @@ -#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 deleted file mode 100644 index e6e3e92..0000000 --- a/shaders/world-1/texture/composite4.vsh +++ /dev/null @@ -1,19 +0,0 @@ -#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 deleted file mode 100644 index 6236ff1..0000000 Binary files a/shaders/world-1/texture/noises.png and /dev/null differ diff --git a/shaders/world-1/texture/noises.png.mcmeta b/shaders/world-1/texture/noises.png.mcmeta deleted file mode 100644 index 33f3199..0000000 --- a/shaders/world-1/texture/noises.png.mcmeta +++ /dev/null @@ -1,7 +0,0 @@ -{ - "texture": - { - "blur": true, - "clamp": false - } -} \ No newline at end of file diff --git a/shaders/world1/block.properties b/shaders/world1/block.properties deleted file mode 100644 index 73045f4..0000000 --- a/shaders/world1/block.properties +++ /dev/null @@ -1,20 +0,0 @@ -#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/composite.fsh b/shaders/world1/composite.fsh new file mode 100644 index 0000000..ea05d63 --- /dev/null +++ b/shaders/world1/composite.fsh @@ -0,0 +1,467 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + +#include "/lib/settings.glsl" +#include "/lib/diffuse_lighting.glsl" + + +varying vec2 texcoord; + +flat varying vec3 avgAmbient; + +flat varying vec2 TAA_Offset; +flat varying float tempOffsets; + +const bool colortex5MipmapEnabled = true; +const bool colortex4MipmapEnabled = true; + +uniform sampler2D colortex0;//clouds +uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16 +uniform sampler2D colortex4;//Skybox +uniform sampler2D colortex3; +uniform sampler2D colortex7; +uniform sampler2D colortex5; +uniform sampler2D colortex2; +uniform sampler2D colortex8; +uniform sampler2D colortex10; +uniform sampler2D colortex15; +uniform sampler2D colortex6;//Skybox +uniform sampler2D depthtex1;//depth +uniform sampler2D depthtex0;//depth +uniform sampler2D noisetex;//depth + +uniform int heldBlockLightValue; +uniform int frameCounter; +uniform int isEyeInWater; +uniform mat4 shadowModelViewInverse; +uniform mat4 shadowProjectionInverse; +uniform float far; +uniform float near; +uniform float frameTimeCounter; +uniform float rainStrength; +uniform mat4 gbufferProjection; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelViewInverse; +uniform mat4 shadowModelView; +uniform mat4 shadowProjection; +uniform mat4 gbufferModelView; + +uniform mat4 gbufferPreviousModelView; +uniform mat4 gbufferPreviousProjection; +uniform vec3 previousCameraPosition; + +uniform vec2 texelSize; +uniform float viewWidth; +uniform float viewHeight; +uniform float aspectRatio; +uniform vec3 cameraPosition; +uniform vec3 sunVec; +uniform ivec2 eyeBrightnessSmooth; + +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) + +vec3 toScreenSpace(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 p3 = p * 2. - 1.; + vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} +#include "/lib/color_transforms.glsl" +#include "/lib/waterBump.glsl" +#include "/lib/sky_gradient.glsl" + + + + +float ld(float dist) { + return (2.0 * near) / (far + near - dist * (far - near)); +} + +vec2 RENDER_SCALE = vec2(1.0); + +#include "/lib/end_fog.glsl" + +#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); +} + + + +float facos(float sx){ + float x = clamp(abs( sx ),0.,1.); + return sqrt( 1. - x ) * ( -0.16882 * x + 1.56734 ); +} +vec3 decode (vec2 encn){ + vec3 n = vec3(0.0); + encn = encn * 2.0 - 1.0; + n.xy = abs(encn); + n.z = 1.0 - n.x - n.y; + n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn; + return clamp(normalize(n.xyz),-1.0,1.0); +} +vec2 decodeVec2(float a){ + const vec2 constant1 = 65535. / vec2( 256., 65536.); + const float constant2 = 256. / 255.; + return fract( a * constant1 ) * constant2 ; +} +// float linZ(float depth) { +// return (2.0 * near) / (far + near - depth * (far - near)); +// // l = (2*n)/(f+n-d(f-n)) +// // f+n-d(f-n) = 2n/l +// // -d(f-n) = ((2n/l)-f-n) +// // d = -((2n/l)-f-n)/(f-n) + +// } +// float invLinZ (float lindepth){ +// return -((2.0*near/lindepth)-far-near)/(far-near); +// } + +// vec3 toClipSpace3(vec3 viewSpacePosition) { +// return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +// } + + + + +vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort) +{ + float alpha0 = sampleNumber/nb; + float alpha = (sampleNumber+jitter)/nb; + float angle = jitter*6.28 + alpha * 4.0 * 6.28; + + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + + return vec2(cos_v, sin_v)*sqrt(alpha); +} + + + +vec3 BilateralFiltering(sampler2D tex, sampler2D depth,vec2 coord,float frDepth,float maxZ){ + vec4 sampled = vec4(texelFetch2D(tex,ivec2(coord),0).rgb,1.0); + + return vec3(sampled.x,sampled.yz/sampled.w); +} +float 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); +} +vec3 toShadowSpaceProjected(vec3 p3){ + p3 = mat3(gbufferModelViewInverse) * p3 + gbufferModelViewInverse[3].xyz; + p3 = mat3(shadowModelView) * p3 + shadowModelView[3].xyz; + p3 = diagonal3(shadowProjection) * p3 + shadowProjection[3].xyz; + + return p3; +} +vec2 tapLocation(int sampleNumber, float spinAngle,int nb, float nbRot,float r0) +{ + float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb))); + float angle = alpha * (nbRot * 6.28) + spinAngle*6.28; + + float ssR = alpha; + float sin_v, cos_v; + + sin_v = sin(angle); + cos_v = cos(angle); + + return vec2(cos_v, sin_v)*ssR; +} + + +float ssao(vec3 fragpos, float dither,vec3 normal) +{ + float mulfov = 1.0; + ivec2 pos = ivec2(gl_FragCoord.xy); + const float tan70 = tan(70.*3.14/180.); + float mulfov2 = gbufferProjection[1][1]/tan70; + + const float PI = 3.14159265; + const float samplingRadius = 0.712; + float angle_thresh = 0.05; + + + + + float rd = mulfov2*0.05; + //pre-rotate direction + float n = 0.; + + float occlusion = 0.0; + + vec2 acc = -vec2(TAA_Offset)*texelSize*0.5; + float mult = (dot(normal,normalize(fragpos))+1.0)*0.5+0.5; + + vec2 v = fract(vec2(dither,interleaved_gradientNoise()) + (frameCounter%10000) * vec2(0.75487765, 0.56984026)); + for (int j = 0; j < 7+2 ;j++) { + vec2 sp = tapLocation(j,v.x,7+2,2.,v.y); + vec2 sampleOffset = sp*rd; + ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight)); + if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth && offset.y < viewHeight ) { + vec3 t0 = toScreenSpace(vec3(offset*texelSize+acc+0.5*texelSize,texelFetch2D(depthtex1,offset,0).x)); + + vec3 vec = t0.xyz - fragpos; + float dsquared = dot(vec,vec); + if (dsquared > 1e-5){ + if (dsquared < fragpos.z*fragpos.z*0.05*0.05*mulfov2*2.*1.412){ + float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.); + occlusion += NdotV; + } + n += 1.0; + } + } + } + + + + + return clamp(1.0-occlusion/n*2.0,0.,1.0); +} +vec3 viewToWorld(vec3 viewPosition) { + vec4 pos; + pos.xyz = viewPosition; + pos.w = 0.0; + pos = gbufferModelViewInverse * pos; + return pos.xyz; +} +vec3 worldToView(vec3 worldPos) { + vec4 pos = vec4(worldPos, 0.0); + pos = gbufferModelView * pos; + return pos.xyz; +} +void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){ + inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value + int spCount = rayMarchSampleCount; + vec3 start = toShadowSpaceProjected(rayStart); + vec3 end = toShadowSpaceProjected(rayEnd); + vec3 dV = (end-start); + //limit ray length at 32 blocks for performance and reducing integration error + //you can't see above this anyway + float maxZ = min(rayLength,12.0)/(1e-8+rayLength); + dV *= maxZ; + vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ; + rayLength *= maxZ; + float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength; + estEndDepth *= maxZ; + estSunDepth *= maxZ; + vec3 absorbance = vec3(1.0); + vec3 vL = vec3(0.0); + + + float expFactor = 11.0; + vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition; + for (int i=0;i -near) ? + (-near -position.z) / dir.z : far*sqrt(3.) ; + vec3 direction = toClipSpace3(position+dir*rayLength)-clipPosition; //convert to clip space + direction.xyz = direction.xyz/max(abs(direction.x)/texelSize.x,abs(direction.y)/texelSize.y); //fixed step size + vec3 stepv = direction * 3.0 * clamp(MC_RENDER_QUALITY,1.,2.0)*vec3(RENDER_SCALE,1.0); + + vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0); + spos += stepv*dither ; + + for (int i = 0; i < int(quality); i++) { + spos += stepv; + + float sp = texture2D(depthtex1,spos.xy).x; + + if( sp < spos.z) { + float dist = abs(linZ(sp)-linZ(spos.z))/linZ(spos.z); + if (dist < 0.015 ) return i / quality; + } + } + return 1.0; +} + + +void main() { + float dirtAmount = Dirt_Amount; + vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); + vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B); + vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon; + vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14; + + float z0 = texture2D(depthtex0,texcoord).x; + float z = texture2D(depthtex1,texcoord).x; + + vec2 tempOffset=TAA_Offset; + float noise = blueNoise(); + + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z)); + vec3 fragpos_RTSHADOW = toScreenSpace(vec3(texcoord,z)); + vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; + vec3 np3 = normVec(p3); + + + vec4 trpData = texture2D(colortex7,texcoord); + bool iswater = trpData.a > 0.99; + vec4 SpecularTex = texture2D(colortex8,texcoord); + bool isEntities = texture2D(colortex10,texcoord).x > 0.0; + vec4 data = texture2D(colortex1,texcoord); // terraom + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); + vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); + + float Translucent_Programs = texture2D(colortex2,texcoord).a; // the shader for all translucent progams. + // Normal // + vec3 normal = decode(dataUnpacked0.yw) ; + + vec4 normalAndAO = texture2D(colortex15,texcoord); + vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0; + float vanilla_AO = 1.0 - exp2(-5 * pow(1-normalAndAO.a,3)) ; + + + vec3 albedo = toLinear(vec3(dataUnpacked0.xz,dataUnpacked1.x)); + + vec2 lightmap = dataUnpacked1.yz; + bool translucent = abs(dataUnpacked1.w-0.5) <0.01; + bool hand = abs(dataUnpacked1.w-0.75) <0.01; + + if (z >= 1.0) { + + gl_FragData[0].rgb = vec3(0.0); + + } else { + + p3 += gbufferModelViewInverse[3].xyz; + + // do all ambient lighting stuff + vec3 Indirect_lighting = DoAmbientLighting_End(gl_Fog.color.rgb, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.x, normal, np3) ; + // Indirect_lighting = vec3(TORCH_R,TORCH_G,TORCH_B) * curveinvert(clamp(lightmap.x,0.0,1.0),2); + + // float ambientfogshadow = GetCloudShadow2(p3+cameraPosition); + // Indirect_lighting *= ambientfogshadow; + + + vec3 LightColor = LightSourceColor(clamp(sqrt(length(p3+cameraPosition) / 150.0 - 1.0) ,0.0,1.0)); + vec3 LightPos = LightSourcePosition(p3+cameraPosition, cameraPosition); + + // float LightFalloff = max(exp2(4.0 + length(LightPos) / -50),0.0); + float LightFalloff = max(1.0-length(LightPos)/255,0.0); + LightFalloff = pow(1.0-pow(1.0-LightFalloff,0.5),2.0); + LightFalloff *= 10.0; + + // 0.5 added because lightsources are always high radius. + float NdotL = clamp( dot(normal,normalize(-LightPos)),0.0,1.0); + + float fogshadow = GetCloudShadow(p3+cameraPosition, LightPos, blueNoise()); + vec3 LightSource = (LightColor * max(LightColor - (1-fogshadow) ,0.0)) * LightFalloff * NdotL ; + + + + + + float LightFalloff2 = max(1.0-length(LightPos)/120,0.0); + LightFalloff2 = pow(1.0-pow(1.0-LightFalloff2,0.5),2.0); + LightFalloff2 *= 25; + + LightSource += (LightColor * (LightColor - 0.6)) * vec3(1.0,1.3,1.0) * LightFalloff2 * (NdotL*0.7+0.3); + + // float RT_Shadows = rayTraceShadow(worldToView(normalize(-LightPos)), fragpos_RTSHADOW, blueNoise()); + // if(!hand) LightSource *= RT_Shadows*RT_Shadows; + + + // finalize + gl_FragData[0].rgb = (Indirect_lighting + LightSource) * albedo; + + #ifdef Specular_Reflections + MaterialReflections_E(gl_FragData[0].rgb, SpecularTex.r, SpecularTex.ggg, albedo, normal, np3, fragpos, vec3(blueNoise(gl_FragCoord.xy).rg,noise), hand, LightColor * LightFalloff, normalize(-LightPos), isEntities); + #endif + + if(!hand) gl_FragData[0].rgb *= ssao(fragpos,noise,FlatNormals) * vanilla_AO; + + #ifdef LabPBR_Emissives + LabEmission(gl_FragData[0].rgb, albedo, SpecularTex.a); + #endif + + } + + ////// border Fog + if(Translucent_Programs > 0.0){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + float fogdistfade = 1.0 - clamp( exp(-pow(length(fragpos / far),2.)*5.0) ,0.0,1.0); + + gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb*0.5*NetherFog_brightness, fogdistfade) ; + } + + + ////// Water Fog + if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){ + vec3 fragpos0 = toScreenSpace(vec3(texcoord-vec2(tempOffset)*texelSize*0.5,z0)); + float Vdiff = distance(fragpos,fragpos0); + + if(isEyeInWater == 1) Vdiff = (length(fragpos)); + + float VdotU = np3.y; + float estimatedDepth = Vdiff; //assuming water plane + float estimatedSunDepth = estimatedDepth; //assuming water plane + + vec3 ambientColVol = vec3(1.0,0.25,0.5) * 0.33 ; + + waterVolumetrics(gl_FragData[0].rgb, fragpos0, fragpos, estimatedDepth , estimatedSunDepth, Vdiff, noise, totEpsilon, scatterCoef, ambientColVol); + } + +/* DRAWBUFFERS:3 */ +} diff --git a/shaders/world1/composite.vsh b/shaders/world1/composite.vsh new file mode 100644 index 0000000..6d29816 --- /dev/null +++ b/shaders/world1/composite.vsh @@ -0,0 +1,51 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable + +#include "/lib/settings.glsl" + +varying vec2 texcoord; + +flat varying vec3 avgAmbient; + +flat varying float tempOffsets; +flat varying vec2 TAA_Offset; +flat varying vec3 zMults; + +uniform sampler2D colortex4; + +uniform float far; +uniform float near; +uniform mat4 gbufferModelViewInverse; +uniform vec3 sunPosition; +uniform float rainStrength; +uniform float sunElevation; +uniform int frameCounter; + +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); + + +#include "/lib/util.glsl" + +void main() { + gl_Position = ftransform(); + texcoord = gl_MultiTexCoord0.xy; + + tempOffsets = HaltonSeq2(frameCounter%10000); + + TAA_Offset = offsets[frameCounter%8]; + + #ifndef TAA + TAA_Offset = vec2(0.0); + #endif + + + avgAmbient = texelFetch2D(colortex4,ivec2(0,37),0).rgb; + zMults = vec3((far * near)*2.0,far+near,far-near); +} diff --git a/shaders/world1/composite10.fsh b/shaders/world1/composite10.fsh index 25c81c0..298ca9a 100644 --- a/shaders/world1/composite10.fsh +++ b/shaders/world1/composite10.fsh @@ -1,45 +1,483 @@ #version 120 -//downsample 1st pass (half res) for bloom +//Vignetting, applies bloom, applies exposure and tonemaps the final image +#extension GL_EXT_gpu_shader4 : enable +#include "/lib/settings.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 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; -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// -//////////////////////////////VOID MAIN////////////////////////////// +uniform float frameTimeCounter; +uniform int frameCounter; +uniform int isEyeInWater; +uniform float near; +uniform float aspectRatio; +uniform float far; + +#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; + #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.)); -/* DRAWBUFFERS:6 */ -vec2 resScale = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.))/vec2(1920.,1080.); -vec2 quarterResTC = gl_FragCoord.xy*2.*texelSize; + vec3 bloom = texture2D(colortex3,texcoord/clampedRes*vec2(1920.,1080.)*0.5).rgb/2./7.0; - //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.); + float lightScat = clamp(BLOOM_STRENGTH * 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)*BLOOMY_FOG*0.5,0.0,1.0)*clamp(1.0-pow(cdist(texcoord.xy),15.0),0.0,1.0); + col = ( mix(col, bloom, VL_abs) + bloom*lightScat) * exposure.rgb; +/* + //Purkinje Effect + float lum = dot(col,vec3(0.15,0.3,0.55)); + float lum2 = dot(col,vec3(0.85,0.7,0.45))/2; + float rodLum = lum2*300.0; + float rodCurve = mix(1.0, rodLum/(2.5+rodLum), rodExposure/2.0*Purkinje_strength); + col = mix(lum*Purkinje_Multiplier*vec3(Purkinje_R, Purkinje_G, Purkinje_B)+0.001, col, rodCurve); +*/ + #ifndef USE_ACES_COLORSPACE_APPROXIMATION + col = LinearTosRGB(TONEMAP(col)); + #else + 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/composite10.vsh b/shaders/world1/composite10.vsh index 8d47d5c..634d9d3 100644 --- a/shaders/world1/composite10.vsh +++ b/shaders/world1/composite10.vsh @@ -1,7 +1,13 @@ #version 120 +#extension GL_EXT_gpu_shader4 : enable + +#include "/lib/settings.glsl" + +varying vec2 texcoord; +flat varying vec4 exposure; +flat varying float rodExposure; +uniform sampler2D colortex4; -uniform float viewWidth; -uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -9,9 +15,9 @@ uniform float viewHeight; //////////////////////////////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; + 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/composite12.fsh b/shaders/world1/composite12.fsh deleted file mode 100644 index dd63b74..0000000 --- a/shaders/world1/composite12.fsh +++ /dev/null @@ -1,61 +0,0 @@ -#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 deleted file mode 100644 index 56683b4..0000000 --- a/shaders/world1/composite12.vsh +++ /dev/null @@ -1,21 +0,0 @@ -#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 deleted file mode 100644 index 6bfa802..0000000 --- a/shaders/world1/composite14.fsh +++ /dev/null @@ -1,103 +0,0 @@ -#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 deleted file mode 100644 index 386f006..0000000 --- a/shaders/world1/composite14.vsh +++ /dev/null @@ -1,17 +0,0 @@ -#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 deleted file mode 100644 index 74136a6..0000000 --- a/shaders/world1/composite15.fsh +++ /dev/null @@ -1,512 +0,0 @@ -#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 deleted file mode 100644 index 5099bbb..0000000 --- a/shaders/world1/composite15.vsh +++ /dev/null @@ -1,25 +0,0 @@ -#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 index 281b2e2..581d559 100644 --- a/shaders/world1/composite2.fsh +++ b/shaders/world1/composite2.fsh @@ -1,593 +1,79 @@ #version 120 -//Render sky, volumetric clouds, direct lighting +//Volumetric fog rendering #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 1.0 // strength of bounced light areas [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 Glass_Tint // multiply the background through glass by the color of the glass for a strong tint. +#include "/lib/settings.glsl" -// #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 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 vec3 WsunVec; -flat varying vec2 TAA_Offset; flat varying float tempOffsets; +flat varying float fogAmount; +flat varying float VFAmount; +uniform sampler2D noisetex; +uniform sampler2D depthtex0; -uniform sampler2D colortex0;//clouds -uniform sampler2D colortex1;//albedo(rgb),material(alpha) RGBA16 + +uniform sampler2D colortex2; uniform sampler2D colortex3; -// uniform sampler2D colortex4;//Skybox -uniform sampler2D colortex5; -uniform sampler2D colortex6;//Skybox -uniform sampler2D colortex7; -uniform sampler2D colortex13; -uniform sampler2D colortex8; -uniform sampler2D depthtex1;//depth -uniform sampler2D depthtex0;//depth -uniform sampler2D noisetex;//depth +// uniform sampler2D colortex4; - -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 float far; +uniform int frameCounter; +uniform float rainStrength; +uniform float sunElevation; 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" +uniform float frameTimeCounter; +uniform int isEyeInWater; +uniform vec2 texelSize; - -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" +#include "/lib/color_transforms.glsl" +#include "/lib/color_dither.glsl" +#include "/lib/projections.glsl" +#include "/lib/end_fog.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); + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); } float blueNoise(){ return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); } -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; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// - 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; -} +varying vec2 texcoord; 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(); +/* DRAWBUFFERS:0 */ - 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)); + if (isEyeInWater == 0){ + vec2 tc = floor(gl_FragCoord.xy)*2.0*texelSize+0.5*texelSize; + float z = texture2D(depthtex0,tc).x; + vec3 fragpos = toScreenSpace(vec3(tc,z)); - vec3 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; + vec3 fragpos_ALT = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); - //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 + float noise = blueNoise(); + mat2x3 vl = getVolumetricRays(noise,fragpos, interleaved_gradientNoise()); - 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; + float absorbance = dot(vl[1],vec3(0.22,0.71,0.07)); - ////// ----- 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] = clamp(vec4(vl[0],absorbance),0.000001,65000.); - 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 + } else { + gl_FragData[0] = vec4(0.0); } - -// / 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 index b1cf351..91f9f96 100644 --- a/shaders/world1/composite2.vsh +++ b/shaders/world1/composite2.vsh @@ -1,68 +1,22 @@ #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////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + 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); - - + gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0; } diff --git a/shaders/world1/composite3.fsh b/shaders/world1/composite3.fsh new file mode 100644 index 0000000..66672e1 --- /dev/null +++ b/shaders/world1/composite3.fsh @@ -0,0 +1,187 @@ +#version 120 +//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog +#extension GL_EXT_gpu_shader4 : enable + +#include "/lib/settings.glsl" + + +varying vec2 texcoord; +flat varying vec3 zMults; +uniform sampler2D depthtex0; +uniform sampler2D depthtex1; +uniform sampler2D colortex13; +uniform sampler2D colortex11; +uniform sampler2D colortex7; +uniform sampler2D colortex3; +uniform sampler2D colortex2; +uniform sampler2D colortex0; +uniform sampler2D noisetex; + +uniform float frameTimeCounter; +uniform int frameCounter; +uniform float far; +uniform float near; +uniform mat4 gbufferModelViewInverse; +uniform mat4 gbufferProjectionInverse; +uniform mat4 gbufferModelView; +uniform vec2 texelSize; +uniform vec3 cameraPosition; + +uniform int isEyeInWater; +uniform float blindness; +uniform float darknessFactor; +uniform float darknessLightFactor; + + +#include "/lib/waterBump.glsl" + +float ld(float depth) { + return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near +} +#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) +#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) +vec3 toScreenSpace(vec3 p) { + vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); + vec3 p3 = p * 2. - 1.; + vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; + return fragposition.xyz / fragposition.w; +} +vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){ + vec4 vl = vec4(0.0); + float sum = 0.0; + mat3x3 weights; + ivec2 posD = ivec2(coord/2.0)*2; + ivec2 posVl = ivec2(coord/2.0); + float dz = zMults.x; + ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2; + //pos = ivec2(1,-1); + + ivec2 tcDepth = posD + ivec2(-4,-4) + pos*2; + float dsample = ld(texelFetch2D(depth,tcDepth,0).r); + float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; + vl += texelFetch2D(tex,posVl+ivec2(-2)+pos,0)*w; + sum += w; + + tcDepth = posD + ivec2(-4,0) + pos*2; + dsample = ld(texelFetch2D(depth,tcDepth,0).r); + w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; + vl += texelFetch2D(tex,posVl+ivec2(-2,0)+pos,0)*w; + sum += w; + + tcDepth = posD + ivec2(0) + pos*2; + dsample = ld(texelFetch2D(depth,tcDepth,0).r); + w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; + vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w; + sum += w; + + tcDepth = posD + ivec2(0,-4) + pos*2; + dsample = ld(texelFetch2D(depth,tcDepth,0).r); + w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; + vl += texelFetch2D(tex,posVl+ivec2(0,-2)+pos,0)*w; + sum += w; + + return vl/sum; +} + +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 luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} +void main() { + /* DRAWBUFFERS:73 */ + //3x3 bilateral upscale from half resolution + float z = texture2D(depthtex0,texcoord).x; + float z2 = texture2D(depthtex1,texcoord).x; + float frDepth = ld(z); + float glassdepth = clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15); + + vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth); + + float bloomyfogmult = 1.0; + + vec4 Translucent_Programs = texture2D(colortex2,texcoord); // the shader for all translucent progams. + + vec4 trpData = texture2D(colortex7,texcoord); + bool iswater = trpData.a > 0.99; + vec2 refractedCoord = texcoord; + + + + vec2 data = texture2D(colortex11,texcoord).xy; // translucents + vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); + + vec3 normals = mat3(gbufferModelViewInverse) * worldToView(decode(dataUnpacked0.yw) ); + + + #ifdef Refraction + refractedCoord += normals.xy * glassdepth; + + float refractedalpha = texture2D(colortex13,refractedCoord).a; + if(refractedalpha <= 0.0) refractedCoord = texcoord; // remove refracted coords on solids + #endif + + vec3 color = texture2D(colortex3,refractedCoord).rgb; + + if (Translucent_Programs.a > 0.0){ + #ifdef Glass_Tint + vec3 GlassAlbedo = texture2D(colortex13,texcoord).rgb * 5.0; + color = color*GlassAlbedo.rgb + color * clamp(pow(1.0-luma(GlassAlbedo.rgb),10.),0.0,1.0); + #endif + + color = color*(1.0-Translucent_Programs.a) + Translucent_Programs.rgb; + } + + color *= vl.a; + color += vl.rgb; + + bloomyfogmult *= vl.a*0.8+0.2; + + // underwater fog + if (isEyeInWater == 1){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + float fogfade = clamp(exp(-length(fragpos) /5. ) ,0.0,1.0); + bloomyfogmult *= fogfade*0.70+0.3 ; + } + /// lava. + if (isEyeInWater == 2){ + color.rgb = vec3(4.0,0.5,0.1); + } + /// powdered snow + if (isEyeInWater == 3){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); + bloomyfogmult = 0.0; + } + // blidnesss + if (blindness > 0.0){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); + color.rgb *= mix(1.0,clamp( exp(pow(length(fragpos)*(blindness*0.2),2) * -5),0.,1.) , blindness); + } + // darkness effect + if(darknessFactor > 0.0){ + vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z2)); + color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); + } + + gl_FragData[0].r = bloomyfogmult; + gl_FragData[1].rgb = clamp(color,6.11*1e-5,65000.0); +} diff --git a/shaders/world-1/lib/composite3.vsh b/shaders/world1/composite3.vsh similarity index 100% rename from shaders/world-1/lib/composite3.vsh rename to shaders/world1/composite3.vsh diff --git a/shaders/world1/composite4.fsh b/shaders/world1/composite4.fsh new file mode 100644 index 0000000..30ed2e9 --- /dev/null +++ b/shaders/world1/composite4.fsh @@ -0,0 +1,361 @@ +#version 120 +//Temporal Anti-Aliasing + Dynamic exposure calculations (vertex shader) +#extension GL_EXT_gpu_shader4 : enable + +#include "/lib/settings.glsl" + +const int noiseTextureResolution = 32; + + +/* +const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2) + low res VL (composite5->composite15) +const int colortex1Format = RGBA16; //terrain gbuffer (gbuffer->composite2) +const int colortex2Format = RGBA16F; //forward + transparencies (gbuffer->composite4) +const int colortex3Format = R11F_G11F_B10F; //frame buffer + bloom (deferred6->final) +const int colortex4Format = RGBA16F; //light values and skyboxes (everything) +const int colortex5Format = R11F_G11F_B10F; //TAA buffer (everything) +const int colortex6Format = R11F_G11F_B10F; //additionnal buffer for bloom (composite3->final) +const int colortex7Format = RGBA8; //Final output, transparencies id (gbuffer->composite4) +*/ +//no need to clear the buffers, saves a few fps +const bool colortex0Clear = false; +const bool colortex1Clear = false; +const bool colortex2Clear = true; +const bool colortex3Clear = false; +const bool colortex4Clear = false; +const bool colortex5Clear = false; +const bool colortex6Clear = false; +const bool colortex7Clear = false; + +varying vec2 texcoord; +flat varying float exposureA; +flat varying float tempOffsets; +uniform sampler2D colortex3; +uniform sampler2D colortex5; +uniform sampler2D colortex10; +uniform sampler2D depthtex0; + +uniform vec2 texelSize; +uniform float frameTimeCounter; +uniform int framemod8; +uniform float viewHeight; +uniform float viewWidth; +uniform vec3 previousCameraPosition; +uniform mat4 gbufferPreviousModelView; + + + + +#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.) + +#include "/lib/projections.glsl" + + +float luma(vec3 color) { + return dot(color,vec3(0.21, 0.72, 0.07)); +} +float interleaved_gradientNoise(){ + return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+tempOffsets); +} +float triangularize(float dither) +{ + float center = dither*2.0-1.0; + dither = center*inversesqrt(abs(center)); + return clamp(dither-fsign(center),0.0,1.0); +} +vec3 fp10Dither(vec3 color,float dither){ + const vec3 mantissaBits = vec3(6.,6.,5.); + vec3 exponent = floor(log2(color)); + return color + dither*exp2(-mantissaBits)*exp2(exponent); +} + + +//returns the projected coordinates of the closest point to the camera in the 3x3 neighborhood +vec3 closestToCamera3x3() +{ + vec2 du = vec2(texelSize.x, 0.0); + vec2 dv = vec2(0.0, texelSize.y); + + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthtex0, texcoord - dv - du).x); + vec3 dtc = vec3(texcoord,0.) + vec3( 0.0, -texelSize.y, texture2D(depthtex0, texcoord - dv).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthtex0, texcoord - dv + du).x); + + vec3 dml = vec3(texcoord,0.) + vec3(-texelSize.x, 0.0, texture2D(depthtex0, texcoord - du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthtex0, texcoord).x); + vec3 dmr = vec3(texcoord,0.) + vec3( texelSize.x, 0.0, texture2D(depthtex0, texcoord + du).x); + + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv - du).x); + vec3 dbc = vec3(texcoord,0.) + vec3( 0.0, texelSize.y, texture2D(depthtex0, texcoord + dv).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthtex0, texcoord + dv + du).x); + + vec3 dmin = dmc; + + dmin = dmin.z > dtc.z? dtc : dmin; + dmin = dmin.z > dtr.z? dtr : dmin; + + dmin = dmin.z > dml.z? dml : dmin; + dmin = dmin.z > dtl.z? dtl : dmin; + dmin = dmin.z > dmr.z? dmr : dmin; + + dmin = dmin.z > dbl.z? dbl : dmin; + dmin = dmin.z > dbc.z? dbc : dmin; + dmin = dmin.z > dbr.z? dbr : dmin; + + return dmin; +} + +//Modified texture interpolation from inigo quilez +vec4 smoothfilter(in sampler2D tex, in vec2 uv) +{ + vec2 textureResolution = vec2(viewWidth,viewHeight); + uv = uv*textureResolution + 0.5; + vec2 iuv = floor( uv ); + vec2 fuv = fract( uv ); + #ifndef SMOOTHESTSTEP_INTERPOLATION + uv = iuv + (fuv*fuv)*(3.0-2.0*fuv); + #endif + #ifdef SMOOTHESTSTEP_INTERPOLATION + uv = iuv + fuv*fuv*fuv*(fuv*(fuv*6.0-15.0)+10.0); + #endif + uv = (uv - 0.5)/textureResolution; + return texture2D( tex, uv); +} +//Due to low sample count we "tonemap" the inputs to preserve colors and smoother edges +vec3 weightedSample(sampler2D colorTex, vec2 texcoord){ + vec3 wsample = texture2D(colorTex,texcoord).rgb*exposureA; + return wsample/(1.0+luma(wsample)); + +} + + +//from : https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 +vec4 SampleTextureCatmullRom(sampler2D tex, vec2 uv, vec2 texSize ) +{ + // We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding + // down the sample location to get the exact center of our "starting" texel. The starting texel will be at + // location [1, 1] in the grid, where [0, 0] is the top left corner. + vec2 samplePos = uv * texSize; + vec2 texPos1 = floor(samplePos - 0.5) + 0.5; + + // Compute the fractional offset from our starting texel to our original sample location, which we'll + // feed into the Catmull-Rom spline function to get our filter weights. + vec2 f = samplePos - texPos1; + + // Compute the Catmull-Rom weights using the fractional offset that we calculated earlier. + // These equations are pre-expanded based on our knowledge of where the texels will be located, + // which lets us avoid having to evaluate a piece-wise function. + vec2 w0 = f * ( -0.5 + f * (1.0 - 0.5*f)); + vec2 w1 = 1.0 + f * f * (-2.5 + 1.5*f); + vec2 w2 = f * ( 0.5 + f * (2.0 - 1.5*f) ); + vec2 w3 = f * f * (-0.5 + 0.5 * f); + + // Work out weighting factors and sampling offsets that will let us use bilinear filtering to + // simultaneously evaluate the middle 2 samples from the 4x4 grid. + vec2 w12 = w1 + w2; + vec2 offset12 = w2 / (w1 + w2); + + // Compute the final UV coordinates we'll use for sampling the texture + vec2 texPos0 = texPos1 - vec2(1.0); + vec2 texPos3 = texPos1 + vec2(2.0); + vec2 texPos12 = texPos1 + offset12; + + texPos0 *= texelSize; + texPos3 *= texelSize; + texPos12 *= texelSize; + + vec4 result = vec4(0.0); + result += texture2D(tex, vec2(texPos0.x, texPos0.y)) * w0.x * w0.y; + result += texture2D(tex, vec2(texPos12.x, texPos0.y)) * w12.x * w0.y; + result += texture2D(tex, vec2(texPos3.x, texPos0.y)) * w3.x * w0.y; + + result += texture2D(tex, vec2(texPos0.x, texPos12.y)) * w0.x * w12.y; + result += texture2D(tex, vec2(texPos12.x, texPos12.y)) * w12.x * w12.y; + result += texture2D(tex, vec2(texPos3.x, texPos12.y)) * w3.x * w12.y; + + result += texture2D(tex, vec2(texPos0.x, texPos3.y)) * w0.x * w3.y; + result += texture2D(tex, vec2(texPos12.x, texPos3.y)) * w12.x * w3.y; + result += texture2D(tex, vec2(texPos3.x, texPos3.y)) * w3.x * w3.y; + + return result; +} +//approximation from SMAA presentation from siggraph 2016 +vec3 FastCatmulRom(sampler2D colorTex, vec2 texcoord, vec4 rtMetrics, float sharpenAmount) +{ + vec2 position = rtMetrics.zw * texcoord; + vec2 centerPosition = floor(position - 0.5) + 0.5; + vec2 f = position - centerPosition; + vec2 f2 = f * f; + vec2 f3 = f * f2; + + float c = sharpenAmount; + vec2 w0 = -c * f3 + 2.0 * c * f2 - c * f; + vec2 w1 = (2.0 - c) * f3 - (3.0 - c) * f2 + 1.0; + vec2 w2 = -(2.0 - c) * f3 + (3.0 - 2.0 * c) * f2 + c * f; + vec2 w3 = c * f3 - c * f2; + + vec2 w12 = w1 + w2; + vec2 tc12 = rtMetrics.xy * (centerPosition + w2 / w12); + vec3 centerColor = texture2D(colorTex, vec2(tc12.x, tc12.y)).rgb; + + vec2 tc0 = rtMetrics.xy * (centerPosition - 1.0); + vec2 tc3 = rtMetrics.xy * (centerPosition + 2.0); + vec4 color = vec4(texture2D(colorTex, vec2(tc12.x, tc0.y )).rgb, 1.0) * (w12.x * w0.y ) + + vec4(texture2D(colorTex, vec2(tc0.x, tc12.y)).rgb, 1.0) * (w0.x * w12.y) + + vec4(centerColor, 1.0) * (w12.x * w12.y) + + vec4(texture2D(colorTex, vec2(tc3.x, tc12.y)).rgb, 1.0) * (w3.x * w12.y) + + vec4(texture2D(colorTex, vec2(tc12.x, tc3.y )).rgb, 1.0) * (w12.x * w3.y ); + return color.rgb/color.a; + +} + +vec3 clip_aabb(vec3 q,vec3 aabb_min, vec3 aabb_max) + { + vec3 p_clip = 0.5 * (aabb_max + aabb_min); + vec3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001; + + vec3 v_clip = q - vec3(p_clip); + vec3 v_unit = v_clip.xyz / e_clip; + vec3 a_unit = abs(v_unit); + float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); + + if (ma_unit > 1.0) + return vec3(p_clip) + v_clip / ma_unit; + else + return q; + } +vec3 toClipSpace3Prev(vec3 viewSpacePosition) { + return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; +} +vec3 tonemap(vec3 col){ + return col/(1+luma(col)); +} +vec3 invTonemap(vec3 col){ + return col/(1-luma(col)); +} +vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth) +{ + vec2 du = vec2(texelSize.x*2., 0.0); + vec2 dv = vec2(0.0, texelSize.y*2.); + + vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x); + vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x); + vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x); + vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x); + vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x); + + vec3 dmin = dmc; + dmin = dmin.z > dtr.z? dtr : dmin; + dmin = dmin.z > dtl.z? dtl : dmin; + dmin = dmin.z > dbl.z? dbl : dmin; + dmin = dmin.z > dbr.z? dbr : dmin; + #ifdef TAA_UPSCALING + dmin.xy = dmin.xy/RENDER_SCALE; + #endif + return dmin; +} +const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), + vec2(-1.,3.)/8., + vec2(5.0,1.)/8., + vec2(-3,-5.)/8., + vec2(-5.,5.)/8., + vec2(-7.,-1.)/8., + vec2(3,7.)/8., + vec2(7.,-7.)/8.); + +vec3 TAA_hq(){ + + vec2 adjTC = texcoord; + + + //use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion + #ifdef CLOSEST_VELOCITY + vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0); + #endif + + #ifndef CLOSEST_VELOCITY + vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x); + #endif + + //reproject previous frame + vec3 fragposition = toScreenSpace(closestToCamera); + fragposition = mat3(gbufferModelViewInverse) * fragposition + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); + vec3 previousPosition = mat3(gbufferPreviousModelView) * fragposition + gbufferPreviousModelView[3].xyz; + previousPosition = toClipSpace3Prev(previousPosition); + vec2 velocity = previousPosition.xy - closestToCamera.xy; + previousPosition.xy = texcoord + velocity; + + //reject history if off-screen and early exit + if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) + return smoothfilter(colortex3, adjTC + offsets[framemod8]*texelSize*0.5).xyz; + + #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; + + bool isEntities = texture2D(colortex10,texcoord).x > 0.0; + // if(isEntities) test = 0.15; + // if(istranslucent) test = 0.1; + + //Blend current pixel with clamped history, apply fast tonemap beforehand to reduce flickering + // vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, min(luma(motionVector) *255,1.0),1.))); + + vec3 supersampled = invTonemap(mix(tonemap(finalcAcc),tonemap(albedoCurrent0),clamp(BLEND_FACTOR + movementRejection, test,1.))); + #endif + + + #ifdef NO_CLIP + vec3 albedoPrev = texture2D(colortex5, previousPosition.xy).xyz; + vec3 supersampled = mix(albedoPrev,albedoCurrent0,clamp(0.05,0.,1.)); + #endif + + //De-tonemap + return supersampled; +} + +void main() { + +/* DRAWBUFFERS:5 */ + gl_FragData[0].a = 1.0; + + #ifdef TAA + vec3 color = TAA_hq(); + gl_FragData[0].rgb = clamp(fp10Dither(color,triangularize(interleaved_gradientNoise())),6.11*1e-5,65000.0); + #endif + + #ifndef TAA + vec3 color = clamp(fp10Dither(texture2D(colortex3,texcoord).rgb,triangularize(interleaved_gradientNoise())),0.,65000.); + gl_FragData[0].rgb = color; + #endif + + + + + +} diff --git a/shaders/world1/composite4.vsh b/shaders/world1/composite4.vsh new file mode 100644 index 0000000..372c136 --- /dev/null +++ b/shaders/world1/composite4.vsh @@ -0,0 +1,20 @@ +#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/composite5.fsh b/shaders/world1/composite5.fsh index 48345fb..a4b6244 100644 --- a/shaders/world1/composite5.fsh +++ b/shaders/world1/composite5.fsh @@ -1,259 +1,45 @@ #version 120 -//Volumetric fog rendering -#extension GL_EXT_gpu_shader4 : enable +//downsample 1st pass (half res) for bloom -#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 sampler2D colortex5; 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 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/composite5.vsh b/shaders/world1/composite5.vsh index 1de7145..386f006 100644 --- a/shaders/world1/composite5.vsh +++ b/shaders/world1/composite5.vsh @@ -1,32 +1,7 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable -#define BASE_FOG_AMOUNT 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0 10.0 20.0 30.0 50.0 100.0 150.0 200.0] Base fog amount amount (does not change the "cloudy" fog) -#define CLOUDY_FOG_AMOUNT 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] -#define FOG_TOD_MULTIPLIER 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] //Influence of time of day on fog amount -#define FOG_RAIN_MULTIPLIER 1.0 //[0.0 0.2 0.4 0.6 0.8 1.0 1.25 1.5 1.75 2.0 3.0 4.0 5.0] //Influence of rain on fog amount - -flat varying vec4 lightCol; -flat varying vec3 ambientUp; -flat varying vec3 ambientLeft; -flat varying vec3 ambientRight; -flat varying vec3 ambientB; -flat varying vec3 ambientF; -flat varying vec3 ambientDown; -flat varying float tempOffsets; -flat varying float fogAmount; -flat varying float VFAmount; - -uniform sampler2D colortex4; -uniform float sunElevation; -uniform float rainStrength; -uniform int isEyeInWater; -uniform int frameCounter; -uniform int worldTime; -#include "/lib/util.glsl" -float luma(vec3 color) { - return dot(color,vec3(0.21, 0.72, 0.07)); -} +uniform float viewWidth; +uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -34,16 +9,9 @@ float luma(vec3 color) { //////////////////////////////VOID MAIN////////////////////////////// void main() { - tempOffsets = HaltonSeq2(frameCounter%10000); + //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(); - gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0; - vec3 avgAmbient = texelFetch2D(colortex4,ivec2(11,37),0).rgb; - ambientUp = texelFetch2D(colortex4,ivec2(0,37),0).rgb; - ambientDown = texelFetch2D(colortex4,ivec2(1,37),0).rgb; - ambientLeft = texelFetch2D(colortex4,ivec2(2,37),0).rgb; - ambientRight = texelFetch2D(colortex4,ivec2(3,37),0).rgb; - ambientB = texelFetch2D(colortex4,ivec2(4,37),0).rgb; - ambientF = texelFetch2D(colortex4,ivec2(5,37),0).rgb; - - + //*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/composite6.fsh b/shaders/world1/composite6.fsh index cf835db..25c81c0 100644 --- a/shaders/world1/composite6.fsh +++ b/shaders/world1/composite6.fsh @@ -1,210 +1,45 @@ #version 120 -//Horizontal bilateral blur for volumetric fog + Forward rendered objects + Draw volumetric fog -#extension GL_EXT_gpu_shader4 : enable +//downsample 1st pass (half res) for bloom -#define Cave_fog // cave fog.... -#define CaveFogFallOff 1.3 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ] - -#define CaveFogColor_R 0.1 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0] -#define CaveFogColor_G 0.2 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0] -#define CaveFogColor_B 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0] - -// #define display_LUT // aaaaaaaaaaaaaaaaaaaaaaa - -varying vec2 texcoord; -flat varying vec3 zMults; -uniform sampler2D depthtex0; -uniform sampler2D depthtex1; -uniform sampler2D colortex7; uniform sampler2D colortex3; -// uniform sampler2D colortex4; -uniform sampler2D colortex2; -uniform sampler2D colortex0; -uniform sampler2D noisetex; - -uniform float frameTimeCounter; -uniform int frameCounter; -uniform float far; -uniform float near; -uniform mat4 gbufferModelViewInverse; -uniform mat4 gbufferProjectionInverse; uniform vec2 texelSize; -uniform vec3 cameraPosition; +uniform float viewWidth; +uniform float viewHeight; +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// -uniform mat4 gbufferModelView; - -uniform float isWastes; -uniform float isWarpedForest; -uniform float isCrimsonForest; -uniform float isSoulValley; -uniform float isBasaltDelta; - -uniform int isEyeInWater; -uniform ivec2 eyeBrightnessSmooth; -uniform float rainStrength; -uniform float blindness; -uniform float darknessFactor; -uniform float darknessLightFactor; -uniform float nightVision; - - - -#include "lib/waterBump.glsl" -#include "lib/waterOptions.glsl" -#include "lib/volumetricClouds.glsl" -float ld(float depth) { - return 1.0 / (zMults.y - depth * zMults.z); // (-depth * (far - near)) = (2.0 * near)/ld - far - near -} -#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z) -#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz) -vec3 toScreenSpace(vec3 p) { - vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw); - vec3 p3 = p * 2. - 1.; - vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3]; - return fragposition.xyz / fragposition.w; -} -vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){ - vec4 vl = vec4(0.0); - float sum = 0.0; - mat3x3 weights; - ivec2 posD = ivec2(coord/2.0)*2; - ivec2 posVl = ivec2(coord/2.0); - float dz = zMults.x; - ivec2 pos = (ivec2(gl_FragCoord.xy+frameCounter) % 2 )*2; - //pos = ivec2(1,-1); - - ivec2 tcDepth = posD + ivec2(-4,-4) + pos*2; - float dsample = ld(texelFetch2D(depth,tcDepth,0).r); - float w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; - vl += texelFetch2D(tex,posVl+ivec2(-2)+pos,0)*w; - sum += w; - - tcDepth = posD + ivec2(-4,0) + pos*2; - dsample = ld(texelFetch2D(depth,tcDepth,0).r); - w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; - vl += texelFetch2D(tex,posVl+ivec2(-2,0)+pos,0)*w; - sum += w; - - tcDepth = posD + ivec2(0) + pos*2; - dsample = ld(texelFetch2D(depth,tcDepth,0).r); - w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; - vl += texelFetch2D(tex,posVl+ivec2(0)+pos,0)*w; - sum += w; - - tcDepth = posD + ivec2(0,-4) + pos*2; - dsample = ld(texelFetch2D(depth,tcDepth,0).r); - w = abs(dsample-frDepth) < dz ? 1.0 : 1e-5; - vl += texelFetch2D(tex,posVl+ivec2(0,-2)+pos,0)*w; - sum += w; - - return vl/sum; -} -float luma(vec3 color) { - return dot(color,vec3(0.21, 0.72, 0.07)); -} -vec3 normVec (vec3 vec){ - return vec*inversesqrt(dot(vec,vec)); -} void main() { - /* DRAWBUFFERS:73 */ - //3x3 bilateral upscale from half resolution - float z = texture2D(depthtex0,texcoord).x; - float z2 = texture2D(depthtex1,texcoord).x; - float frDepth = ld(z); - vec4 vl = BilateralUpscale(colortex0,depthtex0,gl_FragCoord.xy,frDepth); + +/* 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.); - vec4 transparencies = texture2D(colortex2,texcoord); - vec4 trpData = texture2D(colortex7,texcoord); - bool iswater = trpData.a > 0.99; - vec2 refractedCoord = texcoord; - - vec3 fragpos = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z)); - vec3 fragpos2 = toScreenSpace(vec3(texcoord-vec2(0.0)*texelSize*0.5,z2)); - // vec3 np3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition; - - vec3 p3 = mat3(gbufferModelViewInverse) * fragpos; - vec3 np3 = normVec(p3); - - - if (iswater){ - float norm = getWaterHeightmap(np3.xz*1.71, 4.0, 0.25, 1.0); - float displ = norm/(length(fragpos)/far)/35.; - refractedCoord += displ; - - if (texture2D(colortex7,refractedCoord).a < 0.99) - refractedCoord = texcoord; - - } - - - vec3 color = texture2D(colortex3,refractedCoord).rgb; - if (frDepth > 2.5/far || transparencies.a < 0.99) // Discount fix for transparencies through hand - color = color*(1.0-transparencies.a)+transparencies.rgb*10.; - - float dirtAmount = Dirt_Amount; - vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B); - vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B); - vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon; - - color *= vl.a; - - - // vec3 fogColor = clamp(gl_Fog.color.rgb*pow(luma(gl_Fog.color.rgb),-0.75)*0.65,0.0,1.0)*0.05; - - /// lightnign flashes fog - // if (isEyeInWater == 0){ - - // vec3 lightSource = normalize(WsunVec); - // vec3 viewspace_sunvec = mat3(gbufferModelView) * lightSource; - // float SdotV = dot(normalize(viewspace_sunvec), normalize(fragpos)); - // float lightning_shine = clamp(phaseg(SdotV, 0.35) ,0,1); - - // vec3 flashingfogCol = SunCol * 0.25; - // float flashingfogdist = clamp(pow(length(fragpos)/far,5.), 0.0, 1.0) ; - // color.rgb += flashingfogCol * lightning_shine * flashingfogdist; - // // vl.a *= 1.0 - sqrt(flashingfogdist); - // } - - - - - // underwater fog - if (isEyeInWater == 1){ - // color.rgb *= exp(-length(fragpos)/2*totEpsilon); - // vl.a *= (dot(exp(-length(fragpos)/1.2*totEpsilon),vec3(0.2,0.7,0.1)))*0.5+0.5; - - float fogfade = clamp(exp(-length(fragpos) /12 ) ,0.0,1.0); - float fogcolfade = clamp(exp(np3.y*1.5 - 1.5),0.0,1.0); - color.rgb *= fogfade; - color.rgb = color.rgb * (1.0 + vec3(0.0,0.1,0.2) * 12 * (1.0 - fogfade)) + (vec3(0.0,0.1,0.2) * 0.5 * (1.0 - fogfade))*fogcolfade; - - vl.a *= fogfade*0.75 +0.25; - } - /// lava. - if (isEyeInWater == 2){ - color.rgb = vec3(4.0,0.5,0.1); - } - /// powdered snow - if (isEyeInWater == 3){ - color.rgb = mix(color.rgb,vec3(10,15,20),clamp(length(fragpos)*0.5,0.,1.)); - vl.a = 0.0; - } - // blidnesss - color.rgb *= mix(1.0, clamp(1.5-pow(length(fragpos2)*(blindness*0.2),2.0),0.0,1.0), blindness); - // darkness effect - color.rgb *= mix(1.0, (1.0-darknessLightFactor*2.0) * clamp(1.0-pow(length(fragpos2)*(darknessFactor*0.07),2.0),0.0,1.0), darknessFactor); - - - // float BiomeParams = isWastes + isWarpedForest + isCrimsonForest + isSoulValley + isBasaltDelta ; - - color += vl.rgb; - gl_FragData[0].r = vl.a; - gl_FragData[1].rgb = clamp(color.rgb,0.0,68000.0); - gl_FragData[1].rgb = clamp(color,6.11*1e-5,65000.0); - - #ifdef display_LUT - gl_FragData[1].rgb = texture2D(colortex4,texcoord*0.45).rgb * 0.000035; - #endif } diff --git a/shaders/world1/composite6.vsh b/shaders/world1/composite6.vsh index 05cecb7..8d47d5c 100644 --- a/shaders/world1/composite6.vsh +++ b/shaders/world1/composite6.vsh @@ -1,10 +1,7 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable -varying vec2 texcoord; -flat varying vec3 zMults; -uniform float far; -uniform float near; +uniform float viewWidth; +uniform float viewHeight; //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN////////////////////////////// @@ -12,8 +9,9 @@ uniform float near; //////////////////////////////VOID MAIN////////////////////////////// void main() { - zMults = vec3(1.0/(far * near),far+near,far-near); + //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(); - texcoord = gl_MultiTexCoord0.xy; - + //*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/composite7.fsh similarity index 100% rename from shaders/world1/composite11.fsh rename to shaders/world1/composite7.fsh diff --git a/shaders/world1/composite11.vsh b/shaders/world1/composite7.vsh similarity index 100% rename from shaders/world1/composite11.vsh rename to shaders/world1/composite7.vsh diff --git a/shaders/world1/composite8.fsh b/shaders/world1/composite8.fsh index dd85629..dd63b74 100644 --- a/shaders/world1/composite8.fsh +++ b/shaders/world1/composite8.fsh @@ -1,320 +1,61 @@ #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 +//6 Vertical gaussian blurs and vertical downsampling -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 sampler2D colortex6; uniform vec2 texelSize; -uniform float frameTimeCounter; -uniform float viewHeight; +varying vec2 texcoord; 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; +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); } -vec3 toClipSpace3Prev(vec3 viewSpacePosition) { - return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5; + return tot.rgb/max(1.0,tot.a); } -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////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// void main() { +/* DRAWBUFFERS:6 */ +vec2 texcoord = (gl_FragCoord.xy*vec2(2.0,4.0))*texelSize; -/* 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 +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/composite8.vsh b/shaders/world1/composite8.vsh index 24ef8ce..56683b4 100644 --- a/shaders/world1/composite8.vsh +++ b/shaders/world1/composite8.vsh @@ -1,17 +1,21 @@ #version 120 -#extension GL_EXT_gpu_shader4 : enable - +uniform float viewWidth; +uniform float viewHeight; varying vec2 texcoord; -flat varying float exposureA; -flat varying float tempOffsets; -uniform sampler2D colortex4; -uniform int frameCounter; -#include "/lib/util.glsl" -void main() { +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// - tempOffsets = HaltonSeq2(frameCounter%10000); +void main() { + vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.0)); gl_Position = ftransform(); - texcoord = gl_MultiTexCoord0.xy; - exposureA = texelFetch2D(colortex4,ivec2(10,37),0).r; + //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/composite9.fsh b/shaders/world1/composite9.fsh index 517bfe5..6bfa802 100644 --- a/shaders/world1/composite9.fsh +++ b/shaders/world1/composite9.fsh @@ -1,11 +1,78 @@ #version 120 -//downsample 1st pass (half res) for bloom +//Merge and upsample the blurs into a 1/4 res bloom buffer + +uniform sampler2D colortex3; +uniform sampler2D colortex6; -uniform sampler2D colortex5; -uniform sampler2D colortex8; 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////////////////////////////// @@ -13,41 +80,24 @@ uniform float viewHeight; //////////////////////////////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; +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 -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; +bloom += texture2D_bicubic(colortex6,texcoord/4.).rgb; //1/8 res - //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; +bloom += texture2D_bicubic(colortex6,texcoord/8.+vec2(0.25*resScale.x+2.5*texelSize.x,.0)).rgb; //1/16 res - //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; +bloom += texture2D_bicubic(colortex6,texcoord/16.+vec2(0.375*resScale.x+4.5*texelSize.x,.0)).rgb; //1/32 res - //0.125 - gl_FragData[0] += texture2D(colortex5,quarterResTC)*0.125; +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 - 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); +//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/deferred.fsh b/shaders/world1/deferred.fsh index 34b9358..abb060a 100644 --- a/shaders/world1/deferred.fsh +++ b/shaders/world1/deferred.fsh @@ -2,14 +2,7 @@ #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] +#include "/lib/settings.glsl" flat varying vec3 ambientUp; @@ -53,8 +46,12 @@ 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; @@ -73,59 +70,29 @@ float blueNoise(){ vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.); const float[17] Slightmap = float[17](14.0,17.,19.0,22.0,24.0,28.0,31.0,40.0,60.0,79.0,93.0,110.0,132.0,160.0,197.0,249.0,249.0); +#include "/lib/end_fog.glsl" + void main() { /* DRAWBUFFERS:4 */ + gl_FragData[0] = vec4(0.0); -//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; -} +//Fog for reflections +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); -//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); + mat2x3 vL = getVolumetricRays(fract(frameCounter/1.6180339887),mat3(gbufferModelView)*viewVector*1024.,fract(frameCounter/2.6180339887)); + float absorbance = dot(vL[1],vec3(0.22,0.71,0.07)); -//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); + + gl_FragData[0] = vec4(vL[0].rgb * (1.0-absorbance),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.); +gl_FragData[0].rgb = clamp(mix(temp,curr,0.07),0.0,65000.); //Exposure values if (gl_FragCoord.x > 10. && gl_FragCoord.x < 11. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 ) diff --git a/shaders/world1/deferred.vsh b/shaders/world1/deferred.vsh index 2ff914b..4fa6840 100644 --- a/shaders/world1/deferred.vsh +++ b/shaders/world1/deferred.vsh @@ -1,14 +1,8 @@ #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 + +#include "/lib/settings.glsl" + flat varying vec3 ambientUp; flat varying vec3 ambientLeft; flat varying vec3 ambientRight; @@ -43,12 +37,15 @@ uniform float frameTime; uniform float eyeAltitude; uniform int frameCounter; uniform int worldTime; -vec3 sunVec = -normalize(vec3(0.8,0.8,0.2)); +vec3 sunVec = vec3(0.0,1.0,0.0); -#include "lib/sky_gradient.glsl" + +#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); @@ -70,6 +67,10 @@ vec3 cosineHemisphereSample(vec2 Xi) 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) { @@ -95,107 +96,101 @@ void main() { 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); +// 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); +// 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.); +// //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 +// 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); +// 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 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; +// 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); +// 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); +// maxApertureChange *= 1.0+nightVision*4.; +// rad = rad+dir*min(dist,maxApertureChange); - exposureF = rad*rad; - exposure=exposureF*EXPOSURE_MULTIPLIER; +// 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); +// 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); +// 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; + exposure = 1.0; + rodExposure = clamp(log(1.0*2.0+1.0)-0.1,0.0,2.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 deleted file mode 100644 index 24db38d..0000000 --- a/shaders/world1/deferred1.fsh +++ /dev/null @@ -1,87 +0,0 @@ -#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 deleted file mode 100644 index 1afd63f..0000000 --- a/shaders/world1/deferred1.vsh +++ /dev/null @@ -1,21 +0,0 @@ -#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/deferred2.fsh b/shaders/world1/deferred2.fsh new file mode 100644 index 0000000..f59c069 --- /dev/null +++ b/shaders/world1/deferred2.fsh @@ -0,0 +1,30 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#include "/lib/settings.glsl" + +uniform sampler2D colortex4; +uniform sampler2D depthtex1; + +uniform float near; +uniform float far; + + +float linZ(float depth) { + return (2.0 * near) / (far + near - depth * (far - near)); +} +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// +//////////////////////////////VOID MAIN////////////////////////////// + +void main() { +/* DRAWBUFFERS:4 */ + vec3 oldTex = texelFetch2D(colortex4, ivec2(gl_FragCoord.xy), 0).xyz; + float newTex = texelFetch2D(depthtex1, ivec2(gl_FragCoord.xy*4), 0).x; + + if (newTex < 1.0) + gl_FragData[0] = vec4(oldTex, linZ(newTex)*linZ(newTex)*65000.0); + else + gl_FragData[0] = vec4(oldTex, 2.0); +} diff --git a/shaders/world1/deferred2.vsh b/shaders/world1/deferred2.vsh new file mode 100644 index 0000000..8f06db4 --- /dev/null +++ b/shaders/world1/deferred2.vsh @@ -0,0 +1,11 @@ +#version 120 +#extension GL_EXT_gpu_shader4 : enable +#include "/lib/settings.glsl" + +uniform vec2 texelSize; +#include "/lib/res_params.glsl" +void main() { + gl_Position = ftransform(); + vec2 scaleRatio = max(vec2(0.25), vec2(18.+258*2,258.)*texelSize); + gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(scaleRatio+0.01,0.0,1.0)*2.0-1.0; +} diff --git a/shaders/world1/final.fsh b/shaders/world1/final.fsh index 2388d11..90041c9 100644 --- a/shaders/world1/final.fsh +++ b/shaders/world1/final.fsh @@ -1,11 +1,10 @@ #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 ] + +#include "/lib/settings.glsl" + + varying vec2 texcoord; uniform sampler2D colortex7; @@ -15,9 +14,11 @@ uniform float viewHeight; uniform float frameTimeCounter; uniform int frameCounter; uniform int isEyeInWater; -#include "lib/color_transforms.glsl" -#include "lib/color_dither.glsl" + +#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 diff --git a/shaders/world1/final.vsh b/shaders/world1/final.vsh index 7aeb51b..88b6076 100644 --- a/shaders/world1/final.vsh +++ b/shaders/world1/final.vsh @@ -1,9 +1,7 @@ #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 ] +#include "/lib/settings.glsl" varying vec2 texcoord; flat varying vec4 exposure; diff --git a/shaders/world1/gbuffers_all_solid.fsh b/shaders/world1/gbuffers_all_solid.fsh deleted file mode 100644 index 76e3e6c..0000000 --- a/shaders/world1/gbuffers_all_solid.fsh +++ /dev/null @@ -1,411 +0,0 @@ -#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 deleted file mode 100644 index 179d57f..0000000 --- a/shaders/world1/gbuffers_all_solid.vsh +++ /dev/null @@ -1,213 +0,0 @@ -#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 || mc_Entity.x == 100061) ? 0.6 : normalMat.a; - normalMat.a = (mc_Entity.x == 10007 || mc_Entity.x == 10008) ? 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 deleted file mode 100644 index d89e204..0000000 --- a/shaders/world1/gbuffers_all_translucent.fsh +++ /dev/null @@ -1,624 +0,0 @@ -// #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 deleted file mode 100644 index 13986e0..0000000 --- a/shaders/world1/gbuffers_all_translucent.vsh +++ /dev/null @@ -1,112 +0,0 @@ -// #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 index c931e5f..d2a0cfd 100644 --- a/shaders/world1/gbuffers_armor_glint.fsh +++ b/shaders/world1/gbuffers_armor_glint.fsh @@ -8,7 +8,7 @@ varying vec4 normalMat; uniform sampler2D texture; - +uniform sampler2D gaux1; uniform vec4 lightCol; uniform vec3 sunVec; @@ -66,34 +66,15 @@ void main() { gl_FragData[0] = texture2D(texture, lmtexcoord.xy); + vec3 albedo = toLinear(gl_FragData[0].rgb*color.rgb); - vec3 albedo = toLinear(gl_FragData[0].rgb*color.rgb); + float exposure = texelFetch2D(gaux1,ivec2(10,37),0).r; - vec3 normal = normalMat.xyz; - vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize,1.0)); + vec3 col = albedo*exp(-exposure*3.); - - 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; + gl_FragData[0].rgb = col*color.a; + gl_FragData[0].a = gl_FragData[0].a*0.1; diff --git a/shaders/world1/gbuffers_armor_glint.vsh b/shaders/world1/gbuffers_armor_glint.vsh index 40823aa..ab59388 100644 --- a/shaders/world1/gbuffers_armor_glint.vsh +++ b/shaders/world1/gbuffers_armor_glint.vsh @@ -1,6 +1,6 @@ #version 120 #extension GL_EXT_gpu_shader4 : enable -#define TAA +#include "/lib/res_params.glsl" /* !! DO NOT REMOVE !! @@ -14,7 +14,7 @@ varying vec4 color; varying vec4 normalMat; #ifdef MC_NORMAL_MAP varying vec4 tangent; -attribute vec4 at_tangent; +attribute vec4 at_tangent; #endif uniform vec2 texelSize; uniform int framemod8; @@ -26,6 +26,12 @@ uniform int framemod8; 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////////////////////////////// @@ -38,16 +44,20 @@ void main() { vec2 lmcoord = gl_MultiTexCoord1.xy/255.; lmtexcoord.zw = lmcoord*lmcoord; - gl_Position = ftransform(); - color = gl_Color; - - + 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); + 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 -} \ No newline at end of file +} diff --git a/shaders/world1/gbuffers_basic.fsh b/shaders/world1/gbuffers_basic.fsh index 97072f6..7bb4bf0 100644 --- a/shaders/world1/gbuffers_basic.fsh +++ b/shaders/world1/gbuffers_basic.fsh @@ -1,4 +1,6 @@ #version 120 +// #define ENTITIES +#define BLOCKENTITIES #define WORLD -#include "gbuffers_all_solid.fsh" \ No newline at end of file +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_basic.vsh b/shaders/world1/gbuffers_basic.vsh index 5078151..2577f65 100644 --- a/shaders/world1/gbuffers_basic.vsh +++ b/shaders/world1/gbuffers_basic.vsh @@ -1,4 +1,7 @@ #version 120 +// #define ENTITIES +// #define LINE +#define BLOCKENTITIES #define WORLD -#include "gbuffers_all_solid.vsh" \ No newline at end of file +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_block.fsh b/shaders/world1/gbuffers_block.fsh index 95943b4..34cbade 100644 --- a/shaders/world1/gbuffers_block.fsh +++ b/shaders/world1/gbuffers_block.fsh @@ -1,5 +1,5 @@ #version 120 -#define BLOCK_ENT #define WORLD -#include "gbuffers_all_solid.fsh" \ No newline at end of file +#define BLOCKENTITIES +#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 index 9974256..31749b9 100644 --- a/shaders/world1/gbuffers_block.vsh +++ b/shaders/world1/gbuffers_block.vsh @@ -1,5 +1,5 @@ #version 120 -#define BLOCK_ENT #define WORLD -#include "gbuffers_all_solid.vsh" \ No newline at end of file +#define BLOCKENTITIES +#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 deleted file mode 100644 index 563a191..0000000 --- a/shaders/world1/gbuffers_clouds.fsh +++ /dev/null @@ -1,9 +0,0 @@ -#version 120 - -/* DRAWBUFFERS:3 */ - - - -void main() { - -} diff --git a/shaders/world1/gbuffers_clouds.vsh b/shaders/world1/gbuffers_clouds.vsh deleted file mode 100644 index 90c4b9e..0000000 --- a/shaders/world1/gbuffers_clouds.vsh +++ /dev/null @@ -1,14 +0,0 @@ -#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_entities.fsh b/shaders/world1/gbuffers_entities.fsh index 0cd3e0d..234213a 100644 --- a/shaders/world1/gbuffers_entities.fsh +++ b/shaders/world1/gbuffers_entities.fsh @@ -2,4 +2,5 @@ #define WORLD #define ENTITIES -#include "gbuffers_all_solid.fsh" \ No newline at end of file + +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_entities.vsh b/shaders/world1/gbuffers_entities.vsh index f4f07a4..460f566 100644 --- a/shaders/world1/gbuffers_entities.vsh +++ b/shaders/world1/gbuffers_entities.vsh @@ -3,4 +3,4 @@ // #define WORLD #define ENTITIES -#include "gbuffers_all_solid.vsh" \ No newline at end of file +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand.fsh b/shaders/world1/gbuffers_hand.fsh index 21ac244..8350290 100644 --- a/shaders/world1/gbuffers_hand.fsh +++ b/shaders/world1/gbuffers_hand.fsh @@ -1,4 +1,4 @@ #version 120 #define HAND -#include "gbuffers_all_solid.fsh" \ No newline at end of file +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand.vsh b/shaders/world1/gbuffers_hand.vsh index 39504ed..a2820e6 100644 --- a/shaders/world1/gbuffers_hand.vsh +++ b/shaders/world1/gbuffers_hand.vsh @@ -2,4 +2,5 @@ #define WORLD #define HAND -#include "gbuffers_all_solid.vsh" \ No newline at end of file + +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand_water.fsh b/shaders/world1/gbuffers_hand_water.fsh index 2225473..59a7bed 100644 --- a/shaders/world1/gbuffers_hand_water.fsh +++ b/shaders/world1/gbuffers_hand_water.fsh @@ -1,116 +1,3 @@ #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; - } - - - -} +#include "/programs/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_hand_water.vsh b/shaders/world1/gbuffers_hand_water.vsh index 68dc1b7..afcff5d 100644 --- a/shaders/world1/gbuffers_hand_water.vsh +++ b/shaders/world1/gbuffers_hand_water.vsh @@ -1,56 +1,3 @@ #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 -} +#include "/programs/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_terrain.fsh b/shaders/world1/gbuffers_terrain.fsh index 97072f6..d9afdd3 100644 --- a/shaders/world1/gbuffers_terrain.fsh +++ b/shaders/world1/gbuffers_terrain.fsh @@ -1,4 +1,5 @@ #version 120 #define WORLD -#include "gbuffers_all_solid.fsh" \ No newline at end of file + +#include "/programs/all_solid.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_terrain.vsh b/shaders/world1/gbuffers_terrain.vsh index 5078151..d18fc18 100644 --- a/shaders/world1/gbuffers_terrain.vsh +++ b/shaders/world1/gbuffers_terrain.vsh @@ -1,4 +1,5 @@ #version 120 #define WORLD -#include "gbuffers_all_solid.vsh" \ No newline at end of file + +#include "/programs/all_solid.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured.fsh b/shaders/world1/gbuffers_textured.fsh index 2225473..0f62590 100644 --- a/shaders/world1/gbuffers_textured.fsh +++ b/shaders/world1/gbuffers_textured.fsh @@ -1,116 +1,3 @@ #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; - } - - - -} +#include "/programs/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured.vsh b/shaders/world1/gbuffers_textured.vsh index 51f3fd7..a6d1cbf 100644 --- a/shaders/world1/gbuffers_textured.vsh +++ b/shaders/world1/gbuffers_textured.vsh @@ -1,74 +1,3 @@ #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 -} +#include "/programs/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured_lit.fsh b/shaders/world1/gbuffers_textured_lit.fsh index 2225473..0f62590 100644 --- a/shaders/world1/gbuffers_textured_lit.fsh +++ b/shaders/world1/gbuffers_textured_lit.fsh @@ -1,116 +1,3 @@ #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; - } - - - -} +#include "/programs/all_particles.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_textured_lit.vsh b/shaders/world1/gbuffers_textured_lit.vsh index 68dc1b7..c9e7eab 100644 --- a/shaders/world1/gbuffers_textured_lit.vsh +++ b/shaders/world1/gbuffers_textured_lit.vsh @@ -1,56 +1,5 @@ #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 -} +// #define WEATHER +#define PARTICLES +#include "/programs/all_particles.vsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_water.fsh b/shaders/world1/gbuffers_water.fsh index 5d6f344..59a7bed 100644 --- a/shaders/world1/gbuffers_water.fsh +++ b/shaders/world1/gbuffers_water.fsh @@ -1,334 +1,3 @@ #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); - -} +#include "/programs/all_translucent.fsh" \ No newline at end of file diff --git a/shaders/world1/gbuffers_water.vsh b/shaders/world1/gbuffers_water.vsh index ec64b46..afcff5d 100644 --- a/shaders/world1/gbuffers_water.vsh +++ b/shaders/world1/gbuffers_water.vsh @@ -1,89 +1,3 @@ #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 - -} +#include "/programs/all_translucent.vsh" \ No newline at end of file diff --git a/shaders/world1/lib/ACES.glsl b/shaders/world1/lib/ACES.glsl deleted file mode 100644 index d9d6ce7..0000000 --- a/shaders/world1/lib/ACES.glsl +++ /dev/null @@ -1,382 +0,0 @@ -#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 deleted file mode 100644 index 81c4ffd..0000000 --- a/shaders/world1/lib/ACESSPL.glsl +++ /dev/null @@ -1,115 +0,0 @@ -#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 deleted file mode 100644 index f8693d7..0000000 --- a/shaders/world1/lib/ACEST.glsl +++ /dev/null @@ -1,63 +0,0 @@ - -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 deleted file mode 100644 index ef8fcfd..0000000 --- a/shaders/world1/lib/ROBOBO_sky.glsl +++ /dev/null @@ -1,157 +0,0 @@ -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 deleted file mode 100644 index 7556167..0000000 --- a/shaders/world1/lib/Shadow_Params.glsl +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index abd35ef..0000000 --- a/shaders/world1/lib/clouds.glsl +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 73c4960..0000000 --- a/shaders/world1/lib/color_dither.glsl +++ /dev/null @@ -1,46 +0,0 @@ -//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 deleted file mode 100644 index 4813ff4..0000000 --- a/shaders/world1/lib/color_transforms.glsl +++ /dev/null @@ -1,131 +0,0 @@ -//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 deleted file mode 100644 index cb2a2ba..0000000 --- a/shaders/world1/lib/composite3.fsh +++ /dev/null @@ -1,78 +0,0 @@ -#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/projections.glsl b/shaders/world1/lib/projections.glsl deleted file mode 100644 index 72ab381..0000000 --- a/shaders/world1/lib/projections.glsl +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index 559faf3..0000000 --- a/shaders/world1/lib/sky_gradient.glsl +++ /dev/null @@ -1,84 +0,0 @@ -#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 deleted file mode 100644 index 2ee4cdb..0000000 --- a/shaders/world1/lib/specular.glsl +++ /dev/null @@ -1,334 +0,0 @@ -//#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 deleted file mode 100644 index 38d3cbf..0000000 --- a/shaders/world1/lib/stars.glsl +++ /dev/null @@ -1,48 +0,0 @@ -//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 deleted file mode 100644 index 7d58676..0000000 --- a/shaders/world1/lib/texFiltering.glsl +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index f701920..0000000 --- a/shaders/world1/lib/util.glsl +++ /dev/null @@ -1,196 +0,0 @@ -#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 deleted file mode 100644 index 527c5b2..0000000 --- a/shaders/world1/lib/volumetricClouds.glsl +++ /dev/null @@ -1,342 +0,0 @@ -#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.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] - -/////// 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 deleted file mode 100644 index 83212d0..0000000 --- a/shaders/world1/lib/volumetricFog.glsl +++ /dev/null @@ -1,118 +0,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 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 deleted file mode 100644 index fccda4b..0000000 --- a/shaders/world1/texture/composite4.fsh +++ /dev/null @@ -1,37 +0,0 @@ -#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/noises.png b/shaders/world1/texture/noises.png deleted file mode 100644 index 6236ff1..0000000 Binary files a/shaders/world1/texture/noises.png and /dev/null differ diff --git a/shaders/world1/texture/noises.png.mcmeta b/shaders/world1/texture/noises.png.mcmeta deleted file mode 100644 index 33f3199..0000000 --- a/shaders/world1/texture/noises.png.mcmeta +++ /dev/null @@ -1,7 +0,0 @@ -{ - "texture": - { - "blur": true, - "clamp": false - } -} \ No newline at end of file