LOTS of fixes, changes, improvements. changes made is bloated because of a skill issue.

FIXED AND IMPROVED translucent rendering. FIXED random stuff from rendering over the hand. FIXED hand shading. FIXED blue horses. FIXED translucent lighting on the hand. FIXED translucent lighting on entities. IMPROVED colored shadows. IMPROVED SSAO application to the scene. IMPROVED subsurface scattering and give it more settings. IMPROVED bloom. ADD AgX tonemap and make it default.
This commit is contained in:
Xonk
2024-05-04 21:08:24 -04:00
parent 343a68c816
commit 25a2284a60
70 changed files with 4096 additions and 1510 deletions

View File

@ -6,14 +6,19 @@ flat varying vec2 TAA_Offset;
#include "/lib/res_params.glsl"
uniform sampler2D depthtex0;
uniform sampler2D depthtex1;
#ifdef DISTANT_HORIZONS
uniform sampler2D dhDepthTex;
uniform sampler2D dhDepthTex1;
#endif
uniform sampler2D colortex1;
uniform sampler2D colortex3; // Noise
uniform sampler2D colortex6; // Noise
uniform sampler2D colortex8; // Noise
uniform sampler2D colortex14; // Noise
uniform sampler2D colortex12; // Noise
uniform sampler2D colortex15; // Noise
uniform sampler2D shadow;
@ -31,14 +36,22 @@ uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform int frameCounter;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform vec3 cameraPosition;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferPreviousModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform vec3 cameraPosition;
uniform float viewWidth;
uniform float aspectRatio;
uniform float viewHeight;
@ -117,11 +130,11 @@ 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(){
#ifdef TAA
// #ifdef TAA
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
#else
vec2 coord = gl_FragCoord.xy;
#endif
// #else
// vec2 coord = gl_FragCoord.xy;
// #endif
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
}
@ -242,12 +255,13 @@ vec2 SSAO(
#endif
vec2 acc = -(TAA_Offset*(texelSize/2.0))*RENDER_SCALE ;
vec2 BLUENOISE = blueNoise(gl_FragCoord.xy).rg;
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;
vec2 sampleOffset = SpiralSample(i, 7, 8, noise) * mulfov2 * clamp(0.05 + i*0.095, 0.0,0.3) ;
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
@ -300,13 +314,56 @@ float encodeVec2(vec2 a){
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
vec3 toClipSpace3Prev(vec3 viewSpacePosition) {
return projMAD(gbufferPreviousProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
}
vec3 closestToCamera5taps(vec2 texcoord, sampler2D depth, bool hand)
{
vec2 du = vec2(texelSize.x*2., 0.0);
vec2 dv = vec2(0.0, texelSize.y*2.);
vec3 dtl = vec3(texcoord,0.) + vec3(-texelSize, texture2D(depth, texcoord - dv - du).x);
vec3 dtr = vec3(texcoord,0.) + vec3( texelSize.x, -texelSize.y, texture2D(depth, texcoord - dv + du).x);
vec3 dmc = vec3(texcoord,0.) + vec3( 0.0, 0.0, texture2D(depth, texcoord).x);
vec3 dbl = vec3(texcoord,0.) + vec3(-texelSize.x, texelSize.y, texture2D(depth, texcoord + dv - du).x);
vec3 dbr = vec3(texcoord,0.) + vec3( texelSize.x, texelSize.y, texture2D(depth, texcoord + dv + du).x);
if(hand){
convertHandDepth(dtl.z);
convertHandDepth(dtr.z);
convertHandDepth(dmc.z);
convertHandDepth(dbl.z);
convertHandDepth(dbr.z);
}
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;
}
float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
float sampleDepth(sampler2D depthTex, vec2 texcoord, bool hand){
// return texture2D(depthTex, texcoord).r;
return convertHandDepth_2(texture2D(depthTex, texcoord).r, hand);
}
/* RENDERTARGETS:3,14,12*/
void main() {
@ -315,10 +372,16 @@ void main() {
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex1,texcoord).x;
#ifdef DISTANT_HORIZONS
float DH_depth1 = texture2D(dhDepthTex1,texcoord).x;
float swappedDepth = z >= 1.0 ? DH_depth1 : z;
#else
float DH_depth1 = 1.0;
float swappedDepth = z;
#endif
vec4 SHADOWDATA = vec4(0.0);
vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
@ -327,6 +390,7 @@ void main() {
vec2 lightmap = dataUnpacked1.yz;
gl_FragData[1] = vec4(0.0,0.0,0.0, texture2D(colortex14,texcoord).a );
// bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;
@ -338,11 +402,12 @@ void main() {
// bool blocklights = abs(dataUnpacked1.w-0.8) <0.01;
if(hand) convertHandDepth(z);
if(hand){
convertHandDepth(z);
}
vec3 viewPos = toScreenSpace_DH(texcoord/RENDER_SCALE - TAA_Offset*texelSize*0.5, z, DH_depth1);
gl_FragData[1] = vec4(0.0,0.0,0.0,texture2D(colortex14,texcoord).a);
#if defined DENOISE_SSS_AND_SSAO && indirect_effect == 1
float depth = z;
@ -366,15 +431,22 @@ void main() {
gl_FragData[2] = vec4(vec3(0.0), 65000.0);
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
vec3 FlatNormals = texture2D(colortex15,texcoord).rgb * 2.0 - 1.0;
if(z >= 1.0){
FlatNormals = worldToView(normal);
}
gl_FragData[1].xy = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
vec2 SSAO_SSS = SSAO(viewPos, FlatNormals, hand, isLeaf, noise);
if(swappedDepth >= 1.0) SSAO_SSS = vec2(1.0,0.0);
gl_FragData[1].xy = SSAO_SSS;
#else
vec2 SSAO_SSS = vec2(1.0,0.0);
#endif
#ifdef OVERWORLD_SHADER
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-64.0 + SpecularTex * 255.0) / 191.0 ,0.0,1.0);
@ -385,31 +457,25 @@ void main() {
float minshadowfilt = Min_Shadow_Filter_Radius;
float maxshadowfilt = Max_Shadow_Filter_Radius;
if(lightmap.y < 0.1 && !entities){
// minshadowfilt *= vanillAO;
maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
}
// if(lightmap.y < 0.1 && !entities){
// maxshadowfilt = mix(minshadowfilt, maxshadowfilt, vanillAO);
// }
#ifndef Variable_Penumbra_Shadows
if (LabSSS > 0.0 && NdotL < 0.001) minshadowfilt += 50;
#ifdef BASIC_SHADOW_FILTER
if (LabSSS > 0.0 && NdotL < 0.001){
minshadowfilt = 50;
// maxshadowfilt = 50;
}
#endif
if (z < 1.0){
gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0);
gl_FragData[0].a = 0;
// vec3 viewPos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));
#ifdef Variable_Penumbra_Shadows
if (LabSSS > -1) {
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
@ -420,8 +486,9 @@ void main() {
#else
float distortFactor = 1.0;
#endif
//do shadows only if on shadow map
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0 || length(feetPlayerPos) < far){
// if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0 || length(feetPlayerPos) < far){
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
float diffthresh = distortThresh/6000.0*threshMul;
@ -435,24 +502,23 @@ void main() {
float diffthreshM = diffthresh*mult*d0*k/20.;
float avgDepth = 0.0;
vec2 BLUENOISE = blueNoise(gl_FragCoord.xy).rg;
for(int i = 0; i < VPS_Search_Samples; i++){
vec2 offsetS = SpiralSample(i, 7, 8, noise) * 0.5;
float weight = 3.0 + (i+noise) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7;
// float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float d = texelFetch2D(shadowtex1, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float d = texelFetch2D(shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d);
blockerCount += b;
#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;
}
@ -464,7 +530,7 @@ void main() {
float ssample = max(projectedShadowPosition.z - avgBlockerDepth,0.0)*1500.0;
gl_FragData[0].r = clamp(ssample, scales.x, scales.y)/(scales.y)*(mult-minshadowfilt)+minshadowfilt;
}
}
// }
}
#endif
}