Java Code Examples for com.jme3.texture.Texture#setWrap()

The following examples show how to use com.jme3.texture.Texture#setWrap() . 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: TestBrickWall.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example 2
Source File: HelloPhysics.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Initialize the materials used in this scene. */
public void initMaterials() {
  wall_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.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/Unshaded.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/Unshaded.j3md");
  TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
  key3.setGenerateMips(true);
  Texture tex3 = assetManager.loadTexture(key3);
  tex3.setWrap(WrapMode.Repeat);
  floor_mat.setTexture("ColorMap", tex3);
}
 
Example 3
Source File: TestBrickWall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void initMaterial() {
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    mat.setTexture("ColorMap", tex);

    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
    key2.setGenerateMips(true);
    Texture tex2 = assetManager.loadTexture(key2);
    mat2.setTexture("ColorMap", tex2);

    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg");
    key3.setGenerateMips(true);
    Texture tex3 = assetManager.loadTexture(key3);
    tex3.setWrap(WrapMode.Repeat);
    mat3.setTexture("ColorMap", tex3);
}
 
Example 4
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doSetNormalMap(int layer, Texture tex) {
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return;
    if (tex == null) {
        // remove the texture if it is null
        if (layer == 0)
            terrain.getMaterial().clearParam("NormalMap");
        else
            terrain.getMaterial().clearParam("NormalMap_"+layer);
        return;
    }

    tex.setWrap(WrapMode.Repeat);
    
    if (layer == 0)
        terrain.getMaterial().setTexture("NormalMap", tex);
    else
        terrain.getMaterial().setTexture("NormalMap_"+layer, tex);

    setNeedsSave(true);
}
 
Example 5
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doSetNormalMap(int layer, String texturePath) {
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return;

    if (texturePath == null) {
        // remove the texture if it is null
        if (layer == 0)
            terrain.getMaterial().clearParam("NormalMap");
        else
            terrain.getMaterial().clearParam("NormalMap_"+layer);
    } else {
        Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath);
        tex.setWrap(WrapMode.Repeat);

        if (layer == 0)
            terrain.getMaterial().setTexture("NormalMap", tex);
        else
            terrain.getMaterial().setTexture("NormalMap_"+layer, tex);
    }
    enableTextureButtons();
    setNeedsSave(true);
}
 
Example 6
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void doSetDiffuseTexture(int layer, String texturePath) {
    if (texturePath == null || texturePath.equals(""))
        texturePath = DEFAULT_TERRAIN_TEXTURE;

    Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath);
    tex.setWrap(WrapMode.Repeat);
    Terrain terrain = (Terrain) getTerrain(null);
    
    if (layer == 0)
        terrain.getMaterial().setTexture("DiffuseMap", tex);
    else
        terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex);

    doSetTextureScale(layer, DEFAULT_TEXTURE_SCALE);
    
    setNeedsSave(true);
}
 
Example 7
Source File: TestShadowBug.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Geometry makeFloor() {
  Box box = new Box(220, .2f, 220);
  box.scaleTextureCoordinates(new Vector2f(10, 10));
  Geometry floor = new Geometry("the Floor", box);
  floor.setLocalTranslation(200, -9, 200);
  Material matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
  Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
  grass.setWrap(WrapMode.Repeat);
  matGroundL.setTexture("DiffuseMap", grass);
  floor.setMaterial(matGroundL);
  floor.setShadowMode(ShadowMode.CastAndReceive);
  return floor;
}
 
Example 8
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set a new diffuse texture to a level.
 *
 * @param texture the new texture.
 * @param layer   the layer.
 */
