Search in sources :

Example 56 with Texture2D

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

the class EnvironmentCamera method initialize.

@Override
protected void initialize(Application app) {
    this.backGroundColor = app.getViewPort().getBackgroundColor();
    final Camera[] cameras = new Camera[6];
    Texture2D[] textures = new Texture2D[6];
    viewports = new ViewPort[6];
    framebuffers = new FrameBuffer[6];
    buffers = new ByteBuffer[6];
    images = new Image[6];
    for (int i = 0; i < 6; i++) {
        cameras[i] = createOffCamera(size, position, axisX[i], axisY[i], axisZ[i]);
        viewports[i] = createOffViewPort("EnvView" + i, cameras[i]);
        framebuffers[i] = createOffScreenFrameBuffer(size, viewports[i]);
        textures[i] = new Texture2D(size, size, imageFormat);
        framebuffers[i].setColorTexture(textures[i]);
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Camera(com.jme3.renderer.Camera)

Example 57 with Texture2D

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

the class AbstractShadowRenderer 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 58 with Texture2D

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

the class PssmShadowRenderer method setCompareMode.

/**
     * sets the shadow compare mode see {@link CompareMode} for more info
     *
     * @param compareMode
     */
public final void setCompareMode(CompareMode compareMode) {
    if (compareMode == null) {
        throw new NullPointerException();
    }
    if (this.compareMode == compareMode) {
        return;
    }
    this.compareMode = compareMode;
    for (Texture2D shadowMap : shadowMaps) {
        if (compareMode == CompareMode.Hardware) {
            shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
            if (filterMode == FilterMode.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);
    applyHWShadows = true;
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Example 59 with Texture2D

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

the class KTXWriter method write.

/**
     * Writes an image with the given params
     * 
     * textureType, allows one to write textureArrays, Texture3D, and TextureCubeMaps.
     * Texture2D will write a 2D image.
     * Note that the fileName should contain the extension (.ktx sounds like a wise choice)
     * @param image the image to write
     * @param textureType the texture type
     * @param fileName the name of the file to write
     */
public void write(Image image, Class<? extends Texture> textureType, String fileName) {
    FileOutputStream outs = null;
    try {
        File file = new File(filePath + "/" + fileName);
        outs = new FileOutputStream(file);
        DataOutput out = new DataOutputStream(outs);
        //fileID
        out.write(fileIdentifier);
        //endianness
        out.writeInt(0x04030201);
        GLImageFormat format = getGlFormat(image.getFormat());
        //glType
        out.writeInt(format.dataType);
        //glTypeSize
        out.writeInt(1);
        //glFormat
        out.writeInt(format.format);
        //glInernalFormat
        out.writeInt(format.internalFormat);
        //glBaseInternalFormat
        out.writeInt(format.format);
        //pixelWidth
        out.writeInt(image.getWidth());
        //pixelHeight
        out.writeInt(image.getHeight());
        int pixelDepth = 1;
        int numberOfArrayElements = 1;
        int numberOfFaces = 1;
        if (image.getDepth() > 1) {
            //pixelDepth
            if (textureType == Texture3D.class) {
                pixelDepth = image.getDepth();
            }
        }
        if (image.getData().size() > 1) {
            //numberOfArrayElements
            if (textureType == TextureArray.class) {
                numberOfArrayElements = image.getData().size();
            }
            //numberOfFaces                
            if (textureType == TextureCubeMap.class) {
                numberOfFaces = image.getData().size();
            }
        }
        out.writeInt(pixelDepth);
        out.writeInt(numberOfArrayElements);
        out.writeInt(numberOfFaces);
        int numberOfMipmapLevels = 1;
        //numberOfMipmapLevels
        if (image.hasMipmaps()) {
            numberOfMipmapLevels = image.getMipMapSizes().length;
        }
        out.writeInt(numberOfMipmapLevels);
        //bytesOfKeyValueData
        String keyValues = "KTXorientation\0S=r,T=u\0";
        int bytesOfKeyValueData = keyValues.length() + 4;
        int padding = 3 - ((bytesOfKeyValueData + 3) % 4);
        bytesOfKeyValueData += padding;
        out.writeInt(bytesOfKeyValueData);
        //keyAndValueByteSize
        out.writeInt(bytesOfKeyValueData - 4 - padding);
        //values
        out.writeBytes(keyValues);
        pad(padding, out);
        int offset = 0;
        //iterate over data
        for (int mipLevel = 0; mipLevel < numberOfMipmapLevels; mipLevel++) {
            int width = Math.max(1, image.getWidth() >> mipLevel);
            int height = Math.max(1, image.getHeight() >> mipLevel);
            int imageSize;
            if (image.hasMipmaps()) {
                imageSize = image.getMipMapSizes()[mipLevel];
            } else {
                imageSize = width * height * image.getFormat().getBitsPerPixel() / 8;
            }
            out.writeInt(imageSize);
            for (int arrayElem = 0; arrayElem < numberOfArrayElements; arrayElem++) {
                for (int face = 0; face < numberOfFaces; face++) {
                    int nbPixelWritten = 0;
                    for (int depth = 0; depth < pixelDepth; depth++) {
                        ByteBuffer byteBuffer = image.getData(getSlice(face, arrayElem));
                        // BufferUtils.ensureLargeEnough(byteBuffer, imageSize);
                        log.log(Level.FINE, "position {0}", byteBuffer.position());
                        byteBuffer.position(offset);
                        byte[] b = getByteBufferArray(byteBuffer, imageSize);
                        out.write(b);
                        nbPixelWritten = b.length;
                    }
                    //cube padding
                    if (numberOfFaces == 6 && numberOfArrayElements == 0) {
                        padding = 3 - ((nbPixelWritten + 3) % 4);
                        pad(padding, out);
                    }
                }
            }
            //mip padding
            log.log(Level.FINE, "skipping {0}", (3 - ((imageSize + 3) % 4)));
            padding = 3 - ((imageSize + 3) % 4);
            pad(padding, out);
            offset += imageSize;
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(KTXWriter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(KTXWriter.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            if (outs != null) {
                outs.close();
            }
        } catch (IOException ex) {
            Logger.getLogger(KTXWriter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) GLImageFormat(com.jme3.renderer.opengl.GLImageFormat) File(java.io.File) ByteBuffer(java.nio.ByteBuffer)

Example 60 with Texture2D

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

the class MaterialMatParamTest method testTextureMpoOnly.

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

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