Search in sources :

Example 21 with Texture2D

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

the class FilterPostProcessor method renderFilterChain.

/**
     * iterate through the filter list and renders filters
     * @param r
     * @param sceneFb 
     */
private void renderFilterChain(Renderer r, FrameBuffer sceneFb) {
    Texture2D tex = filterTexture;
    FrameBuffer buff = sceneFb;
    boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1;
    for (int i = 0; i < filters.size(); i++) {
        Filter filter = filters.get(i);
        if (prof != null)
            prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName());
        if (filter.isEnabled()) {
            if (filter.getPostRenderPasses() != null) {
                for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator(); it1.hasNext(); ) {
                    Filter.Pass pass = it1.next();
                    if (prof != null)
                        prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), pass.toString());
                    pass.beforeRender();
                    if (pass.requiresSceneAsTexture()) {
                        pass.getPassMaterial().setTexture("Texture", tex);
                        if (tex.getImage().getMultiSamples() > 1) {
                            pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples());
                        } else {
                            pass.getPassMaterial().clearParam("NumSamples");
                        }
                    }
                    if (pass.requiresDepthAsTexture()) {
                        pass.getPassMaterial().setTexture("DepthTexture", depthTexture);
                        if (msDepth) {
                            pass.getPassMaterial().setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
                        } else {
                            pass.getPassMaterial().clearParam("NumSamplesDepth");
                        }
                    }
                    renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial());
                }
            }
            if (prof != null)
                prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "postFrame");
            filter.postFrame(renderManager, viewPort, buff, sceneFb);
            Material mat = filter.getMaterial();
            if (msDepth && filter.isRequiresDepthTexture()) {
                mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
            }
            if (filter.isRequiresSceneTexture()) {
                mat.setTexture("Texture", tex);
                if (tex.getImage().getMultiSamples() > 1) {
                    mat.setInt("NumSamples", tex.getImage().getMultiSamples());
                } else {
                    mat.clearParam("NumSamples");
                }
            }
            boolean wantsBilinear = filter.isRequiresBilinear();
            if (wantsBilinear) {
                tex.setMagFilter(Texture.MagFilter.Bilinear);
                tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            }
            buff = outputBuffer;
            if (i != lastFilterIndex) {
                buff = filter.getRenderFrameBuffer();
                tex = filter.getRenderedTexture();
            }
            if (prof != null)
                prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "render");
            renderProcessing(r, buff, mat);
            if (prof != null)
                prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "postFilter");
            filter.postFilter(r, buff);
            if (wantsBilinear) {
                tex.setMagFilter(Texture.MagFilter.Nearest);
                tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
            }
        }
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 22 with Texture2D

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

the class FilterPostProcessor method reshape.

public void reshape(ViewPort vp, int w, int h) {
    Camera cam = vp.getCamera();
    //this has no effect at first init but is useful when resizing the canvas with multi views
    cam.setViewPort(left, right, bottom, top);
    //resizing the camera to fit the new viewport and saving original dimensions
    cam.resize(w, h, false);
    left = cam.getViewPortLeft();
    right = cam.getViewPortRight();
    top = cam.getViewPortTop();
    bottom = cam.getViewPortBottom();
    originalWidth = w;
    originalHeight = h;
    //computing real dimension of the viewport and resizing the camera 
    width = (int) (w * (Math.abs(right - left)));
    height = (int) (h * (Math.abs(bottom - top)));
    width = Math.max(1, width);
    height = Math.max(1, height);
    //camera must be handled differently
    if (originalWidth != width || originalHeight != height) {
        multiView = true;
    }
    cameraInit = true;
    computeDepth = false;
    if (renderFrameBuffer == null && renderFrameBufferMS == null) {
        outputBuffer = viewPort.getOutputFrameBuffer();
    }
    Collection<Caps> caps = renderer.getCaps();
    //antialiasing on filters only supported in opengl 3 due to depth read problem
    if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample)) {
        renderFrameBufferMS = new FrameBuffer(width, height, numSamples);
        if (caps.contains(Caps.OpenGL32)) {
            Texture2D msColor = new Texture2D(width, height, numSamples, fbFormat);
            Texture2D msDepth = new Texture2D(width, height, numSamples, Format.Depth);
            renderFrameBufferMS.setDepthTexture(msDepth);
            renderFrameBufferMS.setColorTexture(msColor);
            filterTexture = msColor;
            depthTexture = msDepth;
        } else {
            renderFrameBufferMS.setDepthBuffer(Format.Depth);
            renderFrameBufferMS.setColorBuffer(fbFormat);
        }
    }
    if (numSamples <= 1 || !caps.contains(Caps.OpenGL32)) {
        renderFrameBuffer = new FrameBuffer(width, height, 1);
        renderFrameBuffer.setDepthBuffer(Format.Depth);
        filterTexture = new Texture2D(width, height, fbFormat);
        renderFrameBuffer.setColorTexture(filterTexture);
    }
    for (Filter filter : filters.getArray()) {
        initFilter(filter, vp);
    }
    setupViewPortFrameBuffer();
}
Also used : Texture2D(com.jme3.texture.Texture2D) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 23 with Texture2D

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

