Skip to content

Commit

Permalink
Mesh exploder
Browse files Browse the repository at this point in the history
vulkan, d3d11, d3d12 and ogl vtx exploding in BufferViewer toolbar
  • Loading branch information
GertyP committed Nov 14, 2023
1 parent caef1b9 commit 0769933
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 5 deletions.
33 changes: 33 additions & 0 deletions qrenderdoc/Styles/RDStyle/RDStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,26 @@ QRect RDStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,

return opt->rect;
}
else if(cc == QStyle::CC_Slider)
{
QRect ret = opt->rect;
ret.adjust(4,1,-4,-1);
if(sc == QStyle::SC_SliderGroove)
{
int halfHeightLessMargin = ret.height() / 2 - 2;
ret.adjust(0, halfHeightLessMargin, 0, -halfHeightLessMargin);
}
else if(sc == QStyle::SC_SliderHandle)
{
ret.adjust(0, 2, 0, -2);
const QAbstractSlider *slider = qobject_cast<const QAbstractSlider *>(widget);
qreal posUNorm = (qreal)(slider->sliderPosition() - slider->minimum()) / (qreal)(slider->maximum() - slider->minimum());
int sliderX = ret.left() + posUNorm * ret.width();
ret.setLeft(sliderX - 3);
ret.setRight(sliderX + 3);
}
return ret;
}
else if(cc == QStyle::CC_ComboBox)
{
QRect rect = opt->rect;
Expand Down Expand Up @@ -1118,6 +1138,19 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl

return;
}
else if(control == QStyle::CC_Slider)
{
QRect grooveRect = subControlRect(control, opt, QStyle::SC_SliderGroove, widget);
p->drawLine(QLine(grooveRect.x(), grooveRect.y() + grooveRect.height() / 2,
grooveRect.right(), grooveRect.y() + grooveRect.height() / 2));

QRect handleRect = subControlRect(control, opt, QStyle::SC_SliderHandle, widget);
QBrush sliderBrush = opt->palette.brush(QPalette::Dark);
p->setPen(QPen(sliderBrush, 2.5));
p->drawRoundedRect(handleRect, 3.0, 3.0);

return;
}
else if(control == QStyle::CC_ComboBox)
{
const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt);
Expand Down
14 changes: 14 additions & 0 deletions qrenderdoc/Windows/BufferViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5789,6 +5789,20 @@ void BufferViewer::on_highlightVerts_toggled(bool checked)
INVOKE_MEMFN(RT_UpdateAndDisplay);
}

void BufferViewer::on_vtxExploderSlider_valueChanged(int value)
{
m_Config.vtxExploderSliderSNorm = (float)value / 100.0f;

INVOKE_MEMFN(RT_UpdateAndDisplay);
}

void BufferViewer::on_vtxExploderSlider_sliderReleased()
{
//Always snaps back to zero
QAbstractSlider *slider = ui->controlsToolbar->findChild<QAbstractSlider*>(QStringLiteral("vtxExploderSlider"));
slider->setSliderPosition(0);
}

