mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-06 02:18:35 +01:00
Draw the cab probe with all the lights of the cab
This commit is contained in:
@@ -73,7 +73,8 @@ void cab_probe::release()
|
||||
m_masked = false;
|
||||
}
|
||||
|
||||
bool cab_probe::update_wanted(TDynamicObject const *Vehicle, TModel3d const *Cab, glm::vec3 const &Center, glm::vec3 const &Extent, gfx::local_lights::light const *Lamp, unsigned int const Framestamp)
|
||||
bool cab_probe::update_wanted(TDynamicObject const *Vehicle, TModel3d const *Cab, glm::vec3 const &Center, glm::vec3 const &Extent, std::vector<gfx::local_lights::cab_light> const &Lights,
|
||||
unsigned int const Framestamp)
|
||||
{
|
||||
auto const level{std::clamp(Global.gfx_cabprobe, 0, 3)};
|
||||
if (level != m_level)
|
||||
@@ -92,7 +93,12 @@ bool cab_probe::update_wanted(TDynamicObject const *Vehicle, TModel3d const *Cab
|
||||
m_masked = false;
|
||||
return false;
|
||||
}
|
||||
auto const lamp{Lamp != nullptr ? Lamp->color : glm::vec3{0.f}};
|
||||
// the lights the probe is drawn with, together: one of them switched or dimmed changes it
|
||||
glm::vec3 lamp{0.f};
|
||||
for (std::size_t idx = 0; idx < std::min(Lights.size(), gl::MAX_CAB_PROBE_LAMPS); ++idx)
|
||||
{
|
||||
lamp += Lights[idx].source.color;
|
||||
}
|
||||
auto const lampchange{glm::length(lamp - m_lamp)};
|
||||
auto const lampchanged{(lampchange > 0.f) && ((max_component(m_lamp) <= 0.f) || (max_component(lamp) <= 0.f) || (lampchange > LAMP_CHANGED * glm::length(m_lamp)))};
|
||||
if ((Vehicle != m_vehicle) || (Cab != m_cab) || (Center != m_center) || (Extent != m_extent))
|
||||
@@ -120,19 +126,28 @@ bool cab_probe::update_wanted(TDynamicObject const *Vehicle, TModel3d const *Cab
|
||||
return true;
|
||||
}
|
||||
|
||||
void cab_probe::setup_drawing(gl::scene_ubs &Scene, gfx::local_lights::light const *Lamp, glm::vec3 const &Lamplocal, bool const Shadows, glm::vec4 const &Shadowweights) const
|
||||
void cab_probe::setup_drawing(gl::scene_ubs &Scene, std::vector<gfx::local_lights::cab_light> const &Lights, gfx::local_shadows const &Shadows, TDynamicObject const *Vehicle) const
|
||||
{
|
||||
if (Lamp == nullptr)
|
||||
for (std::size_t idx = 0; idx < gl::MAX_CAB_PROBE_LAMPS; ++idx)
|
||||
{
|
||||
Scene.cab_probe_lamp = glm::vec4{0.f};
|
||||
Scene.cab_probe_lamp_color = glm::vec4{0.f};
|
||||
Scene.cab_probe_lamp_shadow = glm::vec4{0.f};
|
||||
return;
|
||||
if (idx >= Lights.size())
|
||||
{
|
||||
// the end of the lights
|
||||
Scene.cab_probe_lamp[idx] = glm::vec4{0.f};
|
||||
Scene.cab_probe_lamp_color[idx] = glm::vec4{0.f};
|
||||
continue;
|
||||
}
|
||||
auto const &light{Lights[idx]};
|
||||
// as the light buffer has it (Write_Local_Light()): the shading takes the light to end at 1 / sqrt(quadratic)
|
||||
Scene.cab_probe_lamp[idx] = glm::vec4{light.local - m_center, 1.f / sq(std::max(light.source.range, 0.01f))};
|
||||
Scene.cab_probe_lamp_cone[idx] = glm::vec4{light.local_direction, light.source.cos_outer};
|
||||
Scene.cab_probe_lamp_shape[idx] = glm::vec4{light.source.cos_inner, (light.source.soft_falloff ? -light.source.radius : light.source.radius), 0.f, 0.f};
|
||||
// with the shadow map of the light, or of the closest light with one
|
||||
auto const slot{Shadows.cab_slot_of(Vehicle, light)};
|
||||
Scene.cab_probe_lamp_color[idx] = glm::vec4{light.source.color, (slot >= 0 ? 1.f : 0.f)};
|
||||
Scene.cab_probe_lamp_shadow[idx] = (slot >= 0 ? Shadows.weights(static_cast<std::size_t>(slot)) : glm::vec4{0.f});
|
||||
Scene.cab_probe_lamp_map[idx] = glm::vec4{(slot >= 0 ? Shadows.cab(static_cast<std::size_t>(slot)).lamp : light.local) - m_center, 0.f};
|
||||
}
|
||||
// as the light buffer has it (Write_Local_Light()): the shading takes the light to end at 1 / sqrt(quadratic)
|
||||
Scene.cab_probe_lamp = glm::vec4{Lamplocal - m_center, 1.f / sq(std::max(Lamp->range, 0.01f))};
|
||||
Scene.cab_probe_lamp_color = glm::vec4{Lamp->color, Shadows ? 1.f : 0.f};
|
||||
Scene.cab_probe_lamp_shadow = Shadowweights;
|
||||
}
|
||||
|
||||
void cab_probe::setup_sun(gl::scene_ubs &Scene, TDynamicObject const *Vehicle, glm::vec3 const &Tosun, glm::vec3 const &Sunlight, glm::dvec3 const &Camera) const
|
||||
|
||||
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "gl/ubo.h"
|
||||
#include "rendering/common/locallights.h"
|
||||
#include "rendering/common/localshadows.h"
|
||||
|
||||
class TDynamicObject;
|
||||
class TModel3d;
|
||||
@@ -25,8 +26,8 @@ namespace gfx
|
||||
// the probe of the occupied cab (Global.gfx_cabprobe, the stage A4 of claude/renderers-plan.md), the part shared by the renderers;
|
||||
// the backend (opengl46_cab_probe, vk14::cab_probe_maps) keeps the maps and draws to them through the gpu_* methods.
|
||||
// - two cube maps drawn from the middle of the box of the cab model (mdKabina), in the space of the model, so they stay right while
|
||||
// the vehicle moves and turns: the light of the cab lamp the cab reflects (with the shadow map of the lamp) and the light of what
|
||||
// glows in it, and the albedo of the cab. both are cleared to nothing and premultiplied by the share of the direction the cab
|
||||
// the vehicle moves and turns: the light of the lights of the cab (the lamp, the light points of the cab model, the brightest
|
||||
// gl::MAX_CAB_PROBE_LAMPS of them, with their shadow maps) the cab reflects and the light of what glows in it, and the albedo of the cab. both are cleared to nothing and premultiplied by the share of the direction the cab
|
||||
// fills, which is in their alpha (the glasses aren't drawn: through them the cab shows nothing), and have mipmaps;
|
||||
// - the six faces are drawn at once (a geometry shader with opengl, multiview with vulkan) by the programs of the probe
|
||||
// (cabprobe.vert, cabprobe.frag), every few frames (Global.gfx_cabprobe_interval: the moving parts of the cab, the lights of the
|
||||
@@ -53,12 +54,13 @@ class cab_probe
|
||||
// size of a face of the maps of the level (Global.gfx_cabprobe), 0 for none
|
||||
static int size_of(int const Level);
|
||||
// whether the probe is to be drawn in this frame. Vehicle: the occupied vehicle whose cab is drawn (nullptr: none), Cab its cab
|
||||
// model, Center and Extent the box of the model (model space); Lamp the cab lamp when it's a light of the frame (nullptr: none).
|
||||
// (re)makes the maps when the level changed
|
||||
bool update_wanted(TDynamicObject const *Vehicle, TModel3d const *Cab, glm::vec3 const &Center, glm::vec3 const &Extent, gfx::local_lights::light const *Lamp, unsigned int const Framestamp);
|
||||
// the fields of the block of the scene the drawing of the probe reads: the cab lamp (Lamp, at Lamplocal in the space of the cab
|
||||
// model, nullptr: none) with its shadow map when Shadows (Shadowweights: the headlight_weights of the map)
|
||||
void setup_drawing(gl::scene_ubs &Scene, gfx::local_lights::light const *Lamp, glm::vec3 const &Lamplocal, bool const Shadows, glm::vec4 const &Shadowweights) const;
|
||||
// model, Center and Extent the box of the model (model space); Lights the lights of the cab of the frame, the brightest first
|
||||
// (empty: none). (re)makes the maps when the level changed
|
||||
bool update_wanted(TDynamicObject const *Vehicle, TModel3d const *Cab, glm::vec3 const &Center, glm::vec3 const &Extent, std::vector<gfx::local_lights::cab_light> const &Lights,
|
||||
unsigned int const Framestamp);
|
||||
// the fields of the block of the scene the drawing of the probe reads: the lights of the cab of Vehicle (Lights, the brightest first)
|
||||
// with the shadow maps Shadows holds for them
|
||||
void setup_drawing(gl::scene_ubs &Scene, std::vector<gfx::local_lights::cab_light> const &Lights, gfx::local_shadows const &Shadows, TDynamicObject const *Vehicle) const;
|
||||
// the fields of the block of the scene the drawing of the probe takes the sun with: Vehicle the vehicle whose cab is drawn, Tosun the
|
||||
// direction towards the sun (the moon), world space, Sunlight its light as the shading gets it (the colour of the light buffer times
|
||||
// its intensity), Camera the camera of the main view (world space). no sun until the mask holds the cab
|
||||
@@ -123,7 +125,7 @@ class cab_probe
|
||||
TModel3d const *m_cab{nullptr};
|
||||
glm::vec3 m_center{0.f};
|
||||
glm::vec3 m_extent{0.f};
|
||||
// the light of the cab lamp the probe was drawn with, 0 without the lamp
|
||||
// the light of the lights of the cab the probe was drawn with (their sum), 0 without them
|
||||
glm::vec3 m_lamp{0.f};
|
||||
unsigned int m_drawnframe{0};
|
||||
// statistics
|
||||
|
||||
@@ -350,6 +350,7 @@ void gfx::local_lights::gather_cab_lights(gfx::geometrybank_manager const &Geome
|
||||
cab_light cablight;
|
||||
cablight.source = m_lights[idx];
|
||||
cablight.local = glm::vec3{m_lights[idx].position};
|
||||
cablight.local_direction = m_lights[idx].direction;
|
||||
cablight.source.position = vehicle->GetWorldPosition(m_lights[idx].position);
|
||||
auto const direction{glm::vec3{rotation * glm::dvec3{m_lights[idx].direction}}};
|
||||
cablight.source.direction = (glm::length2(direction) > 0.f ? glm::normalize(direction) : glm::vec3{0.f, -1.f, 0.f});
|
||||
|
||||
@@ -87,17 +87,13 @@ class local_lights
|
||||
{
|
||||
light source;
|
||||
glm::vec3 local{0.f};
|
||||
glm::vec3 local_direction{0.f, -1.f, 0.f}; // the axis of its cone in the space of the cab model
|
||||
};
|
||||
// the lights of the occupied cab which are on, when the cab is drawn, the brightest first; empty otherwise
|
||||
std::vector<cab_light> const &cab_lights() const
|
||||
{
|
||||
return m_cablights;
|
||||
}
|
||||
// the brightest light of the cab, which lights its probe; nullptr when there is none
|
||||
cab_light const *cab_principal() const
|
||||
{
|
||||
return m_cablights.empty() ? nullptr : &m_cablights.front();
|
||||
}
|
||||
// the vehicle of the lights of the cab, when any of them is on
|
||||
TDynamicObject const *cab_lamp_vehicle() const
|
||||
{
|
||||
|
||||
@@ -6320,16 +6320,15 @@ void opengl46_renderer::Render_cab_probe()
|
||||
glm::vec3 extent{0.f};
|
||||
if ((vehicle != nullptr) && (false == m_locallights.cab_bounds(vehicle->mdKabina, m_geometry, center, extent)))
|
||||
vehicle = nullptr;
|
||||
// the brightest light of the cab lights the probe when it's a light of the frame
|
||||
auto const *principal{(vehicle != nullptr) && (m_locallights.cab_lamp_vehicle() == vehicle) ? m_locallights.cab_principal() : nullptr};
|
||||
auto const *lamp{principal != nullptr ? &principal->source : nullptr};
|
||||
if (false == m_cabprobe.update_wanted(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), center, extent, lamp, m_framestamp))
|
||||
// the lights of the cab light the probe when they're lights of the frame
|
||||
std::vector<gfx::local_lights::cab_light> const nolights;
|
||||
auto const &lights{(vehicle != nullptr) && (m_locallights.cab_lamp_vehicle() == vehicle) ? m_locallights.cab_lights() : nolights};
|
||||
if (false == m_cabprobe.update_wanted(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), center, extent, lights, m_framestamp))
|
||||
return;
|
||||
|
||||
glDebug("render cab probe");
|
||||
// the light with its shadow map, when the map holds the shadows of the light where it is
|
||||
auto const slot{principal != nullptr ? m_localshadows.cab_slot_of(vehicle, *principal) : -1};
|
||||
m_cabprobe.setup_drawing(scene_ubs, lamp, (principal != nullptr ? principal->local : glm::vec3{0.f}), (slot >= 0), (slot >= 0 ? m_localshadows.weights(static_cast<std::size_t>(slot)) : glm::vec4{0.f}));
|
||||
// the lights with their shadow maps, where the maps hold their shadows
|
||||
m_cabprobe.setup_drawing(scene_ubs, lights, m_localshadows, vehicle);
|
||||
// the sun coming in through the windows, as the shading of the last frame got it
|
||||
m_cabprobe.setup_sun(scene_ubs, vehicle, -m_sunlight.direction, glm::vec3{light_data.lights[0].color} * light_data.lights[0].intensity, m_colorpass.pass_camera.position());
|
||||
scene_ubo->update(scene_ubs);
|
||||
|
||||
@@ -348,10 +348,10 @@ void vulkan14_renderer::render_cab_probe()
|
||||
{
|
||||
vehicle = nullptr;
|
||||
}
|
||||
// the brightest light of the cab lights the probe when it's a light of the frame
|
||||
auto const *principal{(vehicle != nullptr) && (m_locallights.cab_lamp_vehicle() == vehicle) ? m_locallights.cab_principal() : nullptr};
|
||||
auto const *lamp{principal != nullptr ? &principal->source : nullptr};
|
||||
if (false == probe.update_wanted(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), center, extent, lamp, m_framestamp))
|
||||
// the lights of the cab light the probe when they're lights of the frame
|
||||
std::vector<gfx::local_lights::cab_light> const nolights;
|
||||
auto const &lights{(vehicle != nullptr) && (m_locallights.cab_lamp_vehicle() == vehicle) ? m_locallights.cab_lights() : nolights};
|
||||
if (false == probe.update_wanted(vehicle, (vehicle != nullptr ? vehicle->mdKabina : nullptr), center, extent, lights, m_framestamp))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -361,9 +361,8 @@ void vulkan14_renderer::render_cab_probe()
|
||||
return;
|
||||
}
|
||||
ctx.passes.begin_pass("cab probe");
|
||||
// the light with its shadow map, when the map holds the shadows of the light where it is
|
||||
auto const slot{principal != nullptr ? scene.lamps.cab_slot_of(vehicle, *principal) : -1};
|
||||
probe.setup_drawing(scene_ubs, lamp, (principal != nullptr ? principal->local : glm::vec3{0.f}), (slot >= 0), (slot >= 0 ? scene.lamps.weights(static_cast<std::size_t>(slot)) : glm::vec4{0.f}));
|
||||
// the lights with their shadow maps, where the maps hold their shadows
|
||||
probe.setup_drawing(scene_ubs, lights, scene.lamps, vehicle);
|
||||
// the sun coming in through the windows, as the shading of the last frame got it. the mask is read once it was copied
|
||||
probe.setup_sun(scene_ubs, vehicle, -m_sunlight.direction, glm::vec3{light_data.lights[0].color} * light_data.lights[0].intensity, m_colorpass.pass_camera.position());
|
||||
if (probe.mask_map() == nullptr)
|
||||
|
||||
@@ -889,6 +889,7 @@ std::string binding_preamble(bool const Raytracing)
|
||||
define("MAX_CASCADES", static_cast<unsigned int>(gl::MAX_CASCADES), "U");
|
||||
define("MAX_PARAMS", static_cast<unsigned int>(gl::MAX_PARAMS), "U");
|
||||
define("MAX_HEADLIGHT_SHADOWS", static_cast<unsigned int>(gl::MAX_HEADLIGHT_SHADOWS), "U");
|
||||
define("MAX_CAB_PROBE_LAMPS", static_cast<unsigned int>(gl::MAX_CAB_PROBE_LAMPS), "U");
|
||||
define("CLUSTER_GRID_X", gl::CLUSTER_GRID_X);
|
||||
define("CLUSTER_GRID_Y", gl::CLUSTER_GRID_Y);
|
||||
define("CLUSTER_GRID_Z", gl::CLUSTER_GRID_Z);
|
||||
|
||||
Reference in New Issue
Block a user