Let me preface this with the fact that I am very new to GLSL.
I am attempting to use a shader to add a blur effect to slot reel symbols while they spin. I have a working blur effect going, which I have commented out just for simplicity and isolating this issue.
Vertex Shader:
//Vertex Shader
attribute vec4 position;
attribute vec4 inColor;
attribute vec2 inUV;
//To be passed to the Fragment Shader "BlurShader.fsh"
varying vec4 colorVarying;
varying vec2 uvOut;
void main()
{
colorVarying = inColor;
gl_Position = position;
uvOut = inUV;
}
Fragment Shader:
//Fragment Shader
uniform sampler2D tex0;
//Passed from Vertex Shader "BlurShader.vsh"
varying vec4 colorVarying; //ISSUE: this is always solid white
varying vec2 uvOut;
//This is the intensity of the blur. Higher is a larger blur
// 25 is a good starting point
// Could possibly make it a varible to be passed in to control directly from Lua
#define INTENSITY 25.0
vec4 BlurVertical(vec2 size, vec2 uv, float radius) {
if (radius >= 1.0)
{
vec4 C = vec4(0.0);
float height = 1.0 / size.y;
float divisor = 0.0;
for (float y = -radius; y <= radius; y++)
{
C += texture(tex0, uv + vec2(0.0, y * height));
divisor++;
}
return vec4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0);
}
return texture2D(tex0, uv);
}
void main()
{
//Apply blur to final output
//gl_FragColor = BlurVertical(textureSize(tex0, 0), uvOut, INTENSITY);
//gl_FragColor = texture2D(tex0, uvOut) * colorVarying; SAME RESULT
gl_FragColor = texture2D(tex0, uvOut);
}
My problem is that the shader results in a strange unwanted grayscale effect and a loss of transparency.
I am very lost at what could be causing this, and I can't seem to find anyone with a similar issue.