feat(4): Task 4
This commit is contained in:
parent
29c45e43e8
commit
889663355c
2 changed files with 40 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
|||
// surface and a light direction. Assume the light has a low
|
||||
// ambient intensity of 0.1. To avoid confusion: this Blinn-Phong shading model
|
||||
// should only consist of ambient, diffuse and specular lighting.
|
||||
// Do not divide by r² (the squared distance to the point light).
|
||||
// Do not divide by r^2 (the squared distance to the point light).
|
||||
|
||||
// Inputs:
|
||||
// ka rgb ambient color
|
||||
|
@ -23,8 +23,18 @@ vec3 blinn_phong(
|
|||
vec3 l)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
return vec3(1,1,1);
|
||||
// Replace with your code
|
||||
float AMBIENT_INTENSITY = 0.1;
|
||||
|
||||
/* Ambient lighting */
|
||||
vec3 rgb = ka * AMBIENT_INTENSITY;
|
||||
/* Diffuse component (Lambertian shading) */
|
||||
rgb += kd * max(dot(n, l), 0.0);
|
||||
/* Specular component (Blinn-Phong shading) */
|
||||
vec3 h = normalize(v + l);
|
||||
rgb += ks * pow(max(0.0, dot(n, h)), p);
|
||||
|
||||
return rgb;
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
|
29
src/4_lit.fs
29
src/4_lit.fs
|
@ -23,7 +23,32 @@ out vec3 color;
|
|||
void main()
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
color = vec3(1,1,1);
|
||||
// Replace with your code
|
||||
float r = 10.0;
|
||||
float h = 8.0;
|
||||
float f = 8.0;
|
||||
float p = 1000.0;
|
||||
|
||||
float x = r * cos(2.0 * M_PI * animation_seconds / f);
|
||||
float z = r * sin(2.0 * M_PI * animation_seconds / f);
|
||||
vec3 light_pos = vec3(x, h, z);
|
||||
|
||||
// Calculate the light direction
|
||||
vec3 l = normalize(light_pos - sphere_fs_in);
|
||||
|
||||
// Calculate the view direction
|
||||
vec3 v = normalize(view_pos_fs_in.xyz - sphere_fs_in);
|
||||
v = normalize(-view_pos_fs_in.xyz);
|
||||
|
||||
// Calculate the normal direction
|
||||
vec3 n = normalize(normal_fs_in);
|
||||
|
||||
// Base colors
|
||||
vec3 ka = vec3(0.1, 0.1, 0.1); // Ambient color
|
||||
vec3 kd = is_moon ? vec3(0.5, 0.45, 0.5) : vec3(0.2, 0.3, 0.8); // Diffuse color
|
||||
vec3 ks = vec3(1.0, 1.0, 1.0); // Specular color
|
||||
|
||||
// Compute the Blinn-Phong shading
|
||||
color = blinn_phong(ka, kd, ks, p, n, v, l);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
|
Reference in a new issue