use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method normalizeVector2.
/**
* Normalize a Vector2f in-buffer.
*
* @param buf
* the buffer to find the Vector2f within
* @param index
* the position (in terms of vectors, not floats) of the vector
* to normalize
*/
public static void normalizeVector2(FloatBuffer buf, int index) {
TempVars vars = TempVars.get();
Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
tempVec2.normalizeLocal();
setInBuffer(tempVec2, buf, index);
vars.release();
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class WaterFilter method write.
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(speed, "speed", 1f);
oc.write(lightDirection, "lightDirection", new Vector3f(0, -1, 0));
oc.write(lightColor, "lightColor", ColorRGBA.White);
oc.write(waterHeight, "waterHeight", 0.0f);
oc.write(waterColor, "waterColor", new ColorRGBA(0.0078f, 0.3176f, 0.5f, 1.0f));
oc.write(deepWaterColor, "deepWaterColor", new ColorRGBA(0.0039f, 0.00196f, 0.145f, 1.0f));
oc.write(colorExtinction, "colorExtinction", new Vector3f(5.0f, 20.0f, 30.0f));
oc.write(waterTransparency, "waterTransparency", 0.1f);
oc.write(maxAmplitude, "maxAmplitude", 1.5f);
oc.write(shoreHardness, "shoreHardness", 0.1f);
oc.write(useFoam, "useFoam", true);
oc.write(foamIntensity, "foamIntensity", 0.5f);
oc.write(foamHardness, "foamHardness", 1.0f);
oc.write(foamExistence, "foamExistence", new Vector3f(0.45f, 4.35f, 1.5f));
oc.write(waveScale, "waveScale", 0.005f);
oc.write(sunScale, "sunScale", 3.0f);
oc.write(shininess, "shininess", 0.7f);
oc.write(windDirection, "windDirection", new Vector2f(0.0f, -1.0f));
oc.write(reflectionMapSize, "reflectionMapSize", 512);
oc.write(useRipples, "useRipples", true);
oc.write(normalScale, "normalScale", 3.0f);
oc.write(useHQShoreline, "useHQShoreline", true);
oc.write(useSpecular, "useSpecular", true);
oc.write(useRefraction, "useRefraction", true);
oc.write(refractionStrength, "refractionStrength", 0.0f);
oc.write(refractionConstant, "refractionConstant", 0.5f);
oc.write(reflectionDisplace, "reflectionDisplace", 30f);
oc.write(underWaterFogDistance, "underWaterFogDistance", 120f);
oc.write(causticsIntensity, "causticsIntensity", 0.5f);
oc.write(useCaustics, "useCaustics", true);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class WaterFilter method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
speed = ic.readFloat("speed", 1f);
lightDirection = (Vector3f) ic.readSavable("lightDirection", new Vector3f(0, -1, 0));
lightColor = (ColorRGBA) ic.readSavable("lightColor", ColorRGBA.White);
waterHeight = ic.readFloat("waterHeight", 0.0f);
waterColor = (ColorRGBA) ic.readSavable("waterColor", new ColorRGBA(0.0078f, 0.3176f, 0.5f, 1.0f));
deepWaterColor = (ColorRGBA) ic.readSavable("deepWaterColor", new ColorRGBA(0.0039f, 0.00196f, 0.145f, 1.0f));
colorExtinction = (Vector3f) ic.readSavable("colorExtinction", new Vector3f(5.0f, 20.0f, 30.0f));
waterTransparency = ic.readFloat("waterTransparency", 0.1f);
maxAmplitude = ic.readFloat("maxAmplitude", 1.5f);
shoreHardness = ic.readFloat("shoreHardness", 0.1f);
useFoam = ic.readBoolean("useFoam", true);
foamIntensity = ic.readFloat("foamIntensity", 0.5f);
foamHardness = ic.readFloat("foamHardness", 1.0f);
foamExistence = (Vector3f) ic.readSavable("foamExistence", new Vector3f(0.45f, 4.35f, 1.5f));
waveScale = ic.readFloat("waveScale", 0.005f);
sunScale = ic.readFloat("sunScale", 3.0f);
shininess = ic.readFloat("shininess", 0.7f);
windDirection = (Vector2f) ic.readSavable("windDirection", new Vector2f(0.0f, -1.0f));
reflectionMapSize = ic.readInt("reflectionMapSize", 512);
useRipples = ic.readBoolean("useRipples", true);
normalScale = ic.readFloat("normalScale", 3.0f);
useHQShoreline = ic.readBoolean("useHQShoreline", true);
useSpecular = ic.readBoolean("useSpecular", true);
useRefraction = ic.readBoolean("useRefraction", true);
refractionStrength = ic.readFloat("refractionStrength", 0.0f);
refractionConstant = ic.readFloat("refractionConstant", 0.5f);
reflectionDisplace = ic.readFloat("reflectionDisplace", 30f);
underWaterFogDistance = ic.readFloat("underWaterFogDistance", 120f);
causticsIntensity = ic.readFloat("causticsIntensity", 0.5f);
useCaustics = ic.readBoolean("useCaustics", true);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class SSAOFilter method initFilter.
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
this.renderManager = renderManager;
this.viewPort = vp;
int screenWidth = w;
int screenHeight = h;
postRenderPasses = new ArrayList<Pass>();
normalPass = new Pass();
normalPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth);
frustumNearFar = new Vector2f();
float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
float farX = farY * ((float) screenWidth / (float) screenHeight);
frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
frustumNearFar.x = vp.getCamera().getFrustumNear();
frustumNearFar.y = vp.getCamera().getFrustumFar();
//ssao Pass
ssaoMat = new Material(manager, "Common/MatDefs/SSAO/ssao.j3md");
ssaoMat.setTexture("Normals", normalPass.getRenderedTexture());
Texture random = manager.loadTexture("Common/MatDefs/SSAO/Textures/random.png");
random.setWrap(Texture.WrapMode.Repeat);
ssaoMat.setTexture("RandomMap", random);
ssaoPass = new Pass("SSAO pass") {
@Override
public boolean requiresDepthAsTexture() {
return true;
}
};
ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat);
// ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
// ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
postRenderPasses.add(ssaoPass);
material = new Material(manager, "Common/MatDefs/SSAO/ssaoBlur.j3md");
material.setTexture("SSAOMap", ssaoPass.getRenderedTexture());
ssaoMat.setVector3("FrustumCorner", frustumCorner);
ssaoMat.setFloat("SampleRadius", sampleRadius);
ssaoMat.setFloat("Intensity", intensity);
ssaoMat.setFloat("Scale", scale);
ssaoMat.setFloat("Bias", bias);
material.setBoolean("UseAo", useAo);
material.setBoolean("UseOnlyAo", useOnlyAo);
ssaoMat.setVector2("FrustumNearFar", frustumNearFar);
material.setVector2("FrustumNearFar", frustumNearFar);
ssaoMat.setParam("Samples", VarType.Vector2Array, samples);
ssaoMat.setBoolean("ApproximateNormals", approximateNormals);
float xScale = 1.0f / w;
float yScale = 1.0f / h;
float blurScale = 2f;
material.setFloat("XScale", blurScale * xScale);
material.setFloat("YScale", blurScale * yScale);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class RayTrace method update.
public void update() {
int w = image.getWidth();
int h = image.getHeight();
float wr = (float) cam.getWidth() / image.getWidth();
float hr = (float) cam.getHeight() / image.getHeight();
scene.updateGeometricState();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
Vector2f v = new Vector2f(x * wr, y * hr);
Vector3f pos = cam.getWorldCoordinates(v, 0.0f);
Vector3f dir = cam.getWorldCoordinates(v, 0.3f);
dir.subtractLocal(pos).normalizeLocal();
Ray r = new Ray(pos, dir);
results.clear();
scene.collideWith(r, results);
if (results.size() > 0) {
image.setRGB(x, h - y - 1, 0xFFFFFFFF);
} else {
image.setRGB(x, h - y - 1, 0xFF000000);
}
}
}
label.repaint();
}
Aggregations