Shaders / ShadedMaterial Example
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); } } }
7 Comments to Shaders / ShadedMaterial Example
Very nice, subtle effect. I likes it
Thanks for this - helps me a lot
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!
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?
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.
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!
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
Search
Recent Posts
- MorphController - Mighty Morphing Papervision3D
- End dump
- Test if a plane is within the view of the camera (aka testing if culled)
- Materials Reference
- Perlin Blob
- Dynamic Text on a Plane
- Maya Texture Baking
- Creating a Custom VectorVision Font
- Workshop video and example dump
- 3D Math Book Recommendation
- Heading to New York. brb ;)
- Launching Flex4.org
- Flex 4 Layouts and Groups
- Flex 4 States
- How to click on stuff in Papervision3D - Viewport, ViewportLayers, InteractiveScene3DEvent, Mouse3D, and MovieMaterial Buttons
Recent Comments
- alexxcz on MorphController - Mighty Morphing Papervision3D
- andre venancio on 3D Math Book Recommendation
- DS on Dynamic Text on a Plane
- John Lindquist on Maya Texture Baking
- Itai on Maya Texture Baking
- Javier on End dump
- samBrown on End dump
- tf on archive
- Pan on requests
- Martin Lindelöf on requests


December 19, 2008