summaryrefslogtreecommitdiff
path: root/keyshade/bin/data/shader.frag
blob: 560766b4fd6677fa45797665a82cb8a785923567 (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
#version 150

uniform vec4 keyColour;
uniform float keyMinDist;
uniform float keyMaxDist;
uniform float time;

// these are our textures
uniform sampler2DRect backgroundTex;
uniform sampler2DRect foregroundTex;

// this comes from the vertex shader
in vec2 texCoordVarying1;
in vec2 texCoordVarying2;



// this is the output of the fragment shader
out vec4 outputColor;

void main()
{
	// Get color values from the background and foreground
	vec4 back = texture(backgroundTex, (texCoordVarying1 - 0.5) * time + (0.5 * time) );
	vec4 fore = texture(foregroundTex, texCoordVarying1);

    vec4 delta = fore - keyColour;
  	float distance2 = dot( delta, delta );
  	float weight =  clamp( (distance2 - keyMinDist) / (keyMaxDist - keyMinDist), 0.0, 1.0);
	
	//mix colors from background and foreground based on the mask value
    outputColor = mix(back, fore, weight);
}