FIX stochastic shadows on IRIS. add filter option for SSAO and all SSS types. imrpove fog upsampling (even when DH is being used). ambient light is more consistent across all types of weather. tweak cloud lighting.

This commit is contained in:
Xonk
2024-02-16 21:28:13 -05:00
parent f99a3c33b5
commit 088b8206c1
19 changed files with 696 additions and 241 deletions

View File

@ -233,6 +233,7 @@ float ld(float dist) {
/* RENDERTARGETS:2,7 */
void main() {
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
bool iswater = isWater > 0;
vec3 normals = normals_and_materials.xyz;
@ -263,10 +264,12 @@ void main() {
vec4 COLORTEST = gl_FragData[0];
#ifndef Vanilla_like_water
if(iswater){
Albedo = vec3(0.0);
gl_FragData[0].a = 1.0/255.0;
}
#endif
// diffuse
vec3 Direct_lighting = lightCol.rgb/80.0;
@ -351,8 +354,9 @@ void main() {
float material = 1.0;
#ifdef DH_OVERDRAW_PREVENTION
float distancefade = min(max(1.0 - length(pos.xz)/far,0.0)*2.0,1.0);
float distancefade = min(max(1.0 - length(pos.xz)/max(far-16.0,0.0),0.0)*2.0,1.0);
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, distancefade);
material = distancefade < 1.0 ? 1.0 : 0.0;
if(texture2D(depthtex1, gl_FragCoord.xy*texelSize).x < 1.0){
@ -360,10 +364,12 @@ void main() {
material = 0.0;
}
#endif
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
if(gl_FragCoord.x*texelSize.x > 0.53) gl_FragData[0] = vec4(0.0);
#endif
gl_FragData[1] = vec4(Albedo, material);
}
}

View File

@ -16,10 +16,11 @@ flat varying vec4 lightCol;
varying mat4 normalmatrix;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
flat varying vec3 WsunVec;
flat varying vec3 WsunVec2;
uniform mat4 dhProjection;
uniform vec3 sunPosition;
uniform float sunElevation;
@ -34,17 +35,36 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
uniform vec3 cameraPosition;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(dhProjection, viewSpacePosition),-viewSpacePosition.z);
}
void main() {
gl_Position = ftransform();
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
pos = gl_ModelViewMatrix * gl_Vertex;
isWater = 0;
if (dhMaterialId == DH_BLOCK_WATER){
isWater = 1;
gl_Position.y -= 6.0/16.0;
gl_Position.z -= 1e-4;
// offset water to not look like a full cube
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz ;
worldpos.y -= 1.8/16.0;
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
}
gl_Position = toClipSpace3(position);
normals_and_materials = vec4(normalize(gl_Normal), 1.0);
gcolor = gl_Color;
@ -73,5 +93,4 @@ void main() {
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
pos = gl_ModelViewMatrix * gl_Vertex;
}

View File

@ -95,11 +95,8 @@ uniform float noPuddleAreas;
// float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
// }
float interleaved_gradientNoise_temp(){
vec2 alpha = vec2(0.75487765, 0.56984026);
vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter;
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
return noise;
float interleaved_gradientNoise_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;
@ -281,13 +278,15 @@ vec4 texture2D_POMSwitch(
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
varying vec3 pos;
#ifdef HAND
/* RENDERTARGETS: 1,7,8,15,2 */
#else
/* RENDERTARGETS: 1,7,8,15 */
#endif
void main() {
#endif
bool ifPOM = false;
@ -311,6 +310,14 @@ 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
// // overdraw prevention
// if(clamp(1.0-length(pos.xyz)/max(far,0.0),0.0,1.0) <= 0.0 ){
// discard;
// return;
// }
// #endif
float torchlightmap = lmtexcoord.z;
#ifdef Hand_Held_lights

View File

@ -182,6 +182,7 @@ float luma(vec3 color) {
//////////////////////////////VOID MAIN//////////////////////////////
varying vec3 pos;
void main() {
gl_Position = ftransform();
@ -189,6 +190,7 @@ void main() {
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
pos = position;
/////// ----- COLOR STUFF ----- ///////
color = gl_Color;

View File

@ -30,6 +30,9 @@ const bool colortex4MipmapEnabled = true;
uniform sampler2D noisetex;
uniform sampler2D depthtex1;
uniform sampler2D depthtex0;
uniform sampler2D dhDepthTex1;
uniform sampler2D colortex12;
uniform sampler2D colortex14;
uniform sampler2D colortex5;
uniform sampler2D texture;
@ -307,8 +310,11 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
//////////////////////////////// ALBEDO
////////////////////////////////
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
vec3 Albedo = toLinear(gl_FragData[0].rgb);
float UnchangedAlpha = gl_FragData[0].a;
@ -607,17 +613,22 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
gl_FragData[0].a = mix(gl_FragData[0].a, 1.0, fresnel);
#endif
#ifdef DISTANT_HORIZONS
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, 1.0-min(max(1.0 - length(feetPlayerPos.xz)/far,0.0)*2.0,1.0) );
#endif
} else {
gl_FragData[0].rgb = FinalColor;
}
#else
gl_FragData[0].rgb = FinalColor;
#endif
// gl_FragData[0].rgb = vec3(1) * (texelFetch2D(depthtex0,ivec2(gl_FragCoord.xy),0).x - texelFetch2D(dhDepthTex1,ivec2(gl_FragCoord.xy),0).x);
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, 1.0-min(max(1.0 - length(feetPlayerPos.xz)/max(far,0.0),0.0)*2.0,1.0) );
#endif
#ifndef HAND
gl_FragData[1] = vec4(Albedo, iswater);

View File

@ -13,6 +13,7 @@ uniform sampler2D dhDepthTex1;
uniform sampler2D colortex1;
uniform sampler2D colortex6; // Noise
uniform sampler2D colortex8; // Noise
uniform sampler2D colortex14; // Noise
uniform sampler2D colortex15; // Noise
uniform sampler2D shadow;
uniform sampler2D noisetex;
@ -77,12 +78,13 @@ 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 + (frameCounter%40000);
// vec2 coord = gl_FragCoord.xy + frameTimeCounter;
// vec2 coord = gl_FragCoord.xy;
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
return noise ;
vec2 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);
@ -136,12 +138,15 @@ vec2 tapLocation_simple(
return vec2(cos_v, sin_v) * sqrt(alpha);
}
vec2 SpiralSample(
int samples, int totalSamples, float rotation, float Xi
){
Xi = max(Xi,0.0015);
float alpha = float(samples + Xi) * (1.0 / float(totalSamples));
float theta = 3.14159265359 * alpha * rotation ;
float theta = (2.0 *3.14159265359) * alpha * rotation;
float r = sqrt(Xi);
float x = r * sin(theta);
@ -150,6 +155,23 @@ vec2 SpiralSample(
return vec2(x, y);
}
vec3 cosineHemisphereSample(vec2 Xi){
float theta = 2.0 * 3.14159265359 * Xi.y;
float r = sqrt(Xi.x);
float x = r * cos(theta);
float y = r * sin(theta);
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
vec3 rodSample(vec2 Xi)
{
float r = sqrt(Xi.x);
float phi = 2 * 3.14159265359 * Xi.y;
return normalize(vec3(cos(phi) * r, sin(phi) * r, sqrt(clamp(1.0 - Xi.x,0.,1.)))).xzy;
}
#include "/lib/DistantHorizons_projections.glsl"
@ -165,16 +187,105 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
return (near * far) / (depth * (near - far) + far);
}
vec2 SSAO(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
){
if(hand) return vec2(1.0,0.0);
int samples = 7;
float occlusion = 0.0;
float sss = 0.0;
/* DRAWBUFFERS:3 */
void main() {
vec2 texcoord = gl_FragCoord.xy*texelSize;
float dist = 1.0 + clamp(viewPos.z*viewPos.z/50.0,0,5); // shrink sample size as distance increases
float mulfov2 = gbufferProjection[1][1]/(3 * dist);
float maxR2 = viewPos.z*viewPos.z*mulfov2*2.*5/50.0;
#ifdef Ambient_SSS
float maxR2_2 = viewPos.z*viewPos.z*mulfov2*2.*2./50.0;
float dist3 = clamp(1-exp( viewPos.z*viewPos.z / -50),0,1);
if(leaves) maxR2_2 = mix(10, maxR2_2, dist3);
#endif
vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ;
int n = 0;
for (int i = 0; i < samples; i++) {
vec2 sampleOffset = SpiralSample(i, 7, 8, noise) * clamp(0.05 + i*0.095, 0.0,0.3) * mulfov2;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) {
#ifdef DISTANT_HORIZONS
float dhdepth = texelFetch2D(dhDepthTex1, offset,0).x;
#else
float dhdepth = 0.0;
#endif
vec3 t0 = toScreenSpace_DH((offset*texelSize+acc+0.5*texelSize) * (1.0/RENDER_SCALE), texelFetch2D(depthtex1, offset,0).x, dhdepth);
vec3 vec = (t0.xyz - viewPos);
float dsquared = dot(vec, vec);
if (dsquared > 1e-5){
if (dsquared < maxR2){
float NdotV = clamp(dot(vec*inversesqrt(dsquared), normalize(normal)),0.,1.);
occlusion += NdotV * clamp(1.0-dsquared/maxR2,0.0,1.0);
}
#ifdef Ambient_SSS
if(dsquared > maxR2_2){
float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.);
sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0);
}
#endif
n += 1;
}
}
}
return max(1.0 - vec2(occlusion, sss)/n, 0.0);
}
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0);
float z = texture2D(depthtex1,texcoord).x;
float DH_depth1 = texture2D(depthtex1,texcoord).x;
return vec4(encn,vec2(lightmaps.x,lightmaps.y));
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
// #include "/lib/indirect_lighting_effects.glsl"
#ifdef DENOISE_SSS_AND_SSAO
/* RENDERTARGETS:3,14,12*/
#else
/* RENDERTARGETS:3*/
#endif
void main() {
float noise = R2_dither();
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex1,texcoord).x;
float DH_depth1 = texture2D(dhDepthTex1,texcoord).x;
vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE - TAA_Offset*texelSize*0.5, z, DH_depth1);
vec2 tempOffset=TAA_Offset;
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
@ -183,35 +294,66 @@ void main() {
vec2 lightmap = dataUnpacked1.yz;
// bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
// bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01;
bool isLeaf = abs(dataUnpacked1.w-0.55) <0.01;
// bool translucent2 = abs(dataUnpacked1.w-0.6) <0.01; // Weak translucency
// bool translucent4 = abs(dataUnpacked1.w-0.65) <0.01; // Weak translucency
bool entities = abs(dataUnpacked1.w-0.45) < 0.01;
bool hand = abs(dataUnpacked1.w-0.75) < 0.01;
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
#ifdef DENOISE_SSS_AND_SSAO
float depth = z;
#ifdef DISTANT_HORIZONS
float _near = near;
float _far = far*4.0;
if (depth >= 1.0) {
depth = DH_depth1;
_near = dhNearPlane;
_far = dhFarPlane;
}
depth = linearizeDepthFast(depth, _near, _far);
depth = depth / dhFarPlane;
#endif
if(depth < 1.0)
gl_FragData[2] = vec4(vec3(0.0), depth * depth * 65000.0);
else
gl_FragData[2] = vec4(vec3(0.0), 65000.0);
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
if(z >= 1.0){
FlatNormals = worldToView(normal);
}
gl_FragData[1] = vec4(0.0,0.0,0.0,texture2D(colortex14,texcoord).a);
gl_FragData[1].xy = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
#endif
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
float NdotL = clamp(dot(normal,WsunVec),0.0,1.0);
float vanillAO = clamp(texture2D(colortex15,texcoord).a,0.0,1.0) ;
float minshadowfilt = Min_Shadow_Filter_Radius;
float maxshadowfilt = Max_Shadow_Filter_Radius;
float NdotL = clamp(dot(normal,WsunVec),0.0,1.0);
// vec4 normalAndAO = texture2D(colortex15,texcoord);
// vec3 FlatNormals = normalAndAO.rgb * 2.0 - 1.0;
// float vanillAO = clamp(normalAndAO.a,0.0,1.0) ;
float vanillAO = clamp(texture2D(colortex15,texcoord).a,0.0,1.0) ;
if(lightmap.y < 0.1 && !entities){
// minshadowfilt *= vanillAO;
maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
}
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
#ifndef Variable_Penumbra_Shadows
if (LabSSS > 0.0 && !hand && NdotL < 0.001) minshadowfilt += 50;
#endif
@ -219,15 +361,14 @@ void main() {
if (z < 1.0 && !hand){
gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0);
gl_FragData[0].y = 0;
gl_FragData[0].a = 0;
// vec3 viewPos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5, z, DH_depth1);
#ifdef Variable_Penumbra_Shadows
if (LabSSS > 0.0) {
if (LabSSS > 0.0 || NdotL > 0.0001) {
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
@ -258,13 +399,9 @@ void main() {
float diffthreshM = diffthresh*mult*d0*k/20.;
float avgDepth = 0.0;
// int seed = (frameCounter%40000) + frameCounter*2;
// float noise = fract(R2_samples(seed).y + blueNoise(gl_FragCoord.xy).y);
float noise = R2_dither();
for(int i = 0; i < VPS_Search_Samples; i++){
vec2 offsetS = SpiralSample(i, 7, 8, noise);
vec2 offsetS = SpiralSample(i, 7, 8, noise) * 0.5;
float weight = 3.0 + (i+noise) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7;
@ -281,6 +418,7 @@ void main() {
gl_FragData[0].g = avgDepth / VPS_Search_Samples;
gl_FragData[0].b = blockerCount / VPS_Search_Samples;
if (blockerCount >= 0.9){
avgBlockerDepth /= blockerCount;
float ssample = max(projectedShadowPosition.z - avgBlockerDepth,0.0)*1500.0;

View File

@ -607,6 +607,46 @@ vec3 getViewPos() {
}
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 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
// float diffThreshold = referenceDepth;
float diffThreshold = 0.0002;
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;
}
void main() {
vec3 DEBUG = vec3(1.0);
@ -768,8 +808,15 @@ void main() {
vec3 filteredShadow = vec3(1.412,1.0,0.0);
if (!hand) filteredShadow = texture2D(colortex3,texcoord).rgb;
#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;
@ -873,6 +920,8 @@ void main() {
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
float biasOffset = 0.0;
if(hand) biasOffset = -0.00035;
#ifdef BASIC_SHADOW_FILTER
float rdMul = filteredShadow.x*distortFactor*d0*k/shadowMapResolution;
@ -967,7 +1016,15 @@ void main() {
/////////////////////////////////////////////////////////////////////////////////
#if indirect_effect == 1
vec2 SSAO_SSS = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
#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)
@ -1053,7 +1110,8 @@ void main() {
#if indirect_effect == 1
vec3 AO = vec3( exp( (vanilla_AO*vanilla_AO) * -3) );
AO *= SSAO_SSS.x*SSAO_SSS.x;
AO *= SSAO_SSS.x*SSAO_SSS.x*SSAO_SSS.x;
SkySSS = SSAO_SSS.y;
Indirect_lighting *= AO;
@ -1167,7 +1225,7 @@ void main() {
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)) ;
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));
}
@ -1184,8 +1242,7 @@ void main() {
}
#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

View File

@ -1,6 +1,7 @@
#include "/lib/settings.glsl"
flat varying vec3 zMults;
flat varying vec3 zMults_DH;
flat varying vec2 TAA_Offset;
flat varying vec3 skyGroundColor;
@ -9,6 +10,7 @@ uniform sampler2D noisetex;
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
uniform sampler2D colortex0;
@ -22,7 +24,7 @@ uniform sampler2D colortex8;
uniform sampler2D colortex9;
uniform sampler2D colortex10;
uniform sampler2D colortex11;
// uniform sampler2D colortex12;
uniform sampler2D colortex12;
uniform sampler2D colortex13;
uniform sampler2D colortex15;
uniform vec2 texelSize;
@ -109,45 +111,121 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
vec4 BilateralUpscale(sampler2D tex, sampler2D depth,vec2 coord,float frDepth){
coord = coord;
vec4 vl = vec4(0.0);
float sum = 0.0;
mat3x3 weights;
const ivec2 scaling = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 posD = ivec2(coord*VL_RENDER_RESOLUTION)*scaling;
ivec2 posVl = ivec2(coord*VL_RENDER_RESOLUTION);
float dz = zMults.x;
ivec2 pos = (ivec2(gl_FragCoord.xy) % 2 )*2;
//pos = ivec2(1,-1);
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);
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;
// vec2 pos = mod(coord,2)*2 - 1;
ivec2 pos = ivec2((coord*texelSize) + 1.0);
// ivec2 pos = (ivec2(gl_FragCoord.xy) % 2 )*2;
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;
ivec2 getRadius[4] = ivec2[](
ivec2(-2,-2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0,-2)
);
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;
float diffThreshold = zMults.x;
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;
vec4 RESULT = vec4(0.0);
float SUM = 0.0;
return vl/sum;
for (int i = 0; i < 4; i++) {
ivec2 radius = getRadius[i];
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;
SUM += EDGES;
}
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;
@ -222,24 +300,24 @@ void main() {
float frDepth = ld(z2);
float swappedDepth = z;
#ifdef DISTANT_HORIZONS
float DH_depth0 = texture2D(dhDepthTex,texcoord).x;
float depthOpaque = z;
float depthOpaqueL = linearizeDepthFast(depthOpaque, near, farPlane);
#ifdef DISTANT_HORIZONS
float dhDepthOpaque = DH_depth0;
float dhDepthOpaqueL = linearizeDepthFast(dhDepthOpaque, dhNearPlane, dhFarPlane);
if (depthOpaque >= 1.0 || (dhDepthOpaqueL < depthOpaqueL && dhDepthOpaque > 0.0)){
depthOpaque = dhDepthOpaque;
depthOpaqueL = dhDepthOpaqueL;
}
#endif
float dhDepthOpaque = DH_depth0;
float dhDepthOpaqueL = linearizeDepthFast(dhDepthOpaque, dhNearPlane, dhFarPlane);
if (depthOpaque >= 1.0 || (dhDepthOpaqueL < depthOpaqueL && dhDepthOpaque > 0.0)){
depthOpaque = dhDepthOpaque;
depthOpaqueL = dhDepthOpaqueL;
}
swappedDepth = depthOpaque;
#else
float DH_depth0 = 0.0;
#endif
swappedDepth = depthOpaque;
#else
float DH_depth0 = 0.0;
#endif
vec3 fragpos = toScreenSpace_DH(texcoord/RENDER_SCALE-vec2(TAA_Offset)*texelSize*0.5, z, DH_depth0);
@ -274,7 +352,12 @@ void main() {
float translucentAlpha = trpData;
////// --------------- get volumetrics
vec4 vl = BilateralUpscale(colortex0, depthtex1, gl_FragCoord.xy, frDepth);
#ifdef DISTANT_HORIZONS
vec4 vl = BilateralUpscale_DH(colortex0, colortex12, gl_FragCoord.xy, sqrt(texture2D(colortex12,texcoord).a/65000.0), z >= 1.0);
#else
vec4 vl = BilateralUpscale(colortex0, depthtex0, gl_FragCoord.xy, frDepth);
#endif
float bloomyFogMult = 1.0;
////// --------------- distort texcoords as a refraction effect
@ -410,6 +493,7 @@ void main() {
vl.a = 1.0;
}
#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[1].rgb = clamp(color.rgb, 0.0,68000.0);

View File

@ -2,8 +2,11 @@
varying vec2 texcoord;
flat varying vec3 zMults;
flat varying vec3 zMults_DH;
uniform float far;
uniform float near;
uniform float dhFarPlane;
uniform float dhNearPlane;
flat varying vec2 TAA_Offset;
uniform int framemod8;
@ -37,6 +40,8 @@ void main() {
TAA_Offset = offsets[framemod8];
zMults = vec3(1.0/(far * near),far+near,far-near);
zMults_DH = vec3(1.0/(dhFarPlane * dhNearPlane),dhFarPlane+dhNearPlane,dhFarPlane-dhNearPlane);
gl_Position = ftransform();
texcoord = gl_MultiTexCoord0.xy;

View File

@ -16,7 +16,7 @@ const int colortex11Format = RGBA16; // unchanged translucents albedo, alpha
const int colortex12Format = RGBA16F; // DISTANT HORIZONS + VANILLA MIXED DEPTHs
const int colortex14Format = RGBA8; // a = skylightmap for translucents.
const int colortex14Format = RGBA8; // rg = SSAO and SS-SSS. a = skylightmap for translucents.
const int colortex15Format = RGBA8; // flat normals and vanilla AO
*/
@ -35,7 +35,7 @@ const bool colortex10Clear = true;
const bool colortex11Clear = true;
const bool colortex12Clear = false;
const bool colortex13Clear = false;
const bool colortex14Clear = true;
const bool colortex14Clear = false;
const bool colortex15Clear = false;

View File

@ -137,9 +137,13 @@ void main() {
}
// only need to sample one spot for this
// averageSkyCol_Clouds = max(averageSkyCol_Clouds * (1.0/(luma(averageSkyCol_Clouds)*0.25+0.75)), minimumlight);
// averageSkyCol = max(averageSkyCol*PLANET_GROUND_BRIGHTNESS, minimumlight);
// maximum control of color and luminance
vec3 minimumlight = vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.003 + nightVision);
averageSkyCol_Clouds = max(averageSkyCol_Clouds * (1.0/(luma(averageSkyCol_Clouds)*0.25+0.75)), minimumlight);
averageSkyCol = max(averageSkyCol*PLANET_GROUND_BRIGHTNESS, minimumlight);
averageSkyCol_Clouds = max( normalize(averageSkyCol_Clouds) * min(luma(averageSkyCol_Clouds) * 3.0,3.0), minimumlight);
averageSkyCol = max( normalize(averageSkyCol) * min(luma(averageSkyCol) * 3.0,3.0) * PLANET_GROUND_BRIGHTNESS, minimumlight);
////////////////////////////////////////
/// --- SUNLIGHT/MOONLIGHT STUFF --- ///

View File

@ -102,6 +102,7 @@ void main() {
vec4 VolumetricClouds = renderClouds(viewPos, vec2(R2_dither(),blueNoise2()), sunColor/80.0, averageSkyCol/30.0);
// gl_FragData[0] = vec4(0.0,0.0,0.0,1.0);
gl_FragData[0] = VolumetricClouds;