Shader materials act a lot like Colormaterials, but with shading. Oh, and they require a Point Light.
FlatShadeMaterial
example: FlatShadeMaterial.swf
source: FlatShadeMaterial.zip
This material type really isn't all that different from ColorMaterial. It applies a flat color against the entire object. Thats really about it. Nothing to crazy about this one. But, if you decide to use it here is how it is done:
//import the FlatShadeMaterial and PointLight3D PV3D Library assets
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.lights.PointLight3D;
//data type your FlatShadeMaterial and your point light
private var flatShadeMaterial:FlatShadeMaterial;
private var pointLight:PointLight3D;
//instantiate your point light and set it back on the z
//pointLight = new PointLight3D(boolean parameter to show the light in the scene or not);
pointLight = new PointLight3D(true);
pointLight.z = -1500;
//instantiate the flatShadeMaterial
//material = new FlatShadeMaterial(point light, diffuse color, ambient color);
flatShadeMaterial = new FlatShadeMaterial(pointLight, 0xFFFFFF, 0x000000);
//apply your flatShadeMaterial to your object
//note: some objects require that you apply your material via a MaterialsList utility
//in this example I'm applying my material to a Plane
plane = new Plane(flatShadeMaterial, 100, 100, 2, 2);
GouraudMaterial
example: GouraudMaterial.swf
source: GouraudMaterial.zip
This material type bounces back light based on the light position in relation to the normals of your geometry. Polygons will then have varying light intensity based on how direct the light is pointing at the geometry normals.
//import the GouraudMaterial and PointLight3D PV3D Library assets
import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.lights.PointLight3D;
//data type your GouraudMaterial and your point light
private var gouraudMaterial:GouraudMaterial;
private var pointLight:PointLight3D;
//instantiate your point light and set it back on the z
//pointLight = new PointLight3D(boolean parameter to show the light in the scene or not);
pointLight = new PointLight3D(true);
pointLight.z = -1500;
//instantiate the gouraudMaterial
//material = new GouraudMaterial(point light, light color, ambient color);
gouraudMaterial= new GouraudMaterial(pointLight, 0xFFFFFF, 0x000000);
//apply your gouraudMaterial to your object
//note: some objects require that you apply your material via a MaterialsList utility
//in this example I'm applying my material to a Plane
plane = new Plane(gouraudMaterial, 100, 100, 2, 2);
PhongMaterial
example: PhongMaterial.swf
source: PhongMaterial.zip
This material type is a calculation of light being reflected at a per pixel region. The light reflections are more intense where the light source is more of a direct hit.
//import the PhongMaterial and PointLight3D PV3D Library assets
import org.papervision3d.materials.shadematerials.PhongMaterial;
import org.papervision3d.lights.PointLight3D;
//data type your PhongMaterial and your point light
private var phongMaterial:PhongMaterial;
private var pointLight:PointLight3D;
//instantiate your point light and set it back on the z
//pointLight = new PointLight3D(boolean parameter to show the light in the scene or not);
pointLight = new PointLight3D(true);
pointLight.z = -1500;
//instantiate the phongMaterial
//material = new PhongMaterial(point light, light color, ambient color, specular intensity);
phongMaterial = new PhongMaterial(pointLight, 0xFFFFFF, 0x000000, 80);
//apply your phongMaterial to your object
//note: some objects require that you apply your material via a MaterialsList utility
//in this example I'm applying my material to a Plane
plane = new Plane(phongMaterial, 100, 100, 2, 2);
CellMaterial
example: CellMaterial.swf
source: CellMaterial.zip
This material is particularly interesting. It actually has a step gradiation of colors between two color (of your choice). For the example I set the number of steps to 10 so it would be easy to see what is going on.
//import the CellMaterial and PointLight3D PV3D Library assets
import org.papervision3d.materials.shadematerials.CellMaterial;
import org.papervision3d.lights.PointLight3D;
//data type your CellMaterial and your point light
private var cellMaterial :CellMaterial ;
private var pointLight:PointLight3D;
//instantiate your point light and set it back on the z
//pointLight = new PointLight3D(boolean parameter to show the light in the scene or not);
pointLight = new PointLight3D(true);
pointLight.z = -1500;
//instantiate the cellMaterial
//material = new CellMaterial (point light, color 1, color 2, number of steps);
cellMaterial = new CellMaterial (pointLight, 0xFFFFFF, 0x000000, 10);
//apply your cellMaterial to your object
//note: some objects require that you apply your material via a MaterialsList utility
//in this example I'm applying my material to a Sphere
sphere = new Sphere(cellMaterial, 300, 12, 12);
Applying PV3D Shader Materials - FlatShadeMaterial / GouraudMaterial / PhongMaterial / CellMaterial
9:10 PM, Posted by Jim Foley, 27 Comments
hey, thanks so much for posting this!
i am totally new to this so not sure it's a valid comment but the Phong material requires 4 variables to create, in your example u only use 3... i tried with 3 but it wouldn't compile, I guess the specular value should be appended...
PhongMaterial(light3D:LightObject3D, lightColor:int, ambientColor:int, specular:int)
hi Jim!
i`m new to pv3d,
and this blog really helps understanding some stuff.
BIG THANKS.
Q: is there a way to apply flat shade or colorMaterial but with GRADIENT??? plain simple linear gradient.
please help...
Gudgo - You're right. Guess I left that out when I was writing it. It does require the specular param. I'll update it asap.
Andy - The Phong material is eccentually a gradient color. Cell is gradient as well and lets you specify the number of steps in the gradient.
Hello
I'm tryin to run your phong example.. But I have following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at org.papervision3d.materials.shadematerials::EnvMapMaterial/drawTriangle()
at org.papervision3d.core.render.command::RenderTriangle/render()
at org.papervision3d.render::BasicRenderEngine/doRender()
at org.papervision3d.render::BasicRenderEngine/renderScene()
at MethodInfo-1170()
I'm using it with pv3d 2.0 Great White.
Do you know maybe what's wrong?
Thanks, for your help.
Regards,
seek - not sure. that could be a number of problems really. seems like something is not correctly instantiated or not instantiated at all. download the example again and give it a try. maybe the code was accidentally change. I ran it and it worked for me.
Hi Jim,
Thanks so much for posting all the great tutorials.
I am trying to get the files to work, but I keep getting error messages on each one saying, for example:
1172: Definition org.papervision3d.view:Viewport3D could not be found.
Just posted a comment but the bottom got cut off.
I have been using a mac SVN client and wonder if this could be the source of the issue?
Thanks for any help.
Emmett
Hi Jim,
I have been watching the videos and having a read. Great stuff. I have not as yet downloaded or installed any of the PV3D stuff etc.
I have flashplayer9, and flash CS3 on my machine so I should be able to download and run the swf files should I not?
Or does the end user have to download something besides the flash player?
The ones that will not run are the ones in sections....
Swift 3D & PV3D (IV)
PV3D Collada (DAE) Files (V)
these files were just blank.
Also are the Camtasia tutorials meant to have audio?
Thanks
Mark
anyway to get the shader to apply to a transparent bitmap material without losing the background transparency?
thanks
@ emmett - Sorry man. Not sure what the problem is. I'd post up some source code and files on the Papervision 3D board. I'm a pc person. Not familiar with the mac.
@mark - some of these examples require the ASCB (actionscript cookbook) library of classes. Others also require the Tweener library classes. If you're simply trying to run the .swf and not the .fla, then it should work. Either way, you can see the .swf in action in the preview links for each shader type.
@ yojimbo - In the examples I posted I am using shader materials. There are shaders that you can apply to existing materials like this: http://www.rockonflash.com/blog/?m=20071205
That is probably the route you'd want to take.
Hi. All the examples are just on primitive shapes. Have you any examples of adding phong/cell/shaded materials to collada files (ie, adding them at run time not through the collada model). Always throws a:
Cannot access a property or method of a null object reference.
at org.papervision3d.materials.shadematerials::EnvMapMaterial/drawTriangle()
at org.papervision3d.core.render.command::RenderTriangle/render()
at org.papervision3d.render::BasicRenderEngine/doRender()
at org.papervision3d.render::BasicRenderEngine/renderScene()
when i try to add a shaded material :(
thanks !
it s very difficult to have example about light for papervision.
Thanks you !
Hi:
How can i apply a shader to a cube?
Thanks for the notes! Part of the missing PV3D manual spread out at the n corners of the web! :)
Hey Jim!
Allways nice to see someone make an effort to spread the knowledge of PV3D.
I would just like to comment on your comment on flatshaded material :p
Compairing it to color material isn´t really fair. First of all - it´s a shaded material where as the color material is not, and that makes all the difference in the world. Without shading an object with one color is like a totally flat silhuette. And of the shaded materials flatshaded is the only one I do use at the moment since gouraud and phong apply just one smoothing group on the whole mesh, which makes them a bit useless to me. This may have changed lately, but it has been an issue so far.
Regards
///JmD
iTs rEally hElpful. tx dUde. u r d mAn. cH33rs
Did anybody solve the problem with asdding shaded material to collada objects? i also get :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at org.papervision3d.materials.shadematerials::EnvMapMaterial/drawTriangle()
at org.papervision3d.core.render.command::RenderTriangle/render()
at org.papervision3d.render::BasicRenderEngine/doRender()
at org.papervision3d.render::BasicRenderEngine/renderScene()
at Papervision3DTutorial/loop3D()
I think the problem is in materialList
thanx for the post...
I had the same problems that ch had:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at org.papervision3d.materials.shadematerials::GouraudMaterial/drawTriangle()
at org.papervision3d.core.render.command::RenderTriangle/render()
at org.papervision3d.render::BasicRenderEngine/org.papervision3d.render:BasicRenderEngine::doRender()
at org.papervision3d.render::BasicRenderEngine/renderScene()
at MethodInfo-1268()
Any clues on how to solve this?
thank you
I found out what was happening. I was using the new "effects" branch of papervision. when I switched to greatwhite it worked out fine.
thanx again
Hi Jim,
It's nice to see swift 3d alive and up to date. Any ideas why did it take so long ? I remember there was a Page Flip contest a year before swift 3d was launched. What happened ?
Back to PV3D 2.0 shadedmaterials.
I am using Great White and I still get the RenderTriangle error when I apply any shaded material on a collada file. I'll try to find a workaround on this one and get back.
I didn't expect the shaded materials to be so easy to use. Thanks for keeping it simple enough for the us.
About the FlatShadeMaterial, I find it quite different from the ColorMaterial. I've placed my light on top as well ( light.y = 500 for example ) and I think the result is pretty close to the Cartoon Full Color option from Vector rendering(ravix) in Swift 3D, where you get to see all the visible faces shaded.
I've asked posted the question on shaded materials on collada models on the Papervision3D mailing list and luckily Tim Knip responded: "Are you using the Collada object or the DAE object?
If you use Collada object, then please use DAE.
Use DAE#replaceMaterialByName to setup the shaded material for a child-node.
Tim"
Also I was using a revision from April, so if you want the replaceMaterialByName method in the DAE class make sure you've got the latest revision.
I don't know why I've been using Collada instead of DAE, because DAE has a whole lot more functionalities ( I'm speaking about the PV3D classes ).
Hope this helps.
I made a simple collada cube in Blender and when I replace your object (in the line "dae.load") with the cube object I made, there's no more phong shading (the rest of the code is the same). Do I need to something special to the cube in Blender for it to be effected by the phong shading?
I am diving into PaperVision 3D and starting to understand it, but I am getting an error when I attept to export this to play with it.
I am getting errors like this: 1195: Attempted access of inaccessible method yaw through a reference with static type org.papervision3d.objects.parsers:DAE.
on lines 58 and 59
Hi,
Thanks so much for posting these. I've been trawling the web for some simple tutorials and yours are the first that actually work!
It's a big help to people like myself who are new to PV3D!
@All - if you're trying to apply materials directly to a Collada or a Cube it won't work. You need to apply them using a MaterialsList object. Filter your Materials through the MaterialsList and then apply the MaterialsList object to your Cube or Collada. Check out the tut on making a Cube in PV3D Primitives (III) video #3.
"This material type really isn't all that different from ColorMaterial" = not true. they can do some pretty different things. The only real similarity they have is that they're both materials. I only read the first part of the post, I assume the rest was equally useless + it was tl;rd.
Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!