O'Reilly logo

Cardboard VR Projects for Android by Matt Schoen, Jonathan Linowes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Vertex color lighting material and shaders

This next topic gets a bit complicated. We're going to write new vertex and fragment shaders that handle lighting and write a corresponding class extending Material that makes use of them. Don't worry though, we've already done this once before. We're just going to actually explain it this time.

Let's dive right into it. Locate the res/raw/ folder. Then, for each file, right-click on it, and go to New | File to create new files.

File: res/raw/vertex_color_lighting_vertex.shader

uniform mat4 u_Model; uniform mat4 u_MVP; uniform mat4 u_MVMatrix; uniform vec3 u_LightPos; attribute vec4 a_Position; attribute vec4 a_Color; attribute vec3 a_Normal; varying vec4 v_Color; const float ONE = 1.0; const float COEFF ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required