Skip to content

Instantly share code, notes, and snippets.

@hikiko
Last active April 13, 2020 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hikiko/15250d799464de31db70335fed7d1ae6 to your computer and use it in GitHub Desktop.
Save hikiko/15250d799464de31db70335fed7d1ae6 to your computer and use it in GitHub Desktop.
xor pattern shader (the comment) :p
#version 430
#extension GL_ARB_separate_shader_objects : enable
const vec2 vdata[] = vec2[] (
vec2(1.0, 1.0),
vec2(1.0, 0.0),
vec2(0.0, 1.0),
vec2(0.0, 0.0));
void main()
{
gl_Position = vec4(vdata[gl_VertexIndex] * 2.0 - 1.0, 0.0, 1.0);
}
==================================================================
#version 450
/* layout(location = 0) in vec2 v_coords; */
layout(push_constant) uniform img_dims {
float w;
float h;
} IMG_DIMS;
layout(location = 0) out vec4 f_color;
/*
void main()
{
int xor = (int(gl_FragCoord.x) ^ int(gl_FragCoord.y));
float r = float((xor * 2) & 0xff) / 255.0;
float g = float((xor * 4) & 0xff) / 255.0;
float b = float((xor * 8) & 0xff) / 255.0;
vec3 col = vec3(r, g, b);
f_color = vec4(col, 1.0);
}
*/
const vec4 colors[] = vec4[] (
vec4(1.0, 0.0, 0.0, 1.0),
vec4(0.0, 1.0, 0.0, 1.0),
vec4(0.0, 0.0, 1.0, 1.0),
vec4(1.0, 1.0, 0.0, 1.0),
vec4(1.0, 0.0, 1.0, 1.0),
vec4(0.0, 1.0, 1.0, 1.0));
void main()
{
int band = int(gl_FragCoord.x * 6.0 / IMG_DIMS.w);
f_color = colors[band];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment