Skip to content Skip to sidebar Skip to footer

Diffuse Shader For Opengl Es 2.0: Light Changes With Camera Movement (vuforia On Android)

As a starting point I use the Vuforia (version 4) sample called MultiTargets which tracks a 3d physical 'cube' in the camera feed and augments it with yellow grid lines along the c

Solution 1:

I finally solved all problems. There were 2 issues that might be of interest for future readers.

  1. Vuforia CubeObject class from the official sample (current Vuforia version 4) has wrong normals. They do not all correspond with the vertex definition order. If you're using the CubeObject from the sample, make sure that the normal definitions are correctly corresponding with the faces. Vuforia fail...

  2. As suspected, my normalMatrix was wrongly built. We cannot just invert-transpose the 4x4 modelViewMatrix, we need to first extract the top left 3x3 submatrix from it and then invert-transpose that.

Here is the code that works for me:

final Mat3 normalMatrixCube=newMat3();
  normalMatrixCube.SetFrom4X4(modelViewMatrix);
  normalMatrixCube.invert();
  normalMatrixCube.transpose();

This code by itself is not that useful though, because it relies on a custom class Mat3 which I randomly imported from this guy because neither Android nor Vuforia seem to offer any matrix class that can invert/transpose 3x3 matrices. This really makes me question my sanity - the only code that works for such a basic problem has to rely on a custom matrix class? Maybe I'm just doing it wrong, I don't know...

Solution 2:

thumbs up for not using the fixed functions on this! I found your example quite useful for understanding that one needs to also translate the light to a position in eyespace. All the questions i've found just recommend using glLight.

While this helped me solve using a static light source, something which is missing from your code if you wish to also make transformations on your model(s) while keeping the light source static(e.g rotating the object) is to keep track of the original modelview matrix until the view is changed, or until you're drawing another object which has a different model. So something like:

vLightPositionEyespace = fixedModelView * uLightPosition;

where fixedModelView can be updated in your renderFrame() method.

This thread on opengl discussion boards helped :)

Post a Comment for "Diffuse Shader For Opengl Es 2.0: Light Changes With Camera Movement (vuforia On Android)"