improve fog upsampler and filtered effects upsampler. improve metals in specular reflections. fix end and nether not compiling, and fix SSAO making them black. redo water shader. added water caustics strength misc setting. add 2 new post process types "xonk tonemapp" and "full reinhard". create overdraw prevention for DH shadowmap. fix SSS with dh shadowmap. tweak screenspace shadow SSS to be better in the distance. add fog behind glass. move water fog to be done in the fog behind glass pass.

This commit is contained in:
Xonk
2024-03-01 22:48:09 -05:00
parent d4a239f223
commit 1ea16b150a
102 changed files with 1982 additions and 753 deletions

View File

@ -66,9 +66,14 @@ uniform float frameTimeCounter;
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float interleaved_gradientNoise(){
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
vec2 alpha = vec2(0.75487765, 0.56984026);
@ -96,7 +101,7 @@ void main() {
#ifdef DH_OVERDRAW_PREVENTION
// overdraw prevention
if(clamp(1.0-length(pos.xyz)/max(far - 16.0,0.0),0.0,1.0) > 0.0 ){
if(clamp(1.0-length(pos.xyz)/max(far - 32.0 * sqrt(interleaved_gradientNoise_temporal()),0.0),0.0,1.0) > 0.0 ){
discard;
return;
}

View File

@ -158,25 +158,24 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
vec3 stepv = direction * mult / quality * vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv;
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++) {
float sp = sqrt(texelFetch2D(colortex12,ivec2(spos.xy/texelSize/4),0).a/65000.0);
sp = DH_inv_ld(sp);
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
spos += stepv;
//small bias
minZ = maxZ-0.00035/DH_ld(spos.z);
minZ = maxZ-0.0000035/DH_ld(spos.z);
maxZ += stepv.z;
}
@ -243,16 +242,14 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
if(iswater){
vec3 posxz = playerPos+cameraPosition;
posxz.xz -= posxz.y;
vec3 waterHeightmap = normalize(getWaveHeight(posxz.xz,1.0));
vec3 waterHeightmap = normalize(getWaveNormal(posxz, true));
float bumpmult = WATER_WAVE_STRENGTH;
waterHeightmap = waterHeightmap * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
waterHeightmap = normalize(waterHeightmap);
vec2 TangentNormal = waterHeightmap.xy*0.5+0.5;
// vec2 TangentNormal = waterHeightmap.xy*0.5+0.5;
// gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(vec2(1.0)), encodeVec2(vec2(1.0)), 1.0);
if(normals.y > 0.0) normals = vec3(waterHeightmap.x,normals.y,waterHeightmap.y);
@ -320,10 +317,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
float normalDotEye = dot(normals, normalize(pos.xyz));
float fresnel = pow(clamp(1.0 + normalDotEye, 0.0, 1.0),5.0);
fresnel = mix(0.02, 1.0, fresnel);
fresnel = mix(0.1, 1.0, fresnel);
#ifdef SNELLS_WINDOW
// snells window looking thing
if(isEyeInWater == 1 ) fresnel = pow(clamp(1.66 + normalDotEye,0.0,1.0), 25.0);
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#endif
#ifdef WATER_REFLECTIONS

View File

@ -18,6 +18,8 @@ varying vec4 color;
flat varying vec4 lightCol;
#endif
uniform int isEyeInWater;
uniform sampler2D texture;
uniform sampler2D noisetex;
uniform sampler2D colortex4;
@ -135,6 +137,10 @@ void main() {
vec3 Direct_lighting = vec3(0.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(0.2,0.4,1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
@ -172,7 +178,7 @@ void main() {
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
#endif
vec3 AmbientLightColor = averageSkyCol_Clouds * 3.0;
vec3 AmbientLightColor = (averageSkyCol_Clouds / 30.0) * 3.0;
#endif
@ -184,7 +190,7 @@ void main() {
vec3 AmbientLightColor = vec3(1.0);
#endif
Indirect_lighting = DoAmbientLightColor(AmbientLightColor, Torch_Color, clamp(lightmap.xy,0,1));
Indirect_lighting = DoAmbientLightColor(AmbientLightColor,MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1));
#ifdef LINES
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);

View File

@ -311,9 +311,9 @@ void main() {
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;
// #ifdef DH_OVERDRAW_PREVENTION
// #if defined DH_OVERDRAW_PREVENTION && defined DISTANT_HORIZONS
// // overdraw prevention
// if(clamp(1.0-length(pos.xyz)/max(far,0.0),0.0,1.0) <= 0.0 ){
// if(clamp(1.0-length(pos.xyz)/max(far - 16.0 * sqrt(interleaved_gradientNoise_temporal()),0.0),0.0,1.0) <= 0.0 ){
// discard;
// return;
// }

View File

@ -44,7 +44,6 @@ varying vec4 normalMat;
varying vec3 binormal;
varying vec3 flatnormal;
varying vec3 viewVector;
@ -77,7 +76,6 @@ uniform vec3 nsunColor;
#include "/lib/projections.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/waterBump.glsl"
#include "/lib/stars.glsl"
#ifdef OVERWORLD_SHADER
flat varying float Flashing;
@ -132,20 +130,29 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
#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]
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);
varying vec3 viewVector;
vec3 getParallaxDisplacement(vec3 posxz) {
vec3 parallaxPos = posxz;
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
float waterHeight = getWaterHeightmap(posxz.xz, waveM, waveZ, iswater) ;
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0;
float waterHeight = getWaterHeightmap(posxz.xz);
parallaxPos.xz += waterHeight * vec;
return parallaxPos;
}
// vec3 getParallaxDisplacement(vec3 posxz,float bumpmult,vec3 viewVec) {
// vec3 parallaxPos = posxz;
// vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
// float waterHeight = getWaterHeightmap(posxz.xz) ;
// parallaxPos.xz += waterHeight * vec;
// return parallaxPos;
// }
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
float bumpmult = 1;
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
@ -258,8 +265,11 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
spos += stepv;
//small bias
minZ = maxZ-(0.0001/dist)/ld(spos.z);
if(inwater) minZ = maxZ-0.0004/ld(spos.z);
if(inwater) {
minZ = maxZ-0.000035/ld(spos.z);
}else{
minZ = maxZ-(0.0001/dist)/ld(spos.z);
}
maxZ += stepv.z;
}
@ -268,7 +278,6 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
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));
@ -278,7 +287,7 @@ vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
float dotNL = clamp(dot(n,l),0.,1.);
float dotNHsq = dotNH*dotNH;
float denom = dotNHsq * r - dotNHsq + 1.;
float denom = dotNHsq * r - dotNHsq + 1.0;
float D = r / (3.141592653589793 * denom * denom);
vec3 F = 0.2 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
float k2 = .25 * r;
@ -286,6 +295,7 @@ vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
}
uniform float dhFarPlane;
#include "/lib/DistantHorizons_projections.glsl"
@ -368,14 +378,13 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#ifndef HAND
if (iswater > 0.95){
vec3 posxz = feetPlayerPos + cameraPosition;
float bumpmult = WATER_WAVE_STRENGTH;
vec3 bump = vec3(0);
vec3 posxz = feetPlayerPos+cameraPosition;
posxz.xz -= posxz.y;
posxz.xyz = getParallaxDisplacement(posxz,iswater,bumpmult,normalize(tbnMatrix*viewPos)) ;
posxz.xyz = getParallaxDisplacement(posxz) ;
bump = normalize(getWaveHeight(posxz.xz,iswater));
vec3 bump = normalize(getWaveNormal(posxz, false));
TangentNormal = bump.xy*0.5+0.5; // tangent space normals for refraction
@ -402,6 +411,8 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#endif
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(0.2,0.4,1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
vec3 Direct_lighting = vec3(0.0);
#ifdef OVERWORLD_SHADER
@ -464,25 +475,19 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
inShadowmapBounds = true;
}
// if(!inShadowmapBounds && !iswater) Shadows = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
if(!inShadowmapBounds) Shadows = 1.0;
Shadows *= GetCloudShadow(feetPlayerPos);
Direct_lighting = (lightCol.rgb/80.0) * NdotL * Shadows;
vec3 AmbientLightColor = averageSkyCol_Clouds;
vec3 AmbientLightColor = averageSkyCol_Clouds/30.0;
vec3 ambientcoefs = WS_normal / dot(abs(WS_normal), vec3(1));
float SkylightDir = ambientcoefs.y*1.5;
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.25);
AmbientLightColor *= skylight;
// float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + viewToWorld(normal).y, 0.25) * 1.35;
// Indirect_lighting = DoAmbientLighting(averageSkyCol_Clouds, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, skylight);
#endif
#ifdef NETHER_SHADER
@ -515,9 +520,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
AmbientLightColor *= clamp(1.5 + dot(WS_normal, normalize(feetPlayerPos))*0.5,0,2);
#endif
Indirect_lighting = DoAmbientLightColor(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy);
// Albedo = Albedo * exp2( (clamp(-dot(normal, normalize(viewPos)),0.0,1.0)) * -10.0);//pow(clamp(1.0 + dot(normal, normalize(viewPos)), 0.0, 1.0),5.0);
Indirect_lighting = DoAmbientLightColor(AmbientLightColor, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy);
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
@ -535,7 +538,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#ifdef WATER_REFLECTIONS
vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02);
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.1);
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
float f0 = SpecularTex.g;
@ -558,10 +561,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
#ifdef SNELLS_WINDOW
// snells window looking thing
if(isEyeInWater == 1 ) fresnel = pow(clamp(1.66 + normalDotEye,0.0,1.0), 25.0);
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#endif
fresnel = mix(f0, 1.0, fresnel);
// vec3 Metals = f0 > 229.5/255.0 ? max(Albedo, fresnel) : vec3(1.0);
// Sun, Sky, and screen-space reflections
@ -570,13 +575,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), roughness, vec3(f0));
#endif
#ifdef WATER_BACKGROUND_SPECULAR
SkyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0;
if(isEyeInWater == 1) SkyReflection = vec3(0.0);
if(isEyeInWater == 0) SkyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0;
#endif
#else
#ifdef WATER_BACKGROUND_SPECULAR
SkyReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0;
if(isEyeInWater == 1) SkyReflection = vec3(0.0);
if(isEyeInWater == 0) SkyReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0;
#endif
#endif
#ifdef SCREENSPACE_REFLECTIONS
@ -594,6 +597,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
}
#endif
#ifdef OVERWORLD_SHADER
if(isEyeInWater == 1 && iswater > 0.9){
SkyReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1) ;
}
#endif
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
#ifdef ENTITIES
@ -606,7 +614,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
Reflections_Final += SunReflection;
gl_FragData[0].rgb = Reflections_Final;
gl_FragData[0].rgb = Reflections_Final ;
#ifndef ENTITIES
//correct alpha channel with fresnel
@ -638,6 +646,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
#endif
gl_FragData[3].a = max(lmtexcoord.w*blueNoise()*0.05 + lmtexcoord.w,0.0);
gl_FragData[3].a = lmtexcoord.w;
}
}

