-
Notifications
You must be signed in to change notification settings - Fork 0
/
fragmentShader
41 lines (32 loc) · 991 Bytes
/
fragmentShader
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
#version 330 core
// Output a color for each fragment
out vec3 color;
in vec3 normal;
in vec3 toLight;
in vec4 gl_FragCoord;
in vec3 positionWorld;
in vec2 UV;
uniform vec3 LightPosition;
uniform sampler2D TextureSampler;
void main(){
// Bright white light
vec3 LightColor = vec3(1,1,1);
float LightPower = 50.0f;
// Green surface
vec3 MaterialDiffuseColor = texture(TextureSampler, UV).rgb;
vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor;
vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3);
float distance = length(LightPosition - positionWorld);
float cosTheta = clamp(dot(normalize(normal),normalize(toLight)),0,1);
// Light color is scaled by the amout it hits directly
color = MaterialAmbientColor + MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance);
// Makes the red line
/*
if(gl_FragCoord.x < 965 && 955 < gl_FragCoord.x){
color = vec3(1,0,0);
}
else{
color = fragmentColor;
}
*/
}