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;
}