Search in sources :

Example 6 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class MaterialMatParamTest method testRemoveTextureOverride.

@Test
public void testRemoveTextureOverride() {
    material("Common/MatDefs/Light/Lighting.j3md");
    Texture2D tex1 = new Texture2D(128, 128, Format.RGBA8);
    Texture2D tex2 = new Texture2D(128, 128, Format.RGBA8);
    reset();
    inputMp(mpoTexture2D("DiffuseMap", tex1));
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex1);
    reset();
    inputMpo(mpoTexture2D("DiffuseMap", tex2));
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex2));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex2);
    reset();
    geometry.clearMatParamOverrides();
    root.updateGeometricState();
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex1));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex1);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Test(org.junit.Test)

Example 7 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class LightSortTest method testSceneGraphSort.

@Test
public void testSceneGraphSort() {
    Node n = new Node("node");
    Geometry g = new Geometry("geom", new Mesh());
    SpotLight spot = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X);
    PointLight point = new PointLight(Vector3f.UNIT_X);
    DirectionalLight directional = new DirectionalLight(Vector3f.UNIT_X);
    AmbientLight ambient = new AmbientLight();
    // Some lights are on the node
    n.addLight(spot);
    n.addLight(point);
    // .. and some on the geometry.
    g.addLight(directional);
    g.addLight(ambient);
    n.attachChild(g);
    n.updateGeometricState();
    LightList list = g.getWorldLightList();
    // check the sorting (when geom is at 0,0,0)
    assert list.get(0) instanceof AmbientLight;
    assert list.get(1) instanceof DirectionalLight;
    assert list.get(2) instanceof SpotLight;
    assert list.get(3) instanceof PointLight;
    // move the geometry closer to the point light
    g.setLocalTranslation(Vector3f.UNIT_X);
    n.updateGeometricState();
    assert list.get(0) instanceof AmbientLight;
    assert list.get(1) instanceof DirectionalLight;
    assert list.get(2) instanceof PointLight;
    assert list.get(3) instanceof SpotLight;
// now move the point light away from the geometry
// and the spot light closer
// XXX: doesn't work! jME can't detect that the light moved!
//        point.setPosition(Vector3f.ZERO);
//        spot.setPosition(Vector3f.UNIT_X);
//        n.updateGeometricState();
//        
//        assert list.get(0) instanceof AmbientLight;
//        assert list.get(1) instanceof DirectionalLight;
//        assert list.get(2) instanceof SpotLight;
//        assert list.get(3) instanceof PointLight;
}
Also used : Geometry(com.jme3.scene.Geometry) Node(com.jme3.scene.Node) Mesh(com.jme3.scene.Mesh) Test(org.junit.Test)

Example 8 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class MaterialContext method applyMaterial.

/**
     * Applies material to a given geometry.
     * 
     * @param geometry
     *            the geometry
     * @param geometriesOMA
     *            the geometries OMA
     * @param userDefinedUVCoordinates
     *            UV coords defined by user
     * @param blenderContext
     *            the blender context
     */
