Login  Register

Re: Help with shaders

Posted by Martin on Feb 13, 2012; 11:21pm
URL: https://forum.jogamp.org/Help-with-shaders-tp3737063p3741974.html

Hi,
Following your suggestions and code samples, I tried to enable lights just before rendering the scene content, but it did not change anything to the cruel black gl_Color:

gl.glEnable(GL2.GL_COLOR_MATERIAL);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);

// I tried with and without
gl.glEnable(GL_AUTO_NORMAL);
gl.glEnable(GL_NORMALIZE);

gl.glLightfv(GL_LIGHT0, GL_POSITION, Buffers.newDirectFloatBuffer(new float[]{3.0f, 3.0f, 3.0f, 0.0f}));
gl.glLightfv(GL_LIGHT0, GL_AMBIENT, Buffers.newDirectFloatBuffer(new float[]{0.0f, 0.0f, 0.0f, 1.0f}));
gl.glLightfv(GL_LIGHT0, GL_DIFFUSE, Buffers.newDirectFloatBuffer(new float[]{1.0f, 1.0f, 1.0f, 1.0f}));
gl.glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Buffers.newDirectFloatBuffer(new float[]{0.2f, 0.2f, 0.2f, 1.0f}));

// following arrays are full of 1
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, materialAmbiantReflection.toArray(), 0);
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_DIFFUSE, materialDiffuseReflection.toArray(), 0);
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, materialSpecularReflection.toArray(), 0);
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SHININESS, materialShininess, 0);
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_EMISSION, materialEmission.toArray(), 0);

// render scene graph, ensure any embedded jzy3d light control is ignored
view.renderSceneGraph(gl, glu, false);

I tried different peeling algorithms leading to the same result.



Thinking Jzy3d might be responsible, I went back to the original example
 (http://www.jzy3d.org/misc/depthpeeling/org.jogl.demos.dualdepthpeeling.zip, a cleanly packed eclipse project), and noticed the problem is the same, so there might be something I missed regarding shaders or depth peeling... although no GLSL script makes any reference to lights.

Anyone wishing to try this gl_Color problem should:
1) add a color to DualDepthPeeling.DrawModel(gl), I choosed gl.glColor4f(1.0f, 0.2f, 0.2f, 0.6f); That makes sure the dragon has a color.
2) edit shader dual_peeling_peel_fragment to replace "vec4 color = ShadeFragment();" by "vec4 color = gl_Color;" to retrieve the current dragon color.