Class Material
- All Implemented Interfaces:
- CloneableSmartAsset,- Savable,- Cloneable
Material describes the rendering style for a given
 Geometry.
 A material is essentially a list of parameters,
 those parameters map to uniforms which are defined in a shader.
 Setting the parameters can modify the behavior of a
 shader.
 
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classTrack bind ids for textures and buffers Used internally
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionMaterial()Do not use this constructor.Material(AssetManager contentMan, String defName) Material(MaterialDef def) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidclearParam(String name) Clear a parameter from this material.clone()Clones this material.booleancontentEquals(Object otherObj) Compares two materials and returns true if they are equal.intWorks likeObject.hashCode()except it may change together with the material as the material is mutable by definition.Returns the currently active technique.Acquire the additionalrender stateto apply for this material.Returns the asset key name of the asset from which this material was loaded.getKey()Returns the asset key that is used to track this asset for garbage collection.Get the material definition (j3md file info) thatthismaterial is implementing.getName()Returns the parameter set on this material with the given name, returnsnullif the parameter is not set.Returns a collection of all parameters set on this material.Returns the ListMap of all parameters set on this material.<T> TgetParamValue(String name) Returns the current parameter's value.intReturns the sorting ID or sorting index for this material.getTextureParam(String name) Returns the texture parameter set on this material with the given name, returnsnullif the parameter is not set.booleanCheck if the material should receive shadows or not.booleanCheck if the transparent value marker is set on this material.voidpreload(RenderManager renderManager, Geometry geometry) Preloads this material for the given render manager.voidread(JmeImporter im) voidrender(Geometry geometry, LightList lights, RenderManager renderManager) Called byRenderManagerto render the geometry by using this material.voidrender(Geometry geom, RenderManager rm) Called byRenderManagerto render the geometry by using this material.voidselectTechnique(String name, RenderManager renderManager) Select the technique to use for rendering this material.voidsetBoolean(String name, boolean value) Pass a boolean to the material shader.voidPass a Color to the material shader.voidPass a float to the material shader.voidPass a float to the material shader.voidPass an int to the material shader.voidAssigns the specified AssetKey to the asset.voidsetMatrix4(String name, Matrix4f value) Pass a Matrix4f to the material shader.voidThis method sets the name of the material.voidPass a parameter to the material shader.voidPass a parameter to the material shader.voidsetReceivesShadows(boolean receivesShadows) Set if the material should receive shadows or not.voidsetShaderStorageBufferObject(String name, BufferObject value) Pass a shader storage buffer object to the material shader.voidsetTexture(String name, Texture value) Pass a texture to the material shader.voidsetTextureParam(String name, VarType type, Texture value) Set a texture parameter.voidsetTransparent(boolean transparent) Set the transparent value marker.voidsetUniformBufferObject(String name, BufferObject value) Pass an uniform buffer object to the material shader.voidsetVector2(String name, Vector2f value) Pass a Vector2f to the material shader.voidsetVector3(String name, Vector3f value) Pass a Vector3f to the material shader.voidsetVector4(String name, Vector4f value) Pass a Vector4f to the material shader.toString()voidwrite(JmeExporter ex) 
- 
Field Details- 
SAVABLE_VERSIONpublic static final int SAVABLE_VERSION- See Also:
 
 
- 
- 
Constructor Details- 
Material
- 
Material
- 
Materialpublic Material()Do not use this constructor. Serialization purposes only.
 
- 
- 
Method Details- 
getAssetNameReturns the asset key name of the asset from which this material was loaded.This value will be nullunless this material was loaded from a .j3m file.- Returns:
- Asset key name of the j3m file
 
- 
getName- Returns:
- the name of the material (not the same as the asset name), the returned value can be null
 
- 
setNameThis method sets the name of the material. The name is not the same as the asset name. It can be null and there is no guarantee of its uniqueness.- Parameters:
- name- the name of the material
 
- 
setKeyDescription copied from interface:CloneableSmartAssetAssigns the specified AssetKey to the asset. This is invoked by theAssetManager. Only clones of the asset have non-null keys. The original copy that was loaded has no key assigned. Only the clones are tracked for garbage collection.- Specified by:
- setKeyin interface- CloneableSmartAsset
- Parameters:
- key- The AssetKey to assign
 
- 
getKeyDescription copied from interface:CloneableSmartAssetReturns the asset key that is used to track this asset for garbage collection.- Specified by:
- getKeyin interface- CloneableSmartAsset
- Returns:
- the asset key that is used to track this asset for garbage collection.
 
- 
getSortIdpublic int getSortId()Returns the sorting ID or sorting index for this material.The sorting ID is used internally by the system to sort rendering of geometries. It sorted to reduce shader switches, if the shaders are equal, then it is sorted by textures. - Returns:
- The sorting ID used for sorting geometries for rendering.
 