View File

@ -78,14 +78,7 @@ vec2 tapLocation2(int sampleNumber, int nb, float jitter){
return vec2(cos_v, sin_v)*sqrt(alpha);
}
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
}
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 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
@ -99,8 +92,27 @@ vec2 decodeVec2(float a){
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
// float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter);
// }
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
@ -339,7 +351,7 @@ void main() {
#endif
#ifdef OVERWORLD_SHADER
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
@ -368,7 +380,7 @@ void main() {
#ifdef Variable_Penumbra_Shadows
if (LabSSS > 0.0 || NdotL > 0.0001) {
if (LabSSS > -1) {
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
@ -393,7 +405,7 @@ void main() {
float mult = maxshadowfilt;
float avgBlockerDepth = 0.0;
vec2 scales = vec2(0.0, 120.0 - Max_Filter_Depth);
vec2 scales = vec2(0.0, Max_Filter_Depth);
float blockerCount = 0.0;
float rdMul = distortFactor*(1.0+mult)*d0*k/shadowMapResolution;
float diffthreshM = diffthresh*mult*d0*k/20.;
@ -412,7 +424,11 @@ void main() {
float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d);
blockerCount += b;
avgDepth += max(projectedShadowPosition.z - d, 0.0)*1000.;
#ifdef DISTANT_HORIZONS_SHADOWMAP
avgDepth += max(projectedShadowPosition.z - d, 0.0)*10000.0;
#else
avgDepth += max(projectedShadowPosition.z - d, 0.0)*1000.0;
#endif
avgBlockerDepth += d * b;
}
@ -428,4 +444,5 @@ void main() {
}
#endif
}
#endif
}

View File

@ -27,7 +27,11 @@ void main() {
WsunVec = (float(sunElevation > 1e-5)*2-1.)*normalize(mat3(gbufferModelViewInverse) * sunPosition);
TAA_Offset = offsets[framemod8];
#ifdef TAA
TAA_Offset = offsets[framemod8];
#else
TAA_Offset = vec2(0.0);
#endif
#ifdef TAA_UPSCALING
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;

View File

@ -13,7 +13,6 @@ const bool colortex5MipmapEnabled = true;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
uniform sampler2D colortex14;
#if Sun_specular_Strength != 0
#define LIGHTSOURCE_REFLECTION
@ -62,6 +61,8 @@ uniform sampler2D colortex9; //Specular
uniform sampler2D colortex10;
uniform sampler2D colortex11;
uniform sampler2D colortex12;
uniform sampler2D colortex13;
uniform sampler2D colortex14;
uniform sampler2D colortex15; // flat normals(rgb), vanillaAO(alpha)
@ -86,6 +87,9 @@ uniform float farPlane;
uniform float dhFarPlane;
uniform float dhNearPlane;
flat varying vec3 zMults;
flat varying vec3 zMults_DH;
uniform vec2 texelSize;
uniform float viewWidth;
uniform float viewHeight;
@ -298,7 +302,6 @@ void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEn
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);
@ -325,42 +328,7 @@ void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEn
#ifdef OVERWORLD_SHADER
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;
}
float fogPhase(float lightPoint){
float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0);
float linear2 = 1.0 - clamp(lightPoint,0.0,1.0);
@ -370,72 +338,70 @@ float fogPhase(float lightPoint){
return exponential;
}
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;
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
inColor *= exp(-rayLength * waterCoefs); // No need to take the integrated value
float phase = fogPhase(VdotL) * 5.0;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
// float phase = (phaseg(VdotL,0.6) + phaseg(VdotL,0.8)) * 0.5;
float phase = fogPhase(VdotL) ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
#endif
vec3 sunMul = exp(-max(estSunDepth * d,0.0) * waterCoefs) * 5.0;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Directlight = (lightSource * phase * sunMul) * sh;
vec3 Indirectlight = ambientMul*ambient;
vec3 light = (Directlight + Indirectlight) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
inColor += vL;
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
#endif
vec3 sunMul = exp(-estSunDepth * d * waterCoefs * 1.1);
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
vec3 Directlight = (lightSource * phase * sunMul) * sh;
vec3 Indirectlight = ambient * ambientMul;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-waterCoefs * dd * rayLength);
}
inColor += vL;
}
#endif
vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, bool isSSS){
@ -460,8 +426,9 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
vec3 direction = toClipSpace3_DH(viewPos + lightDir*rayLength, depthCheck) - clipPosition; //convert to clip space
direction.xyz = direction.xyz / max(abs(direction.x)/texelSize.x, abs(direction.y)/texelSize.y); //fixed step size
float Stepmult = depthCheck ? (isSSS ? 0.5 : 6.0) : (isSSS ? 1.0 : 3.0);
vec3 rayDir = direction * (isSSS ? 1.5 : (depthCheck ? 6.0 : 3.0)) * vec3(RENDER_SCALE,1.0);
vec3 rayDir = direction * Stepmult * vec3(RENDER_SCALE,1.0);
vec3 screenPos = clipPosition * vec3(RENDER_SCALE,1.0) + rayDir*noise;
if(isSSS) screenPos -= rayDir*0.9;
@ -502,15 +469,15 @@ float CustomPhase(float LightPos){
return Final;
}
vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, float lightPos, bool inShadowmapBounds){
vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, float lightPos){
float labcurve = pow(Density, LabSSS_Curve);
float density = 15 - labcurve*10;
float density = 15.0 - labcurve*10.0;
vec3 absorbed = max(1.0 - albedo,0.0);
vec3 scatter = exp(absorbed * Scattering * -5) * exp(Scattering * -density);
vec3 scatter = exp(Scattering * absorbed * -5.0) * exp(Scattering * -density);
scatter *= labcurve;
@ -521,11 +488,11 @@ vec3 SubsurfaceScattering_sun(vec3 albedo, float Scattering, float Density, floa
vec3 SubsurfaceScattering_sky(vec3 albedo, float Scattering, float Density){
vec3 absorbed = max(1.0 - albedo,0.0);
vec3 absorbColor = max(1.0 - albedo,0.0);
vec3 scatter = exp((Scattering*Scattering) * absorbed * -5.0) * sqrt(1.0 - Scattering);
vec3 scatter = vec3(1)*exp(-3.0 * (Scattering*Scattering));
scatter *= clamp(1 - exp(Density * -10),0,1);
scatter *= clamp(1.0 - exp(Density * -10.0),0.0,1.0);
return scatter;
}
@ -535,42 +502,42 @@ void Emission(
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 < 235.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/indirect_lighting_effects.glsl"
#include "/lib/PhotonGTAO.glsl"
vec4 renderInfiniteWaterPlane(
vec3 FragPosition, inout vec3 oceanNormals
){
// vec4 renderInfiniteWaterPlane(
// vec3 FragPosition, inout vec3 oceanNormals
// ){
float planeHeight = 20 + 0.50;
float total_extinction = 1.0;
vec3 color = vec3(0.0);
// float planeHeight = 20 + 0.50;
// float total_extinction = 1.0;
// vec3 color = vec3(0.0);
//project pixel position into projected shadowmap space
vec4 viewPos = normalize(gbufferModelViewInverse * vec4(FragPosition,1.0) );
vec3 dV_view = normalize(viewPos.xyz); dV_view *= 1.0/abs(dV_view.y);
// //project pixel position into projected shadowmap space
// vec4 viewPos = normalize(gbufferModelViewInverse * vec4(FragPosition,1.0) );
// vec3 dV_view = normalize(viewPos.xyz); dV_view *= 1.0/abs(dV_view.y);
float mult = length(dV_view);
// float mult = length(dV_view);
float startFlip = mix(max(cameraPosition.y - planeHeight,0.0), max(planeHeight - cameraPosition.y,0), clamp(dV_view.y,0,1));
float signFlip = mix(-1.0, 1.0, clamp(cameraPosition.y - planeHeight,0.0,1.0));
if(max(signFlip * normalize(dV_view).y,0.0) > 0.0) return vec4(0,0,0,1);
// float startFlip = mix(max(cameraPosition.y - planeHeight,0.0), max(planeHeight - cameraPosition.y,0), clamp(dV_view.y,0,1));
// float signFlip = mix(-1.0, 1.0, clamp(cameraPosition.y - planeHeight,0.0,1.0));
// if(max(signFlip * normalize(dV_view).y,0.0) > 0.0) return vec4(0,0,0,1);
vec3 progress_view = vec3(0,cameraPosition.y,0) + dV_view/abs(dV_view.y) * startFlip;
// vec3 progress_view = vec3(0,cameraPosition.y,0) + dV_view/abs(dV_view.y) * startFlip;
oceanNormals = normalize(getWaveHeight((progress_view+cameraPosition).xz,1));
// oceanNormals = normalize(getWaveHeight((progress_view+cameraPosition).xz,1));
vec3 Lighting = vec3(1);
float object = 1;
// vec3 Lighting = vec3(1);
// float object = 1;
color += max(Lighting - Lighting*exp(-mult*object),0.0) * total_extinction;
total_extinction *= max(exp(-mult*object),0.0);
// color += max(Lighting - Lighting*exp(-mult*object),0.0) * total_extinction;
// total_extinction *= max(exp(-mult*object),0.0);
return vec4(color, total_extinction);
}
// return vec4(color, total_extinction);
// }
// uniform float viewWidth;
@ -606,27 +573,22 @@ vec3 getViewPos() {
return viewPos.xyz;
}
vec4 BilateralUpscale(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth, bool depthCheck){
const ivec2 scaling = ivec2(1.0);
ivec2 posDepth = ivec2(coord)*scaling;
ivec2 posColor = ivec2(coord);
// vec2 pos = mod(coord,2)*2 - 1;
ivec2 pos = ivec2(coord*texelSize) + 1;
// ivec2 pos = (ivec2(gl_FragCoord.xy) % 2 )*2;
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
// float diffThreshold = referenceDepth;
float diffThreshold = 0.0002;
float diffThreshold = zMults.x;
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
@ -635,18 +597,107 @@ vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float refer
ivec2 radius = getRadius[i];
float offsetDepth = sqrt(texelFetch2D(depth, (posDepth + radius * scaling + pos * scaling),0).a/65000.0);
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, (posColor + radius + pos),0) * EDGES;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
SUM += EDGES;
}
// return vec4(0,0,0,1) * SUM;
return RESULT / SUM;
}
vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.01;
#else
float diffThreshold = zMults.x;
#endif
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
SUM += EDGES;
}
// return vec4(1) * SUM;
return RESULT / SUM;
}
void BilateralUpscale_REUSE_Z(sampler2D tex1, sampler2D tex2, sampler2D depth, vec2 coord, float referenceDepth, inout vec2 ambientEffects, inout vec3 filteredShadow){
ivec2 scaling = ivec2(1.0);
ivec2 posDepth = ivec2(coord) * scaling;
ivec2 posColor = ivec2(coord);
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.0005;
#else
float diffThreshold = 0.005;
#endif
vec3 shadow_RESULT = vec3(0.0);
vec2 ssao_RESULT = vec2(0.0);
vec4 fog_RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
shadow_RESULT += texelFetch2D(tex1, posColor + radius + pos, 0).rgb * EDGES;
ssao_RESULT += texelFetch2D(tex2, posColor + radius + pos, 0).rg * EDGES;
SUM += EDGES;
}
filteredShadow = shadow_RESULT/SUM;
ambientEffects = ssao_RESULT/SUM;
}
void main() {
vec3 DEBUG = vec3(1.0);
@ -666,6 +717,7 @@ void main() {
bool isDHrange = z >= 1.0;
#ifdef DISTANT_HORIZONS
float DH_mixedLinearZ = sqrt(texture2D(colortex12,texcoord).a/65000.0);
float DH_depth0 = texture2D(dhDepthTex,texcoord).x;
float DH_depth1 = texture2D(dhDepthTex1,texcoord).x;
@ -716,6 +768,7 @@ void main() {
lightmap.y = 1.0;
#endif
// if(isEyeInWater == 1) lightmap.y = max(lightmap.y, 0.75);
////// --------------- UNPACK MISC --------------- //////
@ -770,13 +823,14 @@ void main() {
scatterCoef = dirtAmount * wateralbedo / 3.14;
}
#endif
vec3 Indirect_lighting = vec3(1.0);
vec3 Absorbtion = vec3(1.0);
vec3 AmbientLightColor = vec3(0.0);
vec3 MinimumLightColor = vec3(0.2,0.4,1.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 Indirect_SSS = vec3(0.0);
vec3 Direct_lighting = vec3(0.0);
vec3 DirectLightColor = vec3(0.0);
vec3 Direct_lighting = vec3(0.0);
vec3 Direct_SSS = vec3(0.0);
float cloudShadow = 1.0;
float Shadows = 1.0;
@ -793,8 +847,8 @@ void main() {
float LM_shadowMapFallback = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
#ifdef OVERWORLD_SHADER
DirectLightColor = lightCol.rgb/80.0;
AmbientLightColor = averageSkyCol_Clouds;
DirectLightColor = lightCol.rgb / 80.0;
AmbientLightColor = averageSkyCol_Clouds / 30.0;
#ifdef PER_BIOME_ENVIRONMENT
// BiomeSunlightColor(DirectLightColor);
@ -806,20 +860,6 @@ void main() {
DirectLightColor = mix(DirectLightColor, biomeDirect, maxDistance);
#endif
vec3 filteredShadow = vec3(1.412,1.0,0.0);
#ifdef DENOISE_SSS_AND_SSAO
if (!hand) filteredShadow = BilateralUpscale_SSAO(colortex3, depthtex0, gl_FragCoord.xy, ld(z0)).rgb;
#else
if (!hand) filteredShadow = texture2D(colortex3,texcoord).rgb;
#endif
float ShadowBlockerDepth = filteredShadow.y;
Shadows = clamp(1.0 - filteredShadow.b,0.0,1.0);
shadowMap = Shadows;
bool inShadowmapBounds = false;
#endif
@ -827,8 +867,28 @@ void main() {
float heightRelativeToClouds = clamp(cameraPosition.y - LAYER0_minHEIGHT,0.0,1.0);
vec4 Clouds = texture2D_bicubic_offset(colortex0, texcoord*CLOUDS_QUALITY, noise, RENDER_SCALE.x);
#endif
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// FILTER STUFF //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
vec3 filteredShadow = vec3(1.412,1.0,0.0);
vec2 SSAO_SSS = vec2(1.0);
#ifdef DISTANT_HORIZONS
BilateralUpscale_REUSE_Z(colortex3, colortex14, colortex12, gl_FragCoord.xy, DH_mixedLinearZ, SSAO_SSS, filteredShadow);
#else
BilateralUpscale_REUSE_Z(colortex3, colortex14, depthtex0, gl_FragCoord.xy, ld(z0), SSAO_SSS, filteredShadow);
#endif
///////////////////////////// start drawin :D
float ShadowBlockerDepth = filteredShadow.y;
Shadows = clamp(1.0 - filteredShadow.b,0.0,1.0);
shadowMap = Shadows;
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// START DRAW ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
if (swappedDepth >= 1.0) {
#ifdef OVERWORLD_SHADER
vec3 Background = vec3(0.0);
@ -875,7 +935,38 @@ void main() {
} else {
feetPlayerPos += gbufferModelViewInverse[3].xyz;
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// UNDER WATER SHADING ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){
#ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
float Vdiff = distance(viewPos, viewPos0)*2.0;
float estimatedDepth = Vdiff * abs(feetPlayerPos_normalized.y); //assuming water plane
// make it such that the estimated depth flips to be correct when entering water.
if (isEyeInWater == 1){
estimatedDepth = 40.0 * pow(max(1.0-lightmap.y,0.0),2.0);
MinimumLightColor = vec3(10.0);
}
float depthfalloff = 1.0 - clamp(exp(-0.1*estimatedDepth),0.0,1.0);
float estimatedSunDepth = Vdiff; //assuming water plane
Absorbtion = mix(exp(-2.0 * totEpsilon * estimatedDepth), exp(-8.0 * totEpsilon), depthfalloff);
// DirectLightColor *= Absorbtion;
// AmbientLightColor *= Absorbtion;
// apply caustics to the lighting, and make sure they dont look weird
// DirectLightColor *= mix(1.0, waterCaustics(feetPlayerPos + cameraPosition, WsunVec)*WATER_CAUSTICS_BRIGHTNESS + 0.25, clamp(estimatedDepth,0,1));
}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// MAJOR LIGHTSOURCE STUFF ////////////////////////
////////////////////////////////////////////////////////////////////////////////////
@ -937,7 +1028,7 @@ void main() {
Shadows = shadowMap;
}
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff);
if(!iswater) Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff);
#ifdef OLD_LIGHTLEAK_FIX
if (isEyeInWater == 0) Shadows *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
@ -949,9 +1040,12 @@ void main() {
////////////////////////////////////////////////////////////////////////////////
#if SSS_TYPE != 0
#ifdef DISTANT_HORIZONS
shadowMapFalloff = pow(1.0-pow(1.0-min(max(1.0 - length(vec3(feetPlayerPos.x,feetPlayerPos.y/1.5,feetPlayerPos.z)) / min(shadowDistance, max(far-32,0.0)),0.0)*5.0,1.0),2.0),2.0);
#endif
#if defined DISTANT_HORIZONS_SHADOWMAP && defined Variable_Penumbra_Shadows
float DH_SSS_DISTANCE = pow(1.0-pow(1.0-min(max(1.0 - length(vec3(feetPlayerPos.x,feetPlayerPos.y/1.5,feetPlayerPos.z)) / min(shadowDistance, far),0.0)*5.0,1.0),2.0),2.0);
ShadowBlockerDepth = mix(pow(1.0 - Shadows,2.0), ShadowBlockerDepth, DH_SSS_DISTANCE);
ShadowBlockerDepth = mix(pow(1.0 - Shadows,2.0), ShadowBlockerDepth, shadowMapFalloff);
#endif
#if !defined Variable_Penumbra_Shadows
@ -976,13 +1070,11 @@ void main() {
ShadowBlockerDepth = mix(1.0, ShadowBlockerDepth, shadowMapFalloff);
#endif
Direct_SSS = SubsurfaceScattering_sun(albedo, ShadowBlockerDepth, sunSSS_density, clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), inShadowmapBounds);
Direct_SSS *= mix(LM_shadowMapFallback, 1.0, shadowMapFalloff);
if (isEyeInWater == 0) Direct_SSS *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
}
Direct_SSS = SubsurfaceScattering_sun(albedo, ShadowBlockerDepth, sunSSS_density, clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0));
// Direct_SSS *= mix(LM_shadowMapFallback, 1.0, shadowMapFalloff);
// if (isEyeInWater == 0) Direct_SSS *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
}
#endif
#ifdef CLOUDS_SHADOWS
@ -992,8 +1084,6 @@ void main() {
#endif
#endif
#ifdef END_SHADER
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
@ -1009,24 +1099,14 @@ void main() {
Direct_lighting += lightColors * endPhase * end_NdotL * fogShadow;
AmbientLightColor += lightColors * (endPhase*endPhase) * (1.0-exp(vec3(0.6,2.0,2) * -(endPhase*0.1))) ;
Direct_lighting *= Absorbtion;
#endif
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////// INDIRECT LIGHTING /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
#if indirect_effect == 1
#ifdef DENOISE_SSS_AND_SSAO
#ifdef DISTANT_HORIZONS
vec2 SSAO_SSS = BilateralUpscale_DH(colortex14, colortex12, gl_FragCoord.xy, sqrt(texture2D(colortex12,texcoord).a/65000.0), z >= 1.0).xy;
#else
vec2 SSAO_SSS = BilateralUpscale_SSAO(colortex14, depthtex0, gl_FragCoord.xy, ld(z)).xy;
#endif
#else
vec2 SSAO_SSS = SSAO(viewPos, FlatNormals, hand, isLeaf, noise_2);
#endif
#endif
#if defined OVERWORLD_SHADER && (indirect_effect == 0 || indirect_effect == 1)
vec3 ambientcoefs = slopednormal / dot(abs(slopednormal), vec3(1));
@ -1040,136 +1120,106 @@ void main() {
skylight = min(skylight, (SSAO_SSS.x*SSAO_SSS.x*SSAO_SSS.x) * 2.5);
#endif
AmbientLightColor *= skylight;
Indirect_lighting = AmbientLightColor * skylight;
#endif
#ifdef NETHER_SHADER
AmbientLightColor = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb;
Indirect_lighting = skyCloudsFromTexLOD2(normal, colortex4, 6).rgb;
vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb;
vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb;
up *= pow( max( slopednormal.y, 0), 2);
down *= pow( max(-slopednormal.y, 0), 2);
AmbientLightColor += up + down;
Indirect_lighting += up + down;
Indirect_lighting *= Absorbtion;
#endif
#ifdef END_SHADER
AmbientLightColor += vec3(0.5,0.75,1.0) * 0.9 + 0.1;
Indirect_lighting += (vec3(0.5,0.75,1.0) * 0.9 + 0.1) * 0.1;
AmbientLightColor *= clamp(1.5 + dot(normal, feetPlayerPos_normalized)*0.5,0,2);
Indirect_lighting *= clamp(1.5 + dot(normal, feetPlayerPos_normalized)*0.5,0,2);
Indirect_lighting *= Absorbtion;
#endif
Indirect_lighting = DoAmbientLightColor(AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy);
Indirect_lighting = DoAmbientLightColor(Indirect_lighting, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy);
#ifdef OVERWORLD_SHADER
Indirect_lighting += LightningFlashLighting;
#endif
////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// UNDER WATER SHADING ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
#ifdef OVERWORLD_SHADER
if ((isEyeInWater == 0 && iswater) || (isEyeInWater == 1 && !iswater)){
#ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
float Vdiff = distance(viewPos, viewPos0);
float VdotU = feetPlayerPos_normalized.y;
float estimatedDepth = Vdiff * abs(VdotU); //assuming water plane
// 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);
DirectLightColor *= Absorbtion;
if(isEyeInWater == 1 ) Indirect_lighting = (Indirect_lighting/exp2(-estimatedDepth*0.5)) * Absorbtion;
// apply caustics to the lighting
float Direct_caustics = waterCaustics(feetPlayerPos + cameraPosition, WsunVec);
DirectLightColor *= 1.0 + max(pow(Direct_caustics * 3.0, 2.0),0.0);
// if(isEyeInWater == 0) DirectLightColor *= max(eyeBrightnessSmooth.y/240., 0.0);
}
#endif
#ifdef SSS_view
Indirect_lighting = vec3(3.0);
#endif
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// EFFECTS FOR INDIRECT /////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
float SkySSS = 0.0;
float SkySSS = 1.0;
vec3 AO = vec3(1.0);
#if indirect_effect == 0
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
AO = vec3( exp( (vanilla_AO*vanilla_AO) * -5) ) ;
Indirect_lighting *= AO;
Direct_lighting *= AO;
// Direct_lighting *= AO;
#endif
#if indirect_effect == 1
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) );
AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) );
AO *= SSAO_SSS.x*SSAO_SSS.x*SSAO_SSS.x;
AO *= SSAO_SSS.x*SSAO_SSS.x*SSAO_SSS.x;//*SSAO_SSS.x*SSAO_SSS.x*SSAO_SSS.x;
// AO *= exp((1-SSAO_SSS.x) * -10);
SkySSS = SSAO_SSS.y;
Indirect_lighting *= AO;
Direct_lighting *= AO;
#endif
// GTAO
#if indirect_effect == 2
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) );
AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) );
vec2 r2 = fract(R2_samples((frameCounter%40000) + frameCounter*2) + bnoise);
if (!hand) AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z), viewPos, worldToView(slopednormal), r2) * vec3(1.0);
Indirect_lighting *= AO;
Direct_lighting *= AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
if (!hand) ApplySSRT(Indirect_lighting, viewPos, normal, vec3(bnoise, noise_2), lightmap.xy, AmbientLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), isGrass);
#endif
#ifdef SSS_view
// albedo = vec3(1);
Indirect_lighting = vec3(0.5);
#if defined END_SHADER
Direct_lighting *= AO;
#endif
//////////////////////////////// SKY SSS ////////////////////////////////
#if defined Ambient_SSS && defined OVERWORLD_SHADER
///////////////////////////// SKY SSS /////////////////////////////
#if defined Ambient_SSS && defined OVERWORLD_SHADER && indirect_effect == 1
if (!hand){
#if indirect_effect != 1
SkySSS = ScreenSpace_SSS(viewPos, FlatNormals, hand, isLeaf, noise);
#endif
vec3 ambientColor = (averageSkyCol_Clouds / 12.0) * ambient_brightness; // divide by 12 to match the brightest part of ambient light facing up
float skylightmap = pow(lightmap.y,3);
vec3 ambientColor = AmbientLightColor * 2.5 * ambient_brightness; // x2.5 to match the brightness of upfacing skylight
float skylightmap = pow(lightmap.y, 3.0);
Indirect_SSS = SubsurfaceScattering_sky(albedo, SkySSS, LabSSS);
Indirect_SSS *= ambientColor;
Indirect_SSS *= skylightmap;
vec3 SSS_forSky = vec3((1.0 - SkySSS) * LabSSS);
SSS_forSky *= ambientColor;
SSS_forSky *= skylightmap;
//light up dark parts so its more visible
Indirect_lighting = max(Indirect_lighting, SSS_forSky * ambientsss_brightness);
Indirect_SSS *= AO;
// apply to ambient light.
Indirect_lighting = max(Indirect_lighting, Indirect_SSS * ambientsss_brightness);
Indirect_lighting = max(Indirect_lighting, Indirect_SSS * ambientsss_brightness );
#ifdef OVERWORLD_SHADER
if(LabSSS > 0.0) Indirect_lighting += (1.0-SkySSS) * LightningPhase * lightningEffect * pow(lightmap.y,10);
#endif
}
#endif
/////////////////////////////////////////////////////////////////////////
///////////////////////////// FINALIZE /////////////////////////////
@ -1180,7 +1230,6 @@ void main() {
#ifdef OVERWORLD_SHADER
// do these here so it gets underwater absorbtion.
// Direct_lighting = max(DirectLightColor * NdotL * Shadows, DirectLightColor * LabSSS*0);
Direct_lighting = max(DirectLightColor * NdotL * Shadows, DirectLightColor * Direct_SSS);
#endif
@ -1197,52 +1246,15 @@ void main() {
}
#ifdef DISTANT_HORIZONS
vec4 vlBehingTranslucents = BilateralUpscale_DH(colortex13, colortex12, gl_FragCoord.xy, sqrt(texture2D(colortex12,texcoord).a/65000.0));
#else
vec4 vlBehingTranslucents = BilateralUpscale(colortex13, depthtex1, gl_FragCoord.xy, ld(z));
#endif
gl_FragData[0].rgb = gl_FragData[0].rgb * vlBehingTranslucents.a + vlBehingTranslucents.rgb;
#ifdef OVERWORLD_SHADER
if (iswater && isEyeInWater == 0){
#ifdef DISTANT_HORIZONS
vec3 viewPos0 = toScreenSpace_DH(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5, z0, DH_depth0);
#else
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
#endif
float Vdiff = distance(viewPos, viewPos0);
float VdotU = feetPlayerPos_normalized.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane
float custom_lightmap_T = clamp(pow(texture2D(colortex14, texcoord).a,3.0),0.0,1.0);
#ifdef DISTANT_HORIZONS
if(isDHrange) custom_lightmap_T = 0.85;
#endif
vec3 lightColVol = lightCol.rgb / 80.;
vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 ambientColVol = max((averageSkyCol_Clouds / 30.0) * custom_lightmap_T , vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision)) ;
waterVolumetrics(gl_FragData[0].rgb, viewPos0, viewPos, estimatedDepth, estimatedSunDepth, Vdiff, noise_2, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(feetPlayerPos_normalized, WsunVec));
}
#else
if (iswater && isEyeInWater == 0){
vec3 viewPos0 = toScreenSpace(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z0));
float Vdiff = distance(viewPos,viewPos0);
float VdotU = feetPlayerPos_normalized.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.3, vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01 + nightVision));
waterVolumetrics_notoverworld(gl_FragData[0].rgb, viewPos0, viewPos, estimatedDepth , estimatedDepth, Vdiff, noise_2, totEpsilon, scatterCoef, ambientColVol);
}
#endif
// gl_FragData[0].rgb = vec3(1) * (abs(ld(texture2D(depthtex0,texcoord + vec2(0.001,0)).r) - ld(z0)) < (1.0/(far * near))*0.1 ? 1.0 : 1e-5 );
//////// DEBUG VIEW STUFF
#if DEBUG_VIEW == debug_SHADOWMAP
@ -1251,7 +1263,7 @@ void main() {
gl_FragData[0].rgb = mix(vec3(0.1) * (normal.y * 0.1 +0.9), Normal_Shadowmap, shadowMap);
#endif
#if DEBUG_VIEW == debug_NORMALS
gl_FragData[0].rgb = normal;
gl_FragData[0].rgb = FlatNormals;
#endif
#if DEBUG_VIEW == debug_SPECULAR
gl_FragData[0].rgb = SpecularTex.rgb;
@ -1266,6 +1278,13 @@ void main() {
gl_FragData[0].rgb = viewPos * 0.001;
#endif
// #if DEBUG_VIEW == debug_FILTERED_STUFF
// vec3 FilteredDebug = vec3(15.0) * exp(-1.0 * vec3(1.0,0.5,1.0) * filteredShadow.y);
// FilteredDebug += vec3(15.0) * exp(-7.0 * vec3(1.0,1.0,0.5) * pow(SSAO_SSS.x,2));
// FilteredDebug += vec3(15.0) * exp(-7.0 * vec3(0.5,1.0,1.0) * pow(SSAO_SSS.y,2));
// gl_FragData[0].rgb = FilteredDebug;
// #endif
#ifdef CLOUDS_INFRONT_OF_WORLD
gl_FragData[1] = texture2D(colortex2, texcoord);
if(heightRelativeToClouds > 0.0 && !hand){

View File

@ -9,10 +9,14 @@ flat varying vec4 lightCol;
flat varying vec2 TAA_Offset;
flat varying vec3 zMults;
flat varying vec3 zMults_DH;
uniform sampler2D colortex4;
// uniform float far;
uniform float near;
uniform float dhFarPlane;
uniform float dhNearPlane;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform float rainStrength;
@ -39,7 +43,8 @@ void main() {
Flashing = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
zMults = vec3((far * near)*2.0,far+near,far-near);
zMults = vec3(1.0/(far * near),far+near,far-near);
zMults_DH = vec3(1.0/(dhFarPlane * dhNearPlane),dhFarPlane+dhNearPlane,dhFarPlane-dhNearPlane);
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
@ -50,7 +55,11 @@ void main() {
// WsunVec = normalize(LightDir);
TAA_Offset = offsets[framemod8];
#ifdef TAA
TAA_Offset = offsets[framemod8];
#else
TAA_Offset = vec2(0.0);
#endif
#ifdef TAA_UPSCALING
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;

View File

@ -95,6 +95,22 @@ vec3 getViewPos() {
return viewPos.xyz;
}
vec3 ACESFilm2(vec3 x){
// float a = 2.51f;
// float b = 0.03f;
// float c = 2.43f;
// float d = 0.59f;
// float e = 0.14f;
float a = 2.51f; // brightests
float b = 0.53f; // lower midtones
float c = 2.43f; // upper midtones
float d = 0.59f; // upper midtones
float e = 0.54f; // lowest tones
return clamp((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0);
}
#define linear_to_srgb(x) (pow(x, vec3(1.0/2.2)))
void main() {
/* DRAWBUFFERS:7 */

View File

@ -2,16 +2,19 @@
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
// flat varying vec3 averageSkyCol_Clouds;
flat varying vec3 averageSkyCol_Clouds;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D colortex7;
flat varying vec3 WsunVec;
uniform vec3 sunVec;
@ -43,6 +46,7 @@ uniform float eyeAltitude;
#include "/lib/res_params.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/Shadow_Params.glsl"
#include "/lib/waterBump.glsl"
#include "/lib/DistantHorizons_projections.glsl"
@ -80,17 +84,31 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
#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)+ 1.0/1.6180339887 * frameCounter);
float interleaved_gradientNoise_temporal(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
}
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
}
// float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*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 );
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
void waterVolumetrics_notoverworld(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
@ -136,44 +154,73 @@ void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEn
}
#ifdef OVERWORLD_SHADER
float waterCaustics(vec3 wPos, vec3 lightSource) { // water waves
// #ifdef OVERWORLD_SHADER
// vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
// int spCount = rayMarchSampleCount;
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)));
// vec3 start = toShadowSpaceProjected(rayStart);
// vec3 end = toShadowSpaceProjected(rayEnd);
// vec3 dV = (end-start);
const vec2 wave_size[4] = vec2[](
vec2(64.),
vec2(32.,16.),
vec2(16.,32.),
vec2(48.)
);
// //limit ray length at 32 blocks for performance and reducing integration error
// //you can't see above this anyway
// float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
// dV *= maxZ;
// rayLength *= maxZ;
// estEndDepth *= maxZ;
// estSunDepth *= maxZ;
// vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
// vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
for (int i = 0; i < 4; i++){
pos = rotationMatrix * pos;
// vec3 newabsorbance = exp(-rayLength * waterCoefs); // No need to take the integrated value
// float phase = fogPhase(VdotL) * 5.0;
// vec3 absorbance = vec3(1.0);
// vec3 vL = vec3(0.0);
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;
// float expFactor = 11.0;
// for (int i=0;i<spCount;i++) {
// float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
// float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
// vec3 spPos = start.xyz + dV*d;
caustic += max( 1.0-sin( 1.0-pow( 0.5+sin( small_wave*3.0 )*0.5, 25.0) ), 0);
// vec3 progressW = start.xyz+cameraPosition+dVWorld;
weightSum -= exp2(caustic*0.1);
}
return caustic / weightSum;
}
// //project into biased shadowmap space
// #ifdef DISTORT_SHADOWMAP
// float distortFactor = calcDistort(spPos.xy);
// #else
// float distortFactor = 1.0;
// #endif
// vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
// float sh = 1.0;
// if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
// pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
// sh = shadow2D( shadow, pos).x;
// }
// #ifdef VL_CLOUDS_SHADOWS
// sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
// #endif
// vec3 sunMul = exp(-estSunDepth * d * waterCoefs * 1.1);
// vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
// vec3 Directlight = (lightSource * phase * sunMul) * sh;
// // vec3 Indirectlight = ambient * ambientMul;
// vec3 Indirectlight = max(ambient * ambientMul, vec3(0.01,0.2,0.4) * ambientMul * 0.1) ;
// vec3 light = (Indirectlight + Directlight) * scatterCoef;
// vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
// absorbance *= exp(-waterCoefs * dd * rayLength);
// }
// // inColor += vL;
// return vec4( vL, dot(newabsorbance,vec3(0.335)));
// }
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){
@ -192,61 +239,74 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
// vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a;
// float phase = (phaseg(VdotL,0.6) + phaseg(VdotL,0.8)) * 0.5;
float phase = fogPhase(VdotL) ;
#ifdef OVERWORLD_SHADER
float phase = fogPhase(VdotL) * 5.0;
#endif
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
float YFade = pow(normalize(dVWorld).y*0.3+0.7,1.5);
#ifdef OVERWORLD_SHADER
float lowlightlevel = clamp(eyeBrightnessSmooth.y/240.0,0.1,1.0);
#else
float lowlightlevel = 1.0;
#endif
// lowlightlevel = pow(lowlightlevel,0.5);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
vec3 spPos = start.xyz + dV*d;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
#ifdef OVERWORLD_SHADER
vec3 spPos = start.xyz + dV*d;
sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
#endif
vec3 sunMul = exp(-max((estSunDepth - dY * d) ,0.0)/abs(refractedSunVec.y) * waterCoefs);
vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs) * 2.0 ;
// float bubble = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - length(d*dVWorld) / (16),0.0)*5.0,1.0),2.0),2.0);
float bubble = exp( -7.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0) );
float bubble2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
float np3_Y = normalize(mat3(gbufferModelViewInverse) * rayEnd).y;
float ambfogfade = clamp(exp(np3_Y*1.5 - 1.5),0.0,1.0) ;
float sunCaustics = (waterCaustics(progressW, WsunVec)) * mix(0.25,10.0,bubble) + 0.75;
float sunCaustics = clamp(pow(waterCaustics(progressW, WsunVec)+1,5) * 2.0, phase*0.8+0.2, 1.0);
vec3 sunMul = exp(-1 * d * waterCoefs * 1.1);
vec3 Directlight = (lightSource * phase * sunMul * sunCaustics) * sh * lowlightlevel * pow(abs(WsunVec.y),1);
#else
vec3 Directlight = vec3(0.0);
#endif
vec3 ambientMul = exp(-1 * d * waterCoefs);
vec3 Indirectlight = ambient * ambientMul * YFade * lowlightlevel;
// make it such that the volume is brighter farther away from the camera.
float bubbleOfClearness = max(pow(length(d*dVWorld)/16,5)*100.0,0.0) + 1;
float bubbleOfClearness2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
vec3 Directlight = (lightSource * sunCaustics * phase * (sunMul+0.5)) * sh * pow(abs(WsunVec.y),2) * bubbleOfClearness;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.6,0.6,1.0) * exp(-waterCoefs) * bubbleOfClearness2) * ambfogfade ;
vec3 light = (Directlight + Indirectlight) * scatterCoef ;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
absorbance *= exp(-waterCoefs * dd * rayLength);
}
inColor += vL;
}
#endif
// #endif
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
@ -255,6 +315,17 @@ vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
float fogPhase2(float lightPoint){
float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0);
float linear2 = 1.0 - clamp(lightPoint,0.0,1.0);
float exponential = exp2(pow(linear,0.3) * -15.0 ) * 1.5;
exponential += sqrt(exp2(sqrt(linear) * -12.5));
return exponential;
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
@ -263,64 +334,75 @@ vec2 R2_samples(int n){
void main() {
/* DRAWBUFFERS:0 */
/* RENDERTARGETS:0 */
float noise_1 = R2_dither();
float noise_1 = max(1.0 - R2_dither(),0.0015);
float noise_2 = blueNoise();
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
float z = texture2D(depthtex0,tc).x;
bool iswater = texture2D(colortex7,tc).a > 0.99;
float z0 = texture2D(depthtex0,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex,tc).x;
float DH_z0 = texture2D(dhDepthTex,tc).x;
#else
float DH_z = 0.0;
float DH_z0 = 0.0;
#endif
vec3 viewPos = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
float z = texture2D(depthtex1,tc).x;
float DH_z = texture2D(dhDepthTex1,tc).x;
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 directLightColor = lightCol.rgb/80.0;
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
////////////////////////////////////////////////////////////
///////////////// IN FRONT OF TRANSLUCENTS /////////////////
////////////////////////////////////////////////////////////
if (isEyeInWater == 0){
#ifdef OVERWORLD_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos, vec2(noise_1,noise_2), lightCol.rgb/80.0, averageSkyCol/30.0);
vec4 VolumetricFog = GetVolumetricFog(viewPos0, vec2(noise_1,noise_2), directLightColor, indirectLightColor);
#endif
#if defined NETHER_SHADER || defined END_SHADER
vec4 VolumetricFog = GetVolumetricFog(viewPos, noise_1, noise_2);
vec4 VolumetricFog = GetVolumetricFog(viewPos0, noise_1, noise_2);
#endif
gl_FragData[0] = clamp(VolumetricFog, 0.0, 65000.0);
}
//////////////////////////////////////////////////////////
///////////////// BEHIND OF TRANSLUCENTS /////////////////
//////////////////////////////////////////////////////////
if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
float estEyeDepth = clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
// estEyeDepth = pow(estEyeDepth,3.0) * 32.0;
estEyeDepth = 0.0;
#ifdef OVERWORLD_SHADER
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float estEyeDepth = 1.0-clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
estEyeDepth = pow(estEyeDepth,3.0) * 32.0;
vec3 vl = vec3(0.0);
waterVolumetrics(vl, vec3(0.0), viewPos0, estEyeDepth, estEyeDepth, length(viewPos0), noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic, directLightColor , dot(normalize(viewPos0), normalize(sunVec* lightCol.a ) ));
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
vec3 lightColVol = lightCol.rgb / 80.;
vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 ambientColVol = (averageSkyCol/30.0);
vec3 vl = vec3(0.0);
waterVolumetrics(vl, vec3(0.0), viewPos, estEyeDepth, estEyeDepth, length(viewPos), noise_1, totEpsilon, scatterCoef, ambientColVol, lightColVol*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)) , dot(normalize(viewPos), normalize(sunVec* lightCol.a ) ));
gl_FragData[0] = clamp(vec4(vl,1.0),0.000001,65000.);
#else
vec3 fragpos0 = toScreenSpace(vec3(tc,z));
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
gl_FragData[0].a = 1;
waterVolumetrics_notoverworld(gl_FragData[0].rgb, fragpos0, viewPos, 1.0, 1.0, 1.0, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
#endif
}
}

