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 = 0.00001; void main() { vec3 modelViewVertex = vec3(u_MVMatrix * a_Position); vec3 modelViewNormal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); float distance = length(u_LightPos - modelViewVertex); vec3 lightVector = normalize...