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

Commit cd10b887 authored by Chris Craik's avatar Chris Craik Committed by android-build-merger
Browse files

Merge "Use LUT for computing final shadow alpha" into nyc-dev am: b2e36d79

am: 92e7158f

* commit '92e7158f':
  Use LUT for computing final shadow alpha

Change-Id: I43398c982d2e7f228d6d99c57774bd7c6eb3e183
parents b2d1773b 92e7158f
Loading
Loading
Loading
Loading
+8 −21
Original line number Diff line number Diff line
@@ -43,9 +43,7 @@
/**
 * Other constants:
 */
// For the edge of the penumbra, the opacity is 0. After transform (1 - alpha),
// it is 1.
#define TRANSFORMED_OUTER_OPACITY (1.0f)
#define OUTER_ALPHA (0.0f)

// Once the alpha difference is greater than this threshold, we will allocate extra
// edge vertices.
@@ -81,17 +79,6 @@ inline float getAlphaFromFactoredZ(float factoredZ) {
    return 1.0 / (1 + std::max(factoredZ, 0.0f));
}

// The shader is using gaussian function e^-(1-x)*(1-x)*4, therefore, we transform
// the alpha value to (1 - alpha)
inline float getTransformedAlphaFromAlpha(float alpha) {
    return 1.0f - alpha;
}

// The output is ranged from 0 to 1.
inline float getTransformedAlphaFromFactoredZ(float factoredZ) {
    return getTransformedAlphaFromAlpha(getAlphaFromFactoredZ(factoredZ));
}

inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike,
        const Vector3& secondVertex, const Vector3& centroid) {
    Vector2 secondSpike  = {secondVertex.x - centroid.x, secondVertex.y - centroid.y};
@@ -225,9 +212,9 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
        if (!isCasterOpaque) {
            umbraVertices[umbraIndex++] = vertexBufferIndex;
        }
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++], casterVertices[i].x,
                casterVertices[i].y,
                getTransformedAlphaFromAlpha(currentAlpha));
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++],
                casterVertices[i].x, casterVertices[i].y,
                currentAlpha);

        const Vector3& innerStart = casterVertices[i];

@@ -249,7 +236,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
            indexBuffer[indexBufferIndex++] = vertexBufferIndex;
            indexBuffer[indexBufferIndex++] = currentInnerVertexIndex;
            AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x,
                    outerVertex.y, TRANSFORMED_OUTER_OPACITY);
                    outerVertex.y, OUTER_ALPHA);

            if (j == 0) {
                outerStart = outerVertex;
@@ -285,7 +272,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
                    (outerLast * startWeight + outerNext * k) / extraVerticesNumber;
                indexBuffer[indexBufferIndex++] = vertexBufferIndex;
                AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentOuter.x,
                        currentOuter.y, TRANSFORMED_OUTER_OPACITY);
                        currentOuter.y, OUTER_ALPHA);

                if (!isCasterOpaque) {
                    umbraVertices[umbraIndex++] = vertexBufferIndex;
@@ -295,7 +282,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
                indexBuffer[indexBufferIndex++] = vertexBufferIndex;
                AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentInner.x,
                        currentInner.y,
                        getTransformedAlphaFromFactoredZ(currentInner.z * heightFactor));
                        getAlphaFromFactoredZ(currentInner.z * heightFactor));
            }
        }
        currentAlpha = nextAlpha;
@@ -307,7 +294,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
    if (!isCasterOpaque) {
        // Add the centroid as the last one in the vertex buffer.
        float centroidOpacity =
            getTransformedAlphaFromFactoredZ(centroid3d.z * heightFactor);
            getAlphaFromFactoredZ(centroid3d.z * heightFactor);
        int centroidIndex = vertexBufferIndex;
        AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x,
                centroid3d.y, centroidOpacity);
