diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-11-24 09:18:24 -0600 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-11-24 09:18:24 -0600 |
commit | 843308f07547b969c97efc23848f4e81b50a5b24 (patch) | |
tree | b709343d4b06880dbd0b06776bc2aa8a57fd9602 /dev/a5-artrender/shaders/artsy.frag | |
parent | Merge branch 'support-code' of https://github.umn.edu/umn-csci-4611-f21/share... (diff) | |
download | csci4611-843308f07547b969c97efc23848f4e81b50a5b24.tar csci4611-843308f07547b969c97efc23848f4e81b50a5b24.tar.gz csci4611-843308f07547b969c97efc23848f4e81b50a5b24.tar.bz2 csci4611-843308f07547b969c97efc23848f4e81b50a5b24.tar.lz csci4611-843308f07547b969c97efc23848f4e81b50a5b24.tar.xz csci4611-843308f07547b969c97efc23848f4e81b50a5b24.tar.zst csci4611-843308f07547b969c97efc23848f4e81b50a5b24.zip |
Do a5
Diffstat (limited to '')
-rw-r--r-- | dev/a5-artrender/shaders/artsy.frag | 23 |
1 files changed, 22 insertions, 1 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; } |