mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-07-26 09:21:37 +00:00
Tweak viewport/scissor overlay to be a little clearer
This commit is contained in:
@@ -46,5 +46,6 @@ DECLARE_EMBED(generic_frag);
|
||||
DECLARE_EMBED(text_frag);
|
||||
DECLARE_EMBED(text_vert);
|
||||
DECLARE_EMBED(sourcecodepro_ttf);
|
||||
DECLARE_EMBED(outline_frag);
|
||||
|
||||
#undef DECLARE_EMBED
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014 Crytek
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#version 420 core
|
||||
|
||||
layout (location = 0) out vec4 color_out;
|
||||
|
||||
uniform vec4 RENDERDOC_Inner_Color;
|
||||
uniform vec4 RENDERDOC_Border_Color;
|
||||
uniform vec4 RENDERDOC_ViewRect;
|
||||
uniform uint RENDERDOC_Scissor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 ret = RENDERDOC_Inner_Color;
|
||||
|
||||
vec2 rectPos = gl_FragCoord.xy - RENDERDOC_ViewRect.xy;
|
||||
vec2 rectSize = RENDERDOC_ViewRect.zw;
|
||||
|
||||
vec2 ab = mod(rectPos.xy, 32.0f.xx);
|
||||
|
||||
bool checkerVariant = (
|
||||
(ab.x < 16 && ab.y < 16) ||
|
||||
(ab.x > 16 && ab.y > 16)
|
||||
);
|
||||
|
||||
if(RENDERDOC_Scissor == 0)
|
||||
{
|
||||
if(rectPos.x < 3.0f || rectPos.x > rectSize.x - 3.0f ||
|
||||
rectPos.y < 3.0f || rectPos.y > rectSize.y - 3.0f)
|
||||
{
|
||||
ret = RENDERDOC_Border_Color;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(rectPos.x < 3.0f || rectPos.x > rectSize.x - 3.0f ||
|
||||
rectPos.y < 3.0f || rectPos.y > rectSize.y - 3.0f)
|
||||
{
|
||||
ret = checkerVariant ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = vec4(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
color_out = ret;
|
||||
}
|
||||
@@ -254,6 +254,45 @@ MultipleOutput RENDERDOC_OverlayPS(float4 IN : SV_Position)
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float4 RENDERDOC_OutlinePS(float4 IN : SV_Position) : SV_Target0
|
||||
{
|
||||
float4 ret = Channels;
|
||||
|
||||
float2 rectPos = IN.xy - float2(RangeMinimum, InverseRangeSize);
|
||||
float2 rectSize = TextureResolutionPS.xy;
|
||||
|
||||
float2 ab = fmod(rectPos.xy, 32.0.xx);
|
||||
|
||||
bool checkerVariant = (
|
||||
(ab.x < 16 && ab.y < 16) ||
|
||||
(ab.x > 16 && ab.y > 16)
|
||||
);
|
||||
|
||||
if(OutputDisplayFormat == 0)
|
||||
{
|
||||
if(rectPos.x < 3.0f || rectPos.x > rectSize.x - 3.0f ||
|
||||
rectPos.y < 3.0f || rectPos.y > rectSize.y - 3.0f)
|
||||
{
|
||||
ret.rgb = WireframeColour.rgb;
|
||||
ret.a = 1.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(rectPos.x < 3.0f || rectPos.x > rectSize.x - 3.0f ||
|
||||
rectPos.y < 3.0f || rectPos.y > rectSize.y - 3.0f)
|
||||
{
|
||||
ret = checkerVariant ? float4(1, 1, 1, 1) : float4(0, 0, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = float4(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
float4 RENDERDOC_CheckerboardPS(float4 IN : SV_Position) : SV_Target0
|
||||
{
|
||||
float2 ab = fmod(IN.xy, 128.0.xx);
|
||||
|
||||
@@ -127,6 +127,7 @@ RESOURCE_mesh_geom TYPE_EMBED "glsl/mesh.geom"
|
||||
RESOURCE_mesh_comp TYPE_EMBED "glsl/mesh.comp"
|
||||
RESOURCE_arraymscopy_comp TYPE_EMBED "glsl/arraymscopy.comp"
|
||||
RESOURCE_quadoverdraw_frag TYPE_EMBED "glsl/quadoverdraw.frag"
|
||||
RESOURCE_outline_frag TYPE_EMBED "glsl/outline.frag"
|
||||
|
||||
RESOURCE_sourcecodepro_ttf TYPE_EMBED "sourcecodepro.ttf"
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#define RESOURCE_mesh_comp 215
|
||||
#define RESOURCE_arraymscopy_comp 216
|
||||
#define RESOURCE_quadoverdraw_frag 217
|
||||
#define RESOURCE_outline_frag 218
|
||||
|
||||
#define RESOURCE_sourcecodepro_ttf 301
|
||||
|
||||
|
||||
@@ -2815,6 +2815,8 @@ void D3D11DebugManager::CreateCustomShaderTex(uint32_t w, uint32_t h)
|
||||
}
|
||||
}
|
||||
|
||||
#include "data/hlsl/debugcbuffers.h"
|
||||
|
||||
ResourceId D3D11DebugManager::RenderOverlay(ResourceId texid, TextureDisplayOverlay overlay, uint32_t frameID, uint32_t eventID, const vector<uint32_t> &passEvents)
|
||||
{
|
||||
TextureShaderDetails details = GetShaderDetails(texid, false);
|
||||
@@ -3127,7 +3129,7 @@ ResourceId D3D11DebugManager::RenderOverlay(ResourceId texid, TextureDisplayOver
|
||||
m_pImmediateContext->HSSetShader(NULL, NULL, 0);
|
||||
m_pImmediateContext->DSSetShader(NULL, NULL, 0);
|
||||
m_pImmediateContext->GSSetShader(NULL, NULL, 0);
|
||||
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
|
||||
m_pImmediateContext->PSSetShader(m_DebugRender.OutlinePS, NULL, 0);
|
||||
m_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
m_pImmediateContext->IASetInputLayout(NULL);
|
||||
|
||||
@@ -3158,11 +3160,28 @@ ResourceId D3D11DebugManager::RenderOverlay(ResourceId texid, TextureDisplayOver
|
||||
}
|
||||
|
||||
m_pImmediateContext->OMSetDepthStencilState(os, 0);
|
||||
|
||||
D3D11_BLEND_DESC blendDesc;
|
||||
RDCEraseEl(blendDesc);
|
||||
|
||||
m_pImmediateContext->OMSetBlendState(NULL, NULL, 0xffffffff);
|
||||
blendDesc.AlphaToCoverageEnable = FALSE;
|
||||
blendDesc.IndependentBlendEnable = FALSE;
|
||||
blendDesc.RenderTarget[0].BlendEnable = TRUE;
|
||||
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
||||
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||
blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||
|
||||
ID3D11BlendState *bs = NULL;
|
||||
hr = m_pDevice->CreateBlendState(&blendDesc, &bs);
|
||||
|
||||
float blendwhite[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
m_pImmediateContext->OMSetBlendState(bs, blendwhite, 0xffffffff);
|
||||
|
||||
ID3D11RasterizerState *rs = NULL;
|
||||
ID3D11RasterizerState *rs2 = NULL;
|
||||
{
|
||||
D3D11_RASTERIZER_DESC rdesc;
|
||||
|
||||
@@ -3183,44 +3202,66 @@ ResourceId D3D11DebugManager::RenderOverlay(ResourceId texid, TextureDisplayOver
|
||||
RDCERR("Failed to create drawcall rast state %08x", hr);
|
||||
return m_OverlayResourceId;
|
||||
}
|
||||
|
||||
rdesc.ScissorEnable = TRUE;
|
||||
|
||||
hr = m_pDevice->CreateRasterizerState(&rdesc, &rs2);
|
||||
if(FAILED(hr))
|
||||
{
|
||||
RDCERR("Failed to create drawcall rast state %08x", hr);
|
||||
return m_OverlayResourceId;
|
||||
}
|
||||
}
|
||||
|
||||
float clearColour[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
m_pImmediateContext->ClearRenderTargetView(rtv, clearColour);
|
||||
|
||||
float overlayConsts[] = { 0.15f, 0.3f, 0.6f, 0.3f };
|
||||
ID3D11Buffer *buf = MakeCBuffer(overlayConsts, sizeof(overlayConsts));
|
||||
|
||||
m_pImmediateContext->PSSetConstantBuffers(1, 1, &buf);
|
||||
|
||||
m_pImmediateContext->RSSetState(rs);
|
||||
|
||||
DebugPixelCBufferData pixelData = {0};
|
||||
|
||||
UINT dummy = 1;
|
||||
D3D11_VIEWPORT views[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE] = {0};
|
||||
m_pImmediateContext->RSGetViewports(&dummy, views);
|
||||
|
||||
// border colour (dark, 2px, opaque)
|
||||
pixelData.WireframeColour = Vec3f(0.1f, 0.1f, 0.1f);
|
||||
// inner colour (light, transparent)
|
||||
pixelData.Channels = Vec4f(0.2f, 0.2f, 0.9f, 0.7f);
|
||||
pixelData.OutputDisplayFormat = 0;
|
||||
pixelData.RangeMinimum = views[0].TopLeftX;
|
||||
pixelData.InverseRangeSize = views[0].TopLeftY;
|
||||
pixelData.TextureResolutionPS = Vec3f(views[0].Width, views[0].Height, 0.0f);
|
||||
|
||||
ID3D11Buffer *buf = MakeCBuffer((float *)&pixelData, sizeof(DebugPixelCBufferData));
|
||||
|
||||
m_pImmediateContext->PSSetConstantBuffers(0, 1, &buf);
|
||||
|
||||
m_pImmediateContext->Draw(3, 0);
|
||||
|
||||
float overlayConsts2[] = { 0.5f, 0.6f, 0.8f, 0.3f };
|
||||
buf = MakeCBuffer(overlayConsts2, sizeof(overlayConsts2));
|
||||
|
||||
if(origdesc.ScissorEnable)
|
||||
{
|
||||
m_pImmediateContext->PSSetConstantBuffers(1, 1, &buf);
|
||||
UINT dummy = 1;
|
||||
D3D11_RECT rects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE] = {0};
|
||||
m_pImmediateContext->RSGetScissorRects(&dummy, rects);
|
||||
|
||||
m_pImmediateContext->RSSetState(rs2);
|
||||
D3D11_VIEWPORT scissorview;
|
||||
|
||||
scissorview.TopLeftX = (float)rects[0].left;
|
||||
scissorview.TopLeftY = (float)rects[0].top;
|
||||
scissorview.MinDepth = 0.0f;
|
||||
scissorview.MaxDepth = 1.0f;
|
||||
scissorview.Width = (float)(rects[0].right - rects[0].left);
|
||||
scissorview.Height = (float)(rects[0].bottom - rects[0].top);
|
||||
|
||||
m_pImmediateContext->RSSetViewports(1, &scissorview);
|
||||
|
||||
pixelData.OutputDisplayFormat = 1;
|
||||
pixelData.RangeMinimum = scissorview.TopLeftX;
|
||||
pixelData.InverseRangeSize = scissorview.TopLeftY;
|
||||
pixelData.TextureResolutionPS = Vec3f(scissorview.Width, scissorview.Height, 0.0f);
|
||||
|
||||
buf = MakeCBuffer((float *)&pixelData, sizeof(DebugPixelCBufferData));
|
||||
|
||||
m_pImmediateContext->PSSetConstantBuffers(0, 1, &buf);
|
||||
|
||||
m_pImmediateContext->Draw(3, 0);
|
||||
}
|
||||
|
||||
SAFE_RELEASE(os);
|
||||
SAFE_RELEASE(rs);
|
||||
SAFE_RELEASE(rs2);
|
||||
SAFE_RELEASE(bs);
|
||||
}
|
||||
else if(overlay == eTexOverlay_Wireframe)
|
||||
{
|
||||
|
||||
@@ -827,6 +827,7 @@ bool D3D11DebugManager::InitDebugRendering()
|
||||
m_DebugRender.WireframePS = MakePShader(displayhlsl.c_str(), "RENDERDOC_WireframePS", "ps_4_0");
|
||||
m_DebugRender.OverlayPS = MakePShader(displayhlsl.c_str(), "RENDERDOC_OverlayPS", "ps_4_0");
|
||||
m_DebugRender.CheckerboardPS = MakePShader(displayhlsl.c_str(), "RENDERDOC_CheckerboardPS", "ps_4_0");
|
||||
m_DebugRender.OutlinePS = MakePShader(displayhlsl.c_str(), "RENDERDOC_OutlinePS", "ps_4_0");
|
||||
|
||||
m_DebugRender.QuadOverdrawPS = MakePShader(displayhlsl.c_str(), "RENDERDOC_QuadOverdrawPS", "ps_5_0");
|
||||
m_DebugRender.QOResolvePS = MakePShader(displayhlsl.c_str(), "RENDERDOC_QOResolvePS", "ps_5_0");
|
||||
|
||||
@@ -419,6 +419,7 @@ class D3D11DebugManager
|
||||
SAFE_RELEASE(GenericVS);
|
||||
SAFE_RELEASE(TexDisplayPS);
|
||||
SAFE_RELEASE(CheckerboardPS);
|
||||
SAFE_RELEASE(OutlinePS);
|
||||
SAFE_RELEASE(MeshVS);
|
||||
SAFE_RELEASE(MeshGS);
|
||||
SAFE_RELEASE(MeshPS);
|
||||
@@ -505,6 +506,7 @@ class D3D11DebugManager
|
||||
ID3D11VertexShader *GenericVS, *WireframeVS, *MeshVS, *WireframeHomogVS, *FullscreenVS;
|
||||
ID3D11GeometryShader *MeshGS;
|
||||
ID3D11PixelShader *TexDisplayPS, *OverlayPS, *WireframePS, *MeshPS, *CheckerboardPS;
|
||||
ID3D11PixelShader *OutlinePS;
|
||||
ID3D11PixelShader *CopyMSToArrayPS, *CopyArrayToMSPS;
|
||||
ID3D11PixelShader *FloatCopyMSToArrayPS, *FloatCopyArrayToMSPS;
|
||||
ID3D11PixelShader *DepthCopyMSToArrayPS, *DepthCopyArrayToMSPS;
|
||||
|
||||
@@ -516,6 +516,10 @@ void GLReplay::InitDebugData()
|
||||
gl.glEnableVertexAttribArray(0);
|
||||
|
||||
DebugData.replayQuadProg = CreateShaderProgram(blitvsSource.c_str(), genericfsSource.c_str());
|
||||
|
||||
string outlinefsSource = GetEmbeddedResource(outline_frag);
|
||||
|
||||
DebugData.outlineQuadProg = CreateShaderProgram(blitvsSource.c_str(), outlinefsSource.c_str());
|
||||
|
||||
MakeCurrentReplayContext(&m_ReplayCtx);
|
||||
|
||||
@@ -633,6 +637,7 @@ void GLReplay::DeleteDebugData()
|
||||
gl.glDeleteBuffers(1, &DebugData.triHighlightBuffer);
|
||||
|
||||
gl.glDeleteProgram(DebugData.replayQuadProg);
|
||||
gl.glDeleteProgram(DebugData.outlineQuadProg);
|
||||
}
|
||||
|
||||
bool GLReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uint32_t sample, float *minval, float *maxval)
|
||||
@@ -1869,21 +1874,42 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, TextureDisplayOverlay overl
|
||||
gl.glClearBufferfv(eGL_COLOR, 0, col);
|
||||
|
||||
// don't need to use the existing program at all!
|
||||
gl.glUseProgram(DebugData.replayQuadProg);
|
||||
gl.glUseProgram(DebugData.outlineQuadProg);
|
||||
gl.glBindProgramPipeline(0);
|
||||
|
||||
GLint colLoc = gl.glGetUniformLocation(DebugData.replayQuadProg, "RENDERDOC_GenericFS_Color");
|
||||
float viewportConsts[] = { 0.15f, 0.3f, 0.6f, 0.3f };
|
||||
gl.glUniform4fv(colLoc, 1, viewportConsts);
|
||||
gl.glDisablei(eGL_SCISSOR_TEST, 0);
|
||||
|
||||
gl.glViewportIndexedf(0, rs.Viewports[0].x, rs.Viewports[0].y, rs.Viewports[0].width, rs.Viewports[0].height);
|
||||
|
||||
GLint innerLoc = gl.glGetUniformLocation(DebugData.outlineQuadProg, "RENDERDOC_Inner_Color");
|
||||
GLint borderLoc = gl.glGetUniformLocation(DebugData.outlineQuadProg, "RENDERDOC_Border_Color");
|
||||
GLint rectLoc = gl.glGetUniformLocation(DebugData.outlineQuadProg, "RENDERDOC_ViewRect");
|
||||
GLint scissorLoc = gl.glGetUniformLocation(DebugData.outlineQuadProg, "RENDERDOC_Scissor");
|
||||
|
||||
float innerConsts[] = { 0.2f, 0.2f, 0.9f, 0.7f };
|
||||
gl.glUniform4fv(innerLoc, 1, innerConsts);
|
||||
|
||||
float borderConsts[] = { 0.1f, 0.1f, 0.1f, 1.0f };
|
||||
gl.glUniform4fv(borderLoc, 1, borderConsts);
|
||||
|
||||
gl.glUniform4fv(rectLoc, 1, (float *)rs.Viewports);
|
||||
|
||||
gl.glUniform1ui(scissorLoc, 0);
|
||||
|
||||
gl.glDrawArrays(eGL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
gl.glEnablei(eGL_SCISSOR_TEST, 0);
|
||||
|
||||
float scissorConsts[] = { 0.5f, 0.6f, 0.8f, 0.3f };
|
||||
gl.glUniform4fv(colLoc, 1, scissorConsts);
|
||||
|
||||
gl.glDrawArrays(eGL_TRIANGLE_STRIP, 0, 4);
|
||||
if(rs.Scissors[0].enabled)
|
||||
{
|
||||
Vec4f scissor((float)rs.Scissors[0].x, (float)rs.Scissors[0].y, (float)rs.Scissors[0].width, (float)rs.Scissors[0].height);
|
||||
|
||||
gl.glViewportIndexedf(0, scissor.x, scissor.y, scissor.z, scissor.w);
|
||||
|
||||
gl.glUniform4fv(rectLoc, 1, (float *)&scissor);
|
||||
|
||||
gl.glUniform1ui(scissorLoc, 1);
|
||||
|
||||
gl.glDrawArrays(eGL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
}
|
||||
else if(overlay == eTexOverlay_Depth || overlay == eTexOverlay_Stencil)
|
||||
{
|
||||
|
||||
@@ -246,6 +246,7 @@ class GLReplay : public IReplayDriver
|
||||
GLuint histogramProgram[64]; // RESTYPE indexed (see debuguniforms.h, 1d/2d/3d etc | uint/sint) src tex -> histogram result buf program
|
||||
|
||||
GLuint replayQuadProg;
|
||||
GLuint outlineQuadProg;
|
||||
|
||||
// program that does a blit of texture from input to output,
|
||||
// no transformation or scaling
|
||||
|
||||
@@ -345,6 +345,7 @@
|
||||
<None Include="data\glsl\mesh.frag" />
|
||||
<None Include="data\glsl\mesh.geom" />
|
||||
<None Include="data\glsl\mesh.vert" />
|
||||
<None Include="data\glsl\outline.frag" />
|
||||
<None Include="data\glsl\quadoverdraw.frag" />
|
||||
<None Include="data\glsl\texdisplay.frag" />
|
||||
<None Include="data\glsl\text.frag" />
|
||||
|
||||
@@ -421,6 +421,9 @@
|
||||
<None Include="data\glsl\mesh.comp">
|
||||
<Filter>Resources\glsl</Filter>
|
||||
</None>
|
||||
<None Include="data\glsl\outline.frag">
|
||||
<Filter>Resources\glsl</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="data\renderdoc.rc">
|
||||
|
||||
Reference in New Issue
Block a user