|
|
|
|
|
|
return normalize(n); |
|
|
|
} |
|
|
|
|
|
|
|
float2 PackNormalHemiOctEncode(float3 n) |
|
|
|
{ |
|
|
|
float l1norm = dot(abs(n), 1.0); |
|
|
|
float2 res = n.xy * (1.0 / l1norm); |
|
|
|
|
|
|
|
return float2(res.x + res.y, res.x - res.y); |
|
|
|
} |
|
|
|
|
|
|
|
float3 UnpackNormalHemiOctEncode(float2 f) |
|
|
|
{ |
|
|
|
float2 val = float2(f.x + f.y, f.x - f.y) * 0.5; |
|
|
|
float3 n = float3(val, 1.0 - dot(abs(val), 1.0)); |
|
|
|
|
|
|
|
return normalize(n); |
|
|
|
} |
|
|
|
|
|
|
|
// Tetrahedral encoding - Looks like Tetra encoding 10:10 + 2 is similar to oct 11:11, as oct is cheaper prefer it |
|
|
|
// To generate the basisNormal below we use these 4 vertex of a regular tetrahedron |
|
|
|
// v0 = float3(1.0, 0.0, -1.0 / sqrt(2.0)); |
|
|
|