Login  Register

Re: Help with shaders

Posted by Martin on Feb 12, 2012; 5:12pm
URL: https://forum.jogamp.org/Help-with-shaders-tp3737063p3737674.html

Thanks, gl_Color is exactly what I was looking for :) Moreover your shaders are great examples for me. By the way, your videos on youtube are beautifull.

Unfortunately, when using gl_Color I always retrieve a black color. Should I do additional work in the java caller code?

------------------------
java caller code

protected void renderAverageColors(GL2 gl) {
        gl.glDisable(GL2.GL_DEPTH_TEST);

        // ---------------------------------------------------------------------
        // 1. Accumulate Colors and Depth Complexity
        // ---------------------------------------------------------------------

        gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, g_accumulationFboId[0]);
        gl.glDrawBuffers(2, g_drawBuffers, 0);

        gl.glClearColor(0, 0, 0, 0);
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT);

        gl.glBlendEquation(GL2.GL_FUNC_ADD);
        gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE);
        gl.glEnable(GL2.GL_BLEND);

        g_shaderAverageInit.bind(gl);
        g_shaderAverageInit.setUniform(gl, "Alpha", g_opacity, 1); // PASS PARAMETER TO SHADER
       
        tasksToRender(gl); // CALL DRAGON AND BOXES CODE TO BE RENDERED
       
        g_shaderAverageInit.unbind(gl);

        gl.glDisable(GL2.GL_BLEND);

        // ---------------------------------------------------------------------
        // 2. Approximate Blending
        // ---------------------------------------------------------------------

        gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
        gl.glDrawBuffer(GL2.GL_BACK);

        g_shaderAverageFinal.bind(gl);
        g_shaderAverageFinal.setUniform(gl, "BackgroundColor", g_backgroundColor, 3);
        g_shaderAverageFinal.bindTextureRECT(gl, "ColorTex0", g_accumulationTexId[0], 0);
        g_shaderAverageFinal.bindTextureRECT(gl, "ColorTex1", g_accumulationTexId[1], 1);
        gl.glCallList(g_quadDisplayList);
        g_shaderAverageFinal.unbind(gl);
    }

------------------------
fragments shader code:

uniform float Alpha;
void main(void)
{
        vec4 color = gl_Color;
        color.a = Alpha;
        gl_FragData[0] = vec4(color.rgb * color.a, color.a);
        gl_FragData[1] = vec4(1.0);
}