Compare commits

..

3 Commits

3 changed files with 15 additions and 11 deletions

View File

@ -40,9 +40,9 @@ int main(void) {
PhongMaterial material = {
.ambient = 0.3f,
.diffuse = 1.0f,
.specular = 0.1f,
.shininess = 0.8f,
.diffuse = 1.5f,
.specular = 0.5f,
.shininess = 0.1f,
};
obj.material = material;

View File

@ -33,11 +33,11 @@ struct phong_material {
f32 shininess;
};
typedef struct directional_light DirectionalLight;
struct directional_light {
typedef struct point_light PointLight;
struct point_light {
V3f diffuse_intensity;
V3f specular_intensity;
V3f direction;
V3f position;
};
typedef struct model Model;

View File

@ -22,10 +22,10 @@ internal Shader perspective = {0};
internal Shader orthographic = {0};
internal V3f g_ambient_light = {0.6f, 0.45f, 0.55f};
internal DirectionalLight g_directional_light = {
internal PointLight g_directional_light = {
.diffuse_intensity = {0.9f, 1.0f, 1.0f},
.specular_intensity = {1.0f, 0.8f, 2.0f},
.direction = {0.0f, 0.0f, 1.45f},
.position = {1.05f, 0.9f, 1.2f},
};
internal V3f g_eye = {0.2f, 0.1f, 0.75f};
internal V3f g_target = {0};
@ -130,9 +130,11 @@ internal FragmentResult phong_shader_fragment(void *shader,
// Ambient term
V3f intensity = num_mul_v3(g_ambient_light, model->material.ambient);
V4f hdir = V3_to_V4(g_directional_light.direction);
V4f hdir = V3_to_V4(g_directional_light.position);
hdir = mat4x4_mul_vec4(matrix, hdir);
V3f light_dir = project_vec4(hdir);
V3f light_pos = project_vec4(hdir);
normalise_v3(light_pos);
V3f light_dir = sub_v3(light_pos, data->position);
// Diffuse term
f32 l_dot_n = dot_v3(norm, light_dir);
@ -147,7 +149,9 @@ internal FragmentResult phong_shader_fragment(void *shader,
// Specular term
V3f _2_l_dot_n_norm = num_mul_v3(norm, 2.0f * l_dot_n);
V3f reflected = sub_v3(_2_l_dot_n_norm, light_dir);
normalise_v3(reflected);
V3f v = sub_v3(g_eye, data->position);
normalise_v3(v);
f32 r_dot_v = dot_v3(reflected, v);
if (r_dot_v <= 0.0f) {
goto RETURN_OUTPUT_COLOUR;
@ -193,7 +197,7 @@ internal M4x4f get_projection_matrix(ProjectionType projection_type) {
}
internal f32 get_intensity(const V3f *normal) {
V3f light = g_directional_light.direction;
V3f light = g_directional_light.position;
normalise_v3(light);
f32 intensity = dot_v3((*normal), light);