summaryrefslogtreecommitdiffhomepage
path: root/shaders/colour_splitter.fs
blob: 1b20175db95f84c634f5186050033c5504710808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#version 330

#define PI 3.1415926538

// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;

// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;

// Output fragment color
out vec4 finalColor;

// Imported variables from code
uniform float renderWidth;
uniform float renderHeight;

// Variable set up
vec2 flipped = vec2(fragTexCoord.x, 1 - fragTexCoord.y); // flipping
vec2 textureResolution = vec2(renderWidth, renderHeight);
vec2 onePixel = vec2(1.0, 1.0) / textureResolution; // distance of a single pixel in texels
vec2 pixelCoor = flipped * textureResolution;

float gridify(float coordinate, float colour) {
	return floor((cos( (coordinate * 2.0 * PI) + (colour * ((2.0 / 3.0) * PI)) + (0.4 * PI) ) / 2.0) + 0.75);
}

vec3 is_pixel(vec2 coordinate) {
	return vec3(gridify(coordinate.x, 1.0), gridify(coordinate.x, 2.0), gridify(coordinate.x, 3.0));
}

void main()
{
	//float is_pixel = gridify(pixelCoor.x, 1.0) * gridify(pixelCoor.y, 1.0);
	vec4 texelColor = texture(texture0, flipped);
	texelColor.rgb *= is_pixel(pixelCoor).rgb;
	//texelColor.r *= 0;
	//texelColor.g *= 0;
	//texelColor.b *= 0;

    // NOTE: Implement here your fragment shader code
    finalColor = texelColor*colDiffuse;
}