View File

@ -4,11 +4,13 @@
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec3 WsunVec;
flat varying vec3 refractedSunVec;
flat varying float tempOffsets;
uniform vec2 texelSize;
uniform sampler2D colortex4;
@ -28,21 +30,40 @@ uniform int frameCounter;
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
#include "/lib/sky_gradient.glsl"
void main() {
gl_Position = ftransform();
// gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0;
#ifdef TAA
tempOffsets = HaltonSeq2(frameCounter%10000);
#else
tempOffsets = 0.0;
#endif
#ifdef OVERWORLD_SHADER
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
#endif
#ifdef NETHER_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(2.0, 1.0, 0.5) * 30.0;
#endif
#ifdef END_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(5.0);
#endif
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
// WsunVec = normalize(LightDir);
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
}

View File

@ -107,28 +107,25 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
return (near * far) / (depth * (near - far) + far);
}
vec4 BilateralUpscale(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth){
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION)*scaling;
ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION) * scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
// vec2 pos = mod(coord,2)*2 - 1;
ivec2 pos = ivec2((coord*texelSize) + 1.0);
// ivec2 pos = (ivec2(gl_FragCoord.xy) % 2 )*2;
ivec2 pos = ivec2(gl_FragCoord.xy*texelSize + 1);
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
float diffThreshold = zMults.x;
#ifdef DISTANT_HORIZONS
float diffThreshold = 0.01;
#else
float diffThreshold = zMults.x;
#endif
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
@ -136,96 +133,24 @@ vec4 BilateralUpscale(sampler2D tex, sampler2D depth, vec2 coord, float referenc
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
float offsetDepth = ld(texelFetch2D(depth, (posDepth + radius * scaling + pos * scaling),0).r);
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, posDepth + radius * scaling + pos * scaling, 0).r);
#endif
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, (posColor + radius + pos),0) * EDGES;
RESULT += texelFetch2D(tex, posColor + radius + pos, 0) * EDGES;
SUM += EDGES;
}
// return vec4(1) * SUM;
return RESULT / SUM;
// 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) % 2 )*2;
// //pos = ivec2(1,-1);
// 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;
}
vec4 BilateralUpscale_DH(sampler2D tex, sampler2D depth, vec2 coord, float referenceDepth, bool depthCheck){
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posDepth = ivec2(coord*VL_RENDER_RESOLUTION)*scaling;
ivec2 posColor = ivec2(coord*VL_RENDER_RESOLUTION);
// vec2 pos = mod(coord,2)*2 - 1;
ivec2 pos = ivec2(coord*texelSize) + 1;
// ivec2 pos = (ivec2(gl_FragCoord.xy) % 2 )*2;
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
// float diffThreshold = referenceDepth;
float diffThreshold = zMults_DH.x;
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
float offsetDepth = sqrt(texelFetch2D(depth, (posDepth + radius * scaling + pos * scaling),0).a/65000.0);
float EDGES = abs(offsetDepth - referenceDepth) < diffThreshold ? 1.0 : 1e-5;
RESULT += texelFetch2D(tex, (posColor + radius + pos),0) * EDGES;
SUM += EDGES;
}
return RESULT / SUM;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
@ -273,17 +198,18 @@ void applyContrast(inout vec3 color, float contrast){
color = ((color - 0.5) * max(contrast, 0.0)) + 0.5;
}
void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, vec2 depths, bool isEntity){
void ApplyDistortion(inout vec2 Texcoord, vec2 TangentNormals, float lineardistance, bool isEntity){
vec2 UnalteredTexcoord = Texcoord;
float refractionStrength = isEntity ? 0.5 : 1.0;
Texcoord = abs(Texcoord + (TangentNormals * clamp((ld(depths.x) - ld(depths.y)) * 0.5,0.0,0.15)) * RENDER_SCALE * refractionStrength );
// Texcoord = abs(Texcoord + (TangentNormals * clamp((ld(depths.x) - ld(depths.y)) * 0.5,0.0,0.15)) * RENDER_SCALE * refractionStrength );
Texcoord = abs(Texcoord + (TangentNormals * mix(0.01, 0.1, pow(clamp(1.0-lineardistance/(32*4),0.0,1.0),2))) * RENDER_SCALE * refractionStrength );
float DistortedAlpha = decodeVec2(texture2D(colortex11,Texcoord).b).g;
if(DistortedAlpha <= 0.001) Texcoord = UnalteredTexcoord; // remove distortion on non-translucents
if(DistortedAlpha < 0.1) Texcoord = UnalteredTexcoord; // remove distortion on non-translucents
}
uniform float dhRenderDistance;
@ -297,7 +223,7 @@ void main() {
float z = texture2D(depthtex0,texcoord).x;
float z2 = texture2D(depthtex1,texcoord).x;
float frDepth = ld(z2);
float frDepth = ld(z);
float swappedDepth = z;
@ -351,11 +277,17 @@ void main() {
bool isTranslucentEntity = abs(trpData-0.1) < 0.01;
float translucentAlpha = trpData;
////// --------------- get volumetrics
#ifdef DISTANT_HORIZONS
vec4 vl = BilateralUpscale_DH(colortex0, colortex12, gl_FragCoord.xy, sqrt(texture2D(colortex12,texcoord).a/65000.0), z >= 1.0);
#ifdef TOGGLE_VL_FOG
#ifdef DISTANT_HORIZONS
vec4 vl = BilateralUpscale(colortex0, colortex12, gl_FragCoord.xy, sqrt(texture2D(colortex12,texcoord).a/65000.0));
#else
vec4 vl = BilateralUpscale(colortex0, depthtex0, gl_FragCoord.xy, frDepth);
#endif
#else
vec4 vl = BilateralUpscale(colortex0, depthtex0, gl_FragCoord.xy, frDepth);
vec4 vl = vec4(0,0,0,1);
#endif
float bloomyFogMult = 1.0;
@ -363,7 +295,7 @@ void main() {
////// --------------- distort texcoords as a refraction effect
vec2 refractedCoord = texcoord;
#ifdef Refraction
ApplyDistortion(refractedCoord, tangentNormals, vec2(z2,z), isTranslucentEntity);
ApplyDistortion(refractedCoord, tangentNormals, linearDistance, isTranslucentEntity);
#endif
////// --------------- MAIN COLOR BUFFER
@ -405,7 +337,7 @@ void main() {
#ifdef BorderFog
color.rgb = mix(color.rgb, borderFogColor, fog);
#endif
}
}
////// --------------- VARIOUS FOG EFFECTS (behind volumetric fog)
//////////// blindness, nightvision, liquid fogs and misc fogs
@ -446,17 +378,30 @@ void main() {
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 fogfade = clamp( exp( (linearDistance / -4) * totEpsilon ) ,0.0,1.0);
fogfade *= 1.0 - clamp( linearDistance / far,0.0,1.0);
vec3 absorbColor = exp(-totEpsilon*linearDistance);
vec3 maxAbsorb = exp(-8.0 * totEpsilon);
color.rgb *= fogfade;
bloomyFogMult *= 0.3;
#ifdef OVERWORLD_SHADER
linearDistance = length(vec3(p3.x,max(-p3.y,0.0),p3.z));
float fogfade = exp(-0.001*(linearDistance*linearDistance));
vec3 thresholdAbsorbedColor = mix(maxAbsorb, absorbColor, clamp(dot(absorbColor,vec3(0.33333)),0.0,1.0));
color.rgb = mix(vec3(1.0) * clamp(WsunVec.y,0,1) * pow(normalize(np3).y*0.3+0.7,1.5) * maxAbsorb, color.rgb * thresholdAbsorbedColor, clamp(fogfade,0.0,1.0));
#else
color.rgb *= absorbColor;
#endif
bloomyFogMult *= 0.4;
}
////// --------------- BLEND FOG INTO SCENE
//////////// apply VL fog over opaque and translucents
color *= vl.a;
color += vl.rgb;
bloomyFogMult *= vl.a;
////// --------------- VARIOUS FOG EFFECTS (in front of volumetric fog)
//////////// blindness, nightvision, liquid fogs and misc fogs
@ -495,10 +440,10 @@ void main() {
#endif
// color.rgb = vec3(1) * sqrt(texture2D(colortex12,texcoord).a/65000.0);
gl_FragData[0].r = vl.a * bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[0].r = bloomyFogMult; // pass fog alpha so bloom can do bloomy fog
gl_FragData[1].rgb = clamp(color.rgb, 0.0,68000.0);
// if(isTranslucentEntity) gl_FragData[1].rgb = vec3(255);
// gl_FragData[1].rgb = vec3(1) * sqrt(texelFetch2D(colortex12,ivec2(gl_FragCoord.xy),0).a/65000.0);
// gl_FragData[1].rgb = clamp(vec3(tangentNormals.xy,0), 0.0,68000.0);
// gl_FragData[1].rgb = vl.rgb;
}

View File

@ -3,11 +3,16 @@
varying vec2 texcoord;
flat varying vec3 zMults;
flat varying vec3 zMults_DH;
flat varying vec3 WsunVec;
uniform float far;
uniform float near;
uniform float dhFarPlane;
uniform float dhNearPlane;
uniform mat4 gbufferModelViewInverse;
uniform vec3 sunPosition;
uniform float sunElevation;
flat varying vec2 TAA_Offset;
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
@ -37,7 +42,14 @@ void main() {
skyGroundColor = texelFetch2D(colortex4,ivec2(1,37),0).rgb / 30.0;
#endif
TAA_Offset = offsets[framemod8];
#ifdef TAA
TAA_Offset = offsets[framemod8];
#else
TAA_Offset = vec2(0.0);
#endif
float lightCola = float(sunElevation > 1e-5)*2.0 - 1.0;
WsunVec = normalize(mat3(gbufferModelViewInverse) * sunPosition);
zMults = vec3(1.0/(far * near),far+near,far-near);
zMults_DH = vec3(1.0/(dhFarPlane * dhNearPlane),dhFarPlane+dhNearPlane,dhFarPlane-dhNearPlane);

View File

@ -13,9 +13,9 @@ const int colortex8Format = RGBA8; // Specular Texture
const int colortex9Format = RGBA8; // rain in alpha
const int colortex10Format = RGBA16; // resourcepack Skies
const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha and tangent normals
const int colortex12Format = RGBA16F; // DISTANT HORIZONS + VANILLA MIXED DEPTHs
const int colortex13Format = RGBA16F; // low res VL (composite5->composite15)
const int colortex14Format = RGBA8; // rg = SSAO and SS-SSS. a = skylightmap for translucents.
const int colortex15Format = RGBA8; // flat normals and vanilla AO
*/

View File

@ -126,6 +126,8 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
// uniform sampler2D colortex12;
// const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
uniform sampler2DShadow shadowtex0;
uniform sampler2DShadow shadowtex1;
#define TEST
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
@ -281,9 +283,10 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
suncol = vec3(0.0);
#endif
vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*1.75, skyGroundCol/30.0);
vec4 clouds = renderClouds(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), suncol*2.0, skyGroundCol/30.0);
sky = sky*clouds.a + clouds.rgb / 5.0;
sky = mix(dot(sky,vec3(0.333)) * vec3(0.5), sky, pow(clamp(viewVector.y+1.0,0.0,1.0),5));
vec4 VL_Fog = GetVolumetricFog(mat3(gbufferModelView)*viewVector*1024., vec2(fract(frameCounter/1.6180339887),1-fract(frameCounter/1.6180339887)), lightSourceColor*1.75, skyGroundCol/30.0);
sky = sky * VL_Fog.a + VL_Fog.rgb / 5.0;

View File

@ -45,7 +45,12 @@ vec3 toScreenSpace(vec3 p) {
}
float R2_dither(){
#ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
@ -67,12 +72,14 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(1.0-gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float blueNoise2(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#ifdef TAA
return fract(texelFetch2D(noisetex, ivec2(1.0-gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
#else
return fract(texelFetch2D(noisetex, ivec2(1.0-gl_FragCoord.xy)%512, 0).a);
#endif
}
vec3 normVec (vec3 vec){
return vec*inversesqrt(dot(vec,vec));
}
@ -100,7 +107,7 @@ void main() {
vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize,1.0));
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(),blueNoise2()), sunColor/80.0, averageSkyCol/30.0);
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(), blueNoise()), sunColor/80.0, averageSkyCol/30.0);
// gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
gl_FragData[0] = VolumetricClouds;

View File

@ -0,0 +1,392 @@
#include "/lib/settings.glsl"
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
// flat varying vec3 averageSkyCol_Clouds;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex6;
flat varying vec3 WsunVec;
uniform vec3 sunVec;
uniform float sunElevation;
// uniform float far;
uniform float dhFarPlane;
uniform float dhNearPlane;
uniform int frameCounter;
uniform float frameTimeCounter;
// varying vec2 texcoord;
uniform vec2 texelSize;
// flat varying vec2 TAA_Offset;
uniform int isEyeInWater;
uniform float rainStrength;
uniform ivec2 eyeBrightnessSmooth;
uniform float eyeAltitude;
#define DHVLFOG
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/projections.glsl"
#include "/lib/res_params.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/Shadow_Params.glsl"
#include "/lib/DistantHorizons_projections.glsl"
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
}
float DH_inv_ld (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
}
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
flat varying vec3 refractedSunVec;
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
#include "/lib/volumetricClouds.glsl"
#include "/lib/overworld_fog.glsl"
#endif
#ifdef NETHER_SHADER
uniform sampler2D colortex4;
#include "/lib/nether_fog.glsl"
#endif
#ifdef END_SHADER
uniform sampler2D colortex4;
#include "/lib/end_fog.glsl"
#endif
#define 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)+ 1.0/1.6180339887 * frameCounter);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter );
}
float R2_dither(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Indirectlight = ambientMul*ambient;
vec3 light = Indirectlight * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
#ifdef OVERWORLD_SHADER
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;
}
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 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
// vec3 WsunVec = mat3(gbufferModelViewInverse) * sunVec * lightCol.a;
// float phase = (phaseg(VdotL,0.6) + phaseg(VdotL,0.8)) * 0.5;
float phase = fogPhase(VdotL) ;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
vec3 spPos = start.xyz + dV*d;
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
sh *= GetCloudShadow_VLFOG(progressW, WsunVec);
vec3 sunMul = exp(-max((estSunDepth - dY * d) ,0.0)/abs(refractedSunVec.y) * waterCoefs);
vec3 ambientMul = exp(-max(estEyeDepth - dY * d,0.0) * waterCoefs) * 2.0 ;
float np3_Y = normalize(mat3(gbufferModelViewInverse) * rayEnd).y;
float ambfogfade = clamp(exp(np3_Y*1.5 - 1.5),0.0,1.0) ;
float sunCaustics = clamp(pow(waterCaustics(progressW, WsunVec)+1,5) * 2.0, phase*0.8+0.2, 1.0);
// make it such that the volume is brighter farther away from the camera.
float bubbleOfClearness = max(pow(length(d*dVWorld)/16,5)*100.0,0.0) + 1;
float bubbleOfClearness2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
vec3 Directlight = (lightSource * sunCaustics * phase * (sunMul+0.5)) * sh * pow(abs(WsunVec.y),2) * bubbleOfClearness;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.6,0.6,1.0) * exp(-waterCoefs) * bubbleOfClearness2) * ambfogfade ;
vec3 light = (Directlight + Indirectlight) * scatterCoef ;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
#endif
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
vec3 newabsorbance = exp(-rayLength * waterCoefs); // No need to take the integrated value
float phase = fogPhase(VdotL) * 5.0;
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
float sh = 1.0;
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
// #ifdef VL_CLOUDS_SHADOWS
// sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
// #endif
vec3 sunMul = exp(-estSunDepth * d * waterCoefs * 1.1);
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
vec3 Directlight = (lightSource * phase * sunMul) * sh;
vec3 Indirectlight = ambient * ambientMul;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-waterCoefs * dd * rayLength);
}
// inColor += vL;
return vec4( vL, dot(newabsorbance,vec3(0.335)));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* RENDERTARGETS:13 */
float noise_1 = R2_dither();
float noise_2 = blueNoise();
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
float z = texture2D(depthtex1,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z = texture2D(dhDepthTex1,tc).x;
#else
float DH_z = 0.0;
#endif
float z0 = texture2D(depthtex0,tc).x;
float DH_z0 = texture2D(dhDepthTex,tc).x;
vec3 viewPos = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
// if (isEyeInWater == 1){
float dirtAmount = Dirt_Amount;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
#ifdef OVERWORLD_SHADER
float estEyeDepth = 1.0-clamp(eyeBrightnessSmooth.y/240.0,0.,1.0);
estEyeDepth = pow(estEyeDepth,3.0) * 32.0;
float Vdiff = distance(viewPos, viewPos0);
float VdotU = 0.5;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane
vec3 lightColVol = lightCol.rgb / 80.;
vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
vec3 ambientColVol = (averageSkyCol/30.0);
vec4 vl = waterVolumetrics_test(vec3(0), viewPos, estimatedDepth, estimatedSunDepth, length(viewPos), noise_1, totEpsilon, scatterCoef, ambientColVol, lightColVol, dot(normalize(viewPos), normalize(sunVec* lightCol.a )) );
// waterVolumetrics(vl, vec3(0.0), viewPos, estEyeDepth, estEyeDepth, length(viewPos), noise_1, totEpsilon, scatterCoef, ambientColVol, lightColVol*(1.0-pow(1.0-sunElevation*lightCol.a,5.0)) , dot(normalize(viewPos), normalize(sunVec* lightCol.a ) ) );
gl_FragData[0] = clamp(vl, 0.000001,65000.);
#else
vec3 fragpos0 = toScreenSpace(vec3(tc,z));
vec3 ambientColVol = max(vec3(1.0,0.5,1.0) * 0.6, vec3(0.2,0.4,1.0) * MIN_LIGHT_AMOUNT*0.01);
gl_FragData[0].a = 1;
waterVolumetrics_notoverworld(gl_FragData[0].rgb, fragpos0, viewPos, 1.0, 1.0, 1.0, blueNoise(), totEpsilon, scatterCoef, ambientColVol);
#endif
// }
}

