-
Notifications
You must be signed in to change notification settings - Fork 0
/
fshader.glsl
74 lines (61 loc) · 1.92 KB
/
fshader.glsl
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
73
#version 410
in vec3 fN;
in vec3 fL;
in vec3 fV;
in vec4 color;
out vec4 fcolor;
in vec2 texCoord;
uniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct;
uniform int UsePicking;
uniform float Shininess;
uniform sampler2D tex;
//Uniform variable for controlling options
uniform int ShadingOption;
uniform int TextureOption;
void main()
{
if(TextureOption == 0){
if(UsePicking == 0){
fcolor = vec4(1.0, 0.0, 0.0, 1.0);
}
else if(UsePicking == 1){
fcolor = vec4(0.0, 1.0, 0.0, 1.0);
}
else if(UsePicking == 2){
fcolor = vec4(0.0, 0.0, 1.0, 1.0);
}
else if(UsePicking == 3){
fcolor = vec4(1.0, 1.0, 0.0, 1.0);
}
//ShadingOption = Gouraud
else if(ShadingOption == 0 && UsePicking == 4) {
fcolor = color;
}
}
//ShadingOption = Phong
else if(ShadingOption == 1 && UsePicking == 4 && TextureOption == 0) {
// Normalize the input lighting vectors
vec3 N = normalize(fN);
vec3 V = normalize(fV);
vec3 L = normalize(fL);
// Normalize the input lighting vectors
vec3 R = normalize( (2.0 * dot(L, N) * N) - L) ; // other phong
vec3 H = normalize( L + V );
vec4 ambient = AmbientProduct;
float Kd = max(dot(L, N), 0.0);
vec4 diffuse = Kd*DiffuseProduct;
float Ks = pow(max(dot(V, R), 0.0), Shininess); // other phong
vec4 specular = Ks*SpecularProduct;
// discard the specular highlight if the light's behind the vertex
if( dot(L, N) < 0.0 ) {
specular = vec4(0.0, 0.0, 0.0, 1.0);
}
fcolor = color + diffuse + ambient;
fcolor.a = 1.0;
}
else if (TextureOption == 1){
fcolor = texture(tex, texCoord);
} else {
fcolor = texture(tex, texCoord);
}
}