use of com.jme3.material.RenderState in project jmonkeyengine by jMonkeyEngine.
the class RenderManager method renderGeometry.
/**
* Renders the given geometry.
* <p>
* First the proper world matrix is set, if
* the geometry's {@link Geometry#setIgnoreTransform(boolean) ignore transform}
* feature is enabled, the identity world matrix is used, otherwise, the
* geometry's {@link Geometry#getWorldMatrix() world transform matrix} is used.
* <p>
* Once the world matrix is applied, the proper material is chosen for rendering.
* If a {@link #setForcedMaterial(com.jme3.material.Material) forced material} is
* set on this RenderManager, then it is used for rendering the geometry,
* otherwise, the {@link Geometry#getMaterial() geometry's material} is used.
* <p>
* If a {@link #setForcedTechnique(java.lang.String) forced technique} is
* set on this RenderManager, then it is selected automatically
* on the geometry's material and is used for rendering. Otherwise, one
* of the {@link MaterialDef#getDefaultTechniques() default techniques} is
* used.
* <p>
* If a {@link #setForcedRenderState(com.jme3.material.RenderState) forced
* render state} is set on this RenderManager, then it is used
* for rendering the material, and the material's own render state is ignored.
* Otherwise, the material's render state is used as intended.
*
* @param geom The geometry to render
*
* @see Technique
* @see RenderState
* @see Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager)
* @see Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager)
*/
public void renderGeometry(Geometry geom) {
if (geom.isIgnoreTransform()) {
setWorldMatrix(Matrix4f.IDENTITY);
} else {
setWorldMatrix(geom.getWorldMatrix());
}
// Perform light filtering if we have a light filter.
LightList lightList = geom.getWorldLightList();
if (lightFilter != null) {
filteredLightList.clear();
lightFilter.filterLights(geom, filteredLightList);
lightList = filteredLightList;
}
Material material = geom.getMaterial();
//else the geom is not rendered
if (forcedTechnique != null) {
MaterialDef matDef = material.getMaterialDef();
if (matDef.getTechniqueDefs(forcedTechnique) != null) {
Technique activeTechnique = material.getActiveTechnique();
String previousTechniqueName = activeTechnique != null ? activeTechnique.getDef().getName() : TechniqueDef.DEFAULT_TECHNIQUE_NAME;
geom.getMaterial().selectTechnique(forcedTechnique, this);
//saving forcedRenderState for future calls
RenderState tmpRs = forcedRenderState;
if (geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) {
//forcing forced technique renderState
forcedRenderState = geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState();
}
// use geometry's material
material.render(geom, lightList, this);
material.selectTechnique(previousTechniqueName, this);
//restoring forcedRenderState
forcedRenderState = tmpRs;
//Reverted this part from revision 6197
//If forcedTechnique does not exists, and forcedMaterial is not set, the geom MUST NOT be rendered
} else if (forcedMaterial != null) {
// use forced material
forcedMaterial.render(geom, lightList, this);
}
} else if (forcedMaterial != null) {
// use forced material
forcedMaterial.render(geom, lightList, this);
} else {
material.render(geom, lightList, this);
}
}
use of com.jme3.material.RenderState in project jmonkeyengine by jMonkeyEngine.
the class J3MLoader method readRenderState.
private void readRenderState(List<Statement> renderStates) throws IOException {
renderState = new RenderState();
for (Statement statement : renderStates) {
readRenderStateStatement(statement);
}
technique.setRenderState(renderState);
renderState = null;
}
use of com.jme3.material.RenderState in project jmonkeyengine by jMonkeyEngine.
the class J3MLoader method readAdditionalRenderState.
private void readAdditionalRenderState(List<Statement> renderStates) throws IOException {
renderState = material.getAdditionalRenderState();
for (Statement statement : renderStates) {
readRenderStateStatement(statement);
}
renderState = null;
}
use of com.jme3.material.RenderState in project jmonkeyengine by jMonkeyEngine.
the class RenderDeviceJme method renderImage.
public void renderImage(RenderImage image, int x, int y, int w, int h, int srcX, int srcY, int srcW, int srcH, Color color, float scale, int centerX, int centerY) {
RenderImageJme jmeImage = (RenderImageJme) image;
Texture2D texture = jmeImage.getTexture();
textureColorMaterial.setColor("Color", convertColor(color, tempColor));
textureColorMaterial.setTexture("ColorMap", texture);
float imageWidth = jmeImage.getWidth();
float imageHeight = jmeImage.getHeight();
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData();
float startX = srcX / imageWidth;
float startY = srcY / imageHeight;
float endX = startX + (srcW / imageWidth);
float endY = startY + (srcH / imageHeight);
startY = 1f - startY;
endY = 1f - endY;
texCoords.rewind();
texCoords.put(startX).put(startY);
texCoords.put(endX).put(startY);
texCoords.put(endX).put(endY);
texCoords.put(startX).put(endY);
texCoords.flip();
quadModTC.updateData(texCoords);
quad.clearBuffer(Type.TexCoord);
quad.setBuffer(quadModTC);
float x0 = centerX + (x - centerX) * scale;
float y0 = centerY + (y - centerY) * scale;
tempMat.loadIdentity();
tempMat.setTranslation(x0, getHeight() - y0, 0);
tempMat.setScale(w * scale, h * scale, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
textureColorMaterial.render(quadGeom, rm);
//System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n", texture.getKey().toString(),
// x, y, w, h, srcX, srcY, srcW, srcH,
// color.toString(), scale, centerX, centerY);
}
use of com.jme3.material.RenderState in project jmonkeyengine by jMonkeyEngine.
the class MaterialLoader method compileMaterial.
private Material compileMaterial() {
Material mat;
if (noLight) {
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
} else {
mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
}
mat.setName(matName);
if (blend) {
RenderState rs = mat.getAdditionalRenderState();
mat.setFloat("AlphaDiscardThreshold", 0.01f);
rs.setBlendMode(RenderState.BlendMode.Alpha);
if (twoSide) {
rs.setFaceCullMode(RenderState.FaceCullMode.Off);
}
// rs.setDepthWrite(false);
mat.setTransparent(true);
if (!noLight) {
// mat.setBoolean("UseAlpha", true);
}
} else {
if (twoSide) {
RenderState rs = mat.getAdditionalRenderState();
rs.setFaceCullMode(RenderState.FaceCullMode.Off);
}
}
if (!noLight) {
if (shinines > 0f) {
mat.setFloat("Shininess", shinines);
} else {
// set shininess to some value anyway..
mat.setFloat("Shininess", 16f);
}
if (vcolor)
mat.setBoolean("UseVertexColor", true);
if (textures[0] != null)
mat.setTexture("DiffuseMap", textures[0]);
mat.setBoolean("UseMaterialColors", true);
if (diffuse != null) {
mat.setColor("Diffuse", diffuse);
} else {
mat.setColor("Diffuse", ColorRGBA.White);
}
if (ambient != null) {
mat.setColor("Ambient", ambient);
} else {
mat.setColor("Ambient", ColorRGBA.DarkGray);
}
if (specular != null) {
mat.setColor("Specular", specular);
} else {
mat.setColor("Specular", ColorRGBA.Black);
}
if (emissive != null) {
mat.setColor("GlowColor", emissive);
}
} else {
if (vcolor) {
mat.setBoolean("VertexColor", true);
}
if (textures[0] != null && textures[1] == null) {
if (separateTexCoord) {
mat.setTexture("LightMap", textures[0]);
mat.setBoolean("SeparateTexCoord", true);
} else {
mat.setTexture("ColorMap", textures[0]);
}
} else if (textures[1] != null) {
mat.setTexture("ColorMap", textures[0]);
mat.setTexture("LightMap", textures[1]);
if (separateTexCoord) {
mat.setBoolean("SeparateTexCoord", true);
}
}
if (diffuse != null) {
mat.setColor("Color", diffuse);
}
if (emissive != null) {
mat.setColor("GlowColor", emissive);
}
}
noLight = false;
Arrays.fill(textures, null);
ambient = null;
diffuse = null;
specular = null;
emissive = null;
shinines = 0f;
vcolor = false;
blend = false;
texUnit = 0;
separateTexCoord = false;
twoSide = false;
matName = null;
texName = null;
return mat;
}
Aggregations