@FromAnyThread
public void setDiffuse(@Nullable final Texture texture, final int layer) {

    final Function<Integer, String> layerToDiffuseName = getLayerToDiffuseName();
    if (layerToDiffuseName == null) {
        return;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final String paramName = layerToDiffuseName.apply(layer);
    final MatParam matParam = material.getParam(paramName);
    final Texture current = matParam == null ? null : (Texture) matParam.getValue();

    if (texture != null) {
        texture.setWrap(Texture.WrapMode.Repeat);
    }

    final PropertyOperation<ChangeConsumer, Node, Texture> operation =
            new PropertyOperation<>(getTerrainNode(), TERRAIN_PARAM, texture, current);

    operation.setApplyHandler((node, newTexture) ->
            NodeUtils.visitGeometry(node, geometry -> updateTexture(newTexture, paramName, geometry)));

    final ModelChangeConsumer changeConsumer = paintingComponent.getChangeConsumer();
    changeConsumer.execute(operation);
}
 
Example 9
Source File: TerrainEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void doSetDiffuseTexture(int layer, Texture tex) {
    tex.setWrap(WrapMode.Repeat);
    Terrain terrain = (Terrain) getTerrain(null);
    if (terrain == null)
        return;
    if (layer == 0)
        terrain.getMaterial().setTexture("DiffuseMap", tex);
    else
        terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex);

    setNeedsSave(true);
}
 
Example 10
Source File: PlaceholderAssets.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Material getPlaceholderMaterial(AssetManager assetManager){
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture tex = assetManager.loadTexture("Common/Textures/MissingMaterial.png");
    tex.setWrap(Texture.WrapMode.Repeat);
    mat.setTexture("ColorMap", tex);
    return mat;
}
 
Example 11
Source File: PlaceholderAssets.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Spatial getPlaceholderModel(AssetManager assetManager){
    // What should be the size? Nobody knows
    // the user's expected scale...
    Box box = new Box(1, 1, 1);
    Geometry geom = new Geometry("placeholder", box);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture tex = assetManager.loadTexture("Common/Textures/MissingModel.png");
    tex.setWrap(Texture.WrapMode.Repeat);
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    return geom;
}
 
Example 12
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set a new normal texture to a level.
 *
 * @param texture the normal texture.
 * @param layer   the layer.
 */
@FromAnyThread
public void setNormal(@Nullable final Texture texture, final int layer) {

    final Function<Integer, String> layerToNormalName = getLayerToNormalName();
    if (layerToNormalName == null) {
        return;
    }

    final Terrain terrain = getTerrain();
    final Material material = terrain.getMaterial();
    final String paramName = layerToNormalName.apply(layer);
    final MatParam matParam = material.getParam(paramName);
    final Texture current = matParam == null ? null : (Texture) matParam.getValue();

    if (texture != null) {
        texture.setWrap(Texture.WrapMode.Repeat);
    }

    final PropertyOperation<ChangeConsumer, Node, Texture> operation =
            new PropertyOperation<>(getTerrainNode(), TERRAIN_PARAM, texture, current);

    operation.setApplyHandler((node, newTexture) ->
            NodeUtils.visitGeometry(node, geometry -> updateTexture(newTexture, paramName, geometry)));

    final ModelChangeConsumer changeConsumer = paintingComponent.getChangeConsumer();
    changeConsumer.execute(operation);
}
 
Example 13
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
TiledTerrain() {
    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    matTerrain.setFloat("Shininess", 0);

    // 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);

    // CREATE THE TERRAIN
    terrain1 = new TerrainQuad("terrain 1", 65, 513, null);
    terrain1.setMaterial(matTerrain);
    terrain1.setLocalTranslation(-256, -100, -256);
    terrain1.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain1);

    terrain2 = new TerrainQuad("terrain 2", 65, 513, null);
    terrain2.setMaterial(matTerrain);
    terrain2.setLocalTranslation(-256, -100, 256);
    terrain2.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain2);

    terrain3 = new TerrainQuad("terrain 3", 65, 513, null);
    terrain3.setMaterial(matTerrain);
    terrain3.setLocalTranslation(256, -100, -256);
    terrain3.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain3);

    terrain4 = new TerrainQuad("terrain 4", 65, 513, null);
    terrain4.setMaterial(matTerrain);
    terrain4.setLocalTranslation(256, -100, 256);
    terrain4.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain4);
    
    terrain1.setNeighbourFinder(this);
    terrain2.setNeighbourFinder(this);
    terrain3.setNeighbourFinder(this);
    terrain4.setNeighbourFinder(this);
    
    MultiTerrainLodControl lodControl = new MultiTerrainLodControl(getCamera());
    lodControl.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
    lodControl.addTerrain(terrain1);
    lodControl.addTerrain(terrain2);
    lodControl.addTerrain(terrain3);// order of these seems to matter
    lodControl.addTerrain(terrain4);
    this.addControl(lodControl);
    
}
 