View File

@ -0,0 +1,48 @@
#include "/lib/settings.glsl"
#include "/lib/util.glsl"
#include "/lib/res_params.glsl"
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 WsunVec;
flat varying vec3 refractedSunVec;
flat varying float tempOffsets;
uniform sampler2D colortex4;
uniform float sunElevation;
uniform vec3 sunPosition;
uniform mat4 gbufferModelViewInverse;
uniform int frameCounter;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
void main() {
gl_Position = ftransform();
// gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0;
tempOffsets = HaltonSeq2(frameCounter%10000);
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
// WsunVec = normalize(LightDir);
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
}

View File

@ -6,6 +6,7 @@ uniform sampler2D colortex7;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform sampler2D shadow;
uniform sampler2D shadowcolor0;
uniform sampler2D shadowcolor1;
uniform sampler2D shadowtex0;
@ -121,6 +122,20 @@ void applyColorCurve(inout vec3 color, vec4 darks, vec4 brights){
}
#endif
//float3 crosstalk_and_saturation(float3 color){
//
// float crosstalk = 0.0;
// float saturation = 0.0
//
// float luminance = dot(COLOR, vec3(0.21, 0.72, 0.07));
//
// float3 difference = color - luminance;
//
// color = color + difference*(-luminance*crosstalk + saturation);
//
// return color;
//}
uniform int hideGUI;
void main() {
#ifdef BICUBIC_UPSCALING
@ -165,7 +180,6 @@ void main() {
gl_FragColor.rgb = FINAL_COLOR;
// vec2 texrood = texcoord * vec2(2.0, 1.0) - vec2(1.0, 0.0);
// if(texcoord.x > 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, texrood).rgb;
// if(texcoord.x > 0.5) gl_FragColor.rgb = texture2D(shadowcolor0, texcoord * vec2(2.0, 1.0) - vec2(1.0, 0.0)).rgb * vec3(1.0);
}

View File

@ -0,0 +1,436 @@
#include "/lib/settings.glsl"
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
uniform sampler2D colortex2;
uniform sampler2D colortex3;
// uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D colortex7;
uniform sampler2D colortex14;
flat varying vec3 WsunVec;
uniform vec3 sunVec;
uniform float sunElevation;
// uniform float far;
uniform float dhFarPlane;
uniform float dhNearPlane;
uniform int frameCounter;
uniform float frameTimeCounter;
// varying vec2 texcoord;
uniform vec2 texelSize;
// flat varying vec2 TAA_Offset;
uniform int isEyeInWater;
uniform float rainStrength;
uniform ivec2 eyeBrightnessSmooth;
uniform float eyeAltitude;
#define DHVLFOG
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
#include "/lib/color_transforms.glsl"
#include "/lib/color_dither.glsl"
#include "/lib/projections.glsl"
#include "/lib/res_params.glsl"
#include "/lib/sky_gradient.glsl"
#include "/lib/Shadow_Params.glsl"
#include "/lib/waterBump.glsl"
#include "/lib/DistantHorizons_projections.glsl"
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
}
float DH_inv_ld (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
}
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
flat varying vec3 refractedSunVec;
#define TIMEOFDAYFOG
#include "/lib/lightning_stuff.glsl"
#include "/lib/volumetricClouds.glsl"
#include "/lib/overworld_fog.glsl"
#endif
#ifdef NETHER_SHADER
uniform sampler2D colortex4;
#include "/lib/nether_fog.glsl"
#endif
#ifdef END_SHADER
uniform sampler2D colortex4;
#include "/lib/end_fog.glsl"
#endif
#define 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)+ 1.0/1.6180339887 * frameCounter);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter );
}
float R2_dither(){
#ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 spPos = start.xyz + dV*d;
vec3 progressW = start.xyz+cameraPosition+dVWorld;
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
vec3 Indirectlight = ambientMul*ambient;
vec3 light = Indirectlight * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-dd * rayLength * waterCoefs);
}
inColor += vL;
}
#ifdef OVERWORLD_SHADER
// 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;
// }
// 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 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
// float phase = fogPhase(VdotL) * 5.0;
// vec3 absorbance = vec3(1.0);
// vec3 vL = vec3(0.0);
// float YFade = pow(normalize(dVWorld).y*0.5+0.6,1.5);
// // float YFade = pow(max(normalize(dVWorld).y,0.0)*0.5+0.5,2);
// float lowlightlevel = clamp(eyeBrightnessSmooth.y/240.0,0.2,1.0);
// float lowlightlevel2 = clamp(eyeBrightnessSmooth.y/240.0,0.02,1.0);
// // lowlightlevel = pow(lowlightlevel,0.5);
// float expFactor = 11.0;
// for (int i=0;i<spCount;i++) {
// float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor); // exponential step position (0-1)
// float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0); //step length (derivative)
// vec3 spPos = start.xyz + dV*d;
// progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
// //project into biased shadowmap space
// #ifdef DISTORT_SHADOWMAP
// float distortFactor = calcDistort(spPos.xy);
// #else
// float distortFactor = 1.0;
// #endif
// vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
// float sh = 1.0;
// if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
// pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
// sh = shadow2D( shadow, pos).x;
// }
// #ifdef VL_CLOUDS_SHADOWS
// sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
// #endif
// // float bubble = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - length(d*dVWorld) / (16),0.0)*5.0,1.0),2.0),2.0);
// float bubble = exp( -7.0 * clamp(1.0 - length(d*dVWorld) / 16.0, 0.0,1.0) );
// float bubble2 = max(pow(length(d*dVWorld)/24,5)*100.0,0.0) + 1;
// float sunCaustics = (waterCaustics(progressW, WsunVec)) * mix(0.25,10.0,bubble) + 0.75;
// vec3 sunMul = exp(-1 * d * waterCoefs * 1.1);
// vec3 ambientMul = exp(-1 * d * waterCoefs);
// vec3 Directlight = (lightSource * phase * sunMul * sunCaustics) * sh * lowlightlevel * pow(abs(WsunVec.y),1);
// vec3 Indirectlight = ambient * ambientMul * lowlightlevel;
// // vec3 Indirectlight = max(ambient * ambientMul * lowlightlevel, vec3(0.01,0.2,0.4) * YFade * exp(-1.0 * d * waterCoefs));
// vec3 light = (Indirectlight + Directlight) * scatterCoef;
// vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
// absorbance *= exp(-waterCoefs * dd * rayLength);
// }
// inColor += vL;
// }
#endif
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
}
vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
float fogPhase2(float lightPoint){
float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0);
float linear2 = 1.0 - clamp(lightPoint,0.0,1.0);
float exponential = exp2(pow(linear,0.3) * -15.0 ) * 1.5;
exponential += sqrt(exp2(sqrt(linear) * -12.5));
return exponential;
}
vec4 waterVolumetrics_test( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
int spCount = rayMarchSampleCount;
vec3 start = toShadowSpaceProjected(rayStart);
vec3 end = toShadowSpaceProjected(rayEnd);
vec3 dV = (end-start);
//limit ray length at 32 blocks for performance and reducing integration error
//you can't see above this anyway
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
dV *= maxZ;
rayLength *= maxZ;
estEndDepth *= maxZ;
estSunDepth *= maxZ;
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
vec3 newabsorbance = exp(-rayLength * waterCoefs); // No need to take the integrated value
#ifdef OVERWORLD_SHADER
float phase = fogPhase(VdotL) * 5.0;
#else
float phase = 1.0;
#endif
vec3 absorbance = vec3(1.0);
vec3 vL = vec3(0.0);
float expFactor = 11.0;
for (int i=0;i<spCount;i++) {
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
vec3 progressW = start.xyz+cameraPosition+dVWorld;
float sh = 1.0;
#ifdef OVERWORLD_SHADER
vec3 spPos = start.xyz + dV*d;
//project into biased shadowmap space
#ifdef DISTORT_SHADOWMAP
float distortFactor = calcDistort(spPos.xy);
#else
float distortFactor = 1.0;
#endif
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
sh = shadow2D( shadow, pos).x;
}
#ifdef VL_CLOUDS_SHADOWS
sh *= GetCloudShadow_VLFOG(progressW,WsunVec);
#endif
#endif
vec3 sunMul = exp(-estSunDepth * d * waterCoefs * 1.1);
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs );
vec3 Directlight = (lightSource * phase * sunMul) * sh;
vec3 Indirectlight = max(ambient * ambientMul, vec3(0.01,0.2,0.4) * ambientMul * 0.1) ;
vec3 light = (Indirectlight + Directlight) * scatterCoef;
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
absorbance *= exp(-waterCoefs * dd * rayLength);
}
// inColor += vL;
return vec4( vL, dot(newabsorbance,vec3(0.335)));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
/* RENDERTARGETS:13 */
float noise_1 = R2_dither();
float noise_2 = blueNoise();
vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize;
bool iswater = texture2D(colortex7,tc).a > 0.99;
float z0 = texture2D(depthtex0,tc).x;
#ifdef DISTANT_HORIZONS
float DH_z0 = texture2D(dhDepthTex,tc).x;
#else
float DH_z0 = 0.0;
#endif
float z = texture2D(depthtex1,tc).x;
float DH_z = texture2D(dhDepthTex1,tc).x;
vec3 viewPos1 = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
vec3 viewPos0 = toScreenSpace_DH(tc/RENDER_SCALE, z0, DH_z0);
vec3 playerPos = normalize(mat3(gbufferModelViewInverse) * viewPos1);
// vec3 lightningColor = (lightningEffect / 3) * (max(eyeBrightnessSmooth.y,0)/240.);
float dirtAmount = Dirt_Amount + 0.1;
vec3 waterEpsilon = vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B);
vec3 dirtEpsilon = vec3(Dirt_Absorb_R, Dirt_Absorb_G, Dirt_Absorb_B);
vec3 totEpsilon = dirtEpsilon*dirtAmount + waterEpsilon;
vec3 scatterCoef = dirtAmount * vec3(Dirt_Scatter_R, Dirt_Scatter_G, Dirt_Scatter_B) / 3.14;
vec3 directLightColor = lightCol.rgb/80.0;
vec3 indirectLightColor = averageSkyCol/30.0;
vec3 indirectLightColor_dynamic = averageSkyCol_Clouds/30.0;
//////////////////////////////////////////////////////////
///////////////// BEHIND OF TRANSLUCENTS /////////////////
//////////////////////////////////////////////////////////
// gl_FragData[0] = vec4(0,0,0,1);
if(texture2D(colortex2, tc).a > 0.0 || iswater){
#ifdef OVERWORLD_SHADER
float lightmap = texture2D(colortex14,tc).a;
if(z >= 1.0 ) lightmap = 1.0;
#else
float lightmap = 1.0;
#endif
float Vdiff = distance(viewPos1, viewPos0);
float VdotU = playerPos.y;
float estimatedDepth = Vdiff * abs(VdotU) ; //assuming water plane
float estimatedSunDepth = estimatedDepth/abs(WsunVec.y); //assuming water plane
vec4 VolumetricFog2 = vec4(0,0,0,1);
#ifdef OVERWORLD_SHADER
if(!iswater) VolumetricFog2 = GetVolumetricFog(viewPos1, vec2(noise_1, noise_2), directLightColor, indirectLightColor);
#endif
vec4 underwaterVlFog = vec4(0,0,0,1);
underwaterVlFog = waterVolumetrics_test(viewPos0, viewPos1, estimatedDepth, estimatedSunDepth, Vdiff, noise_1, totEpsilon, scatterCoef, indirectLightColor_dynamic * max(lightmap,0.0), directLightColor, dot(normalize(viewPos1), normalize(sunVec*lightCol.a)) );
vec4 fogFinal = vec4(underwaterVlFog.rgb * VolumetricFog2.a + VolumetricFog2.rgb, VolumetricFog2.a * underwaterVlFog.a);
gl_FragData[0] = clamp(fogFinal, 0.0, 65000.0);
}else{
gl_FragData[0] = vec4(0,0,0,1);
}
}

