intial changes for commit #495

This commit is contained in:
Xonk
2024-11-15 17:54:18 -05:00
parent b32041d4fc
commit b93d6f1a12
56 changed files with 3550 additions and 2274 deletions

View File

@ -13,7 +13,7 @@ vec3 cosineHemisphereSample(vec2 Xi){
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
}
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
vec3 TangentToWorld(vec3 N, vec3 H){
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 T = normalize(cross(UpVector, N));
vec3 B = cross(N, T);
@ -92,67 +92,6 @@ vec4 BilateralUpscale_SSAO(sampler2D tex, sampler2D depth, vec2 coord, float ref
return RESULT / SUM;
}
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;
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) * 0.2 * mulfov2;
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);
}
float ScreenSpace_SSS(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
){
@ -210,40 +149,79 @@ vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.0,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = maxLengths.y;
vec3 stepv = (direction * mult) / quality*vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE ;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
float minZ = spos.z;
float maxZ = spos.z;
spos += stepv*dither;
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases
for(int i = 0; i < int(quality); i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
#ifdef UseQuarterResDepth
float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0));
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
#else
float sp = texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r;
float sp = linZ(texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r);
#endif
float currZ = linZ(spos.z);
float nextZ = linZ(sp);
if(nextZ < currZ && (sp <= max(minZ,maxZ) && sp >= min(minZ,maxZ))) return vec3(spos.xy/RENDER_SCALE,sp);
float biasamount = 0.00005;
minZ = maxZ - biasamount / currZ;
maxZ += stepv.z;
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv;
}
return vec3(1.1);
}
// vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
// vec3 clipPosition = toClipSpace3(position);
// float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
// (-near -position.z) / dir.z : far*sqrt(3.);
// vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
// direction.xy = normalize(direction.xy);
// //get at which length the ray intersects with the edge of the screen
// vec3 maxLengths = (step(0.0,direction)-clipPosition) / direction;
// float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
// vec3 stepv = (direction * mult) / quality*vec3(RENDER_SCALE,1.0);
// vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0);
// spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE ;
// spos += stepv*dither;
// float minZ = spos.z;
// float maxZ = spos.z;
// for(int i = 0; i < int(quality); i++){
// if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
// #ifdef UseQuarterResDepth
// float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0));
// #else
// float sp = texelFetch2D(depthtex1,ivec2(spos.xy/ texelSize),0).r;
// #endif
// float currZ = linZ(spos.z);
// float nextZ = linZ(sp);
// if(nextZ < currZ && (sp <= max(minZ,maxZ) && sp >= min(minZ,maxZ))) return vec3(spos.xy/RENDER_SCALE,sp);
// float biasamount = 0.00005;
// minZ = maxZ - biasamount / currZ;
// maxZ += stepv.z;
// spos += stepv;
// }
// return vec3(1.1);
// }
float convertHandDepth_3(in float depth, bool hand) {
if(!hand) return depth;
@ -301,7 +279,7 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
return vec3(1.1);
}
vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool hand, inout float CURVE ){
vec3 worldpos = mat3(gbufferModelViewInverse) * position;
@ -324,12 +302,12 @@ vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool ha
int iterations = min(int(min(len, mult*len)-2), maxSteps);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0);// + stepv*noise;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*(noise-0.5);
spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE;
float minZ = spos.z;
float maxZ = spos.z;
CURVE = 0.0;
for(int i = 0; i < iterations; i++){
if (spos.x < 0.0 || spos.y < 0.0 || spos.z < 0.0 || spos.x > 1.0 || spos.y > 1.0 || spos.z > 1.0) return vec3(1.1);
@ -349,8 +327,9 @@ vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool ha
minZ = maxZ-biasamount / currZ;
maxZ += stepv.z;
spos += stepv*(noise*0.25+0.75);
spos += stepv;
CURVE += 1.0/iterations;
}
return vec3(1.1);
}
@ -378,24 +357,30 @@ vec3 ApplySSRT(
vec3 radiance2 = vec3(0.0);
vec3 occlusion2 = vec3(0.0);
vec3 skycontribution2 = unchangedIndirect;
float CURVE = 1.0;
vec3 bouncedLight = vec3(0.0);
for (int i = 0; i < nrays; i++){
int seed = (frameCounter%40000)*nrays+i;
vec2 ij = fract(R2_samples(seed) + noise.xy);
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij)), lightmap);
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij)));
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, noise.z, 50.); // ssr rt
#else
vec3 rayHit = RT_alternate(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 10., isLOD); // choc sspt
vec3 rayHit = RT_alternate(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 10., isLOD, CURVE); // choc sspt
/// RAAAAAAAAAAAAAAAAAAAAAAAAGHH
// CURVE = (1.0-exp(-5.0*(1.0-CURVE)));
CURVE = 1.0-pow(1.0-pow(1.0-CURVE,2.0),5.0);
#endif
#ifdef SKY_CONTRIBUTION_IN_SSRT
#ifdef OVERWORLD_SHADER
skycontribution = doIndirectLighting(pow(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/30.0, vec3(0.7)) * 2.5, minimumLightColor, lightmap) + blockLightColor;
// skycontribution = doIndirectLighting(pow(skyCloudsFromTexLOD(rayDir, colortex4, 0).rgb/1200.0, vec3(0.7)) * 2.5, minimumLightColor, lightmap) + blockLightColor;
skycontribution = doIndirectLighting(skyCloudsFromTex(rayDir, colortex4).rgb/1200.0, minimumLightColor, lightmap) + blockLightColor;
#else
skycontribution = pow(skyCloudsFromTexLOD2(rayDir, colortex4, 6).rgb / 30.0, vec3(0.7)) + blockLightColor;
skycontribution = volumetricsFromTex(rayDir, colortex4, 6).rgb / 1200.0 + blockLightColor;
#endif
#else
#ifdef OVERWORLD_SHADER
@ -413,18 +398,18 @@ vec3 ApplySSRT(
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){
bouncedLight = texture2D(colortex5, previousPosition.xy).rgb * GI_Strength;
bouncedLight = texture2D(colortex5, previousPosition.xy).rgb * GI_Strength * CURVE;
radiance += bouncedLight;
radiance2 += bouncedLight;
}
#endif
occlusion += skycontribution;
occlusion2 += skycontribution2;
occlusion += skycontribution * CURVE;
occlusion2 += skycontribution2 * CURVE;
}
}
// return unchangedIndirect * CURVE;
if(isLOD) return max(radiance/nrays, 0.0);
#ifdef SKY_CONTRIBUTION_IN_SSRT