This repository has been archived on 2024-12-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2024CG-project-render/src/4_lit.fs

53 lines
1.6 KiB
GLSL

// Add (hard code) an orbiting point light to the scene. Light
// the scene using the Blinn-Phong Lighting Model.
// The point light should be 8 units above the planet and orbit with
// a radius of 10 units at a frequency of 1 revolution per 8 seconds.
// The base color of the planet and moon are the same as in 1_blue_and_gray.fs.
// For the specular exponent, pass p=1000 to blinn_phong().
// Since the light is white, ks=(1,1,1).
// Uniforms:
uniform mat4 view;
uniform mat4 proj;
uniform float animation_seconds;
uniform bool is_moon;
// Inputs:
in vec3 sphere_fs_in;
in vec3 normal_fs_in;
in vec4 pos_fs_in;
in vec4 view_pos_fs_in;
// Outputs:
out vec3 color;
// expects: PI, blinn_phong
void main()
{
/////////////////////////////////////////////////////////////////////////////
// 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 = (view * vec4(vec3(x, h, z), 1.0)).xyz;
// Calculate the light direction
vec3 l = normalize(light_pos - view_pos_fs_in.xyz);
// Calculate the view direction
vec3 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);
/////////////////////////////////////////////////////////////////////////////
}