fix normal encoding for denoised rough reflections

This commit is contained in:
Merlin1809
2026-08-08 10:48:13 +02:00
parent 90505ccae5
commit b6e3c64405
4 changed files with 13 additions and 7 deletions
+8 -4
View File
@@ -871,8 +871,8 @@ uniform float wetness;
vec2 driprate = vec2(0.0,frameTimeCounter)*0.05;
vec2 UV = mix(worldPos.xz, worldPos.xy*vec2(2.0, 0.5)+driprate, abs(flatNormals.z));
UV = mix(UV, worldPos.zy*vec2(2.0, 0.5)+driprate, abs(flatNormals.x));
vec2 UV = mix(worldPos.xz, worldPos.xy*vec2(2.0, 0.5)+driprate, pow(abs(flatNormals.z),2));
UV = mix(UV, worldPos.zy*vec2(2.0, 0.5)+driprate, pow(abs(flatNormals.x),2));
#ifdef SHADER_GRASS
if(isShaderGrass) UV = worldPos.xz;
@@ -984,10 +984,14 @@ float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
vec2 signNotZero(vec2 v) {
return step(vec2(0.0), v) * 2.0 - 1.0;
}
vec2 encodeNormal(vec3 n){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0);
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * signNotZero(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,0.0,1.0);
return encn;
}
+3 -1
View File
@@ -490,7 +490,7 @@ void main() {
vec2 lightmap = dataUnpacked1.yz;
vec4 stuff = texelFetch(colortex8, ivec2(gl_FragCoord.xy), 0);
vec3 normal = decode(stuff.xy);
vec3 normal = normalize(decode(stuff.xy));
vec2 speculars = stuff.zw;
float roughness = speculars.r;
@@ -505,6 +505,8 @@ void main() {
// get reflected vector
mat3 basis = CoordBase(normal);
vec3 viewDir = -NplayerPos*basis;
viewDir.z = abs(viewDir.z);
float VdotN = dot(-normalize(viewDir), vec3(0.0,0.0,1.0));
float shlickFresnel = shlickFresnelRoughness(VdotN, roughness);