Skip to content

Commit

Permalink
Switch to Rune Stubbe's oct decode
Browse files Browse the repository at this point in the history
It's a little faster in theory; not that it matters much with RT but
would be good to only have optimal code.
  • Loading branch information
zeux committed Dec 29, 2024
1 parent c3e2c46 commit 03174e5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/shaders/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ vec2 encodeOct(vec3 v)

vec3 decodeOct(vec2 e)
{
// https://x.com/Stubbesaurus/status/937994790553227264
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
vec2 s = vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);
v.xy = v.z < 0 ? (1.0 - abs(v.yx)) * s : v.xy;
float t = max(-v.z, 0);
v.xy += vec2(v.x >= 0 ? -t : t, v.y >= 0 ? -t : t);
return normalize(v);
}

Expand Down

0 comments on commit 03174e5

Please sign in to comment.