Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Material
- Object
- Material
A declarative description of how a surface should be shaded. The 3D engine is
responsible for translating a material into a platform shader (GLSL on OpenGL
ES and WebGL, Metal Shading Language on iOS); applications never write shader
source. A material combines a lighting model (
Type), a base color, an
optional texture and pipeline RenderState.Nested types
enum Material.Type | The built in lighting model used to shade a surface. |
Constructors
public Material() | Creates an unlit white material. |
public Material(Material.Type type) | Creates a material of the supplied type. |
Methods
public Material.Type getType() | Returns the lighting model. |
public Material setType(Material.Type type) | Sets the lighting model. |
public int getColor() | Returns the base color as a packed ARGB integer. |
public Material setColor(int argb) | Sets the base color as a packed ARGB integer (0xAARRGGBB). |
public Texture getTexture() | Returns the diffuse texture, or null when the material is untextured. |
public Material setTexture(Texture texture) | Sets the diffuse texture. |
public float getShininess() | Returns the Phong specular exponent. |
public Material setShininess(float shininess) | Sets the Phong specular exponent (used only by Type.PHONG). |
public RenderState getRenderState() | Returns the pipeline render state. |
public Material setRenderState(RenderState renderState) | Sets the pipeline render state. |
public float getMetallic() | Returns how metallic a Type.PBR surface is, from 0 (a dielectric such as paint, plastic or wood) to 1 (bare metal). |
public Material setMetallic(float metallic) | Sets how metallic a Type.PBR surface is. |
public float getRoughness() | Returns how rough a Type.PBR surface is, from 0 (mirror) to 1 (chalk). |
public Material setRoughness(float roughness) | Sets how rough a Type.PBR surface is. |
public int getEmissive() | Returns the light the surface gives off by itself, as RGB in an ARGB int; black for none. |
public Material setEmissive(int argb) | Sets the light the surface gives off by itself: a lamp, a screen, wet paint catching the sun. |
public boolean isReceiveShadows() | Returns true if the surface is darkened by shadows the light casts. |
public Material setReceiveShadows(boolean receiveShadows) | Sets whether the surface is darkened by the light’s shadows. |
public boolean isCastShadows() | Returns true if geometry drawn with this material casts a shadow. |
public Material setCastShadows(boolean castShadows) | Sets whether geometry drawn with this material casts a shadow. |
public boolean isLit() | Returns true if this material is lit by the directional light. |
public String getShaderKey() | Returns a stable string identifying the shader variant required by this material. |
Inherited methods
Constructor details
Material
public Material()Creates an unlit white material.
Material
public Material(Material.Type type)Creates a material of the supplied type.
Parameters
typeMaterial.Type- the lighting model
Method details
getType
public Material.Type getType()Returns the lighting model.
setType
public Material setType(Material.Type type)Sets the lighting model.
Parameters
typeMaterial.Type- the lighting model
Returns
this material for chaining
getColor
public int getColor()Returns the base color as a packed ARGB integer.
setColor
public Material setColor(int argb)Sets the base color as a packed ARGB integer (0xAARRGGBB).
Parameters
argbint- the packed ARGB color
Returns
this material for chaining
getTexture
public Texture getTexture()Returns the diffuse texture, or null when the material is untextured.
setTexture
public Material setTexture(Texture texture)Sets the diffuse texture. Pass null for an untextured material.
Parameters
textureTexture- the diffuse texture or null
Returns
this material for chaining
getShininess
public float getShininess()Returns the Phong specular exponent.
setShininess
public Material setShininess(float shininess)Sets the Phong specular exponent (used only by
Type.PHONG).Parameters
shininessfloat- the specular exponent
Returns
this material for chaining
getRenderState
public RenderState getRenderState()Returns the pipeline render state.
setRenderState
public Material setRenderState(RenderState renderState)Sets the pipeline render state.
Parameters
renderStateRenderState- the render state
Returns
this material for chaining
getMetallic
public float getMetallic()Returns how metallic a
Type.PBR surface is, from 0 (a dielectric such
as paint, plastic or wood) to 1 (bare metal).setMetallic
public Material setMetallic(float metallic)Sets how metallic a
Type.PBR surface is.Parameters
metallicfloat- 0 for a dielectric, 1 for metal
Returns
this material for chaining
getRoughness
public float getRoughness()Returns how rough a
Type.PBR surface is, from 0 (mirror) to 1 (chalk).setRoughness
public Material setRoughness(float roughness)Sets how rough a
Type.PBR surface is. Rough surfaces spread their
highlight wide and dim; smooth ones make it small and bright.Parameters
roughnessfloat- 0 for a mirror, 1 for fully diffuse
Returns
this material for chaining
getEmissive
public int getEmissive()Returns the light the surface gives off by itself, as RGB in an ARGB
int; black for none.
setEmissive
public Material setEmissive(int argb)Sets the light the surface gives off by itself: a lamp, a screen, wet
paint catching the sun. Emissive colour is added after lighting and is
what a bloom post effect picks up. Used by
Type.PBR, Type.LAMBERT
and Type.PHONG.Parameters
argbint- the emitted colour; black for none
Returns
this material for chaining
isReceiveShadows
public boolean isReceiveShadows()Returns true if the surface is darkened by shadows the light casts.
setReceiveShadows
public Material setReceiveShadows(boolean receiveShadows)Sets whether the surface is darkened by the light’s shadows. A ground
plane receives them; a particle or a muzzle flash should not.
Parameters
receiveShadowsboolean- true to receive shadows
Returns
this material for chaining
isCastShadows
public boolean isCastShadows()Returns true if geometry drawn with this material casts a shadow.
setCastShadows
public Material setCastShadows(boolean castShadows)Sets whether geometry drawn with this material casts a shadow.
Transparent and unlit effects normally should not.
Parameters
castShadowsboolean- true to cast shadows
Returns
this material for chaining
isLit
public boolean isLit()Returns true if this material is lit by the directional light.
getShaderKey
public String getShaderKey()Returns a stable string identifying the shader variant required by this
material. Backends use it together with the mesh
VertexFormat to cache
generated and compiled shader programs. The key intentionally depends
only on properties that change the generated source, not on values such
as the color which are passed as uniforms.Returns
a shader variant cache key