- 
cloneClones this material. The result is returned.- Specified by:
- clonein interface- CloneableSmartAsset
- Overrides:
- clonein class- Object
- Returns:
- A clone of this asset. The cloned asset cannot reference equal this asset.
 
- 
contentEqualsCompares two materials and returns true if they are equal. This methods compare definition, parameters, additional render states. Since materials are mutable objects, implementing equals() properly is not possible, hence the name contentEquals().- Parameters:
- otherObj- the material to compare to this material
- Returns:
- true if the materials are equal.
 
- 
contentHashCodepublic int contentHashCode()Works likeObject.hashCode()except it may change together with the material as the material is mutable by definition.- Returns:
- value for use in hashing
 
- 
getActiveTechniqueReturns the currently active technique.The technique is selected automatically by the RenderManagerbased on system capabilities. Users may select their own technique by usingselectTechnique(java.lang.String, com.jme3.renderer.RenderManager).- Returns:
- the currently active technique.
- See Also:
 
- 
isTransparentpublic boolean isTransparent()Check if the transparent value marker is set on this material.- Returns:
- True if the transparent value marker is set on this material.
- See Also:
 
- 
setTransparentpublic void setTransparent(boolean transparent) Set the transparent value marker.This value is merely a marker, by itself it does nothing. Generally model loaders will use this marker to indicate further up that the material is transparent and therefore any geometries using it should be put into the transparent bucket.- Parameters:
- transparent- the transparent value marker.
 
- 
isReceivesShadowspublic boolean isReceivesShadows()Check if the material should receive shadows or not.- Returns:
- True if the material should receive shadows.
- See Also:
 
- 
setReceivesShadowspublic void setReceivesShadows(boolean receivesShadows) Set if the material should receive shadows or not.This value is merely a marker, by itself it does nothing. Generally model loaders will use this marker to indicate the material should receive shadows and therefore any geometries using it should have RenderQueue.ShadowMode.Receiveset on them.- Parameters:
- receivesShadows- if the material should receive shadows or not.
 
- 
getAdditionalRenderStateAcquire the additionalrender stateto apply for this material.The first call to this method will create an additional render state which can be modified by the user to apply any render states in addition to the ones used by the renderer. Only render states which are modified in the additional render state will be applied. - Returns:
- The additional render state.
 
- 
getMaterialDefGet the material definition (j3md file info) thatthismaterial is implementing.- Returns:
- the material definition this material implements.
 
- 
getParamReturns the parameter set on this material with the given name, returnsnullif the parameter is not set.- Parameters:
- name- The parameter name to look up.
- Returns:
- The MatParam if set, or null if not set.
 
- 
getParamValueReturns the current parameter's value.- Type Parameters:
- T- the expected type of the parameter value
- Parameters:
- name- the parameter name to look up.
- Returns:
- current value or null if the parameter wasn't set.
 
- 
getTextureParamReturns the texture parameter set on this material with the given name, returnsnullif the parameter is not set.- Parameters:
- name- The parameter name to look up.
- Returns:
- The MatParamTexture if set, or null if not set.
 
- 
getParamsReturns a collection of all parameters set on this material.- Returns:
- a collection of all parameters set on this material.
- See Also:
 
- 
getParamsMapReturns the ListMap of all parameters set on this material.- Returns:
- a ListMap of all parameters set on this material.
- See Also:
 
- 
setParamPass a parameter to the material shader.- Parameters:
- name- the name of the parameter defined in the material definition (j3md)
- type- the type of the parameter- VarType
- value- the value of the parameter
 
- 
setParamPass a parameter to the material shader.- Parameters:
- name- the name of the parameter defined in the material definition (j3md)
- value- the value of the parameter
 
- 
clearParamClear a parameter from this material. The parameter must exist- Parameters:
- name- the name of the parameter to clear
 
- 
setTextureParamSet a texture parameter.- Parameters:
- name- The name of the parameter
- type- The variable type- VarType
- value- The texture value of the parameter.
- Throws:
- IllegalArgumentException- is value is null
 
- 
setTexturePass a texture to the material shader.- Parameters:
- name- the name of the texture defined in the material definition (j3md) (for example Texture for Lighting.j3md)
- value- the Texture object previously loaded by the asset manager
 
- 
setMatrix4Pass a Matrix4f to the material shader.- Parameters:
- name- the name of the matrix defined in the material definition (j3md)
- value- the Matrix4f object
 
- 
setBooleanPass a boolean to the material shader.- Parameters:
- name- the name of the boolean defined in the material definition (j3md)
- value- the boolean value
 
- 
setFloatPass a float to the material shader.- Parameters:
- name- the name of the float defined in the material definition (j3md)
- value- the float value
 
- 
setFloatPass a float to the material shader. This version avoids auto-boxing if the value is already a Float.- Parameters:
- name- the name of the float defined in the material definition (j3md)
- value- the float value
 
