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

Commit 8a3452e7 authored by ztenghui's avatar ztenghui Committed by Android (Google) Code Review
Browse files

Merge "Calculate and show the shadow from a spot light."

parents 92351c58 7b4516e7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ ifeq ($(USE_OPENGL_RENDERER),true)
		SkiaColorFilter.cpp \
		SkiaShader.cpp \
		Snapshot.cpp \
		SpotShadow.cpp \
		StatefulBaseRenderer.cpp \
		Stencil.cpp \
		Texture.cpp \
+11 −3
Original line number Diff line number Diff line
@@ -3194,10 +3194,18 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlp
    paint.setColor(mCaches.propertyShadowStrength << 24);
    paint.setAntiAlias(true); // want to use AlphaVertex

    VertexBuffer shadowVertexBuffer;
    VertexBuffer ambientShadowVertexBuffer;
    ShadowTessellator::tessellateAmbientShadow(width, height, casterTransform,
            shadowVertexBuffer);
    return drawVertexBuffer(shadowVertexBuffer, &paint);
            ambientShadowVertexBuffer);
    drawVertexBuffer(ambientShadowVertexBuffer, &paint);

    VertexBuffer spotShadowVertexBuffer;
    ShadowTessellator::tessellateSpotShadow(width, height,
            getWidth(), getHeight(), casterTransform,
            spotShadowVertexBuffer);
    drawVertexBuffer(spotShadowVertexBuffer, &paint);

    return DrawGlInfo::kStatusDrew;
}

status_t OpenGLRenderer::drawColorRects(const float* rects, int count, int color,
+54 −10
Original line number Diff line number Diff line
@@ -21,14 +21,30 @@

#include "AmbientShadow.h"
#include "ShadowTessellator.h"
#include "SpotShadow.h"

namespace android {
namespace uirenderer {

template<typename T>
static inline T max(T a, T b) {
    return a > b ? a : b;
}

// TODO: Support path as the input of the polygon instead of the rect's width
// and height.
void ShadowTessellator::tessellateAmbientShadow(float width, float height,
        const mat4& casterTransform, VertexBuffer& shadowVertexBuffer) {
// and height. And the z values need to be computed according to the
// transformation for each vertex.
/**
 * Generate the polygon for the caster.
 *
 * @param width the width of the caster
 * @param height the height of the caster
 * @param casterTransform transformation info of the caster
 * @param polygon return the caster's polygon
 *
 */
void ShadowTessellator::generateCasterPolygon(float width, float height,
        const mat4& casterTransform, int vertexCount, Vector3* polygon) {

    Vector3 pivot(width / 2, height / 2, 0.0f);
    casterTransform.mapPoint3d(pivot);
@@ -39,10 +55,6 @@ void ShadowTessellator::tessellateAmbientShadow(float width, float height,
            pivot.x + width * zScaleFactor, pivot.y + height * zScaleFactor);

    // Generate the caster's polygon from the rect.
    // TODO: support arbitrary polygon, and the z value need to be computed
    // according to the transformation for each vertex.
    const int vertexCount = 4;
    Vector3 polygon[vertexCount];
    polygon[0].x = blockRect.left;
    polygon[0].y = blockRect.top;
    polygon[0].z = pivot.z;
@@ -55,19 +67,51 @@ void ShadowTessellator::tessellateAmbientShadow(float width, float height,
    polygon[3].x = blockRect.left;
    polygon[3].y = blockRect.bottom;
    polygon[3].z = pivot.z;
}

void ShadowTessellator::tessellateAmbientShadow(float width, float height,
        const mat4& casterTransform, VertexBuffer& shadowVertexBuffer) {

    const int vertexCount = 4;
    Vector3 polygon[vertexCount];
    generateCasterPolygon(width, height, casterTransform, vertexCount, polygon);

    // A bunch of parameters to tweak the shadow.
    // TODO: Allow some of these changable by debug settings or APIs.
    const int rays = 120;
    const int rays = 128;
    const int layers = 2;
    const float strength = 0.5;
    const float heightFactor = 120;
    const float geomFactor = 60;
    const float heightFactor = 128;
    const float geomFactor = 64;

    AmbientShadow::createAmbientShadow(polygon, vertexCount, rays, layers, strength,
            heightFactor, geomFactor, shadowVertexBuffer);

}

void ShadowTessellator::tessellateSpotShadow(float width, float height,
        int screenWidth, int screenHeight,
        const mat4& casterTransform, VertexBuffer& shadowVertexBuffer) {
    const int vertexCount = 4;
    Vector3 polygon[vertexCount];
    generateCasterPolygon(width, height, casterTransform, vertexCount, polygon);

    // A bunch of parameters to tweak the shadow.
    // TODO: Allow some of these changable by debug settings or APIs.
    const int rays = 256;
    const int layers = 2;
    const float strength = 0.5;
    int maximal = max(screenWidth, screenHeight);
    Vector3 lightCenter(screenWidth / 2, 0, maximal);
#if DEBUG_SHADOW
    ALOGD("light center %f %f %f", lightCenter.x, lightCenter.y, lightCenter.z);
#endif
    const float lightSize = maximal / 8;
    const int lightVertexCount = 16;

    SpotShadow::createSpotShadow(polygon, vertexCount, lightCenter, lightSize,
            lightVertexCount, rays, layers, strength, shadowVertexBuffer);

}
}; // namespace uirenderer
}; // namespace android
+8 −0
Original line number Diff line number Diff line
@@ -29,6 +29,14 @@ public:
    static void tessellateAmbientShadow(float width, float height,
            const mat4& casterTransform, VertexBuffer& shadowVertexBuffer);

    static void tessellateSpotShadow(float width, float height,
            int screenWidth, int screenHeight,
            const mat4& casterTransform, VertexBuffer& shadowVertexBuffer);

private:
    static void generateCasterPolygon(float width, float height,
            const mat4& casterTransform, int vertexCount, Vector3* polygon);

}; // ShadowTessellator

}; // namespace uirenderer
+839 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading