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

@ -0,0 +1,28 @@
#ifndef _ENVIRONMENT_SAMPLE_GLSL_
#define _ENVIRONMENT_SAMPLE_GLSL_
// Sample diffuse ambient environment lighting (irradiance)
vec3 sampleDiffuseEnvironment(vec3 normal) {
#ifdef _Irr
vec3 envl = shIrradiance(normal, shirr);
#ifdef _EnvTex
envl /= PI;
#endif
return envl;
#else
return vec3(0.0);
#endif
}
// Sample specular environment reflection (skybox or cubemap)
vec3 sampleSpecularEnvironment(vec3 viewDir, float roughness) {
#ifdef _EnvTex
return textureLod(texEnvironment, viewDir, roughness * 8.0).rgb;
#else
return vec3(0.0);
#endif
}
#endif

View File

@ -109,8 +109,10 @@ vec2 encode_oct(vec3 v) {
vec3 decode_oct(vec2 e) {
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
if (v.z < 0) v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
return normalize(v);
if (v.z < 0.0) {
v.xy = (1.0 - abs(v.yx)) * (vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0));
}
return normalize(v);
}
uint encNor(vec3 n) {

View File

@ -7,6 +7,12 @@ float hash(const vec2 p) {
return fract(sin(h) * 43758.5453123);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
vec2 envMapEquirect(const vec3 normal) {
const float PI = 3.1415926535;
const float PI2 = PI * 2.0;
@ -27,9 +33,9 @@ vec2 rand2(const vec2 coord) {
return vec2(noiseX, noiseY);
}
float linearize(const float depth, vec2 cameraProj) {
// to viewz
return cameraProj.y / (depth - cameraProj.x);
float linearize(float depth, vec2 cameraProj) {
depth = depth * 2.0 - 1.0;
return cameraProj.y / (cameraProj.x - depth);
}
float attenuate(const float dist) {