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

The following examples show how to use com.jme3.material.Material#setBoolean() . 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: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createFlame(){
    flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
    flame.setSelectRandomImage(true);
    flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
    flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    flame.setStartSize(1.3f);
    flame.setEndSize(2f);
    flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    flame.setParticlesPerSec(0);
    flame.setGravity(0, -5, 0);
    flame.setLowLife(.4f);
    flame.setHighLife(.5f);
    flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
    flame.getParticleInfluencer().setVelocityVariation(1f);
    flame.setImagesX(2);
    flame.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    flame.setMaterial(mat);
    explosionEffect.attachChild(flame);
}
 
Example 2
Source File: TestExplosionEffect.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void createFlame(){
    flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
    flame.setSelectRandomImage(true);
    flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
    flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    flame.setStartSize(1.3f);
    flame.setEndSize(2f);
    flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    flame.setParticlesPerSec(0);
    flame.setGravity(0, -5, 0);
    flame.setLowLife(.4f);
    flame.setHighLife(.5f);
    flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
    flame.getParticleInfluencer().setVelocityVariation(1f);
    flame.setImagesX(2);
    flame.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    flame.setMaterial(mat);
    explosionEffect.attachChild(flame);
}
 
Example 3
Source File: TestUnshadedModel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Sphere sphMesh = new Sphere(32, 32, 1);
    sphMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphMesh.updateGeometry(32, 32, 1, false, false);
    TangentBinormalGenerator.generate(sphMesh);

    Geometry sphere = new Geometry("Rock Ball", sphMesh);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.setColor("Ambient", ColorRGBA.DarkGray);
    mat.setColor("Diffuse", ColorRGBA.White);
    mat.setBoolean("UseMaterialColors", true);
    sphere.setMaterial(mat);
    rootNode.attachChild(sphere);

    PointLight pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    pl.setPosition(new Vector3f(4f, 0f, 0f));
    rootNode.addLight(pl);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);
}
 
Example 4
Source File: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createFlash(){
    flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
    flash.setSelectRandomImage(true);
    flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1f / COUNT_FACTOR_F)));
    flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
    flash.setStartSize(.1f);
    flash.setEndSize(3.0f);
    flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
    flash.setParticlesPerSec(0);
    flash.setGravity(0, 0, 0);
    flash.setLowLife(.2f);
    flash.setHighLife(.2f);
    flash.setInitialVelocity(new Vector3f(0, 5f, 0));
    flash.setVelocityVariation(1);
    flash.setImagesX(2);
    flash.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flash.png"));
    mat.setBoolean("PointSprite", POINT_SPRITE);
    flash.setMaterial(mat);
    explosionEffect.attachChild(flash);
}
 
Example 5
Source File: TestCartoonEdge.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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().getMaterialParam("UseMaterialColors") != null) {
                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);
            }
        }
    }
 
Example 6
Source File: ArmatureDebugger.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void initialize(AssetManager assetManager, Camera camera) {

        armatureNode.setCamera(camera);

        Material matJoints = new Material(assetManager, "Common/MatDefs/Misc/Billboard.j3md");
        Texture t = assetManager.loadTexture("Common/Textures/dot.png");
        matJoints.setTexture("Texture", t);
        matJoints.getAdditionalRenderState().setDepthTest(false);
        matJoints.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
        joints.setQueueBucket(RenderQueue.Bucket.Translucent);
        joints.setMaterial(matJoints);

        Material matWires = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matWires.setBoolean("VertexColor", true);
        matWires.getAdditionalRenderState().setLineWidth(1f);
        wires.setMaterial(matWires);

        Material matOutline = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matOutline.setBoolean("VertexColor", true);
        matOutline.getAdditionalRenderState().setLineWidth(1f);
        outlines.setMaterial(matOutline);

        Material matOutline2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");
        matOutline2.getAdditionalRenderState().setLineWidth(1);
        outlines.getChild(1).setMaterial(matOutline2);

        Material matWires2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");
        matWires2.getAdditionalRenderState().setLineWidth(1);
        wires.getChild(1).setMaterial(matWires2);

    }
 
