summaryrefslogtreecommitdiffstats
path: root/dev/a5-artrender/shaders/artsy.frag
blob: ea5b334a94bbb9bbb7d732781adf591cbb02b0b4 (plain) (blame)
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
#version 330

// CSci-4611 Assignment 5:  Art Render

// TODO: You need to calculate per-fragment shading here using a toon shading model

in vec3 position_in_eye_space;
in vec3 normal_in_eye_space;

out vec4 color;

uniform vec3 light_in_eye_space;
uniform vec4 Ia, Id, Is;

uniform vec4 ka, kd, ks;
uniform float s;

uniform sampler2D diffuse_ramp;
uniform sampler2D specular_ramp;


void main() {
    // normalized normal
    vec3 n = normalize(normal_in_eye_space);

    // unit vector from the vertex to the light
    vec3 l = normalize(light_in_eye_space - position_in_eye_space);

    // unit vector from the vertex to the eye point, which is at 0,0,0 in "eye space"
    vec3 e = normalize(-position_in_eye_space);

    // halfway vector
    vec3 h = normalize(l + e);

    // calculate color using the light intensity equation
    vec4 ambient = Ia * ka;
    float diff_intensity = max(dot(n, l), 0.0);
    vec2 diffuse_texture = vec2(diff_intensity, 0.0);
    vec4 diffuse = Id * kd * texture(diffuse_ramp, diffuse_texture);
    float spec_intensity = pow(max(dot(n, h), 0.0), s);
    vec2 specular_texture = vec2(spec_intensity, 0.0);
    vec4 specular = Is * ks * texture(specular_ramp, specular_texture);

    color = diffuse + specular;
}