51 lines
1010 B
GLSL
51 lines
1010 B
GLSL
@header const m = @import("math")
|
|
@ctype mat4 m.Mat4
|
|
|
|
/* main vertex shader */
|
|
@vs vs
|
|
in vec2 position;
|
|
in vec2 texcoord0;
|
|
in vec4 color0;
|
|
out vec4 color;
|
|
out vec4 uv;
|
|
|
|
layout(binding = 0) uniform vs_params {
|
|
mat4 view;
|
|
mat4 projection;
|
|
};
|
|
|
|
void main() {
|
|
gl_Position = projection * view * vec4(position, 0, 1);
|
|
color = color0;
|
|
uv = vec4(texcoord0, 0.0, 1.0);
|
|
}
|
|
@end
|
|
|
|
/* main fragment shader */
|
|
@fs fs
|
|
layout(binding=0) uniform texture2D tex;
|
|
layout(binding=0) uniform sampler smp;
|
|
in vec4 color;
|
|
in vec4 uv;
|
|
out vec4 frag_color;
|
|
|
|
layout(binding = 1) uniform fs_params {
|
|
// Textures modes:
|
|
// 0 - rgba8
|
|
// 1 - r8 - use red channel as opacity, used for fonts.
|
|
int texture_mode;
|
|
};
|
|
|
|
void main() {
|
|
vec4 tex_color = texture(sampler2D(tex, smp), uv.xy);
|
|
if (texture_mode == 0) {
|
|
frag_color = tex_color * color;
|
|
} else if (texture_mode == 1) {
|
|
frag_color = vec4(1, 1, 1, tex_color.r) * color;
|
|
}
|
|
}
|
|
@end
|
|
|
|
/* main shader program */
|
|
@program main vs fs
|