FIX TAA when distant horizons is on. ADD DH submenus

This commit is contained in:
Xonk
2024-02-10 18:10:46 -05:00
parent f2a04b61e5
commit 7d65d65179
19 changed files with 680 additions and 190 deletions

View File

@ -60,11 +60,28 @@ vec3 toScreenSpace(vec3 p) {
return viewPos.xyz / viewPos.w;
}
uniform sampler2D noisetex;
uniform int frameCounter;
uniform float frameTimeCounter;
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
float interleaved_gradientNoise(){
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
}
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 ) ;
}
/* RENDERTARGETS:1,7,8 */
void main() {
// overdraw prevention
if(clamp(1.0-length(pos.xyz)/max(far-16,0.0),0,1) > 0 ) discard;
if(clamp(1.0-length(pos.xyz)/max(far - 16.0,0.0),0.0,1.0) > 0.0 ){
discard;
return;
}
vec3 normals = viewToWorld(normals_and_materials.xyz);
float materials = normals_and_materials.a;

View File

@ -281,11 +281,10 @@ void main() {
#ifdef DISTANT_HORIZONS_SHADOWMAP
float Shadows = 1.0;
mat4 DH_shadowProjection = DH_shadowProjectionTweak(shadowProjection);
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * pos.xyz + gbufferModelViewInverse[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(DH_shadowProjection) * projectedShadowPosition + DH_shadowProjection[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
//apply distortion
#ifdef DISTORT_SHADOWMAP
@ -344,7 +343,7 @@ void main() {
vec3 skyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 ;
skyReflection = mix(skyReflection, ssReflections.rgb, ssReflections.a);
vec3 sunReflection = Direct_lighting * GGX(normals, -normalize(pos.xyz), WsunVec2, 0.05, vec3(0.02));
vec3 sunReflection = Direct_lighting * GGX(normals, -normalize(pos.xyz), WsunVec2, 0.05, vec3(0.02)) * (1-ssReflections.a) ;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, skyReflection, fresnel) + sunReflection ;
gl_FragData[0].a = mix(gl_FragData[0].a, 1.0, fresnel);

View File

@ -405,12 +405,10 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
mat4 DH_shadowProjection = DH_shadowProjectionTweak(shadowProjection);
// mat4 Custom_ViewMatrix = BuildShadowViewMatrix(LightDir);
// vec3 projectedShadowPosition = mat3(Custom_ViewMatrix) * feetPlayerPos_shadow + Custom_ViewMatrix[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(DH_shadowProjection) * projectedShadowPosition + DH_shadowProjection[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
//apply distortion
#ifdef DISTORT_SHADOWMAP

View File

@ -167,8 +167,8 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
void main() {
/* DRAWBUFFERS:3 */
void main() {
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex1,texcoord).x;
@ -229,13 +229,12 @@ void main() {
if (LabSSS > 0.0) {
mat4 DH_shadowProjection = DH_shadowProjectionTweak(shadowProjection);
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(DH_shadowProjection) * projectedShadowPosition + DH_shadowProjection[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
//apply distortion
#ifdef DISTORT_SHADOWMAP

View File

@ -572,6 +572,41 @@ vec4 renderInfiniteWaterPlane(
return vec4(color, total_extinction);
}
// uniform float viewWidth;
// uniform float viewHeight;
// uniform sampler2D depthtex0;
// uniform sampler2D dhDepthTex;
// uniform mat4 gbufferProjectionInverse;
// uniform mat4 dhProjectionInverse;
vec3 getViewPos() {
ivec2 uv = ivec2(gl_FragCoord.xy);
vec2 viewSize = vec2(viewWidth, viewHeight);
vec2 texcoord = gl_FragCoord.xy / viewSize;
vec4 viewPos = vec4(0.0);
float depth = texelFetch(depthtex0, uv, 0).r;
if (depth < 1.0) {
vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
viewPos = gbufferProjectionInverse * ndcPos;
viewPos.xyz /= viewPos.w;
} else {
depth = texelFetch(dhDepthTex, ivec2(gl_FragCoord.xy), 0).r;
vec4 ndcPos = vec4(texcoord, depth, 1.0) * 2.0 - 1.0;
viewPos = dhProjectionInverse * ndcPos;
viewPos.xyz /= viewPos.w;
}
return viewPos.xyz;
}
void main() {
vec3 DEBUG = vec3(1.0);
@ -623,6 +658,8 @@ void main() {
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
vec3 feetPlayerPos_normalized = normVec(feetPlayerPos);
vec3 playerPos = mat3(gbufferModelViewInverse) * getViewPos();
////// --------------- UNPACK OPAQUE GBUFFERS --------------- //////
vec4 data = texture2D(colortex1,texcoord);
@ -798,22 +835,21 @@ void main() {
#ifdef OVERWORLD_SHADER
NdotL = clamp((-15 + dot(slopednormal, WsunVec)*255.0) / 240.0 ,0.0,1.0);
float shadowNDOTL = NdotL;
#ifndef Variable_Penumbra_Shadows
shadowNDOTL += LabSSS;
#endif
// float shadowNDOTL = NdotL;
// #ifndef Variable_Penumbra_Shadows
// shadowNDOTL += LabSSS;
// #endif
if(shadowNDOTL > 0.001){
// if(shadowNDOTL > 0.001){
mat4 DH_shadowProjection = DH_shadowProjectionTweak(shadowProjection);
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
if(!hand || !entities) GriAndEminShadowFix(shadowPlayerPos, viewToWorld(FlatNormals), vanilla_AO, lightmap.y, entities);
vec3 projectedShadowPosition = mat3(shadowModelView) * shadowPlayerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(DH_shadowProjection) * projectedShadowPosition + DH_shadowProjection[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
//apply distortion
#ifdef DISTORT_SHADOWMAP
@ -851,7 +887,7 @@ void main() {
#ifdef OLD_LIGHTLEAK_FIX
if (isEyeInWater == 0) Shadows *= clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0) ,0.0,1.0); // light leak fix
#endif
}
// }
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SUN SSS ////////////////////////////////
@ -1164,7 +1200,7 @@ void main() {
gl_FragData[0].rgb = Direct_lighting;
#endif
#if DEBUG_VIEW == debug_VIEW_POSITION
gl_FragData[0].rgb = viewPos;
gl_FragData[0].rgb = viewPos * 0.001;
#endif

View File

@ -279,7 +279,6 @@ void main() {
#endif
vec3 viewPos = toScreenSpace_DH(tc/RENDER_SCALE, z, DH_z);
// vec3 viewPos = toScreenSpace(vec3(tc/RENDER_SCALE,z));
if (isEyeInWater == 0){

View File

@ -405,8 +405,7 @@ void main() {
////// --------------- FINALIZE
#ifdef display_LUT
vec2 movedTC = texcoord;
vec3 thingy = texture2D(colortex4,movedTC).rgb / 30;
vec3 thingy = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb / 30;
if(luma(thingy) > 0.0){
color.rgb = thingy;

View File

@ -197,24 +197,57 @@ vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
uniform sampler2D dhDepthTex;
uniform float dhFarPlane;
uniform float dhNearPlane;
#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);
}
uniform mat4 dhProjectionInverse;
uniform mat4 dhProjection;
vec3 DH_toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(dhProjectionInverse[0].x, dhProjectionInverse[1].y, dhProjectionInverse[2].zw);
vec3 feetPlayerPos = p * 2. - 1.;
vec4 viewPos = iProjDiag * feetPlayerPos.xyzz + dhProjectionInverse[3];
return viewPos.xyz / viewPos.w;
float linearizeDepthFast(const in float depth, const in float near, const in float far) {
return (near * far) / (depth * (near - far) + far);
}
vec3 DH_toClipSpace3(vec3 viewSpacePosition) {
return projMAD(dhProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
float invertlinearDepthFast(const in float depth, const in float near, const in float far) {
return ((2.0*near/depth)-far-near)/(far-near);
}
vec3 toClipSpace3Prev_DH( vec3 viewSpacePosition, bool depthCheck ) {
mat4 projectionMatrix = depthCheck ? dhPreviousProjection : gbufferPreviousProjection;
return projMAD(projectionMatrix, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
vec4 viewPos = vec4(0.0);
vec3 feetPlayerPos = vec3(0.0);
vec4 iProjDiag = vec4(0.0);
#ifdef DISTANT_HORIZONS
if (depthCheck) {
iProjDiag = vec4(dhProjectionInverse[0].x, dhProjectionInverse[1].y, dhProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + dhProjectionInverse[3];
viewPos.xyz /= viewPos.w;
} else {
#endif
iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
feetPlayerPos = POS * 2.0 - 1.0;
viewPos = iProjDiag * feetPlayerPos.xyzz + gbufferProjectionInverse[3];
viewPos.xyz /= viewPos.w;
#ifdef DISTANT_HORIZONS
}
#endif
return viewPos.xyz;
}
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
@ -226,6 +259,17 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
sampler2D swapSampler(sampler2D depth, sampler2D DHdepth, bool depthCheck ){
if(depthCheck){
return dhDepthTex;
}else{
return depth;
}
}
vec4 TAA_hq(){
#ifdef TAA_UPSCALING
@ -233,23 +277,25 @@ vec4 TAA_hq(){
#else
vec2 adjTC = texcoord;
#endif
bool depthCheck = texture2D(depthtex0,adjTC).x >= 1.0;
//use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion
#ifdef CLOSEST_VELOCITY
#ifdef DISTANT_HORIZONS
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0);
vec3 closestToCamera = closestToCamera5taps(adjTC, swapSampler(depthtex0, dhDepthTex, depthCheck));
#else
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0);
#endif
#endif
#ifndef CLOSEST_VELOCITY
vec3 closestToCamera = vec3(texcoord,texture2D(depthtex1,adjTC).x);
vec3 closestToCamera = vec3(texcoord, texture2D(depthtex1,adjTC).x);
#endif
//reproject previous frame
#ifdef DISTANT_HORIZONS
vec3 viewPos = DH_toScreenSpace(closestToCamera);
vec3 viewPos = toScreenSpace_DH_special(closestToCamera, depthCheck);
#else
vec3 viewPos = toScreenSpace(closestToCamera);
#endif
@ -257,7 +303,7 @@ vec4 TAA_hq(){
viewPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * viewPos + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
previousPosition = toClipSpace3Prev_DH(previousPosition, depthCheck);
vec2 velocity = previousPosition.xy - closestToCamera.xy;
previousPosition.xy = texcoord + velocity;

View File

@ -2,6 +2,13 @@
#define ReflectedFog
#define USE_WEATHER_PARAMS
#ifdef Daily_Weather
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
#endif
flat varying vec3 averageSkyCol_Clouds;
flat varying vec3 averageSkyCol;
@ -42,6 +49,7 @@ uniform vec3 cameraPosition;
// uniform float far;
uniform ivec2 eyeBrightnessSmooth;
vec4 lightCol = vec4(lightSourceColor, float(sunElevation > 1e-5)*2-1.);
#include "/lib/util.glsl"
@ -161,11 +169,33 @@ if (gl_FragCoord.x > pixelPos6.x && gl_FragCoord.x < pixelPos6.x + 1 && gl_FragC
gl_FragData[0] = vec4(1,0,0,1);
}
if(accumuteSpeed < 1.0) mixhistory = 1.0;
#ifdef OVERWORLD_SHADER
//////////////////////////////////////////////
/// --- STORE DAILY WEATHER PARAMETERS --- ///
//////////////////////////////////////////////
// the idea is to store the 8 values, coverage + density of 3 cloud layers and 2 fog density values.
#ifdef Daily_Weather
ivec2 pixelPos = ivec2(0,0);
if (gl_FragCoord.x > 1 && gl_FragCoord.x < 3 && gl_FragCoord.y > 1 && gl_FragCoord.y < 2){
mixhistory = 0.01;
if(gl_FragCoord.x < 2) gl_FragData[0] = dailyWeatherParams0;
if(gl_FragCoord.x > 2) gl_FragData[0] = dailyWeatherParams1;
}
#endif
///////////////////////////////
/// --- STORE COLOR LUT --- ///
///////////////////////////////
@ -175,6 +205,8 @@ if(accumuteSpeed < 1.0) mixhistory = 1.0;
// --- the color of the atmosphere + the average color of the atmosphere.
vec3 skyGroundCol = skyFromTex(vec3(0, -1 ,0), colortex4).rgb;// * clamp(WsunVec.y*2.0,0.2,1.0);
/// --- Save light values
if (gl_FragCoord.x < 1. && gl_FragCoord.y > 19.+18. && gl_FragCoord.y < 19.+18.+1 )
gl_FragData[0] = vec4(averageSkyCol_Clouds * AmbientLightTint,1.0);
@ -338,6 +370,7 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+
vec3 temp = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy),0).rgb;
vec3 curr = gl_FragData[0].rgb*150.;
if(accumuteSpeed < 1.0) mixhistory = 1.0;
gl_FragData[0].rgb = clamp(mix(temp, curr, mixhistory),0.0,65000.);

View File

@ -22,6 +22,9 @@ flat varying float rodExposure;
flat varying float avgL2;
flat varying float centerDepth;
flat varying vec4 dailyWeatherParams0;
flat varying vec4 dailyWeatherParams1;
uniform sampler2D colortex4;
uniform sampler2D colortex6;
uniform sampler2D depthtex0;
@ -72,6 +75,24 @@ float ld(float depth) {
uniform float nightVision;
uniform int worldDay;
void getWeatherParams(
inout vec4 weatherParams0,
inout vec4 weatherParams1,
float layer0_coverage,
float layer1_coverage,
float layer2_coverage,
float uniformFog_density,
float layer0_density,
float layer1_density,
float layer2_density,
float cloudyFog_density
){
weatherParams0 = vec4(layer0_coverage, layer1_coverage, layer2_coverage, uniformFog_density);
weatherParams1 = vec4(layer0_density, layer1_density, layer2_density, cloudyFog_density);
}
void main() {
@ -139,6 +160,25 @@ void main() {
#endif
//////////////////////////////////
/// --- WEATHER PARAMETERS --- ///
//////////////////////////////////
#ifdef Daily_Weather
int dayCounter = int(mod(worldDay, 10));
if(dayCounter == 0) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY0_l0_coverage, DAY0_l1_coverage, DAY0_l2_coverage, DAY0_ufog_density, DAY0_l0_density, DAY0_l1_density, DAY0_l2_density, DAY0_cfog_density);
if(dayCounter == 1) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY1_l0_coverage, DAY1_l1_coverage, DAY1_l2_coverage, DAY1_ufog_density, DAY1_l0_density, DAY1_l1_density, DAY1_l2_density, DAY1_cfog_density);
if(dayCounter == 2) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY2_l0_coverage, DAY2_l1_coverage, DAY2_l2_coverage, DAY2_ufog_density, DAY2_l0_density, DAY2_l1_density, DAY2_l2_density, DAY2_cfog_density);
if(dayCounter == 3) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY3_l0_coverage, DAY3_l1_coverage, DAY3_l2_coverage, DAY3_ufog_density, DAY3_l0_density, DAY3_l1_density, DAY3_l2_density, DAY3_cfog_density);
if(dayCounter == 4) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY4_l0_coverage, DAY4_l1_coverage, DAY4_l2_coverage, DAY4_ufog_density, DAY4_l0_density, DAY4_l1_density, DAY4_l2_density, DAY4_cfog_density);
if(dayCounter == 5) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY5_l0_coverage, DAY5_l1_coverage, DAY5_l2_coverage, DAY5_ufog_density, DAY5_l0_density, DAY5_l1_density, DAY5_l2_density, DAY5_cfog_density);
if(dayCounter == 6) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY6_l0_coverage, DAY6_l1_coverage, DAY6_l2_coverage, DAY6_ufog_density, DAY6_l0_density, DAY6_l1_density, DAY6_l2_density, DAY6_cfog_density);
if(dayCounter == 7) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY7_l0_coverage, DAY7_l1_coverage, DAY7_l2_coverage, DAY7_ufog_density, DAY7_l0_density, DAY7_l1_density, DAY7_l2_density, DAY7_cfog_density);
if(dayCounter == 8) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY8_l0_coverage, DAY8_l1_coverage, DAY8_l2_coverage, DAY8_ufog_density, DAY8_l0_density, DAY8_l1_density, DAY8_l2_density, DAY8_cfog_density);
if(dayCounter == 9) getWeatherParams(dailyWeatherParams0, dailyWeatherParams1, DAY9_l0_coverage, DAY9_l1_coverage, DAY9_l2_coverage, DAY9_ufog_density, DAY9_l0_density, DAY9_l1_density, DAY9_l2_density, DAY9_cfog_density);
#endif
//////////////////////////////
/// --- EXPOSURE STUFF --- ///
//////////////////////////////

View File

@ -1,11 +1,15 @@
#include "/lib/settings.glsl"
//Computes volumetric clouds at variable resolution (default 1/4 res)
#define USE_WEATHER_PARAMS
#ifdef Daily_Weather
flat varying vec3 dailyWeatherParams0;
flat varying vec3 dailyWeatherParams1;
#endif
flat varying vec3 sunColor;
flat varying vec3 moonColor;
flat varying vec3 averageSkyCol;

View File

@ -1,5 +1,7 @@
#include "/lib/settings.glsl"
flat varying vec3 dailyWeatherParams0;
flat varying vec3 dailyWeatherParams1;
flat varying vec3 averageSkyCol;
flat varying vec3 sunColor;
flat varying vec3 moonColor;
@ -25,6 +27,9 @@ void main() {
gl_Position = ftransform();
gl_Position.xy = (gl_Position.xy*0.5+0.5)*clamp(CLOUDS_QUALITY+0.01,0.0,1.0)*2.0-1.0;
dailyWeatherParams0 = texelFetch2D(colortex4,ivec2(1,1),0).rgb/150.0;
dailyWeatherParams1 = texelFetch2D(colortex4,ivec2(2,1),0).rgb/150.0;
averageSkyCol = texelFetch2D(colortex4,ivec2(1,37),0).rgb;
sunColor = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
moonColor = texelFetch2D(colortex4,ivec2(13,37),0).rgb;