Log in or register to post comments

Artifacts/Issues when Rendering Textures

July 16, 2013 - 12:22am #1

Hello everybody,

I have a problem when rendering an object with multiple textures in conjuction with Vuforia. The issue I'm describing can be found in the attached images.

To reproduce:

1 - Point the camera to the first marker which then renders the "Coffee Machine" (see Second object.png). This object has only one texture that covers a small part of it.

2- Close ARView, deinit() Vuforia

3- Start ARView again and point camera to second marker which then renders the "Tea cups set" (see Artifacts-Blending-Videframe.png). The output is rendered incorrectly, and you can see parts of the videoframe instead of the texture.

If I point the camera to the second marker without rendering the "Coffee Machine" first, then it works fine (see Correct output.png)

I must point out that this issue happens only with Vuforia, as I have another GLView that uses the same loading, rendering and cleanup code but without using Vuforia, and it doesn't happen there.

Any pointers, hints or suggestions as to why such issue may arise are appreciated.

PS: let me know if you need to see any code snippets.

AttachmentSize
Image icon Artifacts-Blending-Videoframe.png878.51 KB
Image icon Second object.png515.79 KB
Image icon Correct output.png582.42 KB

Artifacts/Issues when Rendering Textures

August 14, 2013 - 9:31am #20

Thanks for the update.  I will pass this on to the dev team.

Are you able to work around this now?

 

N

Artifacts/Issues when Rendering Textures

August 14, 2013 - 6:46am #19

After extensive testing I can say with 99% certainty, that the problem only occurs when both OpenGL context and Vuforia are teared down.

The problem doesn't occur:

  • if I unload the models along with their textures while Vuforia is still running and then load/init them again.
  • if I tear down Vuforia and start it again without touching the models, textures and the OpenGL context.

 

Artifacts/Issues when Rendering Textures

August 5, 2013 - 5:43am #18

In that case are you able to try not tearing down OpenGL and seeing whether you get the same results?

N

Artifacts/Issues when Rendering Textures

August 5, 2013 - 5:33am #17

Yes, I tear down everything. The buffers, textures, OpenGL context ..etc

Artifacts/Issues when Rendering Textures

August 5, 2013 - 5:30am #16

When you deinit() are you tearing down OpenGL?

N

Artifacts/Issues when Rendering Textures

August 5, 2013 - 5:22am #15

Yes, only after a deinit().

If I close the app and start again, this doesn't happen.

Artifacts/Issues when Rendering Textures

August 5, 2013 - 5:20am #14

Reading your original message again, does this happen only after you deinit() Vuforia and then go back in?

N

 

Artifacts/Issues when Rendering Textures

August 5, 2013 - 4:07am #13

I updated Vuforia SDK to the latest version (2.6.8) and here is the result using the same rendering code as before. Hope this helps in figuring out the issue.

AttachmentSize
Image icon Screenshot 2013.08.05 13.04.30.png814.43 KB

Artifacts/Issues when Rendering Textures

July 19, 2013 - 6:45am #12

If I activate anu other unit, then every textured model is rendered black. Only the non-textured parts are rendered with the right material values (ambient, diffuse & specular)

Artifacts/Issues when Rendering Textures

July 19, 2013 - 4:48am #11

What happens when you try a different Texture Unit?

N

 

Artifacts/Issues when Rendering Textures

July 19, 2013 - 4:39am #10

All the rendering logic is implemented in the "scene" object. It loads all textures, model data, lights ..etc and manipulates OpenGL states. If used alone in a method that's called let's say via a "display link" all rendering is done correctly.

The "Render" method is called for each "model" in the "scene" with the corresponding parameters.

here is a code snippet:

void Render( // shader, light, texture .. etc) {
	// use program
    glUseProgram(shader->_shaderProgramID);

	// set uniforms
    glUniformMatrix4fv(shader->_projectionMatrix, 1, GL_FALSE, (GLfloat *)projectionMatrix);
    glUniformMatrix4fv(shader->_viewMatrix, 1, GL_FALSE, (GLfloat *)viewMatrix);
    glUniformMatrix4fv(shader->_modelMatrix, 1, GL_FALSE, (GLfloat *)modelMatrix);

    glUniform4f(_lightPositionHandle, _lightPosition[0], _lightPosition[1], _lightPosition[2] , 1);

    glUniform3f(_ambientMaterialHandle, _ambient[0], _ambient[1], _ambient[2]);
	glUniform3f(_diffuseMaterialHandle, _diffuse[0], _diffuse[1], _diffuse[2]);
   	glUniform3f(_specularMaterialHandle, _specular[0], _specular[1], _specular[2]);
	
	// activate texture
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture->_textureID);

	// bind vao and render
    glBindVertexArrayOES(_vertexArrayObjectHandle);
    glDrawArrays(GL_TRIANGLES, 0, (GLsizei)( _vertexDataSize/sizeof(float) ) /3);
    
	// unbind
    glBindTexture(GL_TEXTURE_2D, 0);
    glBindVertexArrayOES(0);
}

 

Artifacts/Issues when Rendering Textures

July 19, 2013 - 3:53am #9

I cannot see how you have modified the code at all from the standard Image Targets app?

Where are you saving/restoring states?  and how have you applied the information from here ?

