Switch to cos interpolation of shadow alpha
bug:16852257 Updates default shadow opacities to compensate. Also, update variable/constant naming related to vertex alpha. Change-Id: I9055b4ac3c9ac305ca9d515f21b52d6aa6dc9c5c
This commit is contained in:
@ -1360,7 +1360,7 @@ please see styles_device_defaults.xml.
|
||||
<item name="lightZ">800dp</item>
|
||||
<item name="lightRadius">800dp</item>
|
||||
<item name="ambientShadowAlpha">0.06</item>
|
||||
<item name="spotShadowAlpha">0.22</item>
|
||||
<item name="spotShadowAlpha">0.16</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@ -117,10 +117,13 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
|
||||
|
||||
// inner ring of points
|
||||
float opacity = 1.0 / (1 + rayHeight[rayIndex] * heightFactor);
|
||||
// NOTE: Shadow alpha values are transformed when stored in alphavertices,
|
||||
// so that they can be consumed directly by gFS_Main_ApplyVertexAlphaShadowInterp
|
||||
float transformedOpacity = acos(1.0f - 2.0f * opacity);
|
||||
AlphaVertex::set(&shadowVertices[rays + rayIndex],
|
||||
intersection.x,
|
||||
intersection.y,
|
||||
opacity);
|
||||
transformedOpacity);
|
||||
}
|
||||
|
||||
if (isCasterOpaque) {
|
||||
|
@ -1641,9 +1641,9 @@ void OpenGLRenderer::setupDrawNoTexture() {
|
||||
mCaches.disableTexCoordsVertexArray();
|
||||
}
|
||||
|
||||
void OpenGLRenderer::setupDrawAA(bool useShadowInterp) {
|
||||
mDescription.isAA = true;
|
||||
mDescription.isShadowAA = useShadowInterp;
|
||||
void OpenGLRenderer::setupDrawVertexAlpha(bool useShadowAlphaInterp) {
|
||||
mDescription.hasVertexAlpha = true;
|
||||
mDescription.useShadowAlphaInterp = useShadowAlphaInterp;
|
||||
}
|
||||
|
||||
void OpenGLRenderer::setupDrawColor(int color, int alpha) {
|
||||
@ -2382,7 +2382,7 @@ status_t OpenGLRenderer::drawVertexBuffer(float translateX, float translateY,
|
||||
|
||||
setupDraw();
|
||||
setupDrawNoTexture();
|
||||
if (isAA) setupDrawAA((displayFlags & kVertexBuffer_ShadowAA));
|
||||
if (isAA) setupDrawVertexAlpha((displayFlags & kVertexBuffer_ShadowInterp));
|
||||
setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha);
|
||||
setupDrawColorFilter(getColorFilter(paint));
|
||||
setupDrawShader(getShader(paint));
|
||||
@ -3168,12 +3168,12 @@ status_t OpenGLRenderer::drawShadow(float casterAlpha,
|
||||
|
||||
if (ambientShadowVertexBuffer && mAmbientShadowAlpha > 0) {
|
||||
paint.setARGB(casterAlpha * mAmbientShadowAlpha, 0, 0, 0);
|
||||
drawVertexBuffer(*ambientShadowVertexBuffer, &paint, kVertexBuffer_ShadowAA);
|
||||
drawVertexBuffer(*ambientShadowVertexBuffer, &paint, kVertexBuffer_ShadowInterp);
|
||||
}
|
||||
|
||||
if (spotShadowVertexBuffer && mSpotShadowAlpha > 0) {
|
||||
paint.setARGB(casterAlpha * mSpotShadowAlpha, 0, 0, 0);
|
||||
drawVertexBuffer(*spotShadowVertexBuffer, &paint, kVertexBuffer_ShadowAA);
|
||||
drawVertexBuffer(*spotShadowVertexBuffer, &paint, kVertexBuffer_ShadowInterp);
|
||||
}
|
||||
|
||||
return DrawGlInfo::kStatusDrew;
|
||||
|
@ -96,7 +96,7 @@ enum ClipSideFlags {
|
||||
|
||||
enum VertexBufferDisplayFlags {
|
||||
kVertexBuffer_Offset = 0x1,
|
||||
kVertexBuffer_ShadowAA = 0x2,
|
||||
kVertexBuffer_ShadowInterp = 0x2,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -847,7 +847,7 @@ private:
|
||||
void setupDrawWithTextureAndColor(bool isAlpha8 = false);
|
||||
void setupDrawWithExternalTexture();
|
||||
void setupDrawNoTexture();
|
||||
void setupDrawAA(bool useShadowInterp);
|
||||
void setupDrawVertexAlpha(bool useShadowAlphaInterp);
|
||||
void setupDrawColor(int color, int alpha);
|
||||
void setupDrawColor(float r, float g, float b, float a);
|
||||
void setupDrawAlpha8Color(int color, int alpha);
|
||||
|
@ -71,8 +71,8 @@ namespace uirenderer {
|
||||
#define PROGRAM_GRADIENT_TYPE_SHIFT 33 // 2 bits for gradient type
|
||||
#define PROGRAM_MODULATE_SHIFT 35
|
||||
|
||||
#define PROGRAM_HAS_AA_SHIFT 36
|
||||
#define PROGRAM_HAS_SHADOW_AA_SHIFT 37
|
||||
#define PROGRAM_HAS_VERTEX_ALPHA_SHIFT 36
|
||||
#define PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT 37
|
||||
|
||||
#define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38
|
||||
#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39
|
||||
@ -135,8 +135,8 @@ struct ProgramDescription {
|
||||
bool hasBitmap;
|
||||
bool isBitmapNpot;
|
||||
|
||||
bool isAA; // drawing with a per-vertex alpha
|
||||
bool isShadowAA; // drawing per vertex alpha with shadow interpolation
|
||||
bool hasVertexAlpha;
|
||||
bool useShadowAlphaInterp;
|
||||
|
||||
bool hasGradient;
|
||||
Gradient gradientType;
|
||||
@ -176,8 +176,8 @@ struct ProgramDescription {
|
||||
|
||||
hasColors = false;
|
||||
|
||||
isAA = false;
|
||||
isShadowAA = false;
|
||||
hasVertexAlpha = false;
|
||||
useShadowAlphaInterp = false;
|
||||
|
||||
modulate = false;
|
||||
|
||||
@ -264,8 +264,8 @@ struct ProgramDescription {
|
||||
key |= (framebufferMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT;
|
||||
if (swapSrcDst) key |= PROGRAM_KEY_SWAP_SRC_DST;
|
||||
if (modulate) key |= programid(0x1) << PROGRAM_MODULATE_SHIFT;
|
||||
if (isAA) key |= programid(0x1) << PROGRAM_HAS_AA_SHIFT;
|
||||
if (isShadowAA) key |= programid(0x1) << PROGRAM_HAS_SHADOW_AA_SHIFT;
|
||||
if (hasVertexAlpha) key |= programid(0x1) << PROGRAM_HAS_VERTEX_ALPHA_SHIFT;
|
||||
if (useShadowAlphaInterp) key |= programid(0x1) << PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT;
|
||||
if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT;
|
||||
if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT;
|
||||
if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION;
|
||||
|
@ -46,7 +46,7 @@ const char* gVS_Header_Attributes_TexCoords =
|
||||
"attribute vec2 texCoords;\n";
|
||||
const char* gVS_Header_Attributes_Colors =
|
||||
"attribute vec4 colors;\n";
|
||||
const char* gVS_Header_Attributes_AAVertexShapeParameters =
|
||||
const char* gVS_Header_Attributes_VertexAlphaParameters =
|
||||
"attribute float vtxAlpha;\n";
|
||||
const char* gVS_Header_Uniforms_TextureTransform =
|
||||
"uniform mat4 mainTextureTransform;\n";
|
||||
@ -64,7 +64,7 @@ const char* gVS_Header_Varyings_HasTexture =
|
||||
"varying vec2 outTexCoords;\n";
|
||||
const char* gVS_Header_Varyings_HasColors =
|
||||
"varying vec4 outColors;\n";
|
||||
const char* gVS_Header_Varyings_IsAAVertexShape =
|
||||
const char* gVS_Header_Varyings_HasVertexAlpha =
|
||||
"varying float alpha;\n";
|
||||
const char* gVS_Header_Varyings_HasBitmap =
|
||||
"varying highp vec2 outBitmapTexCoords;\n";
|
||||
@ -122,9 +122,7 @@ const char* gVS_Main_Position =
|
||||
" vec4 transformedPosition = projection * transform * position;\n"
|
||||
" gl_Position = transformedPosition;\n";
|
||||
|
||||
const char* gVS_Main_ShadowAAVertexShape =
|
||||
" alpha = pow(vtxAlpha, 0.667);\n";
|
||||
const char* gVS_Main_AAVertexShape =
|
||||
const char* gVS_Main_VertexAlpha =
|
||||
" alpha = vtxAlpha;\n";
|
||||
|
||||
const char* gVS_Main_HasRoundRectClip =
|
||||
@ -239,10 +237,10 @@ const char* gFS_Main_FetchColor =
|
||||
" fragColor = color;\n";
|
||||
const char* gFS_Main_ModulateColor =
|
||||
" fragColor *= color.a;\n";
|
||||
const char* gFS_Main_AccountForAAVertexShape =
|
||||
const char* gFS_Main_ApplyVertexAlphaLinearInterp =
|
||||
" fragColor *= alpha;\n";
|
||||
const char* gFS_Main_AccountForShadowAAVertexShape =
|
||||
" fragColor *= pow(alpha, 1.5);\n";
|
||||
const char* gFS_Main_ApplyVertexAlphaShadowInterp =
|
||||
" fragColor *= (1.0 - cos(alpha)) / 2.0;\n";
|
||||
|
||||
const char* gFS_Main_FetchTexture[2] = {
|
||||
// Don't modulate
|
||||
@ -473,8 +471,8 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
|
||||
if (description.hasTexture || description.hasExternalTexture) {
|
||||
shader.append(gVS_Header_Attributes_TexCoords);
|
||||
}
|
||||
if (description.isAA) {
|
||||
shader.append(gVS_Header_Attributes_AAVertexShapeParameters);
|
||||
if (description.hasVertexAlpha) {
|
||||
shader.append(gVS_Header_Attributes_VertexAlphaParameters);
|
||||
}
|
||||
if (description.hasColors) {
|
||||
shader.append(gVS_Header_Attributes_Colors);
|
||||
@ -497,8 +495,8 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
|
||||
if (description.hasTexture || description.hasExternalTexture) {
|
||||
shader.append(gVS_Header_Varyings_HasTexture);
|
||||
}
|
||||
if (description.isAA) {
|
||||
shader.append(gVS_Header_Varyings_IsAAVertexShape);
|
||||
if (description.hasVertexAlpha) {
|
||||
shader.append(gVS_Header_Varyings_HasVertexAlpha);
|
||||
}
|
||||
if (description.hasColors) {
|
||||
shader.append(gVS_Header_Varyings_HasColors);
|
||||
@ -520,12 +518,8 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
|
||||
} else if (description.hasTexture || description.hasExternalTexture) {
|
||||
shader.append(gVS_Main_OutTexCoords);
|
||||
}
|
||||
if (description.isAA) {
|
||||
if (description.isShadowAA) {
|
||||
shader.append(gVS_Main_ShadowAAVertexShape);
|
||||
} else {
|
||||
shader.append(gVS_Main_AAVertexShape);
|
||||
}
|
||||
if (description.hasVertexAlpha) {
|
||||
shader.append(gVS_Main_VertexAlpha);
|
||||
}
|
||||
if (description.hasColors) {
|
||||
shader.append(gVS_Main_OutColors);
|
||||
@ -575,8 +569,8 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
|
||||
if (description.hasTexture || description.hasExternalTexture) {
|
||||
shader.append(gVS_Header_Varyings_HasTexture);
|
||||
}
|
||||
if (description.isAA) {
|
||||
shader.append(gVS_Header_Varyings_IsAAVertexShape);
|
||||
if (description.hasVertexAlpha) {
|
||||
shader.append(gVS_Header_Varyings_HasVertexAlpha);
|
||||
}
|
||||
if (description.hasColors) {
|
||||
shader.append(gVS_Header_Varyings_HasColors);
|
||||
@ -617,7 +611,7 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
|
||||
}
|
||||
|
||||
// Optimization for common cases
|
||||
if (!description.isAA
|
||||
if (!description.hasVertexAlpha
|
||||
&& !blendFramebuffer
|
||||
&& !description.hasColors
|
||||
&& description.colorOp == ProgramDescription::kColorNone
|
||||
@ -759,11 +753,11 @@ String8 ProgramCache::generateFragmentShader(const ProgramDescription& descripti
|
||||
// Apply the color op if needed
|
||||
shader.append(gFS_Main_ApplyColorOp[description.colorOp]);
|
||||
|
||||
if (description.isAA) {
|
||||
if (description.isShadowAA) {
|
||||
shader.append(gFS_Main_AccountForShadowAAVertexShape);
|
||||
if (description.hasVertexAlpha) {
|
||||
if (description.useShadowAlphaInterp) {
|
||||
shader.append(gFS_Main_ApplyVertexAlphaShadowInterp);
|
||||
} else {
|
||||
shader.append(gFS_Main_AccountForAAVertexShape);
|
||||
shader.append(gFS_Main_ApplyVertexAlphaLinearInterp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -754,9 +754,13 @@ void SpotShadow::generateTriangleStrip(bool isCasterOpaque, const Vector2* penum
|
||||
AlphaVertex* shadowVertices =
|
||||
shadowTriangleStrip.alloc<AlphaVertex>(SHADOW_VERTEX_COUNT);
|
||||
|
||||
// NOTE: Shadow alpha values are transformed when stored in alphavertices,
|
||||
// so that they can be consumed directly by gFS_Main_ApplyVertexAlphaShadowInterp
|
||||
float transformedMaxAlpha = M_PI;
|
||||
|
||||
// Calculate the vertices (x, y, alpha) in the shadow area.
|
||||
AlphaVertex centroidXYA;
|
||||
AlphaVertex::set(¢roidXYA, centroid.x, centroid.y, 1.0f);
|
||||
AlphaVertex::set(¢roidXYA, centroid.x, centroid.y, transformedMaxAlpha);
|
||||
for (int rayIndex = 0; rayIndex < rays; rayIndex++) {
|
||||
float dx = cosf(step * rayIndex);
|
||||
float dy = sinf(step * rayIndex);
|
||||
@ -770,14 +774,16 @@ void SpotShadow::generateTriangleStrip(bool isCasterOpaque, const Vector2* penum
|
||||
// umbra ring
|
||||
float umbraDistance = umbraDistPerRay[rayIndex];
|
||||
AlphaVertex::set(&shadowVertices[rays + rayIndex],
|
||||
dx * umbraDistance + centroid.x, dy * umbraDistance + centroid.y, 1.0f);
|
||||
dx * umbraDistance + centroid.x,
|
||||
dy * umbraDistance + centroid.y,
|
||||
transformedMaxAlpha);
|
||||
|
||||
// occluded umbra ring
|
||||
if (hasOccludedUmbraArea) {
|
||||
float occludedUmbraDistance = occludedUmbraDistPerRay[rayIndex];
|
||||
AlphaVertex::set(&shadowVertices[2 * rays + rayIndex],
|
||||
dx * occludedUmbraDistance + centroid.x,
|
||||
dy * occludedUmbraDistance + centroid.y, 1.0f);
|
||||
dy * occludedUmbraDistance + centroid.y, transformedMaxAlpha);
|
||||
} else {
|
||||
// Put all vertices of the occluded umbra ring at the centroid.
|
||||
shadowVertices[2 * rays + rayIndex] = centroidXYA;
|
||||
|
Reference in New Issue
Block a user