diff options
| author | Scott Mansell <phiren@gmail.com> | 2015-01-03 06:06:56 +1300 |
|---|---|---|
| committer | Scott Mansell <phiren@gmail.com> | 2015-01-23 03:32:31 +1300 |
| commit | 88c7afd315d06c27e459a8352f753cdeca5a1fe5 (patch) | |
| tree | 9f207f8dc65159d269ef534479672e007e99e3cb /Source/Core/VideoCommon/PixelShaderGen.cpp | |
| parent | 418296961cba39e4ae5bc441b3f52bf1459ad2bb (diff) | |
Make zfreeze use screenspace coordinates independant of IR.
OpenGL requires the y coordinates to be flipped.
Also refactored PixelGen code to remove duplicate code.
Diffstat (limited to 'Source/Core/VideoCommon/PixelShaderGen.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/PixelShaderGen.cpp | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 8bc7a7980b..5899f0100b 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -144,6 +144,7 @@ template<class T> static inline void WriteTevRegular(T& out, const char* compone template<class T> static inline void SampleTexture(T& out, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType); template<class T> static inline void WriteAlphaTest(T& out, pixel_shader_uid_data* uid_data, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth); template<class T> static inline void WriteFog(T& out, pixel_shader_uid_data* uid_data); +template<class T> static inline void WritePerPixelDepth(T& out, pixel_shader_uid_data* uid_data, API_TYPE ApiType); template<class T> static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) @@ -229,6 +230,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T "\tint4 " I_FOGI";\n" "\tfloat4 " I_FOGF"[2];\n" "\tfloat4 " I_ZSLOPE";\n" + "\tfloat4 " I_EFBSCALE";\n" "};\n"); if (g_ActiveConfig.bEnablePixelLighting) @@ -544,14 +546,7 @@ 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()) { - if (bpmem.genMode.zfreeze) - { - out.Write("\tdepth = float(" I_ZSLOPE".z + " I_ZSLOPE".x * rawpos.x + " I_ZSLOPE".y * rawpos.y) / float(0xffffff);\n"); - } - else - { - out.Write("\tdepth = float(zCoord) / float(0xFFFFFF);\n"); - } + WritePerPixelDepth<T>(out, uid_data, ApiType); } // Note: depth texture output is only written to depth buffer if late depth test is used @@ -567,14 +562,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T if (per_pixel_depth && bpmem.UseLateDepthTest()) { - if (bpmem.genMode.zfreeze) - { - out.Write("\tdepth = float(" I_ZSLOPE".z + " I_ZSLOPE".x * rawpos.x + " I_ZSLOPE".y * rawpos.y) / float(0xffffff);\n"); - } - else - { - out.Write("\tdepth = float(zCoord) / float(0xFFFFFF);\n"); - } + WritePerPixelDepth<T>(out, uid_data, ApiType); } if (dstAlphaMode == DSTALPHA_ALPHA_PASS) @@ -1115,6 +1103,29 @@ static inline void WriteFog(T& out, pixel_shader_uid_data* uid_data) out.Write("\tprev.rgb = (prev.rgb * (256 - ifog) + " I_FOGCOLOR".rgb * ifog) >> 8;\n"); } +template<class T> +static inline void WritePerPixelDepth(T& out, pixel_shader_uid_data* uid_data, API_TYPE ApiType) +{ + if (bpmem.genMode.zfreeze) + { + out.SetConstantsUsed(C_ZSLOPE, C_ZSLOPE); + out.SetConstantsUsed(C_EFBSCALE, C_EFBSCALE); + + out.Write("\tfloat2 screenpos = rawpos.xy * " I_EFBSCALE".xy;\n"); + + // Opengl has reversed vertical screenspace coordiantes + if(ApiType == API_OPENGL) + out.Write("\tscreenpos.y = %i - screenpos.y - 1;\n", EFB_HEIGHT); + + out.Write("\tdepth = float(" I_ZSLOPE".z + " I_ZSLOPE".x * screenpos.x + " I_ZSLOPE".y * screenpos.y) / float(0xffffff);\n"); + } + else + { + out.Write("\tdepth = float(zCoord) / float(0xFFFFFF);\n"); + } +} + + void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) { GeneratePixelShader<PixelShaderUid>(object, dstAlphaMode, ApiType, components); |
