4 ms·
struct aabb { float x_minmax[2]; float y_minmax[2]; float z_minmax[2]; }; Why not just do struct aabb { float mins[3]; float maxs[3]; };
by throwaway2027 9mo ago
struct aabb {
float x_minmax[2];
float y_minmax[2];
float z_minmax[2];
};
Why not just do
struct aabb {
float mins[3];
float maxs[3];
};
- pkaler 9mo agoSIMD and data locality. You probably want to check across three vectors simultaneously and load the coordinates next to each other. I'm guessing here. I haven't written video games in 20 years but struct packing/alignment was super important on the Sony PSP back then.
- shihab 9mo agoFor SIMD at least, the {mins[3], maxs[3]} representation aligns more naturally with actual instructions on x86. To compute a new bounding box: new_box.mins = _mm_min_ps(a.mins[3], b.mins[3]);
- delta_p_delta_x 9mo agoIndeed. This is classic array-of-structs versus struct-of-arrays.
- astrange 9mo agoYou would want [4] not [3], with the last one being padding. Of course, you can't always afford that.
- nice_byte 9mo ago(author here) Both would work - doesn't fundamentally change the underlying idea. This particular representation is lifted from raytracing in one weekend and emphasizes the fact that we're really thinking of aabb as an intersection of three "slabs" of space. for me, it makes the ray intersection bit somewhat easier to explain.