Java Code Examples for com.jme3.material.Material#setFloat()

The following examples show how to use com.jme3.material.Material#setFloat() . 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: RefEnv.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void switchMat(Spatial s) {
    if (s instanceof Node) {
        Node n = (Node) s;
        for (Spatial children : n.getChildren()) {
            switchMat(children);
        }
    } else if (s instanceof Geometry) {
        Geometry g = (Geometry) s;
        Material mat = g.getMaterial();
        if (((Float) mat.getParam("Metallic").getValue()) == 1f) {
            mat.setFloat("Metallic", 0);
            mat.setColor("BaseColor", ColorRGBA.Black);
            ref.attachChild(refImg);
        } else {
            mat.setFloat("Metallic", 1);
            mat.setColor("BaseColor", ColorRGBA.White);
            refImg.removeFromParent();
        }
    }
}
 
Example 2
Source File: PosterizationFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
    material.setInt("NumColors", numColors);
    material.setFloat("Gamma", gamma);
    material.setFloat("Strength", strength);
}
 
Example 3
Source File: TestBatchLod.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
//        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);

        // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        flyCam.setMoveSpeed(5);
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                Geometry clonePot = teapot.clone();

                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                clonePot.setMaterial(mat);
                rootNode.attachChild(clonePot);
            }
        }
        GeometryBatchFactory.optimize(rootNode, true);
        LodControl control = new LodControl();
        rootNode.getChild(0).addControl(control);
        cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
        cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));

    }
 
Example 4
Source File: PosterizationFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
    material.setInt("NumColors", numColors);
    material.setFloat("Gamma", gamma);
    material.setFloat("Strength", strength);
}
 
Example 5
Source File: TestTexture3DLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setEnabled(false);


    Quad q = new Quad(10, 10);

    Geometry geom = new Geometry("Quad", q);
    Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
    TextureKey key = new TextureKey("Textures/3D/flame.dds");
    key.setGenerateMips(true);
    key.setTextureTypeHint(Texture.Type.ThreeDimensional);

    Texture t = assetManager.loadTexture(key);

    int rows = 4;//4 * 4

    q.scaleTextureCoordinates(new Vector2f(rows, rows));

    //The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
    material.setFloat("InvDepth", 1f / 16f);
    material.setInt("Rows", rows);
    material.setTexture("Texture", t);
    geom.setMaterial(material);

    rootNode.attachChild(geom);

    cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
 
Example 6
Source File: TestCameraMotionPath.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createScene() {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 1f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Black);
    mat.setColor("Diffuse", ColorRGBA.DarkGray);
    mat.setColor("Specular", ColorRGBA.White.mult(0.6f));
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Gray);
    matSoil.setColor("Specular", ColorRGBA.Black);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalScale(3);
    teapot.setMaterial(mat);



    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -1.0f, 0), 50, 1, 50));
    soil.setMaterial(matSoil);
    rootNode.attachChild(soil);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
}
 
Example 7
Source File: DepthOfFieldFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager assets, RenderManager renderManager,
        ViewPort vp, int w, int h) {
    material = new Material(assets, "Common/MatDefs/Post/DepthOfField.j3md");
    material.setFloat("FocusDistance", focusDistance);
    material.setFloat("FocusRange", focusRange);
    material.setFloat("BlurThreshold", blurThreshold);
    material.setBoolean("DebugUnfocus", debugUnfocus);

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

    material.setFloat("XScale", blurScale * xScale);
    material.setFloat("YScale", blurScale * yScale);
}
 
Example 8
Source File: CartoonEdgeFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 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;
    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), w, h, Format.RGBA8, Format.Depth);
    material = new Material(manager, "Common/MatDefs/Post/CartoonEdge.j3md");
    material.setFloat("EdgeWidth", edgeWidth);
    material.setFloat("EdgeIntensity", edgeIntensity);
    material.setFloat("NormalThreshold", normalThreshold);
    material.setFloat("DepthThreshold", depthThreshold);
    material.setFloat("NormalSensitivity", normalSensitivity);
    material.setFloat("DepthSensitivity", depthSensitivity);
    material.setColor("EdgeColor", edgeColor);
}
 
Example 9
Source File: TestLodStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);
        
//        Sphere sph = new Sphere(16, 16, 4);
//        Geometry teapot = new Geometry("teapot", sph);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);
        
       // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        for (int y = -10; y < 10; y++){
            for (int x = -10; x < 10; x++){
                Geometry clonePot = teapot.clone();
                
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                
                LodControl control = new LodControl();
                clonePot.addControl(control);
                rootNode.attachChild(clonePot);
            }
        }

        cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
        cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    }
 
Example 10
Source File: TestBloomAlphaThreshold.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp()
{
	// put the camera in a bad position
	cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -10));
	cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
	// cam.setFrustumFar(1000);

	Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");

	mat.setFloat("Shininess", 15f);
	mat.setBoolean("UseMaterialColors", true);
	mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
	mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
	mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));
	mat.setColor("GlowColor", ColorRGBA.Green);

	Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
	matSoil.setFloat("Shininess", 15f);
	matSoil.setBoolean("UseMaterialColors", true);
	matSoil.setColor("Ambient", ColorRGBA.Gray);
	matSoil.setColor("Diffuse", ColorRGBA.Black);
	matSoil.setColor("Specular", ColorRGBA.Gray);

	teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
	teapot.setLocalTranslation(0, 0, 10);

	teapot.setMaterial(mat);
	teapot.setShadowMode(ShadowMode.CastAndReceive);
	teapot.setLocalScale(10.0f);
	rootNode.attachChild(teapot);

               Vector3f boxMin1 = new Vector3f(-800f, -23f, -150f);
               Vector3f boxMax1 = new Vector3f(800f, 3f, 1250f);
               Box boxMesh1 = new Box(boxMin1, boxMax1);
	Geometry soil = new Geometry("soil", boxMesh1);
	soil.setMaterial(matSoil);
	soil.setShadowMode(ShadowMode.CastAndReceive);
	rootNode.attachChild(soil);

	Material matBox = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
	matBox.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
	matBox.setFloat("AlphaDiscardThreshold", 0.5f);
   
               Vector3f boxMin2 = new Vector3f(-5.5f, 8f, -4f);
               Vector3f boxMax2 = new Vector3f(-1.5f, 12f, 0f);
               Box boxMesh2 = new Box(boxMin2, boxMax2);
	Geometry box = new Geometry("box", boxMesh2);
	box.setMaterial(matBox);
               box.setQueueBucket(RenderQueue.Bucket.Translucent);
	// box.setShadowMode(ShadowMode.CastAndReceive);
	rootNode.attachChild(box);

	DirectionalLight light = new DirectionalLight();
	light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
	light.setColor(ColorRGBA.White.mult(1.5f));
	rootNode.addLight(light);

	// load sky
	Spatial sky = SkyFactory.createSky(assetManager, 
                       "Textures/Sky/Bright/FullskiesBlueClear03.dds",
                       EnvMapType.CubeMap);
	sky.setCullHint(Spatial.CullHint.Never);
	rootNode.attachChild(sky);

	fpp = new FilterPostProcessor(assetManager);
	int numSamples = getContext().getSettings().getSamples();
	if (numSamples > 0)
	{
		fpp.setNumSamples(numSamples);
	}

	BloomFilter bloom = new BloomFilter(GlowMode.Objects);
	bloom.setDownSamplingFactor(2);
	bloom.setBlurScale(1.37f);
	bloom.setExposurePower(3.30f);
	bloom.setExposureCutOff(0.2f);
	bloom.setBloomIntensity(2.45f);
	BloomUI ui = new BloomUI(inputManager, bloom);

	viewPort.addProcessor(fpp);
	fpp.addFilter(bloom);
	initInputs();

}
 
Example 11
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);

    }
 
Example 12
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 13
Source File: TestLightNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        Torus torus = new Torus(10, 6, 1, 3);
//        Torus torus = new Torus(50, 30, 1, 3);
        Geometry g = new Geometry("Torus Geom", torus);
        g.rotate(-FastMath.HALF_PI, 0, 0);
        g.center();
