-
-
Notifications
You must be signed in to change notification settings - Fork 10
Embed GLSL
Maverick Peppers edited this page Mar 17, 2019
·
3 revisions
Swoosh can embed GLSL without strings; making it look completely natural and retaining your IDE syntax highlighting.
First add #include <Swoosh/EmbedGLSL.h>
to the top of your file.
This will export a macro definition GLSL(version, shader)
that returns std::string
. We'll use it to write the script. The first value is your GLSL version number.
e.g. #version 110
would become GLSL(110, ...)
.
After, we simply write our script as if it were another class.
auto CHECKERBOARD_FRAG_SHADER = GLSL
(
110,
uniform sampler2D texture;
uniform sampler2D pattern;
uniform float progress;
void main()
{
vec4 pixel = texture2D(texture, vec2(gl_TexCoord[0].xy));
vec4 transition = texture2D(pattern, vec2(gl_TexCoord[0].xy));
vec4 color = gl_Color * pixel;
if (progress >= transition.g) {
color = vec4(1, 1, 1, 0);
}
gl_FragColor = color;
}
);
Get started here.