public void applyMaterial(Geometry geometry, Long geometriesOMA, Map<String, List<Vector2f>> userDefinedUVCoordinates, BlenderContext blenderContext) {
    Material material = null;
    if (shadeless) {
        material = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
        if (!transparent) {
            diffuseColor.a = 1;
        }
        material.setColor("Color", diffuseColor);
    } else {
        material = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
        material.setBoolean("UseMaterialColors", Boolean.TRUE);
        // setting the colors
        if (!transparent) {
            diffuseColor.a = 1;
        }
        material.setColor("Diffuse", diffuseColor);
        material.setColor("Specular", specularColor);
        material.setFloat("Shininess", shininess);
        material.setColor("Ambient", new ColorRGBA(ambientFactor, ambientFactor, ambientFactor, 1f));
    }
    // applying textures
    int textureIndex = 0;
    if (loadedTextures != null && loadedTextures.size() > 0) {
        if (loadedTextures.size() > TextureHelper.TEXCOORD_TYPES.length) {
            LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different textures. JME supports only {0} UV mappings.", TextureHelper.TEXCOORD_TYPES.length);
        }
        for (CombinedTexture combinedTexture : loadedTextures) {
            if (textureIndex < TextureHelper.TEXCOORD_TYPES.length) {
                String usedUserUVSet = combinedTexture.flatten(geometry, geometriesOMA, userDefinedUVCoordinates, blenderContext);
                this.setTexture(material, combinedTexture.getMappingType(), combinedTexture.getResultTexture());
                List<Vector2f> uvs = combinedTexture.getResultUVS();
                if (uvs != null && uvs.size() > 0) {
                    VertexBuffer uvCoordsBuffer = new VertexBuffer(TextureHelper.TEXCOORD_TYPES[textureIndex++]);
                    uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()])));
                    geometry.getMesh().setBuffer(uvCoordsBuffer);
                }
                if (usedUserUVSet != null) {
                    userDefinedUVCoordinates = new HashMap<>(userDefinedUVCoordinates);
                    userDefinedUVCoordinates.remove(usedUserUVSet);
                }
            } else {
                LOGGER.log(Level.WARNING, "The texture could not be applied because JME only supports up to {0} different UV's.", TextureHelper.TEXCOORD_TYPES.length);
            }
        }
    }
    if (userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) {
        LOGGER.fine("Storing unused, user defined UV coordinates sets.");
        if (userDefinedUVCoordinates.size() > TextureHelper.TEXCOORD_TYPES.length) {
            LOGGER.log(Level.WARNING, "The blender file has defined more than {0} different UV coordinates for the mesh. JME supports only {0} UV coordinates buffers.", TextureHelper.TEXCOORD_TYPES.length);
        }
        for (Entry<String, List<Vector2f>> entry : userDefinedUVCoordinates.entrySet()) {
            if (textureIndex < TextureHelper.TEXCOORD_TYPES.length) {
                List<Vector2f> uvs = entry.getValue();
                VertexBuffer uvCoordsBuffer = new VertexBuffer(TextureHelper.TEXCOORD_TYPES[textureIndex++]);
                uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, BufferUtils.createFloatBuffer(uvs.toArray(new Vector2f[uvs.size()])));
                geometry.getMesh().setBuffer(uvCoordsBuffer);
            } else {
                LOGGER.log(Level.WARNING, "The user's UV set named: '{0}' could not be stored because JME only supports up to {1} different UV's.", new Object[] { entry.getKey(), TextureHelper.TEXCOORD_TYPES.length });
            }
        }
    }
    // applying additional data
    material.setName(name);
    if (vertexColor) {
        material.setBoolean(shadeless ? "VertexColor" : "UseVertexColor", true);
    }
    material.getAdditionalRenderState().setFaceCullMode(faceCullMode != null ? faceCullMode : blenderContext.getBlenderKey().getFaceCullMode());
    if (transparent) {
        material.setTransparent(true);
        material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
        geometry.setQueueBucket(Bucket.Transparent);
    }
    geometry.setMaterial(material);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) VertexBuffer(com.jme3.scene.VertexBuffer) Vector2f(com.jme3.math.Vector2f) Material(com.jme3.material.Material) List(java.util.List) CombinedTexture(com.jme3.scene.plugins.blender.textures.CombinedTexture)

Example 9 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class TestBloomAlphaThreshold method simpleInitApp.

@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);
    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);
    Material matBox = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matBox.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
    matBox.setFloat("AlphaDiscardThreshold", 0.5f);
    Geometry box = new Geometry("box", new Box(new Vector3f(-3.5f, 10, -2), 2, 2, 2));
    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", false);
    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();
}
Also used : Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 10 with Light

use of com.jme3.light.Light in project jmonkeyengine by jMonkeyEngine.

the class TestMonkeyHead method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    Spatial bumpy = (Spatial) assetManager.loadModel("Models/MonkeyHead/MonkeyHead.mesh.xml");
    rootNode.attachChild(bumpy);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);
    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    // sunset light
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
    rootNode.addLight(dl);
    // skylight
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.6f, -1, -0.6f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f));
    rootNode.addLight(dl);
    // white ambient light
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight)

Aggregations

Vector3f (com.jme3.math.Vector3f)64 Material (com.jme3.material.Material)61 DirectionalLight (com.jme3.light.DirectionalLight)55 Geometry (com.jme3.scene.Geometry)52 PointLight (com.jme3.light.PointLight)27 Spatial (com.jme3.scene.Spatial)27 Box (com.jme3.scene.shape.Box)26 Sphere (com.jme3.scene.shape.Sphere)26 ColorRGBA (com.jme3.math.ColorRGBA)24 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)21 AmbientLight (com.jme3.light.AmbientLight)20 Texture (com.jme3.texture.Texture)18 SpotLight (com.jme3.light.SpotLight)16 FilterPostProcessor (com.jme3.post.FilterPostProcessor)15 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 Test (org.junit.Test)11 TempVars (com.jme3.util.TempVars)10 Light (com.jme3.light.Light)9 Camera (com.jme3.renderer.Camera)9