gameknife / gkNextRenderer

A Modern gkRenderer
15 stars 2 forks source link

what vec3 AlignWithNormal(vec3 ray, vec3 normal) do? #3

Closed tigrazone closed 2 weeks ago

tigrazone commented 2 weeks ago

It look like ONB isnt it?

void Onb(in vec3 N, inout vec3 T, inout vec3 B)
{
    vec3 up = abs(N.z) < 0.9999999 ? vec3(0, 0, 1) : vec3(1, 0, 0);
    T = normalize(cross(up, N));
    B = cross(N, T);
}

or newer https://graphics.pixar.com/library/OrthonormalB/paper.pdf

void branchless_onb(vec3 n, out vec3 b1, out vec3 b2) {
    float sign = n.z > 0.f ? 1.f : -1.f;
    float a = -1.f / (sign + n.z);
    b2 = vec3(n.x * n.y * a, sign + n.y * n.y * a, -n.y);
    b1 = vec3(1.f + sign * n.x * n.x * a, sign * b2.x, -sign * n.x);
}
gameknife commented 2 weeks ago

it is ONB, copy from Metal3 PathTracing code, performance friendly