ztenghui | 55bfb4e | 2013-12-03 10:38:55 -0800 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2013 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_HWUI_SHADOW_TESSELLATOR_H |
| 19 | #define ANDROID_HWUI_SHADOW_TESSELLATOR_H |
| 20 | |
| 21 | #include "Debug.h" |
| 22 | #include "Matrix.h" |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 23 | #include "VertexBuffer.h" |
ztenghui | 55bfb4e | 2013-12-03 10:38:55 -0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 28 | // All SHADOW_* are used to define all the geometry property of shadows. |
| 29 | // Use a simplified example to illustrate the geometry setup here. |
| 30 | // Assuming we use 6 rays and only 1 layer, Then we will have 2 hexagons, which |
| 31 | // are 0 to 5 and 6 to 11. The area between them will be the penumbra area, and |
| 32 | // the area inside the 2nd hexagon is the umbra. |
| 33 | // Also, we need to add the centroid "12" to draw the umbra area as triangle fans. |
| 34 | // |
| 35 | // Triange strip indices for penumbra area: (0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 0, 6) |
| 36 | // Triange strip indices for numbra area: (6, 12, 7, 12, 8, 12, 9, 12, 10, 12, 11, 12, 6) |
| 37 | // 0 |
| 38 | // |
| 39 | // 5 6 1 |
| 40 | // 11 7 |
| 41 | // 12 |
| 42 | // 10 8 |
| 43 | // 4 9 2 |
| 44 | // |
| 45 | // 3 |
| 46 | |
| 47 | // The total number of rays starting from the centroid of shadow area, in order |
| 48 | // to generate the shadow geometry. |
Chris Craik | 726118b | 2014-03-07 18:27:49 -0800 | [diff] [blame] | 49 | #define SHADOW_RAY_COUNT 128 |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 50 | |
| 51 | // The total number of all the vertices representing the shadow. |
Chris Craik | 726118b | 2014-03-07 18:27:49 -0800 | [diff] [blame] | 52 | #define SHADOW_VERTEX_COUNT (2 * SHADOW_RAY_COUNT + 1) |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 53 | |
| 54 | // The total number of indices used for drawing the shadow geometry as triangle strips. |
Chris Craik | 726118b | 2014-03-07 18:27:49 -0800 | [diff] [blame] | 55 | #define SHADOW_INDEX_COUNT (2 * SHADOW_RAY_COUNT + 1 + 2 * (SHADOW_RAY_COUNT + 1)) |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 56 | |
Chris Craik | b98f211 | 2014-03-11 17:42:29 -0700 | [diff] [blame] | 57 | #define SHADOW_MIN_CASTER_Z 0.001f |
| 58 | |
ztenghui | 55bfb4e | 2013-12-03 10:38:55 -0800 | [diff] [blame] | 59 | class ShadowTessellator { |
| 60 | public: |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 61 | static void tessellateAmbientShadow(const Vector3* casterPolygon, |
| 62 | int casterVertexCount, const Vector3& centroid3d, |
ztenghui | cc3c256 | 2014-01-17 10:34:10 -0800 | [diff] [blame] | 63 | VertexBuffer& shadowVertexBuffer); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 64 | |
Chris Craik | 15a07a2 | 2014-01-26 13:43:53 -0800 | [diff] [blame] | 65 | static void tessellateSpotShadow(const Vector3* casterPolygon, int casterVertexCount, |
| 66 | const Vector3& lightPosScale, const mat4& receiverTransform, |
| 67 | int screenWidth, int screenHeight, VertexBuffer& shadowVertexBuffer); |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 68 | |
| 69 | static void generateShadowIndices(uint16_t* shadowIndices); |
| 70 | |
| 71 | static Vector2 centroid2d(const Vector2* poly, int polyLength); |
ztenghui | 55bfb4e | 2013-12-03 10:38:55 -0800 | [diff] [blame] | 72 | }; // ShadowTessellator |
| 73 | |
| 74 | }; // namespace uirenderer |
| 75 | }; // namespace android |
| 76 | |
| 77 | #endif // ANDROID_HWUI_SHADOW_TESSELLATOR_H |