Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e6ad3b8 authored by Chris Craik's avatar Chris Craik Committed by Android (Google) Code Review
Browse files

Merge "Force shadow casters above the Z=0 plane"

parents 5b568aa0 b98f2116
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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);
+2 −0
Original line number Diff line number Diff line
@@ -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,
+0 −5
Original line number Diff line number Diff line
@@ -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");