0
0
Fork 0
mirror of https://bitbucket.org/CPMADevs/cnq3 synced 2025-04-11 20:02:26 +00:00

added a magnifier tool to the CRP

This commit is contained in:
myT 2024-01-15 22:03:50 +01:00
parent c70df1f2af
commit 31b960255d
9 changed files with 192 additions and 0 deletions

View file

@ -218,6 +218,16 @@ private:
uint32_t tileHeight;
};
struct Magnifier
{
void Init();
void Draw();
void DrawGUI();
private:
HPipeline pipeline;
};
struct BaseBufferId
{
enum Id
@ -325,6 +335,7 @@ struct CRP : IRenderPipeline
GatherDepthOfField gatherDof;
AccumDepthOfField accumDof;
Fog fog;
Magnifier magnifier;
};
extern CRP crp;

View file

@ -0,0 +1,97 @@
/*
===========================================================================
Copyright (C) 2024 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 - magnifier tool for pixel peeping
#include "crp_local.h"
#include "../client/cl_imgui.h"
#include "compshaders/crp/fullscreen.h"
#include "compshaders/crp/magnifier.h"
#pragma pack(push, 4)
struct MagnifierRC
{
uint32_t colorTextureIndex;
uint32_t cursorIndexX;
uint32_t cursorIndexY;
uint32_t magnifierWidth;
uint32_t magnifierScale;
uint32_t edgeWidth;
uint32_t edgeColor;
};
#pragma pack(pop)
static bool s_magnifierActive = false;
void Magnifier::Init()
{
GraphicsPipelineDesc desc("Magnifier");
desc.shortLifeTime = true;
desc.vertexShader = ShaderByteCode(g_fullscreen_vs);
desc.pixelShader = ShaderByteCode(g_magnifier_ps);
desc.depthStencil.DisableDepth();
desc.rasterizer.cullMode = CT_TWO_SIDED;
desc.AddRenderTarget(0, crp.renderTargetFormat);
pipeline = CreateGraphicsPipeline(desc);
}
void Magnifier::Draw()
{
if(r_debugUI->integer == 0 || !s_magnifierActive)
{
return;
}
srp.renderMode = RenderMode::None;
SCOPED_RENDER_PASS("Magnifier", 1.0f, 1.0f, 1.0f);
CmdSetViewportAndScissor(0, 0, glConfig.vidWidth, glConfig.vidHeight);
crp.SwapRenderTargets();
CmdBeginBarrier();
CmdTextureBarrier(crp.GetReadRenderTarget(), ResourceStates::PixelShaderAccessBit);
CmdTextureBarrier(crp.GetWriteRenderTarget(), ResourceStates::RenderTargetBit);
CmdEndBarrier();
MagnifierRC rc = {};
rc.colorTextureIndex = GetTextureIndexSRV(crp.GetReadRenderTarget());
rc.cursorIndexX = ImGui::GetIO().MousePos.x;
rc.cursorIndexY = ImGui::GetIO().MousePos.y;
rc.magnifierWidth = 256;
rc.magnifierScale = 4;
rc.edgeWidth = 2;
rc.edgeColor = 0xFF00FFFF;
CmdBindRenderTargets(1, &crp.renderTarget, NULL);
CmdBindPipeline(pipeline);
CmdSetGraphicsRootConstants(0, sizeof(rc), &rc);
CmdDraw(3, 0);
}
void Magnifier::DrawGUI()
{
ToggleBooleanWithShortcut(s_magnifierActive, ImGuiKey_M);
GUI_AddMainMenuItem(GUI_MainMenu::Tools, "Magnifier", "Ctrl+M", &s_magnifierActive);
}

View file

@ -329,6 +329,7 @@ void CRP::Init()
gatherDof.Init();
accumDof.Init();
fog.Init();
magnifier.Init();
srp.firstInit = false;
}
@ -367,8 +368,10 @@ void CRP::BeginFrame()
void CRP::EndFrame()
{
srp.DrawGUI();
magnifier.DrawGUI();
imgui.Draw(renderTarget);
toneMap.DrawToneMap();
magnifier.Draw();
BlitRenderTarget(GetSwapChainTexture(), "Blit to Swap Chain");
BlitRenderTarget(readbackRenderTarget, "Blit to Readback Texture");
srp.EndFrame();

View file

@ -0,0 +1,64 @@
/*
===========================================================================
Copyright (C) 2024 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/>.
===========================================================================
*/
// magnifier for pixel peeping
#include "common.hlsli"
#include "fullscreen.hlsli"
cbuffer RootConstants
{
uint colorTextureIndex;
int cursorIndexX;
int cursorIndexY;
int magnifierWidth;
int magnifierScale;
int edgeWidth;
uint edgeColor;
};
float4 ps(VOut input) : SV_Target
{
Texture2D colorTexture = ResourceDescriptorHeap[colorTextureIndex];
int2 tc = int2(input.position.xy);
int2 tcCursor = int2(cursorIndexX, cursorIndexY);
int2 diff = tc - tcCursor;
int2 dist = abs(diff);
int distInner = magnifierWidth / 2;
int distOuter = distInner + edgeWidth;
if(all(dist <= distInner))
{
// we need to map diff values -N..-1 to -1 and 0..N-1 to 0 after division
// hence the N-1 offset for negative diff values
int2 negOffset = int2(magnifierScale - 1, magnifierScale - 1);
diff -= diff < int2(0, 0) ? negOffset : int2(0, 0);
tc = tcCursor + diff / magnifierScale;
}
float3 color = colorTexture.Load(int3(tc.x, tc.y, 0)).rgb;
if(any(dist > distInner) && all(dist <= distOuter))
{
color = UnpackColor(edgeColor).rgb;
}
float4 result = float4(color, 1.0);
return result;
}