Example 7
Source File: TestTangentCube.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
        Box aBox = new Box(1, 1, 1);
        Geometry aGeometry = new Geometry("Box", aBox);
        TangentBinormalGenerator.generate(aBox);

        Material aMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        aMaterial.setTexture("DiffuseMap",
                assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
        aMaterial.setTexture("NormalMap",
                assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_normal.jpg"));
        aMaterial.setBoolean("UseMaterialColors", false);
        aMaterial.setColor("Diffuse", ColorRGBA.White);
        aMaterial.setColor("Specular", ColorRGBA.White);
        aMaterial.setFloat("Shininess", 64f);
        aGeometry.setMaterial(aMaterial);

        // Rotate 45 degrees to see multiple faces
        aGeometry.rotate(FastMath.QUARTER_PI, FastMath.QUARTER_PI, 0.0f);
        rootNode.attachChild(aGeometry);

        /**
         * Must add a light to make the lit object visible!
         */
        PointLight aLight = new PointLight();
        aLight.setPosition(new Vector3f(0, 3, 3));
        aLight.setColor(ColorRGBA.Red);
        rootNode.addLight(aLight);
//
//        AmbientLight bLight = new AmbientLight();
//        bLight.setColor(ColorRGBA.Gray);
//        rootNode.addLight(bLight);

        
        ChaseCameraAppState chaser = new ChaseCameraAppState();
        chaser.setTarget(aGeometry);
        getStateManager().attach(chaser);
    }
 
Example 8
Source File: TestLightRadius.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 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);

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

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

        DirectionalLight dl = new DirectionalLight();
        dl.setColor(ColorRGBA.Red);
        dl.setDirection(new Vector3f(0, 1, 0));
        rootNode.addLight(dl);
    }
 
Example 9
Source File: MaterialUtils.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Set the material parameter with check of existing this parameter in the material's definition.
 *
 * @param material the material.
 * @param name     the parameter's name.
 * @param value    the value.
 */
@FromAnyThread
public static void safeSet(@Nullable Material material, @NotNull String name, boolean value) {

    if (material == null) {
        return;
    }

    var materialParam = material.getMaterialDef()
            .getMaterialParam(name);

    if (materialParam != null) {
        material.setBoolean(name, value);
    }
}
 
Example 10
Source File: TestIssue1283.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configure materials during startup.
 */
private void configureMaterials() {
    wallMaterial = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    wallMaterial.setColor("Color", ColorRGBA.White.clone());
    wallMaterial.getAdditionalRenderState().setWireframe(true);

    projectileMaterial = new Material(assetManager,
            "Common/MatDefs/Light/Lighting.j3md");
    projectileMaterial.setBoolean("UseMaterialColors", true);
    projectileMaterial.setColor("Ambient", ColorRGBA.Red.clone());
    projectileMaterial.setColor("Diffuse", ColorRGBA.Red.clone());
    projectileMaterial.setColor("Specular", ColorRGBA.Black.clone());
}
 
Example 11
Source File: FbxMaterial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Material createMaterial() {
	Material m = new Material(scene.assetManager, "Common/MatDefs/Light/Lighting.j3md");
	m.setName(name);
	ambientColor.multLocal(ambientFactor);
	diffuseColor.multLocal(diffuseFactor);
	specularColor.multLocal(specularFactor);
	m.setColor("Ambient", new ColorRGBA(ambientColor.x, ambientColor.y, ambientColor.z, 1));
	m.setColor("Diffuse", new ColorRGBA(diffuseColor.x, diffuseColor.y, diffuseColor.z, 1));
	m.setColor("Specular", new ColorRGBA(specularColor.x, specularColor.y, specularColor.z, 1));
	m.setFloat("Shininess", shininessExponent);
	m.setBoolean("UseMaterialColors", true);
	m.setFloat("AlphaDiscardThreshold", 0.5f); // TODO replace with right way in JME to set "Aplha Test"
	m.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
	return m;
}
 
Example 12
Source File: TestCameraMotionPath.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" 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(50, 1, 50));
    soil.setLocalTranslation(0, -1, 0);
    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 13
Source File: RenderDeviceJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public RenderDeviceJme(NiftyJmeDisplay display) {
    this.display = display;

    quadColor = new VertexBuffer(Type.Color);
    quadColor.setNormalized(true);
    ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4);
    quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb);
    quad.setBuffer(quadColor);

    quadModTC.setUsage(Usage.Stream);

    // Load the 3 material types separately to avoid
    // reloading the shader when the defines change.

    // Material with a single color (no texture or vertex color)
    colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

    // Material with a texture and a color (no vertex color)
    textureColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

    // Material with vertex color, used for gradients (no texture)
    vertexColorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    vertexColorMaterial.setBoolean("VertexColor", true);

    // Shared render state for all materials
    renderState.setDepthTest(false);
    renderState.setDepthWrite(false);
}
 
