Search in sources :

Example 1 with TextureCubeMap

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

the class J3MLoader method parseTextureType.

private Texture parseTextureType(final VarType type, final String value) {
    final List<String> textureValues = tokenizeTextureValue(value);
    final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);
    TextureKey textureKey = null;
    // If there is only one token on the value, it must be the path to the texture.
    if (textureValues.size() == 1) {
        textureKey = new TextureKey(textureValues.get(0), false);
    } else {
        String texturePath = value.trim();
        // If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
        if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
            boolean flipY = false;
            if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
                texturePath = texturePath.substring(12).trim();
                flipY = true;
            } else if (texturePath.startsWith("Flip ")) {
                texturePath = texturePath.substring(5).trim();
                flipY = true;
            } else if (texturePath.startsWith("Repeat ")) {
                texturePath = texturePath.substring(7).trim();
            }
            // Support path starting with quotes (double and single)
            if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
                texturePath = texturePath.substring(1);
            }
            // Support path ending with quotes (double and single)
            if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
                texturePath = texturePath.substring(0, texturePath.length() - 1);
            }
            textureKey = new TextureKey(texturePath, flipY);
        }
        if (textureKey == null) {
            textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
        }
        // Apply texture options to the texture key
        if (!textureOptionValues.isEmpty()) {
            for (final TextureOptionValue textureOptionValue : textureOptionValues) {
                textureOptionValue.applyToTextureKey(textureKey);
            }
        }
    }
    switch(type) {
        case Texture3D:
            textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
            break;
        case TextureArray:
            textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
            break;
        case TextureCubeMap:
            textureKey.setTextureTypeHint(Texture.Type.CubeMap);
            break;
    }
    textureKey.setGenerateMips(true);
    Texture texture;
    try {
        texture = assetManager.loadTexture(textureKey);
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { textureKey, key });
        texture = null;
    }
    if (texture == null) {
        texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
        texture.setKey(textureKey);
        texture.setName(textureKey.getName());
    }
    // Apply texture options to the texture
    if (!textureOptionValues.isEmpty()) {
        for (final TextureOptionValue textureOptionValue : textureOptionValues) {
            textureOptionValue.applyToTexture(texture);
        }
    }
    return texture;
}
Also used : Texture2D(com.jme3.texture.Texture2D) Texture(com.jme3.texture.Texture)

Example 2 with TextureCubeMap

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

the class EnvMapUtils method createPrefilteredEnvMap.

/**
     * initialize the pem map
     * @param size the size of the map
     * @param imageFormat the format of the image
     * @return the initialized prefiltered env map
     */
public static TextureCubeMap createPrefilteredEnvMap(int size, Image.Format imageFormat) {
    TextureCubeMap pem = new TextureCubeMap(size, size, imageFormat);
    pem.setMagFilter(Texture.MagFilter.Bilinear);
    pem.setMinFilter(Texture.MinFilter.Trilinear);
    pem.getImage().setColorSpace(ColorSpace.Linear);
    int nbMipMap = (int) (Math.log(size) / Math.log(2) - 1);
    CubeMapWrapper targetWrapper = new CubeMapWrapper(pem);
    targetWrapper.initMipMaps(nbMipMap);
    return pem;
}
Also used : TextureCubeMap(com.jme3.texture.TextureCubeMap)

Example 3 with TextureCubeMap

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

the class EnvMapUtils method generateIrradianceMap.

/**
     * Generates the Irradiance map (used for image based difuse lighting) from
     * Spherical Harmonics coefficients previously computed with
     * {@link EnvMapUtils#getSphericalHarmonicsCoefficents(com.jme3.texture.TextureCubeMap)}
     * Note that the output cube map is in RGBA8 format.
     *
     * @param shCoeffs the SH coeffs
     * @param targetMapSize the size of the irradiance map to generate
     * @param fixSeamsMethod the method to fix seams
     * @param store
     * @return The irradiance cube map for the given coefficients
     */
public static TextureCubeMap generateIrradianceMap(Vector3f[] shCoeffs, int targetMapSize, FixSeamsMethod fixSeamsMethod, TextureCubeMap store) {
    TextureCubeMap irrCubeMap = store;
    if (irrCubeMap == null) {
        irrCubeMap = new TextureCubeMap(targetMapSize, targetMapSize, Image.Format.RGB16F);
        irrCubeMap.setMagFilter(Texture.MagFilter.Bilinear);
        irrCubeMap.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
        irrCubeMap.getImage().setColorSpace(ColorSpace.Linear);
    }
    for (int i = 0; i < 6; i++) {
        ByteBuffer buf = BufferUtils.createByteBuffer(targetMapSize * targetMapSize * irrCubeMap.getImage().getFormat().getBitsPerPixel() / 8);
        irrCubeMap.getImage().setData(i, buf);
    }
    Vector3f texelVect = new Vector3f();
    ColorRGBA color = new ColorRGBA(ColorRGBA.Black);
    float[] shDir = new float[9];
    CubeMapWrapper envMapWriter = new CubeMapWrapper(irrCubeMap);
    for (int face = 0; face < 6; face++) {
        for (int y = 0; y < targetMapSize; y++) {
            for (int x = 0; x < targetMapSize; x++) {
                getVectorFromCubemapFaceTexCoord(x, y, targetMapSize, face, texelVect, fixSeamsMethod);
                evalShBasis(texelVect, shDir);
                color.set(0, 0, 0, 0);
                for (int i = 0; i < NUM_SH_COEFFICIENT; i++) {
                    color.set(color.r + shCoeffs[i].x * shDir[i] * shBandFactor[i], color.g + shCoeffs[i].y * shDir[i] * shBandFactor[i], color.b + shCoeffs[i].z * shDir[i] * shBandFactor[i], 1.0f);
                }
                //clamping the color because very low value close to zero produce artifacts
                color.r = Math.max(0.0001f, color.r);
                color.g = Math.max(0.0001f, color.g);
                color.b = Math.max(0.0001f, color.b);
                envMapWriter.setPixel(x, y, face, color);
            }
        }
    }
    return irrCubeMap;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) TextureCubeMap(com.jme3.texture.TextureCubeMap) Vector3f(com.jme3.math.Vector3f) ByteBuffer(java.nio.ByteBuffer)

Example 4 with TextureCubeMap

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

the class EnvMapUtils method createIrradianceMap.

/**
     * initialize the Irradiancemap
     * @param size the size of the map
     * @param imageFormat the format of the image
     * @return the initialized Irradiance map
     */
public static TextureCubeMap createIrradianceMap(int size, Image.Format imageFormat) {
    TextureCubeMap irrMap = new TextureCubeMap(size, size, imageFormat);
    irrMap.setMagFilter(Texture.MagFilter.Bilinear);
    irrMap.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
    irrMap.getImage().setColorSpace(ColorSpace.Linear);
    return irrMap;
}
Also used : TextureCubeMap(com.jme3.texture.TextureCubeMap)

Example 5 with TextureCubeMap

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

the class EnvMapUtils method getCubeMapCrossDebugView.

/**
     * Creates a debug Node of the given cube map to attach to the gui node
     *
     * the cube map is layered this way :
     * <pre>
     *         _____
     *        |     |
     *        | +Y  |
     *   _____|_____|_____ _____
     *  |     |     |     |     |
     *  | -X  | +Z  | +X  | -Z  |
     *  |_____|_____|_____|_____|
     *        |     |
     *        | -Y  |
     *        |_____|
     *
     *</pre>
     *
     * @param cubeMap the cube map
     * @param assetManager the asset Manager
     * @return
     */
public static Node getCubeMapCrossDebugView(TextureCubeMap cubeMap, AssetManager assetManager) {
    Node n = new Node("CubeMapDebug" + cubeMap.getName());
    int size = cubeMap.getImage().getWidth();
    Picture[] pics = new Picture[6];
    float ratio = 128f / (float) size;
    for (int i = 0; i < 6; i++) {
        pics[i] = new Picture("bla");
        Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, cubeMap.getImage().getData(i), cubeMap.getImage().getColorSpace()));
        pics[i].setTexture(assetManager, tex, true);
        pics[i].setWidth(size);
        pics[i].setHeight(size);
        n.attachChild(pics[i]);
    }
    pics[0].setLocalTranslation(size, size * 2, 1);
    pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[1].setLocalTranslation(size * 3, size * 2, 1);
    pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[2].setLocalTranslation(size * 2, size * 3, 1);
    pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[3].setLocalTranslation(size * 2, size, 1);
    pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[4].setLocalTranslation(size * 2, size * 2, 1);
    pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[5].setLocalTranslation(size * 4, size * 2, 1);
    pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    Quad q = new Quad(size * 4, size * 3);
    Geometry g = new Geometry("bg", q);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Black);
    g.setMaterial(mat);
    g.setLocalTranslation(0, 0, 0);
    n.attachChild(g);
    n.setLocalScale(ratio);
    return n;
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Texture2D(com.jme3.texture.Texture2D) Quaternion(com.jme3.math.Quaternion) Picture(com.jme3.ui.Picture) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Image(com.jme3.texture.Image)

Aggregations

TextureCubeMap (com.jme3.texture.TextureCubeMap)16 Image (com.jme3.texture.Image)10 ColorRGBA (com.jme3.math.ColorRGBA)6 Vector3f (com.jme3.math.Vector3f)6 ByteBuffer (java.nio.ByteBuffer)6 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Texture2D (com.jme3.texture.Texture2D)4 ArrayList (java.util.ArrayList)4 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)3 TextureKey (com.jme3.asset.TextureKey)2 BoundingSphere (com.jme3.bounding.BoundingSphere)2 CubeMapWrapper (com.jme3.environment.util.CubeMapWrapper)2 Quaternion (com.jme3.math.Quaternion)2 Node (com.jme3.scene.Node)2 Quad (com.jme3.scene.shape.Quad)2 Texture (com.jme3.texture.Texture)2 Picture (com.jme3.ui.Picture)2 IrradianceMapGenerator (com.jme3.environment.generation.IrradianceMapGenerator)1 PrefilteredEnvMapFaceGenerator (com.jme3.environment.generation.PrefilteredEnvMapFaceGenerator)1