mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2024-11-23 12:32:14 +00:00
111 lines
3.6 KiB
C++
111 lines
3.6 KiB
C++
/*
|
|
===========================================================================
|
|
Copyright (C) 2023 Gian 'myT' Schellenbaum
|
|
|
|
This file is part of Challenge Quake 3 (CNQ3).
|
|
|
|
Challenge Quake 3 is free software; you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
or (at your option) any later version.
|
|
|
|
Challenge Quake 3 is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Challenge Quake 3. If not, see <https://www.gnu.org/licenses/>.
|
|
===========================================================================
|
|
*/
|
|
// Cinematic Rendering Pipeline - OIT resolve pass
|
|
|
|
|
|
#include "crp_local.h"
|
|
namespace transp_resolve
|
|
{
|
|
#include "compshaders/crp/transp_resolve_vs.h"
|
|
#include "compshaders/crp/transp_resolve_ps.h"
|
|
}
|
|
|
|
|
|
#pragma pack(push, 4)
|
|
struct TranspResolveRC
|
|
{
|
|
uint32_t renderTargetTexture;
|
|
uint32_t shaderIndexBuffer;
|
|
uint32_t indexTexture;
|
|
uint32_t fragmentBuffer;
|
|
uint16_t centerPixelX;
|
|
uint16_t centerPixelY;
|
|
uint32_t depthTexture;
|
|
float proj22;
|
|
float proj32;
|
|
float scissorMinX;
|
|
float scissorMinY;
|
|
float scissorMaxX;
|
|
float scissorMaxY;
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
|
|
void TranspResolve::Init()
|
|
{
|
|
GraphicsPipelineDesc desc("OIT Resolve");
|
|
desc.shortLifeTime = true;
|
|
desc.vertexShader = ShaderByteCode(transp_resolve::g_vs);
|
|
desc.pixelShader = ShaderByteCode(transp_resolve::g_ps);
|
|
desc.depthStencil.DisableDepth();
|
|
desc.rasterizer.cullMode = CT_TWO_SIDED;
|
|
desc.AddRenderTarget(0, crp.renderTargetFormat);
|
|
pipeline = CreateGraphicsPipeline(desc);
|
|
}
|
|
|
|
void TranspResolve::Draw(const drawSceneViewCommand_t& cmd)
|
|
{
|
|
if(cmd.numTranspSurfs <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
srp.renderMode = RenderMode::World;
|
|
|
|
SCOPED_RENDER_PASS("OIT Resolve", 1.0f, 0.5f, 0.5f);
|
|
|
|
CmdSetViewportAndScissor(0, 0, glConfig.vidWidth, glConfig.vidHeight);
|
|
|
|
crp.SwapRenderTargets();
|
|
const TextureBarrier texBarriers[] =
|
|
{
|
|
TextureBarrier(crp.GetReadRenderTarget(), ResourceStates::PixelShaderAccessBit),
|
|
TextureBarrier(crp.GetWriteRenderTarget(), ResourceStates::RenderTargetBit),
|
|
TextureBarrier(crp.oitIndexTexture, ResourceStates::UnorderedAccessBit),
|
|
TextureBarrier(crp.depthTexture, ResourceStates::PixelShaderAccessBit)
|
|
};
|
|
const BufferBarrier bufBarriers[] =
|
|
{
|
|
BufferBarrier(crp.oitFragmentBuffer, ResourceStates::UnorderedAccessBit),
|
|
BufferBarrier(srp.traceRenderBuffer, ResourceStates::UnorderedAccessBit)
|
|
};
|
|
CmdBarrier(ARRAY_LEN(texBarriers), texBarriers, ARRAY_LEN(bufBarriers), bufBarriers);
|
|
|
|
TranspResolveRC rc = {};
|
|
rc.fragmentBuffer = GetBufferIndexUAV(crp.oitFragmentBuffer);
|
|
rc.indexTexture = GetTextureIndexUAV(crp.oitIndexTexture, 0);
|
|
rc.renderTargetTexture = GetTextureIndexSRV(crp.GetReadRenderTarget());
|
|
rc.shaderIndexBuffer = GetBufferIndexUAV(srp.traceRenderBuffer);
|
|
rc.centerPixelX = glConfig.vidWidth / 2;
|
|
rc.centerPixelY = glConfig.vidHeight / 2;
|
|
rc.depthTexture = GetTextureIndexSRV(crp.depthTexture);
|
|
rc.proj22 = -backEnd.viewParms.projectionMatrix[2 * 4 + 2];
|
|
rc.proj32 = backEnd.viewParms.projectionMatrix[3 * 4 + 2];
|
|
rc.scissorMinX = backEnd.viewParms.viewportX;
|
|
rc.scissorMinY = backEnd.viewParms.viewportY;
|
|
rc.scissorMaxX = rc.scissorMinX + backEnd.viewParms.viewportWidth - 1;
|
|
rc.scissorMaxY = rc.scissorMinY + backEnd.viewParms.viewportHeight - 1;
|
|
|
|
CmdBindRenderTargets(1, &crp.renderTarget, NULL);
|
|
CmdBindPipeline(pipeline);
|
|
CmdSetGraphicsRootConstants(0, sizeof(rc), &rc);
|
|
CmdDraw(3, 0);
|
|
}
|