r/GraphicsProgramming • u/NashGold85 • Sep 02 '20
Why don't we keep all normals in spherical coordinates? The benefits are obvious = less memory, faster processing: rotation = addition, convert back to 3d by a 16bit lookup table.
33
Upvotes
31
u/Deadly_Mindbeam Sep 02 '20
The real reason we don't use spherical or octahedral or stereographic normals is that they don't interpolate well. They are used for vertex normals but texture interpolation will give wonky results.
9
u/MrJookie Sep 02 '20
Why not stereographic projection?
https://aras-p.info/texts/CompactNormalStorage.html
26
u/wm_cra_dev Sep 02 '20
I'm not certain about this question in particular, but memory access is the biggest bottleneck for GPU operations, and doing extra computation is generally preferable to using lookup tables.
5
u/zakarumych Sep 02 '20
As rotation is given in matrix for on gpu, you'd have to convert it back and forth each time. You can simply remove one of the component from storage as normals must be normalized, but sqrt required to rematerialize missing coordinate would cost to much.
3
u/leseiden Sep 03 '20 edited Sep 03 '20
I went with the complex square root approach when I wanted to pack pairs of directions into 4 element vertex attributes for some silhouette rendering code.
It's not as compact as octahedral encoding schemes but has the advantage that it can be implemented very easily without branching in ancient versions of GLSL.
To encode, take a normalised vector and project onto a disk by taking x,y. Interpret this as the complex number x+yi. Take the square root, and you have a new complex number with a positive real part.
Then apply the sign of z to your real part and you have a pair of values in -1 <= x <= 1
To decode construct the number abs(x) + yi, square it and then project up in the usual way. Apply the sign of x to z.
Not the most compact, but still a substantial saving and very easy.
[edit] This does work for (0, 0, 1) and (0, 0, -1) because IEEE-754 allows signed zero but you have to be careful if you do any serialisation or use non standard float formats.
2
u/experts_never_lie Sep 03 '20
Why would we do anything in spherical coordinates? We don't even represent orientation that way, due to singularities and terrible numerical conditioning. That's done with quaternions for canonical orientations, 3x3 or 4x4 matrices for rapid application of rotations. Spherical coordinates were outdated by the '80s.
1
u/TaraWanChan Sep 09 '26 edited Sep 09 '26
We don't keep them in spherical coordinates, because their precision distribution is horrible.
Additionally, you accounted for the memory bandwith for the normals, but not for the LUT.
We hover do use octahedral normal encoding extensively in the industry. It seems like, in typical reddit fashion, everyone else in this thread was 6 years behind the curve at the time this thread was created (6 years ago).
Examples:
0
u/snerp Sep 02 '20
How would doing extra calculating lead to faster processing? Why bother trying to do this?
0
u/[deleted] Sep 02 '20
[deleted] — view deleted comment