Example 14
Source File: TerrainTestModifyHeight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createTerrainGrid() {
    
    // TERRAIN TEXTURE material
    matTerrain = new Material(this.assetManager, "Common/MatDefs/Terrain/HeightBasedTerrain.j3md");

    // Parameters to material:
    // regionXColorMap: X = 1..4 the texture that should be appliad to state X
    // regionX: a Vector3f containing the following information:
    //      regionX.x: the start height of the region
    //      regionX.y: the end height of the region
    //      regionX.z: the texture scale for the region
    //  it might not be the most elegant way for storing these 3 values, but it packs the data nicely :)
    // slopeColorMap: the texture to be used for cliffs, and steep mountain sites
    // slopeTileFactor: the texture scale for slopes
    // terrainSize: the total size of the terrain (used for scaling the texture)
    // GRASS texture
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("region1ColorMap", grass);
    matTerrain.setVector3("region1", new Vector3f(88, 200, this.grassScale));

    // DIRT texture
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("region2ColorMap", dirt);
    matTerrain.setVector3("region2", new Vector3f(0, 90, this.dirtScale));

    // ROCK texture
    Texture rock = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
    rock.setWrap(WrapMode.Repeat);
    matTerrain.setTexture("region3ColorMap", rock);
    matTerrain.setVector3("region3", new Vector3f(198, 260, this.rockScale));

    matTerrain.setTexture("region4ColorMap", rock);
    matTerrain.setVector3("region4", new Vector3f(198, 260, this.rockScale));

    matTerrain.setTexture("slopeColorMap", rock);
    matTerrain.setFloat("slopeTileFactor", 32);

    matTerrain.setFloat("terrainSize", 513);

    FractalSum base = new FractalSum();
    base.setRoughness(0.7f);
    base.setFrequency(1.0f);
    base.setAmplitude(1.0f);
    base.setLacunarity(2.12f);
    base.setOctaves(8);
    base.setScale(0.02125f);
    base.addModulator(new NoiseModulator() {
        @Override
        public float value(float... in) {
            return ShaderUtils.clamp(in[0] * 0.5f + 0.5f, 0, 1);
        }
    });

    FilteredBasis ground = new FilteredBasis(base);

    PerturbFilter perturb = new PerturbFilter();
    perturb.setMagnitude(0.119f);

    OptimizedErode therm = new OptimizedErode();
    therm.setRadius(5);
    therm.setTalus(0.011f);

    SmoothFilter smooth = new SmoothFilter();
    smooth.setRadius(1);
    smooth.setEffect(0.7f);

    IterativeFilter iterate = new IterativeFilter();
    iterate.addPreFilter(perturb);
    iterate.addPostFilter(smooth);
    iterate.setFilter(therm);
    iterate.setIterations(1);

    ground.addPreFilter(iterate);

    this.terrain = new TerrainGrid("terrain", 65, 257, new FractalTileLoader(ground, 256f));


    terrain.setMaterial(matTerrain);
    terrain.setLocalTranslation(0, 0, 0);
    terrain.setLocalScale(2f, 1f, 2f);
    
    rootNode.attachChild(this.terrain);

    TerrainLodControl control = new TerrainLodControl(this.terrain, getCamera());
    this.terrain.addControl(control);
}
 
