use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class SkyFactory method checkImagesForCubeMap.
private static void checkImagesForCubeMap(Image... images) {
if (images.length == 1) {
return;
}
Format fmt = images[0].getFormat();
int width = images[0].getWidth();
int height = images[0].getHeight();
ByteBuffer data = images[0].getData(0);
int size = data != null ? data.capacity() : 0;
checkImage(images[0]);
for (int i = 1; i < images.length; i++) {
Image image = images[i];
checkImage(images[i]);
if (image.getFormat() != fmt) {
throw new IllegalArgumentException("Images must have same format");
}
if (image.getWidth() != width || image.getHeight() != height) {
throw new IllegalArgumentException("Images must have same resolution");
}
ByteBuffer data2 = image.getData(0);
if (data2 != null) {
if (data2.capacity() != size) {
throw new IllegalArgumentException("Images must have same size");
}
}
}
}
use of com.jme3.scene.VertexBuffer.Format in project jmonkeyengine by jMonkeyEngine.
the class ShaderNodeLoaderDelegate method parseMapping.
/**
* reads a mapping statement. Sets the nameSpace, name and swizzling of the
* left variable. Sets the name, nameSpace and swizzling of the right
* variable types will be determined later.
*
* <code>
* Format : <nameSpace>.<varName>[.<swizzling>] =
* <nameSpace>.<varName>[.<swizzling>][:Condition]
* </code>
*
* @param statement the statement to read
* @return the read mapping
*/
protected VariableMapping parseMapping(Statement statement, boolean[] hasNameSpace) throws IOException {
VariableMapping mapping = new VariableMapping();
String[] cond = statement.getLine().split(":");
String[] vars = cond[0].split("=");
checkMappingFormat(vars, statement);
ShaderNodeVariable[] variables = new ShaderNodeVariable[2];
String[] swizzle = new String[2];
for (int i = 0; i < vars.length; i++) {
String[] expression = vars[i].trim().split("\\.");
if (hasNameSpace[i]) {
if (expression.length <= 3) {
variables[i] = new ShaderNodeVariable("", expression[0].trim(), expression[1].trim());
}
if (expression.length == 3) {
swizzle[i] = expression[2].trim();
}
} else {
if (expression.length <= 2) {
variables[i] = new ShaderNodeVariable("", expression[0].trim());
}
if (expression.length == 2) {
swizzle[i] = expression[1].trim();
}
}
}
mapping.setLeftVariable(variables[0]);
mapping.setLeftSwizzling(swizzle[0] != null ? swizzle[0] : "");
mapping.setRightVariable(variables[1]);
mapping.setRightSwizzling(swizzle[1] != null ? swizzle[1] : "");
if (cond.length > 1) {
extractCondition(cond[1], statement);
mapping.setCondition(conditionParser.getFormattedExpression());
}
return mapping;
}
use of com.jme3.scene.VertexBuffer.Format 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;
}
use of com.jme3.scene.VertexBuffer.Format 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;
}
use of com.jme3.scene.VertexBuffer.Format 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;
}
Aggregations