allow SSAO to interact with the hand

This commit is contained in:
Xonk 2024-03-27 18:19:55 -04:00
parent 0fc3d21d8a
commit 1637a994ec
5 changed files with 34 additions and 19 deletions

View File

@ -214,6 +214,13 @@ void convertHandDepth(inout float depth) {
depth = ndcDepth * 0.5 + 0.5;
}
float convertHandDepth_2(in float depth, bool hand) {
if(!hand) return depth;
float ndcDepth = depth * 2.0 - 1.0;
ndcDepth /= MC_HAND_DEPTH;
return ndcDepth * 0.5 + 0.5;
}
vec2 SSAO(
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
){
@ -225,7 +232,7 @@ vec2 SSAO(
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;
float maxR2 = viewPos.z*viewPos.z*mulfov2*2.0 * 5.0 / mix(4.0, 50.0, clamp(viewPos.z*viewPos.z - 0.1,0,1));
#ifdef Ambient_SSS
float maxR2_2 = viewPos.z*viewPos.z*mulfov2*2.*2./50.0;
@ -234,7 +241,7 @@ vec2 SSAO(
if(leaves) maxR2_2 = mix(10, maxR2_2, dist3);
#endif
vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ;
vec2 acc = -(TAA_Offset*(texelSize/2.0))*RENDER_SCALE ;
int n = 0;
@ -251,7 +258,8 @@ vec2 SSAO(
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 t0 = toScreenSpace_DH((offset*texelSize+acc+0.5*texelSize) * (1.0/RENDER_SCALE), convertHandDepth_2(texelFetch2D(depthtex1, offset,0).x, hand), dhdepth);
vec3 vec = (t0.xyz - viewPos);
float dsquared = dot(vec, vec);

View File

@ -1264,18 +1264,21 @@ void main() {
// GTAO
#if indirect_effect == 2
Indirect_lighting = AmbientLightColor/2.5;
vec2 r2 = fract(R2_samples((frameCounter%40000) + frameCounter*2) + bnoise);
if (!hand) AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z), viewPos, worldToView(slopednormal), r2) * vec3(1.0);
if(!hand){
Indirect_lighting = AmbientLightColor/2.5;
AO = ambient_occlusion(vec3(texcoord/RENDER_SCALE-TAA_Offset*texelSize*0.5,z), viewPos, worldToView(slopednormal), r2) * vec3(1.0);
}
Indirect_lighting *= AO;
#endif
// RTAO and/or SSGI
#if indirect_effect == 3 || indirect_effect == 4
Indirect_lighting = AmbientLightColor;
if (!hand) ApplySSRT(Indirect_lighting, viewPos, normal, vec3(bnoise, noise_2), lightmap.xy, AmbientLightColor*2.5, vec3(TORCH_R,TORCH_G,TORCH_B), isGrass);
if(!hand){
Indirect_lighting = AmbientLightColor;
ApplySSRT(Indirect_lighting, viewPos, normal, vec3(bnoise, noise_2), lightmap.xy, AmbientLightColor*2.5, vec3(TORCH_R,TORCH_G,TORCH_B), isGrass, hand);
}
#endif
#if defined END_SHADER

View File

@ -66,8 +66,5 @@ void applyGameplayEffects_FRAGMENT(inout vec3 color, in vec2 texcoord){
// when damage is taken, flash the above effect. because it uses the stuff above, it seamlessly blends to them.
color = mix(color, distortedScreen, (vignette*vignette) * sqrt(hurt));
#endif
// if(isDead) color = vec3(0);
#endif
}

View File

@ -237,9 +237,15 @@ vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
}
return vec3(1.1);
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
float convertHandDepth_3(in float depth, bool hand) {
if(!hand) return depth;
float ndcDepth = depth * 2.0 - 1.0;
ndcDepth /= MC_HAND_DEPTH;
return ndcDepth * 0.5 + 0.5;
}
vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes, bool hand){
float dist = 1.0 + clamp(position.z*position.z,0,2); // shrink sample size as distance increases
float stepSize = stepsizes / dist;
int maxSteps = STEPS;
@ -257,6 +263,7 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
vec3 stepv = direction/len;
int iterations = min(int(min(len, mult*len)-2), maxSteps);
//Do one iteration for closest texel (good contact shadows)
@ -278,7 +285,7 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (dist <= 0.1) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
if (dist <= mix(0.5, 0.1, clamp(position.z*position.z - 0.1,0,1))) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
}
return vec3(1.1);
@ -294,7 +301,8 @@ void ApplySSRT(
vec3 skylightcolor,
vec3 torchcolor,
bool isGrass
bool isGrass,
bool hand
){
int nrays = RAY_COUNT;
@ -318,7 +326,7 @@ void ApplySSRT(
#ifdef HQ_SSGI
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, noise.z, 50.); // ssr rt
#else
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 30.); // choc sspt
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, noise.z, 30., hand); // choc sspt
#endif
#ifdef SKY_CONTRIBUTION_IN_SSRT

View File

@ -200,8 +200,7 @@ float cloudVol(int layer, in vec3 pos, in vec3 samplePos, in float cov, in int L
// float curvature = 1-exp(-25*pow(clamp(1.0 - length(pos - cameraPosition)/(32*80),0.0,1.0),2));
// curvature = clamp(1.0 - length(pos - cameraPosition)/(32*128),0.0,1.0);
float otherlayer = max(pos.y - (CloudLayer0_height+99.5), 0.0) > 0 ? 0.0 : 1.0;
float upperPlane = otherlayer;