packages/wallpapers/Basic
修订版 | 6a500a1d5e15bd5a563995f31d0796552cc13640 (tree) |
---|---|
时间 | 2010-02-12 11:09:56 |
作者 | Jason Sams <rjsams@andr...> |
Commiter | Jason Sams |
DO NOT MERGE. Port Froyo livewallpaper support to eclair for droid..
Update grass to use fragment shaders.
Create struct for blade data.
Use indicies to reduce grass cpu usage. Fix aliasing of tips of grass.
Update to new RS texture API.
Update to new RS element API.
Update to use RS generic attrib support.
Change to user attrib types.
Disable per touch logging.
Simplify the fall water script. Remove some dead code from the java layer that was left over from the old integer mesh.
Move Fall waveform calculation to vertex shader.
Add uses-feature to the manifest.
Enable red-pulses-only mode in Nexus wallpaper.
Also load textures with CLAMP for Droid compatiblity.
Bug: 2395147
Change-Id: Id310674e1c3160a545d632b286506e55e9cbc8ad
Fix shader problems in Nexus, er, Neural Network LW.
Change-Id: I852bdf4700d61f18a006ebcf619e9d4f3b51e4cd
Fix Galaxy in landscape mode.
modified: src/com/android/wallpaper/galaxy/GalaxyRS.java
@@ -21,6 +21,8 @@ | ||
21 | 21 | xmlns:android="http://schemas.android.com/apk/res/android" |
22 | 22 | package="com.android.wallpaper"> |
23 | 23 | |
24 | + <uses-feature android:name="android.software.live_wallpaper" /> | |
25 | + | |
24 | 26 | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
25 | 27 | <uses-permission android:name="android.permission.CAMERA" /> |
26 | 28 |
@@ -26,21 +26,10 @@ float skyOffsetY; | ||
26 | 26 | float g_DT; |
27 | 27 | int g_LastTime; |
28 | 28 | |
29 | -struct vert_s { | |
30 | - float x; | |
31 | - float y; | |
32 | - float z; | |
33 | - float s; | |
34 | - float t; | |
35 | -}; | |
36 | - | |
37 | 29 | struct drop_s { |
38 | 30 | float ampS; |
39 | 31 | float ampE; |
40 | 32 | float spread; |
41 | - float spread2; | |
42 | - float invSpread; | |
43 | - float invSpread2; | |
44 | 33 | float x; |
45 | 34 | float y; |
46 | 35 | }; |
@@ -63,9 +52,7 @@ struct Leaves_s { | ||
63 | 52 | }; |
64 | 53 | |
65 | 54 | struct Leaves_s gLeavesStore[LEAVES_COUNT]; |
66 | - | |
67 | 55 | struct Leaves_s* gLeaves[LEAVES_COUNT]; |
68 | - | |
69 | 56 | struct Leaves_s* gNextLeaves[LEAVES_COUNT]; |
70 | 57 | |
71 | 58 | void init() { |
@@ -75,9 +62,6 @@ void init() { | ||
75 | 62 | gDrops[ct].ampS = 0; |
76 | 63 | gDrops[ct].ampE = 0; |
77 | 64 | gDrops[ct].spread = 1; |
78 | - gDrops[ct].spread2 = gDrops[ct].spread * gDrops[ct].spread; | |
79 | - gDrops[ct].invSpread = 1 / gDrops[ct].spread; | |
80 | - gDrops[ct].invSpread2 = gDrops[ct].invSpread * gDrops[ct].invSpread; | |
81 | 65 | } |
82 | 66 | } |
83 | 67 |
@@ -107,10 +91,7 @@ void initLeaves() { | ||
107 | 91 | |
108 | 92 | void updateDrop(int ct) { |
109 | 93 | gDrops[ct].spread += 30.f * g_DT; |
110 | - gDrops[ct].spread2 = gDrops[ct].spread * gDrops[ct].spread; | |
111 | - gDrops[ct].invSpread = 1 / gDrops[ct].spread; | |
112 | - gDrops[ct].invSpread2 = gDrops[ct].invSpread * gDrops[ct].invSpread; | |
113 | - gDrops[ct].ampE = gDrops[ct].ampS * gDrops[ct].invSpread; | |
94 | + gDrops[ct].ampE = gDrops[ct].ampS / gDrops[ct].spread; | |
114 | 95 | } |
115 | 96 | |
116 | 97 | void drop(int x, int y, float s) { |
@@ -131,65 +112,20 @@ void drop(int x, int y, float s) { | ||
131 | 112 | } |
132 | 113 | |
133 | 114 | void generateRipples() { |
134 | - int rippleMapSize = State->rippleMapSize; | |
135 | - int width = State->meshWidth; | |
136 | - int height = State->meshHeight; | |
137 | - int index = State->rippleIndex; | |
138 | - float ratio = (float)State->meshWidth / State->glWidth; | |
139 | - float xShift = State->xOffset * ratio * 2; | |
140 | - | |
141 | - float *vertices = loadSimpleMeshVerticesF(NAMED_WaterMesh, 0); | |
142 | - struct vert_s *vert = (struct vert_s *)vertices; | |
143 | - | |
144 | - float fw = 1.0f / width; | |
145 | - float fh = 1.0f / height; | |
146 | - int x, y, ct; | |
147 | - struct vert_s *v = vert; | |
148 | - for (y=0; y < height; y++) { | |
149 | - for (x=0; x < width; x++) { | |
150 | - struct drop_s * d = &gDrops[0]; | |
151 | - float z = 0; | |
152 | - | |
153 | - for (ct = 0; ct < gMaxDrops; ct++) { | |
154 | - if (d->ampE > 0.01f) { | |
155 | - float dx = (d->x - xShift) - x; | |
156 | - float dy = d->y - y; | |
157 | - float dist2 = dx*dx + dy*dy; | |
158 | - if (dist2 < d->spread2) { | |
159 | - float dist = sqrtf(dist2); | |
160 | - float a = d->ampE * (dist * d->invSpread); | |
161 | - z += sinf(d->spread - dist) * a; | |
162 | - } | |
163 | - } | |
164 | - d++; | |
165 | - } | |
166 | - v->z = z; | |
167 | - v ++; | |
168 | - } | |
169 | - } | |
115 | + int ct; | |
170 | 116 | for (ct = 0; ct < gMaxDrops; ct++) { |
171 | - updateDrop(ct); | |
117 | + struct drop_s * d = &gDrops[ct]; | |
118 | + vecF32_4_t *v = &Constants->Drop01; | |
119 | + v += ct; | |
120 | + v->x = d->x; | |
121 | + v->y = d->y; | |
122 | + v->z = d->ampE * 0.12f; | |
123 | + v->w = d->spread; | |
172 | 124 | } |
125 | + Constants->Offset.x = State->xOffset; | |
173 | 126 | |
174 | - v = vert; | |
175 | - for (y = 0; y < height; y += 1) { | |
176 | - for (x = 0; x < width; x += 1) { | |
177 | - struct vec3_s n1, n2, n3; | |
178 | - vec3Sub(&n1, (struct vec3_s *)&(v+1)->x, (struct vec3_s *)&v->x); | |
179 | - vec3Sub(&n2, (struct vec3_s *)&(v+width)->x, (struct vec3_s *)&v->x); | |
180 | - vec3Cross(&n3, &n1, &n2); | |
181 | - | |
182 | - // Average of previous normal and N1 x N2 | |
183 | - vec3Sub(&n1, (struct vec3_s *)&(v+width+1)->x, (struct vec3_s *)&v->x); | |
184 | - vec3Cross(&n2, &n1, &n2); | |
185 | - vec3Add(&n3, &n3, &n2); | |
186 | - //vec3Norm(&n3); // Not necessary for our constrained mesh. | |
187 | - | |
188 | - v->s = (float)x * fw + n3.x;// * 0.2; | |
189 | - v->t = (float)y * fh + n3.y;// * 0.2; | |
190 | - v->z = 0; | |
191 | - v += 1; | |
192 | - } | |
127 | + for (ct = 0; ct < gMaxDrops; ct++) { | |
128 | + updateDrop(ct); | |
193 | 129 | } |
194 | 130 | } |
195 | 131 |
@@ -357,46 +293,8 @@ void drawLeaves() { | ||
357 | 293 | |
358 | 294 | void drawRiverbed() { |
359 | 295 | bindTexture(NAMED_PFBackground, 0, NAMED_TRiverbed); |
360 | - | |
361 | - float matrix[16]; | |
362 | - matrixLoadScale(matrix, 0.5f * 960.0f / 1024.0f, -1.0f * 800.0f / 1024.0f, 1.0f); | |
363 | - matrixTranslate(matrix, State->xOffset, 0.0f, 0.0f); | |
364 | - vpLoadTextureMatrix(matrix); | |
365 | - | |
366 | - drawSimpleMesh(NAMED_WaterMesh); | |
367 | - | |
368 | - matrixLoadIdentity(matrix); | |
369 | - vpLoadTextureMatrix(matrix); | |
370 | -} | |
371 | - | |
372 | -/* | |
373 | -void drawSky() { | |
374 | - color(1.0f, 1.0f, 1.0f, 0.5f); | |
375 | - | |
376 | - bindProgramFragment(NAMED_PFSky); | |
377 | - bindProgramFragmentStore(NAMED_PFSLeaf); | |
378 | - bindTexture(NAMED_PFSky, 0, NAMED_TSky); | |
379 | - | |
380 | - float x = skyOffsetX + State->skySpeedX; | |
381 | - float y = skyOffsetY + State->skySpeedY; | |
382 | - | |
383 | - if (x > 1.0f) x = 0.0f; | |
384 | - if (x < -1.0f) x = 0.0f; | |
385 | - if (y > 1.0f) y = 0.0f; | |
386 | - | |
387 | - skyOffsetX = x; | |
388 | - skyOffsetY = y; | |
389 | - | |
390 | - float matrix[16]; | |
391 | - matrixLoadTranslate(matrix, x + State->xOffset, y, 0.0f); | |
392 | - vpLoadTextureMatrix(matrix); | |
393 | - | |
394 | 296 | drawSimpleMesh(NAMED_WaterMesh); |
395 | - | |
396 | - matrixLoadIdentity(matrix); | |
397 | - vpLoadTextureMatrix(matrix); | |
398 | 297 | } |
399 | -*/ | |
400 | 298 | |
401 | 299 | int main(int index) { |
402 | 300 | // Compute dt in seconds. |
@@ -425,17 +323,17 @@ int main(int index) { | ||
425 | 323 | genLeafDrop(gLeaves[i], randf(0.3f) + 0.1f); |
426 | 324 | } |
427 | 325 | |
428 | - generateRipples(); | |
429 | - updateSimpleMesh(NAMED_WaterMesh); | |
430 | - | |
431 | 326 | if (State->rotate) { |
432 | 327 | float matrix[16]; |
433 | 328 | matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f); |
434 | 329 | vpLoadModelMatrix(matrix); |
435 | 330 | } |
436 | 331 | |
332 | + bindProgramVertex(NAMED_PVWater); | |
333 | + generateRipples(); | |
437 | 334 | drawRiverbed(); |
438 | - // drawSky(); | |
335 | + | |
336 | + bindProgramVertex(NAMED_PVSky); | |
439 | 337 | drawLeaves(); |
440 | 338 | |
441 | 339 | return 30; |
@@ -13,7 +13,7 @@ | ||
13 | 13 | // limitations under the License. |
14 | 14 | |
15 | 15 | #pragma version(1) |
16 | -#pragma stateVertex(PVBackground) | |
16 | +#pragma stateVertex(PVBkOrtho) | |
17 | 17 | #pragma stateRaster(parent) |
18 | 18 | #pragma stateFragment(PFBackground) |
19 | 19 | #pragma stateStore(PFSBackground) |
@@ -51,25 +51,30 @@ float randomGauss() { | ||
51 | 51 | return x1 * w; |
52 | 52 | } |
53 | 53 | |
54 | +float gSpeed[12000]; | |
55 | + | |
54 | 56 | /** |
55 | 57 | * Generates the properties for a given star. |
56 | 58 | */ |
57 | -void createParticle(struct Stars_s *star, struct Particles_s *part, float scale) { | |
59 | +void createParticle(struct Particles_s *part, int idx, float scale) { | |
58 | 60 | float d = fabsf(randomGauss()) * State->galaxyRadius * 0.5f + randf(64.0f); |
59 | 61 | float id = d / State->galaxyRadius; |
60 | 62 | float z = randomGauss() * 0.4f * (1.0f - id); |
61 | 63 | float p = -d * ELLIPSE_TWIST; |
62 | 64 | |
65 | + int r,g,b,a; | |
63 | 66 | if (d < State->galaxyRadius * 0.33f) { |
64 | - part->r = (int) (220 + id * 35); | |
65 | - part->g = 220; | |
66 | - part->b = 220; | |
67 | + r = (int) (220 + id * 35); | |
68 | + g = 220; | |
69 | + b = 220; | |
67 | 70 | } else { |
68 | - part->r= 180; | |
69 | - part->g = 180; | |
70 | - part->b = (int) clampf(140.f + id * 115.f, 140.f, 255.f); | |
71 | + r = 180; | |
72 | + g = 180; | |
73 | + b = (int) clampf(140.f + id * 115.f, 140.f, 255.f); | |
71 | 74 | } |
72 | - part->a = (int) (140 + (1.0f - id) * 115); | |
75 | + // Stash point size * 10 in Alpha | |
76 | + a = (int) (randf2(1.2f, 2.1f) * 60); | |
77 | + part->color = r | g<<8 | b<<16 | a<<24; | |
73 | 78 | |
74 | 79 | if (d > State->galaxyRadius * 0.15f) { |
75 | 80 | z *= 0.6f * (1.0f - id); |
@@ -80,14 +85,11 @@ void createParticle(struct Stars_s *star, struct Particles_s *part, float scale) | ||
80 | 85 | // Map to the projection coordinates (viewport.x = -1.0 -> 1.0) |
81 | 86 | d = mapf(-4.0f, State->galaxyRadius + 4.0f, 0.0f, scale, d); |
82 | 87 | |
83 | - star->angle = randf(TWO_PI); | |
84 | - star->distance = d; | |
85 | - star->speed = randf2(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f; | |
86 | - star->s = cosf(p); | |
87 | - star->t = sinf(p); | |
88 | + part->position.x = randf(TWO_PI); | |
89 | + part->position.y = d; | |
90 | + gSpeed[idx] = randf2(0.0015f, 0.0025f) * (0.5f + (scale / d)) * 0.8f; | |
88 | 91 | |
89 | - part->z = z / 5.0f; | |
90 | - part->pointSize = randf2(1.2f, 2.1f) * 6; | |
92 | + part->position.z = z / 5.0f; | |
91 | 93 | } |
92 | 94 | |
93 | 95 | /** |
@@ -98,15 +100,13 @@ void initParticles() { | ||
98 | 100 | angle = 0.0f; |
99 | 101 | } |
100 | 102 | |
101 | - struct Stars_s *star = Stars; | |
102 | 103 | struct Particles_s *part = Particles; |
103 | 104 | int particlesCount = State->particlesCount; |
104 | 105 | float scale = State->galaxyRadius / (State->width * 0.5f); |
105 | 106 | |
106 | 107 | int i; |
107 | 108 | for (i = 0; i < particlesCount; i ++) { |
108 | - createParticle(star, part, scale); | |
109 | - star++; | |
109 | + createParticle(part, i, scale); | |
110 | 110 | part++; |
111 | 111 | } |
112 | 112 | } |
@@ -121,7 +121,7 @@ void drawSpace(float xOffset, int width, int height) { | ||
121 | 121 | } |
122 | 122 | |
123 | 123 | void drawLights(float xOffset, int width, int height) { |
124 | - bindProgramVertex(NAMED_PVStars); | |
124 | + bindProgramVertex(NAMED_PVBkProj); | |
125 | 125 | bindProgramFragment(NAMED_PFBackground); |
126 | 126 | bindTexture(NAMED_PFBackground, 0, NAMED_TLight1); |
127 | 127 |
@@ -158,26 +158,16 @@ void drawParticles(float xOffset, float offset, int width, int height) { | ||
158 | 158 | vpLoadModelMatrix(matrix); |
159 | 159 | |
160 | 160 | // quadratic attenuation |
161 | - pointAttenuation(0.1f + 0.3f * fabsf(offset), 0.0f, 0.06f + 0.1f * fabsf(offset)); | |
161 | + //pointAttenuation(0.1f + 0.3f * fabsf(offset), 0.0f, 0.06f + 0.1f * fabsf(offset)); | |
162 | 162 | |
163 | 163 | int radius = State->galaxyRadius; |
164 | 164 | int particlesCount = State->particlesCount; |
165 | 165 | |
166 | - struct Stars_s *star = Stars; | |
167 | 166 | struct Particles_s *vtx = Particles; |
168 | 167 | |
169 | 168 | int i = 0; |
170 | 169 | for ( ; i < particlesCount; i++) { |
171 | - float a = star->angle + star->speed; | |
172 | - float x = star->distance * sinf(a); | |
173 | - float y = star->distance * cosf(a) * ELLIPSE_RATIO; | |
174 | - | |
175 | - vtx->x = star->t * x + star->s * y + xOffset; | |
176 | - vtx->y = star->s * x - star->t * y; | |
177 | - | |
178 | - star->angle = a; | |
179 | - | |
180 | - star++; | |
170 | + vtx->position.x = vtx->position.x + gSpeed[i]; | |
181 | 171 | vtx++; |
182 | 172 | } |
183 | 173 |
@@ -17,25 +17,8 @@ | ||
17 | 17 | #pragma stateFragment(PFBackground) |
18 | 18 | #pragma stateStore(PFSBackground) |
19 | 19 | |
20 | -#define RSID_STATE 0 | |
21 | -#define RSID_BLADES 1 | |
22 | 20 | #define RSID_BLADES_BUFFER 2 |
23 | 21 | |
24 | -#define BLADE_STRUCT_FIELDS_COUNT 13 | |
25 | -#define BLADE_STRUCT_ANGLE 0 | |
26 | -#define BLADE_STRUCT_SIZE 1 | |
27 | -#define BLADE_STRUCT_XPOS 2 | |
28 | -#define BLADE_STRUCT_YPOS 3 | |
29 | -#define BLADE_STRUCT_OFFSET 4 | |
30 | -#define BLADE_STRUCT_SCALE 5 | |
31 | -#define BLADE_STRUCT_LENGTHX 6 | |
32 | -#define BLADE_STRUCT_LENGTHY 7 | |
33 | -#define BLADE_STRUCT_HARDNESS 8 | |
34 | -#define BLADE_STRUCT_H 9 | |
35 | -#define BLADE_STRUCT_S 10 | |
36 | -#define BLADE_STRUCT_B 11 | |
37 | -#define BLADE_STRUCT_TURBULENCEX 12 | |
38 | - | |
39 | 22 | #define TESSELATION 0.5f |
40 | 23 | #define HALF_TESSELATION 0.25f |
41 | 24 |
@@ -48,6 +31,21 @@ | ||
48 | 31 | |
49 | 32 | #define REAL_TIME 1 |
50 | 33 | |
34 | +void updateBlades() | |
35 | +{ | |
36 | + int bladesCount = State->bladesCount; | |
37 | + struct Blades_s *bladeStruct = Blades; | |
38 | + | |
39 | + int i; | |
40 | + for (i = 0; i < bladesCount; i ++) { | |
41 | + float xpos = randf2(-State->width, State->width); | |
42 | + bladeStruct->xPos = xpos; | |
43 | + bladeStruct->turbulencex = xpos * 0.006f; | |
44 | + bladeStruct->yPos = State->height; | |
45 | + bladeStruct++; | |
46 | + } | |
47 | +} | |
48 | + | |
51 | 49 | float time(int isPreview) { |
52 | 50 | if (REAL_TIME && !isPreview) { |
53 | 51 | return (hour() * 3600.0f + minute() * 60.0f + second()) / SECONDS_IN_DAY; |
@@ -88,91 +86,62 @@ void drawSunset(int width, int height) { | ||
88 | 86 | drawRect(0.0f, 0.0f, width, height, 0.0f); |
89 | 87 | } |
90 | 88 | |
91 | -int drawBlade(float *bladeStruct, float *bladeBuffer, int *bladeColor, | |
89 | +int drawBlade(struct Blades_s *bladeStruct, float *bladeBuffer, int *bladeColor, | |
92 | 90 | float brightness, float xOffset, float now) { |
93 | 91 | |
94 | - float offset = bladeStruct[BLADE_STRUCT_OFFSET]; | |
95 | - float scale = bladeStruct[BLADE_STRUCT_SCALE]; | |
96 | - float angle = bladeStruct[BLADE_STRUCT_ANGLE]; | |
97 | - float hardness = bladeStruct[BLADE_STRUCT_HARDNESS]; | |
98 | - float turbulenceX = bladeStruct[BLADE_STRUCT_TURBULENCEX]; | |
99 | - | |
100 | - float xpos = bladeStruct[BLADE_STRUCT_XPOS] + xOffset; | |
101 | - float ypos = bladeStruct[BLADE_STRUCT_YPOS]; | |
92 | + float scale = bladeStruct->scale; | |
93 | + float angle = bladeStruct->angle; | |
94 | + float xpos = bladeStruct->xPos + xOffset; | |
95 | + int size = bladeStruct->size; | |
102 | 96 | |
103 | - float lengthX = bladeStruct[BLADE_STRUCT_LENGTHX]; | |
104 | - float lengthY = bladeStruct[BLADE_STRUCT_LENGTHY]; | |
97 | + int color = hsbToAbgr(bladeStruct->h, bladeStruct->s, | |
98 | + lerpf(0, bladeStruct->b, brightness), 1.0f); | |
105 | 99 | |
106 | - int size = bladeStruct[BLADE_STRUCT_SIZE]; | |
107 | - | |
108 | - float h = bladeStruct[BLADE_STRUCT_H]; | |
109 | - float s = bladeStruct[BLADE_STRUCT_S]; | |
110 | - float b = bladeStruct[BLADE_STRUCT_B]; | |
111 | - | |
112 | - int color = hsbToAbgr(h, s, lerpf(0, b, brightness), 1.0f); | |
113 | - | |
114 | - float newAngle = (turbulencef2(turbulenceX, now, 4.0f) - 0.5f) * 0.5f; | |
115 | - angle = clampf(angle + (newAngle + offset - angle) * 0.15f, -MAX_BEND, MAX_BEND); | |
100 | + float newAngle = (turbulencef2(bladeStruct->turbulencex, now, 4.0f) - 0.5f) * 0.5f; | |
101 | + angle = clampf(angle + (newAngle + bladeStruct->offset - angle) * 0.15f, -MAX_BEND, MAX_BEND); | |
116 | 102 | |
117 | 103 | float currentAngle = HALF_PI; |
118 | 104 | |
119 | 105 | float bottomX = xpos; |
120 | - float bottomY = ypos; | |
106 | + float bottomY = bladeStruct->yPos; | |
121 | 107 | |
122 | - float d = angle * hardness; | |
108 | + float d = angle * bladeStruct->hardness; | |
123 | 109 | |
124 | - int triangles = size * 2; | |
110 | + | |
111 | + float si = size * scale; | |
112 | + float bottomLeft = bottomX - si; | |
113 | + float bottomRight = bottomX + si; | |
114 | + float bottom = bottomY + HALF_TESSELATION; | |
115 | + | |
116 | + bladeColor[0] = color; // V1.ABGR | |
117 | + bladeBuffer[1] = bottomLeft; // V1.X | |
118 | + bladeBuffer[2] = bottom; // V1.Y | |
119 | + bladeColor[5] = color; // V2.ABGR | |
120 | + bladeBuffer[6] = bottomRight; // V2.X | |
121 | + bladeBuffer[7] = bottom; // V2.Y | |
122 | + bladeBuffer += 10; | |
123 | + bladeColor += 10; | |
125 | 124 | |
126 | 125 | for ( ; size > 0; size -= 1) { |
127 | - float topX = bottomX - cosf_fast(currentAngle) * lengthX; | |
128 | - float topY = bottomY - sinf_fast(currentAngle) * lengthY; | |
126 | + float topX = bottomX - cosf_fast(currentAngle) * bladeStruct->lengthX; | |
127 | + float topY = bottomY - sinf_fast(currentAngle) * bladeStruct->lengthY; | |
129 | 128 | |
130 | - float si = size * scale; | |
129 | + si = (float)size * scale; | |
131 | 130 | float spi = si - scale; |
132 | 131 | |
133 | - float bottomLeft = bottomX - si; | |
134 | - float bottomRight = bottomX + si; | |
135 | 132 | float topLeft = topX - spi; |
136 | 133 | float topRight = topX + spi; |
137 | - float bottom = bottomY + HALF_TESSELATION; | |
138 | 134 | |
139 | - // First triangle | |
140 | 135 | bladeColor[0] = color; // V1.ABGR |
136 | + bladeBuffer[1] = topLeft; // V2.X | |
137 | + bladeBuffer[2] = topY; // V2.Y | |
141 | 138 | |
142 | - bladeBuffer[1] = bottomLeft; // V1.X | |
143 | - bladeBuffer[2] = bottom; // V1.Y | |
144 | - | |
145 | - bladeColor[5] = color; // V1.ABGR | |
146 | - | |
147 | - bladeBuffer[6] = topLeft; // V2.X | |
148 | - bladeBuffer[7] = topY; // V2.Y | |
149 | - | |
150 | - bladeColor[10] = color; // V3.ABGR | |
151 | - | |
152 | - bladeBuffer[11] = topRight; // V3.X | |
153 | - bladeBuffer[12] = topY; // V3.Y | |
154 | - | |
155 | - // Second triangle | |
156 | - bladeBuffer += 15; | |
157 | - bladeColor += 15; | |
158 | - | |
159 | - bladeColor[0] = color; // V1.ABGR | |
160 | - | |
161 | - bladeBuffer[1] = bottomLeft; // V1.X | |
162 | - bladeBuffer[2] = bottom; // V1.Y | |
163 | - | |
164 | - bladeColor[5] = color; // V2.ABGR | |
165 | - | |
166 | - bladeBuffer[6] = topRight; // V2.X | |
167 | - bladeBuffer[7] = topY; // V2.Y | |
168 | - | |
169 | - bladeColor[10] = color; // V3.ABGR | |
170 | - | |
171 | - bladeBuffer[11] = bottomRight; // V3.X | |
172 | - bladeBuffer[12] = bottom; // V3.Y | |
139 | + bladeColor[5] = color; // V3.ABGR | |
140 | + bladeBuffer[6] = topRight; // V3.X | |
141 | + bladeBuffer[7] = topY; // V3.Y | |
173 | 142 | |
174 | - bladeBuffer += 15; | |
175 | - bladeColor += 15; | |
143 | + bladeBuffer += 10; | |
144 | + bladeColor += 10; | |
176 | 145 | |
177 | 146 | bottomX = topX; |
178 | 147 | bottomY = topY; |
@@ -180,21 +149,20 @@ int drawBlade(float *bladeStruct, float *bladeBuffer, int *bladeColor, | ||
180 | 149 | currentAngle += d; |
181 | 150 | } |
182 | 151 | |
183 | - bladeStruct[BLADE_STRUCT_ANGLE] = angle; | |
152 | + bladeStruct->angle = angle; | |
184 | 153 | |
185 | - // 3 vertices per triangle, 5 properties per vertex (RGBA, X, Y, S, T) | |
186 | - return triangles * 15; | |
154 | + // 2 vertices per triangle, 5 properties per vertex (RGBA, X, Y, S, T) | |
155 | + return bladeStruct->size * 10 + 10; | |
187 | 156 | } |
188 | 157 | |
189 | 158 | void drawBlades(float brightness, float xOffset) { |
190 | 159 | // For anti-aliasing |
191 | - bindTexture(NAMED_PFBackground, 0, NAMED_TAa); | |
160 | + bindTexture(NAMED_PFGrass, 0, NAMED_TAa); | |
192 | 161 | |
193 | 162 | int bladesCount = State->bladesCount; |
194 | - int trianglesCount = State->trianglesCount; | |
195 | 163 | |
196 | 164 | int i = 0; |
197 | - float *bladeStruct = loadArrayF(RSID_BLADES, 0); | |
165 | + struct Blades_s *bladeStruct = Blades; | |
198 | 166 | float *bladeBuffer = loadArrayF(RSID_BLADES_BUFFER, 0); |
199 | 167 | int *bladeColor = loadArrayI32(RSID_BLADES_BUFFER, 0); |
200 | 168 |
@@ -204,11 +172,11 @@ void drawBlades(float brightness, float xOffset) { | ||
204 | 172 | int offset = drawBlade(bladeStruct, bladeBuffer, bladeColor, brightness, xOffset, now); |
205 | 173 | bladeBuffer += offset; |
206 | 174 | bladeColor += offset; |
207 | - bladeStruct += BLADE_STRUCT_FIELDS_COUNT; | |
175 | + bladeStruct ++; | |
208 | 176 | } |
209 | 177 | |
210 | 178 | uploadToBufferObject(NAMED_BladesBuffer); |
211 | - drawSimpleMeshRange(NAMED_BladesMesh, 0, trianglesCount * 3); | |
179 | + drawSimpleMeshRange(NAMED_BladesMesh, 0, State->indexCount); | |
212 | 180 | } |
213 | 181 | |
214 | 182 | int main(int launchID) { |
@@ -262,7 +230,8 @@ int main(int launchID) { | ||
262 | 230 | newB = 0.0f; |
263 | 231 | } |
264 | 232 | |
233 | + bindProgramFragment(NAMED_PFGrass); | |
265 | 234 | drawBlades(newB, x); |
266 | 235 | |
267 | - return 30; | |
236 | + return 50; | |
268 | 237 | } |
@@ -14,7 +14,6 @@ | ||
14 | 14 | |
15 | 15 | #pragma version(1) |
16 | 16 | #pragma stateVertex(PVOrtho) |
17 | -#pragma stateFragment(PFTexture) | |
18 | 17 | #pragma stateStore(PSSolid) |
19 | 18 | |
20 | 19 | #define MAX_PULSES 20 |
@@ -48,18 +47,21 @@ int gNow; | ||
48 | 47 | |
49 | 48 | |
50 | 49 | void setColor(int c) { |
51 | - if (c == 0) { | |
50 | + if (State->mode == 1) { | |
51 | + // sholes red | |
52 | + color(0.9f, 0.1f, 0.1f, 0.8f); | |
53 | + } else if (c == 0) { | |
52 | 54 | // red |
53 | - color(1.0f, 0.0f, 0.0f, 1.0f); | |
55 | + color(1.0f, 0.0f, 0.0f, 0.8f); | |
54 | 56 | } else if (c == 1) { |
55 | 57 | // green |
56 | - color(0.0f, 0.6f, 0.0f, 1.0f); | |
58 | + color(0.0f, 0.8f, 0.0f, 0.8f); | |
57 | 59 | } else if (c == 2) { |
58 | 60 | // blue |
59 | - color(0.0f, 0.4f, 0.8f, 1.0f); | |
61 | + color(0.0f, 0.4f, 0.9f, 0.8f); | |
60 | 62 | } else if (c == 3) { |
61 | 63 | // yellow |
62 | - color(1.0f, 0.8f, 0.0f, 1.0f); | |
64 | + color(1.0f, 0.8f, 0.0f, 0.8f); | |
63 | 65 | } |
64 | 66 | } |
65 | 67 |
@@ -115,7 +117,8 @@ void initPulses() { | ||
115 | 117 | } |
116 | 118 | |
117 | 119 | void drawBackground(int width, int height) { |
118 | - bindTexture(NAMED_PFTexture, 0, NAMED_TBackground); | |
120 | + bindProgramFragment(NAMED_PFTexture565); | |
121 | + bindTexture(NAMED_PFTexture565, 0, NAMED_TBackground); | |
119 | 122 | color(1.0f, 1.0f, 1.0f, 1.0f); |
120 | 123 | if (State->rotate) { |
121 | 124 | drawRect(0.0f, 0.0f, height*2, width, 0.0f); |
@@ -267,8 +270,8 @@ int main(int index) { | ||
267 | 270 | gNow = uptimeMillis(); |
268 | 271 | |
269 | 272 | if (Command->command != 0) { |
270 | - debugF("x", Command->x); | |
271 | - debugF("y", Command->y); | |
273 | + //debugF("x", Command->x); | |
274 | + //debugF("y", Command->y); | |
272 | 275 | Command->command = 0; |
273 | 276 | addTap(Command->x, Command->y); |
274 | 277 | } |
@@ -0,0 +1,3 @@ | ||
1 | +<resources> | |
2 | + <integer name="nexus_mode">0</integer> | |
3 | +</resources> |
@@ -17,6 +17,7 @@ | ||
17 | 17 | package com.android.wallpaper.fall; |
18 | 18 | |
19 | 19 | import android.os.Bundle; |
20 | +import android.renderscript.Element; | |
20 | 21 | import android.renderscript.ScriptC; |
21 | 22 | import android.renderscript.ProgramFragment; |
22 | 23 | import android.renderscript.ProgramStore; |
@@ -28,11 +29,10 @@ import android.renderscript.Type; | ||
28 | 29 | import android.renderscript.SimpleMesh; |
29 | 30 | import android.renderscript.Script; |
30 | 31 | import static android.renderscript.Sampler.Value.LINEAR; |
31 | -import static android.renderscript.Sampler.Value.WRAP; | |
32 | +import static android.renderscript.Sampler.Value.CLAMP; | |
32 | 33 | import static android.renderscript.ProgramStore.DepthFunc.*; |
33 | 34 | import static android.renderscript.ProgramStore.BlendDstFunc; |
34 | 35 | import static android.renderscript.ProgramStore.BlendSrcFunc; |
35 | -import static android.renderscript.ProgramFragment.EnvMode.*; | |
36 | 36 | import static android.renderscript.Element.*; |
37 | 37 | |
38 | 38 | import android.app.WallpaperManager; |
@@ -49,16 +49,20 @@ class FallRS extends RenderScriptScene { | ||
49 | 49 | private static final int MESH_RESOLUTION = 48; |
50 | 50 | |
51 | 51 | private static final int RSID_STATE = 0; |
52 | + private static final int RSID_CONSTANTS = 1; | |
53 | + private static final int RSID_DROP = 2; | |
52 | 54 | |
53 | 55 | private static final int TEXTURES_COUNT = 2; |
54 | 56 | private static final int RSID_TEXTURE_RIVERBED = 0; |
55 | 57 | private static final int RSID_TEXTURE_LEAVES = 1; |
56 | 58 | private static final int RSID_TEXTURE_SKY = 2; |
57 | 59 | |
58 | - private static final int RSID_RIPPLE_MAP = 1; | |
59 | - private static final int RSID_DROP = 2; | |
60 | 60 | |
61 | 61 | |
62 | + static class Defines { | |
63 | + | |
64 | + }; | |
65 | + | |
62 | 66 | private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options(); |
63 | 67 | |
64 | 68 | @SuppressWarnings({"FieldCanBeLocal"}) |
@@ -71,6 +75,7 @@ class FallRS extends RenderScriptScene { | ||
71 | 75 | private ProgramStore mPfsLeaf; |
72 | 76 | @SuppressWarnings({"FieldCanBeLocal"}) |
73 | 77 | private ProgramVertex mPvSky; |
78 | + private ProgramVertex mPvWater; | |
74 | 79 | private ProgramVertex.MatrixAllocation mPvOrthoAlloc; |
75 | 80 | @SuppressWarnings({"FieldCanBeLocal"}) |
76 | 81 | private Sampler mSampler; |
@@ -81,14 +86,13 @@ class FallRS extends RenderScriptScene { | ||
81 | 86 | private Type mStateType; |
82 | 87 | private Type mDropType; |
83 | 88 | private int mMeshWidth; |
89 | + private Allocation mUniformAlloc; | |
84 | 90 | |
85 | 91 | private int mMeshHeight; |
86 | 92 | @SuppressWarnings({"FieldCanBeLocal"}) |
87 | 93 | private SimpleMesh mMesh; |
88 | 94 | private WorldState mWorldState; |
89 | 95 | |
90 | - private Allocation mRippleMap; | |
91 | - | |
92 | 96 | private float mGlHeight; |
93 | 97 | |
94 | 98 | public FallRS(int width, int height) { |
@@ -114,7 +118,7 @@ class FallRS extends RenderScriptScene { | ||
114 | 118 | } |
115 | 119 | return null; |
116 | 120 | } |
117 | - | |
121 | + | |
118 | 122 | @Override |
119 | 123 | public void start() { |
120 | 124 | super.start(); |
@@ -139,16 +143,19 @@ class FallRS extends RenderScriptScene { | ||
139 | 143 | |
140 | 144 | @Override |
141 | 145 | protected ScriptC createScript() { |
146 | + createMesh(); | |
147 | + createState(); | |
142 | 148 | createProgramVertex(); |
143 | 149 | createProgramFragmentStore(); |
144 | 150 | createProgramFragment(); |
145 | - createMesh(); | |
146 | - createScriptStructures(); | |
147 | 151 | loadTextures(); |
148 | 152 | |
153 | + | |
154 | + | |
149 | 155 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
150 | 156 | sb.setType(mStateType, "State", RSID_STATE); |
151 | 157 | sb.setType(mDropType, "Drop", RSID_DROP); |
158 | + sb.setType(mUniformAlloc.getType(), "Constants", RSID_CONSTANTS); | |
152 | 159 | sb.setScript(mResources, R.raw.fall); |
153 | 160 | Script.Invokable invokable = sb.addInvokable("initLeaves"); |
154 | 161 | sb.setRoot(true); |
@@ -158,7 +165,7 @@ class FallRS extends RenderScriptScene { | ||
158 | 165 | script.setTimeZone(TimeZone.getDefault().getID()); |
159 | 166 | |
160 | 167 | script.bindAllocation(mState, RSID_STATE); |
161 | - script.bindAllocation(mRippleMap, RSID_RIPPLE_MAP); | |
168 | + script.bindAllocation(mUniformAlloc, RSID_CONSTANTS); | |
162 | 169 | script.bindAllocation(mDropState, RSID_DROP); |
163 | 170 | |
164 | 171 | invokable.execute(); |
@@ -167,8 +174,7 @@ class FallRS extends RenderScriptScene { | ||
167 | 174 | } |
168 | 175 | |
169 | 176 | private void createMesh() { |
170 | - SimpleMesh.TriangleMeshBuilder tmb = new SimpleMesh.TriangleMeshBuilder(mRS, 3, | |
171 | - SimpleMesh.TriangleMeshBuilder.TEXTURE_0); | |
177 | + SimpleMesh.TriangleMeshBuilder tmb = new SimpleMesh.TriangleMeshBuilder(mRS, 2, 0); | |
172 | 178 | |
173 | 179 | final int width = mWidth > mHeight ? mHeight : mWidth; |
174 | 180 | final int height = mWidth > mHeight ? mWidth : mHeight; |
@@ -186,11 +192,9 @@ class FallRS extends RenderScriptScene { | ||
186 | 192 | hResolution += 2; |
187 | 193 | |
188 | 194 | for (int y = 0; y <= hResolution; y++) { |
189 | - final float yOffset = y * quadHeight - glHeight / 2.0f - quadHeight; | |
190 | - final float t = 1.0f - y / (float) hResolution; | |
195 | + final float yOffset = (((float)y / hResolution) * 2.f - 1.f) * height / width; | |
191 | 196 | for (int x = 0; x <= wResolution; x++) { |
192 | - tmb.setTexture(x / (float) wResolution, t); | |
193 | - tmb.addVertex(-1.0f + x * quadWidth - quadWidth, yOffset, 0.0f); | |
197 | + tmb.addVertex(((float)x / wResolution) * 2.f - 1.f, yOffset); | |
194 | 198 | } |
195 | 199 | } |
196 | 200 |
@@ -217,26 +221,12 @@ class FallRS extends RenderScriptScene { | ||
217 | 221 | mMeshHeight = hResolution + 1; |
218 | 222 | } |
219 | 223 | |
220 | - private void createScriptStructures() { | |
221 | - final int rippleMapSize = (mMeshWidth + 2) * (mMeshHeight + 2); | |
222 | - | |
223 | - createState(rippleMapSize); | |
224 | - createRippleMap(rippleMapSize); | |
225 | - } | |
226 | - | |
227 | - private void createRippleMap(int rippleMapSize) { | |
228 | - final int[] rippleMap = new int[rippleMapSize * 2]; | |
229 | - mRippleMap = Allocation.createSized(mRS, USER_I32(mRS), rippleMap.length); | |
230 | - mRippleMap.data(rippleMap); | |
231 | - } | |
232 | - | |
233 | 224 | static class WorldState { |
234 | 225 | public int frameCount; |
235 | 226 | public int width; |
236 | 227 | public int height; |
237 | 228 | public int meshWidth; |
238 | 229 | public int meshHeight; |
239 | - public int rippleMapSize; | |
240 | 230 | public int rippleIndex; |
241 | 231 | public int leavesCount; |
242 | 232 | public float glWidth; |
@@ -253,13 +243,12 @@ class FallRS extends RenderScriptScene { | ||
253 | 243 | public int dropY; |
254 | 244 | } |
255 | 245 | |
256 | - private void createState(int rippleMapSize) { | |
246 | + private void createState() { | |
257 | 247 | mWorldState = new WorldState(); |
258 | 248 | mWorldState.width = mWidth; |
259 | 249 | mWorldState.height = mHeight; |
260 | 250 | mWorldState.meshWidth = mMeshWidth; |
261 | 251 | mWorldState.meshHeight = mMeshHeight; |
262 | - mWorldState.rippleMapSize = rippleMapSize; | |
263 | 252 | mWorldState.rippleIndex = 0; |
264 | 253 | mWorldState.glWidth = 2.0f; |
265 | 254 | mWorldState.glHeight = mGlHeight; |
@@ -280,7 +269,7 @@ class FallRS extends RenderScriptScene { | ||
280 | 269 | mDropState = Allocation.createTyped(mRS, mDropType); |
281 | 270 | mDropState.data(mDrop); |
282 | 271 | } |
283 | - | |
272 | + | |
284 | 273 | private void loadTextures() { |
285 | 274 | final Allocation[] textures = new Allocation[TEXTURES_COUNT]; |
286 | 275 | textures[RSID_TEXTURE_RIVERBED] = loadTexture(R.drawable.pond, "TRiverbed"); |
@@ -311,20 +300,20 @@ class FallRS extends RenderScriptScene { | ||
311 | 300 | Sampler.Builder sampleBuilder = new Sampler.Builder(mRS); |
312 | 301 | sampleBuilder.setMin(LINEAR); |
313 | 302 | sampleBuilder.setMag(LINEAR); |
314 | - sampleBuilder.setWrapS(WRAP); | |
315 | - sampleBuilder.setWrapT(WRAP); | |
303 | + sampleBuilder.setWrapS(CLAMP); | |
304 | + sampleBuilder.setWrapT(CLAMP); | |
316 | 305 | mSampler = sampleBuilder.create(); |
317 | 306 | |
318 | - ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null); | |
319 | - builder.setTexEnable(true, 0); | |
320 | - builder.setTexEnvMode(REPLACE, 0); | |
307 | + ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS); | |
308 | + builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, | |
309 | + ProgramFragment.Builder.Format.RGBA, 0); | |
321 | 310 | mPfBackground = builder.create(); |
322 | 311 | mPfBackground.setName("PFBackground"); |
323 | 312 | mPfBackground.bindSampler(mSampler, 0); |
324 | 313 | |
325 | - builder = new ProgramFragment.Builder(mRS, null, null); | |
326 | - builder.setTexEnable(true, 0); | |
327 | - builder.setTexEnvMode(MODULATE, 0); | |
314 | + builder = new ProgramFragment.Builder(mRS); | |
315 | + builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, | |
316 | + ProgramFragment.Builder.Format.RGBA, 0); | |
328 | 317 | mPfSky = builder.create(); |
329 | 318 | mPfSky.setName("PFSky"); |
330 | 319 | mPfSky.bindSampler(mSampler, 0); |
@@ -353,10 +342,157 @@ class FallRS extends RenderScriptScene { | ||
353 | 342 | mPvOrthoAlloc.setupProjectionNormalized(mWidth, mHeight); |
354 | 343 | |
355 | 344 | ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null); |
356 | - builder.setTextureMatrixEnable(true); | |
357 | 345 | mPvSky = builder.create(); |
358 | 346 | mPvSky.bindAllocation(mPvOrthoAlloc); |
359 | 347 | mPvSky.setName("PVSky"); |
348 | + | |
349 | + float dw = 480.f / mMeshWidth; | |
350 | + float dh = 800.f / mMeshHeight; | |
351 | + | |
352 | + Element.Builder eb = new Element.Builder(mRS); | |
353 | + // Make this an array when we can. | |
354 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop01"); | |
355 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop02"); | |
356 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop03"); | |
357 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop04"); | |
358 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop05"); | |
359 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop06"); | |
360 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop07"); | |
361 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop08"); | |
362 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop09"); | |
363 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Drop10"); | |
364 | + eb.add(Element.createVector(mRS, Element.DataType.FLOAT_32, 4), "Offset"); | |
365 | + Element e = eb.create(); | |
366 | + | |
367 | + mUniformAlloc = Allocation.createSized(mRS, e, 1); | |
368 | + | |
369 | + | |
370 | + ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS); | |
371 | + String t = new String("void main() {\n" + | |
372 | + " vec4 pos;\n" + | |
373 | + " pos.x = ATTRIB_position.x;\n" + | |
374 | + " pos.y = ATTRIB_position.y;\n" + | |
375 | + " pos.z = 0.0;\n" + | |
376 | + " pos.w = 1.0;\n" + | |
377 | + " gl_Position = pos;\n" + | |
378 | + | |
379 | + // When we resize the texture we will need to tweak this. | |
380 | + " varTex0.x = (pos.x + 1.0) * 0.25;\n" + | |
381 | + " varTex0.x += UNI_Offset.x * 0.5 * 0.85;\n" + | |
382 | + " varTex0.y = (pos.y + 1.6666) * 0.33;\n" + | |
383 | + " varTex0.w = 0.0;\n" + | |
384 | + " varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" + | |
385 | + | |
386 | + " pos.x += UNI_Offset.x * 2.0;\n" + | |
387 | + " pos.x += 1.0;\n" + | |
388 | + " pos.y += 1.0;\n" + | |
389 | + " pos.x *= 25.0;\n" + | |
390 | + " pos.y *= 42.0;\n" + | |
391 | + | |
392 | + " vec2 delta;\n" + | |
393 | + " float dist;\n" + | |
394 | + " float amp;\n" + | |
395 | + | |
396 | + " delta = UNI_Drop01.xy - pos.xy;\n" + | |
397 | + " dist = length(delta);\n" + | |
398 | + " if (dist < UNI_Drop01.w) { \n" + | |
399 | + " amp = UNI_Drop01.z * dist;\n" + | |
400 | + " amp /= UNI_Drop01.w * UNI_Drop01.w;\n" + | |
401 | + " amp *= sin(UNI_Drop01.w - dist);\n" + | |
402 | + " varTex0.xy += delta * amp;\n" + | |
403 | + " }\n" + | |
404 | + | |
405 | + " delta = UNI_Drop02.xy - pos.xy;\n" + | |
406 | + " dist = length(delta);\n" + | |
407 | + " if (dist < UNI_Drop02.w) { \n" + | |
408 | + " amp = UNI_Drop02.z * dist;\n" + | |
409 | + " amp /= UNI_Drop02.w * UNI_Drop02.w;\n" + | |
410 | + " amp *= sin(UNI_Drop02.w - dist);\n" + | |
411 | + " varTex0.xy += delta * amp;\n" + | |
412 | + " }\n" + | |
413 | + | |
414 | + " delta = UNI_Drop03.xy - pos.xy;\n" + | |
415 | + " dist = length(delta);\n" + | |
416 | + " if (dist < UNI_Drop03.w) { \n" + | |
417 | + " amp = UNI_Drop03.z * dist;\n" + | |
418 | + " amp /= UNI_Drop03.w * UNI_Drop03.w;\n" + | |
419 | + " amp *= sin(UNI_Drop03.w - dist);\n" + | |
420 | + " varTex0.xy += delta * amp;\n" + | |
421 | + " }\n" + | |
422 | + | |
423 | + " delta = UNI_Drop04.xy - pos.xy;\n" + | |
424 | + " dist = length(delta);\n" + | |
425 | + " if (dist < UNI_Drop04.w) { \n" + | |
426 | + " amp = UNI_Drop04.z * dist;\n" + | |
427 | + " amp /= UNI_Drop04.w * UNI_Drop04.w;\n" + | |
428 | + " amp *= sin(UNI_Drop04.w - dist);\n" + | |
429 | + " varTex0.xy += delta * amp;\n" + | |
430 | + " }\n" + | |
431 | + | |
432 | + " delta = UNI_Drop05.xy - pos.xy;\n" + | |
433 | + " dist = length(delta);\n" + | |
434 | + " if (dist < UNI_Drop05.w) { \n" + | |
435 | + " amp = UNI_Drop05.z * dist;\n" + | |
436 | + " amp /= UNI_Drop05.w * UNI_Drop05.w;\n" + | |
437 | + " amp *= sin(UNI_Drop05.w - dist);\n" + | |
438 | + " varTex0.xy += delta * amp;\n" + | |
439 | + " }\n" + | |
440 | + | |
441 | + " delta = UNI_Drop06.xy - pos.xy;\n" + | |
442 | + " dist = length(delta);\n" + | |
443 | + " if (dist < UNI_Drop06.w) { \n" + | |
444 | + " amp = UNI_Drop06.z * dist;\n" + | |
445 | + " amp /= UNI_Drop06.w * UNI_Drop06.w;\n" + | |
446 | + " amp *= sin(UNI_Drop06.w - dist);\n" + | |
447 | + " varTex0.xy += delta * amp;\n" + | |
448 | + " }\n" + | |
449 | + | |
450 | + " delta = UNI_Drop07.xy - pos.xy;\n" + | |
451 | + " dist = length(delta);\n" + | |
452 | + " if (dist < UNI_Drop07.w) { \n" + | |
453 | + " amp = UNI_Drop07.z * dist;\n" + | |
454 | + " amp /= UNI_Drop07.w * UNI_Drop07.w;\n" + | |
455 | + " amp *= sin(UNI_Drop07.w - dist);\n" + | |
456 | + " varTex0.xy += delta * amp;\n" + | |
457 | + " }\n" + | |
458 | + | |
459 | + " delta = UNI_Drop08.xy - pos.xy;\n" + | |
460 | + " dist = length(delta);\n" + | |
461 | + " if (dist < UNI_Drop08.w) { \n" + | |
462 | + " amp = UNI_Drop08.z * dist;\n" + | |
463 | + " amp /= UNI_Drop08.w * UNI_Drop08.w;\n" + | |
464 | + " amp *= sin(UNI_Drop08.w - dist);\n" + | |
465 | + " varTex0.xy += delta * amp;\n" + | |
466 | + " }\n" + | |
467 | + | |
468 | + " delta = UNI_Drop09.xy - pos.xy;\n" + | |
469 | + " dist = length(delta);\n" + | |
470 | + " if (dist < UNI_Drop09.w) { \n" + | |
471 | + " amp = UNI_Drop09.z * dist;\n" + | |
472 | + " amp /= UNI_Drop09.w * UNI_Drop09.w;\n" + | |
473 | + " amp *= sin(UNI_Drop09.w - dist);\n" + | |
474 | + " varTex0.xy += delta * amp;\n" + | |
475 | + " }\n" + | |
476 | + | |
477 | + " delta = UNI_Drop10.xy - pos.xy;\n" + | |
478 | + " dist = length(delta);\n" + | |
479 | + " if (dist < UNI_Drop10.w) { \n" + | |
480 | + " amp = UNI_Drop10.z * dist;\n" + | |
481 | + " amp /= UNI_Drop10.w * UNI_Drop10.w;\n" + | |
482 | + " amp *= sin(UNI_Drop10.w - dist);\n" + | |
483 | + " varTex0.xy += delta * amp;\n" + | |
484 | + " }\n" + | |
485 | + | |
486 | + | |
487 | + "}\n"); | |
488 | + sb.setShader(t); | |
489 | + sb.addConstant(mUniformAlloc.getType()); | |
490 | + sb.addInput(mMesh.getVertexType(0).getElement()); | |
491 | + mPvWater = sb.create(); | |
492 | + mPvWater.bindAllocation(mPvOrthoAlloc); | |
493 | + mPvWater.setName("PVWater"); | |
494 | + mPvWater.bindConstants(mUniformAlloc, 1); | |
495 | + | |
360 | 496 | } |
361 | 497 | |
362 | 498 | void addDrop(float x, float y) { |
@@ -33,7 +33,6 @@ import static android.renderscript.Sampler.Value.WRAP; | ||
33 | 33 | import static android.renderscript.ProgramStore.DepthFunc.*; |
34 | 34 | import static android.renderscript.ProgramStore.BlendDstFunc; |
35 | 35 | import static android.renderscript.ProgramStore.BlendSrcFunc; |
36 | -import static android.renderscript.ProgramFragment.EnvMode.*; | |
37 | 36 | import static android.renderscript.Element.*; |
38 | 37 | import android.graphics.Bitmap; |
39 | 38 | import android.graphics.BitmapFactory; |
@@ -48,8 +47,7 @@ class GalaxyRS extends RenderScriptScene { | ||
48 | 47 | private static final int PARTICLES_COUNT = 12000; |
49 | 48 | |
50 | 49 | private static final int RSID_STATE = 0; |
51 | - private static final int RSID_PARTICLES = 1; | |
52 | - private static final int RSID_PARTICLES_BUFFER = 2; | |
50 | + private static final int RSID_PARTICLES_BUFFER = 1; | |
53 | 51 | |
54 | 52 | private static final int TEXTURES_COUNT = 3; |
55 | 53 | private static final int RSID_TEXTURE_SPACE = 0; |
@@ -67,7 +65,9 @@ class GalaxyRS extends RenderScriptScene { | ||
67 | 65 | @SuppressWarnings({"FieldCanBeLocal"}) |
68 | 66 | private ProgramStore mPfsLights; |
69 | 67 | @SuppressWarnings({"FieldCanBeLocal"}) |
70 | - private ProgramVertex mPvBackground; | |
68 | + private ProgramVertex mPvBkOrtho; | |
69 | + @SuppressWarnings({"FieldCanBeLocal"}) | |
70 | + private ProgramVertex mPvBkProj; | |
71 | 71 | @SuppressWarnings({"FieldCanBeLocal"}) |
72 | 72 | private ProgramVertex mPvStars; |
73 | 73 | @SuppressWarnings({"FieldCanBeLocal"}) |
@@ -84,8 +84,6 @@ class GalaxyRS extends RenderScriptScene { | ||
84 | 84 | private GalaxyState mGalaxyState; |
85 | 85 | private Type mStateType; |
86 | 86 | private Allocation mState; |
87 | - private Allocation mParticles; | |
88 | - private Type mParticlesType; | |
89 | 87 | private Allocation mParticlesBuffer; |
90 | 88 | @SuppressWarnings({"FieldCanBeLocal"}) |
91 | 89 | private SimpleMesh mParticlesMesh; |
@@ -100,17 +98,16 @@ class GalaxyRS extends RenderScriptScene { | ||
100 | 98 | |
101 | 99 | @Override |
102 | 100 | protected ScriptC createScript() { |
101 | + createScriptStructures(); | |
103 | 102 | createProgramVertex(); |
104 | 103 | createProgramRaster(); |
105 | 104 | createProgramFragmentStore(); |
106 | 105 | createProgramFragment(); |
107 | - createScriptStructures(); | |
108 | 106 | loadTextures(); |
109 | 107 | |
110 | 108 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
111 | 109 | sb.setType(mStateType, "State", RSID_STATE); |
112 | 110 | sb.setType(mParticlesMesh.getVertexType(0), "Particles", RSID_PARTICLES_BUFFER); |
113 | - sb.setType(mParticlesType, "Stars", RSID_PARTICLES); | |
114 | 111 | mInitParticles = sb.addInvokable("initParticles"); |
115 | 112 | sb.setScript(mResources, R.raw.galaxy); |
116 | 113 | sb.setRoot(true); |
@@ -120,7 +117,6 @@ class GalaxyRS extends RenderScriptScene { | ||
120 | 117 | script.setTimeZone(TimeZone.getDefault().getID()); |
121 | 118 | |
122 | 119 | script.bindAllocation(mState, RSID_STATE); |
123 | - script.bindAllocation(mParticles, RSID_PARTICLES); | |
124 | 120 | script.bindAllocation(mParticlesBuffer, RSID_PARTICLES_BUFFER); |
125 | 121 | mInitParticles.execute(); |
126 | 122 |
@@ -130,14 +126,14 @@ class GalaxyRS extends RenderScriptScene { | ||
130 | 126 | private void createScriptStructures() { |
131 | 127 | createState(); |
132 | 128 | createParticlesMesh(); |
133 | - createParticles(); | |
134 | 129 | } |
135 | 130 | |
136 | 131 | private void createParticlesMesh() { |
137 | 132 | final Builder elementBuilder = new Builder(mRS); |
138 | - elementBuilder.addUNorm8RGBA(""); | |
139 | - elementBuilder.addFloatXYZ(""); | |
140 | - elementBuilder.addFloatPointSize(""); | |
133 | + elementBuilder.add(Element.createAttrib(mRS, Element.DataType.UNSIGNED_8, | |
134 | + Element.DataKind.USER, 4), "color"); | |
135 | + elementBuilder.add(Element.createAttrib(mRS, Element.DataType.FLOAT_32, | |
136 | + Element.DataKind.USER, 3), "position"); | |
141 | 137 | final Element vertexElement = elementBuilder.create(); |
142 | 138 | |
143 | 139 | final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS); |
@@ -167,6 +163,8 @@ class GalaxyRS extends RenderScriptScene { | ||
167 | 163 | mState.data(mGalaxyState); |
168 | 164 | |
169 | 165 | mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight); |
166 | + mPvProjectionAlloc.setupProjectionNormalized(mWidth, mHeight); | |
167 | + | |
170 | 168 | mInitParticles.execute(); |
171 | 169 | } |
172 | 170 |
@@ -180,14 +178,6 @@ class GalaxyRS extends RenderScriptScene { | ||
180 | 178 | public int scale; |
181 | 179 | } |
182 | 180 | |
183 | - static class GalaxyParticle { | |
184 | - public float angle; | |
185 | - public float distance; | |
186 | - public float speed; | |
187 | - public float s; | |
188 | - public float t; | |
189 | - } | |
190 | - | |
191 | 181 | private void createState() { |
192 | 182 | boolean isPreview = isPreview(); |
193 | 183 |
@@ -207,11 +197,6 @@ class GalaxyRS extends RenderScriptScene { | ||
207 | 197 | mState.data(mGalaxyState); |
208 | 198 | } |
209 | 199 | |
210 | - private void createParticles() { | |
211 | - mParticlesType = Type.createFromClass(mRS, GalaxyParticle.class, PARTICLES_COUNT, "Particle"); | |
212 | - mParticles = Allocation.createTyped(mRS, mParticlesType); | |
213 | - } | |
214 | - | |
215 | 200 | private void loadTextures() { |
216 | 201 | mTextures = new Allocation[TEXTURES_COUNT]; |
217 | 202 |
@@ -249,9 +234,9 @@ class GalaxyRS extends RenderScriptScene { | ||
249 | 234 | samplerBuilder.setWrapT(WRAP); |
250 | 235 | mSampler = samplerBuilder.create(); |
251 | 236 | |
252 | - ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null); | |
253 | - builder.setTexEnable(true, 0); | |
254 | - builder.setTexEnvMode(REPLACE, 0); | |
237 | + ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS); | |
238 | + builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, | |
239 | + ProgramFragment.Builder.Format.RGB, 0); | |
255 | 240 | mPfBackground = builder.create(); |
256 | 241 | mPfBackground.setName("PFBackground"); |
257 | 242 | mPfBackground.bindSampler(mSampler, 0); |
@@ -263,10 +248,10 @@ class GalaxyRS extends RenderScriptScene { | ||
263 | 248 | samplerBuilder.setWrapT(WRAP); |
264 | 249 | mStarSampler = samplerBuilder.create(); |
265 | 250 | |
266 | - builder = new ProgramFragment.Builder(mRS, null, null); | |
251 | + builder = new ProgramFragment.Builder(mRS); | |
267 | 252 | builder.setPointSpriteTexCoordinateReplacement(true); |
268 | - builder.setTexEnable(true, 0); | |
269 | - builder.setTexEnvMode(MODULATE, 0); | |
253 | + builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, | |
254 | + ProgramFragment.Builder.Format.RGBA, 0); | |
270 | 255 | mPfStars = builder.create(); |
271 | 256 | mPfStars.setName("PFStars"); |
272 | 257 | mPfBackground.bindSampler(mStarSampler, 0); |
@@ -294,15 +279,40 @@ class GalaxyRS extends RenderScriptScene { | ||
294 | 279 | mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight); |
295 | 280 | |
296 | 281 | ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS, null, null); |
297 | - mPvBackground = builder.create(); | |
298 | - mPvBackground.bindAllocation(mPvOrthoAlloc); | |
299 | - mPvBackground.setName("PVBackground"); | |
282 | + mPvBkOrtho = builder.create(); | |
283 | + mPvBkOrtho.bindAllocation(mPvOrthoAlloc); | |
284 | + mPvBkOrtho.setName("PVBkOrtho"); | |
300 | 285 | |
301 | 286 | mPvProjectionAlloc = new ProgramVertex.MatrixAllocation(mRS); |
302 | 287 | mPvProjectionAlloc.setupProjectionNormalized(mWidth, mHeight); |
303 | 288 | |
304 | 289 | builder = new ProgramVertex.Builder(mRS, null, null); |
305 | - mPvStars = builder.create(); | |
290 | + mPvBkProj = builder.create(); | |
291 | + mPvBkProj.bindAllocation(mPvProjectionAlloc); | |
292 | + mPvBkProj.setName("PVBkProj"); | |
293 | + | |
294 | + ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(mRS); | |
295 | + String t = "void main() {\n" + | |
296 | + " float dist = ATTRIB_position.y;\n" + | |
297 | + " float angle = ATTRIB_position.x;\n" + | |
298 | + " float x = dist * sin(angle);\n" + | |
299 | + " float y = dist * cos(angle) * 0.892;\n" + | |
300 | + " float p = dist * 5.5;\n" + | |
301 | + " float s = cos(p);\n" + | |
302 | + " float t = sin(p);\n" + | |
303 | + " vec4 pos;\n" + | |
304 | + " pos.x = t * x + s * y;\n" + | |
305 | + " pos.y = s * x - t * y;\n" + | |
306 | + " pos.z = ATTRIB_position.z;\n" + | |
307 | + " pos.w = 1.0;\n" + | |
308 | + " gl_Position = UNI_MVP * pos;\n" + | |
309 | + " gl_PointSize = ATTRIB_color.a * 10.0;\n" + | |
310 | + " varColor.rgb = ATTRIB_color.rgb;\n" + | |
311 | + " varColor.a = 1.0;\n" + | |
312 | + "}\n"; | |
313 | + sb.setShader(t); | |
314 | + sb.addInput(mParticlesMesh.getVertexType(0).getElement()); | |
315 | + mPvStars = sb.create(); | |
306 | 316 | mPvStars.bindAllocation(mPvProjectionAlloc); |
307 | 317 | mPvStars.setName("PVStars"); |
308 | 318 | } |
@@ -17,7 +17,6 @@ | ||
17 | 17 | package com.android.wallpaper.grass; |
18 | 18 | |
19 | 19 | import android.renderscript.Sampler; |
20 | -import static android.renderscript.ProgramFragment.EnvMode.*; | |
21 | 20 | import static android.renderscript.ProgramStore.DepthFunc.*; |
22 | 21 | import static android.renderscript.ProgramStore.BlendSrcFunc; |
23 | 22 | import static android.renderscript.ProgramStore.BlendDstFunc; |
@@ -53,7 +52,7 @@ class GrassRS extends RenderScriptScene { | ||
53 | 52 | @SuppressWarnings({"UnusedDeclaration"}) |
54 | 53 | private static final String LOG_TAG = "Grass"; |
55 | 54 | private static final boolean DEBUG = false; |
56 | - | |
55 | + | |
57 | 56 | private static final int LOCATION_UPDATE_MIN_TIME = DEBUG ? 5 * 60 * 1000 : 60 * 60 * 1000; // 1 hour |
58 | 57 | private static final int LOCATION_UPDATE_MIN_DISTANCE = DEBUG ? 10 : 150 * 1000; // 150 km |
59 | 58 |
@@ -63,32 +62,35 @@ class GrassRS extends RenderScriptScene { | ||
63 | 62 | private static final int RSID_STATE = 0; |
64 | 63 | private static final int RSID_BLADES = 1; |
65 | 64 | private static final int BLADES_COUNT = 200; |
66 | - private static final int BLADE_STRUCT_FIELDS_COUNT = 13; | |
67 | - private static final int BLADE_STRUCT_ANGLE = 0; | |
68 | - private static final int BLADE_STRUCT_SIZE = 1; | |
69 | - private static final int BLADE_STRUCT_XPOS = 2; | |
70 | - private static final int BLADE_STRUCT_YPOS = 3; | |
71 | - private static final int BLADE_STRUCT_OFFSET = 4; | |
72 | - private static final int BLADE_STRUCT_SCALE = 5; | |
73 | - private static final int BLADE_STRUCT_LENGTHX = 6; | |
74 | - private static final int BLADE_STRUCT_LENGTHY = 7; | |
75 | - private static final int BLADE_STRUCT_HARDNESS = 8; | |
76 | - private static final int BLADE_STRUCT_H = 9; | |
77 | - private static final int BLADE_STRUCT_S = 10; | |
78 | - private static final int BLADE_STRUCT_B = 11; | |
79 | - private static final int BLADE_STRUCT_TURBULENCEX = 12; | |
65 | + | |
66 | + class BladesStruct { | |
67 | + public float angle; | |
68 | + public int size; | |
69 | + public float xPos; | |
70 | + public float yPos; | |
71 | + public float offset; | |
72 | + public float scale; | |
73 | + public float lengthX; | |
74 | + public float lengthY; | |
75 | + public float hardness; | |
76 | + public float h; | |
77 | + public float s; | |
78 | + public float b; | |
79 | + public float turbulencex; | |
80 | + }; | |
80 | 81 | |
81 | 82 | private static final int RSID_BLADES_BUFFER = 2; |
82 | 83 | |
84 | + private ScriptC.Invokable mUpdateBladesInvokable; | |
83 | 85 | @SuppressWarnings({ "FieldCanBeLocal" }) |
84 | 86 | private ProgramFragment mPfBackground; |
85 | 87 | @SuppressWarnings({ "FieldCanBeLocal" }) |
88 | + private ProgramFragment mPfGrass; | |
89 | + @SuppressWarnings({ "FieldCanBeLocal" }) | |
86 | 90 | private ProgramStore mPfsBackground; |
87 | 91 | @SuppressWarnings({ "FieldCanBeLocal" }) |
88 | 92 | private ProgramVertex mPvBackground; |
89 | 93 | @SuppressWarnings({"FieldCanBeLocal"}) |
90 | - private Sampler mSampler; | |
91 | - @SuppressWarnings({"FieldCanBeLocal"}) | |
92 | 94 | private ProgramVertex.MatrixAllocation mPvOrthoAlloc; |
93 | 95 | |
94 | 96 | @SuppressWarnings({ "FieldCanBeLocal" }) |
@@ -97,13 +99,17 @@ class GrassRS extends RenderScriptScene { | ||
97 | 99 | private Type mStateType; |
98 | 100 | private Allocation mState; |
99 | 101 | |
102 | + private Type mBladesType; | |
100 | 103 | private Allocation mBlades; |
101 | 104 | private Allocation mBladesBuffer; |
105 | + private Allocation mBladesIndicies; | |
102 | 106 | @SuppressWarnings({"FieldCanBeLocal"}) |
103 | 107 | private SimpleMesh mBladesMesh; |
104 | 108 | |
105 | - private int mTriangles; | |
106 | - private float[] mBladesData; | |
109 | + | |
110 | + private int mVerticies; | |
111 | + private int mIndicies; | |
112 | + private int[] mBladeSizes; | |
107 | 113 | private final float[] mFloatData5 = new float[5]; |
108 | 114 | |
109 | 115 | private WorldState mWorldState; |
@@ -132,7 +138,7 @@ class GrassRS extends RenderScriptScene { | ||
132 | 138 | filter.addAction(Intent.ACTION_DATE_CHANGED); |
133 | 139 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
134 | 140 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
135 | - | |
141 | + | |
136 | 142 | mContext.registerReceiver(mTimezoneTracker, filter); |
137 | 143 | } |
138 | 144 |
@@ -153,7 +159,7 @@ class GrassRS extends RenderScriptScene { | ||
153 | 159 | mContext.unregisterReceiver(mTimezoneTracker); |
154 | 160 | mTimezoneTracker = null; |
155 | 161 | } |
156 | - | |
162 | + | |
157 | 163 | if (mLocationUpdater != null) { |
158 | 164 | mLocationManager.removeUpdates(mLocationUpdater); |
159 | 165 | mLocationUpdater = null; |
@@ -168,27 +174,24 @@ class GrassRS extends RenderScriptScene { | ||
168 | 174 | mWorldState.height = height; |
169 | 175 | mState.data(mWorldState); |
170 | 176 | |
171 | - final float[] blades = mBladesData; | |
172 | - for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) { | |
173 | - updateBlade(blades, i); | |
174 | - } | |
175 | - mBlades.data(blades); | |
176 | - | |
177 | - mPvOrthoAlloc.setupOrthoWindow(width, height); | |
177 | + mUpdateBladesInvokable.execute(); | |
178 | + mPvOrthoAlloc.setupOrthoWindow(width, height); | |
178 | 179 | } |
179 | 180 | |
180 | 181 | @Override |
181 | 182 | protected ScriptC createScript() { |
182 | 183 | createProgramVertex(); |
183 | 184 | createProgramFragmentStore(); |
185 | + loadTextures(); | |
184 | 186 | createProgramFragment(); |
185 | 187 | createScriptStructures(); |
186 | - loadTextures(); | |
187 | 188 | |
188 | 189 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
189 | 190 | sb.setType(mStateType, "State", RSID_STATE); |
191 | + sb.setType(mBladesType, "Blades", RSID_BLADES); | |
190 | 192 | sb.setScript(mResources, R.raw.grass); |
191 | 193 | sb.setRoot(true); |
194 | + mUpdateBladesInvokable = sb.addInvokable("updateBlades"); | |
192 | 195 | |
193 | 196 | ScriptC script = sb.create(); |
194 | 197 | script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
@@ -214,7 +217,7 @@ class GrassRS extends RenderScriptScene { | ||
214 | 217 | |
215 | 218 | static class WorldState { |
216 | 219 | public int bladesCount; |
217 | - public int trianglesCount; | |
220 | + public int indexCount; | |
218 | 221 | public int width; |
219 | 222 | public int height; |
220 | 223 | public float xOffset; |
@@ -232,7 +235,7 @@ class GrassRS extends RenderScriptScene { | ||
232 | 235 | mWorldState.width = mWidth; |
233 | 236 | mWorldState.height = mHeight; |
234 | 237 | mWorldState.bladesCount = BLADES_COUNT; |
235 | - mWorldState.trianglesCount = mTriangles; | |
238 | + mWorldState.indexCount = mIndicies; | |
236 | 239 | mWorldState.isPreview = isPreview ? 1 : 0; |
237 | 240 | if (isPreview) { |
238 | 241 | mWorldState.xOffset = 0.5f; |
@@ -244,32 +247,35 @@ class GrassRS extends RenderScriptScene { | ||
244 | 247 | } |
245 | 248 | |
246 | 249 | private void createBlades() { |
247 | - int triangles = 0; | |
248 | - | |
249 | - mBladesData = new float[BLADES_COUNT * BLADE_STRUCT_FIELDS_COUNT]; | |
250 | - | |
251 | - final float[] blades = mBladesData; | |
252 | - for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) { | |
253 | - triangles += createBlade(blades, i); | |
250 | + mVerticies = 0; | |
251 | + mIndicies = 0; | |
252 | + | |
253 | + mBladesType = Type.createFromClass(mRS, BladesStruct.class, BLADES_COUNT, "Blade"); | |
254 | + mBlades = Allocation.createTyped(mRS, mBladesType); | |
255 | + BladesStruct bs = new BladesStruct(); | |
256 | + | |
257 | + mBladeSizes = new int[BLADES_COUNT]; | |
258 | + for (int i = 0; i < BLADES_COUNT; i++) { | |
259 | + createBlade(bs); | |
260 | + mIndicies += bs.size * 2 * 3; | |
261 | + mVerticies += bs.size + 2; | |
262 | + mBlades.subData(i, bs); | |
263 | + mBladeSizes[i] = bs.size; | |
254 | 264 | } |
255 | 265 | |
256 | - mBlades = Allocation.createSized(mRS, USER_F32(mRS), blades.length); | |
257 | - mBlades.data(blades); | |
258 | - | |
259 | - mTriangles = triangles; | |
260 | - | |
261 | - createMesh(triangles); | |
266 | + createMesh(); | |
262 | 267 | } |
263 | 268 | |
264 | - private void createMesh(int triangles) { | |
269 | + private void createMesh() { | |
265 | 270 | Builder elementBuilder = new Builder(mRS); |
266 | - elementBuilder.addUNorm8RGBA(); | |
267 | - elementBuilder.addFloatXY(); | |
268 | - elementBuilder.addFloatST(); | |
271 | + elementBuilder.add(Element.ATTRIB_COLOR_U8_4(mRS), "color"); | |
272 | + elementBuilder.add(Element.ATTRIB_POSITION_2(mRS), "position"); | |
273 | + elementBuilder.add(Element.ATTRIB_TEXTURE_2(mRS), "texture"); | |
269 | 274 | final Element vertexElement = elementBuilder.create(); |
270 | 275 | |
271 | 276 | final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS); |
272 | - final int vertexSlot = meshBuilder.addVertexType(vertexElement, triangles * 3); | |
277 | + final int vertexSlot = meshBuilder.addVertexType(vertexElement, mVerticies * 2); | |
278 | + meshBuilder.setIndexType(Element.INDEX_16(mRS), mIndicies); | |
273 | 279 | meshBuilder.setPrimitive(Primitive.TRIANGLE); |
274 | 280 | mBladesMesh = meshBuilder.create(); |
275 | 281 | mBladesMesh.setName("BladesMesh"); |
@@ -277,74 +283,65 @@ class GrassRS extends RenderScriptScene { | ||
277 | 283 | mBladesBuffer = mBladesMesh.createVertexAllocation(vertexSlot); |
278 | 284 | mBladesBuffer.setName("BladesBuffer"); |
279 | 285 | mBladesMesh.bindVertexAllocation(mBladesBuffer, 0); |
286 | + mBladesIndicies = mBladesMesh.createIndexAllocation(); | |
287 | + mBladesMesh.bindIndexAllocation(mBladesIndicies); | |
280 | 288 | |
281 | 289 | // Assign the texture coordinates of each triangle |
282 | 290 | final float[] floatData = mFloatData5; |
283 | 291 | final Allocation buffer = mBladesBuffer; |
284 | 292 | |
285 | - int bufferIndex = 0; | |
286 | - for (int i = 0; i < triangles; i += 2) { | |
287 | - floatData[3] = 0.0f; | |
288 | - floatData[4] = 1.0f; | |
289 | - buffer.subData1D(bufferIndex, 1, floatData); | |
290 | - bufferIndex++; | |
293 | + short[] idx = new short[mIndicies]; | |
291 | 294 | |
295 | + int bufferIndex = 0; | |
296 | + int i2 = 0; | |
297 | + for (int i = 0; i < mVerticies; i +=2) { | |
292 | 298 | floatData[3] = 0.0f; |
293 | 299 | floatData[4] = 0.0f; |
294 | - buffer.subData1D(bufferIndex, 1, floatData); | |
295 | - bufferIndex++; | |
300 | + buffer.subData1D(bufferIndex++, 1, floatData); | |
296 | 301 | |
297 | 302 | floatData[3] = 1.0f; |
298 | 303 | floatData[4] = 0.0f; |
299 | - buffer.subData1D(bufferIndex, 1, floatData); | |
300 | - bufferIndex++; | |
301 | - | |
302 | - floatData[3] = 0.0f; | |
303 | - floatData[4] = 0.0f; | |
304 | - buffer.subData1D(bufferIndex, 1, floatData); | |
305 | - bufferIndex++; | |
306 | - | |
307 | - floatData[3] = 1.0f; | |
308 | - floatData[4] = 1.0f; | |
309 | - buffer.subData1D(bufferIndex, 1, floatData); | |
310 | - bufferIndex++; | |
304 | + buffer.subData1D(bufferIndex++, 1, floatData); | |
305 | + } | |
311 | 306 | |
312 | - floatData[3] = 1.0f; | |
313 | - floatData[4] = 0.0f; | |
314 | - buffer.subData1D(bufferIndex, 1, floatData); | |
315 | - bufferIndex++; | |
307 | + int idxIdx = 0; | |
308 | + int vtxIdx = 0; | |
309 | + for (int i = 0; i < mBladeSizes.length; i++) { | |
310 | + for (int ct = 0; ct < mBladeSizes[i]; ct ++) { | |
311 | + idx[idxIdx + 0] = (short)(vtxIdx + 0); | |
312 | + idx[idxIdx + 1] = (short)(vtxIdx + 1); | |
313 | + idx[idxIdx + 2] = (short)(vtxIdx + 2); | |
314 | + idx[idxIdx + 3] = (short)(vtxIdx + 1); | |
315 | + idx[idxIdx + 4] = (short)(vtxIdx + 3); | |
316 | + idx[idxIdx + 5] = (short)(vtxIdx + 2); | |
317 | + idxIdx += 6; | |
318 | + vtxIdx += 2; | |
319 | + } | |
320 | + vtxIdx += 2; | |
316 | 321 | } |
317 | - } | |
318 | 322 | |
319 | - private void updateBlade(float[] blades, int index) { | |
320 | - final int xpos = random(-mWidth, mWidth); | |
321 | - blades[index + BLADE_STRUCT_XPOS] = xpos; | |
322 | - blades[index + BLADE_STRUCT_TURBULENCEX] = xpos * 0.006f; | |
323 | - blades[index + BLADE_STRUCT_YPOS] = mHeight; | |
323 | + mBladesIndicies.data(idx); | |
324 | + mBladesIndicies.uploadToBufferObject(); | |
324 | 325 | } |
325 | 326 | |
326 | - private int createBlade(float[] blades, int index) { | |
327 | + private void createBlade(BladesStruct blades) { | |
327 | 328 | final float size = random(4.0f) + 4.0f; |
328 | 329 | final int xpos = random(-mWidth, mWidth); |
329 | 330 | |
330 | 331 | //noinspection PointlessArithmeticExpression |
331 | - blades[index + BLADE_STRUCT_ANGLE] = 0.0f; | |
332 | - blades[index + BLADE_STRUCT_SIZE] = size / TESSELATION; | |
333 | - blades[index + BLADE_STRUCT_XPOS] = xpos; | |
334 | - blades[index + BLADE_STRUCT_YPOS] = mHeight; | |
335 | - blades[index + BLADE_STRUCT_OFFSET] = random(0.2f) - 0.1f; | |
336 | - blades[index + BLADE_STRUCT_SCALE] = 4.0f / (size / TESSELATION) + | |
337 | - (random(0.6f) + 0.2f) * TESSELATION; | |
338 | - blades[index + BLADE_STRUCT_LENGTHX] = (random(4.5f) + 3.0f) * TESSELATION * size; | |
339 | - blades[index + BLADE_STRUCT_LENGTHY] = (random(5.5f) + 2.0f) * TESSELATION * size; | |
340 | - blades[index + BLADE_STRUCT_HARDNESS] = (random(1.0f) + 0.2f) * TESSELATION; | |
341 | - blades[index + BLADE_STRUCT_H] = random(0.02f) + 0.2f; | |
342 | - blades[index + BLADE_STRUCT_S] = random(0.22f) + 0.78f; | |
343 | - blades[index + BLADE_STRUCT_B] = random(0.65f) + 0.35f; | |
344 | - blades[index + BLADE_STRUCT_TURBULENCEX] = xpos * 0.006f; | |
345 | - | |
346 | - // Each blade is made of "size" quads, so we double to count the triangles | |
347 | - return (int) (blades[index + BLADE_STRUCT_SIZE]) * 2; | |
332 | + blades.angle = 0.0f; | |
333 | + blades.size = (int)(size / TESSELATION); | |
334 | + blades.xPos = xpos; | |
335 | + blades.yPos = mHeight; | |
336 | + blades.offset = random(0.2f) - 0.1f; | |
337 | + blades.scale = 4.0f / (size / TESSELATION) + (random(0.6f) + 0.2f) * TESSELATION; | |
338 | + blades.lengthX = (random(4.5f) + 3.0f) * TESSELATION * size; | |
339 | + blades.lengthY = (random(5.5f) + 2.0f) * TESSELATION * size; | |
340 | + blades.hardness = (random(1.0f) + 0.2f) * TESSELATION; | |
341 | + blades.h = random(0.02f) + 0.2f; | |
342 | + blades.s = random(0.22f) + 0.78f; | |
343 | + blades.b = random(0.65f) + 0.35f; | |
344 | + blades.turbulencex = xpos * 0.006f; | |
348 | 345 | } |
349 | 346 | |
350 | 347 | private void loadTextures() { |
@@ -367,10 +364,21 @@ class GrassRS extends RenderScriptScene { | ||
367 | 364 | final Type.Builder builder = new Type.Builder(mRS, A_8(mRS)); |
368 | 365 | builder.add(Dimension.X, width); |
369 | 366 | builder.add(Dimension.Y, height); |
367 | + builder.add(Dimension.LOD, 1); | |
370 | 368 | |
371 | 369 | final Allocation allocation = Allocation.createTyped(mRS, builder.create()); |
372 | - allocation.data(data); | |
373 | 370 | allocation.setName(name); |
371 | + | |
372 | + int[] grey1 = new int[] {0x3f3f3f3f}; | |
373 | + int[] grey2 = new int[] {0x00000000}; | |
374 | + Allocation.Adapter2D a = allocation.createAdapter2D(); | |
375 | + a.setConstraint(Dimension.LOD, 0); | |
376 | + a.subData(0, 0, 4, 1, data); | |
377 | + a.setConstraint(Dimension.LOD, 1); | |
378 | + a.subData(0, 0, 2, 1, grey1); | |
379 | + a.setConstraint(Dimension.LOD, 2); | |
380 | + a.subData(0, 0, 1, 1, grey2); | |
381 | + | |
374 | 382 | return allocation; |
375 | 383 | } |
376 | 384 |
@@ -383,18 +391,29 @@ class GrassRS extends RenderScriptScene { | ||
383 | 391 | |
384 | 392 | private void createProgramFragment() { |
385 | 393 | Sampler.Builder samplerBuilder = new Sampler.Builder(mRS); |
386 | - samplerBuilder.setMin(LINEAR); | |
394 | + samplerBuilder.setMin(LINEAR_MIP_LINEAR); | |
387 | 395 | samplerBuilder.setMag(LINEAR); |
388 | 396 | samplerBuilder.setWrapS(WRAP); |
389 | 397 | samplerBuilder.setWrapT(WRAP); |
390 | - mSampler = samplerBuilder.create(); | |
391 | - | |
392 | - ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null); | |
393 | - builder.setTexEnable(true, 0); | |
394 | - builder.setTexEnvMode(REPLACE, 0); | |
398 | + Sampler sl = samplerBuilder.create(); | |
399 | + | |
400 | + samplerBuilder.setMin(NEAREST); | |
401 | + samplerBuilder.setMag(NEAREST); | |
402 | + Sampler sn = samplerBuilder.create(); | |
403 | + | |
404 | + ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS); | |
405 | + builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, | |
406 | + ProgramFragment.Builder.Format.ALPHA, 0); | |
407 | + mPfGrass = builder.create(); | |
408 | + mPfGrass.setName("PFGrass"); | |
409 | + mPfGrass.bindSampler(sl, 0); | |
410 | + | |
411 | + builder = new ProgramFragment.Builder(mRS); | |
412 | + builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, | |
413 | + ProgramFragment.Builder.Format.RGB, 0); | |
395 | 414 | mPfBackground = builder.create(); |
396 | 415 | mPfBackground.setName("PFBackground"); |
397 | - mPfBackground.bindSampler(mSampler, 0); | |
416 | + mPfBackground.bindSampler(sn, 0); | |
398 | 417 | } |
399 | 418 | |
400 | 419 | private void createProgramFragmentStore() { |
@@ -412,7 +431,6 @@ class GrassRS extends RenderScriptScene { | ||
412 | 431 | mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight); |
413 | 432 | |
414 | 433 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
415 | - pvb.setTextureMatrixEnable(true); | |
416 | 434 | mPvBackground = pvb.create(); |
417 | 435 | mPvBackground.bindAllocation(mPvOrthoAlloc); |
418 | 436 | mPvBackground.setName("PVBackground"); |
@@ -18,15 +18,15 @@ package com.android.wallpaper.nexus; | ||
18 | 18 | |
19 | 19 | import static android.renderscript.Element.RGBA_8888; |
20 | 20 | import static android.renderscript.Element.RGB_565; |
21 | -import static android.renderscript.ProgramFragment.EnvMode.MODULATE; | |
22 | -import static android.renderscript.ProgramFragment.EnvMode.REPLACE; | |
23 | 21 | import static android.renderscript.ProgramStore.DepthFunc.ALWAYS; |
24 | 22 | import static android.renderscript.Sampler.Value.LINEAR; |
23 | +import static android.renderscript.Sampler.Value.CLAMP; | |
25 | 24 | import static android.renderscript.Sampler.Value.WRAP; |
26 | 25 | |
27 | 26 | import com.android.wallpaper.R; |
28 | 27 | import com.android.wallpaper.RenderScriptScene; |
29 | 28 | |
29 | +import android.content.res.Resources; | |
30 | 30 | import android.graphics.Bitmap; |
31 | 31 | import android.graphics.BitmapFactory; |
32 | 32 | import android.graphics.Rect; |
@@ -56,6 +56,7 @@ class NexusRS extends RenderScriptScene { | ||
56 | 56 | private final BitmapFactory.Options mOptionsARGB = new BitmapFactory.Options(); |
57 | 57 | |
58 | 58 | private ProgramFragment mPfTexture; |
59 | + private ProgramFragment mPfTexture565; | |
59 | 60 | |
60 | 61 | private ProgramFragment mPfColor; |
61 | 62 |
@@ -67,7 +68,8 @@ class NexusRS extends RenderScriptScene { | ||
67 | 68 | |
68 | 69 | private ProgramVertex.MatrixAllocation mPvOrthoAlloc; |
69 | 70 | |
70 | - private Sampler mSampler; | |
71 | + private Sampler mClampSampler; | |
72 | + private Sampler mWrapSampler; | |
71 | 73 | |
72 | 74 | private Allocation mState; |
73 | 75 |
@@ -148,6 +150,7 @@ class NexusRS extends RenderScriptScene { | ||
148 | 150 | public int rotate; |
149 | 151 | public int isPreview; |
150 | 152 | public float xOffset; |
153 | + public int mode; | |
151 | 154 | } |
152 | 155 | |
153 | 156 | static class CommandState { |
@@ -163,6 +166,12 @@ class NexusRS extends RenderScriptScene { | ||
163 | 166 | mWorldState.rotate = mWidth > mHeight ? 1 : 0; |
164 | 167 | mWorldState.isPreview = isPreview() ? 1 : 0; |
165 | 168 | |
169 | + try { | |
170 | + mWorldState.mode = mResources.getInteger(R.integer.nexus_mode); | |
171 | + } catch (Resources.NotFoundException exc) { | |
172 | + mWorldState.mode = 0; // standard nexus mode | |
173 | + } | |
174 | + | |
166 | 175 | mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState"); |
167 | 176 | mState = Allocation.createTyped(mRS, mStateType); |
168 | 177 | mState.data(mWorldState); |
@@ -203,26 +212,37 @@ class NexusRS extends RenderScriptScene { | ||
203 | 212 | } |
204 | 213 | |
205 | 214 | private void createProgramFragment() { |
215 | + // sampler and program fragment for pulses | |
206 | 216 | Sampler.Builder sampleBuilder = new Sampler.Builder(mRS); |
207 | 217 | sampleBuilder.setMin(LINEAR); |
208 | 218 | sampleBuilder.setMag(LINEAR); |
209 | 219 | sampleBuilder.setWrapS(WRAP); |
210 | 220 | sampleBuilder.setWrapT(WRAP); |
211 | - mSampler = sampleBuilder.create(); | |
212 | - | |
213 | - ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null); | |
214 | - builder.setTexEnable(true, 0); | |
215 | - builder.setTexEnvMode(MODULATE, 0); | |
221 | + mWrapSampler = sampleBuilder.create(); | |
222 | + ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS); | |
223 | + builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, | |
224 | + ProgramFragment.Builder.Format.RGBA, 0); | |
216 | 225 | mPfTexture = builder.create(); |
217 | 226 | mPfTexture.setName("PFTexture"); |
218 | - mPfTexture.bindSampler(mSampler, 0); | |
227 | + mPfTexture.bindSampler(mWrapSampler, 0); | |
219 | 228 | |
220 | - builder = new ProgramFragment.Builder(mRS, null, null); | |
221 | - builder.setTexEnable(true, 0); | |
222 | - builder.setTexEnvMode(REPLACE, 0); | |
229 | + builder = new ProgramFragment.Builder(mRS); | |
230 | + builder.setTexture(ProgramFragment.Builder.EnvMode.REPLACE, | |
231 | + ProgramFragment.Builder.Format.RGB, 0); | |
223 | 232 | mPfColor = builder.create(); |
224 | 233 | mPfColor.setName("PFColor"); |
225 | - mPfColor.bindSampler(mSampler, 0); | |
234 | + mPfColor.bindSampler(mWrapSampler, 0); | |
235 | + | |
236 | + // sampler and program fragment for background image | |
237 | + sampleBuilder.setWrapS(CLAMP); | |
238 | + sampleBuilder.setWrapT(CLAMP); | |
239 | + mClampSampler = sampleBuilder.create(); | |
240 | + builder = new ProgramFragment.Builder(mRS); | |
241 | + builder.setTexture(ProgramFragment.Builder.EnvMode.MODULATE, | |
242 | + ProgramFragment.Builder.Format.RGB, 0); | |
243 | + mPfTexture565 = builder.create(); | |
244 | + mPfTexture565.setName("PFTexture565"); | |
245 | + mPfTexture565.bindSampler(mClampSampler, 0); | |
226 | 246 | } |
227 | 247 | |
228 | 248 | private void createProgramFragmentStore() { |
@@ -278,4 +298,4 @@ class NexusRS extends RenderScriptScene { | ||
278 | 298 | mCommand.command = command; |
279 | 299 | mCommandAllocation.data(mCommand); |
280 | 300 | } |
281 | -} | |
\ No newline at end of file | ||
301 | +} |