# Panda3D/Manual/Materiais

Materials affect how the surfaces of models appear when lights are enabled in Panda. These have various effects such as how shiny an object appears, the brightness of it's colors etc. Material properties are combined with textures and lighting to get the final look of an object.
It must be emphasized that materials only work when lights are applied to an object. Otherwise, materials have no effect. Explanation of Lighting
When light strikes a 3D model, light reflects off the model. If there were no light reflecting off the model, the model would appear pitch black. The light reflecting off the model is what causes it to have a non-black color onscreen. In the real world, light is incredibly complicated --- so complicated, that it is infeasible to do realistic calculations. Instead, Panda3D leaves it in your hands, giving you some basic tools to express how much light you want reflecting from each surface.
The tools provided are lights and materials. Lights are used to express how much light is striking the model. Materials are used to express how much of the light striking the model is reflected.
Panda3D separates the light striking the model into two general categories: nondirectional, and directional. Directional light is light that comes straight from a particular lamp. Because we know where it's coming from, we also know what direction it is coming from. Nondirectional light is light that maybe came from somewhere, bounced around a bit, and then eventually hit the model. Because we don't know exactly where it came from, we don't know what direction it is coming from. Panda3D handles nondirectional and directional light separately.
There are four kinds of lights in Panda3D: ambient, point, diffuse, and directional. The ambient light only creates nondirectional light. The other three create directional light.
When light strikes the surface of the model, it is the Material that governs how much of it reflects. The Material consists of four values:
Default Behavior and Explicit Behavior
If the model does not have an explicit material, does not have a flat color, and does not have vertex colors, the behavior is this:
If the model does not have an explicit material, but it does have a flat color or a vertex color, the behavior is this:
When you set an explicit material on an object, the behavior is as follows:
It is possible to mix-and-match explicit with default behavior. For example, you can specify an explicit specular color, but not specify an explicit ambient, diffuse, or emissive color. If you do that, the behavior would be:
Creating and Using Materials
To use explicit materials, import the Materials module when you first begin your script. Then creating Materials is a matter of creating instances of the Material class and setting the relevant properties:
from pandac.PandaModules import Material from pandac.PandaModules import VBase4
myMaterial = Material myMaterial.setShininess(5.0) #Make this material shiny myMaterial.setAmbient(VBase4(0,0,1,1)) #Make this material blue
myNode = loader.loadModel("panda") #Load the model to apply the material to myNode.setMaterial(myMaterial) #Apply the material to this nodePath
Material Properties
The following table details the properties available in a material, its effects as well as the relevant setter method. Most of these properties have additional pegar e limpar methods as well. Property Effects Setter Method Ambient This is the color of the object as it appears in the absence of direct light. This will be the multiplied by any ambient lights in effect on the material to set its base color. material.setAmbient(VBase4(R,G,B,A)) Diffuse This is the primary color of an object; the color of the object as it appears in direct light, in the absence of highlights. This will be multiplied by any lights in effect on the material to get the color in the parts of the object illuminated by the lights. material.setDiffuse(VBase4(R,G,B,A)) Emission This is the color of the object as it appears in the absence of any light whatsover, including ambient light. It is as if the object is glowing by this color (although of course it will not illuminate neighboring objects) material.setEmission(VBase4(R,G,B,A)) Shininess This controls the size of the specular highlight spot. In general, larger number produce a smaller specular highlight, which makes the object appear shinier. Smaller numbers produce a larger highlight, which makes the object appear less shiny. material.setShininess(<float>) Specular This is the highlight color of an object: the color of small highlight reflections. material.setSpecular(VBase4(R,G,B,A)) Other Material Methods
Besides the setter methods covered above, you can also get material properties using their get methods, such as material.getShininess , material.getDiffuse, etc.
Properties can also be reset by using the clear methods: material.clearAmbient,material.clearSpecular, etc. Shininess does not have a clear method.
Additionally you can check if a material has a property with the has methods: material.hasAmbient , material.hasEmission, etc.
Materials have two other methods that have not been covered yet, setLocal and setTwoside. setLocal controls whether to use camera-relative specular highlights or orthogonal specular highlights. This should be set to True unless an orthogonal projection camera is in use. setTwoside controls if lighting should appear on both sides of a polygon. Both these methods have equivalent get methods. Related Classes