make mask for leaves so ambient SSS can look good everywhere else

This commit is contained in:
Xonk
2023-06-24 18:30:46 -04:00
parent 4345e0560e
commit c46ac275df
12 changed files with 193 additions and 57 deletions

View File

@ -299,6 +299,7 @@ const float shadowDistanceRenderMul = -1.0; //[-1.0 1.0] THIS WILL BREAK SUBSURF
#define SSR_STEPS 30 //[10 15 20 25 30 35 40 50 100 200 400]
#define SUN_MICROFACET_SPECULAR // If enabled will use realistic rough microfacet model, else will just reflect the sun. No performance impact.
#define USE_QUARTER_RES_DEPTH // Uses a quarter resolution depth buffer to raymarch screen space reflections, improves performance but may introduce artifacts
#define Dynamic_SSR_quality // rougher reflections have lower quality. this improves performance a bit in alot of scenes
#ifdef Specular_Reflections
#define Puddles // yes

View File

@ -134,7 +134,7 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool
spos += stepv;
//small bias
float biasamount = (0.0002 + 0.0015*depthcancleoffset ) / dist;
float biasamount = (0.0002 + 0.0015*pow(depthcancleoffset,5) ) / dist;
// float biasamount = 0.0002 / dist;
if(hand) biasamount = 0.01;
minZ = maxZ-biasamount / ld(spos.z);
@ -147,10 +147,29 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool
return vec3(1.1);
}
// vec3 sampleGGXVNDF(vec3 V_, float roughness, float U1, float U2){
// // stretch view
// vec3 V = normalize(vec3(roughness * V_.x, roughness * V_.y, V_.z));
// // orthonormal basis
// vec3 T1 = (V.z < 0.9999) ? normalize(cross(V, vec3(0,0,1))) : vec3(1,0,0);
// vec3 T2 = cross(T1, V);
// // sample point with polar coordinates (r, phi)
// float a = 1.0 / (1.0 + V.z);
// float r = sqrt(U1*0.25);
// float phi = (U2<a) ? U2/a * 3.141592653589793 : 3.141592653589793 + (U2-a)/(1.0-a) * 3.141592653589793;
// float P1 = r*cos(phi);
// float P2 = r*sin(phi)*((U2<a) ? 1.0 : V.z);
// // compute normal
// vec3 N = P1*T1 + P2*T2 + sqrt(max(0.0, 1.0 - P1*P1 - P2*P2))*V;
// // unstretch
// N = normalize(vec3(roughness*N.x, roughness*N.y, N.z));
// return N;
// }
float xonk_fma(float a,float b,float c){
return a * b + c;
}
//// thank you Zombye | the paper: https://ggx-research.github.io/publication/2023/06/09/publication-ggx.html
vec3 SampleVNDFGGX(
vec3 viewerDirection, // Direction pointing towards the viewer, oriented such that +Z corresponds to the surface normal
@ -178,28 +197,9 @@ vec3 SampleVNDFGGX(
return normalize(vec3(alpha * halfway.xy, halfway.z));
}
vec3 sampleGGXVNDF(vec3 V_, float roughness, float U1, float U2){
// stretch view
vec3 V = normalize(vec3(roughness * V_.x, roughness * V_.y, V_.z));
// orthonormal basis
vec3 T1 = (V.z < 0.9999) ? normalize(cross(V, vec3(0,0,1))) : vec3(1,0,0);
vec3 T2 = cross(T1, V);
// sample point with polar coordinates (r, phi)
float a = 1.0 / (1.0 + V.z);
float r = sqrt(U1*0.25);
float phi = (U2<a) ? U2/a * 3.141592653589793 : 3.141592653589793 + (U2-a)/(1.0-a) * 3.141592653589793;
float P1 = r*cos(phi);
float P2 = r*sin(phi)*((U2<a) ? 1.0 : V.z);
// compute normal
vec3 N = P1*T1 + P2*T2 + sqrt(max(0.0, 1.0 - P1*P1 - P2*P2))*V;
// unstretch
N = normalize(vec3(roughness*N.x, roughness*N.y, N.z));
return N;
}
vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
r = pow(r,2.5);
// r*=r;
vec3 GGX(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
r = max(pow(r,2.5), 0.0001);
vec3 h = l + v;
float hn = inversesqrt(dot(h, h));
@ -255,7 +255,6 @@ void MaterialReflections(
#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));
@ -286,8 +285,15 @@ void MaterialReflections(
#ifdef Screen_Space_Reflections
float rayQuality = mix_float(reflection_quality,6.0,rayContribLuma); // Scale quality with ray contribution
if(hand) {rayQuality = max(rayQuality,30.0); noise.b = 0.5 + (noise.b-0.5);}
#ifndef Dynamic_SSR_quality
rayQuality = reflection_quality;
#endif
noise.b = mix_float(noise.b, 0.5 + (noise.b-0.5),rayContribLuma);
if(hand) {rayQuality = max(rayQuality,30.0); noise.b = 0.5 + (noise.b-0.5);}
vec3 rtPos = rayTraceSpeculars(mat3(gbufferModelView) * L, fragpos.xyz, noise.b, rayQuality, hand, reflectLength);
float LOD = clamp(reflectLength * 6.0, 0.0,6.0);
@ -306,6 +312,8 @@ void MaterialReflections(
}
// check if the f0 is within the metal ranges, then tint by albedo if it's true.
// // the brightening is disgusting
// vec3 Metals = f0.y > 229.5/255.0 ? clamp((albedo / max(pow(luma(albedo),0.1),0.4)) + fresnel,0.0,1.0) : vec3(1.0);
vec3 Metals = f0.y > 229.5/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0);
SunReflection *= Metals;

View File

@ -386,7 +386,7 @@ float GetCloudShadow_VLFOG(vec3 WorldPos, vec3 WorldSpace_sunVec){
// 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 + WorldSpace_sunVec/abs(WorldSpace_sunVec.y) * max((MaxCumulusHeight - 60) - WorldPos.y,0.0) ;
shadow += GetCumulusDensity(lowShadowStart,0)*Cumulus_density;
shadow += max(GetCumulusDensity(lowShadowStart,0) - 0.2,0.0)*Cumulus_density;
#endif
#ifdef Altostratus