OSDN Git Service

Fix clamping depth output to [0, 1] range.
authorNicolas Capens <capn@google.com>
Tue, 2 Jan 2018 20:55:11 +0000 (15:55 -0500)
committerNicolas Capens <nicolascapens@google.com>
Wed, 3 Jan 2018 14:11:25 +0000 (14:11 +0000)
OpenGL ES 3.0 specifies that "For fixed-point depth buffers, the final
fragment depth written by a fragment shader is first clamped to [0, 1]
and then converted to fixed-point as if it were a window z value (see
section 2.13.1). For floating-point depth buffers, conversion is not
performed but clamping is."

Change-Id: Ic7f22f7e47106aaa86c4916fbbbe23ad9c52e186
Reviewed-on: https://swiftshader-review.googlesource.com/15628
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/Shader/PixelPipeline.cpp
src/Shader/PixelProgram.cpp

index e623735..d4faebd 100644 (file)
@@ -256,15 +256,15 @@ namespace sw
                                }
                        }
                }
-       }
 
-       Bool PixelPipeline::alphaTest(Int cMask[4])
-       {
                current.x = Min(current.x, Short4(0x0FFF)); current.x = Max(current.x, Short4(0x0000));
                current.y = Min(current.y, Short4(0x0FFF)); current.y = Max(current.y, Short4(0x0000));
                current.z = Min(current.z, Short4(0x0FFF)); current.z = Max(current.z, Short4(0x0000));
                current.w = Min(current.w, Short4(0x0FFF)); current.w = Max(current.w, Short4(0x0000));
+       }
 
+       Bool PixelPipeline::alphaTest(Int cMask[4])
+       {
                if(!state.alphaTestActive())
                {
                        return true;
index 3e9082d..9ee5869 100644 (file)
@@ -525,12 +525,17 @@ namespace sw
                                c[i] = oC[i];
                        }
                }
+
+               clampColor(c);
+
+               if(state.depthOverride)
+               {
+                       oDepth = Min(Max(oDepth, Float4(0.0f)), Float4(1.0f));
+               }
        }
 
        Bool PixelProgram::alphaTest(Int cMask[4])
        {
-               clampColor(c);
-
                if(!state.alphaTestActive())
                {
                        return true;