void BufferViewer::on_wireframeRender_toggled(bool checked)
{
m_Config.wireframeDraw = checked;
Expand Down
2 changes: 2 additions & 0 deletions qrenderdoc/Windows/BufferViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private slots:
void on_showPadding_toggled(bool checked);
void on_resourceDetails_clicked();
void on_highlightVerts_toggled(bool checked);
void on_vtxExploderSlider_valueChanged(int value);
void on_vtxExploderSlider_sliderReleased();
void on_wireframeRender_toggled(bool checked);
void on_solidShading_currentIndexChanged(int index);
void on_drawRange_currentIndexChanged(int index);
Expand Down
89 changes: 86 additions & 3 deletions qrenderdoc/Windows/BufferViewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>788</width>
<height>537</height>
<width>1318</width>
<height>837</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -120,7 +120,7 @@
<rect>
<x>50</x>
<y>220</y>
<width>666</width>
<width>866</width>
<height>312</height>
</rect>
</property>
Expand Down Expand Up @@ -382,6 +382,89 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="vtxExploderLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Exploder</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="vtxExploderSlider">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>30</height>
</size>
</property>
<property name="baseSize">
<size>
<width>90</width>
<height>30</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string>Explode vertices</string>
</property>
<property name="accessibleName">
<string>slider name</string>
</property>
<property name="accessibleDescription">
<string>slider description</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="sliderPosition">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>20</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
2 changes: 2 additions & 0 deletions renderdoc/api/replay/control_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ struct MeshDisplay
SolidShade solidShadeMode = SolidShade::NoSolid;
DOCUMENT("``True`` if the wireframe of the mesh should be rendered as well as solid shading.");
bool wireframeDraw = true;
DOCUMENT("Displace/explode vertices to help visualise vertex reuse vs disjointedness.");
float vtxExploderSliderSNorm = 0.0f;

static const uint32_t NoHighlight = ~0U;
};
Expand Down
3 changes: 2 additions & 1 deletion renderdoc/data/glsl/glsl_ubos.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ BINDING(0) uniform MeshUBOData
vec2 pointSpriteSize;
uint rawoutput;
uint flipY;
vec2 padding;
float vtxExploderSNorm;
float padding;
}
INST_NAME(Mesh);

Expand Down
10 changes: 10 additions & 0 deletions renderdoc/data/glsl/mesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
#define SECONDARY_TYPE vec4
#endif

vec3 vtxExploder(vec3 pos, int vid)
{
float nonLinearVtxExplodeScale = 8.0f * Mesh.vtxExploderSNorm * Mesh.vtxExploderSNorm * Mesh.vtxExploderSNorm;
vec3 explodeDir = normalize(pos);

float displacement = nonLinearVtxExplodeScale * ((float((vid >> 1) & 0xf) / 15.0f) * 1.5f - 0.5f);
return pos + (explodeDir * displacement);
}

IO_LOCATION(0) in POSITION_TYPE vsin_position;
IO_LOCATION(1) in SECONDARY_TYPE vsin_secondary;

Expand All @@ -48,6 +57,7 @@ void main(void)
vec2[](vec2(-1.0f, -1.0f), vec2(-1.0f, 1.0f), vec2(1.0f, -1.0f), vec2(1.0f, 1.0f));

vec4 pos = vec4(vsin_position);
pos.xyz = vtxExploder(pos.xyz, VERTEX_ID);
if(Mesh.homogenousInput == 0u)
{
pos = vec4(pos.xyz, 1);
Expand Down
2 changes: 2 additions & 0 deletions renderdoc/data/hlsl/hlsl_cbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ cbuffer MeshVertexCBuffer REG(b0)
float2 SpriteSize;

uint homogenousInput;

float vtxExploderSNorm;
};

cbuffer MeshGeometryCBuffer REG(b0)
Expand Down
10 changes: 10 additions & 0 deletions renderdoc/data/hlsl/mesh.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ struct meshA2V
float4 secondary : sec;
};

float3 vtxExploder(float3 pos, uint vid)
{
float nonLinearVtxExplodeScale = 8.0f * vtxExploderSNorm * vtxExploderSNorm * vtxExploderSNorm;
float3 explodeDir = normalize(pos);

float displacement = nonLinearVtxExplodeScale * ((float((vid >> 1u) & 0xfu) / 15.0f) * 1.5f - 0.5f);
return pos + (explodeDir * displacement);
}

meshV2F RENDERDOC_MeshVS(meshA2V IN, uint vid : SV_VertexID)
{
meshV2F OUT = (meshV2F)0;
Expand All @@ -45,6 +54,7 @@ meshV2F RENDERDOC_MeshVS(meshA2V IN, uint vid : SV_VertexID)
float2(1.0f, 1.0f)};

