protected void applyTextures(Material mat) { mat.setTexture("water_reflection", reflectionTexture); mat.setTexture("water_refraction", refractionTexture); mat.setTexture("water_depthmap", depthTexture); mat.setTexture("water_normalmap", normalTexture); mat.setTexture("water_dudvmap", dudvTexture); }
@Override public void simpleInitApp() { /** 1. Create terrain material and load four textures into it. */ mat_terrain = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md"); /** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */ mat_terrain.setTexture( "Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png")); /** 1.2) Add GRASS texture into the red layer (Tex1). */ Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); mat_terrain.setTexture("Tex1", grass); mat_terrain.setFloat("Tex1Scale", 64f); /** 1.3) Add DIRT texture into the green layer (Tex2) */ Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); dirt.setWrap(WrapMode.Repeat); mat_terrain.setTexture("Tex2", dirt); mat_terrain.setFloat("Tex2Scale", 32f); /** 1.4) Add ROAD texture into the blue layer (Tex3) */ Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); mat_terrain.setTexture("Tex3", rock); mat_terrain.setFloat("Tex3Scale", 128f); /** 2. Create the height map */ AbstractHeightMap heightmap = null; Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png"); heightmap = new ImageBasedHeightMap(heightMapImage.getImage()); heightmap.load(); /** * 3. We have prepared material and heightmap. Now we create the actual terrain: 3.1) Create a * TerrainQuad and name it "my terrain". 3.2) A good value for terrain tiles is 64x64 -- so we * supply 64+1=65. 3.3) We prepared a heightmap of size 512x512 -- so we supply 512+1=513. 3.4) * As LOD step scale we supply Vector3f(1,1,1). 3.5) We supply the prepared heightmap itself. */ int patchSize = 65; terrain = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap()); /** 4. We give the terrain its material, position & scale it, and attach it. */ terrain.setMaterial(mat_terrain); terrain.setLocalTranslation(0, -100, 0); terrain.setLocalScale(2f, 1f, 2f); rootNode.attachChild(terrain); /** 5. The LOD (level of detail) depends on were the camera is: */ TerrainLodControl control = new TerrainLodControl(terrain, getCamera()); terrain.addControl(control); inputManager.removeListener(flyCam); final RTSCam rtsCam = new RTSCam(cam, rootNode); rtsCam.registerWithInput(inputManager); rtsCam.setCenter(new Vector3f(0, 5f, 0)); }
public Terrain(MonkeyWar war) { /** 1. Create terrain material and load four textures into it. */ material = new Material(war.getAssetManager(), "Common/MatDefs/Terrain/Terrain.j3md"); /** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */ material.setTexture( "Alpha", war.getAssetManager().loadTexture("Textures/Terrain/splat/alphamap.png")); /** 1.2) Add GRASS texture into the red layer (Tex1). */ Texture grass = war.getAssetManager().loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); material.setTexture("Tex1", grass); material.setFloat("Tex1Scale", 64f); /** 1.3) Add DIRT texture into the green layer (Tex2) */ Texture dirt = war.getAssetManager().loadTexture("Textures/Terrain/splat/dirt.jpg"); dirt.setWrap(WrapMode.Repeat); material.setTexture("Tex2", dirt); material.setFloat("Tex2Scale", 32f); /** 1.4) Add ROAD texture into the blue layer (Tex3) */ Texture rock = war.getAssetManager().loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); material.setTexture("Tex3", rock); material.setFloat("Tex3Scale", 128f); /** 2. Create the height map */ AbstractHeightMap heightmap = null; Texture heightMapImage = war.getAssetManager().loadTexture("Textures/Terrain/splat/mountains512.png"); heightmap = new ImageBasedHeightMap(heightMapImage.getImage()); heightmap.load(); /** * 3. We have prepared material and heightmap. Now we create the actual terrain: 3.1) Create a * TerrainQuad and name it "my terrain". 3.2) A good value for terrain tiles is 64x64 -- so we * supply 64+1=65. 3.3) We prepared a heightmap of size 512x512 -- so we supply 512+1=513. 3.4) * As LOD step scale we supply Vector3f(1,1,1). 3.5) We supply the prepared heightmap itself. */ int patchSize = 65; quad = new TerrainQuad("my terrain", patchSize, 513, heightmap.getHeightMap()); /** 4. We give the terrain its material, position & scale it, and attach it. */ quad.setMaterial(material); quad.setLocalScale(2f, 1f, 2f); Terrain.node.attachChild(quad); /** 5. The LOD (level of detail) depends on were the camera is: */ TerrainLodControl lod = new TerrainLodControl(quad, war.getCamera()); quad.addControl(lod); /** ATTACH THE TERRAIN CONTROL TO THE TERRAIN */ quad.addControl(this); }
private void createTerrain() { // First, we load up our textures and the heightmap texture for the terrain // TERRAIN TEXTURE material matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md"); matTerrain.setBoolean("useTriPlanarMapping", false); matTerrain.setBoolean("WardIso", true); matTerrain.setFloat("Shininess", 0); // ALPHA map (for splat textures) matTerrain.setTexture( "AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png")); // GRASS texture Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); grass.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap", grass); matTerrain.setFloat("DiffuseMap_0_scale", grassScale); // DIRT texture Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); dirt.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap_1", dirt); matTerrain.setFloat("DiffuseMap_1_scale", dirtScale); // ROCK texture Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); rock.setWrap(WrapMode.Repeat); matTerrain.setTexture("DiffuseMap_2", rock); matTerrain.setFloat("DiffuseMap_2_scale", rockScale); // HEIGHTMAP image (for the terrain heightmap) Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png"); AbstractHeightMap heightmap = null; try { heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.5f); heightmap.load(); heightmap.smooth(0.9f, 1); } catch (Exception e) { e.printStackTrace(); } // CREATE THE TERRAIN terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); TerrainLodControl control = new TerrainLodControl(terrain, getCamera()); control.setLodCalculator(new DistanceLodCalculator(65, 2.7f)); // patch size, and a multiplier terrain.addControl(control); terrain.setMaterial(matTerrain); terrain.setLocalTranslation(0, -100, 0); terrain.setLocalScale(2.5f, 0.5f, 2.5f); rootNode.attachChild(terrain); }
/** for internal use only */ protected void setPostShadowParams() { setMaterialParameters(postshadowMat); for (int j = 0; j < nbShadowMaps; j++) { postshadowMat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]); postshadowMat.setTexture("ShadowMap" + j, shadowMaps[j]); } }
public void renderImage( RenderImage image, int x, int y, int width, int height, Color color, float imageScale) { RenderImageJme jmeImage = (RenderImageJme) image; textureColorMaterial.setColor("Color", convertColor(color, tempColor)); textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture()); quad.clearBuffer(Type.TexCoord); quad.setBuffer(quadDefaultTC); float x0 = x + 0.5f * width * (1f - imageScale); float y0 = y + 0.5f * height * (1f - imageScale); tempMat.loadIdentity(); tempMat.setTranslation(x0, getHeight() - y0, 0); tempMat.setScale(width * imageScale, height * imageScale, 0); rm.setWorldMatrix(tempMat); rm.setForcedRenderState(renderState); textureColorMaterial.render(quadGeom, rm); // System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", // jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), // imageScale); }
private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) { this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md"); shadowFB = new FrameBuffer[nbShadowMaps]; shadowMaps = new Texture2D[nbShadowMaps]; dispPic = new Picture[nbShadowMaps]; lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps]; // DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8); preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md"); postshadowMat.setFloat("ShadowMapSize", shadowMapSize); for (int i = 0; i < nbShadowMaps; i++) { lightViewProjectionsMatrices[i] = new Matrix4f(); shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1); shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth); shadowFB[i].setDepthTexture(shadowMaps[i]); // DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) shadowFB[i].setColorTexture(dummyTex); postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]); // quads for debuging purpose dispPic[i] = new Picture("Picture" + i); dispPic[i].setTexture(assetManager, shadowMaps[i], false); } setShadowCompareMode(shadowCompareMode); setEdgeFilteringMode(edgeFilteringMode); setShadowIntensity(shadowIntensity); }
public void generateRandomAsteroid() { Material asteroidMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); asteroidMaterial.setTexture( "DiffuseMap", assetManager.loadTexture("Textures/Asteroid/Solid.png")); asteroidMaterial.setTexture( "NormalMap", assetManager.loadTexture("Textures/Asteroid/Normal.png")); Asteroid asteroid = new Asteroid("Asteroid", assetManager.loadModel("Models/Asteroid.j3o"), asteroidMaterial); asteroid.getModel().scale((float) Math.random() / 2); if (Math.random() * noComet < 0.05) { asteroid.getModel().scale((float) Math.random() / 2); asteroid.addTrail( new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"), assetManager.loadTexture("Effects/Explosion/flame.png")); asteroid.setSpeed((int) (Math.random() * 4) + 10); noComet = 1; } else { asteroid.setSpeed((int) (Math.random() * 4) + 4); noComet -= 0.05; } rootNode.attachChild(asteroid); float theta = (float) (2 * FastMath.PI * Math.random()); float phi = (float) (2 * FastMath.PI * Math.random()); float r = 120; float x = r * FastMath.cos(theta) * FastMath.sin(phi); float y = r * FastMath.sin(theta) * FastMath.cos(phi); float z = r * FastMath.cos(phi); asteroid.setLocalTranslation(x, y, z); asteroid.setDirection( planets[2] .getGeom() .getWorldTranslation() .subtract(asteroid.getLocalTranslation()) .normalize()); asteroid.setRotation( new Vector3f((float) Math.random(), (float) Math.random(), (float) Math.random()) .normalize()); asteroid.registerPhysics(bap.getPhysicsSpace()); asteroids.attachChild(asteroid); }
PAppletDisplayGeometry( String name, float width, float height, Material material, Texture texture) { super(name); Mesh box = new Box(Vector3f.ZERO, width / 2, height / 2, 0.01f); this.setMesh(box); material.setTexture("ColorMap", texture); this.setMaterial(material); }
/** * iterate through the filter list and renders filters * * @param r * @param sceneFb */ private void renderFilterChain(Renderer r, FrameBuffer sceneFb) { Texture2D tex = filterTexture; FrameBuffer buff = sceneFb; boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1; for (int i = 0; i < filters.size(); i++) { Filter filter = filters.get(i); if (filter.isEnabled()) { if (filter.getPostRenderPasses() != null) { for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator(); it1.hasNext(); ) { Filter.Pass pass = it1.next(); pass.beforeRender(); if (pass.requiresSceneAsTexture()) { pass.getPassMaterial().setTexture("Texture", tex); if (tex.getImage().getMultiSamples() > 1) { pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples()); } else { pass.getPassMaterial().clearParam("NumSamples"); } } if (pass.requiresDepthAsTexture()) { pass.getPassMaterial().setTexture("DepthTexture", depthTexture); if (msDepth) { pass.getPassMaterial() .setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples()); } else { pass.getPassMaterial().clearParam("NumSamplesDepth"); } } renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial()); } } filter.postFrame(renderManager, viewPort, buff, sceneFb); Material mat = filter.getMaterial(); if (msDepth && filter.isRequiresDepthTexture()) { mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples()); } if (filter.isRequiresSceneTexture()) { mat.setTexture("Texture", tex); if (tex.getImage().getMultiSamples() > 1) { mat.setInt("NumSamples", tex.getImage().getMultiSamples()); } else { mat.clearParam("NumSamples"); } } buff = outputBuffer; if (i != lastFilterIndex) { buff = filter.getRenderFrameBuffer(); tex = filter.getRenderedTexture(); } renderProcessing(r, buff, mat); } } }
private void setupEnvironments() { // カメラ設定 cam.setFrustumPerspective(80f, 1f, 1f, 1000f); cam.setLocation(new Vector3f(0, 1.5f, 10)); // cam.lookAt(new Vector3f(0, 1.6f, 0), Vector3f.UNIT_Y); flyCam.setDragToRotate(true); // ライティング DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White.mult(3.0f)); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); // マテリアル設定 Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg")); Material whitemat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"); // 床面 Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(textureMat); floorGeom.setLocalTranslation(0, 0, 0); rootNode.attachChild(floorGeom); // 壁面 wallGeom[0] = new Geometry("Wall1", new Box(Vector3f.ZERO, 20f, 4f, 0.1f)); wallGeom[1] = new Geometry("Wall2", new Box(Vector3f.ZERO, 20f, 4f, 0.1f)); wallGeom[2] = new Geometry("Wall3", new Box(Vector3f.ZERO, 20f, 4f, 0.1f)); wallGeom[0].setMaterial(whitemat); wallGeom[1].setMaterial(whitemat); wallGeom[2].setMaterial(whitemat); wallGeom[0].setLocalTranslation(0, 4, -2); wallGeom[1].setLocalTranslation(-20, 4, 0); wallGeom[2].setLocalTranslation(20, 4, 0); wallGeom[1].rotate(0, (float) (Math.PI / 2f), 0); wallGeom[2].rotate(0, (float) (Math.PI / 2f), 0); rootNode.attachChild(wallGeom[0]); rootNode.attachChild(wallGeom[1]); rootNode.attachChild(wallGeom[2]); // 女性をランダムに追加 for (int i = 0; i < girl.length; i++) { girl[i] = assetManager.loadModel("myAssets/Models/WalkingGirl/WalkingGirl.obj"); girlPos[i] = new Vector3f((float) (Math.random() * 16.0f - 8f), 0, (float) (Math.random() * 8f)); // 移動スピードをランダムに girlSpeed[i] = (float) (Math.random() * -0.02f) + 0.01f; if (girlSpeed[i] < 0) { girl[i].rotate(0, (float) (-Math.PI / 2.0f), 0); } else { girl[i].rotate(0, (float) (Math.PI / 2.0f), 0); } girl[i].setLocalTranslation(girlPos[i]); this.rootNode.attachChild(girl[i]); } }
/** * set the post shadow material for this renderer * * @param postShadowMat */ protected final void setPostShadowMaterial(Material postShadowMat) { this.postshadowMat = postShadowMat; postshadowMat.setFloat("ShadowMapSize", shadowMapSize); for (int i = 0; i < nbShadowMaps; i++) { postshadowMat.setTexture("ShadowMap" + i, shadowMaps[i]); } setShadowCompareMode(shadowCompareMode); setEdgeFilteringMode(edgeFilteringMode); setShadowIntensity(shadowIntensity); }
private void setupBox() { Box boxshape1 = new Box(new Vector3f(-3f, 1.1f, 0f), 1f, 1f, 1f); Geometry cube = new Geometry("My Textured Box", boxshape1); Material mat_stl = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); Texture tex_ml = app.getAssetManager().loadTexture("Textures/test.png"); mat_stl.setTexture("ColorMap", tex_ml); cube.setMaterial(mat_stl); app.getRootNode().attachChild(cube); }
/** Initialize the materials used in this scene. */ public void initMaterials() { wall_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg"); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); wall_mat.setTexture("ColorMap", tex); stone_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = assetManager.loadTexture(key2); stone_mat.setTexture("ColorMap", tex2); floor_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.png"); key3.setGenerateMips(true); Texture tex3 = assetManager.loadTexture(key3); tex3.setWrap(WrapMode.Repeat); floor_mat.setTexture("ColorMap", tex3); }
public static void LoadObjectHelper() { highlightMat = new Material(Main.s_AssetManager, "Common/MatDefs/Misc/Unshaded.j3md"); Texture texture = Main.s_AssetManager.loadTexture("Models/tree.png"); highlightMat.setTexture("ColorMap", texture); greenTrans = new Material(Main.s_AssetManager, "Common/MatDefs/Misc/Unshaded.j3md"); greenTrans.setColor("Color", new ColorRGBA(0, 1, 0, 0.3f)); greenTrans.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); redTrans = new Material(Main.s_AssetManager, "Common/MatDefs/Misc/Unshaded.j3md"); redTrans.setColor("Color", new ColorRGBA(1, 0, 0, 0.3f)); redTrans.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); }
@Override public void simpleInitApp() { // sun DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal()); dl.setColor(ColorRGBA.Orange); rootNode.addLight(dl); // ambient light AmbientLight al = new AmbientLight(); al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f)); rootNode.addLight(al); // floor Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg")); Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(textureMat); rootNode.attachChild(floorGeom); // object Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o"); tree.setQueueBucket(Bucket.Transparent); rootNode.attachChild(tree); // projector PApplet applet = new ColorBarsPApplet(); PAppletProjectorNode projectorNode = new PAppletProjectorNode("projector0", assetManager, applet, 200, 200, true); rootNode.attachChild(projectorNode); rootNode.attachChild( projectorNode .getFrustmMdel()); // if you don't want to see frustum, please don't attach it to // rootNode. // projector should be added to TextureProjectorRenderer, and TextureProjectorRenderer should be // added to ViewPort. TextureProjectorRenderer ptr = new TextureProjectorRenderer(assetManager); ptr.getTextureProjectors().add(projectorNode.getProjector()); viewPort.addProcessor(ptr); // projector is a kind of Shadow, and following processes are necessary for Shadow Rendering. floorGeom.setShadowMode(ShadowMode.Receive); tree.setShadowMode(ShadowMode.CastAndReceive); // tree makes and receives shadow projectorNode.setLocalTranslation(new Vector3f(0, 10, 0)); // move the projector, projectorNode.lookAt( new Vector3f(0, 0, 0), Vector3f.UNIT_X); // and make it to look at where you want. // cam cam.setLocation(Vector3f.UNIT_XYZ.mult(10.0f)); // camera moves to 10, 10, 10 cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); // and looks at 0,0,0. }
public void setAllTex(Texture tex) { frontTex = backTex = leftTex = rightTex = topTex = bottomTex = tex; frontMat.setTexture(textureFieldName, frontTex); backMat.setTexture(textureFieldName, backTex); leftMat.setTexture(textureFieldName, leftTex); rightMat.setTexture(textureFieldName, rightTex); topMat.setTexture(textureFieldName, topTex); bottomMat.setTexture(textureFieldName, bottomTex); }
protected void createMaterial() { Material material; if (alpha < 1f && transparent) { diffuse.a = alpha; } if (shadeless) { material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); material.setColor("Color", diffuse.clone()); material.setTexture("ColorMap", diffuseMap); // TODO: Add handling for alpha map? } else { material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); material.setBoolean("UseMaterialColors", true); material.setColor("Ambient", ambient.clone()); material.setColor("Diffuse", diffuse.clone()); material.setColor("Specular", specular.clone()); material.setFloat("Shininess", shininess); // prevents "premature culling" bug if (diffuseMap != null) material.setTexture("DiffuseMap", diffuseMap); if (specularMap != null) material.setTexture("SpecularMap", specularMap); if (normalMap != null) material.setTexture("NormalMap", normalMap); if (alphaMap != null) material.setTexture("AlphaMap", alphaMap); } if (transparent) { material.setTransparent(true); material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); material.getAdditionalRenderState().setAlphaTest(true); material.getAdditionalRenderState().setAlphaFallOff(0.01f); } material.setName(matName); matList.put(matName, material); }
private void setMatParams() { GeometryList l = viewPort.getQueue().getShadowQueueContent(ShadowMode.Receive); // iteration throught all the geometries of the list to gather the materials matCache.clear(); for (int i = 0; i < l.size(); i++) { Material mat = l.get(i).getMaterial(); // checking if the material has the post technique and adding it to the material cache if (mat.getMaterialDef().getTechniqueDef(postTechniqueName) != null) { if (!matCache.contains(mat)) { matCache.add(mat); } } else { needsfallBackMaterial = true; } } // iterating through the mat cache and setting the parameters for (Material mat : matCache) { mat.setFloat("ShadowMapSize", shadowMapSize); for (int j = 0; j < nbShadowMaps; j++) { mat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]); } for (int j = 0; j < nbShadowMaps; j++) { mat.setTexture("ShadowMap" + j, shadowMaps[j]); } mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware); mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue()); mat.setFloat("PCFEdge", edgesThickness); mat.setFloat("ShadowIntensity", shadowIntensity); setMaterialParameters(mat); } // At least one material of the receiving geoms does not support the post shadow techniques // so we fall back to the forced material solution (transparent shadows won't be supported for // these objects) if (needsfallBackMaterial) { setPostShadowParams(); } }
@Override public void simpleInitApp() { Spatial gameLevel = assetManager.loadModel("Scenes/town/main.j3o"); gameLevel.setLocalTranslation(0, -5.2f, 0); gameLevel.setLocalScale(2); rootNode.attachChild(gameLevel); Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj"); Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); teapot.setMaterial(mat_default); rootNode.attachChild(teapot); // Create a wall with a simple texture from test data Box box = new Box(Vector3f.ZERO, 2.5f, 2.5f, 2.5f); Spatial wall = new Geometry("Box", box); Material mat_brick = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_brick.setTexture( "ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg")); wall.setMaterial(mat_brick); wall.setLocalTranslation(2.0f, -2.5f, 0.0f); rootNode.attachChild(wall); // Display a line of text with a default font guiNode.detachAllChildren(); guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); BitmapText helloText = new BitmapText(guiFont, false); helloText.setSize(guiFont.getCharSet().getRenderedSize()); helloText.setText("Hello World"); helloText.setLocalTranslation(300, helloText.getLineHeight(), 0); guiNode.attachChild(helloText); // Load a model from test_data (OgreXML+material+texture) Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml"); ninja.scale(0.05f, 0.05f, 0.05f); ninja.rotate(0.0f, -3.0f, 0.0f); ninja.setLocalTranslation(0.0f, -5.0f, -2.0f); rootNode.attachChild(ninja); // You must add a light to make the model visible DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f)); rootNode.addLight(sun); }
public void makeToonish(Spatial spatial) { if (spatial instanceof Node) { Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); } else if (spatial instanceof Geometry) { Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")) { Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
/** * Creates a BasicShadowRenderer * * @param manager the asset manager * @param size the size of the shadow map (the map is square) */ public BasicShadowRenderer(AssetManager manager, int size) { shadowFB = new FrameBuffer(size, size, 1); shadowMap = new Texture2D(size, size, Format.Depth); shadowFB.setDepthTexture(shadowMap); shadowCam = new Camera(size, size); // DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash) dummyTex = new Texture2D(size, size, Format.RGBA8); shadowFB.setColorTexture(dummyTex); preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md"); postshadowMat = new Material(manager, "Common/MatDefs/Shadow/BasicPostShadow.j3md"); postshadowMat.setTexture("ShadowMap", shadowMap); dispPic.setTexture(manager, shadowMap, false); for (int i = 0; i < points.length; i++) { points[i] = new Vector3f(); } }
private void initSparks() { sparksEmitter = new ParticleEmitter("Spark", ParticleMesh.Type.Triangle, 20); Material sparkMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); sparkMat.setTexture("Texture", assetManager.loadTexture("Effects/spark.png")); sparksEmitter.setMaterial(sparkMat); sparksEmitter.setImagesX(1); sparksEmitter.setImagesY(1); explosionNode.attachChild(sparksEmitter); sparksEmitter.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f)); // orange sparksEmitter.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, .5f)); sparksEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 25, 0)); sparksEmitter.getParticleInfluencer().setVelocityVariation(1); sparksEmitter.setFacingVelocity(true); sparksEmitter.setGravity(0, 15, 0); sparksEmitter.setStartSize(5f); sparksEmitter.setEndSize(5f); sparksEmitter.setLowLife(.9f); sparksEmitter.setHighLife(1.1f); sparksEmitter.setParticlesPerSec(0); sparksEmitter.setLocalTranslation(pos); }
@Override public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Textures/contenedorMadera.jpg")); geom.setMaterial(mat); rootNode.attachChild(geom); NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort); nifty = niftyDisplay.getNifty(); nifty.fromXml("Interface/Nifty/Probando-NiftyGUI.xml", "start", this); // attach the nifty display to the gui view port as a processor guiViewPort.addProcessor(niftyDisplay); // disable the fly cam // flyCam.setEnabled(false); // flyCam.setDragToRotate(true); inputManager.setCursorVisible(true); }
private void initEmbers() { embersEmitter = new ParticleEmitter("embers", ParticleMesh.Type.Triangle, 50); Material embersMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); embersMat.setTexture("Texture", assetManager.loadTexture("Effects/embers.png")); embersEmitter.setMaterial(embersMat); embersEmitter.setImagesX(1); embersEmitter.setImagesY(1); explosionNode.attachChild(embersEmitter); embersEmitter.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, 1.0f)); embersEmitter.setEndColor(new ColorRGBA(0, 0, 0, 0.5f)); embersEmitter.setStartSize(12f); embersEmitter.setEndSize(18f); embersEmitter.setGravity(0, -.5f, 0); embersEmitter.setLowLife(1.8f); embersEmitter.setHighLife(5f); embersEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3, 0)); embersEmitter.getParticleInfluencer().setVelocityVariation(.5f); embersEmitter.setShape(new EmitterSphereShape(Vector3f.ZERO, 2f)); embersEmitter.setParticlesPerSec(0); embersEmitter.setLocalTranslation(pos); }
public static Material getLightingTexture(String texturePath) { // We first check if the requested texture exist in the material map if (texturesMap.containsKey(texturePath)) { return texturesMap.get(texturePath); } // At this point, we know that the texture doesn't exist. // We must create a new material, add it to the map and return it. Material res = new Material(am, "Common/MatDefs/Light/Lighting.j3md"); Texture t = am.loadTexture(texturePath); t.setWrap(WrapMode.Repeat); t.setAnisotropicFilter(8); res.setTexture("DiffuseMap", t); res.setFloat("Shininess", 10f); // [0,128] // test for envmap // TextureCubeMap envmap = new // TextureCubeMap(assetManager.loadTexture("Textures/cubemap_reflec.dds").getImage()); // res.setTexture("EnvMap", envmap); // res.setVector3("FresnelParams", new Vector3f(0.05f, 0.18f, 0.11f)); // res.setVector3("FresnelParams", new Vector3f(0.05f, 0.05f, 0.05f)); // normal map loading // String normalPath = texturePath.replaceAll(".jpg", "norm.jpg");; // try { // Texture normalMap = assetManager.loadTexture(normalPath); // normalMap.setWrap(WrapMode.Repeat); // normalMap.setAnisotropicFilter(8); // res.setTexture("NormalMap", normalMap); // }catch (Exception e) { // LogUtil.logger.info("No normal map found for "+texturePath); // } texturesMap.put(texturePath, res); return res; }
private void initSmoke() { smokeEmitter = new ParticleEmitter("Smoke emitter", ParticleMesh.Type.Triangle, 20); Material smokeMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); smokeMat.setTexture("Texture", assetManager.loadTexture("Effects/smoketrail.png")); smokeEmitter.setMaterial(smokeMat); smokeEmitter.setImagesX(1); smokeEmitter.setImagesY(3); smokeEmitter.setSelectRandomImage(true); explosionNode.attachChild(smokeEmitter); smokeEmitter.setStartColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 1f)); smokeEmitter.setEndColor(new ColorRGBA(.1f, 0.1f, 0.1f, .5f)); smokeEmitter.setLowLife(4f); smokeEmitter.setHighLife(4f); smokeEmitter.setGravity(0, 2, 0); smokeEmitter.setFacingVelocity(true); smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 6f, 0)); smokeEmitter.getParticleInfluencer().setVelocityVariation(1); smokeEmitter.setStartSize(5f); smokeEmitter.setEndSize(30f); smokeEmitter.setParticlesPerSec(0); smokeEmitter.setLocalTranslation(pos); }
private void initShockwave() { shockwaveEmitter = new ParticleEmitter("Shockwave", ParticleMesh.Type.Triangle, 2); shockwaveEmitter.setLocalTranslation(0, 15, 0); Material shockwaveMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); shockwaveMat.setTexture("Texture", assetManager.loadTexture("Effects/shockwave.png")); shockwaveEmitter.setImagesX(1); shockwaveEmitter.setImagesY(1); shockwaveEmitter.setMaterial(shockwaveMat); explosionEffect.attachChild(shockwaveEmitter); shockwaveEmitter.setFaceNormal(Vector3f.UNIT_Y); shockwaveEmitter.setStartColor(new ColorRGBA(.68f, 0.77f, 0.61f, 1f)); shockwaveEmitter.setEndColor(new ColorRGBA(.68f, 0.77f, 0.61f, 0f)); shockwaveEmitter.setStartSize(5f); shockwaveEmitter.setEndSize(20f); shockwaveEmitter.setGravity(0, 0, 0); shockwaveEmitter.setLowLife(1f); shockwaveEmitter.setHighLife(1f); shockwaveEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0)); shockwaveEmitter.getParticleInfluencer().setVelocityVariation(0f); shockwaveEmitter.setParticlesPerSec(0); shockwaveEmitter.setLocalTranslation(pos); }
public void generateExplosion(Vector3f position) { ParticleEmitter explosion = new ParticleEmitter("Explosion", ParticleMesh.Type.Triangle, 10); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png")); explosion.setMaterial(mat_red); explosion.setImagesX(2); explosion.setImagesY(2); // 2x2 texture animation explosion.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red explosion.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow explosion.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0)); explosion.setGravity(0, 0, 0); explosion.setStartSize(2); explosion.setEndSize(4); explosion.setLowLife(1); explosion.setHighLife(2); explosion.setParticlesPerSec(0); explosion.getParticleInfluencer().setVelocityVariation(4); explosion.setLocalTranslation(position); explosions.attachChild(explosion); explosion.emitAllParticles(); explosionAudio.playInstance(); }
public void generateDebris(Vector3f position) { ParticleEmitter explosion = new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 6); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/Debris.png")); explosion.setMaterial(mat_red); explosion.setImagesX(3); explosion.setImagesY(3); explosion.setRotateSpeed(4); explosion.setSelectRandomImage(true); explosion.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0.4f, 0)); explosion.setStartSize(1); explosion.setEndSize(1); explosion.setStartColor(ColorRGBA.Gray); explosion.setEndColor(ColorRGBA.Gray); explosion.setGravity(0, 0, 0); explosion.setLowLife(6); explosion.setHighLife(8); explosion.setParticlesPerSec(0); explosion.getParticleInfluencer().setVelocityVariation(10); explosion.setLocalTranslation(position); explosions.attachChild(explosion); explosion.emitAllParticles(); }