-1
\$\begingroup\$

I've been working on this problem for a while now. My problem is that the sphere in the top image, is under-lapping the plane which should have a lower Z value. Although, when depth testing is disabled, it is resolved. But it favors draw order over actual fragment depth value. I was changing the depth mask out of desperation. ;)

GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
rootObject.render(ambient);

GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
GL11.glDepthMask(false);
GL11.glDepthFunc(GL11.GL_EQUAL);

for(int i = 0; i < lights.size(); i++){
    lights.get(i).use();
    rootObject.render(lights.get(i).getProgram());
}

GL11.glDepthFunc(GL11.GL_LESS);
GL11.glDepthMask(true);

-- Screenies:

GL11.glEnable(GL11.GL_DEPTH_TEST);

depth issue1

GL11.glDisable(GL11.GL_DEPTH_TEST);

depth issue2

\$\endgroup\$
4
  • 1
    \$\begingroup\$ It is unclear what you asking. What is the problem exactly? \$\endgroup\$ Commented Nov 24, 2014 at 5:59
  • \$\begingroup\$ And why do you think you need to change GL11.glDepthMask ? \$\endgroup\$ Commented Nov 24, 2014 at 6:00
  • \$\begingroup\$ My problem is that the sphere in the top image, is under-lapping the plane which should have a lower Z value. Although, when depth testing is disabled, it is resolved. But it favors draw order over actual fragment depth value. I was changing the depth mask out of desperation. ;) \$\endgroup\$ Commented Nov 24, 2014 at 6:15
  • \$\begingroup\$ @Ecumene Edit that into the question. \$\endgroup\$ Commented Nov 26, 2014 at 12:25

2 Answers 2

0
\$\begingroup\$

From the looks of it, you need to throw glDepthMask out.

GL11.glEnable(GL11.GL_DEPTH_TEST); // Enable depth testing
GL11.glEnable(GL11.GL_BLEND); // Enable blending
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Common blending formula for transparency
rootObject.render(ambient); // Background

GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); // This is uncommon blending formula ..
GL11.glDepthFunc(GL11.GL_LEQUAL); //<-- Less or Equal = LEqual

for(int i = 0; i < lights.size(); i++){
    lights.get(i).use();
    rootObject.render(lights.get(i).getProgram()); // spheres?
}
\$\endgroup\$
5
  • \$\begingroup\$ Still isn't working... Same result as the second image \$\endgroup\$ Commented Nov 24, 2014 at 15:22
  • \$\begingroup\$ You did not say - What is the desired result? \$\endgroup\$ Commented Nov 24, 2014 at 15:36
  • \$\begingroup\$ I wanted the sphere to be overlapping the plane, with depth testing. But when depth is enabled, the plane gets drawn over the spheres \$\endgroup\$ Commented Nov 24, 2014 at 20:34
  • \$\begingroup\$ Try also removing the GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); It looks out of place too. \$\endgroup\$ Commented Nov 24, 2014 at 20:42
  • \$\begingroup\$ That's for the shader-light pass. \$\endgroup\$ Commented Nov 24, 2014 at 21:21
0
\$\begingroup\$

Turns out, the problem was my projection matrix. I found this error when I was switching vector math libraries. And I forgot transformations in javax's vecmath are row-major order. So I switched the near and far planes, and it worked perfectly.

(0.1f, 1000f) to (1000f, 0.1f)
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.