Java Code Examples for com.jme3.material.Material#selectTechnique()
The following examples show how to use
com.jme3.material.Material#selectTechnique() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestShaderNodes.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { flyCam.setMoveSpeed(20); Logger.getLogger("com.jme3").setLevel(Level.WARNING); Box boxshape1 = new Box(1f, 1f, 1f); Geometry cube_tex = new Geometry("A Textured Box", boxshape1); Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md"); mat.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager); Technique t = mat.getActiveTechnique(); for (Shader.ShaderSource shaderSource : t.getDef().getShader(assetManager, renderer.getCaps(), t.getDynamicDefines()).getSources()) { System.out.println(shaderSource.getSource()); } mat.setColor("Color", ColorRGBA.Yellow); mat.setTexture("ColorMap", tex); cube_tex.setMaterial(mat); rootNode.attachChild(cube_tex); }
Example 2
Source File: OpaqueComparatorTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testSortByTechnique() { Material lightingMatDefault = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material lightingPreShadow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material lightingPostShadow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material lightingMatPreNormalPass = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material lightingMatGBuf = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material lightingMatGlow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); lightingMatDefault.setName("TechDefault"); lightingMatDefault.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager); lightingPostShadow.setName("TechPostShad"); lightingPostShadow.selectTechnique("PostShadow", renderManager); lightingPreShadow.setName("TechPreShad"); lightingPreShadow.selectTechnique("PreShadow", renderManager); lightingMatPreNormalPass.setName("TechNorm"); lightingMatPreNormalPass.selectTechnique("PreNormalPass", renderManager); lightingMatGlow.setName("TechGlow"); lightingMatGlow.selectTechnique("Glow", renderManager); testSort(lightingMatGlow, lightingPreShadow, lightingMatPreNormalPass, lightingMatDefault, lightingPostShadow); }
Example 3
Source File: RenderManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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 com.jme3.material.MaterialDef#getTechniqueDefsNames() 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 com.jme3.material.Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager) * @see com.jme3.material.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(); //if forcedTechnique we try to force it for render, //if it does not exists in the mat def, we check for forcedMaterial and render the geom if not null //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); } }
Example 4
Source File: OpaqueComparatorTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testSortByAll() { Material matBase1 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material matBase2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); Texture texBase = createTexture("BASE"); texBase.getImage().setId(1); Texture tex1 = createTexture("1"); tex1.getImage().setId(2); Texture tex2 = createTexture("2"); tex2.getImage().setId(3); matBase1.setName("BASE"); matBase1.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager); matBase1.setBoolean("UseVertexColor", true); matBase1.setTexture("DiffuseMap", texBase); Material mat1100 = matBase1.clone(); mat1100.setName("1100"); mat1100.selectTechnique("PreShadow", renderManager); Material mat1101 = matBase1.clone(); mat1101.setName("1101"); mat1101.selectTechnique("PreShadow", renderManager); mat1101.setTexture("DiffuseMap", tex1); Material mat1102 = matBase1.clone(); mat1102.setName("1102"); mat1102.selectTechnique("PreShadow", renderManager); mat1102.setTexture("DiffuseMap", tex2); Material mat1110 = matBase1.clone(); mat1110.setName("1110"); mat1110.selectTechnique("PreShadow", renderManager); mat1110.setFloat("AlphaDiscardThreshold", 2f); Material mat1120 = matBase1.clone(); mat1120.setName("1120"); mat1120.selectTechnique("PreShadow", renderManager); mat1120.setBoolean("UseInstancing", true); Material mat1121 = matBase1.clone(); mat1121.setName("1121"); mat1121.selectTechnique("PreShadow", renderManager); mat1121.setBoolean("UseInstancing", true); mat1121.setTexture("DiffuseMap", tex1); Material mat1122 = matBase1.clone(); mat1122.setName("1122"); mat1122.selectTechnique("PreShadow", renderManager); mat1122.setBoolean("UseInstancing", true); mat1122.setTexture("DiffuseMap", tex2); Material mat1140 = matBase1.clone(); mat1140.setName("1140"); mat1140.selectTechnique("PreShadow", renderManager); mat1140.setFloat("AlphaDiscardThreshold", 2f); mat1140.setBoolean("UseInstancing", true); Material mat1200 = matBase1.clone(); mat1200.setName("1200"); mat1200.selectTechnique("PostShadow", renderManager); Material mat1210 = matBase1.clone(); mat1210.setName("1210"); mat1210.selectTechnique("PostShadow", renderManager); mat1210.setFloat("AlphaDiscardThreshold", 2f); Material mat1220 = matBase1.clone(); mat1220.setName("1220"); mat1220.selectTechnique("PostShadow", renderManager); mat1220.setBoolean("UseInstancing", true); Material mat2000 = matBase2.clone(); mat2000.setName("2000"); testSort(mat1100, mat1101, mat1102, mat1110, mat1120, mat1121, mat1122, mat1140, mat1200, mat1210, mat1220, mat2000); }