fix fog reflection lighting, tweak speculars

This commit is contained in:
Xonk 2023-06-22 14:58:16 -04:00
parent f644949ad2
commit 4d1673a54c
5 changed files with 26 additions and 23 deletions

View File

@ -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

View File

@ -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) ;

View File

@ -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,18 +288,15 @@ 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;
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
@ -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

View File

@ -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

View File

@ -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);