//        g.move(0, 1, 0);
        
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 32f);
        mat.setBoolean("UseMaterialColors", true);
        mat.setColor("Ambient",  ColorRGBA.Black);
        mat.setColor("Diffuse",  ColorRGBA.White);
        mat.setColor("Specular", ColorRGBA.White);
//        mat.setBoolean("VertexLighting", true);
//        mat.setBoolean("LowQuality", true);
        g.setMaterial(mat);

        rootNode.attachChild(g);

        Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        
        movingNode=new Node("lightParentNode");
        movingNode.attachChild(lightMdl);  
        rootNode.attachChild(movingNode);

        PointLight pl = new PointLight();
        pl.setColor(ColorRGBA.Green);
        pl.setRadius(4f);
        rootNode.addLight(pl);
        
        LightNode lightNode=new LightNode("pointLight", pl);
        movingNode.attachChild(lightNode);

        DirectionalLight dl = new DirectionalLight();
        dl.setColor(ColorRGBA.Red);
        dl.setDirection(new Vector3f(0, 1, 0));
        rootNode.addLight(dl);
    }
 
Example 14
Source File: TestPosterization.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));

    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));

    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);

    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

    Geometry soil = new Geometry("soil", new Box(800, 10, 700));
    soil.setLocalTranslation(0, -13, 550);
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", SkyFactory.EnvMapType.CubeMap);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    pf = new PosterizationFilter();
    fpp.addFilter(pf);

    viewPort.addProcessor(fpp);
    initInputs();

}
 
Example 15
Source File: TestBloom.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    //cam.setFrustumFar(1000);


    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));




    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
   


    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

  

    Geometry soil=new Geometry("soil", new Box(new Vector3f(0, -13, 550), 800, 10, 700));
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    fpp=new FilterPostProcessor(assetManager);
   // fpp.setNumSamples(4);
    BloomFilter bloom=new BloomFilter();
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    BloomUI ui=new BloomUI(inputManager, bloom);
   

    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    initInputs();

}
 
Example 16
Source File: HelloMaterial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

  /** A simple textured cube -- in good MIP map quality. */
  Box cube1Mesh = new Box( 1f,1f,1f);
  Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
  cube1Geo.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
  Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
  cube1Mat.setTexture("ColorMap", cube1Tex);
  cube1Geo.setMaterial(cube1Mat);
  rootNode.attachChild(cube1Geo);

  /** A translucent/transparent texture, similar to a window frame. */
  Box cube2Mesh = new Box( 1f,1f,0.01f);
  Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
  Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);  // activate transparency
  cube2Geo.setQueueBucket(Bucket.Transparent);
  cube2Geo.setMaterial(cube2Mat);
  rootNode.attachChild(cube2Geo);

  /** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
  Sphere sphereMesh = new Sphere(32,32, 2f);
  Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
  sphereMesh.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
  TangentBinormalGenerator.generate(sphereMesh);           // for lighting effect
  Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
  sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
  sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
  sphereMat.setBoolean("UseMaterialColors",true);    
  sphereMat.setColor("Diffuse",ColorRGBA.White);
  sphereMat.setColor("Specular",ColorRGBA.White);
  sphereMat.setFloat("Shininess", 64f); // [0,128]
  sphereGeo.setMaterial(sphereMat);
  //sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
  sphereGeo.setLocalTranslation(0,2,-2); // Move it a bit
  sphereGeo.rotate(1.6f, 0, 0);          // Rotate it a bit
  rootNode.attachChild(sphereGeo);
  
  /** Must add a light to make the lit object visible! */
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
  sun.setColor(ColorRGBA.White);
  rootNode.addLight(sun);
}
 
Example 17
Source File: TestSimpleLighting.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
        TangentBinormalGenerator.generate(teapot.getMesh(), true);

        teapot.setLocalScale(2f);
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
//        mat.selectTechnique("GBuf");
        mat.setFloat("Shininess", 25);
        mat.setBoolean("UseMaterialColors", true);
        cam.setLocation(new Vector3f(0.015041917f, 0.4572918f, 5.2874837f));
        cam.setRotation(new Quaternion(-1.8875003E-4f, 0.99882424f, 0.04832061f, 0.0039016632f));

