-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFragmentSource.frag
63 lines (52 loc) · 1.79 KB
/
FragmentSource.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
59
60
61
62
63
#version 330 core
in vec3 Normal;
in vec3 FragPos;
in vec2 TexCoords;
struct Material {
vec3 ambient;
sampler2D diffuse;
sampler2D specular;
float shininess;
};
struct LightPoint {
float constant;
float linear;
float quadratic;
};
struct LightSpot {
float cosPhy;
};
uniform vec3 ambientColor;
uniform vec3 objColor;
uniform vec3 lightPos;
uniform vec3 lightDir;
uniform vec3 lightColor;
uniform vec3 eyePos;
uniform Material material;
uniform LightPoint lightPtr;
uniform LightSpot lightSpot;
out vec4 FragColor;
void main()
{
float dist = length(lightPos - FragPos);
//float attenuation = 1.f / (lightPtr.constant + lightPtr.linear * (dist) + lightPtr.quadratic * (dist * dist));
vec3 lightDir = normalize(lightPos - FragPos);
vec3 reflectVec = reflect(-lightDir, Normal);
vec3 eyeVec = normalize(eyePos - FragPos);
/* ¸ß¹âÇ¿¶È */
float specularAmount = pow(max(dot(reflectVec, eyeVec), 0), material.shininess);
vec3 Specular = texture(material.specular, TexCoords).rgb * specularAmount * lightColor;
vec3 Diffuse = texture(material.diffuse, TexCoords).rgb * max(dot(lightDir, Normal), 0) * lightColor;
//vec3 Diffuse = texture(material.diffuse, TexCoords).rgb;
vec3 Ambient = texture(material.diffuse, TexCoords).rgb * ambientColor;
float cosTheta = dot(normalize(FragPos - lightPos), -1 * lightDir);
if(cosTheta > lightSpot.cosPhy) {
//resultColor = (Diffuse + Specular + Ambient) * objColor;
FragColor = vec4((Ambient + Diffuse + Specular) * objColor, 1.f);
} else {
//resultColor = Ambient * objColor;
FragColor = vec4((Ambient) * objColor, 1.f);
}
//vec3 resultColor = (attenuation * (Diffuse + Specular) + Ambient) * objColor;
//FragColor = vec4(resultColor, 1.f);
}