-
Notifications
You must be signed in to change notification settings - Fork 0
/
FS_Stipling1.txt
56 lines (45 loc) · 1.47 KB
/
FS_Stipling1.txt
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
#version 430
uniform mat4 matView;
uniform vec3 lightPos;
uniform vec3 lightColor;
uniform vec3 viewPos;
uniform sampler2D diffuseMap;
in vec3 out_color;
in vec3 out_pos;
in vec3 out_normal;
in vec2 out_uv;
layout(location = 0) out vec4 gl_FragColor;
void main(void) {
vec3 camPos = viewPos;
vec3 lightDir= normalize(lightPos-out_pos);
vec3 viewDir= normalize(camPos-out_pos);
//ambient lighting
float Kamb= 1.0;
vec3 ambient= Kamb*lightColor;
//diffused lighting
float Kdiff= 1.0;
vec3 norm= normalize(out_normal);
float diff= max(dot(norm, lightDir), 0.0); //to clamp between 0 and 1
vec3 diffuse= Kdiff*diff*lightColor; //light intensity * cos
//specular lighting
float Kspec = 1.0f;
vec3 reflectDir= reflect(-lightDir, norm);
float spec= pow(max(dot(viewDir, reflectDir), 0.0), 16);
vec3 specular= Kspec*spec*lightColor;
//Get outline
float edge_thresh=0.0; //set threshold for edge detection
float visiblity=dot(viewDir, norm);
float edge_detection = (visiblity > edge_thresh) ? 0 : 1; //Black color if dot product is smaller than 0.2 else keep the same colors
//final color for object
vec3 tex_final= texture(diffuseMap, out_uv).rgb;
vec3 final_color;
if(edge_detection ==0){
final_color= (ambient+diffuse+specular)*out_color; //teapot
}else{
float scale_origin=0.5;
float scale=scale_origin+edge_thresh;
float factor= (visiblity+scale_origin)/scale;
final_color= factor*ambient*out_color; //teapot
}
gl_FragColor= vec4(final_color, 1.0f);
}