- 
setIntPass an int to the material shader.- Parameters:
- name- the name of the int defined in the material definition (j3md)
- value- the int value
 
- 
setColorPass a Color to the material shader.- Parameters:
- name- the name of the color defined in the material definition (j3md)
- value- the ColorRGBA value
 
- 
setUniformBufferObjectPass an uniform buffer object to the material shader.- Parameters:
- name- the name of the buffer object defined in the material definition (j3md).
- value- the buffer object.
 
- 
setShaderStorageBufferObjectPass a shader storage buffer object to the material shader.- Parameters:
- name- the name of the buffer object defined in the material definition (j3md).
- value- the buffer object.
 
- 
setVector2Pass a Vector2f to the material shader.- Parameters:
- name- the name of the Vector2f defined in the material definition (j3md)
- value- the Vector2f value
 
- 
setVector3Pass a Vector3f to the material shader.- Parameters:
- name- the name of the Vector3f defined in the material definition (j3md)
- value- the Vector3f value
 
- 
setVector4Pass a Vector4f to the material shader.- Parameters:
- name- the name of the Vector4f defined in the material definition (j3md)
- value- the Vector4f value
 
- 
selectTechniqueSelect the technique to use for rendering this material.Any candidate technique for selection (either default or named) must be verified to be compatible with the system, for that, the renderManageris queried for capabilities.- Parameters:
- name- The name of the technique to select, pass- TechniqueDef.DEFAULT_TECHNIQUE_NAMEto select one of the default techniques.
- renderManager- The- render managerto query for capabilities.
- Throws:
- IllegalArgumentException- If no technique exists with the given name.
- UnsupportedOperationException- If no candidate technique supports the system capabilities.
 
- 
preloadPreloads this material for the given render manager.Preloading the material can ensure that when the material is first used for rendering, there won't be any delay since the material has been already been setup for rendering. - Parameters:
- renderManager- The render manager to preload for
- geometry- to determine the applicable parameter overrides, if any
 
- 
renderCalled byRenderManagerto render the geometry by using this material.The material is rendered as follows: - Determine which technique to use to render the material -
 either what the user selected via
 Material.selectTechnique(), or the first default technique that the renderer supports (based on the technique'srequested rendering capabilities)- If the technique has been changed since the last frame, then it is notified via
 Technique.makeCurrent(). If the technique wants to use a shader to render the model, it should load it at this part - the shader should have all the proper defines as declared in the technique definition, including those that are bound to material parameters. The technique can re-use the shader from the last frame if no changes to the defines occurred.
 
- If the technique has been changed since the last frame, then it is notified via
 
- Set the RenderStateto use for rendering. The render states are applied in this order (later RenderStates override earlier RenderStates):- Technique Definition's RenderState- i.e. specific RenderState that is required for the shader.
- Material Instance Additional RenderState- i.e. ad-hoc RenderState set per model
- RenderManager's Forced RenderState- i.e. RenderState requested by a- SceneProcessoror post-processing filter.
 
- If the technique uses a shader, then the uniforms of the shader must be updated.- Uniforms bound to material parameters are updated based on the current material parameter values.
- Uniforms bound to world parameters are updated from the RenderManager.
 Internally UniformBindingManageris used for this task.
- Uniforms bound to textures will cause the texture to be uploaded as necessary. The uniform is set to the texture unit where the texture is bound.
 
- If the technique uses a shader, the model is then rendered according
 to the lighting mode specified on the technique definition.- single pass light modefills the shader's light uniform arrays with the first 4 lights and renders the model once.
- multi pass light modelight mode renders the model multiple times, for the first light it is rendered opaque, on subsequent lights it is rendered with- alpha-additiveblending and depth writing disabled.
 
- For techniques that do not use shaders,
 fixed function OpenGL is used to render the model (see GLRendererinterface):- OpenGL state that is bound to material parameters is updated.
- The texture set on the material is uploaded and bound. Currently only 1 texture is supported for fixed function techniques.
- If the technique uses lighting, then OpenGL lighting state is updated based on the light list on the geometry, otherwise OpenGL lighting is disabled.
- The mesh is uploaded and rendered.
 
 - Parameters:
- geometry- The geometry to render
- lights- Presorted and filtered light list to use for rendering
- renderManager- The render manager requesting the rendering
 
- Determine which technique to use to render the material -
 either what the user selected via
 
- 
renderCalled byRenderManagerto render the geometry by using this material. Note that this version of the render method does not perform light filtering.- Parameters:
- geom- The geometry to render
- rm- The render manager requesting the rendering
 
- 
write- Specified by:
- writein interface- Savable
- Throws:
- IOException
 
- 
toString
- 
read- Specified by:
- readin interface- Savable
- Throws:
- IOException
 
 
-