mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +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:
parent
464043b8ab
commit
ff6dcfea82
32 changed files with 1476 additions and 565 deletions
|
@ -19,102 +19,66 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "interlaced.h"
|
||||
#include "secondstage.h"
|
||||
#include "client/client.h"
|
||||
#include "client/shader.h"
|
||||
#include "client/tile.h"
|
||||
#include "client/camera.h"
|
||||
|
||||
RenderingCoreInterlaced::RenderingCoreInterlaced(
|
||||
IrrlichtDevice *_device, Client *_client, Hud *_hud)
|
||||
: RenderingCoreStereo(_device, _client, _hud)
|
||||
InitInterlacedMaskStep::InitInterlacedMaskStep(TextureBuffer *_buffer, u8 _index) :
|
||||
buffer(_buffer), index(_index)
|
||||
{
|
||||
initMaterial();
|
||||
}
|
||||
|
||||
void RenderingCoreInterlaced::initMaterial()
|
||||
void InitInterlacedMaskStep::run(PipelineContext &context)
|
||||
{
|
||||
IShaderSource *s = client->getShaderSource();
|
||||
mat.UseMipMaps = false;
|
||||
mat.ZBuffer = false;
|
||||
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
|
||||
mat.ZWriteEnable = video::EZW_OFF;
|
||||
#else
|
||||
mat.ZWriteEnable = false;
|
||||
#endif
|
||||
u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC);
|
||||
mat.MaterialType = s->getShaderInfo(shader).material;
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
mat.TextureLayer[k].AnisotropicFilter = false;
|
||||
mat.TextureLayer[k].BilinearFilter = false;
|
||||
mat.TextureLayer[k].TrilinearFilter = false;
|
||||
mat.TextureLayer[k].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
||||
mat.TextureLayer[k].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
||||
}
|
||||
}
|
||||
video::ITexture *mask = buffer->getTexture(index);
|
||||
if (!mask)
|
||||
return;
|
||||
if (mask == last_mask)
|
||||
return;
|
||||
last_mask = mask;
|
||||
|
||||
void RenderingCoreInterlaced::initTextures()
|
||||
{
|
||||
v2u32 image_size{screensize.X, screensize.Y / 2};
|
||||
left = driver->addRenderTargetTexture(
|
||||
image_size, "3d_render_left", video::ECF_A8R8G8B8);
|
||||
right = driver->addRenderTargetTexture(
|
||||
image_size, "3d_render_right", video::ECF_A8R8G8B8);
|
||||
mask = driver->addTexture(screensize, "3d_render_mask", video::ECF_A8R8G8B8);
|
||||
initMask();
|
||||
mat.TextureLayer[0].Texture = left;
|
||||
mat.TextureLayer[1].Texture = right;
|
||||
mat.TextureLayer[2].Texture = mask;
|
||||
}
|
||||
|
||||
void RenderingCoreInterlaced::clearTextures()
|
||||
{
|
||||
driver->removeTexture(left);
|
||||
driver->removeTexture(right);
|
||||
driver->removeTexture(mask);
|
||||
}
|
||||
|
||||
void RenderingCoreInterlaced::initMask()
|
||||
{
|
||||
auto size = mask->getSize();
|
||||
u8 *data = reinterpret_cast<u8 *>(mask->lock());
|
||||
for (u32 j = 0; j < screensize.Y; j++) {
|
||||
for (u32 j = 0; j < size.Height; j++) {
|
||||
u8 val = j % 2 ? 0xff : 0x00;
|
||||
memset(data, val, 4 * screensize.X);
|
||||
data += 4 * screensize.X;
|
||||
memset(data, val, 4 * size.Width);
|
||||
data += 4 * size.Width;
|
||||
}
|
||||
mask->unlock();
|
||||
}
|
||||
|
||||
void RenderingCoreInterlaced::drawAll()
|
||||
void populateInterlacedPipeline(RenderPipeline *pipeline, Client *client)
|
||||
{
|
||||
renderBothImages();
|
||||
merge();
|
||||
drawHUD();
|
||||
}
|
||||
static const u8 TEXTURE_LEFT = 0;
|
||||
static const u8 TEXTURE_RIGHT = 1;
|
||||
static const u8 TEXTURE_MASK = 2;
|
||||
|
||||
void RenderingCoreInterlaced::merge()
|
||||
{
|
||||
static const video::S3DVertex vertices[4] = {
|
||||
video::S3DVertex(1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
|
||||
video::SColor(255, 0, 255, 255), 1.0, 0.0),
|
||||
video::S3DVertex(-1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
|
||||
video::SColor(255, 255, 0, 255), 0.0, 0.0),
|
||||
video::S3DVertex(-1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
|
||||
video::SColor(255, 255, 255, 0), 0.0, 1.0),
|
||||
video::S3DVertex(1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
|
||||
video::SColor(255, 255, 255, 255), 1.0, 1.0),
|
||||
};
|
||||
static const u16 indices[6] = {0, 1, 2, 2, 3, 0};
|
||||
driver->setMaterial(mat);
|
||||
driver->drawVertexPrimitiveList(&vertices, 4, &indices, 2);
|
||||
}
|
||||
TextureBuffer *buffer = pipeline->createOwned<TextureBuffer>();
|
||||
buffer->setTexture(TEXTURE_LEFT, v2f(1.0f, 0.5f), "3d_render_left", video::ECF_A8R8G8B8);
|
||||
buffer->setTexture(TEXTURE_RIGHT, v2f(1.0f, 0.5f), "3d_render_right", video::ECF_A8R8G8B8);
|
||||
buffer->setTexture(TEXTURE_MASK, v2f(1.0f, 1.0f), "3d_render_mask", video::ECF_A8R8G8B8);
|
||||
|
||||
void RenderingCoreInterlaced::useEye(bool _right)
|
||||
{
|
||||
driver->setRenderTarget(_right ? right : left, true, true, skycolor);
|
||||
RenderingCoreStereo::useEye(_right);
|
||||
}
|
||||
pipeline->addStep<InitInterlacedMaskStep>(buffer, TEXTURE_MASK);
|
||||
|
||||
void RenderingCoreInterlaced::resetEye()
|
||||
{
|
||||
driver->setRenderTarget(nullptr, false, false, skycolor);
|
||||
RenderingCoreStereo::resetEye();
|
||||
}
|
||||
auto step3D = pipeline->own(create3DStage(client, v2f(1.0f, 0.5f)));
|
||||
|
||||
// eyes
|
||||
for (bool right : { false, true }) {
|
||||
pipeline->addStep<OffsetCameraStep>(right);
|
||||
auto output = pipeline->createOwned<TextureBufferOutput>(buffer, right ? TEXTURE_RIGHT : TEXTURE_LEFT);
|
||||
pipeline->addStep<SetRenderTargetStep>(step3D, output);
|
||||
pipeline->addStep(step3D);
|
||||
pipeline->addStep<MapPostFxStep>();
|
||||
}
|
||||
|
||||
pipeline->addStep<OffsetCameraStep>(0.0f);
|
||||
IShaderSource *s = client->getShaderSource();
|
||||
u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC);
|
||||
video::E_MATERIAL_TYPE material = s->getShaderInfo(shader).material;
|
||||
auto texture_map = { TEXTURE_LEFT, TEXTURE_RIGHT, TEXTURE_MASK };
|
||||
auto merge = pipeline->addStep<PostProcessingStep>(material, texture_map);
|
||||
merge->setRenderSource(buffer);
|
||||
merge->setRenderTarget(pipeline->createOwned<ScreenTarget>());
|
||||
pipeline->addStep<DrawHUD>();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue