Material Definition Properties
In jMonkeyEngine 3, colors and textures are represented as Material objects.
-
All Geometries must have Materials. To improve performance, reuse Materials for similar models, don’t create a new Material object for every Geometry. (E.g. use one bark Material for several tree models.)
-
Each Material is based on one of jme3’s default Material Definitions (.j3md files) that are included in the engine. Advanced users can create additional custom Material Definitions (see how it’s done in the jme3 sources).
Find out quickly How to Use Materials, including the most commonly used code samples and RenderStates. |
All Materials Definition Properties
The following Materials table shows the Material Definitions that jMonkeyEngine 3 supports.
Looks confusing? |
Most Material parameters are optional. For example, it is okay to specify solely the DiffuseMap
and NormalMap
when using Lighting.j3md
, and leave the other texture maps empty. In this case, you are only using a subset of the possible features, but that’s fine if it already makes in the material look the way that you want. You can always add more texture maps later.
Unshaded Coloring and Textures
jMonkeyEngine supports illuminated and unshaded Material Definitions.
-
Phong Illuminated materials look more naturalistic.
-
Unshaded materials look more abstract.
“Unshaded” materials look somewhat abstract because they ignore lighting and shading. Unshaded Materials work even if the scene does not include a light source. These Materials can be single-colored or textured. For example, they are used for cards and tiles, for the sky, billboards and UI elements, for toon-style games, or for testing.
Material Definition | Usage | Material Parameters |
---|---|---|
Common/MatDefs/Misc/ |
Standard, non-illuminated Materials. Use this for simple coloring, texturing, glow, and transparency. See also: Hello Material |
Texture Maps |
Other useful, but less commonly used material definitions:
Material Definition | Usage | Material Parameters |
---|---|---|
Common/MatDefs/Misc/ |
A solid sky blue, or use with a custom SkyDome texture. See also: Sky |
setTexture(“Texture”, assetManager.loadTexture(“name”)); |
Common/MatDefs/Terrain/ |
Splat textures for, e.g. terrains. See also: Hello Terrain |
setTexture(“Tex1”, assetManager.loadTexture(“name”)); |
Common/MatDefs/Terrain/ |
A multi-layered texture for terrains. Specify four textures and a Vector3f describing the region in which each texture should appear: X = start height, Texture regions can overlap. For example: Specify a seafloor texture for the lowest areas. A sandy texture for the beaches. A grassy texture for inland areas. A rocky texture for mountain tops. |
setFloat(“terrainSize”,512f); |
Common/MatDefs/Misc/ |
Used with texture masks for particle effects, or for point sprites. The Quadratic value scales the particle for perspective view. (formula) Does support an optional colored glow effect. See also: Hello Effects |
setTexture(“Texture”, assetManager.loadTexture(“name”)); |
Phong Illuminated
jMonkeyEngine supports illuminated and unshaded Material Definitions.
-
Phong Illuminated materials look more naturalistic.
-
Unshaded materials look more abstract.
Illuminated materials require a light source added to at least one of their parent nodes! (e.g. rootNode.) Illuminated materials are darker on the sides facing away from light sources. They use Phong illumination model (default), or the Ward isotropic gaussian specular shader (WardIso) which looks more like plastic. They do not cast drop shadows unless you use a FilterPostProcessor.
Material Definition | Usage | Material Parameters |
---|---|---|
Common/MatDefs/Light/ |
Commonly used Material with Phong illumination. Use this material together with DiffuseMap, SpecularMap, BumpMap (NormalMaps, ParalaxMap) textures. Supports shininess, transparency, and plain material colors (Diffuse, Ambient, Specular). See also: Hello Material |
Texture Maps |
Material Definitions | Usage | Material Parameters |
---|---|---|
Common/MatDefs/Terrain/ |
Same kind of multi-layered splat texture as Terrain.j3md, but with illumination and shading. Typically used for terrains, but works on any mesh. For every three splat textures, you need one alpha map. You can use a total of 11 texture maps in the terrain’s splat texture: Note that diffuse and normal maps all count against that. For example: You can use a maximum of nine diffuse textures, two of which can have normal maps; or, five textures with both diffuse and normal maps. |
Texture Splat Maps |
Common/MatDefs/Light/ |
Reflective glass material with environment map (CubeMap/SphereMap). |
setTexture(“Texture”, assetManager.loadTexture(“name”)); |
Other: Test and Debug
Material Definition | Usage |
---|---|
Common/MatDefs/Misc/ |
A color gradient calculated from the model’s surface normal’s. You can use this built-in material to debug the generation of normal’s in meshes, to preview models that have no material and no lights, or as fall-back default material. This built-in material has no parameters. |
RenderStates
Material Option | Description | Example |
---|---|---|
getAdditionalRenderState(). |
This is the default, no transparency. |
Use for all opaque objects like walls, floors, people… |
getAdditionalRenderState() |
Interpolates the background pixel with the current pixel by using the current pixel’s alpha. |
Use this for normal every-day translucency: Frosted window panes, ice, glass, alpha-blended vegetation textures… |
getAdditionalRenderState() |
Disables writing of the pixel’s depth value to the depth buffer. |
Use this on Materials if you have several transparent/translucent objects obscuring one another, but you want to see through both. |
getAdditionalRenderState() getAdditionalRenderState() |
Enables Alpha Testing with a “AlphaDiscardThreshold” in the AlphaMap. |
Activate Alpha Testing for (partially) transparent objects such as foliage, hair, etc. Deactivate Alpha Testing for gradually translucent objects, such as colored glass, smoked glass, ghosts. |
getAdditionalRenderState() |
Additive alpha blending adds colors in a commutative way, i.e. the result does not depend on the order of transparent layers since it adds the scene’s background pixel color to the current pixel color. This is useful if you have many transparent textures overlapping and don’t care about the order. Note: Viewed in front of a white background, Additive textures become fully transparent! |
This is the default for Particle.j3md-based textures that have a black color background. |
getAdditionalRenderState() |
Same as “Additive”, except first it multiplies the current pixel color by the pixel alpha. |
This can be used for particle effects that have alpha as background. |
getAdditionalRenderState() |
Blends by color. |
Generally useless. |
getAdditionalRenderState() |
Multiplies the background pixel by the current pixel. |
? |
getAdditionalRenderState() |
Same as “Modulate”, except the result is doubled. |
? |
getAdditionalRenderState() |
Pre-multiplied alpha blending. E.g. if the color of the object has already been multiplied by its alpha, this is used instead of “Alpha” blend mode. |
For use with Premult Alpha textures. |
If the DiffuseMap has an alpha channel, use:
mat.setBoolean("UseAlpha",true);
Later, put the Geometry (not the Material!) in the appropriate render queue.
geo.setQueueBucket(Bucket.Translucent);
or
geo.setQueueBucket(Bucket.Transparent);
Material Option | Usage | Example |
---|---|---|
getAdditionalRenderState() |
Activates back-face culling. Mesh faces that are facing away from the camera are not rendered, which saves time. Backface culling is activated by default as a major optimization. |
The invisible backsides and insides of models are not calculated. |
getAdditionalRenderState() |
No meshes are culled. Both mesh faces are rendered, even if they face away from the camera. Slow. |
Sometimes used to debug custom meshes if you messed up some of the polygon sides, or for special shadow effects. |
getAdditionalRenderState() |
Activates front-face culling. Mesh faces facing the camera are not rendered. |
No example – Typically not used because you wouldn’t see anything meaningful. |
getAdditionalRenderState() |
Culls both backfaces and frontfaces. |
Use this as an efficient way to make an object temporarily invisible, while keeping all its other in-game properties (such as node attachment, collision shapes, interactions, etc.) active. |
Material Option | Useage | Example |
---|---|---|
getAdditionalRenderState() |
Disable writing the color of pixels. |
Use this together with setDepthWrite(true) to write pixels only to the depth buffer, for example. |
getAdditionalRenderState() |
Enables point-sprite mode, e.g. meshes with “Mode”.Points will be rendered as textured sprites. Note that gl_PointCoord must be set in the shader. |
Point sprites are used internally for hardware accelerated particle effects. |
getAdditionalRenderState() |
Enable polygon offset. |
Use this when you have meshes that have triangles really close to each over (e.g. Coplanar), it will shift the depth values to prevent Z-fighting. |
Related Links