mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 13:59:12 +01:00
Light the cab with the sun coming in through its windows
This commit is contained in:
@@ -82,6 +82,7 @@ void opengl46_cab_probe::bind()
|
||||
{
|
||||
glBindTextureUnit(gl::CAB_PROBE_TEX, (m_light != 0) ? m_light : m_empty);
|
||||
glBindTextureUnit(gl::CAB_PROBE_ALBEDO_TEX, (m_albedo != 0) ? m_albedo : m_empty);
|
||||
glBindTextureUnit(gl::CAB_PROBE_MASK_TEX, (m_mask != 0) ? m_mask : m_empty);
|
||||
if (m_sh)
|
||||
m_sh->bind_base();
|
||||
}
|
||||
@@ -91,6 +92,13 @@ bool opengl46_cab_probe::gpu_allocate(int const Size)
|
||||
m_light = make_cube(GL_RGBA16F, Size, true);
|
||||
m_albedo = make_cube(GL_RGBA8, Size, true);
|
||||
m_depth = make_cube(GL_DEPTH_COMPONENT32F, Size, false);
|
||||
// the mask: the level of the albedo of at most CAB_PROBE_MASK_SIZE pixels a face, as mask_size() has it once the size is set
|
||||
auto masksize{Size};
|
||||
while (masksize > static_cast<int>(gl::CAB_PROBE_MASK_SIZE))
|
||||
masksize >>= 1;
|
||||
m_mask = make_cube(GL_RGBA8, std::max(masksize, 1), false);
|
||||
glTextureParameteri(m_mask, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(m_mask, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// all the faces at once, the geometry shader picks the face
|
||||
glCreateFramebuffers(1, &m_framebuffer);
|
||||
glNamedFramebufferTexture(m_framebuffer, GL_COLOR_ATTACHMENT0, m_light, 0);
|
||||
@@ -106,7 +114,7 @@ void opengl46_cab_probe::gpu_release()
|
||||
{
|
||||
if (m_framebuffer != 0)
|
||||
glDeleteFramebuffers(1, &m_framebuffer);
|
||||
for (auto *texture : {&m_light, &m_albedo, &m_depth})
|
||||
for (auto *texture : {&m_light, &m_albedo, &m_depth, &m_mask})
|
||||
{
|
||||
if (*texture != 0)
|
||||
glDeleteTextures(1, texture);
|
||||
@@ -143,6 +151,9 @@ void opengl46_cab_probe::gpu_end()
|
||||
gl::framebuffer::unbind();
|
||||
glGenerateTextureMipmap(m_light);
|
||||
glGenerateTextureMipmap(m_albedo);
|
||||
// where the windows are, for the next drawing
|
||||
auto const masksize{mask_size()};
|
||||
glCopyImageSubData(m_albedo, GL_TEXTURE_CUBE_MAP, mask_level(), 0, 0, 0, m_mask, GL_TEXTURE_CUBE_MAP, 0, 0, 0, 0, masksize, masksize, 6);
|
||||
// the light the cab lights itself with again, from a small level of the light reflected
|
||||
glBindTextureUnit(0, m_light);
|
||||
glProgramUniform2i(*m_sh_program, SH_LEVEL_LOCATION, sh_level(), sh_size());
|
||||
|
||||
@@ -28,8 +28,8 @@ class opengl46_cab_probe : public gfx::cab_probe
|
||||
|
||||
// creates the programs, the stand-ins and the storage of the spherical harmonics. throws gl::shader_exception
|
||||
void init();
|
||||
// puts the maps (or the stand-ins) on their texture units, gl::CAB_PROBE_TEX and gl::CAB_PROBE_ALBEDO_TEX, and the spherical
|
||||
// harmonics on gl::CAB_PROBE_SSBO_BINDING. once per context and frame
|
||||
// puts the maps (or the stand-ins) on their texture units, gl::CAB_PROBE_TEX, gl::CAB_PROBE_ALBEDO_TEX and the mask on
|
||||
// gl::CAB_PROBE_MASK_TEX, and the spherical harmonics on gl::CAB_PROBE_SSBO_BINDING. once per context and frame
|
||||
void bind();
|
||||
// program of the probe, of the alpha tested materials when Alpha
|
||||
gl::program &program(bool const Alpha)
|
||||
@@ -60,6 +60,8 @@ class opengl46_cab_probe : public gfx::cab_probe
|
||||
GLuint m_albedo{0};
|
||||
GLuint m_depth{0};
|
||||
GLuint m_framebuffer{0};
|
||||
// the copy of a small level of the albedo of the last drawing, which the next one reads to tell where the windows are
|
||||
GLuint m_mask{0};
|
||||
// stand-ins: a cube map of 1x1 faces of nothing, a 1x1 white texture
|
||||
GLuint m_empty{0};
|
||||
GLuint m_white{0};
|
||||
|
||||
@@ -1661,7 +1661,7 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
}
|
||||
// the reflections: the ground below the horizon of the environment map, and the screen space ones set up for the colour
|
||||
// pass of the main view only
|
||||
scene_ubs.env_params = glm::vec4{Global.gfx_ambient_groundalbedo, 0.f, 0.f, 0.f};
|
||||
scene_ubs.env_params = glm::vec4{Global.gfx_ambient_groundalbedo, 0.f, Global.gfx_interior_bounce, 0.f};
|
||||
gfx::screen_reflections::clear(scene_ubs);
|
||||
// the occlusion of the sky by the scenery, seen from the camera of the view
|
||||
m_skyocclusion.setup_scene(scene_ubs, m_colorpass.pass_camera.position());
|
||||
@@ -4593,7 +4593,7 @@ void opengl46_renderer::Setup_Ao_Lighting( viewport_config &Viewport )
|
||||
// the compute passes leave the units of the textures to be bound anew
|
||||
::glBindTextureUnit( gl::SCENE_DEPTH_TEX, Viewport.clusters_depth_tex->id );
|
||||
::glBindTextureUnit( gl::SCENE_AO_TEX, Viewport.ssao_blur_tex->id );
|
||||
scene_ubs.ao_params = glm::vec4{ 1.f, Global.gfx_postfx_ao_strength, 0.f, 0.f };
|
||||
scene_ubs.ao_params = glm::vec4{ 1.f, Global.gfx_postfx_ao_strength, Global.gfx_postfx_ao_cab, 0.f };
|
||||
scene_ubo->update( scene_ubs );
|
||||
m_aolighting = true;
|
||||
}
|
||||
@@ -6319,6 +6319,8 @@ void opengl46_renderer::Render_cab_probe()
|
||||
// the lamp with its shadow map, when the map holds the shadows of the lamp where it is
|
||||
auto const shadows{(lamp != nullptr) && m_localshadows.ready(vehicle) && (m_localshadows.lamp() == m_locallights.cab_lamp_local())};
|
||||
m_cabprobe.setup_drawing(scene_ubs, lamp, m_locallights.cab_lamp_local(), shadows, m_localshadows.weights());
|
||||
// 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);
|
||||
// the cab drawn by the colour mode with the programs of the probe. the camera is put at the vehicle, which Render_cab() places
|
||||
// the cab relative to, and the modelview takes the cab model to the space of the probe
|
||||
|
||||
Reference in New Issue
Block a user