17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-12 02:58:14 +01:00

Add the optional Radius, ShadeSelf, CastShadows and SoftFalloff of FreeSpotLight and make FalloffAngle 360 a point light

This commit is contained in:
2026-10-28 16:18:03 +01:00
parent 413cebed9c
commit c4e23932bf
25 changed files with 327 additions and 72 deletions

View File

@@ -3995,13 +3995,14 @@ void vulkan14_renderer::write_local_light(gl::light_element &Light, gfx::local_l
}
Light.color = Source.color;
Light.intensity = 1.0f;
Light.ambient = 0.0f;
// the sphere the light shines from, see gl::light_element
Light.ambient = (Source.soft_falloff ? -Source.radius : Source.radius);
// the shading takes the light to end at 1 / sqrt(quadratic)
Light.linear = 0.0f;
Light.quadratic = 1.0f / sq(std::max(Source.range, 0.01f));
Light.headlight_projection = glm::mat4{1.0f};
// no shadow map
Light.headlight_weights = glm::vec4{-1.0f, 0.0f, 0.0f, 0.0f};
// no shadow map; a light which casts no shadows has no contact shadows either
Light.headlight_weights = glm::vec4{-1.0f, (Source.cast_shadows ? 0.0f : 1.0f), 0.0f, 0.0f};
}
void vulkan14_renderer::headlight_projector(light_array::light_record const &Light, glm::dvec3 &Position, glm::mat3 &Rotation, glm::mat4 &Projection, float &Near, float &Fieldofview)

View File

@@ -225,27 +225,33 @@ void vulkan14_renderer::render_lamp_shadow(std::size_t const Slot, bool const Ve
{
cull = light_shadow_cull(m_context->scene.cull.lamps, m_lampscenerydrawn++, Global.gfx_gpucull_shadows_lamps);
}
auto const *owner{static_cast<TAnimModel const *>(slot.owner)};
// the model of the lamp is left out, unless its shadows are wanted (shadeself:): what is within the near plane of the map (the
// radius of the light) casts none even then
auto const *owner{slot.shade_self ? nullptr : static_cast<TAnimModel const *>(slot.owner)};
auto const nearplane{slot.nearplane};
if (walks_wanted())
{
// walked by a walker (gfx.vulkan.parallelpasses), its draws counted once it's done
fork_walk([target = m_draw->local_target, Vehicles, vehicles, Cab, owner, cull](vulkan14_renderer &Walker) {
fork_walk([target = m_draw->local_target, Vehicles, vehicles, Cab, owner, cull, nearplane](vulkan14_renderer &Walker) {
Walker.m_draw->local_target = target;
Walker.walk_lamp(Vehicles, vehicles, Cab, owner, cull);
Walker.walk_lamp(Vehicles, vehicles, Cab, owner, cull, nearplane);
}, walk_kind::lamp);
lamps.end_lamp(0);
}
else
{
walk_lamp(Vehicles, vehicles, Cab, owner, cull);
walk_lamp(Vehicles, vehicles, Cab, owner, cull, nearplane);
lamps.end_lamp(static_cast<std::uint32_t>(m_renderpass.draw_stats.drawcalls));
}
m_renderpass = m_colorpass;
}
// the walk of the map of a lamp set up by render_lamp_shadow()
void vulkan14_renderer::walk_lamp(bool const Vehicles, std::vector<TDynamicObject *> const &Dynamics, TDynamicObject *Cab, TAnimModel const *Owner, vk14::instance_cull *Cull)
void vulkan14_renderer::walk_lamp(bool const Vehicles, std::vector<TDynamicObject *> const &Dynamics, TDynamicObject *Cab, TAnimModel const *Owner, vk14::instance_cull *Cull, float const Near)
{
// the near plane of the map, for shadowcube.vert, in the scene block begin_local_shadow_target() uploads
auto const previousnear{scene_ubs.shadow_fit.y};
scene_ubs.shadow_fit.y = Near;
begin_local_shadow_target();
m_cubeshadows = true;
if (Vehicles)
@@ -271,6 +277,7 @@ void vulkan14_renderer::walk_lamp(bool const Vehicles, std::vector<TDynamicObjec
}
m_cubeshadows = false;
end_local_shadow_rendering();
scene_ubs.shadow_fit.y = previousnear;
}
void vulkan14_renderer::render_headlight_shadows()

View File

@@ -315,7 +315,7 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk
std::size_t m_helpgroups{0};
// the passes the walkers walk, as the main renderer walked them (render_shadows(), render_lamp_shadow(), render_headlight_shadow())
void walk_cascade(std::size_t const Index);
void walk_lamp(bool const Vehicles, std::vector<TDynamicObject *> const &Dynamics, TDynamicObject *Cab, TAnimModel const *Owner, vk14::instance_cull *Cull);
void walk_lamp(bool const Vehicles, std::vector<TDynamicObject *> const &Dynamics, TDynamicObject *Cab, TAnimModel const *Owner, vk14::instance_cull *Cull, float const Near);
void walk_headlight(TDynamicObject const *Owner, TDynamicObject *Cab, vk14::instance_cull *Cull);
// the walk lock taken by the main thread for the frame (walk_sync::open()) and the walkers given passes in it
bool m_walkwindow{false};