Search in sources :

Example 46 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class LightScatteringFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    this.viewPort = vp;
    material = new Material(manager, "Common/MatDefs/Post/LightScattering.j3md");
}
Also used : Material(com.jme3.material.Material)

Example 47 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class PssmShadowRenderer method setMatParams.

private void setMatParams() {
    GeometryList l = lightReceivers;
    //iteration throught all the geometries of the list to gather the materials
    matCache.clear();
    for (int i = 0; i < l.size(); i++) {
        Material mat = l.get(i).getMaterial();
        //checking if the material has the post technique and adding it to the material cache
        if (mat.getMaterialDef().getTechniqueDefs(postTechniqueName) != null) {
            if (!matCache.contains(mat)) {
                matCache.add(mat);
            }
        } else {
            needsfallBackMaterial = true;
        }
    }
    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {
        mat.setColor("Splits", splits);
        mat.setFloat("ShadowMapSize", shadowMapSize);
        for (int j = 0; j < nbSplits; j++) {
            mat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]);
        }
        for (int j = 0; j < nbSplits; j++) {
            mat.setTexture("ShadowMap" + j, shadowMaps[j]);
        }
        mat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", filterMode.ordinal());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        if (fadeInfo != null) {
            mat.setVector2("FadeInfo", fadeInfo);
        }
    }
    applyHWShadows = false;
    applyFilterMode = false;
    applyPCFEdge = false;
    applyShadowIntensity = false;
    applyFadeInfo = false;
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }
}
Also used : GeometryList(com.jme3.renderer.queue.GeometryList) Material(com.jme3.material.Material)

Example 48 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class InstancedNode method addToInstancedGeometry.

private void addToInstancedGeometry(Geometry geom) {
    Material material = geom.getMaterial();
    MatParam param = material.getParam("UseInstancing");
    if (param == null || !((Boolean) param.getValue()).booleanValue()) {
        throw new IllegalStateException("You must set the 'UseInstancing' " + "parameter to true on the material prior " + "to adding it to InstancedNode");
    }
    InstancedGeometry ig = lookUpByGeometry(geom);
    igByGeom.put(geom, ig);
    geom.associateWithGroupNode(this, 0);
    ig.addInstance(geom);
}
Also used : MatParam(com.jme3.material.MatParam) Material(com.jme3.material.Material)

Example 49 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method clearMatParams.

private void clearMatParams() {
    for (Material mat : matCache) {
        //at least 1 shadow map and will set it on each frame anyway.
        for (int j = 1; j < nbShadowMaps; j++) {
            mat.clearParam(lightViewStringCache[j]);
        }
        for (int j = 1; j < nbShadowMaps; j++) {
            mat.clearParam(shadowMapStringCache[j]);
        }
        mat.clearParam("FadeInfo");
        clearMaterialParameters(mat);
    }
//No need to clear the postShadowMat params as the instance is locale to each renderer       
}
Also used : Material(com.jme3.material.Material)

Example 50 with Material

use of com.jme3.material.Material in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRenderer method init.

private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
    shadowMapStringCache = new String[nbShadowMaps];
    lightViewStringCache = new String[nbShadowMaps];
    //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);
    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
    for (int i = 0; i < nbShadowMaps; i++) {
        lightViewProjectionsMatrices[i] = new Matrix4f();
        shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
        shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
        shadowFB[i].setDepthTexture(shadowMaps[i]);
        //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
        shadowFB[i].setColorTexture(dummyTex);
        shadowMapStringCache[i] = "ShadowMap" + i;
        lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
        postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
        //quads for debuging purpose
        dispPic[i] = new Picture("Picture" + i);
        dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }
    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
    initForcedRenderState();
}
Also used : Texture2D(com.jme3.texture.Texture2D) Matrix4f(com.jme3.math.Matrix4f) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Aggregations

Material (com.jme3.material.Material)310 Geometry (com.jme3.scene.Geometry)191 Vector3f (com.jme3.math.Vector3f)120 Box (com.jme3.scene.shape.Box)81 Texture (com.jme3.texture.Texture)70 Spatial (com.jme3.scene.Spatial)53 DirectionalLight (com.jme3.light.DirectionalLight)49 ColorRGBA (com.jme3.math.ColorRGBA)47 Node (com.jme3.scene.Node)47 Sphere (com.jme3.scene.shape.Sphere)44 Quaternion (com.jme3.math.Quaternion)31 Quad (com.jme3.scene.shape.Quad)26 ArrayList (java.util.ArrayList)25 Texture2D (com.jme3.texture.Texture2D)21 KeyTrigger (com.jme3.input.controls.KeyTrigger)20 Mesh (com.jme3.scene.Mesh)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 TextureKey (com.jme3.asset.TextureKey)18 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 ParticleEmitter (com.jme3.effect.ParticleEmitter)17