diff options
Diffstat (limited to 'advanced_lighting/blinn_phong/shaders/blinn_phong.fs')
-rw-r--r-- | advanced_lighting/blinn_phong/shaders/blinn_phong.fs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/advanced_lighting/blinn_phong/shaders/blinn_phong.fs b/advanced_lighting/blinn_phong/shaders/blinn_phong.fs new file mode 100644 index 0000000..23e2968 --- /dev/null +++ b/advanced_lighting/blinn_phong/shaders/blinn_phong.fs @@ -0,0 +1,62 @@ +#version 330 core + +in vec2 tex_coords; +in vec3 normal; +in vec3 frag_pos; + +out vec4 frag_color; + +uniform sampler2D texture_diffuse; +uniform sampler2D texture_specular; + +uniform vec3 light_pos; +uniform vec3 view_pos; + +uniform float ambient_strength; +uniform float specular_strength; +uniform float shininess; + +vec4 +spotlight(vec3 light_dir, vec3 view_dir) +{ + vec3 tex_color_diff = texture(texture_diffuse, tex_coords); + float ambient_strength = 0.1f; + vec4 ambient = tex_color_diff*ambient_strength; + vec4 diffuse = tex_color_diff*dot(-light_dir, ) + return(color); +} + +vec4 +blinn_phong() +{ + // Sample the diffuse color from the texture + vec3 diffuse_color = texture(texture_diffuse, tex_coords).rgb; + + // Sample the specular color from the texture (if available) + vec3 specular_color = texture(texture_specular, tex_coords).rgb; + + // Ambient lighting + vec3 ambient = ambient_strength*diffuse_color; + + // Diffuse lighting + vec3 norm = normalize(normal); + vec3 light_dir = normalize(light_pos-frag_pos); + float diff = max(dot(norm, light_dir), 0.0); + vec3 diffuse = diff * diffuse_color; + + // Specular lighting + vec3 view_dir = normalize(view_pos-frag_pos); + vec3 halfway_dir = normalize(light_dir+view_dir); // Halfway vector + float spec = pow(max(dot(norm, halfway_dir), 0.0), shininess); + vec3 specular = specular_strength*spec*specular_color; + + // Combine all components + vec3 result = (ambient+diffuse+specular); + return((result, 1.0)); +} + +void +main(void) +{ + frag_color = blinn_phong(); +} |