Email Updates RSS Subscribe
Line

This blog is created and maintained by the technical team at Hook in an effort to preserve and share the insights and experience gained during the research and testing phases of our development process. Often, much of this information is lost or hidden once a project is completed. These articles aim to revisit, expand and/or review the concepts that seem worth exploring further. The site also serves as a platform for releasing tools developed internally to help streamline ad development.

Launch
Line

Hook is a digital production company that develops interactive content for industry leading agencies and their brands. For more information visit www.byhook.com.

Line

WhiteShadingBitmapMaterial shading flicker in Away3D

Line
Posted on February 1st, 2010 by Norm McGarry
Line

Recently, I was having a weird issue with shading flickering while working on a project with Away3D. I wanted to use basic lighting with the WhiteShadingBitmapMaterial class. All I needed was a simple gradient lighting and this material seemed perfect for the job. It seemed even with the object perfectly still, the material would change shading, and dramatically too. It just didn’t make sense, so I dug into the Away3D code and found something interesting:

In the renderTri() method, on line 92, there was the following:

                if (step < 64)
                    if (Math.random() < 0.01)
                        doubleStepTo(64);

Despite Away3D’s severe lacking of code commenting, all the code seemed pretty normal in the class, except for that line. Why would they do an if-statement with Math.random() that is going to qualify as true about 1% of the time? My thought: performance.

Luckily, my application wasn’t very complicated. Simply removing the if-statement leaves me to this:

                if (step < 64)
                    doubleStepTo(64);

The result is a non-flickering WhiteShadingBitmapMaterial! See the example below!


Get Adobe Flash player


Line
1 Response to “WhiteShadingBitmapMaterial shading flicker in Away3D”
  1. Hugo says:

    Wow, I’m surprised that an engine like Away3D randomizes things up in an attempt to “optimize” speed …

    Kind of unprofessional to me.


Leave a Reply

*

Line
Line
Pony