//        mat.setTexture("ColorRamp", assetManager.loadTexture("Textures/ColorRamp/cloudy.png"));
//
//        mat.setBoolean("VTangent", true);
//        mat.setBoolean("Minnaert", true);
//        mat.setBoolean("WardIso", true);
//        mat.setBoolean("VertexLighting", true);
//        mat.setBoolean("LowQuality", true);
//        mat.setBoolean("HighQuality", true);

        mat.setColor("Ambient",  ColorRGBA.Black);
        mat.setColor("Diffuse",  ColorRGBA.Gray);
        mat.setColor("Specular", ColorRGBA.Gray);
        
        teapot.setMaterial(mat);
        rootNode.attachChild(teapot);

        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        lightMdl.getMesh().setStatic();
        rootNode.attachChild(lightMdl);

        pl = new PointLight();
        pl.setColor(ColorRGBA.White);
        pl.setRadius(4f);
        rootNode.addLight(pl);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        dl.setColor(ColorRGBA.Green);
        rootNode.addLight(dl);
        
        
        MaterialDebugAppState debug = new MaterialDebugAppState();
        debug.registerBinding("Common/ShaderLib/BlinnPhongLighting.glsllib", teapot);
        stateManager.attach(debug);
        setPauseOnLostFocus(false);
        flyCam.setDragToRotate(true);
        
    }
 
Example 18
Source File: OpaqueComparatorTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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);
}
 
Example 19
Source File: TestSoftParticles.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void createParticles() {
    
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    material.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    material.setFloat("Softness", 3f); // 
    
    //Fire
    ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30);
    fire.setMaterial(material);
    fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f));
    fire.setImagesX(2);
    fire.setImagesY(2); // 2x2 texture animation
    fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red
    fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow
    fire.setStartSize(0.6f);
    fire.setEndSize(0.01f);
    fire.setGravity(0, -0.3f, 0);
    fire.setLowLife(0.5f);
    fire.setHighLife(3f);
    fire.setLocalTranslation(0, 0.2f, 0);

    particleNode.attachChild(fire);
    
    
    ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30);
    smoke.setMaterial(material);
    smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5));
    smoke.setImagesX(1);
    smoke.setImagesY(1); // 2x2 texture animation
    smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f,1f)); // dark gray
    smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f)); // gray      
    smoke.setStartSize(3f);
    smoke.setEndSize(5f);
    smoke.setGravity(0, -0.001f, 0);
    smoke.setLowLife(100f);
    smoke.setHighLife(100f);
    smoke.setLocalTranslation(0, 0.1f, 0);        
    smoke.emitAllParticles();
    
    particleNode.attachChild(smoke);
}
 
Example 20
Source File: TestOgreComplexAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");

    skinningControl = model.getControl(SkinningControl.class);
    AnimComposer ac = model.getControl(AnimComposer.class);

    ArmatureMask feet = ArmatureMask.createMask(skinningControl.getArmature(), "hip.right", "hip.left");
    Action dodgeAction = ac.action("Dodge");
    dodgeAction.setMask(feet);
    dodgeAction.setSpeed(2f);
    Action walkAction = ac.action("Walk");
    walkAction.setMask(feet);
    walkAction.setSpeed(0.25f);

    ArmatureMask rightHand = ArmatureMask.createMask(skinningControl.getArmature(), "uparm.right");
    Action pullAction = ac.action("pull");
    pullAction.setMask(rightHand);
    pullAction.setSpeed(0.5f);
    Action standAction = ac.action("stand");
    standAction.setMask(rightHand);
    standAction.setSpeed(0.5f);

    ac.actionSequence("complexAction",
            ac.actionSequence("feetAction", dodgeAction, walkAction),
            ac.actionSequence("rightHandAction", pullAction, standAction));

    ac.setCurrentAction("complexAction");

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat.setFloat("PointSize", 7f); // Bug ? do not change size of debug points ?
    mat.getAdditionalRenderState().setDepthTest(false);

    ArmatureDebugger armatureDebug = new ArmatureDebugger("armature", skinningControl.getArmature(),
            skinningControl.getArmature().getJointList());
    armatureDebug.setMaterial(mat);
    model.attachChild(armatureDebug);

    rootNode.attachChild(model);
}