https://developer.vuforia.com/resources/dev-guide/opengl-state-changes-video-background-renderer

 

What are you doing to ensure the correct texture unit is active and that the right texture id is being used?

 

N

Artifacts/Issues when Rendering Textures

July 19, 2013 - 3:37am #8

I already have the following change in my code, but still the issue persists

- (void)renderFrameQCAR
{
    if (_qUtils.appStatus != APPSTATUS_CAMERA_RUNNING) return;
 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    QCAR::State state = QCAR::Renderer::getInstance().begin();
    QCAR::Renderer::getInstance().drawVideoBackground();

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
 
    //    
       rest code: rendering, trackable .. etc    
    //

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    QCAR::Renderer::getInstance().end();
    [self presentFramebuffer];
}

Artifacts/Issues when Rendering Textures

July 19, 2013 - 2:49am #7

I would have thought you would need to save and restore the states at the beginning / end of renderFrameQCAR.

i.e. line 4 - save & line 33.5 - restore

 

This way you would do it once, which should theoretically improve performance as well.

In terms of an explanation, please see this article about OpenGL ES state changes:

https://developer.vuforia.com/resources/dev-guide/opengl-state-changes-video-background-renderer

 

N

 

Artifacts/Issues when Rendering Textures

July 18, 2013 - 12:55pm #6

Hi @iska,

I'm having a very similar problem so I just wanted to know if you could solve it.

Thanks!

Artifacts/Issues when Rendering Textures

July 18, 2013 - 2:35am #5

Here is my rendering code, the "_scene->Render" method takes only two matrices (projection and view) then does all the rendering without any further Vuforia interaction.
The "_scene" object itself is loaded along with the textures separately before initializing Vuforia. The "ARMarker" is just a small wrapper object that holds offsets and rotation values to position the object relative to the tracked marker.

The whole OpenGL rendering (states, shaders, loading, deiniting ..) is handled internaly in the "_scene" object, which works fine without the Vuforia bit. The problem only happens when I open the Vuforia view twice with two different models. In the first time it works as expected, but the second time it is corrupted.

I agree, that it looks like an init/deinit problem, but I can't figure out where exactly that happens.

- (void)renderFrameQCAR
{
    if (_qUtils.appStatus != APPSTATUS_CAMERA_RUNNING) return;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    QCAR::State state = QCAR::Renderer::getInstance().begin();
    QCAR::Renderer::getInstance().drawVideoBackground();
    
    for(int i = 0; i < state.getNumTrackableResults(); ++i) {
        const QCAR::TrackableResult* trackableResult = state.getTrackableResult(i);
        QCAR::Matrix44F viewMatrix = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose());
        
        // Check the type of the trackable:
        assert(trackableResult->getType() == QCAR::TrackableResult::MARKER_RESULT);
        const QCAR::MarkerResult* markerResult = static_cast<const QCAR::MarkerResult*>(trackableResult);
        
        const QCAR::Marker& marker = markerResult->getTrackable();
        
        int markerID = marker.getMarkerId();
        ARMarker *armarker = [_sceneDictionary objectForKey:[NSNumber numberWithInt:markerID]];

        MatrixUtils::RotatePoseMatrix(armarker.rotationZ, 0, 0, 1, &viewMatrix.data[0]);
        MatrixUtils::RotatePoseMatrix(armarker.rotationY, 0, 1, 0, &viewMatrix.data[0]);
        MatrixUtils::RotatePoseMatrix(armarker.rotationX, 1, 0, 0, &viewMatrix.data[0]);

        _scene->Render(&_qUtils.projectionMatrix.data[0], &viewMatrix.data[0]);
    }
    QCAR::Renderer::getInstance().end();
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    [self presentFramebuffer];
}

 

Artifacts/Issues when Rendering Textures

July 18, 2013 - 1:21am #4

the same rendering code works fine if I use it without Vuforia

Which is why potentially having Vuforia within the rendering loop might be causing some kind of impact.

 

If you look closely, you can see parts of the videoframe being applied to the objects instead of the textures.

Yes I saw this, which is why it seems to be using the wrong texture i.e. it must be using the same Texture Unit and the same Texture ID to draw this.  Assuming this is not what you want, it indicates there has to be a problem here.

 

...which is why I clarified that Vuforia does not save/restore the rendering state.

 

Artifacts/Issues when Rendering Textures

July 18, 2013 - 12:30am #3

Hi NalinS,

thanks for the reply. I've already checked all those, and as I stated in the question, the same rendering code works fine if I use it without Vuforia regardless of how many times I start, pause and resume it.

As to the wrong texture being used, If you look closely, you can see parts of the videoframe being applied to the objects instead of the textures.

Any other suggestions ?

Artifacts/Issues when Rendering Textures

July 16, 2013 - 3:06am #2

Hi iska

Looking at your first image, it appears that the wrong texture is being used to render some of the objects.

Potentially this points to textures not being initialised / deinitialised, or Texture Units not being set up correctly - so this might need checking.

There may also be an issue due to the fact that Vuforia does not save the GL state at the beginning of the Renderloop, nor does it restore them at the end - instead this is left up to the developer.

 

HTH

N

 

 

Log in or register to post comments