I would like to create a simple shadow shader in glsl, I am using jogl binding. Though when I use the discard function to create transparent, unaltered pixels so I can see the images behind the shader it is not transparent to the background I am displaying.
Here is my java / JOGL code
public void init(GLAutoDrawable drawable) {
gl = drawable.getGL().getGL2();
initShaders(gl);
gl.glEnable(gl.GL_BLEND);
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(gl.GL_ALPHA_TEST);
gl.glAlphaFunc(gl.GL_GREATER, 0.1f);
gl.glMatrixMode(GL_TEXTURE);
gl.glClearColor(1,1, 1, 1);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
images();
game.surface();
world.setContactListener(new ContactListen());
}
public void display(GLAutoDrawable drawable) {
if (currentTime - lastTime >= 10) {
lastTime = currentTime;
angle += step;
}
gl = drawable.getGL().getGL2();
gl.glClearColor(1,1, 1, 1);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
Display.fill(255, 0, 0, 1);
Display.fillRect(0, 0, 1920, 1080);
game.update(System.currentTimeMillis());
if (renderProgram != 0) {
gl.glUseProgram(renderProgram);
gl.glUniform2f(block, 800, 500);
gl.glUniform2f(mouse, mouseX, mouseY);
}
}
GLSL code frag
uniform vec2 light;
uniform vec2 block;
void main(void)
{
vec3 alpha = vec3(0.0, 0.0, 255.0);
float m = ((light.x - gl_FragCoord.x)/(light.y - gl_FragCoord.y));
float o = ((light.x - block.x)/(light.y - block.y));
gl_FragColor = vec4(alpha, 1.0);
if(gl_FragCoord.x > 500){
discard;
}
}