new TAA test for AMD. a improved ambient lighting for clouds. fixed line on border fog.

This commit is contained in:
Xonk 2024-02-11 16:27:14 -05:00
parent 12df326c72
commit d2d28bdf8e
5 changed files with 92 additions and 64 deletions

View File

@ -39,6 +39,7 @@ uniform float frameTimeCounter;
uniform int frameCounter;
uniform float far;
uniform float near;
uniform float farPlane;
uniform float dhNearPlane;
uniform float dhFarPlane;
@ -221,28 +222,24 @@ void main() {
float frDepth = ld(z2);
float swappedDepth = z;
#ifdef DISTANT_HORIZONS
float DH_depth0 = texture2D(dhDepthTex,texcoord).x;
#else
float DH_depth0 = 0.0;
#endif
#ifdef DISTANT_HORIZONS
float mixedDepth = z;
float _near = near;
float _far = far*4.0;
if (mixedDepth >= 1.0) {
mixedDepth = DH_depth0;
_near = dhNearPlane;
_far = dhFarPlane;
}
mixedDepth = linearizeDepthFast(mixedDepth, _near, _far);
mixedDepth = mixedDepth / dhFarPlane;
float depthOpaque = z;
float depthOpaqueL = linearizeDepthFast(depthOpaque, near, farPlane);
swappedDepth = DH_inv_ld(mixedDepth);
if(swappedDepth >= 0.999999) swappedDepth = 1.0;
#endif
#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
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);
@ -295,9 +292,9 @@ void main() {
#if defined BorderFog
#ifdef DISTANT_HORIZONS
float fog = exp(-25.0 * pow(clamp(1.0-linearDistance/max(dhFarPlane-1000,0.0),0.0,1.0),2.0));
float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance / dhFarPlane,0.0)*3.0,1.0),2.0),2.0);
#else
float fog = exp(-50.0 * pow(clamp(1.0-linearDistance/far,0.0,1.0),2.0));
float fog = 1.0 - pow(1.0-pow(1.0-min(max(1.0 - linearDistance / far,0.0)*5.0,1.0),2.0),2.0);
#endif
fog *= exp(-10.0 * pow(clamp(np3.y,0.0,1.0)*4.0,2.0));

View File

