Login  Register

Help with shaders

Posted by Martin on Feb 12, 2012; 11:44am
URL: https://forum.jogamp.org/Help-with-shaders-tp3737063.html

Hi,
I am trying to integrate an existing GL program (namely the dual depth peeling demo) into jzy3d. I am stuck with shaders that I discovered while exploring the demo. I wonder if any experienced shader user can give me a hint.

In the program, I got a fragment shader that acts like a kind of color filter, and I would like to desactivate this behavior.

-----------------
vec4 ShadeFragment();
void main(void)
{
        vec4 color = ShadeFragment(); // return a color defined in another script (e.g. return vec3(0.0))
        gl_FragData[0] = vec4(color.rgb * color.a, color.a);
        gl_FragData[1] = vec4(1.0);
}
-----------------

What I want to do is getting the "original color", the one that was set up in the original OpenGL program with gl.glColorXX(...), so I primarily thought about passing it as argument to the shader (maybe there's a more straightforward way?). I modified the fragment shader script this way:

-----------------
uniform vec4 in_Color;
void main(void)
{
        vec4 color = in_Color; // should get original color as input
        gl_FragData[0] = vec4(color.rgb * color.a, color.a);
        gl_FragData[1] = vec4(1.0);
}
-----------------

But I wonder how I should send the colors when calling the GLSL program. I've seen I may call the following kind of code in my draw(GL2 gl) method:
int id = gl.glGetUniformLocation(glslId, "in_Color");
gl.glUniform3fv(id, 1, val, 0);

where val should be the "original color" for each fragment. My question is: "how to retrieve such original color?"

Best regards,
Martin