Merge "Update the shadow fall off function from cosine to gaussian."
This commit is contained in:
@@ -380,10 +380,10 @@
|
||||
|
||||
<!-- Lighting and shadow properties -->
|
||||
<dimen name="light_y">-200dp</dimen>
|
||||
<dimen name="light_z">800dp</dimen>
|
||||
<dimen name="light_radius">600dp</dimen>
|
||||
<item type="dimen" format="float" name="ambient_shadow_alpha">0.075</item>
|
||||
<item type="dimen" format="float" name="spot_shadow_alpha">0.15</item>
|
||||
<dimen name="light_z">600dp</dimen>
|
||||
<dimen name="light_radius">800dp</dimen>
|
||||
<item type="dimen" format="float" name="ambient_shadow_alpha">0.039</item>
|
||||
<item type="dimen" format="float" name="spot_shadow_alpha">0.19</item>
|
||||
|
||||
<!-- Floating toolbar dimensions -->
|
||||
<dimen name="floating_toolbar_height">48dp</dimen>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user