float4 pos = IN.pos;
pos.xyz = vtxExploder(pos.xyz, vid);

if(homogenousInput == 0u)
{
Expand Down
2 changes: 2 additions & 0 deletions renderdoc/driver/d3d11/d3d11_rendermesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void D3D11Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
vertexData.ModelViewProj = projMat.Mul(camMat.Mul(axisMapMat));
vertexData.SpriteSize = Vec2f();
vertexData.homogenousInput = cfg.position.unproject;
vertexData.vtxExploderSNorm = cfg.vtxExploderSliderSNorm;

Vec4f col(0.0f, 0.0f, 0.0f, 1.0f);
ID3D11Buffer *psCBuf = GetDebugManager()->MakeCBuffer(&col, sizeof(col));
Expand Down Expand Up @@ -329,6 +330,7 @@ void D3D11Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
// set up state for drawing helpers
{
vertexData.ModelViewProj = projMat.Mul(camMat.Mul(axisMapMat));
vertexData.vtxExploderSNorm = 0.0f;
GetDebugManager()->FillCBuffer(vsCBuf, &vertexData, sizeof(vertexData));

m_pImmediateContext->RSSetState(m_MeshRender.SolidRasterState);
Expand Down
2 changes: 2 additions & 0 deletions renderdoc/driver/d3d12/d3d12_rendermesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ void D3D12Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
vertexData.ModelViewProj = projMat.Mul(camMat.Mul(axisMapMat));
vertexData.SpriteSize = Vec2f();
vertexData.homogenousInput = cfg.position.unproject;
vertexData.vtxExploderSNorm = cfg.vtxExploderSliderSNorm;

MeshPixelCBuffer pixelData;

Expand Down Expand Up @@ -577,6 +578,7 @@ void D3D12Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
pixelData.MeshDisplayFormat = MESHDISPLAY_SOLID;

vertexData.homogenousInput = 0U;
vertexData.vtxExploderSNorm = 0.0f;

vsCB = GetDebugManager()->UploadConstants(&vertexData, sizeof(vertexData));

Expand Down
4 changes: 4 additions & 0 deletions renderdoc/driver/gl/gl_rendermesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void GLReplay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secondar
uboParams.mvp = ModelViewProj;
uboParams.homogenousInput = cfg.position.unproject;
uboParams.pointSpriteSize = Vec2f(0.0f, 0.0f);
uboParams.vtxExploderSNorm = cfg.vtxExploderSliderSNorm;

if(!secondaryDraws.empty())
{
Expand Down Expand Up @@ -366,6 +367,7 @@ void GLReplay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secondar
soliddata->mvp = ModelViewProj;
soliddata->pointSpriteSize = Vec2f(0.0f, 0.0f);
soliddata->homogenousInput = cfg.position.unproject;
soliddata->vtxExploderSNorm = cfg.vtxExploderSliderSNorm;

soliddata->color = Vec4f(0.8f, 0.8f, 0.0f, 1.0f);

Expand Down Expand Up @@ -469,6 +471,8 @@ void GLReplay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secondar
// helpers always use basic float-input program
drv.glUseProgram(DebugData.meshProg[0]);

uboParams.vtxExploderSNorm = 0.0f;

if(cfg.showBBox)
{
Vec4f a = Vec4f(cfg.minBounds.x, cfg.minBounds.y, cfg.minBounds.z, cfg.minBounds.w);
Expand Down
3 changes: 2 additions & 1 deletion renderdoc/driver/vulkan/vk_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,8 @@ ResourceId VulkanReplay::RenderOverlay(ResourceId texid, FloatVector clearCol, D
data->displayFormat = 0;
data->rawoutput = 1;
data->flipY = 0;
data->padding = Vec2f();
data->vtxExploderSNorm = 0.0f;
data->padding = 0.0f;
m_MeshRender.UBO.Unmap();

uint32_t viewOffs = 0;
Expand Down
Loading

0 comments on commit 0769933

Please sign in to comment.