Problem with rendering

Started by thejauffre, January 18, 2018, 11:42:48 AM

Previous topic - Next topic

thejauffre

Hi everybody,
I'm developing an Android AR application using Vuforia (for target recognition) and JPCT-AE for the rendering of 3D objects.
I have a problem with depth sorting: when I try to render a teapot, it shows also elements that should not be present (like the handle, when I look at the teapot facing the beak).
I searched over internet, and (if I understood correctly) it is related to OpenGL and how it manages the depth rendering. However, even if I added some lines to the code (when I initialize the renderer):
GLES20.glEnable(GLES20.GL_BLEND);
        GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        GLES20.glEnable(GLES20.GL_FRAGMENT_SHADER);
        GLES20.glEnable(GLES20.GL_DEPTH_TEST);
        GLES20.glEnable(GLES20.GL_TRUE);
        GLES20.glDepthFunc(GLES20.GL_LESS);
        GLES20.glDepthMask(GLES20.GL_TRUE);
        GLES20.glClearDepthf(1.0f);
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

it didn't change. Can you help me?
Anyway, thanks for your amazing work.

EgonOlsen

You are not supposed to initialize GL behind jPCT-AE's back. That won't work properly. jPCT-AE's gl context always uses a depth buffer. However, it might be a setup problem with Vuforia. Have you had a look at the examples in the wiki?

thejauffre

To integrate Vuforia and JPCT I followed this (http://www.jpct.net/wiki/index.php?title=Integrating_JPCT-AE_with_Vuforia).
I did some more research; apparently, Vuforia's renderer (used to render the video background) performed "GLES20.glDisable(GLES20.GL_DEPTH_TEST)" before JPCT's rendering.
Moving that glDisable command at the end of renderFrame solves the original problem.
Now I have another: the rendering of the teapot is shown only when I am close to the target, but not too close. I think it is related to the clipping planes, but if I change the values of world.setClippingPlanes or cam.setClippingPlanes there's no difference.

EgonOlsen

Maybe Vuforia overrides these settings? No idea, I've never used it myself. Do you have a screen shot of the clipping effect?

thejauffre

I think I understood this problem: Vuforia uses a plane, rendered with OpenGLES, where it draws the camera input. My impression is that this plane "cuts" the teapot when I move the device around the target, or shows nothing when the plane is between the camera and the target.
Vuforia creates the plane by using some JNI calls, and I don't know if I can set the distance between camera and plane; i'll contact their support forum, and bring here the solution (if any).

thejauffre

I managed how to solve the problem.
Vuforia uses a custom shader to render the background plane, defined in their VideoBackgroundShader class.
In the vertex shader, I had just to add a translation along the z component of the gl_Position vector.