@ -170,6 +170,7 @@ vec3 tonemap(vec3 col){
vec3 invTonemap(vec3 col){
return col/(1-luma(col));
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
{
vec2 du = vec2(texelSize.x*2., 0.0);
@ -194,6 +195,34 @@ vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth)
return dmin;
}
vec3 closestToCamera5taps_DH(vec2 texcoord, sampler2D depth, sampler2D dhDepth, bool depthCheck)
{
vec2 du = vec2(texelSize.x*2., 0.0);
vec2 dv = vec2(0.0, texelSize.y*2.);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depthCheck ? dhDepth : depth, texcoord - dv - du).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depthCheck ? dhDepth : depth, texcoord - dv + du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depthCheck ? dhDepth : depth, texcoord).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depthCheck ? dhDepth : depth, texcoord + dv - du).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depthCheck ? dhDepth : depth, texcoord + dv + du).x);
vec3 dmin = dmc;
dmin = dmin.z > dtr.z? dtr : dmin;
dmin = dmin.z > dtl.z? dtl : dmin;
dmin = dmin.z > dbl.z? dbl : dmin;
dmin = dmin.z > dbr.z? dbr : dmin;
#ifdef TAA_UPSCALING
dmin.xy = dmin.xy/RENDER_SCALE;
#endif
return dmin;
}
uniform sampler2D dhDepthTex;
uniform float dhFarPlane;
uniform float dhNearPlane;
@ -249,7 +278,6 @@ vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
return viewPos.xyz;
}
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
@ -259,15 +287,6 @@ 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(){
@ -283,7 +302,7 @@ vec4 TAA_hq(){
//use velocity from the nearest texel from camera in a 3x3 box in order to improve edge quality in motion
#ifdef CLOSEST_VELOCITY
#ifdef DISTANT_HORIZONS
vec3 closestToCamera = closestToCamera5taps(adjTC, swapSampler(depthtex0, dhDepthTex, depthCheck));
vec3 closestToCamera = closestToCamera5taps_DH(adjTC, depthtex0, dhDepthTex, depthCheck);
#else
vec3 closestToCamera = closestToCamera5taps(adjTC, depthtex0);
#endif

View File

@ -12,8 +12,6 @@ flat varying vec3 sunColor;
flat varying vec3 moonColor;
flat varying vec3 averageSkyCol;
flat varying float tempOffsets;
// uniform float far;
uniform float near;

View File

@ -144,7 +144,7 @@ vec4 GetVolumetricFog(
#endif
skyLightPhased = max(skyLightPhased + skyLightPhased*(normalize(wpos).y*0.9+0.1),0.0);
LightSourcePhased *= mie;
LightSourcePhased *= mie;
float lightleakfix = clamp(pow(eyeBrightnessSmooth.y/240.,2) ,0.0,1.0);

View File

@ -209,8 +209,9 @@ float cloudVol(int layer, in vec3 pos, in vec3 samplePos, in float cov, in int L
samplePos.xz -= cloud_movement/4;
// WIND
samplePos.xz += pow( max(pos.y - (minHeight+20), 0.0) / 20.0,1.50) * upperPlane;
if(layer == 0 || layer == 1) samplePos.xz += pow( max(pos.y - (minHeight+20), 0.0) / 20.0,1.50);
if(layer == -1) samplePos.xz += pow( max(pos.y - (minHeight+20), 0.0) / 20.0,1.50) * upperPlane;
noise += (1.0-densityAtPos(samplePos * mix(100.0,200.0,upperPlane)) ) * mix(2.0,1.0,upperPlane);
@ -267,21 +268,39 @@ vec3 DoCloudLighting(
float distantfog
){
float powder = 1.0 - exp(densityFaded * -10);
float powder = 1.0 - exp(-10.0 * densityFaded);
float lesspowder = powder*0.4+0.6;
vec3 skyLight = skyLightCol;
float indirectScatter = exp( -10 * sqrt((skyScatter*skyScatter*skyScatter) * densityFaded)) * lesspowder;
float skyLightShading = exp2((skyScatter*skyScatter) * densityFaded * -35.0) * lesspowder;
vec3 indirectLight = skyLightCol * mix(1.0, indirectScatter, distantfog);
skyLight *= mix(1.0, skyLightShading, distantfog);
vec3 directLight = sunScatter * exp(-10.0 * sunShadows + powder);
directLight += sunMultiScatter * exp(-3.0 * sunShadows ) * (powder*0.7+0.3);
vec3 sunLight = exp(sunShadows * -15 + powder ) * sunScatter;
sunLight += exp(sunShadows * -3) * sunMultiScatter * (powder*0.7+0.3);
// return indirectLight;
// return directLight;
return indirectLight + directLight;
}
vec3 rodSample_CLOUD(vec2 Xi)
{
float r = sqrt(1.0f - Xi.x*Xi.y);
float phi = 2 * 3.14159265359 * Xi.y;
// return skyLight;
// return sunLight;
return skyLight + sunLight;
return normalize(vec3(cos(phi) * r, sin(phi) * r, Xi.x)).xzy;
}
vec2 R2_samples_CLOUD(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
vec3 cosineHemisphereSample_CLOUD(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.)));
}
vec4 renderLayer(
@ -341,6 +360,12 @@ if(layer == 2){
return vec4(COLOR, TOTAL_EXTINCTION);
}else{
#if defined CloudLayer1 && defined CloudLayer0
float upperLayerOcclusion = layer == 0 ? LAYER1_DENSITY *2* GetCumulusDensity(1, rayProgress + vec3(0.0,1.0,0.0) * max((LAYER1_minHEIGHT+30) - rayProgress.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT) : 0.0;
float skylightOcclusion = max(exp2(-5.0 * (upperLayerOcclusion*upperLayerOcclusion)), 0.75 + (1.0-distantfog)*0.25);
#else
float skylightOcclusion = 1.0;
#endif
for(int i = 0; i < QUALITY; i++) {
@ -363,37 +388,26 @@ if(layer == 2){
}
/// shadows cast from one layer to another
/// large cumulus -> small cumulus
#if defined CloudLayer1 && defined CloudLayer0
if(layer == 0) directLight += LAYER1_DENSITY * 2.0 * GetCumulusDensity(1, rayProgress + dV_Sun/abs(dV_Sun.y) * max((LAYER1_minHEIGHT+70*dither) - rayProgress.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT);
#endif
// altostratus -> cumulus
#ifdef CloudLayer2
// cast a shadow from higher clouds onto lower clouds
vec3 HighAlt_shadowPos = rayProgress + dV_Sun/abs(dV_Sun.y) * max(LAYER2_HEIGHT - rayProgress.y,0.0);
float HighAlt_shadow = GetAltostratusDensity(HighAlt_shadowPos) * CloudLayer2_density;
directLight += HighAlt_shadow;
#endif
#if defined CloudLayer1 && defined CloudLayer0
float upperLayerOcclusion = layer == 0 ? LAYER1_DENSITY * 2.0 * GetCumulusDensity(1, rayProgress + vec3(0.0,1.0,0.0) * max((LAYER1_maxHEIGHT-70) - rayProgress.y,0.0), 0, LAYER1_minHEIGHT, LAYER1_maxHEIGHT) : 0.0;
float skylightOcclusion = max(exp2((upperLayerOcclusion*upperLayerOcclusion) * -5), 0.75 + (1.0-distantfog)*0.25);
#else
float skylightOcclusion = 1.0;
#endif
float skyScatter = clamp(((maxHeight - 20 - rayProgress.y) / 275.0) * (0.5+cloudDensity),0.0,1.0);
vec3 lighting = DoCloudLighting(muE, cumulus, skyLightCol*skylightOcclusion, skyScatter, directLight, sunScatter, sunMultiScatter, distantfog);
vec3 lighting = DoCloudLighting(muE, cumulus, skyLightCol * skylightOcclusion, skyScatter, directLight, sunScatter, sunMultiScatter, distantfog);
// #if defined CloudLayer1 && defined CloudLayer0
// // a horrible approximation of direct light indirectly hitting the lower layer of clouds after scattering through/bouncing off the upper layer.
// lighting += indirectScatter * exp((skyScatter*skyScatter) * cumulus * -35.0) * upperLayerOcclusion * exp(-20.0 * pow(abs(upperLayerOcclusion - 0.3),2));
// #endif
COLOR += max(lighting - lighting*exp(-mult*muE),0.0) * TOTAL_EXTINCTION;
TOTAL_EXTINCTION *= max(exp(-mult*muE),0.0);
if (TOTAL_EXTINCTION < 1e-5) break;
}
rayProgress += dV_view;
}
return vec4(COLOR, TOTAL_EXTINCTION);
@ -490,7 +504,7 @@ vec4 renderClouds(
directScattering *= scatter;
directMultiScattering *= scatter;
sunIndirectScattering *= scatter;
// sunIndirectScattering *= scatter;
//////////////////////////////////////////
////// render Cloud layers and do blending orders
@ -641,12 +655,12 @@ float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
shadow += GetCumulusDensity(0, lowShadowStart, 0, CloudLayer0_height,CloudLayer0_height+100)*LAYER0_DENSITY;
#endif
#ifdef CloudLayer1
vec3 higherShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.0)) * max((CloudLayer1_height + 70) - WorldPos.y,0.0) ;
vec3 higherShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.0)) * max((CloudLayer1_height + 50) - WorldPos.y,0.0) ;
shadow += GetCumulusDensity(1,higherShadowStart, 0, CloudLayer1_height,CloudLayer1_height+100)*LAYER1_DENSITY;
#endif
#ifdef CloudLayer2
vec3 highShadowStart = WorldPos + (WorldSpace_sunVec / max(abs(WorldSpace_sunVec.y),0.0)) * max(CloudLayer2_height - WorldPos.y,0.0);
shadow += GetAltostratusDensity(highShadowStart)*LAYER2_DENSITY;
shadow += GetAltostratusDensity(highShadowStart)*LAYER2_DENSITY * 0.5;
#endif
shadow = clamp(shadow,0.0,1.0);