summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorztenghui <ztenghui@google.com>2015-04-09 17:48:59 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-09 17:49:00 +0000
commit3f6d5aa5dd39ec326b60ba0e3b2742a2abaab69a (patch)
tree3856269d998f1c4bd5ef0e769b59a24c00dc1c56 /libs
parent52f57de9f618f4b3303fb9b59084e775f5312984 (diff)
parentecf091e171012831cddea59f1f64a46e87ee8c4f (diff)
downloadframeworks_base-3f6d5aa5dd39ec326b60ba0e3b2742a2abaab69a.zip
frameworks_base-3f6d5aa5dd39ec326b60ba0e3b2742a2abaab69a.tar.gz
frameworks_base-3f6d5aa5dd39ec326b60ba0e3b2742a2abaab69a.tar.bz2
Merge "Update the shadow fall off function from cosine to gaussian."
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/AmbientShadow.cpp15
-rw-r--r--libs/hwui/ProgramCache.cpp5
-rw-r--r--libs/hwui/SpotShadow.cpp11
3 files changed, 19 insertions, 12 deletions
diff --git a/libs/hwui/AmbientShadow.cpp b/libs/hwui/AmbientShadow.cpp
index 0a210d6..a4100a2 100644
--- a/libs/hwui/AmbientShadow.cpp
+++ b/libs/hwui/AmbientShadow.cpp
@@ -45,8 +45,9 @@
/**
* Other constants:
*/
-// For the edge of the penumbra, the opacity is 0.
-#define OUTER_OPACITY (0.0f)
+// For the edge of the penumbra, the opacity is 0. After transform (1 - alpha),
+// it is 1.
+#define TRANSFORMED_OUTER_OPACITY (1.0f)
// Once the alpha difference is greater than this threshold, we will allocate extra
// edge vertices.
@@ -83,11 +84,13 @@ inline float getAlphaFromFactoredZ(float factoredZ) {
return 1.0 / (1 + MathUtils::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 acosf(1.0f - 2.0f * alpha);
+ return 1.0f - alpha;
}
-// The output is ranged from 0 to M_PI.
+// The output is ranged from 0 to 1.
inline float getTransformedAlphaFromFactoredZ(float factoredZ) {
return getTransformedAlphaFromAlpha(getAlphaFromFactoredZ(factoredZ));
}
@@ -249,7 +252,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
indexBuffer[indexBufferIndex++] = vertexBufferIndex;
indexBuffer[indexBufferIndex++] = currentInnerVertexIndex;
AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x,
- outerVertex.y, OUTER_OPACITY);
+ outerVertex.y, TRANSFORMED_OUTER_OPACITY);
if (j == 0) {
outerStart = outerVertex;
@@ -285,7 +288,7 @@ void AmbientShadow::createAmbientShadow(bool isCasterOpaque,
(outerLast * startWeight + outerNext * k) / extraVerticesNumber;
indexBuffer[indexBufferIndex++] = vertexBufferIndex;
AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentOuter.x,
- currentOuter.y, OUTER_OPACITY);
+ currentOuter.y, TRANSFORMED_OUTER_OPACITY);
if (!isCasterOpaque) {
umbraVertices[umbraIndex++] = vertexBufferIndex;
diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp
index e9b22e2..41adda1 100644
--- a/libs/hwui/ProgramCache.cpp
+++ b/libs/hwui/ProgramCache.cpp
@@ -240,8 +240,9 @@ const char* gFS_Main_ModulateColor =
const char* gFS_Main_ApplyVertexAlphaLinearInterp =
" fragColor *= alpha;\n";
const char* gFS_Main_ApplyVertexAlphaShadowInterp =
- " fragColor *= (1.0 - cos(alpha)) / 2.0;\n";
-
+ // Use a gaussian function for the shadow fall off. Note that alpha here
+ // is actually (1.0 - alpha) for saving computation.
+ " fragColor *= exp(- alpha * alpha * 4.0) - 0.018;\n";
const char* gFS_Main_FetchTexture[2] = {
// Don't modulate
" fragColor = texture2D(baseSampler, outTexCoords);\n",
diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp
index b3b06d6..db3c2d9 100644
--- a/libs/hwui/SpotShadow.cpp
+++ b/libs/hwui/SpotShadow.cpp
@@ -44,6 +44,9 @@
// For each RADIANS_DIVISOR, we would allocate one more vertex b/t the normals.
#define SPOT_CORNER_RADIANS_DIVISOR (M_PI / SPOT_EXTRA_CORNER_VERTEX_PER_PI)
+// For performance, we use (1 - alpha) value for the shader input.
+#define TRANSFORMED_PENUMBRA_ALPHA 1.0f
+#define TRANSFORMED_UMBRA_ALPHA 0.0f
#include <math.h>
#include <stdlib.h>
@@ -964,11 +967,11 @@ void SpotShadow::generateTriangleStrip(bool isCasterOpaque, float shadowStrength
// Fill the IB and VB for the penumbra area.
for (int i = 0; i < newPenumbraLength; i++) {
AlphaVertex::set(&shadowVertices[vertexBufferIndex++], newPenumbra[i].x,
- newPenumbra[i].y, 0.0f);
+ newPenumbra[i].y, TRANSFORMED_PENUMBRA_ALPHA);
}
for (int i = 0; i < umbraLength; i++) {
AlphaVertex::set(&shadowVertices[vertexBufferIndex++], umbra[i].x, umbra[i].y,
- M_PI);
+ TRANSFORMED_UMBRA_ALPHA);
}
for (int i = 0; i < verticesPairIndex; i++) {
@@ -1008,14 +1011,14 @@ void SpotShadow::generateTriangleStrip(bool isCasterOpaque, float shadowStrength
indexBuffer[indexBufferIndex++] = newPenumbraLength + i;
indexBuffer[indexBufferIndex++] = vertexBufferIndex;
AlphaVertex::set(&shadowVertices[vertexBufferIndex++],
- closerVertex.x, closerVertex.y, M_PI);
+ closerVertex.x, closerVertex.y, TRANSFORMED_UMBRA_ALPHA);
}
} else {
// If there is no occluded umbra at all, then draw the triangle fan
// starting from the centroid to all umbra vertices.
int lastCentroidIndex = vertexBufferIndex;
AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid.x,
- centroid.y, M_PI);
+ centroid.y, TRANSFORMED_UMBRA_ALPHA);
for (int i = 0; i < umbraLength; i++) {
indexBuffer[indexBufferIndex++] = newPenumbraLength + i;
indexBuffer[indexBufferIndex++] = lastCentroidIndex;