<solved> RenderPass and MaterialStates, JME2

Hallo,



could it be that RenderPasses don’t like MaterialStates? I’ve tried to attach a quad with a white Texture and a MaterialState that should looks the Quad blue. But there is only shown the white Quad.



I’ve tried to set the MaterialState to the Quad, the Node and to the RenderPass but it’s always the same result.



[java]

private Quad createGrid() {



Quad grid = new Quad(“Grid”, 100,100);

grid.setLocalTranslation(0,0,0);

grid.setLocalRotation(new Quaternion().fromAngles(FastMath.HALF_PI, 0, 0));



TextureState tsGrid = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();

Texture tex = TextureManager.loadTexture(Main.class.getClassLoader().getResource(“jmetool/data/texture/gitter.png”));

tex.setApply(Texture.ApplyMode.Combine);

tsGrid.setTexture(tex);



MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();

ms.setAmbient(ColorRGBA.blue);

ms.setDiffuse(ColorRGBA.blue);

ms.setEmissive(ColorRGBA.blue);

ms.setShininess(128);

ms.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);



BlendState bsGrid = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();

bsGrid.setEnabled(true);

bsGrid.setSourceFunction(BlendState.SourceFunction.SourceAlpha);

bsGrid.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);

bsGrid.setBlendEnabled(true);

bsGrid.setTestEnabled(true);

bsGrid.setTestFunction(BlendState.TestFunction.GreaterThan);



ZBufferState zGrid = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();

zGrid.setEnabled(true);



grid.setRenderState(tsGrid);

grid.setRenderState(ms);

grid.setRenderState(bsGrid);

grid.setRenderState(zGrid);

grid.setCullHint(Spatial.CullHint.Never);

grid.updateRenderState();



gridPass = new RenderPass();

gridPass.add(grid);



return grid;

}

[/java]

MaterialStates only work in conjunction with LightState. So: if you dont have a light influencing the Geometry that has the MaterialState set, the MaterialState is ignored.



EDIT: if you want to tint your Geometry without having a Light set you can manipulate the ColorBuffer of the Geometry or just set the ColorBuffer null and use g.setDefaultColor(ColorRGBA.blue.clone());

1 Like

sometimes it is so simple.



thanks, the missing LightState solved the problem.