Example 15
Source File: TextureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * This class returns a texture read from the file or from packed blender
 * data. The returned texture has the name set to the value of its blender
 * type.
 * 
 * @param tex
 *            texture structure filled with data
 * @param blenderContext
 *            the blender context
 * @return the texture that can be used by JME engine
 * @throws BlenderFileException
 *             this exception is thrown when the blend file structure is
 *             somehow invalid or corrupted
 */
public Texture getTexture(Structure tex, Structure mTex, BlenderContext blenderContext) throws BlenderFileException {
    Texture result = (Texture) blenderContext.getLoadedFeature(tex.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
    if (result != null) {
        return result;
    }
    int type = ((Number) tex.getFieldValue("type")).intValue();
    int imaflag = ((Number) tex.getFieldValue("imaflag")).intValue();

    switch (type) {
        case TEX_IMAGE:// (it is first because probably this will be most commonly used)
            Pointer pImage = (Pointer) tex.getFieldValue("ima");
            if (pImage.isNotNull()) {
                Structure image = pImage.fetchData(blenderContext.getInputStream()).get(0);
                Texture loadedTexture = this.loadTexture(image, imaflag, blenderContext);
                if (loadedTexture != null) {
                    result = loadedTexture;
                    this.applyColorbandAndColorFactors(tex, result.getImage(), blenderContext);
                }
            }
            break;
        case TEX_CLOUDS:
        case TEX_WOOD:
        case TEX_MARBLE:
        case TEX_MAGIC:
        case TEX_BLEND:
        case TEX_STUCCI:
        case TEX_NOISE:
        case TEX_MUSGRAVE:
        case TEX_VORONOI:
        case TEX_DISTNOISE:
            result = new GeneratedTexture(tex, mTex, textureGeneratorFactory.createTextureGenerator(type), blenderContext);
            break;
        case TEX_NONE:// No texture, do nothing
            break;
        case TEX_POINTDENSITY:
        case TEX_VOXELDATA:
        case TEX_PLUGIN:
        case TEX_ENVMAP:
            LOGGER.log(Level.WARNING, "Unsupported texture type: {0} for texture: {1}", new Object[] { type, tex.getName() });
            break;
        default:
            throw new BlenderFileException("Unknown texture type: " + type + " for texture: " + tex.getName());
    }
    if (result != null) {
        result.setName(tex.getName());
        result.setWrap(WrapMode.Repeat);

        // decide if the mipmaps will be generated
        switch (blenderContext.getBlenderKey().getMipmapGenerationMethod()) {
            case ALWAYS_GENERATE:
                result.setMinFilter(MinFilter.Trilinear);
                break;
            case NEVER_GENERATE:
                break;
            case GENERATE_WHEN_NEEDED:
                if ((imaflag & 0x04) != 0) {
                    result.setMinFilter(MinFilter.Trilinear);
                }
                break;
            default:
                throw new IllegalStateException("Unknown mipmap generation method: " + blenderContext.getBlenderKey().getMipmapGenerationMethod());
        }

        if (type != TEX_IMAGE) {// only generated textures should have this key
            result.setKey(new GeneratedTextureKey(tex.getName()));
        }

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "Adding texture {0} to the loaded features with OMA = {1}", new Object[] { result.getName(), tex.getOldMemoryAddress() });
        }
        blenderContext.addLoadedFeatures(tex.getOldMemoryAddress(), tex.getName(), tex, result);
    }
    return result;
}
 
