-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture_fragmentshader.txt
51 lines (40 loc) · 1.49 KB
/
texture_fragmentshader.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
#version 150
varying vec3 N;
varying vec3 v;
uniform sampler2D color_texture;
uniform vec4 color1 = vec4(0.0, 0.0, 1.0, 1.0);
uniform vec4 color2 = vec4(0.3, 0.7, 0.5, 1.0);
out vec4 colorOut;
float max(float x, float y){
if(x > y)
return x;
else
return y;
}
void main (void)
{
//Ross: Here's a hint on how to get the light source position
vec3 light = gl_LightSource[0].position.xyz;
vec3 L = normalize(light - vec3(v.x, v.y, v.z));
//Ross: V is the view direction vector and we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 V = normalize(vec3(-v.x, -v.y, -v.z));
vec4 amb = gl_FrontLightProduct[0].ambient;
amb = clamp(amb, 0.0, 1.0);
//calculate Diffuse Term:
vec4 dif = max( dot(L, N), 0.0) * gl_FrontLightProduct[0].diffuse;
dif = clamp(dif, 0.0, 1.0);
//calculate Specular Term:
float alpha = gl_FrontMaterial.shininess;
vec3 R = normalize(2 * dot(L, N) * N - L);
vec4 spec = pow( max(dot(V, R), 0.0), alpha) * gl_FrontLightProduct[0].specular;
spec = clamp(spec, 0.0, 1.0);
// write Total Color:
//colorOut = gl_FrontLightModelProduct.sceneColor;
vec4 color = amb + dif + spec;
color.a = 0.6;
//Ross: If I want to sample my texture, I need to sample it at the (s,t) coordinate of my texture coordinate
vec4 texel = texture2D(color_texture, vec2(1.0, 1.0) * gl_TexCoord[0].st);
gl_FragColor = color + texel;
//Ross: Generic color output is now making all geometry blue
//colorOut = color1;
}