Fix transparent ambient for perspective shadows
authorJim Van Verth <jvanverth@google.com>
Thu, 11 May 2017 14:23:53 +0000 (10:23 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 11 May 2017 14:52:56 +0000 (14:52 +0000)
When splitting the long edges for the ambient code, I wasn't adding
the corresponding triangle for the new point into the center region
for transparent occluders.

Change-Id: Ie2d1dcffbd701c0750d5da95e9d673b700a0e85a
Reviewed-on: https://skia-review.googlesource.com/16492
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>

src/utils/SkShadowTessellator.cpp

index 9a82ec3..d8990d3 100755 (executable)
@@ -449,6 +449,16 @@ SkAmbientShadowTessellator::SkAmbientShadowTessellator(const SkPath& path,
             *fIndices.push() = fPositions.count() - 1;
             *fIndices.push() = fPositions.count() - 2;
 
+            // if transparent, add point to first one in array and add to center fan
+            if (fTransparent) {
+                fPositions[0] += centerPoint;
+                ++fCentroidCount;
+
+                *fIndices.push() = 0;
+                *fIndices.push() = fPrevUmbraIndex;
+                *fIndices.push() = fPositions.count() - 2;
+            }
+
             fPrevUmbraIndex = fPositions.count() - 2;
         }
 
@@ -479,6 +489,7 @@ SkAmbientShadowTessellator::SkAmbientShadowTessellator(const SkPath& path,
     // finalize centroid
     if (fTransparent) {
         fPositions[0] *= SkScalarFastInvert(fCentroidCount);
+        fColors[0] = this->umbraColor(fTransformedHeightFunc(fPositions[0]));
 
         *fIndices.push() = 0;
         *fIndices.push() = fPrevUmbraIndex;
@@ -606,6 +617,16 @@ void SkAmbientShadowTessellator::addEdge(const SkPoint& nextPoint, const SkVecto
             *fIndices.push() = fPositions.count() - 3;
         }
 
+        // if transparent, add point to first one in array and add to center fan
+        if (fTransparent) {
+            fPositions[0] += centerPoint;
+            ++fCentroidCount;
+
+            *fIndices.push() = 0;
+            *fIndices.push() = fPrevUmbraIndex;
+            *fIndices.push() = fPositions.count() - 2;
+        }
+
         fPrevUmbraIndex = fPositions.count() - 2;
     }