Search in sources :

Example 66 with Texture2D

use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method setEdgeFilteringMode.

/**
     * Sets the filtering mode for shadow edges. See {@link EdgeFilteringMode}
     * for more info.
     *
     * @param filterMode the desired filter mode (not null)
     */
public final void setEdgeFilteringMode(EdgeFilteringMode filterMode) {
    if (filterMode == null) {
        throw new NullPointerException();
    }
    this.edgeFilteringMode = filterMode;
    postshadowMat.setInt("FilterMode", filterMode.getMaterialParamValue());
    postshadowMat.setFloat("PCFEdge", edgesThickness);
    if (shadowCompareMode == CompareMode.Hardware) {
        for (Texture2D shadowMap : shadowMaps) {
            if (filterMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        }
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Example 67 with Texture2D

use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR 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)

Example 68 with Texture2D

use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method setShadowCompareMode.

/**
     * Sets the shadow compare mode. See {@link CompareMode} for more info.
     *
     * @param compareMode the desired compare mode (not null)
     */
public final void setShadowCompareMode(CompareMode compareMode) {
    if (compareMode == null) {
        throw new IllegalArgumentException("Shadow compare mode cannot be null");
    }
    this.shadowCompareMode = compareMode;
    for (Texture2D shadowMap : shadowMaps) {
        if (compareMode == CompareMode.Hardware) {
            shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
            if (edgeFilteringMode == EdgeFilteringMode.Bilinear) {
                shadowMap.setMagFilter(MagFilter.Bilinear);
                shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
            } else {
                shadowMap.setMagFilter(MagFilter.Nearest);
                shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
            }
        } else {
            shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
            shadowMap.setMagFilter(MagFilter.Nearest);
            shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
        }
    }
    postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Example 69 with Texture2D

use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method setupFinalFullTexture.

private void setupFinalFullTexture(Camera cam) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // create offscreen framebuffer
            FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
            //offBuffer.setSrgb(true);
            //setup framebuffer's texture
            dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
            dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);
            logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")");
            logger.config("               Type: " + dualEyeTex.getType());
            logger.config("               Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight());
            logger.config("        Image depth: " + dualEyeTex.getImage().getDepth());
            logger.config("       Image format: " + dualEyeTex.getImage().getFormat());
            logger.config("  Image color space: " + dualEyeTex.getImage().getColorSpace());
            //setup framebuffer to use texture
            out.setDepthBuffer(Image.Format.Depth);
            out.setColorTexture(dualEyeTex);
            ViewPort viewPort = environment.getApplication().getViewPort();
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            viewPort.setOutputFrameBuffer(out);
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 70 with Texture2D

use of com.jme3.texture.Texture2D in project chordatlas by twak.

the class SkelFootprint method getColor.

public static ColorRGBA getColor(Geometry geom, Vector3f pt, int index, Tweed tweed) {
    MatParam param = geom.getMaterial().getParam("DiffuseMap");
    ImageRaster ir = ImageRaster.create(tweed.getAssetManager().loadTexture(((Texture2D) param.getValue()).getName()).getImage());
    Mesh mesh = geom.getMesh();
    // geom.getMaterial().getMaterialDef().
    VertexBuffer pb = mesh.getBuffer(Type.Position);
    VertexBuffer tb = mesh.getBuffer(Type.TexCoord);
    IndexBuffer ib = mesh.getIndicesAsList();
    Vector2f uva = new Vector2f(), uvb = new Vector2f(), uvc = new Vector2f();
    Vector3f la = new Vector3f(), lb = new Vector3f(), lc = new Vector3f();
    if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3) {
        FloatBuffer fpb = (FloatBuffer) pb.getData();
        FloatBuffer ftb = (FloatBuffer) tb.getData();
        // aquire triangle's vertex indices
        int vertIndex = index * 3;
        int va = ib.get(vertIndex);
        int vb = ib.get(vertIndex + 1);
        int vc = ib.get(vertIndex + 2);
        BufferUtils.populateFromBuffer(la, fpb, va);
        BufferUtils.populateFromBuffer(lb, fpb, vb);
        BufferUtils.populateFromBuffer(lc, fpb, vc);
        BufferUtils.populateFromBuffer(uva, ftb, va);
        BufferUtils.populateFromBuffer(uvb, ftb, vb);
        BufferUtils.populateFromBuffer(uvc, ftb, vc);
        // PaintThing.debug.put(1, new Line ( la.x, la.z, lb.x, lb.z) );
        // PaintThing.debug.put(2, new Line ( lb.x, lb.z, lc.x, lc.z) );
        // PaintThing.debug.put(3, new Line ( lc.x, lc.z, la.x, la.z) );
        float[] bary = barycentric(pt, la, lb, lc);
        int x = (int) ((uva.x * bary[0] + uvb.x * bary[1] + uvc.x * bary[2]) * ir.getWidth()), y = (int) ((uva.y * bary[0] + uvb.y * bary[1] + uvc.y * bary[2]) * ir.getHeight());
        // ir.getHeight() - y -1 );
        ColorRGBA out = ir.getPixel(x, y);
        return out;
    } else {
        throw new UnsupportedOperationException("Position buffer not set or has incompatible format");
    }
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) MatParam(com.jme3.material.MatParam) ColorRGBA(com.jme3.math.ColorRGBA) VertexBuffer(com.jme3.scene.VertexBuffer) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) ImageRaster(com.jme3.texture.image.ImageRaster) FloatBuffer(java.nio.FloatBuffer) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint)

Aggregations

Texture2D (com.jme3.texture.Texture2D)54 Material (com.jme3.material.Material)19 FrameBuffer (com.jme3.texture.FrameBuffer)18 Picture (com.jme3.ui.Picture)12 Geometry (com.jme3.scene.Geometry)11 Image (com.jme3.texture.Image)11 ViewPort (com.jme3.renderer.ViewPort)9 Texture (com.jme3.texture.Texture)9 Camera (com.jme3.renderer.Camera)8 Node (com.jme3.scene.Node)7 Spatial (com.jme3.scene.Spatial)7 TextureKey (com.jme3.asset.TextureKey)6 Vector3f (com.jme3.math.Vector3f)6 ByteBuffer (java.nio.ByteBuffer)6 Quaternion (com.jme3.math.Quaternion)5 BufferedImage (java.awt.image.BufferedImage)4 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 Vector2f (com.jme3.math.Vector2f)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3