Skip to content

cf_m4_normal_matrix

Category: math
GitHub: cute_math3d.h


Returns the matrix for transforming normals: the inverse-transpose of model.

CF_M4x4 cf_m4_normal_matrix(CF_M4x4 model) { return cf_m4_transpose(cf_m4_invert(model)); }
Parameters Description
model The model (or model-view) matrix.

Remarks

Normals must not be transformed by the model matrix directly when it contains non-uniform scale -- doing so leaves them non-perpendicular to the surface. The translation column is irrelevant to normals and is left as-is; upload the result as a mat4 and use its upper 3x3 in the shader. Metal only supports mat4 inside a uniform block, so a mat3 normal matrix cannot be uploaded directly.

CF_M4x4
cf_m4_invert
cf_m4_transpose
cf_m4_transform_dir