diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-04 23:21:24 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-04 23:21:24 +0000 |
| commit | 19dcf476e8f9b079191bd43ee8da9e9cfe5e3e64 (patch) | |
| tree | 4ebd90768fbcd8c6f5dda8f48e8558f59bf4a262 /Graphics/HLSL2GLSLConverterLib | |
| parent | Fixed few issues with 3D texture views in GL and VK (diff) | |
| download | DiligentCore-19dcf476e8f9b079191bd43ee8da9e9cfe5e3e64.tar.gz DiligentCore-19dcf476e8f9b079191bd43ee8da9e9cfe5e3e64.zip | |
Corrected depth-related GLSL definitions for Vulkan case
Diffstat (limited to 'Graphics/HLSL2GLSLConverterLib')
| -rw-r--r-- | Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h | 23 | ||||
| -rw-r--r-- | Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h | 23 |
2 files changed, 30 insertions, 16 deletions
diff --git a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h index 8fb4fd70..35c4c839 100644 --- a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h +++ b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h @@ -981,25 +981,32 @@ uvec4 _ToUvec( vec4 f4 ){ return _ToUvec4( f4.x, f4.y, f4.z, f4.w ); } // Helper functions +#ifdef TARGET_API_VULKAN + +#define NDC_MIN_Z 0.0 // Minimal z in the normalized device space +#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 1.0) + +#else + +#define NDC_MIN_Z -1.0 // Minimal z in the normalized device space +#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5) + +#endif + float2 NormalizedDeviceXYToTexUV( float2 f2ProjSpaceXY ) { - return float2(0.5,0.5) + float2(0.5,0.5) * f2ProjSpaceXY.xy; + return float2(0.5,0.5) + F3NDC_XYZ_TO_UVD_SCALE.xy * f2ProjSpaceXY.xy; } float NormalizedDeviceZToDepth(float fNDC_Z) { - return fNDC_Z * 0.5 + 0.5; // [-1, +1] -> [0, 1] + return (fNDC_Z - NDC_MIN_Z) * F3NDC_XYZ_TO_UVD_SCALE.z; } - float DepthToNormalizedDeviceZ(float fDepth) { - return fDepth * 2.0 - 1.0; // [0, 1] -> [-1, +1] + return fDepth / F3NDC_XYZ_TO_UVD_SCALE.z + NDC_MIN_Z; } -#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5) - -#define NDC_MIN_Z -1.0 // Minimal z in the normalized device space - #define MATRIX_ELEMENT(mat, row, col) mat[col][row] float4x4 MatrixFromRows(float4 row0, float4 row1, float4 row2, float4 row3) diff --git a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h index cdbc0527..20b9e2f0 100644 --- a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h +++ b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h @@ -981,25 +981,32 @@ "\n" "// Helper functions\n" "\n" +"#ifdef TARGET_API_VULKAN\n" +"\n" +"#define NDC_MIN_Z 0.0 // Minimal z in the normalized device space\n" +"#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 1.0)\n" +"\n" +"#else\n" +"\n" +"#define NDC_MIN_Z -1.0 // Minimal z in the normalized device space\n" +"#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5)\n" +"\n" +"#endif\n" +"\n" "float2 NormalizedDeviceXYToTexUV( float2 f2ProjSpaceXY )\n" "{\n" -" return float2(0.5,0.5) + float2(0.5,0.5) * f2ProjSpaceXY.xy;\n" +" return float2(0.5,0.5) + F3NDC_XYZ_TO_UVD_SCALE.xy * f2ProjSpaceXY.xy;\n" "}\n" "\n" "float NormalizedDeviceZToDepth(float fNDC_Z)\n" "{\n" -" return fNDC_Z * 0.5 + 0.5; // [-1, +1] -> [0, 1]\n" +" return (fNDC_Z - NDC_MIN_Z) * F3NDC_XYZ_TO_UVD_SCALE.z;\n" "}\n" -"\n" "float DepthToNormalizedDeviceZ(float fDepth)\n" "{\n" -" return fDepth * 2.0 - 1.0; // [0, 1] -> [-1, +1]\n" +" return fDepth / F3NDC_XYZ_TO_UVD_SCALE.z + NDC_MIN_Z;\n" "}\n" "\n" -"#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, 0.5, 0.5)\n" -"\n" -"#define NDC_MIN_Z -1.0 // Minimal z in the normalized device space\n" -"\n" "#define MATRIX_ELEMENT(mat, row, col) mat[col][row]\n" "\n" "float4x4 MatrixFromRows(float4 row0, float4 row1, float4 row2, float4 row3)\n" |