Example 16
Source File: TerrainFractalGridTest.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(100f);
    ScreenshotAppState state = new ScreenshotAppState();
    this.stateManager.attach(state);

    // TERRAIN TEXTURE material
    this.mat_terrain = new Material(this.assetManager, "Common/MatDefs/Terrain/HeightBasedTerrain.j3md");

    // Parameters to material:
    // regionXColorMap: X = 1..4 the texture that should be appliad to state X
    // regionX: a Vector3f containing the following information:
    //      regionX.x: the start height of the region
    //      regionX.y: the end height of the region
    //      regionX.z: the texture scale for the region
    //  it might not be the most elegant way for storing these 3 values, but it packs the data nicely :)
    // slopeColorMap: the texture to be used for cliffs, and steep mountain sites
    // slopeTileFactor: the texture scale for slopes
    // terrainSize: the total size of the terrain (used for scaling the texture)
    // GRASS texture
    Texture grass = this.assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    this.mat_terrain.setTexture("region1ColorMap", grass);
    this.mat_terrain.setVector3("region1", new Vector3f(15, 200, this.grassScale));

    // DIRT texture
    Texture dirt = this.assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    this.mat_terrain.setTexture("region2ColorMap", dirt);
    this.mat_terrain.setVector3("region2", new Vector3f(0, 20, this.dirtScale));

    // ROCK texture
    Texture rock = this.assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
    rock.setWrap(WrapMode.Repeat);
    this.mat_terrain.setTexture("region3ColorMap", rock);
    this.mat_terrain.setVector3("region3", new Vector3f(198, 260, this.rockScale));

    this.mat_terrain.setTexture("region4ColorMap", rock);
    this.mat_terrain.setVector3("region4", new Vector3f(198, 260, this.rockScale));

    this.mat_terrain.setTexture("slopeColorMap", rock);
    this.mat_terrain.setFloat("slopeTileFactor", 32);

    this.mat_terrain.setFloat("terrainSize", 513);

    this.base = new FractalSum();
    this.base.setRoughness(0.7f);
    this.base.setFrequency(1.0f);
    this.base.setAmplitude(1.0f);
    this.base.setLacunarity(2.12f);
    this.base.setOctaves(8);
    this.base.setScale(0.02125f);
    this.base.addModulator(new NoiseModulator() {

        @Override
        public float value(float... in) {
            return ShaderUtils.clamp(in[0] * 0.5f + 0.5f, 0, 1);
        }
    });

    FilteredBasis ground = new FilteredBasis(this.base);

    this.perturb = new PerturbFilter();
    this.perturb.setMagnitude(0.119f);

    this.therm = new OptimizedErode();
    this.therm.setRadius(5);
    this.therm.setTalus(0.011f);

    this.smooth = new SmoothFilter();
    this.smooth.setRadius(1);
    this.smooth.setEffect(0.7f);

    this.iterate = new IterativeFilter();
    this.iterate.addPreFilter(this.perturb);
    this.iterate.addPostFilter(this.smooth);
    this.iterate.setFilter(this.therm);
    this.iterate.setIterations(1);

    ground.addPreFilter(this.iterate);

    this.terrain = new TerrainGrid("terrain", 33, 129, new FractalTileLoader(ground, 256f));

    this.terrain.setMaterial(this.mat_terrain);
    this.terrain.setLocalTranslation(0, 0, 0);
    this.terrain.setLocalScale(2f, 1f, 2f);
    this.rootNode.attachChild(this.terrain);

    TerrainLodControl control = new TerrainGridLodControl(this.terrain, this.getCamera());
    control.setLodCalculator(new DistanceLodCalculator(33, 2.7f)); // patch size, and a multiplier
    this.terrain.addControl(control);



    this.getCamera().setLocation(new Vector3f(0, 300, 0));

    this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));

    
}
 
Example 17
Source File: SSAOFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    this.renderManager = renderManager;
    this.viewPort = vp;
    int screenWidth = w;
    int screenHeight = h;
    postRenderPasses = new ArrayList<Pass>();

    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth);


    frustumNearFar = new Vector2f();

    float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
    float farX = farY * ((float) screenWidth / (float) screenHeight);
    frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
    frustumNearFar.x = vp.getCamera().getFrustumNear();
    frustumNearFar.y = vp.getCamera().getFrustumFar();





    //ssao Pass
    ssaoMat = new Material(manager, "Common/MatDefs/SSAO/ssao.j3md");
    ssaoMat.setTexture("Normals", normalPass.getRenderedTexture());
    Texture random = manager.loadTexture("Common/MatDefs/SSAO/Textures/random.png");
    random.setWrap(Texture.WrapMode.Repeat);
    ssaoMat.setTexture("RandomMap", random);

    ssaoPass = new Pass() {

        @Override
        public boolean requiresDepthAsTexture() {
            return true;
        }
    };

    ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat);
    ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
    ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
    postRenderPasses.add(ssaoPass);
    material = new Material(manager, "Common/MatDefs/SSAO/ssaoBlur.j3md");
    material.setTexture("SSAOMap", ssaoPass.getRenderedTexture());

    ssaoMat.setVector3("FrustumCorner", frustumCorner);
    ssaoMat.setFloat("SampleRadius", sampleRadius);
    ssaoMat.setFloat("Intensity", intensity);
    ssaoMat.setFloat("Scale", scale);
    ssaoMat.setFloat("Bias", bias);
    material.setBoolean("UseAo", useAo);
    material.setBoolean("UseOnlyAo", useOnlyAo);
    ssaoMat.setVector2("FrustumNearFar", frustumNearFar);
    material.setVector2("FrustumNearFar", frustumNearFar);
    ssaoMat.setParam("Samples", VarType.Vector2Array, samples);

    float xScale = 1.0f / w;
    float yScale = 1.0f / h;

    float blurScale = 2f;
    material.setFloat("XScale", blurScale * xScale);
    material.setFloat("YScale", blurScale * yScale);

}
 
Example 18
Source File: J3MLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private Object readValue(VarType type, String value) throws IOException{
        if (type.isTextureType()){
//            String texturePath = readString("[\n;(//)(\\})]");
            String texturePath = value.trim();
            boolean flipY = false;
            boolean repeat = false;
            if (texturePath.startsWith("Flip Repeat ")){
                texturePath = texturePath.substring(12).trim();
                flipY = true;
                repeat = true;
            }else if (texturePath.startsWith("Flip ")){
                texturePath = texturePath.substring(5).trim();
                flipY = true;
            }else if (texturePath.startsWith("Repeat ")){
                texturePath = texturePath.substring(7).trim();
                repeat = true;
            }

            TextureKey key = new TextureKey(texturePath, flipY);
            key.setAsCube(type == VarType.TextureCubeMap);
            key.setGenerateMips(true);

            Texture tex = owner.loadTexture(key);
            if (tex != null){
                if (repeat)
                    tex.setWrap(WrapMode.Repeat);
            }
            return tex;
        }else{
            String[] split = value.trim().split(whitespacePattern);
            switch (type){
                case Float:
                    if (split.length != 1){
                        throw new IOException("Float value parameter must have 1 entry: " + value);
                    }
                     return Float.parseFloat(split[0]);
                case Vector2:
                    if (split.length != 2){
                        throw new IOException("Vector2 value parameter must have 2 entries: " + value);
                    }
                    return new Vector2f(Float.parseFloat(split[0]),
                                                               Float.parseFloat(split[1]));
                case Vector3:
                    if (split.length != 3){
                        throw new IOException("Vector3 value parameter must have 3 entries: " + value);
                    }
                    return new Vector3f(Float.parseFloat(split[0]),
                                                               Float.parseFloat(split[1]),
                                                               Float.parseFloat(split[2]));
                case Vector4:
                    if (split.length != 4){
                        throw new IOException("Vector4 value parameter must have 4 entries: " + value);
                    }
                    return new ColorRGBA(Float.parseFloat(split[0]),
                                                                Float.parseFloat(split[1]),
                                                                Float.parseFloat(split[2]),
                                                                Float.parseFloat(split[3]));
                case Int:
                    if (split.length != 1){
                        throw new IOException("Int value parameter must have 1 entry: " + value);
                    }
                    return Integer.parseInt(split[0]);
                case Boolean:
                    if (split.length != 1){
                        throw new IOException("Boolean value parameter must have 1 entry: " + value);
                    }
                    return Boolean.parseBoolean(split[0]);
                default:
                    throw new UnsupportedOperationException("Unknown type: "+type);
            }
        }
    }
 
