mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Shadow mapping render pass (#11244)
Co-authored-by: x2048 <codeforsmile@gmail.com>
This commit is contained in:
parent
46f42e15c4
commit
c47313db65
35 changed files with 2624 additions and 38 deletions
|
@ -738,6 +738,7 @@ protected:
|
|||
const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
|
||||
void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
||||
const CameraOrientation &cam);
|
||||
void updateShadows();
|
||||
|
||||
// Misc
|
||||
void limitFps(FpsControl *fps_timings, f32 *dtime);
|
||||
|
@ -3831,13 +3832,20 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||
*/
|
||||
runData.update_draw_list_timer += dtime;
|
||||
|
||||
float update_draw_list_delta = 0.2f;
|
||||
if (ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer())
|
||||
update_draw_list_delta = shadow->getUpdateDelta();
|
||||
|
||||
v3f camera_direction = camera->getDirection();
|
||||
if (runData.update_draw_list_timer >= 0.2
|
||||
if (runData.update_draw_list_timer >= update_draw_list_delta
|
||||
|| runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2
|
||||
|| m_camera_offset_changed) {
|
||||
|
||||
runData.update_draw_list_timer = 0;
|
||||
client->getEnv().getClientMap().updateDrawList();
|
||||
runData.update_draw_list_last_cam_dir = camera_direction;
|
||||
|
||||
updateShadows();
|
||||
}
|
||||
|
||||
m_game_ui->update(*stats, client, draw_control, cam, runData.pointed_old, gui_chat_console, dtime);
|
||||
|
@ -3968,7 +3976,34 @@ inline void Game::updateProfilerGraphs(ProfilerGraph *graph)
|
|||
graph->put(values);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Shadows
|
||||
*****************************************************************************/
|
||||
void Game::updateShadows()
|
||||
{
|
||||
ShadowRenderer *shadow = RenderingEngine::get_shadow_renderer();
|
||||
if (!shadow)
|
||||
return;
|
||||
|
||||
float in_timeofday = fmod(runData.time_of_day_smooth, 1.0f);
|
||||
|
||||
float timeoftheday = fmod(getWickedTimeOfDay(in_timeofday) + 0.75f, 0.5f) + 0.25f;
|
||||
const float offset_constant = 10000.0f;
|
||||
|
||||
v3f light(0.0f, 0.0f, -1.0f);
|
||||
light.rotateXZBy(90);
|
||||
light.rotateXYBy(timeoftheday * 360 - 90);
|
||||
light.rotateYZBy(sky->getSkyBodyOrbitTilt());
|
||||
|
||||
v3f sun_pos = light * offset_constant;
|
||||
|
||||
if (shadow->getDirectionalLightCount() == 0)
|
||||
shadow->addDirectionalLight();
|
||||
shadow->getDirectionalLight().setDirection(sun_pos);
|
||||
shadow->setTimeOfDay(in_timeofday);
|
||||
|
||||
shadow->getDirectionalLight().update_frustum(camera, client);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Misc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue