Math fixes, SSR enhancements, improved precision and image sharpness, moved envmap into its own shader to improve SSR realism. Various improvements.

This commit is contained in:
TriVoxel
2025-04-28 06:12:27 -06:00
parent ddc3a071f4
commit 0cdb90bdb8
5 changed files with 247 additions and 93 deletions

View File

@ -2,12 +2,10 @@
#include "compiled.inc"
#include "std/gbuffer.glsl"
#ifdef _Clusters
#include "std/clusters.glsl"
#endif
#ifdef _Irr
#include "std/shirr.glsl"
#endif
#ifdef _SSS
#include "std/sss.glsl"
#endif
@ -15,6 +13,15 @@
#include "std/ssrs.glsl"
#endif
// Environment map
uniform float envmapStrength;
#ifdef _Irr
uniform vec4 shirr[7];
uniform float ambientIntensity;
#include "std/shirr.glsl"
#endif
#include "std/environment_sample.glsl"
uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
@ -39,10 +46,6 @@ uniform sampler3D voxelsSDF;
uniform float clipmaps[10 * voxelgiClipmapCount];
#endif
uniform float envmapStrength;
#ifdef _Irr
uniform vec4 shirr[7];
#endif
#ifdef _Brdf
uniform sampler2D senvmapBrdf;
#endif
@ -217,6 +220,7 @@ void main() {
vec2 occspec = unpackFloat2(g1.a);
vec3 albedo = surfaceAlbedo(g1.rgb, metallic); // g1.rgb - basecolor
vec3 f0 = surfaceF0(g1.rgb, metallic);
vec3 envl = vec3(0.0);
float depth = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0;
vec3 p = getPos(eye, eyeLook, normalize(viewRay), depth, cameraProj);
@ -235,24 +239,23 @@ void main() {
vec2 envBRDF = texelFetch(senvmapBrdf, ivec2(vec2(dotNV, 1.0 - roughness) * 256.0), 0).xy;
#endif
// Envmap
#ifdef _Irr
// Sample ambient diffuse lighting
vec3 ambient = sampleDiffuseEnvironment(n);
vec3 envl = shIrradiance(n, shirr);
#ifdef _gbuffer2
if (g2.b >= 0.5) {
ambient = vec3(0.0); // Mask it if g2 says this surface wants no ambient lighting
}
#endif
#ifdef _gbuffer2
if (g2.b < 0.5) {
envl = envl;
} else {
envl = vec3(0.0);
}
#endif
fragColor.rgb += ambient * ambientIntensity;
#endif
#ifdef _EnvTex
envl /= PI;
#endif
#else
vec3 envl = vec3(0.0);
#ifndef _SSR
// Only apply specular environment lighting if SSR is NOT active
vec3 envSpecular = sampleSpecularEnvironment(reflect(viewDir, normal), roughness);
finalColor.rgb += envSpecular * environmentIntensity;
#endif
#ifdef _Rad