the class HDRRenderer method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    if (!enabled)
        return;
    renderer = rm.getRenderer();
    renderManager = rm;
    viewPort = vp;
    // loadInitial()
    fsQuad = new Picture("HDR Fullscreen Quad");
    Format lumFmt = Format.RGB8;
    scene64FB = new FrameBuffer(64, 64, 1);
    scene64 = new Texture2D(64, 64, lumFmt);
    scene64FB.setColorTexture(scene64);
    scene64.setMagFilter(fbMagFilter);
    scene64.setMinFilter(fbMinFilter);
    scene8FB = new FrameBuffer(8, 8, 1);
    scene8 = new Texture2D(8, 8, lumFmt);
    scene8FB.setColorTexture(scene8);
    scene8.setMagFilter(fbMagFilter);
    scene8.setMinFilter(fbMinFilter);
    scene1FB[0] = new FrameBuffer(1, 1, 1);
    scene1[0] = new Texture2D(1, 1, lumFmt);
    scene1FB[0].setColorTexture(scene1[0]);
    scene1FB[1] = new FrameBuffer(1, 1, 1);
    scene1[1] = new Texture2D(1, 1, lumFmt);
    scene1FB[1].setColorTexture(scene1[1]);
    // prepare tonemap shader
    tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
    tone.setFloat("A", 0.18f);
    tone.setFloat("White", 100);
    // load();
    int w = vp.getCamera().getWidth();
    int h = vp.getCamera().getHeight();
    reshape(vp, w, h);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Format(com.jme3.texture.Image.Format) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 24 with Texture2D

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

the class TestSoftwareMouse method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);
    //        inputManager.setCursorVisible(false);
    Texture tex = assetManager.loadTexture("Interface/Logo/Cursor.png");
    cursor = new Picture("cursor");
    cursor.setTexture(assetManager, (Texture2D) tex, true);
    cursor.setWidth(64);
    cursor.setHeight(64);
    guiNode.attachChild(cursor);
    inputManager.addRawInputListener(inputListener);
//        Image img = tex.getImage();
//        ByteBuffer data = img.getData(0);
//        IntBuffer image = BufferUtils.createIntBuffer(64 * 64);
//        for (int y = 0; y < 64; y++){
//            for (int x = 0; x < 64; x++){
//                int rgba = data.getInt();
//                image.put(rgba);
//            }
//        }
//        image.clear();
//
//        try {
//            Cursor cur = new Cursor(64, 64, 2, 62, 1, image, null);
//            Mouse.setNativeCursor(cur);
//        } catch (LWJGLException ex) {
//            Logger.getLogger(TestSoftwareMouse.class.getName()).log(Level.SEVERE, null, ex);
//        }
}
Also used : Picture(com.jme3.ui.Picture) Texture(com.jme3.texture.Texture)

Example 25 with Texture2D

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

the class FbxTexture method toJmeObject.

@Override
protected Texture toJmeObject() {
    Image image = null;
    TextureKey key = null;
    if (media != null) {
        image = (Image) media.getJmeObject();
        key = media.getTextureKey();
    }
    if (image == null) {
        image = PlaceholderAssets.getPlaceholderImage(assetManager);
    }
    Texture2D tex = new Texture2D(image);
    if (key != null) {
        tex.setKey(key);
        tex.setName(key.getName());
        tex.setAnisotropicFilter(key.getAnisotropy());
    }
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);
    if (wrapModeU == 0) {
        tex.setWrap(WrapAxis.S, WrapMode.Repeat);
    }
    if (wrapModeV == 0) {
        tex.setWrap(WrapAxis.T, WrapMode.Repeat);
    }
    return tex;
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D) Image(com.jme3.texture.Image)

Aggregations

Texture2D (com.jme3.texture.Texture2D)53 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)10 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 ByteBuffer (java.nio.ByteBuffer)6 Quaternion (com.jme3.math.Quaternion)5 Vector3f (com.jme3.math.Vector3f)5 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 Box (com.jme3.scene.shape.Box)3 BufferedImage (java.awt.image.BufferedImage)3