Shaders / ShadedMaterial Example

Friday, December 19th, 2008 | examples, requests


source

package
{
	import flash.display.Bitmap;
	import flash.events.Event;
 
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.shaders.PhongShader;
	import org.papervision3d.materials.shaders.ShadedMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
 
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class ShadersExample extends BasicView
	{
		[Embed(source="assets/santa.jpg")]
		private var santaAsset:Class;
 
		private var plane:Plane;
 
		public function ShadersExample()
		{
			camera.z = -500;
 
			var santaBitmap:Bitmap = new santaAsset() as Bitmap;
 
			var light:PointLight3D = new PointLight3D();
 
			var bitmapMaterial:BitmapMaterial = new BitmapMaterial(santaBitmap.bitmapData, true);
			var shader:PhongShader = new PhongShader(light, 0xffffff, 0x000000, 10);
			var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader);
			shadedMaterial.doubleSided = true;
 
 
			plane = new Plane(shadedMaterial);
 
			scene.addChild(plane);
			startRendering();	
 		}
 
 		override protected function onRenderTick(event:Event=null):void
 		{
 			plane.rotationY = viewport.containerSprite.mouseX / 4;
 			super.onRenderTick(event);
 		}
	}
}

Tags: ,

7 Comments to Shaders / ShadedMaterial Example

TK
December 19, 2008

Very nice, subtle effect. I likes it :)

I like to play
December 21, 2008

Thanks for this - helps me a lot :-)

alex grande
January 3, 2009

I really like that your examples are written in OOP. This is important for people who are new to AS3. I also like the simple example illustrating shading material. I wish, though, that your examples would have more comments in the code. Keep it up!

Phil
January 6, 2009

Heya, i’ve got a problem over here!
When i’m exporting my swf i’ve got Error #1007 output.
The thing is it does that even with your original source code… Any tips on that?

John Lindquist
January 6, 2009

@Phil - I imagine you’re using Flash instead of FlexBuilder. I’ll be putting together a video tutorial of how to import the examples into Flash when I get back home next week.

trix
January 8, 2009

Hi John! You’re examples are awesome!
I have one issue here, however. I’ve implemented this solution in a project, where the plane can turn all the way around and the light doesn’t seem to interact with the back face although the bitmap is visible.
I’ve set doubleSided to true for both the BitmapMaterial and the ShadedMaterial. When I set it for the PhongShader it throws an error (==undefined property).
Keep up the good work!

mike
April 14, 2009

im having an issue with all types of shaders. as soon as i apply a shaded material to my planes which are set up in the shape of a cube they all seem to get bigger.

any ideas why?

Leave a comment