-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_pixel_lighting.vert
More file actions
72 lines (57 loc) · 2.29 KB
/
model_pixel_lighting.vert
File metadata and controls
72 lines (57 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#version 120
uniform mat4 projection_matrix; // Projection matrix passed in to vertex shader
uniform mat4 modelview_matrix; // Modelview matrix passed in to vertex shader
struct light {
vec4 position;
vec4 ambient;
vec4 diffuse;
vec4 specular;
};
uniform light light0; // Input light source 0
uniform vec4 material_ambient;
uniform vec4 material_diffuse;
uniform vec4 material_specular;
uniform vec4 material_emissive;
uniform float material_shininess;
uniform float fogDensity;
uniform float lerp_value;
attribute vec3 a_Vertex; // Input vertex from current animation frame
attribute vec3 b_Vertex; // Input vertex from next animation frame
attribute vec2 a_TexCoord0; // Input texture coordinate
attribute vec3 a_Normal; // Input vertex normal
attribute vec3 b_Normal; // Input vertex normal from next animation frame
attribute vec4 a_Color; // Input color
varying vec4 color;
varying vec2 texCoord0; // Output texture coordinate to be interpolated and passed to fragment shader
varying vec3 normal; // Output lerped normal
varying vec3 light_pos; // Output light position
varying vec3 half_vector; // Output half vector
varying vec4 vertex_ambient; // Vertex ambient light value
varying vec4 vertex_diffuse; // Vertex diffuse light value
varying float blend_factor;
void main(void)
{
//Interpolate vertex coords.
vec3 lerped_vertex = mix(a_Vertex, b_Vertex, lerp_value);
//Interpolate normal coords.
vec3 lerped_normal = mix(a_Normal, b_Normal, lerp_value);
//Calculate normal matrix and transform normal into eye space.
mat3x3 normal_matrix = mat3x3(modelview_matrix);
normal = normalize(normal_matrix * lerped_normal);
//Transform light position into eye space.
light_pos = normalize(modelview_matrix * light0.position).xyz;
//Calculate ambient colour.
vertex_ambient = material_ambient * light0.ambient;
//Calculate diffuse colour.
vertex_diffuse = material_diffuse * light0.diffuse;
//Transform vertex into eye space.
vec4 pos = modelview_matrix * vec4(lerped_vertex, 1.0);
//Calculate eye vector.
vec3 E = -pos.xyz;
//Calculate half vector.
half_vector = normalize(light_pos + E);
//blendFactor = exp2(-fogDensity * length(pos));
gl_Position = projection_matrix * pos;
texCoord0 = a_TexCoord0;
color = a_Color;
}