mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-22 22:46:41 +00:00
Reverse-Z detection on output for vulkan
This commit is contained in:
@@ -5053,6 +5053,8 @@ void VulkanDebugManager::InitPostVSBuffers(uint32_t frameID, uint32_t eventID)
|
||||
float farp = 100.0f;
|
||||
|
||||
Vec4f *pos0 = (Vec4f *)byteData;
|
||||
|
||||
bool found = false;
|
||||
|
||||
// expect position at the start of the buffer, as system values are sorted first
|
||||
// and position is the first value
|
||||
@@ -5080,7 +5082,7 @@ void VulkanDebugManager::InitPostVSBuffers(uint32_t frameID, uint32_t eventID)
|
||||
Vec4f *pos = (Vec4f *)(byteData + i*bufStride);
|
||||
|
||||
// skip invalid vertices (w=0)
|
||||
if(pos->w > 0.0f && fabs(pos->w - pos0->w) > 0.01f)
|
||||
if(pos->w != 0.0f && fabs(pos->w - pos0->w) > 0.01f && fabs(pos->z - pos0->z) > 0.01f)
|
||||
{
|
||||
Vec2f A(pos0->w, pos0->z);
|
||||
Vec2f B(pos->w, pos->z);
|
||||
@@ -5095,10 +5097,21 @@ void VulkanDebugManager::InitPostVSBuffers(uint32_t frameID, uint32_t eventID)
|
||||
nearp = -c/m;
|
||||
farp = c/(1-m);
|
||||
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we didn't find anything, all z's and w's were identical.
|
||||
// If the z is positive and w greater for the first element then
|
||||
// we detect this projection as reversed z with infinite far plane
|
||||
if(!found && pos0->z > 0.0f && pos0->w > pos0->z)
|
||||
{
|
||||
nearp = pos0->z;
|
||||
farp = FLT_MAX;
|
||||
}
|
||||
|
||||
m_pDriver->vkUnmapMemory(m_Device, readbackMem);
|
||||
|
||||
// clean up temporary memories
|
||||
|
||||
@@ -1520,7 +1520,9 @@ void VulkanReplay::RenderMesh(uint32_t frameID, uint32_t eventID, const vector<M
|
||||
{
|
||||
// the derivation of the projection matrix might not be right (hell, it could be an
|
||||
// orthographic projection). But it'll be close enough likely.
|
||||
Matrix4f guessProj = Matrix4f::Perspective(cfg.fov, cfg.position.nearPlane, cfg.position.farPlane, cfg.aspect);
|
||||
Matrix4f guessProj = cfg.position.farPlane != FLT_MAX
|
||||
? Matrix4f::Perspective(cfg.fov, cfg.position.nearPlane, cfg.position.farPlane, cfg.aspect)
|
||||
: Matrix4f::ReversePerspective(cfg.fov, cfg.position.nearPlane, cfg.aspect);
|
||||
|
||||
if(cfg.ortho)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user