Scripts, Tools & Methods Developed at Hook
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!