Search in sources :

Example 41 with Material

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

the class AbstractShadowRendererVR method postFrame.

public void postFrame(FrameBuffer out) {
    if (skipPostPass) {
        return;
    }
    if (debug) {
        displayShadowMap(renderManager.getRenderer());
    }
    getReceivers(lightReceivers);
    if (lightReceivers.size() != 0) {
        //setting params to recieving geometry list
        setMatParams(lightReceivers);
        Camera cam = viewPort.getCamera();
        //some materials in the scene does not have a post shadow technique so we're using the fall back material
        if (needsfallBackMaterial) {
            renderManager.setForcedMaterial(postshadowMat);
        }
        //forcing the post shadow technique and render state
        renderManager.setForcedTechnique(postTechniqueName);
        //rendering the post shadow pass
        viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
        //resetting renderManager settings
        renderManager.setForcedTechnique(null);
        renderManager.setForcedMaterial(null);
        renderManager.setCamera(cam, false);
        //clearing the params in case there are some other shadow renderers
        clearMatParams();
    }
}
Also used : Camera(com.jme3.renderer.Camera)

Example 42 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 43 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 44 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 45 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)285 Geometry (com.jme3.scene.Geometry)165 Vector3f (com.jme3.math.Vector3f)110 Box (com.jme3.scene.shape.Box)79 Texture (com.jme3.texture.Texture)69 DirectionalLight (com.jme3.light.DirectionalLight)49 Sphere (com.jme3.scene.shape.Sphere)43 Node (com.jme3.scene.Node)39 ColorRGBA (com.jme3.math.ColorRGBA)38 Spatial (com.jme3.scene.Spatial)35 Quaternion (com.jme3.math.Quaternion)31 Quad (com.jme3.scene.shape.Quad)26 Texture2D (com.jme3.texture.Texture2D)21 KeyTrigger (com.jme3.input.controls.KeyTrigger)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 ArrayList (java.util.ArrayList)19 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 TextureKey (com.jme3.asset.TextureKey)17 ParticleEmitter (com.jme3.effect.ParticleEmitter)17 AmbientLight (com.jme3.light.AmbientLight)16