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: ,

  • I am sure that anyone would like to visit it again and again. After reading this post I got some very unique information which are really very helpful for anyone

  • When I run this code I get the following error
    "TypeError: Error #1007: Instantiation attempted on a non-constructor."

    I guess it has something to do with "var santaBitmap:Bitmap = new santaAsset() as Bitmap;"
    But I'm not sure.
    Maybe it's the program I use? -> flash 9.0 CS3

    Any of you guys have an idea?

  • jofo70

    The null problem was my fault. I tried to declare it before it was loaded. I'd still love to see the video you're talking about here though. It's even one step harder to learn Papervision3D when you have to set up all of the Flex examples to Flash.

  • jofo70

    Unlike most of your examples, this did not compile correctly in flash cs3. I'm getting a different error at runtime though. #1009 null object reference. did you ever make the video tutorial about importing your examples to flash? I've not had a problem yet doing that with your examples until now. thanks for all you've taught me.

  • pradeep

    thanks,

    i can i start to create .fla file and use my image and create my own?

    please reply me

  • mike

    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?

  • 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!

  • John Lindquist

    @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.

  • Phil

    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?

  • 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!

  • Thanks for this - helps me a lot :-)

  • TK

    Very nice, subtle effect. I likes it :)

blog comments powered by Disqus

Search

Recommended Books

Speaking at FITC Toronto

 

December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...