View File

@ -0,0 +1,71 @@
#include "/lib/settings.glsl"
#include "/lib/util.glsl"
#include "/lib/res_params.glsl"
flat varying vec4 lightCol;
flat varying vec3 averageSkyCol;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec3 WsunVec;
flat varying vec3 refractedSunVec;
flat varying float tempOffsets;
uniform sampler2D colortex4;
uniform float sunElevation;
uniform vec2 texelSize;
uniform vec3 sunPosition;
uniform mat4 gbufferModelViewInverse;
uniform int frameCounter;
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
#include "/lib/sky_gradient.glsl"
void main() {
gl_Position = ftransform();
// gl_Position.xy = (gl_Position.xy*0.5+0.5)*0.51*2.0-1.0;
gl_Position.xy = (gl_Position.xy*0.5+0.5)*(0.01+VL_RENDER_RESOLUTION)*2.0-1.0;
#ifdef TAA
tempOffsets = HaltonSeq2(frameCounter%10000);
#else
tempOffsets = 0.0;
#endif
#ifdef OVERWORLD_SHADER
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
averageSkyCol_Clouds = texelFetch2D(colortex4,ivec2(0,37),0).rgb;
#endif
#ifdef NETHER_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(2.0, 1.0, 0.5) * 30.0;
#endif
#ifdef END_SHADER
lightCol.rgb = vec3(0.0);
averageSkyCol = vec3(0.0);
averageSkyCol_Clouds = vec3(5.0);
#endif
lightCol.a = float(sunElevation > 1e-5)*2.0 - 1.0;
WsunVec = lightCol.a * normalize(mat3(gbufferModelViewInverse) * sunPosition);
// WsunVec = normalize(LightDir);
refractedSunVec = refract(WsunVec, -vec3(0.0,1.0,0.0), 1.0/1.33333);
}