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
*/
50
namespace
MayaFlux::ShaderCompat
{
51
52
using
vec2
= glm::vec2;
53
using
vec3
= glm::vec3;
54
using
vec4
= glm::vec4;
55
using
ivec2
= glm::ivec2;
56
using
ivec3
= glm::ivec3;
57
using
uvec3
= glm::uvec3;
58
using
mat3
= glm::mat3;
59
using
mat4
= glm::mat4;
60
using
uint
= std::uint32_t;
61
62
using
glm::abs;
63
using
glm::ceil;
64
using
glm::clamp;
65
using
glm::floor;
66
using
glm::fract;
67
using
glm::max;
68
using
glm::min;
69
using
glm::mix;
70
using
glm::mod;
71
using
glm::sign;
72
using
glm::smoothstep;
73
using
glm::step;
74
75
using
glm::exp;
76
using
glm::exp2;
77
using
glm::inversesqrt;
78
using
glm::log;
79
using
glm::log2;
80
using
glm::pow;
81
using
glm::sqrt;
82
83
using
glm::acos;
84
using
glm::asin;
85
using
glm::atan;
86
using
glm::cos;
87
using
glm::sin;
88
using
glm::tan;
89
90
using
glm::cross;
91
using
glm::distance;
92
using
glm::dot;
93
using
glm::faceforward;
94
using
glm::length;
95
using
glm::normalize;
96
using
glm::reflect;
97
using
glm::refract;
98
99
}
// namespace MayaFlux::ShaderCompat
MayaFlux::ShaderCompat::vec4
glm::vec4 vec4
Definition
ShaderCompat.hpp:54
MayaFlux::ShaderCompat::vec3
glm::vec3 vec3
Definition
ShaderCompat.hpp:53
MayaFlux::ShaderCompat::mat3
glm::mat3 mat3
Definition
ShaderCompat.hpp:58
MayaFlux::ShaderCompat::uint
std::uint32_t uint
Definition
ShaderCompat.hpp:60
MayaFlux::ShaderCompat::ivec3
glm::ivec3 ivec3
Definition
ShaderCompat.hpp:56
MayaFlux::ShaderCompat::uvec3
glm::uvec3 uvec3
Definition
ShaderCompat.hpp:57
MayaFlux::ShaderCompat::ivec2
glm::ivec2 ivec2
Definition
ShaderCompat.hpp:55
MayaFlux::ShaderCompat::vec2
glm::vec2 vec2
Definition
ShaderCompat.hpp:52
MayaFlux::ShaderCompat::mat4
glm::mat4 mat4
Definition
ShaderCompat.hpp:59
MayaFlux::ShaderCompat
Definition
ShaderCompat.hpp:50
src
MayaFlux
Kinesis
Tendency
ShaderCompat.hpp
Generated by
1.9.8