summaryrefslogtreecommitdiff
path: root/demo.fs
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-05-24 18:49:46 -0500
committersanine-a <sanine.not@pm.me>2020-05-24 18:49:46 -0500
commit2ca743d8df36f8cf863caa9c40f965398f72ef2e (patch)
tree9fddae310989e47e95e54fb085a818adfe1f392e /demo.fs
parentabf135246914e5ad57892fb005274da96f040fc2 (diff)
add blinn-phong lighting demo
Diffstat (limited to 'demo.fs')
-rw-r--r--demo.fs26
1 files changed, 24 insertions, 2 deletions
diff --git a/demo.fs b/demo.fs
index a9a0275..65700b7 100644
--- a/demo.fs
+++ b/demo.fs
@@ -1,15 +1,37 @@
#version 330 core
+in vec3 normal;
in vec2 texture_coordinate;
+in vec3 fragment_position;
+
+uniform vec3 ambient_color;
uniform vec3 light_color;
+uniform vec3 light_position;
uniform sampler2D box_texture;
uniform sampler2D happy_texture;
+uniform mat4 model;
+uniform mat4 view;
+
out vec4 fragment_color;
void main()
{
- fragment_color = texture(box_texture, texture_coordinate) * vec4(light_color.xyz, 1.0);
-}
+ /* diffuse light */
+ vec3 norm = normalize(normal);
+ vec3 light_pos = vec3(view * vec4(light_position.xyz, 1.0));
+ vec3 light_direction = normalize(light_pos - fragment_position);
+ float diffuse = max( dot(norm, light_direction), 0 );
+ vec3 diffuse_light = light_color * diffuse;
+
+ /* specular reflection */
+ vec3 view_direction = normalize(-fragment_position);
+ vec3 reflection_direction = reflect(-light_direction, norm);
+ float specular = pow(max(dot(view_direction, reflection_direction), 0), 32);
+ vec3 specular_light = 1.0 * specular * light_color;
+
+ vec4 total_light = vec4((ambient_color + diffuse_light + specular_light).xyz, 1.0);
+ fragment_color = total_light * texture(box_texture, texture_coordinate);
+}