ExperimentalGear/shaders/laser.fs

47 lines
916 B
Forth
Raw Normal View History

#ifdef EMBEDDED
varying vec2 fsTex;
varying vec4 position;
#else
2021-07-25 20:10:06 +02:00
#extension GL_ARB_separate_shader_objects : enable
layout(location=1) in vec2 fsTex;
layout(location=0) out vec4 target;
in vec4 position;
2021-07-25 20:10:06 +02:00
#endif
uniform sampler2D mainTex;
uniform vec4 color;
uniform float objectGlow;
// 0 = body, 1 = entry, 2 = exit
uniform int laserPart;
// 20Hz flickering. 0 = Miss, 1 = Inactive, 2 & 3 = Active alternating.
uniform int hitState;
2021-07-25 20:10:06 +02:00
const float laserSize = 1.0675;
2021-07-25 20:10:06 +02:00
void main() {
if (laserPart == 1) {
target = texture(mainTex, fsTex);
return;
}
2021-07-25 20:10:06 +02:00
float x = fsTex.x;
2021-08-31 16:41:49 +02:00
// if (x < 0.0 || x > 1.0) {
// target = vec4(0.0);
2021-08-31 16:41:49 +02:00
// return;
// }
2021-07-25 20:10:06 +02:00
x -= (laserSize / 2);
x /= laserSize;
x += (laserSize / 2);
2021-07-25 20:10:06 +02:00
float y = 0.25 * ceil(float(hitState)) + 0.01;
float visiblityMultiplier = 1;
2021-07-25 20:10:06 +02:00
target = texture(mainTex, vec2(x, y)) * vec4(visiblityMultiplier,visiblityMultiplier,visiblityMultiplier,1);
2021-07-25 20:10:06 +02:00
}