Example 19
Source File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
TiledTerrain() {
    // TERRAIN TEXTURE material
    matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matTerrain.setBoolean("useTriPlanarMapping", false);
    matTerrain.setBoolean("WardIso", true);
    matTerrain.setFloat("Shininess", 0);

    // 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);

    // CREATE THE TERRAIN
    terrain1 = new TerrainQuad("terrain 1", 65, 513, null);
    terrain1.setMaterial(matTerrain);
    terrain1.setLocalTranslation(-256, -100, -256);
    terrain1.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain1);

    terrain2 = new TerrainQuad("terrain 2", 65, 513, null);
    terrain2.setMaterial(matTerrain);
    terrain2.setLocalTranslation(-256, -100, 256);
    terrain2.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain2);

    terrain3 = new TerrainQuad("terrain 3", 65, 513, null);
    terrain3.setMaterial(matTerrain);
    terrain3.setLocalTranslation(256, -100, -256);
    terrain3.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain3);

    terrain4 = new TerrainQuad("terrain 4", 65, 513, null);
    terrain4.setMaterial(matTerrain);
    terrain4.setLocalTranslation(256, -100, 256);
    terrain4.setLocalScale(1f, 1f, 1f);
    this.attachChild(terrain4);
    
    terrain1.setNeighbourFinder(this);
    terrain2.setNeighbourFinder(this);
    terrain3.setNeighbourFinder(this);
    terrain4.setNeighbourFinder(this);
    
    MultiTerrainLodControl lodControl = new MultiTerrainLodControl(getCamera());
    lodControl.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
    lodControl.addTerrain(terrain1);
    lodControl.addTerrain(terrain2);
    lodControl.addTerrain(terrain3);// order of these seems to matter
    lodControl.addTerrain(terrain4);
    this.addControl(lodControl);
    
}
 
Example 20
Source File: SSAOFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
        this.renderManager = renderManager;
        this.viewPort = vp;
        int screenWidth = w;
        int screenHeight = h;
        postRenderPasses = new ArrayList<Pass>();

        normalPass = new Pass();
        normalPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth);


        frustumNearFar = new Vector2f();

        float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
        float farX = farY * (screenWidth / (float) screenHeight);
        frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
        frustumNearFar.x = vp.getCamera().getFrustumNear();
        frustumNearFar.y = vp.getCamera().getFrustumFar();





        //ssao Pass
        ssaoMat = new Material(manager, "Common/MatDefs/SSAO/ssao.j3md");
        ssaoMat.setTexture("Normals", normalPass.getRenderedTexture());
        Texture random = manager.loadTexture("Common/MatDefs/SSAO/Textures/random.png");
        random.setWrap(Texture.WrapMode.Repeat);
        ssaoMat.setTexture("RandomMap", random);

        ssaoPass = new Pass("SSAO pass") {

            @Override
            public boolean requiresDepthAsTexture() {
                return true;
            }
        };

        ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat);
//        ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
//        ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
        postRenderPasses.add(ssaoPass);
        material = new Material(manager, "Common/MatDefs/SSAO/ssaoBlur.j3md");
        material.setTexture("SSAOMap", ssaoPass.getRenderedTexture());

        ssaoMat.setVector3("FrustumCorner", frustumCorner);
        ssaoMat.setFloat("SampleRadius", sampleRadius);
        ssaoMat.setFloat("Intensity", intensity);
        ssaoMat.setFloat("Scale", scale);
        ssaoMat.setFloat("Bias", bias);
        material.setBoolean("UseAo", useAo);
        material.setBoolean("UseOnlyAo", useOnlyAo);
        ssaoMat.setVector2("FrustumNearFar", frustumNearFar);
        material.setVector2("FrustumNearFar", frustumNearFar);
        ssaoMat.setParam("Samples", VarType.Vector2Array, samples);
        ssaoMat.setBoolean("ApproximateNormals", approximateNormals);

        float xScale = 1.0f / w;
        float yScale = 1.0f / h;

        float blurScale = 2f;
        material.setFloat("XScale", blurScale * xScale);
        material.setFloat("YScale", blurScale * yScale);

    }