diff options
| author | Jules Blok <jules.blok@gmail.com> | 2015-05-26 15:39:50 +0200 |
|---|---|---|
| committer | Jules Blok <jules.blok@gmail.com> | 2015-05-26 15:39:50 +0200 |
| commit | 0b61a0dfc591cbbac7a450bb8b5a7166c9504e51 (patch) | |
| tree | a3c9f5d568cc50e44dd0234d3d69221415c249f5 /Source/Core/VideoCommon | |
| parent | d7900b442367c4481b66a35fbcb1d30dd5c25176 (diff) | |
| parent | ca7801da449d214bebdfd2573aeae16cd492bc72 (diff) | |
Merge pull request #2448 from Armada651/depth-inversion
D3D: Depth range inversion.
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/PixelShaderGen.cpp | 17 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/TextureConversionShader.cpp | 10 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderGen.cpp | 2 |
3 files changed, 24 insertions, 5 deletions
diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index ecb47d5584..d9d8c18599 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -582,7 +582,10 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T } else { - out.Write("\tint zCoord = int(rawpos.z * 16777216.0);\n"); + if (ApiType == API_D3D) + out.Write("\tint zCoord = int((1.0 - rawpos.z) * 16777216.0);\n"); + else + out.Write("\tint zCoord = int(rawpos.z * 16777216.0);\n"); } out.Write("\tzCoord = clamp(zCoord, " I_ZBIAS"[1].x - " I_ZBIAS"[1].y, " I_ZBIAS"[1].x);\n"); @@ -600,7 +603,10 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T // Note: z-textures are not written to depth buffer if early depth test is used if (per_pixel_depth && bpmem.UseEarlyDepthTest()) { - out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); + if (ApiType == API_D3D) + out.Write("\tdepth = 1.0 - float(zCoord) / 16777216.0;\n"); + else + out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); } // Note: depth texture output is only written to depth buffer if late depth test is used @@ -616,7 +622,10 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T if (per_pixel_depth && bpmem.UseLateDepthTest()) { - out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); + if (ApiType == API_D3D) + out.Write("\tdepth = 1.0 - float(zCoord) / 16777216.0;\n"); + else + out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); } if (dstAlphaMode == DSTALPHA_ALPHA_PASS) @@ -1129,7 +1138,7 @@ static inline void WriteAlphaTest(T& out, pixel_shader_uid_data* uid_data, API_T if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) out.Write("\t\tocol1 = float4(0.0, 0.0, 0.0, 0.0);\n"); if (per_pixel_depth) - out.Write("\t\tdepth = 1.0;\n"); + out.Write("\t\tdepth = %s;\n", (ApiType == API_D3D) ? "0.0" : "1.0"); // ZCOMPLOC HACK: // The only way to emulate alpha test + early-z is to force early-z in the shader. diff --git a/Source/Core/VideoCommon/TextureConversionShader.cpp b/Source/Core/VideoCommon/TextureConversionShader.cpp index fac5a0823c..f93d465a16 100644 --- a/Source/Core/VideoCommon/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/TextureConversionShader.cpp @@ -462,15 +462,19 @@ static void WriteZ8Encoder(char*& p, const char* multiplier,API_TYPE ApiType) WRITE(p, " float depth;\n"); WriteSampleColor(p, "r", "depth", 0, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier); WriteSampleColor(p, "r", "depth", 1, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier); WriteSampleColor(p, "r", "depth", 2, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier); WriteSampleColor(p, "r", "depth", 3, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier); WriteEncoderEnd(p, ApiType); @@ -486,6 +490,7 @@ static void WriteZ16Encoder(char*& p,API_TYPE ApiType) // byte order is reversed WriteSampleColor(p, "r", "depth", 0, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, " depth = clamp(depth * 16777216.0, 0.0, float(0xFFFFFF));\n"); WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n"); @@ -496,6 +501,7 @@ static void WriteZ16Encoder(char*& p,API_TYPE ApiType) WRITE(p, " ocol0.g = expanded.r / 255.0;\n"); WriteSampleColor(p, "r", "depth", 1, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, " depth = clamp(depth * 16777216.0, 0.0, float(0xFFFFFF));\n"); WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n"); @@ -518,6 +524,7 @@ static void WriteZ16LEncoder(char*& p,API_TYPE ApiType) // byte order is reversed WriteSampleColor(p, "r", "depth", 0, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, " depth = clamp(depth * 16777216.0, 0.0, float(0xFFFFFF));\n"); WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n"); @@ -530,6 +537,7 @@ static void WriteZ16LEncoder(char*& p,API_TYPE ApiType) WRITE(p, " ocol0.g = expanded.g / 255.0;\n"); WriteSampleColor(p, "r", "depth", 1, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth = 1.0f - depth;\n"); WRITE(p, " depth = clamp(depth * 16777216.0, 0.0, float(0xFFFFFF));\n"); WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n"); @@ -554,7 +562,9 @@ static void WriteZ24Encoder(char*& p, API_TYPE ApiType) WRITE(p, " float3 expanded1;\n"); WriteSampleColor(p, "r", "depth0", 0, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth0 = 1.0f - depth0;\n"); WriteSampleColor(p, "r", "depth1", 1, ApiType); + if (ApiType == API_D3D) WRITE(p, "depth1 = 1.0f - depth1;\n"); for (int i = 0; i < 2; i++) { diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 28c2e1c827..084ac48aaf 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -385,7 +385,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ } else if (api_type == API_D3D) { - out.Write("o.pos.z = o.pos.w + o.pos.z;\n"); + out.Write("o.pos.z = -o.pos.z;\n"); } else // OGL { |
