Setting the alpha value of a material leads to visible triangles

12 views
Skip to first unread message

Knut Urdalen

unread,
Oct 6, 2008, 8:28:47 AM10/6/08
to away3...@googlegroups.com
Hi,

While at FOTB I played around with Away3D and
SoundMixer.computeSpectrum() to simply distribute some pumping cubes on
a grid based on the current music playing.

I set the alpha-value of a color material on a cube like this on each frame:

ColorMaterial(cubes[index].material).alpha = dampValues[i] / amplitude;

but that leads to some weird rendering issue. Have a look yourself and I
guess you see what I mean.

Demo: http://www.urdalen.com/lab/spectrumanalyzer/
Source: http://www.urdalen.com/lab/spectrumanalyzer/SpectrumAnalyzer.as

I've also tried with a using a BitmapRenderSession on the view (Rob's
suggestion), with no luck. Anyone that understand what's going on here?
I feel a bit lost here. Source is supplied so you can play around with it :)

Knut

Jensa

unread,
Oct 7, 2008, 9:34:43 AM10/7/08
to away3d.dev
Hi Knut,
Thought I'd see you at the FUGN meet yesterday. I had a look at it,
played around and there's definitely something weird here. This should
just have worked.
Maybe Fabrice has an explanation for this odd behavior?

J

Fabrice

unread,
Oct 7, 2008, 10:31:42 AM10/7/08
to away3...@googlegroups.com
Actually I don't, I haven't got time to run the script,
but seing this, alpha values would be the first thing I would trace.
out of range values may be...

Fabrice

Jensa

unread,
Oct 7, 2008, 3:57:05 PM10/7/08
to away3d.dev
I tested it and even though some of the values were above 1, clamping
them made no difference. Anybody else that have an idea?

J

Benoit Beausejour

unread,
Oct 8, 2008, 11:47:22 AM10/8/08
to away3d.dev
Hi Jensa,

I was having the same problem on a project and tracked it down to a
problem with faces not behind correctly destroyed/removed from
primitives when a rebuilt.

The problem comes from setting width/height on planes and/or
primitives. This will trigger a rebuild of the primitive, the core
code had a bug which could leave faces behind. When this happens when
ownCanvas and alpha are applied,some faces are then "drawn twice",
causing difference in alpha of the doubloon triangles.

The following patch to AbstractPrimitive.as corrects the issue very
simply: (This is against 2.1)

Index: /Users/bbeausej/Documents/DEV/Away3D_2_1/src/away3d/primitives/
AbstractPrimitive.as
===================================================================
--- /Users/bbeausej/Documents/DEV/Away3D_2_1/src/away3d/primitives/
AbstractPrimitive.as (revision 722)
+++ /Users/bbeausej/Documents/DEV/Away3D_2_1/src/away3d/primitives/
AbstractPrimitive.as (working copy)
@@ -104,7 +104,7 @@
_primitiveDirty = false;

//remove all elements from the mesh
- for each (_face in faces)
+ for(var i:int = faces.length-1; i >= 0; i--)
removeFace(_face);

//clear vertex objects


Hope this works!

Ben

Benoit Beausejour

unread,
Oct 8, 2008, 11:59:49 AM10/8/08
to away3d.dev
Oups, a bit trigger happy on that post and spelling, sorry about
that, here goes:


Index: /Users/bbeausej/Documents/DEV/Away3D_2_1/src/away3d/primitives/
AbstractPrimitive.as
===================================================================
--- /Users/bbeausej/Documents/DEV/Away3D_2_1/src/away3d/primitives/
AbstractPrimitive.as (revision 722)
+++ /Users/bbeausej/Documents/DEV/Away3D_2_1/src/away3d/primitives/
AbstractPrimitive.as (working copy)
@@ -104,8 +104,11 @@
_primitiveDirty = false;

//remove all elements from the mesh
- for each (_face in faces)
+ for(var i:int = faces.length-1; i >= 0; i--)
+ {
+ _face = faces[i];
removeFace(_face);
+ }

//clear vertex objects
_vStore = _vStore.concat(_vActive);

Knut Urdalen

unread,
Oct 8, 2008, 4:16:50 PM10/8/08
to away3...@googlegroups.com
Kudos Benoit! This solved the problem. Rob: Please commit patch :)

Here's my result:

Before: http://www.urdalen.com/lab/spectrumanalyzer/
After: http://www.urdalen.com/lab/spectrumanalyzer/working/

Knut

Jensa

unread,
Oct 8, 2008, 4:47:43 PM10/8/08
to away3d.dev
Cool!
Knut? The path to that MP3...? ;)

J

Rob Bateman

unread,
Oct 8, 2008, 8:55:17 PM10/8/08
to away3...@googlegroups.com
svn updated. That mistake was a nice hangover from as2 days when for.. in loops stepped through arrays in the reverse order to the order they had been created :)

i've used a while loop instead, but the principal is the same. also fixed the same problem in AbstractWirePrimitive


Rob
--
Rob Bateman
Flash Development & Consultancy

rob.b...@gmail.com
www.infiniteturtles.co.uk
www.away3d.com

Knut Urdalen

unread,
Oct 9, 2008, 4:12:37 AM10/9/08
to away3...@googlegroups.com
Great! Thanks :)

Knut

Reply all
Reply to author
Forward
0 new messages