Search in sources :

Example 71 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class PrefilteredEnvMapFaceGenerator method prefilterEnvMapTexel.

private Vector3f prefilterEnvMapTexel(CubeMapWrapper envMapReader, float roughness, Vector3f N, int numSamples, Vector3f store) {
    Vector3f prefilteredColor = store;
    float totalWeight = 0.0f;
    // a = roughness² and a2 = a²
    float a2 = roughness * roughness;
    a2 *= a2;
    a2 *= 10;
    for (int i = 0; i < numSamples; i++) {
        Xi = getHammersleyPoint(i, numSamples, Xi);
        H = importanceSampleGGX(Xi, a2, N, H);
        H.normalizeLocal();
        tmp.set(H);
        float NoH = N.dot(tmp);
        Vector3f L = tmp.multLocal(NoH * 2).subtractLocal(N);
        float NoL = clamp(N.dot(L), 0.0f, 1.0f);
        if (NoL > 0) {
            envMapReader.getPixel(L, c);
            prefilteredColor.setX(prefilteredColor.x + c.r * NoL);
            prefilteredColor.setY(prefilteredColor.y + c.g * NoL);
            prefilteredColor.setZ(prefilteredColor.z + c.b * NoL);
            totalWeight += NoL;
        }
    }
    return prefilteredColor.divideLocal(totalWeight);
}
Also used : Vector3f(com.jme3.math.Vector3f) EnvMapUtils.getHammersleyPoint(com.jme3.environment.util.EnvMapUtils.getHammersleyPoint)

Example 72 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class PrefilteredEnvMapFaceGenerator method importanceSampleGGX.

public Vector3f importanceSampleGGX(Vector4f xi, float a2, Vector3f normal, Vector3f store) {
    if (store == null) {
        store = new Vector3f();
    }
    float cosTheta = sqrt((1f - xi.x) / (1f + (a2 - 1f) * xi.x));
    float sinTheta = sqrt(1f - cosTheta * cosTheta);
    //xi.z is cos(phi)
    float sinThetaCosPhi = sinTheta * xi.z;
    //xi.w is sin(phi)
    float sinThetaSinPhi = sinTheta * xi.w;
    Vector3f upVector = Vector3f.UNIT_X;
    if (abs(normal.z) < 0.999) {
        upVector = Vector3f.UNIT_Y;
    }
    Vector3f tangentX = tmp1.set(upVector).crossLocal(normal).normalizeLocal();
    Vector3f tangentY = tmp2.set(normal).crossLocal(tangentX);
    // Tangent to world space
    tangentX.multLocal(sinThetaCosPhi);
    tangentY.multLocal(sinThetaSinPhi);
    tmp3.set(normal).multLocal(cosTheta);
    // Tangent to world space
    store.set(tangentX).addLocal(tangentY).addLocal(tmp3);
    return store;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 73 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class CubeMapWrapper method getPixel.

/**
     * 
     * Reads a pixel from the cube map given the coordinate vector
     * @param vector the direction vector to fetch the texel
     * @param mipLevel the mip level to read from
     * @param store the color in which to store the pixel color read.
     * @return the color of the pixel read.
     */
public ColorRGBA getPixel(Vector3f vector, int mipLevel, ColorRGBA store) {
    if (mipMapRaster == null) {
        throw new IllegalArgumentException("This cube map has no mip maps");
    }
    if (store == null) {
        store = new ColorRGBA();
    }
    int face = EnvMapUtils.getCubemapFaceTexCoordFromVector(vector, sizes[mipLevel], uvs, EnvMapUtils.FixSeamsMethod.Stretch);
    mipMapRaster.setSlice(face);
    mipMapRaster.setMipLevel(mipLevel);
    return mipMapRaster.getPixel((int) uvs.x, (int) uvs.y, store);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA)

Example 74 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class EmitterMeshFaceShape method setMeshes.

@Override
public void setMeshes(List<Mesh> meshes) {
    this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
    this.normals = new ArrayList<List<Vector3f>>(meshes.size());
    for (Mesh mesh : meshes) {
        Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
        int[] indices = new int[3];
        List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
        List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
        for (int i = 0; i < mesh.getTriangleCount(); ++i) {
            mesh.getTriangle(i, indices);
            vertices.add(vertexTable[indices[0]]);
            vertices.add(vertexTable[indices[1]]);
            vertices.add(vertexTable[indices[2]]);
            normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
        }
        this.vertices.add(vertices);
        this.normals.add(normals);
    }
}
Also used : Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) Mesh(com.jme3.scene.Mesh) List(java.util.List) ArrayList(java.util.ArrayList)

Example 75 with Vector3f

use of com.jme3.math.Vector3f in project jmonkeyengine by jMonkeyEngine.

the class EmitterMeshVertexShape method deepClone.

@Override
public EmitterShape deepClone() {
    try {
        EmitterMeshVertexShape clone = (EmitterMeshVertexShape) super.clone();
        if (this.vertices != null) {
            clone.vertices = new ArrayList<List<Vector3f>>(vertices.size());
            for (List<Vector3f> list : vertices) {
                List<Vector3f> vectorList = new ArrayList<Vector3f>(list.size());
                for (Vector3f vector : list) {
                    vectorList.add(vector.clone());
                }
                clone.vertices.add(vectorList);
            }
        }
        if (this.normals != null) {
            clone.normals = new ArrayList<List<Vector3f>>(normals.size());
            for (List<Vector3f> list : normals) {
                List<Vector3f> vectorList = new ArrayList<Vector3f>(list.size());
                for (Vector3f vector : list) {
                    vectorList.add(vector.clone());
                }
                clone.normals.add(vectorList);
            }
        }
        return clone;
    } catch (CloneNotSupportedException e) {
        throw new AssertionError();
    }
}
Also used : Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Vector3f (com.jme3.math.Vector3f)536 Material (com.jme3.material.Material)126 Geometry (com.jme3.scene.Geometry)118 DirectionalLight (com.jme3.light.DirectionalLight)95 Quaternion (com.jme3.math.Quaternion)94 TempVars (com.jme3.util.TempVars)67 ColorRGBA (com.jme3.math.ColorRGBA)64 Node (com.jme3.scene.Node)63 Spatial (com.jme3.scene.Spatial)57 Box (com.jme3.scene.shape.Box)57 Sphere (com.jme3.scene.shape.Sphere)51 Texture (com.jme3.texture.Texture)41 KeyTrigger (com.jme3.input.controls.KeyTrigger)36 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)35 Vector2f (com.jme3.math.Vector2f)35 FilterPostProcessor (com.jme3.post.FilterPostProcessor)34 FloatBuffer (java.nio.FloatBuffer)34 InputCapsule (com.jme3.export.InputCapsule)33 BoundingBox (com.jme3.bounding.BoundingBox)30 AmbientLight (com.jme3.light.AmbientLight)30