summaryrefslogtreecommitdiffstats
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/a5-artrender/shaders/artsy.frag23
-rw-r--r--dev/a5-artrender/shaders/gouraud.frag2
-rw-r--r--dev/a5-artrender/shaders/gouraud.vert23
-rw-r--r--dev/a5-artrender/shaders/outline.vert10
-rw-r--r--dev/a5-artrender/shaders/phong.frag21
5 files changed, 63 insertions, 16 deletions
diff --git a/dev/a5-artrender/shaders/artsy.frag b/dev/a5-artrender/shaders/artsy.frag
index a148eaa..ea5b334 100644
--- a/dev/a5-artrender/shaders/artsy.frag
+++ b/dev/a5-artrender/shaders/artsy.frag
@@ -20,5 +20,26 @@ uniform sampler2D specular_ramp;
void main() {
- color = vec4(0,0,0,1);
+ // 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;
}
diff --git a/dev/a5-artrender/shaders/gouraud.frag b/dev/a5-artrender/shaders/gouraud.frag
index 73d43c7..057d4b3 100644
--- a/dev/a5-artrender/shaders/gouraud.frag
+++ b/dev/a5-artrender/shaders/gouraud.frag
@@ -14,5 +14,5 @@ out vec4 final_color;
void main() {
// For a Gouraud shader, there is nothing more to compute at this stage. We
// just output the input color.
- final_color = vec4(0,0,0,1);
+ final_color = color;
}
diff --git a/dev/a5-artrender/shaders/gouraud.vert b/dev/a5-artrender/shaders/gouraud.vert
index fa763cb..ca40e12 100644
--- a/dev/a5-artrender/shaders/gouraud.vert
+++ b/dev/a5-artrender/shaders/gouraud.vert
@@ -32,27 +32,26 @@ out vec4 color;
void main() {
-
+
// transform the vertex position into "eye space"
- vec3 v;
+ vec3 v = vec3(model_view_matrix * vec4(vertex, 1.0));
// unit vector from the vertex to the light
- vec3 l;
-
+ vec3 l = normalize(light_in_eye_space - v);
// unit vector from the vertex to the eye point, which is at 0,0,0 in "eye space"
- vec3 e;
+ vec3 e = normalize(-v);
// normal transformed into "eye space"
- vec3 n;
-
+ vec3 n = (normal_matrix * vec4(normal, 0)).xyz;
// halfway vector
- vec3 h;
-
+ vec3 h = normalize(l + e);
// calculating lighting output the color for this vertex
- // ...
-
-
+ vec4 ambient = ka * Ia;
+ vec4 diffuse = kd * Id * max(dot(n, l), 0);
+ vec4 specular = ks * Is * pow(max(dot(n, h), 0), s);
+ color = ambient + diffuse + specular;
+
// do the standard projection of the incoming vertex
gl_Position = proj_matrix * model_view_matrix * vec4(vertex,1);
}
diff --git a/dev/a5-artrender/shaders/outline.vert b/dev/a5-artrender/shaders/outline.vert
index 302cfeb..58e1308 100644
--- a/dev/a5-artrender/shaders/outline.vert
+++ b/dev/a5-artrender/shaders/outline.vert
@@ -18,5 +18,13 @@ layout(location = 2) in vec3 left_normal;
layout(location = 3) in vec3 right_normal;
void main() {
- gl_Position = proj_matrix * model_view_matrix * vec4(vertex,1);
+ vec3 e = (model_view_matrix * vec4(vertex, 1.0)).xyz;
+ vec3 n_vertex = vertex;
+ vec3 ln = (normal_matrix * vec4(left_normal, 1.0)).xyz;
+ vec3 rn = (normal_matrix * vec4(right_normal, 1.0)).xyz;
+ if (dot(ln, e) * dot(rn, e) < 0.0) {
+ n_vertex = vertex + thickness * normal;
+ }
+
+ gl_Position = proj_matrix * model_view_matrix * vec4(n_vertex,1);
}
diff --git a/dev/a5-artrender/shaders/phong.frag b/dev/a5-artrender/shaders/phong.frag
index 2f7c013..5c51159 100644
--- a/dev/a5-artrender/shaders/phong.frag
+++ b/dev/a5-artrender/shaders/phong.frag
@@ -13,5 +13,24 @@ uniform float s;
void main() {
- color = vec4(0,0,0,1);
+ // transoform the vertex position into "eye space"
+ vec3 v = position_in_eye_space;
+
+ // unit vector from the vertex to the light
+ vec3 l = normalize(light_in_eye_space - v);
+
+ // unit vector from the vertex to the eye point, which is at 0,0,0 in "eye space"
+ vec3 e = normalize(vec3(0,0,0) - v);
+
+ // normal transformed into "eye space"
+ vec3 n = normalize(normalize(normal_in_eye_space));
+ // halfway vector
+ vec3 h = normalize(e+l);
+
+ // calculate color using the light intensity equation
+ vec4 ambient = ka * Ia;
+ vec4 diffuse = kd * Id * max(dot(n, l), 0);
+ vec4 specular = ks * Is * pow(max(dot(h, n), 0), s);
+
+ color = ambient + diffuse + specular;
}