blob: 49a3d2c3f632a62caa72a6d22ef073a5f2e78144 [file] [log] [blame]
ztenghui55bfb4e2013-12-03 10:38:55 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include <math.h>
20#include <utils/Log.h>
21
22#include "AmbientShadow.h"
23#include "ShadowTessellator.h"
24
25namespace android {
26namespace uirenderer {
27
28// TODO: Support path as the input of the polygon instead of the rect's width
29// and height.
30void ShadowTessellator::tessellateAmbientShadow(float width, float height,
31 const mat4& casterTransform, VertexBuffer& shadowVertexBuffer) {
32
33 Vector3 pivot(width / 2, height / 2, 0.0f);
34 casterTransform.mapPoint3d(pivot);
35
36 // TODO: The zScaleFactor need to be mapped to the screen.
37 float zScaleFactor = 0.5;
38 Rect blockRect(pivot.x - width * zScaleFactor, pivot.y - height * zScaleFactor,
39 pivot.x + width * zScaleFactor, pivot.y + height * zScaleFactor);
40
41 // Generate the caster's polygon from the rect.
42 // TODO: support arbitrary polygon, and the z value need to be computed
43 // according to the transformation for each vertex.
44 const int vertexCount = 4;
45 Vector3 polygon[vertexCount];
46 polygon[0].x = blockRect.left;
47 polygon[0].y = blockRect.top;
48 polygon[0].z = pivot.z;
49 polygon[1].x = blockRect.right;
50 polygon[1].y = blockRect.top;
51 polygon[1].z = pivot.z;
52 polygon[2].x = blockRect.right;
53 polygon[2].y = blockRect.bottom;
54 polygon[2].z = pivot.z;
55 polygon[3].x = blockRect.left;
56 polygon[3].y = blockRect.bottom;
57 polygon[3].z = pivot.z;
58
59 // A bunch of parameters to tweak the shadow.
60 // TODO: Allow some of these changable by debug settings or APIs.
61 const int rays = 120;
62 const int layers = 2;
63 const float strength = 0.5;
64 const float heightFactor = 120;
65 const float geomFactor = 60;
66
67 AmbientShadow::createAmbientShadow(polygon, vertexCount, rays, layers, strength,
68 heightFactor, geomFactor, shadowVertexBuffer);
69
70}
71
72}; // namespace uirenderer
73}; // namespace android