Skip to content

Local Coordinate Systems

Sergey Kosov edited this page Apr 2, 2025 · 6 revisions

We chose tangent and cotangent vectors based on the normal vector to form an LCS. For calculating the tangent vector we use the following function, defined in mathutils.h file:

inline Vec3f tangent(const Vec3f& v) {
return (fabs(v.dot(Vec3f(1, 0, 0))) < 0.999f)
? normalize(Vec3f(1, 0, 0).cross(v))
: normalize(Vec3f(0, 0, 1).cross(v));
}

CPrimPlane

In the constructor, we define:

m_u = tangent(normal);
m_v = normal.cross(m_u);

m_u and m_v are used in texturing getTextureCoords() and in the calculation of the derivatives of the primitive's surface over its parametrization parameters u and v dp()

CPrimDisc

In the constructor, we define one tangent vector:

m_t = tangent(normal);

It is used in texturing getTextureCoords()

CSolidDisc

in the constructor, we define:

axis1 = tangent(normal);
axis2 = normal.cross(axis1);

They are used to calculate the points lying on the circumference

CShaderOrenNayar

In the BRDF function, we create an LCS at the shading point to transform light ingoing and outgoing directions to LCS with a transformation matrix M:

// transfer to the local coordinate system
Vec3f t = tangent(n);
Vec3f s = n.cross(t);
Matx33f M (
t[0], t[1], t[2],
s[0], s[1], s[2],
n[0], n[1], n[2]
);

Clone this wiki locally