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);
}
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;
}
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);
}
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);
}
}
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();
}
}
Aggregations