-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpn-triangles.frag
58 lines (47 loc) · 1.97 KB
/
pn-triangles.frag
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
#version 460 core
// All of the following variables could be defined in the OpenGL
// program and passed to this shader as uniform variables. This
// would be necessary if their values could change during runtim.
// However, we will not change them and therefore we define them
// here for simplicity.
vec3 I = vec3(1, 1, 1); // point light intensity
vec3 Iamb = vec3(0.8, 0.8, 0.8); // ambient light intensity
//vec3 kd = vec3(0.7, 0.5, 0.2); // diffuse reflectance coefficient
//vec3 kd = vec3(0.6, 0.3, 0.3); // diffuse reflectance coefficient
vec3 kd = vec3(0.8, 0.8, 0.8); //
//vec3 kd = vec3(0.1, 0.8, 0.2); // diffuse reflectance coefficient
vec3 ka = vec3(0.3, 0.3, 0.3); // ambient reflectance coefficient
vec3 ks = vec3(0.8, 0.8, 0.8); // specular reflectance coefficient
vec3 lightPos = vec3(5, 5, 5); // light position in world coordinates
layout (std140, binding = 0) uniform matrices
{
mat4 modelingMatrix;
mat4 viewingMatrix;
mat4 projectionMatrix;
vec3 eyePos;
};
in TESE_FS_INTERFACE
{
vec4 fragWorldPos;
vec3 fragWorldNor;
} fs_in;
out vec4 fragColor;
void main(void)
{
// Compute lighting. We assume lightPos and eyePos are in world
// coordinates. fragWorldPos and fragWorldNor are the interpolated
// coordinates by the rasterizer.
vec3 L = normalize(lightPos - vec3(fs_in.fragWorldPos));
vec3 V = normalize(eyePos - vec3(fs_in.fragWorldPos));
vec3 H = normalize(L + V);
vec3 N = normalize(fs_in.fragWorldNor);
float NdotL = dot(N, L); // for diffuse component
float NdotH = dot(N, H); // for specular component
vec3 diffuseColor = I * kd * max(0, NdotL);
vec3 specularColor = I * ks * pow(max(0, NdotH), 100);
vec3 ambientColor = Iamb * ka;
fragColor = vec4(diffuseColor + specularColor + ambientColor, 1);
//fragColor = vec4(0,1,0,1);
//fragColor = vec4(noise3(fs_in.fragWorldPos.x/3 +fs_in.fragWorldPos.y/3 + fs_in.fragWorldPos.z/3)/2+vec3(0.5,0.5,0.5), 1.0f);
//fragColor = vec4(0, 0.8, 0, 1);
}