17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 05:09:20 +02:00

Cast shadows of vehicle headlights from the scene in their beam in the GL 4.6 renderer

This commit is contained in:
2026-10-16 14:13:36 +02:00
parent 466cb5339e
commit d509775269
10 changed files with 612 additions and 50 deletions

View File

@@ -61,6 +61,8 @@ void gl::glsl_common_setup()
"#define SKY_VIEW_TEX " + std::to_string(SKY_VIEW_TEX) + "\n" +
"#define LOCAL_SHADOW_TEX " + std::to_string(LOCAL_SHADOW_TEX) + "\n" +
"#define LOCAL_SHADOW_LAMPS_TEX " + std::to_string(LOCAL_SHADOW_LAMPS_TEX) + "\n" +
"#define HEADLIGHT_SHADOW_TEX " + std::to_string(HEADLIGHT_SHADOW_TEX) + "\n" +
"#define MAX_HEADLIGHT_SHADOWS " + std::to_string(MAX_HEADLIGHT_SHADOWS) + "U\n" +
R"STRING(
const uint LIGHT_SPOT = 0U;
const uint LIGHT_POINT = 1U;
@@ -196,6 +198,9 @@ void gl::glsl_common_setup()
vec4 wiper_pos;
vec4 wiper_timer_out;
vec4 wiper_timer_return;
// shadow maps of the headlights, see gl::scene_ubs
mat4 headlight_shadow[MAX_HEADLIGHT_SHADOWS];
vec4 headlight_shadow_params[MAX_HEADLIGHT_SHADOWS];
};
#ifdef STAGE_VERTEX

View File

@@ -62,6 +62,9 @@ namespace gl
const size_t LOCAL_SHADOW_TEX = MAX_TEXTURES + HELPER_TEXTURES + 1;
// the same for the lamps of scenery models (a texture of its own: the maps have another size)
const size_t LOCAL_SHADOW_LAMPS_TEX = MAX_TEXTURES + HELPER_TEXTURES + 2;
// shadow maps of the headlights of vehicles (2d array, depth compared; opengl46_local_shadows), and how many of them there may be
const size_t HEADLIGHT_SHADOW_TEX = MAX_TEXTURES + HELPER_TEXTURES + 3;
const size_t MAX_HEADLIGHT_SHADOWS = 4;
struct scene_ubs
{
@@ -74,9 +77,14 @@ namespace gl
glm::vec4 wiper_pos;
glm::vec4 wiper_timer_out;
glm::vec4 wiper_timer_return;
// view space of the pass to the space of the shadow map of a set of headlights (HEADLIGHTS lights with headlight_weights.w
// above 0 read the map w - 1): x, y 0..1 across the map, z / w the depth of the map, w the distance along the axis of the
// projector. and x: size of a texel of the map one metre from the projector, y: radius of the filter in texels
glm::mat4 headlight_shadow[MAX_HEADLIGHT_SHADOWS];
glm::vec4 headlight_shadow_params[MAX_HEADLIGHT_SHADOWS];
};
static_assert(sizeof(scene_ubs) == 400, "bad size of ubs");
static_assert(sizeof(scene_ubs) == 400 + 80 * MAX_HEADLIGHT_SHADOWS, "bad size of ubs");
const size_t MAX_PARAMS = 3;
@@ -140,7 +148,8 @@ namespace gl
float intensity;
float ambient;
// HEADLIGHTS: view space to the space of the beam texture, and the weights of its channels.
// HEADLIGHTS: view space to the space of the beam texture, and the weights of its channels; w: 1 + the shadow map of the
// headlights (scene_ubs::headlight_shadow), 0 when they have none.
// SPOT and POINT (lamps): view space to the space of the cube shadow map of the lamp (origin at the lamp), and
// x: layer of the cube map array the map is in, below 0 when the lamp has no shadows; y: near plane of the map;
// z: size of a texel of the map one metre from the lamp; w: radius of the filter, in texels. the map is in the array of