1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-26 21:35:28 +01:00

Get rid of depth buffer workaround in the render pipeline code (#15407)

I originally wanted to get of the legacy IVideoDriver::setRenderTarget altogether,
but that ended up being too much work.
The remaining usage is in "dynamicshadowsrender.cpp".

Here's a comment I wrote about the workaround:

----------------------------------------

Use legacy call when there's single texture without depth texture
This means Irrlicht creates a depth texture for us and binds it to the FBO

This is currently necessary for a working depth buffer in the following cases:

- post-processing disabled, undersampling enabled
  (addUpscaling specifies no depth texture)

- post-processing disabled, 3d_mode = sidebyside / topbottom / crossview
  (populateSideBySidePipeline specifies no depth texture)

- post-processing disabled, 3d_mode = interlaced
  (probably, can't test since it's broken)
  (populateInterlacedPipeline specifies no depth texture)

With post-processing disabled, the world is rendered to the TextureBufferOutput
created in the functions listed above, so a depth buffer is needed
(-> this workaround is needed).
With post-processing enabled, only a fullscreen rectangle is rendered to
this TextureBufferOutput, so a depth buffer isn't actually needed.
But: These pipeline steps shouldn't rely on what ends up being rendered to
the TextureBufferOutput they provide, since that may change.

This workaround was added in 1e96403954 /
https://irc.minetest.net/minetest-dev/2022-10-04#i_6021940

This workaround should be replaced by explicitly configuring depth
textures where needed.

----------------------------------------
This commit is contained in:
grorp
2024-11-15 11:38:56 +01:00
committed by GitHub
parent d4378a74d3
commit a9fe83126a
7 changed files with 54 additions and 27 deletions

View File

@@ -4,6 +4,7 @@
// Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
#include "sidebyside.h"
#include "client/client.h"
#include "client/hud.h"
#include "client/camera.h"
@@ -35,6 +36,11 @@ void populateSideBySidePipeline(RenderPipeline *pipeline, Client *client, bool h
{
static const u8 TEXTURE_LEFT = 0;
static const u8 TEXTURE_RIGHT = 1;
static const u8 TEXTURE_DEPTH = 2;
auto driver = client->getSceneManager()->getVideoDriver();
video::ECOLOR_FORMAT color_format = selectColorFormat(driver);
video::ECOLOR_FORMAT depth_format = selectDepthFormat(driver);
v2f offset;
if (horizontal) {
@@ -47,15 +53,17 @@ void populateSideBySidePipeline(RenderPipeline *pipeline, Client *client, bool h
}
TextureBuffer *buffer = pipeline->createOwned<TextureBuffer>();
buffer->setTexture(TEXTURE_LEFT, virtual_size_scale, "3d_render_left", video::ECF_A8R8G8B8);
buffer->setTexture(TEXTURE_RIGHT, virtual_size_scale, "3d_render_right", video::ECF_A8R8G8B8);
buffer->setTexture(TEXTURE_LEFT, virtual_size_scale, "3d_render_left", color_format);
buffer->setTexture(TEXTURE_RIGHT, virtual_size_scale, "3d_render_right", color_format);
buffer->setTexture(TEXTURE_DEPTH, virtual_size_scale, "3d_depthmap_sidebyside", depth_format);
auto step3D = pipeline->own(create3DStage(client, virtual_size_scale));
// eyes
for (bool right : { false, true }) {
pipeline->addStep<OffsetCameraStep>(flipped ? !right : right);
auto output = pipeline->createOwned<TextureBufferOutput>(buffer, right ? TEXTURE_RIGHT : TEXTURE_LEFT);
auto output = pipeline->createOwned<TextureBufferOutput>(
buffer, std::vector<u8> {right ? TEXTURE_RIGHT : TEXTURE_LEFT}, TEXTURE_DEPTH);
pipeline->addStep<SetRenderTargetStep>(step3D, output);
pipeline->addStep(step3D);
pipeline->addStep<DrawWield>();