# Layout of octahedral depth values from GetAdditionalBakedProbes()?

It came to my attention that Unity’s lightmapper returns octahedral depth values, 64 per probe. What would be the layout of those values? I’m currently researching them, but can’t figure out how to properly parse them. The documentation for the method doesn’t specify anything of the sorts. Thanks.

I believe it’s based on this paper https://jcgt.org/published/0003/02/01/, the ‘oct’ encoding.

Listing 1 in the paper:

// Returns ±1
vec2 signNotZero(vec2 v) {
return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);
}

// Assume normalized input. Output is on [-1, 1] for each component.
vec2 float32x3_to_oct(in vec3 v) {
// Project the sphere onto the octahedron, and then onto the xy plane
vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));
// Reflect the folds of the lower hemisphere over the diagonals
return (v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p;
}

This function takes a unit vector gives you a [-1; 1] set of 2D coordinate. To get the index into those 64 per-probe values for a unit normal, do this:

• Call the the function with your normal to get coordinates in [-1;1]
• Map those coordinates to [0; 7] (since we have 8x8 values per probe)
• To calculate the index, do index = y * 8 + x with the mapped coordinates

Keep in mind that API in the Experimental namespace isn’t officially supported. There are some known issues with the way this data is calculated, which we plan to address at some point in the future. So use at your own volition.

1 Like