View file

@ -405,6 +405,7 @@ void ProcessCRP()
CompilePixelShader("gatherdof_debug.h", "gatherdof_debug.hlsl", "debug");
CompileGraphics("fog_inside.h", "fog_inside.hlsl", "inside");
CompileGraphics("fog_outside.h", "fog_outside.hlsl", "outside");
CompilePixelShader("magnifier.h", "magnifier.hlsl", "magnifier");
}
int main(int /*argc*/, const char** argv)

View file

@ -131,6 +131,7 @@
<ClCompile Include="..\..\code\renderer\crp_dof_gather.cpp" />
<ClCompile Include="..\..\code\renderer\crp_fog.cpp" />
<ClCompile Include="..\..\code\renderer\crp_geometry.cpp" />
<ClCompile Include="..\..\code\renderer\crp_magnifier.cpp" />
<ClCompile Include="..\..\code\renderer\crp_main.cpp" />
<ClCompile Include="..\..\code\renderer\crp_opaque.cpp" />
<ClCompile Include="..\..\code\renderer\crp_tone_map.cpp" />
@ -217,6 +218,9 @@
<FxCompile Include="..\..\code\renderer\shaders\crp\imgui.hlsl">
<ExcludedFromBuild>true</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\magnifier.hlsl">
<ExcludedFromBuild>true</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\mip_1.hlsl">
<ExcludedFromBuild>true</ExcludedFromBuild>
</FxCompile>

View file

@ -35,6 +35,7 @@
<ClCompile Include="..\..\code\renderer\crp_dof_gather.cpp" />
<ClCompile Include="..\..\code\renderer\crp_fog.cpp" />
<ClCompile Include="..\..\code\renderer\crp_geometry.cpp" />
<ClCompile Include="..\..\code\renderer\crp_magnifier.cpp" />
<ClCompile Include="..\..\code\renderer\crp_main.cpp" />
<ClCompile Include="..\..\code\renderer\crp_opaque.cpp" />
<ClCompile Include="..\..\code\renderer\crp_tone_map.cpp" />
@ -121,6 +122,9 @@
<FxCompile Include="..\..\code\renderer\shaders\crp\imgui.hlsl">
<Filter>shaders\crp</Filter>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\magnifier.hlsl">
<Filter>shaders\crp</Filter>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\mip_1.hlsl">
<Filter>shaders\crp</Filter>
</FxCompile>

View file

@ -133,6 +133,7 @@
<ClCompile Include="..\..\code\renderer\crp_dof_gather.cpp" />
<ClCompile Include="..\..\code\renderer\crp_fog.cpp" />
<ClCompile Include="..\..\code\renderer\crp_geometry.cpp" />
<ClCompile Include="..\..\code\renderer\crp_magnifier.cpp" />
<ClCompile Include="..\..\code\renderer\crp_main.cpp" />
<ClCompile Include="..\..\code\renderer\crp_opaque.cpp" />
<ClCompile Include="..\..\code\renderer\crp_tone_map.cpp" />
@ -219,6 +220,9 @@
<FxCompile Include="..\..\code\renderer\shaders\crp\imgui.hlsl">
<ExcludedFromBuild>true</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\magnifier.hlsl">
<ExcludedFromBuild>true</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\mip_1.hlsl">
<ExcludedFromBuild>true</ExcludedFromBuild>
</FxCompile>

View file

@ -35,6 +35,7 @@
<ClCompile Include="..\..\code\renderer\crp_dof_gather.cpp" />
<ClCompile Include="..\..\code\renderer\crp_fog.cpp" />
<ClCompile Include="..\..\code\renderer\crp_geometry.cpp" />
<ClCompile Include="..\..\code\renderer\crp_magnifier.cpp" />
<ClCompile Include="..\..\code\renderer\crp_main.cpp" />
<ClCompile Include="..\..\code\renderer\crp_opaque.cpp" />
<ClCompile Include="..\..\code\renderer\crp_tone_map.cpp" />
@ -121,6 +122,9 @@
<FxCompile Include="..\..\code\renderer\shaders\crp\imgui.hlsl">
<Filter>shaders\crp</Filter>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\magnifier.hlsl">
<Filter>shaders\crp</Filter>
</FxCompile>
<FxCompile Include="..\..\code\renderer\shaders\crp\mip_1.hlsl">
<Filter>shaders\crp</Filter>
</FxCompile>