LibGL+LibSoftGPU: Calculate spotlight cutoff angle as degrees

We were storing the radians but never using that value in the GPU. We
now directly use the degrees value.
This commit is contained in:
Jelle Raaijmakers 2022-01-13 03:01:42 +01:00 committed by Andreas Kling
parent 8c28d167c9
commit 9d4c2f6308
Notes: sideshowbarker 2024-07-17 20:59:47 +09:00
3 changed files with 1 additions and 6 deletions

View file

@ -3007,7 +3007,6 @@ void SoftwareGLContext::sync_light_state()
light.spotlight_direction = current_light_state.spotlight_direction;
light.spotlight_exponent = current_light_state.spotlight_exponent;
light.spotlight_cutoff_angle = current_light_state.spotlight_cutoff_angle;
light.spotlight_cutoff_angle_rads = current_light_state.spotlight_cutoff_angle_rads;
light.constant_attenuation = current_light_state.constant_attenuation;
light.linear_attenuation = current_light_state.linear_attenuation;
light.quadratic_attenuation = current_light_state.quadratic_attenuation;
@ -3119,7 +3118,6 @@ void SoftwareGLContext::gl_lightf(GLenum light, GLenum pname, GLfloat param)
break;
case GL_SPOT_CUTOFF:
light_state.spotlight_cutoff_angle = param;
light_state.spotlight_cutoff_angle_rads = param * (AK::Pi<float> / 180.0f);
break;
default:
VERIFY_NOT_REACHED();
@ -3165,7 +3163,6 @@ void SoftwareGLContext::gl_lightfv(GLenum light, GLenum pname, GLfloat const* pa
break;
case GL_SPOT_CUTOFF:
light_state.spotlight_cutoff_angle = *params;
light_state.spotlight_cutoff_angle_rads = *params * (AK::Pi<float> / 180.0f);
break;
case GL_SPOT_DIRECTION: {
FloatVector4 direction_vector = { params[0], params[1], params[2], 0.0f };

View file

@ -698,7 +698,7 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
if (light.spotlight_cutoff_angle != 180.0f) {
const auto spotlight_direction_normalized = 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()));
const auto cos_spotlight_cutoff = AK::cos<float>(light.spotlight_cutoff_angle);
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)
spotlight_factor = AK::pow<float>(light_to_vertex_dot_normalized_spotlight_direction, light.spotlight_exponent);

View file

@ -28,8 +28,6 @@ struct Light {
float constant_attenuation { 1.0f }; // This is referred to `k0i` in the OpenGL spec
float linear_attenuation { 0.0f }; // This is referred to `k1i` in the OpenGL spec
float quadratic_attenuation { 0.0f }; // This is referred to `k2i` in the OpenGL spec
float spotlight_cutoff_angle_rads { AK::Pi<float> / 180.0f };
};
}