-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.glsl
More file actions
executable file
·49 lines (37 loc) · 1.18 KB
/
simple.glsl
File metadata and controls
executable file
·49 lines (37 loc) · 1.18 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
/* simple.glsl
simple diffuse lighting based on laberts cosine law; see e.g.:
http://en.wikipedia.org/wiki/Lambertian_reflectance
http://en.wikipedia.org/wiki/Lambert%27s_cosine_law
*/
---VERTEX SHADER-------------------------------------------------------
#ifdef GL_ES
precision highp float;
#endif
attribute vec3 v_pos;
attribute vec3 v_normal;
uniform vec3 offset;// = vec3(0,0,0);
uniform mat4 rotation;
uniform mat4 modelview_mat;
uniform mat4 projection_mat;
varying vec4 normal_vec;
varying vec4 vertex_pos;
void main (void) {
//compute vertex position in eye_space and normalize normal vector
vec4 rot_pos = rotation * vec4(v_pos,1.0);
vec3 tmp_pos = rot_pos.xyz + offset;
vec4 pos = modelview_mat * vec4(tmp_pos,1.0);
vertex_pos = pos;
normal_vec = vec4(v_normal,0.0);
gl_Position = projection_mat * pos;
}
---FRAGMENT SHADER-----------------------------------------------------
#ifdef GL_ES
precision highp float;
#endif
varying vec4 normal_vec;
varying vec4 vertex_pos;
void main (void){
float dot_val = dot(normal_vec.xyz,vec3(1.0,1.0,1.0));
vec3 color= vec3(0.3,0.3,1.0)*abs(dot_val);
gl_FragColor = vec4( color,1.0);
}