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

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