Calculate light direction from position
This commit is contained in:
parent
62aa2fbc3b
commit
8ccc424b06
@ -130,9 +130,11 @@ internal FragmentResult phong_shader_fragment(void *shader,
|
|||||||
// Ambient term
|
// Ambient term
|
||||||
V3f intensity = num_mul_v3(g_ambient_light, model->material.ambient);
|
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);
|
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
|
// Diffuse term
|
||||||
f32 l_dot_n = dot_v3(norm, light_dir);
|
f32 l_dot_n = dot_v3(norm, light_dir);
|
||||||
@ -147,7 +149,9 @@ internal FragmentResult phong_shader_fragment(void *shader,
|
|||||||
// Specular term
|
// Specular term
|
||||||
V3f _2_l_dot_n_norm = num_mul_v3(norm, 2.0f * l_dot_n);
|
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);
|
V3f reflected = sub_v3(_2_l_dot_n_norm, light_dir);
|
||||||
|
normalise_v3(reflected);
|
||||||
V3f v = sub_v3(g_eye, data->position);
|
V3f v = sub_v3(g_eye, data->position);
|
||||||
|
normalise_v3(v);
|
||||||
f32 r_dot_v = dot_v3(reflected, v);
|
f32 r_dot_v = dot_v3(reflected, v);
|
||||||
if (r_dot_v <= 0.0f) {
|
if (r_dot_v <= 0.0f) {
|
||||||
goto RETURN_OUTPUT_COLOUR;
|
goto RETURN_OUTPUT_COLOUR;
|
||||||
@ -193,7 +197,7 @@ internal M4x4f get_projection_matrix(ProjectionType projection_type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal f32 get_intensity(const V3f *normal) {
|
internal f32 get_intensity(const V3f *normal) {
|
||||||
V3f light = g_directional_light.direction;
|
V3f light = g_directional_light.position;
|
||||||
normalise_v3(light);
|
normalise_v3(light);
|
||||||
|
|
||||||
f32 intensity = dot_v3((*normal), light);
|
f32 intensity = dot_v3((*normal), light);
|
||||||
|
Loading…
Reference in New Issue
Block a user