//////////////////////////////////////////////////////////// //~ Gpu math constants #define Pi ((f32)3.14159265358979323846) #define Tau ((f32)6.28318530717958647693) #define GoldenRatio ((f32)1.61803398874989484820) //////////////////////////////////////////////////////////// //~ Gpu math types typedef float2 Vec2; typedef float3 Vec3; typedef float4 Vec4; typedef int2 Vec2I32; typedef int3 Vec3I32; typedef int4 Vec4I32; typedef uint2 Vec2U32; typedef uint3 Vec3U32; typedef uint4 Vec4U32; typedef uint2 PackedVec4; typedef float2x3 Xform; typedef float4 Rect; typedef float4 ClipRect; typedef float4 Aabb; typedef float4 Quad; typedef float4x4 Mat4x4; //////////////////////////////////////////////////////////// //~ Color helpers Vec4 Vec4FromU32(u32 v) { Vec4 result; result.r = ((v >> 0) & 0xFF) / 255.0; result.g = ((v >> 8) & 0xFF) / 255.0; result.b = ((v >> 16) & 0xFF) / 255.0; result.a = ((v >> 24) & 0xFF) / 255.0; return result; } //////////////////////////////////////////////////////////// //~ Vertex ID helpers Vec2 RectUvFromVertexId(u32 id) { static const Vec2 uvs[4] = { Vec2(0, 0), Vec2(1, 0), Vec2(1, 1), Vec2(0, 1) }; return uvs[id]; } //////////////////////////////////////////////////////////// //~ Ndc helpers Vec2 NdcFromViewport(Vec2 viewport_size, Vec2 viewport_coords) { Vec2 result; result = viewport_coords / viewport_size; result *= Vec2(2, -2); result += Vec2(-1, 1); return result; }