1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00: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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 27 deletions

View file

@ -104,9 +104,10 @@ static v2f getDownscaleFactor()
return v2f(1.0f / undersampling);
}
RenderStep* addUpscaling(RenderPipeline *pipeline, RenderStep *previousStep, v2f downscale_factor)
RenderStep* addUpscaling(RenderPipeline *pipeline, RenderStep *previousStep, v2f downscale_factor, Client *client)
{
const int TEXTURE_UPSCALE = 0;
const int TEXTURE_LOWRES_COLOR = 0;
const int TEXTURE_LOWRES_DEPTH = 1;
if (downscale_factor.X == 1.0f && downscale_factor.Y == 1.0f)
return previousStep;
@ -115,13 +116,18 @@ RenderStep* addUpscaling(RenderPipeline *pipeline, RenderStep *previousStep, v2f
if (g_settings->getBool("enable_post_processing"))
return previousStep;
auto driver = client->getSceneManager()->getVideoDriver();
video::ECOLOR_FORMAT color_format = selectColorFormat(driver);
video::ECOLOR_FORMAT depth_format = selectDepthFormat(driver);
// Initialize buffer
TextureBuffer *buffer = pipeline->createOwned<TextureBuffer>();
buffer->setTexture(TEXTURE_UPSCALE, downscale_factor, "upscale", video::ECF_A8R8G8B8);
buffer->setTexture(TEXTURE_LOWRES_COLOR, downscale_factor, "lowres_color", color_format);
buffer->setTexture(TEXTURE_LOWRES_DEPTH, downscale_factor, "lowres_depth", depth_format);
// Attach previous step to the buffer
TextureBufferOutput *buffer_output = pipeline->createOwned<TextureBufferOutput>(buffer, TEXTURE_UPSCALE);
TextureBufferOutput *buffer_output = pipeline->createOwned<TextureBufferOutput>(
buffer, std::vector<u8> {TEXTURE_LOWRES_COLOR}, TEXTURE_LOWRES_DEPTH);
previousStep->setRenderTarget(buffer_output);
// Add upscaling step
@ -140,9 +146,25 @@ void populatePlainPipeline(RenderPipeline *pipeline, Client *client)
pipeline->addStep<DrawWield>();
pipeline->addStep<MapPostFxStep>();
step3D = addUpscaling(pipeline, step3D, downscale_factor);
step3D = addUpscaling(pipeline, step3D, downscale_factor, client);
step3D->setRenderTarget(pipeline->createOwned<ScreenTarget>());
pipeline->addStep<DrawHUD>();
}
video::ECOLOR_FORMAT selectColorFormat(video::IVideoDriver *driver)
{
if (driver->queryTextureFormat(video::ECF_A16B16G16R16F))
return video::ECF_A16B16G16R16F;
return video::ECF_A8R8G8B8;
}
video::ECOLOR_FORMAT selectDepthFormat(video::IVideoDriver *driver)
{
if (driver->queryTextureFormat(video::ECF_D32))
return video::ECF_D32;
if (driver->queryTextureFormat(video::ECF_D24S8))
return video::ECF_D24S8;
return video::ECF_D16; // fallback depth format
}