+3 −2
Original line number Diff line number Diff line
@@ -346,11 +346,12 @@ static void renderVertexBuffer(BakedOpRenderer& renderer, const BakedOpState& st
        bool shadowInterp = vertexBufferRenderFlags & VertexBufferRenderFlags::ShadowInterp;
        const int transformFlags = vertexBufferRenderFlags & VertexBufferRenderFlags::Offset
                ? TransformFlags::OffsetByFudgeFactor : 0;

        Glop glop;
        GlopBuilder(renderer.renderState(), renderer.caches(), &glop)
                .setRoundRectClipState(state.roundRectClipState)
                .setMeshVertexBuffer(vertexBuffer, shadowInterp)
                .setFillPaint(paint, state.alpha)
                .setMeshVertexBuffer(vertexBuffer)
                .setFillPaint(paint, state.alpha, shadowInterp)
                .setTransform(state.computedState.transform, transformFlags)
                .setModelViewOffsetRect(translateX, translateY, vertexBuffer.getBounds())
                .build();
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ bool Caches::init() {

    mPixelBufferState = new PixelBufferState();
    mTextureState = new TextureState();
    mTextureState->constructTexture(*this);

    return true;
}
+5 −0
Original line number Diff line number Diff line
@@ -44,9 +44,14 @@ class Texture;

namespace VertexAttribFlags {
    enum {
        // Mesh is pure x,y vertex pairs
        None = 0,
        // Mesh has texture coordinates embedded. Note that texture can exist without this flag
        // being set, if coordinates passed to sampler are determined another way.
        TextureCoord = 1 << 0,
        // Mesh has color embedded (to export to varying)
        Color = 1 << 1,
        // Mesh has alpha embedded (to export to varying)
        Alpha = 1 << 2,
    };
};
+16 −7
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ GlopBuilder& GlopBuilder::setMeshColoredTexturedMesh(ColorTextureVertex* vertexD
    return *this;
}

GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer, bool shadowInterp) {
GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer) {
    TRIGGER_STAGE(kMeshStage);

    const VertexBuffer::MeshFeatureFlags flags = vertexBuffer.getMeshFeatureFlags();
@@ -210,8 +210,6 @@ GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer,
            alphaVertex ? kAlphaVertexStride : kVertexStride };
    mOutGlop->mesh.elementCount = indices
                ? vertexBuffer.getIndexCount() : vertexBuffer.getVertexCount();

    mDescription.useShadowAlphaInterp = shadowInterp;
    return *this;
}

@@ -368,15 +366,23 @@ GlopBuilder& GlopBuilder::setFillTexturePaint(Texture& texture,
    return *this;
}

GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale) {
GlopBuilder& GlopBuilder::setFillPaint(const SkPaint& paint, float alphaScale, bool shadowInterp) {
    TRIGGER_STAGE(kFillStage);
    REQUIRE_STAGES(kMeshStage | kRoundRectClipStage);

    mOutGlop->fill.texture = { nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM, GL_INVALID_ENUM, nullptr };
    if (CC_LIKELY(!shadowInterp)) {
        mOutGlop->fill.texture = {
                nullptr, GL_INVALID_ENUM, GL_INVALID_ENUM, GL_INVALID_ENUM, nullptr };
    } else {
        mOutGlop->fill.texture = {
                mCaches.textureState().getShadowLutTexture(), GL_TEXTURE_2D,
                GL_INVALID_ENUM, GL_INVALID_ENUM, nullptr };
    }

    setFill(paint.getColor(), alphaScale,
            PaintUtils::getXfermode(paint.getXfermode()), Blend::ModeOrderSwap::NoSwap,
            paint.getShader(), paint.getColorFilter());
    mDescription.useShadowAlphaInterp = shadowInterp;
    mDescription.modulate = mOutGlop->fill.color.a < 1.0f;
    return *this;
}
@@ -593,8 +599,11 @@ GlopBuilder& GlopBuilder::setRoundRectClipState(const RoundRectClipState* roundR
void verify(const ProgramDescription& description, const Glop& glop) {
    if (glop.fill.texture.texture != nullptr) {
        LOG_ALWAYS_FATAL_IF(((description.hasTexture && description.hasExternalTexture)
                        || (!description.hasTexture && !description.hasExternalTexture)
                        || ((glop.mesh.vertices.attribFlags & VertexAttribFlags::TextureCoord) == 0)),
                        || (!description.hasTexture
                                && !description.hasExternalTexture
                                && !description.useShadowAlphaInterp)
                        || ((glop.mesh.vertices.attribFlags & VertexAttribFlags::TextureCoord) == 0
                                && !description.useShadowAlphaInterp)),
                "Texture %p, hT%d, hET %d, attribFlags %x",
                glop.fill.texture.texture,
                description.hasTexture, description.hasExternalTexture,
Loading