mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:47:44 +00:00
LibSoftGPU: Add sgi_dot
lambda
This function is used quite a bit during the lighting calculations, so it's a bit cleaner having it in a centralized spot instead of just arbitrarily calling `dot()` with numerous `FloatVector3` conversions.
This commit is contained in:
parent
fc8dd0bf68
commit
5a735602b0
1 changed files with 9 additions and 6 deletions
|
@ -828,6 +828,10 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto sgi_dot_operator = [](FloatVector3 const& d1, FloatVector3 const& d2) {
|
||||||
|
return AK::max(d1.dot(d2), 0.0f);
|
||||||
|
};
|
||||||
|
|
||||||
float vector_length = 0.0f;
|
float vector_length = 0.0f;
|
||||||
FloatVector3 vertex_to_light = sgi_arrow_operator(vertex.eye_coordinates, light.position, vector_length);
|
FloatVector3 vertex_to_light = sgi_arrow_operator(vertex.eye_coordinates, light.position, vector_length);
|
||||||
|
|
||||||
|
@ -843,12 +847,11 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
|
||||||
// Spotlight factor
|
// Spotlight factor
|
||||||
float spotlight_factor = 1.0f;
|
float spotlight_factor = 1.0f;
|
||||||
if (light.spotlight_cutoff_angle != 180.0f) {
|
if (light.spotlight_cutoff_angle != 180.0f) {
|
||||||
const auto spotlight_direction_normalized = light.spotlight_direction.normalized();
|
auto const vertex_to_light_dot_spotlight_direction = sgi_dot_operator(vertex_to_light, light.spotlight_direction.normalized());
|
||||||
const auto light_to_vertex_dot_normalized_spotlight_direction = spotlight_direction_normalized.dot(FloatVector3(vertex_to_light.x(), vertex_to_light.y(), vertex_to_light.z()));
|
auto const cos_spotlight_cutoff = AK::cos<float>(light.spotlight_cutoff_angle * AK::Pi<float> / 180.f);
|
||||||
const auto cos_spotlight_cutoff = AK::cos<float>(light.spotlight_cutoff_angle * AK::Pi<float> / 180.f);
|
|
||||||
|
|
||||||
if (light_to_vertex_dot_normalized_spotlight_direction >= cos_spotlight_cutoff)
|
if (vertex_to_light_dot_spotlight_direction >= cos_spotlight_cutoff)
|
||||||
spotlight_factor = AK::pow<float>(light_to_vertex_dot_normalized_spotlight_direction, light.spotlight_exponent);
|
spotlight_factor = AK::pow<float>(vertex_to_light_dot_spotlight_direction, light.spotlight_exponent);
|
||||||
else
|
else
|
||||||
spotlight_factor = 0.0f;
|
spotlight_factor = 0.0f;
|
||||||
}
|
}
|
||||||
|
@ -866,7 +869,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
|
||||||
auto const ambient_component = ambient * light.ambient_intensity;
|
auto const ambient_component = ambient * light.ambient_intensity;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
auto const normal_dot_vertex_to_light = vertex.normal.dot(FloatVector3(vertex_to_light.x(), vertex_to_light.y(), vertex_to_light.z()));
|
auto const normal_dot_vertex_to_light = sgi_dot_operator(vertex.normal, vertex_to_light);
|
||||||
auto const diffuse_component = ((diffuse * light.diffuse_intensity) * normal_dot_vertex_to_light).clamped(0.0f, 1.0f);
|
auto const diffuse_component = ((diffuse * light.diffuse_intensity) * normal_dot_vertex_to_light).clamped(0.0f, 1.0f);
|
||||||
|
|
||||||
FloatVector4 color = ambient_component;
|
FloatVector4 color = ambient_component;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue