1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Implement rendering pipeline and post-processing (#12465)

Co-authored-by: Lars Mueller <appgurulars@gmx.de>
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: lhofhansl <lhofhansl@yahoo.com>
This commit is contained in:
x2048 2022-09-06 08:25:18 +02:00 committed by GitHub
parent 464043b8ab
commit ff6dcfea82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 1476 additions and 565 deletions

View file

@ -19,111 +19,48 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "core.h"
#include "client/camera.h"
#include "client/client.h"
#include "client/clientmap.h"
#include "client/hud.h"
#include "client/minimap.h"
#include "plain.h"
#include "client/shadows/dynamicshadowsrender.h"
#include "settings.h"
RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
: device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
mapper(client->getMinimap()), hud(_hud),
shadow_renderer(nullptr)
RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud,
ShadowRenderer *_shadow_renderer, RenderPipeline *_pipeline, v2f _virtual_size_scale)
: device(_device), client(_client), hud(_hud), shadow_renderer(_shadow_renderer),
pipeline(_pipeline), virtual_size_scale(_virtual_size_scale)
{
screensize = driver->getScreenSize();
virtual_size = screensize;
// disable if unsupported
if (g_settings->getBool("enable_dynamic_shadows") && (
g_settings->get("video_driver") != "opengl" ||
!g_settings->getBool("enable_shaders"))) {
g_settings->setBool("enable_dynamic_shadows", false);
}
if (g_settings->getBool("enable_shaders") &&
g_settings->getBool("enable_dynamic_shadows")) {
shadow_renderer = new ShadowRenderer(device, client);
}
}
RenderingCore::~RenderingCore()
{
clearTextures();
delete pipeline;
delete shadow_renderer;
}
void RenderingCore::initialize()
{
// have to be called late as the VMT is not ready in the constructor:
initTextures();
if (shadow_renderer)
shadow_renderer->initialize();
}
pipeline->addStep<RenderShadowMapStep>();
void RenderingCore::updateScreenSize()
{
virtual_size = screensize;
clearTextures();
initTextures();
createPipeline();
}
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
bool _draw_wield_tool, bool _draw_crosshair)
{
v2u32 ss = driver->getScreenSize();
if (screensize != ss) {
screensize = ss;
updateScreenSize();
}
skycolor = _skycolor;
show_hud = _show_hud;
show_minimap = _show_minimap;
draw_wield_tool = _draw_wield_tool;
draw_crosshair = _draw_crosshair;
v2u32 screensize = device->getVideoDriver()->getScreenSize();
virtual_size = v2u32(screensize.X * virtual_size_scale.X, screensize.Y * virtual_size_scale.Y);
if (shadow_renderer) {
// This is necessary to render shadows for animations correctly
smgr->getRootSceneNode()->OnAnimate(device->getTimer()->getTime());
shadow_renderer->update();
}
PipelineContext context(device, client, hud, shadow_renderer, _skycolor, screensize);
context.draw_crosshair = _draw_crosshair;
context.draw_wield_tool = _draw_wield_tool;
context.show_hud = _show_hud;
context.show_minimap = _show_minimap;
beforeDraw();
drawAll();
pipeline->reset(context);
pipeline->run(context);
}
void RenderingCore::draw3D()
v2u32 RenderingCore::getVirtualSize() const
{
smgr->drawAll();
if (shadow_renderer)
shadow_renderer->drawDebug();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
if (!show_hud)
return;
hud->drawBlockBounds();
hud->drawSelectionMesh();
if (draw_wield_tool)
camera->drawWieldedTool();
}
void RenderingCore::drawHUD()
{
if (show_hud) {
if (draw_crosshair)
hud->drawCrosshair();
hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
hud->drawLuaElements(camera->getOffset());
camera->drawNametags();
if (mapper && show_minimap)
mapper->drawMinimap();
}
guienv->drawAll();
}
void RenderingCore::drawPostFx()
{
client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
}
return virtual_size;
}