1
\$\begingroup\$

Ok, bear with me, I am a beginner with Google Cardboard programming.
What I have been doing is looking at the TreasureHunter sample app from Google's page and (with the help of documentation and other sources) have been trying to create a simple cube floating in space.
I have also been trying to avoid making everything as bare bones as the sample, so I have been trying to object orient things such as lights and the meshes.

I am pretty sure that my matrices and methods are correct, but I think there could be something wrong with my shaders.

When I compile the app and install it, no errors are thrown, but I am given just my white screen (set with glClearColor) with the Cardboard binocular UI/view; no cube is rendered, tilting/looking around has no effect.

I am using the colors, verticies, and normals from the Treasure Hunter sample, so those should be correct.

Full source code (Java) is here.

uniform mat4 u_Model; // model position in world space
uniform mat4 u_MVP;  // model in projection space
uniform mat4 u_MVMatrix; // model in view space
uniform vec3 u_LightPos; // Light position in eye/camera space (projection space)

attribute vec4 a_Position; // vertex in local space
attribute vec4 a_Color; //Vertex colors
attribute vec3 a_Normal; //vertex normal

varying vec4 v_Color; // color
varying vec3 v_Grid;
varying vec3 v_Normal;
varying vec3 v_Position;

void main() {
   v_Grid = vec3(u_Model * a_Position);
   v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));
   v_Position = vec3(u_MVMatrix * a_Position);
   vec3 modelViewVertex = vec3(u_MVMatrix * a_Position); //Vertex position in view space
   vec3 modelViewNormal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); //Normal in view space

   float distance = distance(u_LightPos, modelViewVertex);
   vec3 lightVector = normalize(u_LightPos - modelViewVertex);
   float diffuse = max(dot(modelViewNormal, lightVector), 0.5);

   diffuse = diffuse * 1.0/(distance * distance);
   v_Color = a_Color * diffuse;
   gl_Position = u_MVP * a_Position;
}

My vertex shader:

My fragment shader:

precision mediump float;

varying vec4 v_Color;

void main()
{
    gl_FragColor = v_Color;
}
\$\endgroup\$
4
  • \$\begingroup\$ Do they have any sample apps with a single triangle that you can start from? If not, that is very sad and someone needs to make one :p \$\endgroup\$ Commented Nov 25, 2016 at 16:41
  • 1
    \$\begingroup\$ @AlanWolfe, no they do not have a simple triangles sample. The have samples for VR videos and panorama photos, but nothing else for VR with OpenGL. \$\endgroup\$ Commented Nov 25, 2016 at 17:14
  • \$\begingroup\$ You should make every varying variable exist on both sides. \$\endgroup\$ Commented Nov 25, 2016 at 18:59
  • \$\begingroup\$ @Bálint, tried your suggestion, but sadly no effect :/ \$\endgroup\$ Commented Nov 25, 2016 at 19:11

1 Answer 1

0
\$\begingroup\$

Turns out I was calculating my "u_MVP" (Model View Projection) matrix wrong. I used a vector instead of a matrix for the model position. That along with many other bugs. Now it's fixed.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.