Example 14
Source File: BloomFilter.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;
    screenWidth = (int) Math.max(1, (w / downSamplingFactor));
    screenHeight = (int) Math.max(1, (h / downSamplingFactor));
    //    System.out.println(screenWidth + " " + screenHeight);
    if (glowMode != GlowMode.Scene) {
        preGlowPass = new Pass();
        preGlowPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth);
    }

    postRenderPasses = new ArrayList<Pass>();
    //configuring extractPass
    extractMat = new Material(manager, "Common/MatDefs/Post/BloomExtract.j3md");
    extractPass = new Pass() {

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

        @Override
        public void beforeRender() {
            extractMat.setFloat("ExposurePow", exposurePower);
            extractMat.setFloat("ExposureCutoff", exposureCutOff);
            if (glowMode != GlowMode.Scene) {
                extractMat.setTexture("GlowMap", preGlowPass.getRenderedTexture());
            }
            extractMat.setBoolean("Extract", glowMode != GlowMode.Objects);
        }
    };

    extractPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, extractMat);
    postRenderPasses.add(extractPass);

    //configuring horizontal blur pass
    hBlurMat = new Material(manager, "Common/MatDefs/Blur/HGaussianBlur.j3md");
    horizontalBlur = new Pass() {

        @Override
        public void beforeRender() {
            hBlurMat.setTexture("Texture", extractPass.getRenderedTexture());
            hBlurMat.setFloat("Size", screenWidth);
            hBlurMat.setFloat("Scale", blurScale);
        }
    };

    horizontalBlur.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, hBlurMat);
    postRenderPasses.add(horizontalBlur);

    //configuring vertical blur pass
    vBlurMat = new Material(manager, "Common/MatDefs/Blur/VGaussianBlur.j3md");
    verticalalBlur = new Pass() {

        @Override
        public void beforeRender() {
            vBlurMat.setTexture("Texture", horizontalBlur.getRenderedTexture());
            vBlurMat.setFloat("Size", screenHeight);
            vBlurMat.setFloat("Scale", blurScale);
        }
    };

    verticalalBlur.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, vBlurMat);
    postRenderPasses.add(verticalalBlur);


    //final material
    material = new Material(manager, "Common/MatDefs/Post/BloomFinal.j3md");
    material.setTexture("BloomTex", verticalalBlur.getRenderedTexture());
}
 
Example 15
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 16
Source File: TestMaterialWrite.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testWriteMat() throws Exception {

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

    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Diffuse", ColorRGBA.White);
    mat.setColor("Ambient", ColorRGBA.DarkGray);
    mat.setFloat("AlphaDiscardThreshold", 0.5f);

    mat.setFloat("Shininess", 2.5f);

    Texture tex = assetManager.loadTexture("Common/Textures/MissingTexture.png");
    tex.setMagFilter(Texture.MagFilter.Nearest);
    tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
    tex.setWrap(Texture.WrapAxis.S, Texture.WrapMode.Repeat);
    tex.setWrap(Texture.WrapAxis.T, Texture.WrapMode.MirroredRepeat);

    mat.setTexture("DiffuseMap", tex);
    mat.getAdditionalRenderState().setDepthWrite(false);
    mat.getAdditionalRenderState().setDepthTest(false);
    mat.getAdditionalRenderState().setLineWidth(5);
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);

    final ByteArrayOutputStream stream = new ByteArrayOutputStream();

    J3MExporter exporter = new J3MExporter();
    try {
        exporter.save(mat, stream);
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.err.println(stream.toString());

    J3MLoader loader = new J3MLoader();
    AssetInfo info = new AssetInfo(assetManager, new AssetKey("test")) {
        @Override
        public InputStream openStream() {
            return new ByteArrayInputStream(stream.toByteArray());
        }
    };
    Material mat2 = (Material)loader.load(info);

    assertTrue(mat.contentEquals(mat2));
}
 
Example 17
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 18
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 19
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 20
Source File: TestSimpleLighting.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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", 12);
        mat.setBoolean("UseMaterialColors", true);

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