summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2015-03-02 14:08:24 -0800
committerJohn Hoford <hoford@google.com>2015-03-05 13:25:46 -0800
commit5ee349cd7a75079b6bac1d8ace66455ecd1afb17 (patch)
tree236c360d7d3a0a6c0d2b8ca470f5860dec879eb6 /java
parenta1f7816a57fb2f8538b52da87c401facc8238250 (diff)
downloadrs-5ee349cd7a75079b6bac1d8ace66455ecd1afb17.tar.gz
added programaticly generated android volume model
Change-Id: Ib345fded966db1db93a519f890a0e949c3b871d1
Diffstat (limited to 'java')
-rw-r--r--java/tests/VrDemo/AndroidManifest.xml2
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/VrActivity.java13
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/engine/bricked.rs56
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/engine/bugdroid.rs225
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/engine/mandelbulb.rs80
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/engine/vr.rs2
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Droid.java96
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Mandelbulb.java34
-rw-r--r--java/tests/VrDemo/src/com/example/android/rs/vr/loaders/VolumeLoader.java5
9 files changed, 440 insertions, 73 deletions
diff --git a/java/tests/VrDemo/AndroidManifest.xml b/java/tests/VrDemo/AndroidManifest.xml
index 9f5930ce..d41986f0 100644
--- a/java/tests/VrDemo/AndroidManifest.xml
+++ b/java/tests/VrDemo/AndroidManifest.xml
@@ -22,7 +22,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
- android:theme="@style/AppTheme" >
+ android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen" >
<activity
android:name="com.example.android.rs.vr.VrActivity"
android:label="@string/app_name" >
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/VrActivity.java b/java/tests/VrDemo/src/com/example/android/rs/vr/VrActivity.java
index 4fe8f8e2..fa5347f6 100644
--- a/java/tests/VrDemo/src/com/example/android/rs/vr/VrActivity.java
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/VrActivity.java
@@ -38,6 +38,8 @@ import rsexample.google.com.vrdemo.R;
import com.example.android.rs.vr.engine.Volume;
import com.example.android.rs.vr.engine.VrState;
+import com.example.android.rs.vr.loaders.Droid;
+import com.example.android.rs.vr.loaders.Mandelbulb;
import com.example.android.rs.vr.loaders.VolumeLoader;
/**
@@ -69,11 +71,11 @@ public class VrActivity extends Activity {
class VrSetupTask extends AsyncTask<String, Integer, Volume> {
ProgressDialog progressDialog;
-
+ String message;
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(VrActivity.this);
- progressDialog.setMessage( "Loading Volume");
+ progressDialog.setMessage(message= "Loading Volume");
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setProgress(0);
@@ -90,12 +92,17 @@ public class VrActivity extends Activity {
@Override
protected Volume doInBackground(String... names) {
+ if (names[0].equals(Droid.NAME) || names[0].equals(Mandelbulb.NAME)) {
+ message = "Computing "+names[0]+": ";
+ } else {
+ message =" Loading " + names[0]+": ";
+ }
return mLoader.getVolume(mRs, names[0]);
}
@Override
protected void onProgressUpdate(Integer... progress) {
- progressDialog.setMessage("load "+progress[0]+"/"+progress[1]);
+ progressDialog.setMessage(message+progress[0]+"/"+progress[1]);
progressDialog.setMax(progress[1]);
progressDialog.setProgress(progress[0]);
Log.v(LOGTAG,"Loading "+ progress[0]+"/"+progress[1]);
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bricked.rs b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bricked.rs
index 808722c3..cf5bd91c 100644
--- a/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bricked.rs
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bricked.rs
@@ -148,59 +148,3 @@ int z;
void __attribute__((kernel)) copy(short in, uint32_t x, uint32_t y) {
rsSetElementAt_short(volume, in, x, y, z);
}
-
-int size;
-
-static float3 nylander(float3 p, int n) {
- float3 out;
- float r = length(p);
- float phi = atan2(p.y, p.x);
- float theta = acos(p.z / r);
- float rn = pow(r, n);
- out.x = sin(n * theta) * cos(n * phi);
- out.y = sin(n * theta) * sin(n * phi);
- out.z = cos(n * theta);
- return out * rn;
-}
-
-/**
-* 8 x faster than the above for n = 3
-*/
-static float3 nylander3(float3 p) {
- float3 out = (float3){0.f, 0.f, 0.f};
- float xy2 = p.x * p.x + p.y * p.y;
- if (xy2 == 0) return out;
- float z23x2y2 = (3 * p.z * p.z - p.x * p.x - p.y * p.y);
- out.x = (z23x2y2 * p.x * (p.x * p.x - 3 * p.y * p.y)) / xy2;
- out.y = (z23x2y2 * p.y * (3 * p.x * p.x - p.y * p.y)) / xy2;
- out.z = p.z * (p.z * p.z - 3 * p.x * p.x - 3 * p.y * p.y);
- return out;
-}
-
-static float vsize(float3 p) {
- return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
-}
-
-short __attribute__((kernel)) mandelbulb(uint32_t x, uint32_t y) {
- int size2 = size / 2;
- if (z < size2) {
- return 256-4*(size2-z+4)*hypot((float)x-size2,(float)y-size2) / size2 ;
- }
- float3 c = (float3) {(float) x, (float) y, (float) z};
- c = ((c - size2) / (size2 * .9f));
-
- int loop = 25;
- float3 p = c;
- float len;
- for (int i = 0; i < loop; i++) {
- // p = nylander(p, 3) + c;
- p = nylander3(p) + c;
- len = fast_length(p);
- if (len > 2.f) return 255 - loop*10;
- if (len < .3f) return loop*10;
-
- }
- len = length(p);
- return (short) (255 - (len * 255) / 4);
-}
-
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bugdroid.rs b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bugdroid.rs
new file mode 100644
index 00000000..4cdfc121
--- /dev/null
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/bugdroid.rs
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.example.android.rs.vr.engine)
+#pragma rs_fp_relaxed
+
+int size;
+int z;
+rs_allocation volume;
+
+static float sigmoid(float f) {
+ return (float) (1 / (1 + exp(f / 2)));
+}
+
+static float pillDistance(float3 p1, float3 p2, float3 img) {
+
+ if (dot(p2 - p1, img - p1) > 0 && dot(p1 - p2, img - p2) > 0) {
+ return length(cross(img - p1, img - p2)) / length(p2 - p1);
+ }
+ return min(distance(p1, img), distance(p2, img));
+}
+
+static short pill(float3 p1, float3 p2, float rad, short max, float3 img) {
+ return (short) (max * sigmoid(pillDistance(p1, p2, img) - rad));
+}
+
+static short cogPill(float3 p1, float3 p2, float rad, short max, float3 img) {
+ float3 vec = (p1 + p2) / 2 - img;
+ float angle = fabs(2 * fract(atan2pi(vec.z, vec.y) * 5) - 1);
+ return (short) (max
+ * sigmoid(pillDistance(p1, p2, img) - rad * (1 + angle / 2)));
+}
+
+static float cylinderDistance(float3 p1, float3 p2, float3 img) {
+ float dot1 = dot(p2 - p1, img - p1);
+ float dot2 = dot(p1 - p2, img - p2);
+ if (dot1 > 0 && dot2 > 0) {
+ return length(cross(img - p1, img - p2)) / length(p2 - p1);
+ }
+ return -dot1 * dot2;
+}
+
+static short cylinder(float3 p1, float3 p2, float rad, short max, float3 img) {
+ return (short) (max * sigmoid(cylinderDistance(p1, p2, img) - rad));
+}
+
+static short cogCylinder(float3 p1, float3 p2, float rad, short max, float3 img) {
+ float3 vec = (p1 + p2) / 2 - img;
+ float angle = fabs(2 * fract(atan2pi(vec.y, vec.x) * 6) - 1);
+ return (short) (max
+ * sigmoid(cylinderDistance(p1, p2, img) - rad * (1 + angle / 5)));
+}
+
+static float distanceCircle(float3 center, float radius, float3 normal,
+ float3 img) {
+ float3 pc = img - center;
+ float tmp1 = dot(normal, pc);
+ tmp1 = tmp1 * tmp1;
+ float tmp2 = (sqrt(length(pc) * length(pc) - tmp1) - radius);
+ return tmp1 + tmp2 * tmp2;
+}
+
+static short circle(float3 center, float circleRadius, float3 normal, float rad,
+ short max, float3 img) {
+ return (short) (max
+ * sigmoid(distanceCircle(center, circleRadius, normal, img) - rad));
+}
+
+static float distanceDisk(float3 center, float radius, float3 normal,
+ float3 img) {
+ float3 pc = img - center;
+ float tmp1 = dot(normal, pc);
+ tmp1 = tmp1 * tmp1;
+ float tmp2 = (sqrt(length(pc) * length(pc) - tmp1) - radius);
+ if (length(pc - dot(normal, pc) * normal) > radius) {
+ return (tmp1 + tmp2 * tmp2);
+ }
+ return tmp1;
+}
+
+static short disk(float3 center, float circleRadius, float3 normal, float rad,
+ short max, float3 img) {
+ return (short) (max
+ * sigmoid(distanceDisk(center, circleRadius, normal, img) - rad));
+}
+
+static short cogDisk(float3 center, float circleRadius, float3 normal,
+ float rad, short max, float3 img) {
+ float3 vec = center - img;
+ float angle = fabs(2 * fract(atan2pi(vec.y, vec.x) * 20) - 1);
+ return (short) (max
+ * sigmoid(
+ distanceDisk(center, circleRadius * (1 + angle / 10),
+ normal, img) - rad));
+}
+
+static float andyBody(float3 img) {
+ short v = 0;
+ { // body
+ float3 p1 = { size * 0.5f, size * 0.5f, size * 0.3f };
+ float3 p2 = { size * 0.5f, size * 0.5f, size * 0.65f };
+ float radius = size * 0.22f;
+ v = max(v, cylinder(p1, p2, radius, 144, img));
+ p2.z = size * 0.4f;
+ v = max(v, pill(p1, p2, radius, 144, img));
+ float3 normal = { 0.0f, 0.0f, 1.0f };
+ v -= circle(p1, radius*0.9f, normal, size * 0.05, 144, img);
+ }
+ float armOffset = 0.27f;
+ { // arm 1
+ float3 p1 = { size * (0.5f - armOffset), size * 0.5f, size * 0.4f };
+ float3 p2 = { size * (0.5f - armOffset), size * 0.5f, size * 0.57f };
+ v = max(v, pill(p1, p2, size * 0.09f, 144, img));
+ }
+ { // arm 2
+ float3 p1 = { size * (0.5f + armOffset), size * 0.5f, size * 0.4f };
+ float3 p2 = { size * (0.5f + armOffset), size * 0.5f, size * 0.57f };
+ v = max(v, pill(p1, p2, size * 0.09f, 144, img));
+ }
+ { // leg 1
+ float3 p1 = { size * 0.6f, size * 0.5f, size * 0.6f };
+ float3 p2 = { size * 0.6f, size * 0.5f, size * 0.8f };
+ v = max(v, pill(p1, p2, size * 0.08f, 144, img));
+ }
+ { // leg 2
+ float3 p1 = { size * 0.4f, size * 0.5f, size * 0.6f };
+ float3 p2 = { size * 0.4f, size * 0.5f, size * 0.8f };
+ v = max(v, pill(p1, p2, size * 0.08f, 144, img));
+ }
+ float3 p1 = { size * 0.5f, size * 0.5f, size * 0.3f };
+ ;
+ { // antenna
+ float spacex = .1;
+
+ float3 p2 = { size * (0.5f - spacex), size * 0.5f, size * 0.07f };
+ v = max(v, pill(p1, p2, size * 0.017f, 400, img));
+ float3 p3 = { size * (0.5f + spacex), size * 0.5f, size * 0.07f };
+ v = max(v, pill(p1, p3, size * 0.017f, 400, img));
+ }
+ { // eyes
+ float spacex = .105;
+ float3 p2 = { size * (0.5f - spacex), size * 0.4f, size * 0.2f };
+ float3 p3 = { size * (0.5f + spacex), size * 0.4f, size * 0.2f };
+ v -= pill(p2, p2, size * 0.018f, 144, img);
+ v -= pill(p3, p3, size * 0.018f, 144, img);
+ v = max(v, pill(p1, p2, size * 0.032f, 400, img));
+ v = max(v, pill(p1, p3, size * 0.032f, 400, img));
+ }
+ return v;
+
+}
+
+static float andySkeleton(float3 img) {
+ short v = 0;
+ { // body
+ float3 p1 = { size * 0.5f, size * 0.5f, size * 0.3f };
+ float radius = size * 0.15f;
+
+ float3 normal = { 0.0f, 0.0f, 1.0f };
+ for (int i = 0; i < 5; i++) {
+ p1.z += size * 0.04;
+ v += circle(p1, radius, normal, size * 0.07, 400, img);
+ }
+ p1.z = size * 0.3f;
+ float3 p2 = { size * 0.5f, size * 0.5f, size * 0.6f };
+ v = max(v, cogDisk(p2, radius*0.7f, normal, size * 0.07, 400, img));
+ v = max(v, cogCylinder(p1, p2, size * 0.04, 400, img));
+ }
+
+ float armOffset = 0.27f;
+ {
+ float3 p1 = { size * (0.5f - armOffset), size * 0.5f, size * 0.4f };
+ float3 p2 = { size * (0.5f + armOffset), size * 0.5f, size * 0.4f };
+ v = max(v, cogPill(p1, p2, size * 0.02f, 400, img));
+ }
+
+ { // arm 1
+ float3 p1 = { size * (0.5f - armOffset), size * 0.5f, size * 0.4f };
+ float3 p2 = { size * (0.5f - armOffset), size * 0.5f, size * 0.57f };
+ v = max(v, pill(p1, p2, size * 0.02f, 400, img));
+ }
+ { // arm 2
+ float3 p1 = { size * (0.5f + armOffset), size * 0.5f, size * 0.4f };
+ float3 p2 = { size * (0.5f + armOffset), size * 0.5f, size * 0.57f };
+ v = max(v, pill(p1, p2, size * 0.02f, 400, img));
+ }
+ { // leg 1
+ float3 p1 = { size * 0.6f, size * 0.5f, size * 0.6f };
+ float3 p2 = { size * 0.6f, size * 0.5f, size * 0.8f };
+ v = max(v, pill(p1, p2, size * 0.02f, 400, img));
+ }
+ { // leg 2
+ float3 p1 = { size * 0.4f, size * 0.5f, size * 0.6f };
+ float3 p2 = { size * 0.4f, size * 0.5f, size * 0.8f };
+ v = max(v, pill(p1, p2, size * 0.02f, 400, img));
+ }
+
+ return v;
+}
+
+short __attribute__((kernel)) andy(uint32_t x, uint32_t y) {
+ float3 img = { x, y, z };
+ float v = andyBody(img);
+ v = max(v, andySkeleton(img));
+ return v;
+
+}
+
+void __attribute__((kernel)) copy(short in, uint32_t x, uint32_t y) {
+ rsSetElementAt_short(volume, in, x, y, z);
+}
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/engine/mandelbulb.rs b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/mandelbulb.rs
new file mode 100644
index 00000000..23c1bc64
--- /dev/null
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/mandelbulb.rs
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.example.android.rs.vr.engine)
+#pragma rs_fp_relaxed
+
+int size;
+int z;
+rs_allocation volume;
+
+static float3 nylander(float3 p, int n) {
+ float3 out;
+ float r = length(p);
+ float phi = atan2(p.y, p.x);
+ float theta = acos(p.z / r);
+ float rn = pow(r, n);
+ out.x = sin(n * theta) * cos(n * phi);
+ out.y = sin(n * theta) * sin(n * phi);
+ out.z = cos(n * theta);
+ return out * rn;
+}
+
+/**
+* 8 x faster than the above for n = 3
+*/
+static float3 nylander3(float3 p) {
+ float3 out = (float3){0.f, 0.f, 0.f};
+ float xy2 = p.x * p.x + p.y * p.y;
+ if (xy2 == 0) return out;
+ float z23x2y2 = (3 * p.z * p.z - p.x * p.x - p.y * p.y);
+ out.x = (z23x2y2 * p.x * (p.x * p.x - 3 * p.y * p.y)) / xy2;
+ out.y = (z23x2y2 * p.y * (3 * p.x * p.x - p.y * p.y)) / xy2;
+ out.z = p.z * (p.z * p.z - 3 * p.x * p.x - 3 * p.y * p.y);
+ return out;
+}
+
+static float vsize(float3 p) {
+ return sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
+}
+
+short __attribute__((kernel)) mandelbulb(uint32_t x, uint32_t y) {
+ int size2 = size / 2;
+ if (z < size2) {
+ return 256-4*(size2-z+4)*hypot((float)x-size2,(float)y-size2) / size2 ;
+ }
+ float3 c = (float3) {(float) x, (float) y, (float) z};
+ c = ((c - size2) / (size2 * .9f));
+
+ int loop = 25;
+ float3 p = c;
+ float len;
+ for (int i = 0; i < loop; i++) {
+ // p = nylander(p, 3) + c;
+ p = nylander3(p) + c;
+ len = fast_length(p);
+ if (len > 2.f) return 255 - loop*10;
+ if (len < .3f) return loop*10;
+
+ }
+ len = length(p);
+ return (short) (255 - (len * 255) / 4);
+}
+
+void __attribute__((kernel)) copy(short in, uint32_t x, uint32_t y) {
+ rsSetElementAt_short(volume, in, x, y, z);
+}
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/engine/vr.rs b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/vr.rs
index 43fb794c..2b51eeee 100644
--- a/java/tests/VrDemo/src/com/example/android/rs/vr/engine/vr.rs
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/engine/vr.rs
@@ -287,7 +287,7 @@ uchar4 __attribute__ ((kernel)) draw_z_buffer(float2 in, uint32_t x, uint32_t y)
}
}
- out = convert_uchar4(total_color);
+ out = convert_uchar4(clamp(total_color, 0.f, 255.f));
out.a = 0xFF;
return out;
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Droid.java b/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Droid.java
new file mode 100644
index 00000000..fa8f98cf
--- /dev/null
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Droid.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.rs.vr.loaders;
+
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+import android.renderscript.Type;
+import android.util.Log;
+
+import com.example.android.rs.vr.engine.ScriptC_bugdroid;
+import com.example.android.rs.vr.engine.Volume;
+
+/**
+ * Provides a simple an example of a computed data set and allows the application to
+ * be run without any data sets.
+ */
+public class Droid {
+ private static final String LOGTAG = "RawLoader";
+ private static final String simpleLook = "simple";
+ private static final int[][] simpleOpacity = {{120, 0x0}, {150, 0xFF}};
+ private static final int[][] simpleColor = {
+ {144, 0xA4C639, 10, 80, 0},
+ {155, 0xA4C639, 10, 80, 0},
+ {200, 0x5555CC, 10, 80, 0},
+ {300, 0xAA5555, 40, 60, 0},
+ {255, 0xAAAAAA, 10, 80, 0}};
+
+ private static final String internalLook = "internal";
+ private static final int[][] internalOpacity = {{300, 0x0}, {400, 0xFF}};
+ private static final int[][] internalColor = {
+ {200, 0x44AA44, 70, 30, 30},
+ {230, 0xAA44AA, 70, 30, 20},
+ {300, 0xAA5555, 70, 30, 20},
+ {400, 0xAAAAAA, 70, 30, 20}};
+ private static final String tranlLook = "translucent";
+ private static final int[][] tranOpacity = {{110, 0x0},{140, 0x13},{143, 0x0}, {400, 0xFF}};
+ private static final int[][] tranColor = {
+ {144, 0xA4C639, 70, 30, 0},
+ {230, 0xAA44AA, 70, 30, 0},
+ {300, 0xAA5555, 70, 30, 20},
+ {400, 0xAAAAAA, 70, 30, 20}};
+
+ private static final int SIZE = 256;
+ public static final String NAME = "A Droid";
+
+ public static Volume buildRSVolume(RenderScript rs,
+ final VolumeLoader.ProgressListener listener) {
+ ScriptC_bugdroid scriptC_bricked = new ScriptC_bugdroid(rs);
+
+ Volume v = new Volume();
+ v.mDimx = v.mDimy = v.mDimz = SIZE;
+ v.mVoxelDim[0] = v.mVoxelDim[1] = v.mVoxelDim[2] = 1.f;
+
+ v.addLook(internalLook, internalColor, internalOpacity);
+ v.addLook(tranlLook, tranColor, tranOpacity);
+ v.addLook(simpleLook, simpleColor, simpleOpacity);
+
+ Type.Builder b = new Type.Builder(rs, android.renderscript.Element.I16(rs));
+ b.setX(v.mDimx).setY(v.mDimy);
+ Allocation tmp = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT);
+ b.setZ(v.mDimz);
+ b.setX(v.mDimx).setY(v.mDimy).setZ(v.mDimz);
+ v.mVolumeAllocation = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT);
+
+ scriptC_bricked.set_volume(v.mVolumeAllocation);
+ scriptC_bricked.set_size(SIZE);
+ long time = System.nanoTime();
+ for (int z = 0; z < v.mDimz; z++) {
+ scriptC_bricked.set_z(z);
+ scriptC_bricked.forEach_andy(tmp);
+ scriptC_bricked.forEach_copy(tmp);
+ rs.finish();
+ listener.progress(z, v.mDimz);
+ }
+
+ Log.v(LOGTAG, "compute Droid in" + ((System.nanoTime() - time) / 1E9f) + "seconds");
+ tmp.destroy();
+ scriptC_bricked.destroy();
+ return v;
+ }
+
+}
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Mandelbulb.java b/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Mandelbulb.java
index 9b160396..fd1ed6bb 100644
--- a/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Mandelbulb.java
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/Mandelbulb.java
@@ -21,7 +21,7 @@ import android.renderscript.RenderScript;
import android.renderscript.Type;
import android.util.Log;
-import com.example.android.rs.vr.engine.ScriptC_bricked;
+import com.example.android.rs.vr.engine.ScriptC_mandelbulb;
import com.example.android.rs.vr.engine.Volume;
/**
@@ -30,24 +30,36 @@ import com.example.android.rs.vr.engine.Volume;
*/
public class Mandelbulb {
private static final String LOGTAG = "RawLoader";
- private static final String simpleLook = "simple";
+ private static final String simpleLook = "green";
private static final int[][] simpleOpacity = {{120, 0x0}, {140, 0xFF}};
private static final int[][] simpleColor = {
- {200, 0x44AA44, 70, 30, 0},
+ {144, 0xA4C639, 10, 80, 0},
+ {155, 0xA4C639, 10, 60, 0},
+ {300, 0xAA5555, 40, 60, 0},
+ {255, 0xAAAAAA, 10, 80, 0}};
+
+
+ private static final String tranlLook = "purple";
+ private static final int[][] tranOpacity = {{110, 0x0},{140, 0x13},{143, 0x0}, {400, 0xFF}};
+ private static final int[][] tranColor = {
+ {144, 0xA4C639, 70, 30, 0},
{230, 0xAA44AA, 70, 30, 0},
- {255, 0xAAAAAA, 70, 30, 0}};
+ {300, 0xAA5555, 70, 30, 20},
+ {400, 0xAAAAAA, 70, 30, 20}};
private static final int SIZE = 256;
public static final String NAME = "A Mandelbulb";
public static Volume buildRSVolume(RenderScript rs,
final VolumeLoader.ProgressListener listener) {
- ScriptC_bricked scriptC_bricked = new ScriptC_bricked(rs);
+ ScriptC_mandelbulb scriptC_mandelbulb = new ScriptC_mandelbulb(rs);
Volume v = new Volume();
v.mDimx = v.mDimy = v.mDimz = SIZE;
v.mVoxelDim[0] = v.mVoxelDim[1] = v.mVoxelDim[2] = 1.f;
+
v.addLook(simpleLook, simpleColor, simpleOpacity);
+ v.addLook(tranlLook, tranColor, tranOpacity);
Type.Builder b = new Type.Builder(rs, android.renderscript.Element.I16(rs));
b.setX(v.mDimx).setY(v.mDimy);
@@ -56,20 +68,20 @@ public class Mandelbulb {
b.setX(v.mDimx).setY(v.mDimy).setZ(v.mDimz);
v.mVolumeAllocation = Allocation.createTyped(rs, b.create(), Allocation.USAGE_SCRIPT);
- scriptC_bricked.set_volume(v.mVolumeAllocation);
- scriptC_bricked.set_size(SIZE);
+ scriptC_mandelbulb.set_volume(v.mVolumeAllocation);
+ scriptC_mandelbulb.set_size(SIZE);
long time = System.nanoTime();
for (int z = 0; z < v.mDimz; z++) {
- scriptC_bricked.set_z(z);
- scriptC_bricked.forEach_mandelbulb(tmp);
- scriptC_bricked.forEach_copy(tmp);
+ scriptC_mandelbulb.set_z(z);
+ scriptC_mandelbulb.forEach_mandelbulb(tmp);
+ scriptC_mandelbulb.forEach_copy(tmp);
rs.finish();
listener.progress(z, v.mDimz);
}
Log.v(LOGTAG, "compute Mandelbulb in" + ((System.nanoTime() - time) / 1E9f) + "seconds");
tmp.destroy();
- scriptC_bricked.destroy();
+ scriptC_mandelbulb.destroy();
return v;
}
diff --git a/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/VolumeLoader.java b/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/VolumeLoader.java
index 2321e294..1cbf02cf 100644
--- a/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/VolumeLoader.java
+++ b/java/tests/VrDemo/src/com/example/android/rs/vr/loaders/VolumeLoader.java
@@ -36,7 +36,7 @@ public class VolumeLoader {
public VolumeLoader(String dir) {
map.put(Mandelbulb.NAME,null);
-
+ map.put(Droid.NAME,null);
baseDir = new File(dir);
if (!baseDir.exists()) {
Log.e(LOGTAG, "Directory: \""+dir+"\" does not exist ");
@@ -59,6 +59,9 @@ public class VolumeLoader {
if (name.equals(Mandelbulb.NAME)) {
return Mandelbulb.buildRSVolume(rs,mListener);
}
+ if (name.equals(Droid.NAME)) {
+ return Droid.buildRSVolume(rs,mListener);
+ }
Properties p = map.get(name);
if (p == null) {
Log.v(LOGTAG,"Could not find "+name);