/// <summary> /// Trnasforms the given direction from shading space into world space and normalizes it. /// Assumes the shading normal is a valid normal (i.e. normalized). /// </summary> public static Vector3 ShadingToWorld(Vector3 shadingNormal, Vector3 shadingDirection) { SanityChecks.IsNormalized(shadingDirection); ComputeBasisVectors(shadingNormal, out var tangent, out var binormal); Vector3 dir = shadingDirection.Z * shadingNormal + shadingDirection.X * tangent + shadingDirection.Y * binormal; return(dir); }
/// <summary> /// Trnasforms the given direction into normalized shading space. /// Assumes that both the direction and the shading normal are normalized. /// </summary> public static Vector3 WorldToShading(Vector3 shadingNormal, Vector3 worldDirection) { SanityChecks.IsNormalized(worldDirection); ComputeBasisVectors(shadingNormal, out var tangent, out var binormal); float z = Vector3.Dot(shadingNormal, worldDirection); float x = Vector3.Dot(tangent, worldDirection); float y = Vector3.Dot(binormal, worldDirection); return(new Vector3(x, y, z)); }