From 636f2b9d2b579c767c5ae7c8c5ddf1fd02de0b0a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 4 Jul 2018 16:48:36 -0700 Subject: Added NDC attribs data to DeviceCaps structure --- Graphics/GraphicsEngine/interface/DeviceCaps.h | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/interface/DeviceCaps.h b/Graphics/GraphicsEngine/interface/DeviceCaps.h index b4e00081..496f3599 100644 --- a/Graphics/GraphicsEngine/interface/DeviceCaps.h +++ b/Graphics/GraphicsEngine/interface/DeviceCaps.h @@ -129,5 +129,44 @@ namespace Diligent { return DevType == DeviceType::Vulkan; } + + struct NDCAttribs + { + const float MinZ; // Minimum z value of normalized device coordinate space + const float ZtoDepthScale; // NDC z to depth scale + const float YtoVScale; // Scale to transform NDC y coordinate to texture V coordinate + + float GetZtoDepthBias() const + { + // Returns ZtoDepthBias such that given NDC z coordinate, depth value can be + // computed as follows: + // d = z * ZtoDepthScale + ZtoDepthBias + return -MinZ * ZtoDepthScale; + } + }; + + const NDCAttribs& GetNDCAttribs()const + { + if (IsVulkanDevice()) + { + static constexpr const NDCAttribs NDCAttribsVk {0.0f, 1.0f, 0.5f}; + return NDCAttribsVk; + } + else if (IsD3DDevice()) + { + static constexpr const NDCAttribs NDCAttribsD3D {0.0f, 1.0f, -0.5f}; + return NDCAttribsD3D; + } + else if (IsGLDevice()) + { + static constexpr const NDCAttribs NDCAttribsGL {-1.0f, 0.5f, 0.5f}; + return NDCAttribsGL; + } + else + { + static constexpr const NDCAttribs NDCAttribsDefault {0.0f, 1.0f, 0.5f}; + return NDCAttribsDefault; + } + } }; } -- cgit v1.2.3