summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-03-11 17:42:29 -0700
committerChris Craik <ccraik@google.com>2014-03-12 11:19:42 -0700
commitb98f2116f5896acb4b221015b22624a3c5d5a7fe (patch)
tree4bf1d02992d5fd3d0b333eb5e042d7337a572667 /libs
parentd84133af441caed8102b2da79cdb6f50673b80cb (diff)
downloadframeworks_base-b98f2116f5896acb4b221015b22624a3c5d5a7fe.zip
frameworks_base-b98f2116f5896acb4b221015b22624a3c5d5a7fe.tar.gz
frameworks_base-b98f2116f5896acb4b221015b22624a3c5d5a7fe.tar.bz2
Force shadow casters above the Z=0 plane
Change-Id: Ifee75414829d4bfb3c7aa6219f1f9bcfd50ff0c6
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp11
-rw-r--r--libs/hwui/ShadowTessellator.h2
-rw-r--r--libs/hwui/SpotShadow.cpp5
3 files changed, 13 insertions, 5 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 83de772..879b4c7 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -3222,10 +3222,12 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransformXY, const mat4& c
// map 2d caster poly into 3d
const int casterVertexCount = casterVertices2d.size();
Vector3 casterPolygon[casterVertexCount];
+ float minZ = FLT_MAX;
for (int i = 0; i < casterVertexCount; i++) {
const Vertex& point2d = casterVertices2d[i];
casterPolygon[i] = Vector3(point2d.x, point2d.y, 0);
mapPointFakeZ(casterPolygon[i], casterTransformXY, casterTransformZ);
+ minZ = fmin(minZ, casterPolygon[i].z);
}
// map the centroid of the caster into 3d
@@ -3235,6 +3237,15 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransformXY, const mat4& c
Vector3 centroid3d(centroid.x, centroid.y, 0);
mapPointFakeZ(centroid3d, casterTransformXY, casterTransformZ);
+ // if the caster intersects the z=0 plane, lift it in Z so it doesn't
+ if (minZ < SHADOW_MIN_CASTER_Z) {
+ float casterLift = SHADOW_MIN_CASTER_Z - minZ;
+ for (int i = 0; i < casterVertexCount; i++) {
+ casterPolygon[i].z += casterLift;
+ }
+ centroid3d.z += casterLift;
+ }
+
// draw caster's shadows
if (mCaches.propertyAmbientShadowStrength > 0) {
paint.setARGB(casterAlpha * mCaches.propertyAmbientShadowStrength, 0, 0, 0);
diff --git a/libs/hwui/ShadowTessellator.h b/libs/hwui/ShadowTessellator.h
index 120774b..c558460 100644
--- a/libs/hwui/ShadowTessellator.h
+++ b/libs/hwui/ShadowTessellator.h
@@ -54,6 +54,8 @@ namespace uirenderer {
// The total number of indices used for drawing the shadow geometry as triangle strips.
#define SHADOW_INDEX_COUNT (2 * SHADOW_RAY_COUNT + 1 + 2 * (SHADOW_RAY_COUNT + 1))
+#define SHADOW_MIN_CASTER_Z 0.001f
+
class ShadowTessellator {
public:
static void tessellateAmbientShadow(const Vector3* casterPolygon,
diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp
index 4e52555..8538b29 100644
--- a/libs/hwui/SpotShadow.cpp
+++ b/libs/hwui/SpotShadow.cpp
@@ -548,11 +548,6 @@ void SpotShadow::computeSpotShadow(const Vector3* lightPoly, int lightPolyLength
// Validate input, receiver is always at z = 0 plane.
bool inputPolyPositionValid = true;
for (int i = 0; i < polyLength; i++) {
- if (poly[i].z <= 0.00001) {
- inputPolyPositionValid = false;
- ALOGW("polygon below the surface");
- break;
- }
if (poly[i].z >= lightPoly[0].z) {
inputPolyPositionValid = false;
ALOGW("polygon above the light");