From 4d1673a54cfba3eefebd7eee5f31eef5cc58d9ce Mon Sep 17 00:00:00 2001 From: Xonk Date: Thu, 22 Jun 2023 14:58:16 -0400 Subject: [PATCH] fix fog reflection lighting, tweak speculars --- shaders/composite1.fsh | 2 +- shaders/deferred.fsh | 3 +++ shaders/lib/specular.glsl | 31 +++++++++++++++---------------- shaders/lib/volumetricClouds.glsl | 6 +++--- shaders/lib/volumetricFog.glsl | 7 ++++--- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/shaders/composite1.fsh b/shaders/composite1.fsh index 57563e7..11998b1 100644 --- a/shaders/composite1.fsh +++ b/shaders/composite1.fsh @@ -287,7 +287,7 @@ void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estE } #ifdef VL_CLOUDS_SHADOWS - sh *= GetCloudShadow_VLFOG(progressW); + sh *= GetCloudShadow_VLFOG(progressW,WsunVec); #endif diff --git a/shaders/deferred.fsh b/shaders/deferred.fsh index ff0d078..2647f7d 100644 --- a/shaders/deferred.fsh +++ b/shaders/deferred.fsh @@ -180,7 +180,9 @@ if (gl_FragCoord.x > 18. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257){ vec2 planetSphere = vec2(0.0); vec3 sky = vec3(0.0); vec3 skyAbsorb = vec3(0.0); + vec3 WsunVec = mat3(gbufferModelViewInverse)*sunVec; + sky = calculateAtmosphere(avgSky*4000./2.0, viewVector, vec3(0.0,1.0,0.0), WsunVec, -WsunVec, planetSphere, skyAbsorb, 10, blueNoise()); #ifdef AEROCHROME_MODE @@ -197,6 +199,7 @@ if (gl_FragCoord.x > 18.+257. && gl_FragCoord.y > 1. && gl_FragCoord.x < 18+257+ vec2 p = clamp(floor(gl_FragCoord.xy-vec2(18.+257,1.))/256.+tempOffsets/256.,0.0,1.0); vec3 viewVector = cartToSphere(p); + vec3 WsunVec = mat3(gbufferModelViewInverse)*sunVec; vec3 skytex = texelFetch2D(colortex4,ivec2(gl_FragCoord.xy)-ivec2(257,0),0).rgb/150.; if(viewVector.y < -0.025) skytex = skytex * clamp( exp(viewVector.y) - 1.0,0.25,1.0) ; diff --git a/shaders/lib/specular.glsl b/shaders/lib/specular.glsl index 37c95e5..a4d3a0a 100644 --- a/shaders/lib/specular.glsl +++ b/shaders/lib/specular.glsl @@ -121,8 +121,7 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool float maxZ = spos.z; spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE; - float depthcancle = pow(1.0-(quality/reflection_quality),5); - + float depthcancleoffset = pow(1.0-(quality/reflection_quality),1); float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases for (int i = 0; i <= int(quality); i++) { @@ -135,7 +134,8 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool spos += stepv; //small bias - float biasamount = max(0.0002, depthcancle*0.0035) / dist; + float biasamount = (0.0002 + 0.0015*depthcancleoffset ) / dist; + // float biasamount = 0.0002 / dist; if(hand) biasamount = 0.01; minZ = maxZ-biasamount / ld(spos.z); maxZ += stepv.z; @@ -157,19 +157,21 @@ vec3 SampleVNDFGGX( vec2 alpha, // Roughness parameter along X and Y of the distribution vec2 xy // Pair of uniformly distributed numbers in [0, 1) ) { + // alpha *= alpha; // Transform viewer direction to the hemisphere configuration viewerDirection = normalize(vec3(alpha * viewerDirection.xy, viewerDirection.z)); // Sample a reflection direction off the hemisphere const float tau = 6.2831853; // 2 * pi float phi = tau * xy.x; - float cosTheta = xonk_fma(1.0 - xy.y, 1.0 + viewerDirection.z, -viewerDirection.z); - float sinTheta = sqrt(clamp(1.0 - cosTheta * cosTheta, 0.0, 1.0)*0.25); + float cosTheta = xonk_fma(1.0 - xy.y, 1.0 + viewerDirection.z, -viewerDirection.z) ; + float sinTheta = sqrt(clamp(1.0 - cosTheta * cosTheta, 0.0, 1.0)); vec3 reflected = vec3(vec2(cos(phi), sin(phi)) * sinTheta, cosTheta); // Evaluate halfway direction // This gives the normal on the hemisphere - vec3 halfway = reflected + viewerDirection; + // xonk note, i added those magic numbers huhuhuh + vec3 halfway = reflected*0.5 + viewerDirection*1.5; // Transform the halfway direction back to hemiellispoid configuation // This gives the final sampled normal @@ -286,20 +288,17 @@ void MaterialReflections( #endif #ifdef Screen_Space_Reflections - // #ifdef SCREENSHOT_MODEFconst - // float rayQuality = reflection_quality; - // #else - float rayQuality = mix_float(reflection_quality,6.0,luma(rayContrib)); // Scale quality with ray contribution - // #endif - // float rayQuality = reflection_quality; + + float rayQuality = mix_float(reflection_quality,6.0,luma(rayContrib)); // Scale quality with ray contribution + vec3 rtPos = rayTraceSpeculars(mat3(gbufferModelView) * L, fragpos.xyz, noise.b, rayQuality, hand, reflectLength); float LOD = clamp(reflectLength * 6.0, 0.0,6.0); - + // LOD = 0.0; if(hand || isEntities) LOD = 6.0; - + if (rtPos.z < 1.) { // Reproject on previous frame vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition; previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz; @@ -369,7 +368,7 @@ void MaterialReflections_N( #ifdef Rough_reflections int seed = (frameCounter%40000); vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ; - vec3 H = sampleGGXVNDF(normSpaceView, roughness, ij.x, ij.y); + vec3 H = SampleVNDFGGX(normSpaceView, vec2(roughness), ij.xy); if(hand) H = normalize(vec3(0.0,0.0,1.0)); #else @@ -472,7 +471,7 @@ void MaterialReflections_E( #ifdef Rough_reflections int seed = (frameCounter%40000); vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ; - vec3 H = sampleGGXVNDF(normSpaceView, roughness, ij.x, ij.y); + vec3 H = SampleVNDFGGX(normSpaceView, vec2(roughness), ij.xy); if(hand) H = normalize(vec3(0.0,0.0,1.0)); #else diff --git a/shaders/lib/volumetricClouds.glsl b/shaders/lib/volumetricClouds.glsl index 81a0d38..619b5c1 100644 --- a/shaders/lib/volumetricClouds.glsl +++ b/shaders/lib/volumetricClouds.glsl @@ -374,18 +374,18 @@ float GetCloudShadow(vec3 eyePlayerPos){ return shadow; } -float GetCloudShadow_VLFOG(vec3 WorldPos){ +float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){ float shadow = 0.0; // assume a flat layer of cloud, and stretch the sampled density along the sunvector, starting from some vertical layer in the cloud. #ifdef Cumulus - vec3 lowShadowStart = WorldPos + WsunVec/abs(WsunVec.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ; + vec3 lowShadowStart = WorldPos + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ; shadow += GetCumulusDensity(lowShadowStart,0)*Cumulus_density; #endif #ifdef Altostratus - vec3 highShadowStart = WorldPos + WsunVec/abs(WsunVec.y) * max(AltostratusHeight - WorldPos.y,0.0); + vec3 highShadowStart = WorldPos + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max(AltostratusHeight - WorldPos.y,0.0); shadow += GetAltostratusDensity(highShadowStart); #endif diff --git a/shaders/lib/volumetricFog.glsl b/shaders/lib/volumetricFog.glsl index c71cec5..4f99f08 100644 --- a/shaders/lib/volumetricFog.glsl +++ b/shaders/lib/volumetricFog.glsl @@ -3,6 +3,7 @@ float phaseRayleigh(float cosTheta) { return cosTheta * mul_add.x + mul_add.y; // optimized version from [Elek09], divided by 4 pi for energy conservation } +uniform float noPuddleAreas; float densityAtPosFog(in vec3 pos){ pos /= 18.; pos.xz *= 0.5; @@ -15,7 +16,6 @@ float densityAtPosFog(in vec3 pos){ return mix(xy.r,xy.g, f.y); } -uniform float noPuddleAreas; float cloudVol(in vec3 pos){ @@ -118,7 +118,7 @@ vec4 getVolumetricRays( } #ifdef VL_CLOUDS_SHADOWS - sh *= GetCloudShadow_VLFOG(progressW); + sh *= GetCloudShadow_VLFOG(progressW,WsunVec); #endif //Water droplets(fog) @@ -141,6 +141,7 @@ vec4 getVolumetricRays( vec3 vL0 = (DirectLight + AmbientLight + AtmosphericFog + rainRays ) * max(eyeBrightnessSmooth.y,0)/240. ; + vL += (vL0 - vL0 * exp(-(rL+m)*dd*dL)) / ((rL+m)+0.00000001)*absorbance; absorbance *= dot(clamp(exp(-(rL+m)*dd*dL),0.0,1.0), vec3(0.333333)); } @@ -258,7 +259,7 @@ vec4 InsideACloudFog( Shadows_for_Fog = sh; #ifdef VL_CLOUDS_SHADOWS - Shadows_for_Fog = sh * GetCloudShadow_VLFOG(progressW); + Shadows_for_Fog = sh * GetCloudShadow_VLFOG(progressW,WsunVec); #endif float densityVol = cloudVol(progressW);