MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ShaderCompat.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glm/glm.hpp>
4
5#include <cstdint>
6
7/**
8 * @file ShaderCompat.hpp
9 * @brief GLSL type and function spellings made valid as C++.
10 *
11 * A dual-source field body is authored once and compiled twice: by the host
12 * compiler into a callable, and by shaderc into SPIR-V. GLSL has no namespace
13 * qualification, so the body must be written unqualified, and this header makes
14 * unqualified lookup succeed on the host side.
15 *
16 * Nothing is reimplemented. glm already mirrors the GLSL function set. Vector
17 * arguments would resolve through ADL without any declaration here, since a
18 * glm::vec3 argument brings namespace glm into the lookup set. Scalar arguments
19 * would not: a float has no associated namespace. The declarations below are
20 * therefore load-bearing for expressions such as clamp(d, 0.0f, 1.0f) and
21 * max(d * d, 0.1f), and the type aliases are load-bearing because vec3 and uint
22 * have no glm spelling that is also GLSL.
23 *
24 * Authoring rules for any body that must survive both compilers:
25 *
26 * 1. Do not author inside namespace MayaFlux::Kinesis or any namespace nested
27 * within it. A using-directive injects these names into the nearest
28 * namespace enclosing both, which is MayaFlux, so Kinesis::clamp and
29 * Kinesis::smoothstep hide the glm overloads rather than competing with
30 * them and the call fails to resolve. Author in MayaFlux::Fields or
31 * another namespace outside Kinesis; the resulting .cpu halves compose
32 * with the Kinesis factories through qualification as normal.
33 * 2. Every decimal literal carries an f suffix. GLSL reads 0.1 as float; C++
34 * reads it as double, and glm's scalar overloads are templates that fail
35 * deduction on mixed types. GLSL 4.60 accepts the suffix, so 0.1f is valid
36 * in both.
37 * 3. No // comments. Stringification collapses the body to one line and a
38 * line comment would swallow the remainder.
39 * 4. No std::, no captures, no references, no if constexpr, no templates.
40 * 5. No swizzles. GLM_FORCE_SWIZZLE yields proxy types rather than vectors.
41 *
42 * Opening this namespace alongside `using namespace std` produces ambiguity on
43 * max, min and abs. Keep the directive scoped to the namespace where fields are
44 * authored.
45 *
46 * Verified against glslangValidator -S comp and g++ -std=c++20 for radial
47 * attraction, cross-product swirl, sphere distance, smoothstep falloff, a
48 * four-iteration accumulation loop, and a ternary-guarded normalisation.
49 */
51
52using vec2 = glm::vec2;
53using vec3 = glm::vec3;
54using vec4 = glm::vec4;
55using ivec2 = glm::ivec2;
56using ivec3 = glm::ivec3;
57using uvec3 = glm::uvec3;
58using mat3 = glm::mat3;
59using mat4 = glm::mat4;
60using uint = std::uint32_t;
61
62using glm::abs;
63using glm::ceil;
64using glm::clamp;
65using glm::floor;
66using glm::fract;
67using glm::max;
68using glm::min;
69using glm::mix;
70using glm::mod;
71using glm::sign;
72using glm::smoothstep;
73using glm::step;
74
75using glm::exp;
76using glm::exp2;
77using glm::inversesqrt;
78using glm::log;
79using glm::log2;
80using glm::pow;
81using glm::sqrt;
82
83using glm::acos;
84using glm::asin;
85using glm::atan;
86using glm::cos;
87using glm::sin;
88using glm::tan;
89
90using glm::cross;
91using glm::distance;
92using glm::dot;
93using glm::faceforward;
94using glm::length;
95using glm::normalize;
96using glm::reflect;
97using glm::refract;
98
99} // namespace MayaFlux::ShaderCompat