This commit is contained in:
CodingJellyfish 2024-01-18 01:13:23 +08:00 committed by GitHub
parent 6573ebe09e
commit ec8362915d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 8 deletions

View File

@ -1,7 +1,9 @@
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
n = n * 2.0 - 1.0;
vec3 ret = vec3(n.x, n.y, 1.0 - abs(n.x) - abs(n.y));
float t = max(-ret.z, 0.0);
ret.x += ret.x >= 0.0 ? -t : t;
ret.y += ret.y >= 0.0 ? -t : t;
return normalize(ret);
}

View File

@ -1,5 +1,17 @@
// from Crytek "a bit more deferred CryEngine"
// Octahedron Normal Vector
vec2 OctWrap(vec2 v)
{
vec2 w = 1.0 - abs( v.yx );
if (v.x < 0.0) w.x = -w.x;
if (v.y < 0.0) w.y = -w.y;
return w;
}
vec2 EncodeNormal(vec3 n)
{
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
}
n /= (abs(n.x) + abs(n.y) + abs(n.z));
n.xy = n.z >= 0.0 ? n.xy : OctWrap(n.xy);
n.xy = n.xy * 0.5 + 0.5;
return n.xy;
}