diff --git a/shaders/lib/indirect_lighting_effects.glsl b/shaders/lib/indirect_lighting_effects.glsl index e9d0c50..fd48c6f 100644 --- a/shaders/lib/indirect_lighting_effects.glsl +++ b/shaders/lib/indirect_lighting_effects.glsl @@ -134,6 +134,7 @@ vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){ float sp = invLinZ(sampleDepth) ; if( (sp < max(minZ, maxZ) && sp > min(minZ, maxZ))) return vec3(spos.xy/RENDER_SCALE,sp); + minZ = maxZ - biasAmount / linZ(spos.z); maxZ += stepv.z; @@ -180,7 +181,7 @@ vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool ha stepv.xy *= RENDER_SCALE; vec3 spos = clipPosition + stepv*noise; - spos += stepv*0.3; + // spos += stepv*0.3; spos.xy += TAA_Offset*texelSize*0.5*RENDER_SCALE; @@ -205,8 +206,7 @@ vec3 RT_alternate(vec3 dir, vec3 position, float noise, float stepsizes, bool ha if(nextZ < currZ && (sp <= max(minZ,maxZ) && sp >= min(minZ,maxZ))) return vec3(spos.xy/RENDER_SCALE,sp); - - minZ = maxZ-biasamount / currZ; + minZ = maxZ - biasamount / currZ; maxZ += stepv.z; spos += stepv; @@ -241,6 +241,7 @@ vec3 ApplySSRT( 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); @@ -250,16 +251,14 @@ vec3 ApplySSRT( 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, 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/1200.0, vec3(0.7)) * 2.5, minimumLightColor, lightmap) + blockLightColor; skycontribution = doIndirectLighting(skyCloudsFromTex(rayDir, colortex4).rgb/1200.0, minimumLightColor, lightmap) + blockLightColor; #else skycontribution = volumetricsFromTex(rayDir, colortex4, 6).rgb / 1200.0 + blockLightColor; @@ -273,14 +272,16 @@ vec3 ApplySSRT( radiance += skycontribution; radiance2 += skycontribution2; - if (rayHit.z < 1.0){ + if (rayHit.z < 0.9999 && distance(gl_FragCoord.xy*texelSize, rayHit.xy) > 0.001){ #if indirect_effect == SSRT_AO_GI vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; 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.y < 1.0){ - bouncedLight = texture2D(colortex5, previousPosition.xy).rgb * GI_Strength * CURVE; + bouncedLight = texelFetch2D(colortex5, ivec2(previousPosition.xy/texelSize),0).rgb * GI_Strength * CURVE; + // bouncedLight = texture2D(colortex5, previousPosition.xy).rgb * GI_Strength * CURVE; + radiance += bouncedLight; radiance2 += bouncedLight; diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl index 141215a..ed9a308 100644 --- a/shaders/lib/specular.glsl +++ b/shaders/lib/specular.glsl @@ -122,8 +122,8 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo clipPosition.xy *= RENDER_SCALE; stepv.xy *= RENDER_SCALE; - vec3 spos = clipPosition + stepv*dither; - spos += stepv*0.5 + vec3(0.5*texelSize,0.0); // small offsets to reduce artifacts from precision differences. + vec3 spos = clipPosition + stepv*(dither*0.5+0.5); + spos += vec3(0.5*texelSize,0.0); // small offsets to reduce artifacts from precision differences. #if defined DEFERRED_SPECULAR && TAA_MODE > 0 spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; @@ -131,7 +131,6 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo float minZ = spos.z - 0.00025 / linZ(spos.z); float maxZ = spos.z; - vec3 hitPos = vec3(1.1); for (int i = 0; i <= int(quality); i++) { @@ -185,7 +184,8 @@ vec4 screenSpaceReflections( #endif vec3 raytracePos = rayTraceSpeculars(reflectedVector, viewPos, noise, quality, isHand, reflectionLength); - if (raytracePos.z > 1.0) return reflection; + + if (raytracePos.z > 1.0 || distance(gl_FragCoord.xy*texelSize, raytracePos.xy) < 0.002) return reflection; // use higher LOD as the reflection goes on, to blur it. this helps denoise a little. reflectionLength = min(max(reflectionLength - 0.1, 0.0)/0.9, 1.0); @@ -205,7 +205,7 @@ vec4 screenSpaceReflections( reflection.a = 1.0; #endif - #ifdef FORWARD_RENDERED_SPECULAR + #ifdef FORWARD_SPECULAR // vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); // vec2 resScale = vec2(1920.,1080.)/clampedRes; // vec2 bloomTileUV = (((previousPosition.xy/texelSize)*2.0 + 0.5)*texelSize/2.0) / clampedRes*vec2(1920.,1080.); @@ -317,7 +317,7 @@ vec3 specularReflections( f0 = f0 == 0.0 ? 0.02 : f0; - // f0 = 0.1; + // f0 = 0.9; // roughness = 0.0; bool isMetal = f0 > 229.5/255.0; @@ -380,8 +380,10 @@ vec3 specularReflections( #endif #endif #endif + #if DEFERRED_SSR_QUALITY > 0 || FORWARD_SSR_QUALITY > 0 vec4 enviornmentReflection = screenSpaceReflections(mat3(gbufferModelView) * reflectedVector_L, viewPos, noise.z, isHand, roughness, backgroundReflectMask); + // darkening for metals. vec3 DarkenedDiffuseLighting = isMetal ? diffuseLighting * (1.0-enviornmentReflection.a) * (1.0-lightmap) : diffuseLighting; #else @@ -401,6 +403,7 @@ vec3 specularReflections( // lerp back to diffuse lighting if the reflection has not been deemed visible enough specularReflections = mix(specularReflections, diffuseLighting, reflectionVisibilty); + } #endif