use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestTransparentCartoonEdge method simpleInitApp.
public void simpleInitApp() {
renderManager.setAlphaToCoverage(true);
cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f));
cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f));
// cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f));
// cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f, -0.13857932f));
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
Quad q = new Quad(20, 20);
q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5));
Geometry geom = new Geometry("floor", q);
Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
geom.setMaterial(mat);
geom.rotate(-FastMath.HALF_PI, 0, 0);
geom.center();
geom.setShadowMode(ShadowMode.Receive);
rootNode.attachChild(geom);
// create the geometry and attach it
Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
teaGeom.setQueueBucket(Bucket.Transparent);
teaGeom.setShadowMode(ShadowMode.Cast);
makeToonish(teaGeom);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(2));
rootNode.addLight(al);
DirectionalLight dl1 = new DirectionalLight();
dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal());
dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
rootNode.addLight(dl1);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
rootNode.addLight(dl);
rootNode.attachChild(teaGeom);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
CartoonEdgeFilter toon = new CartoonEdgeFilter();
toon.setEdgeWidth(0.5f);
toon.setEdgeIntensity(1.0f);
toon.setNormalThreshold(0.8f);
fpp.addFilter(toon);
viewPort.addProcessor(fpp);
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class HelloOpenCL method testImages.
private boolean testImages(Context clContext, CommandQueue clQueue) {
try {
//query supported formats
for (MemoryAccess ma : MemoryAccess.values()) {
for (Image.ImageType type : Image.ImageType.values()) {
try {
System.out.println("Formats for " + ma + " and " + type + ": " + Arrays.toString(clContext.querySupportedFormats(ma, type)));
} catch (UnsupportedOperationException e) {
LOG.warning(e.getLocalizedMessage());
}
}
}
//create an image
Image.ImageFormat format = new Image.ImageFormat(Image.ImageChannelOrder.RGBA, Image.ImageChannelType.FLOAT);
Image.ImageDescriptor descr = new Image.ImageDescriptor(Image.ImageType.IMAGE_2D, 1920, 1080, 0, 0);
Image image = clContext.createImage(MemoryAccess.READ_WRITE, format, descr);
System.out.println("image created");
//check queries
assertEquals(descr.type, image.getImageType(), "Wrong image type");
assertEquals(format, image.getImageFormat(), "Wrong image format");
assertEquals(descr.width, image.getWidth(), "Wrong width");
assertEquals(descr.height, image.getHeight(), "Wrong height");
//fill with red and blue
ColorRGBA color1 = ColorRGBA.Red;
ColorRGBA color2 = ColorRGBA.Blue;
Event e1 = image.fillAsync(clQueue, new long[] { 0, 0, 0 }, new long[] { descr.width / 2, descr.height, 1 }, color1);
Event e2 = image.fillAsync(clQueue, new long[] { descr.width / 2, 0, 0 }, new long[] { descr.width / 2, descr.height, 1 }, color2);
e1.waitForFinished();
e2.waitForFinished();
//copy to a buffer
Buffer buffer = clContext.createBuffer(4 * 4 * 500 * 1024);
Event e3 = image.copyToBufferAsync(clQueue, buffer, new long[] { 10, 10, 0 }, new long[] { 500, 1024, 1 }, 0);
e3.release();
//this buffer must be completely red
ByteBuffer map1 = buffer.map(clQueue, MappingAccess.MAP_READ_ONLY);
FloatBuffer map1F = map1.asFloatBuffer();
map1F.rewind();
for (int x = 0; x < 500; ++x) {
for (int y = 0; y < 1024; ++y) {
float r = map1F.get();
float g = map1F.get();
float b = map1F.get();
float a = map1F.get();
assertEquals(1, r, "Wrong red component");
assertEquals(0, g, "Wrong green component");
assertEquals(0, b, "Wrong blue component");
assertEquals(1, a, "Wrong alpha component");
}
}
buffer.unmap(clQueue, map1);
//create a second image
format = new Image.ImageFormat(Image.ImageChannelOrder.RGBA, Image.ImageChannelType.FLOAT);
descr = new Image.ImageDescriptor(Image.ImageType.IMAGE_2D, 512, 512, 0, 0);
Image image2 = clContext.createImage(MemoryAccess.READ_WRITE, format, descr);
//copy an area of image1 to image2
image.copyTo(clQueue, image2, new long[] { 1000, 20, 0 }, new long[] { 0, 0, 0 }, new long[] { 512, 512, 1 });
//this area should be completely blue
Image.ImageMapping map2 = image2.map(clQueue, new long[] { 0, 0, 0 }, new long[] { 512, 512, 1 }, MappingAccess.MAP_READ_WRITE);
FloatBuffer map2F = map2.buffer.asFloatBuffer();
for (int y = 0; y < 512; ++y) {
for (int x = 0; x < 512; ++x) {
long index = 4 * x + y * (map2.rowPitch / 4);
map2F.position((int) index);
float r = map2F.get();
float g = map2F.get();
float b = map2F.get();
float a = map2F.get();
assertEquals(0, r, "Wrong red component");
assertEquals(0, g, "Wrong green component");
assertEquals(1, b, "Wrong blue component");
assertEquals(1, a, "Wrong alpha component");
}
}
image2.unmap(clQueue, map2);
//release
image.release();
image2.release();
buffer.release();
} catch (AssertionError ex) {
LOG.log(Level.SEVERE, "image test failed with an assertion error");
return false;
} catch (Exception ex) {
LOG.log(Level.SEVERE, "image test failed with:", ex);
return false;
}
return true;
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestSimpleBumps method simpleInitApp.
@Override
public void simpleInitApp() {
Quad quadMesh = new Quad(1, 1);
Geometry sphere = new Geometry("Rock Ball", quadMesh);
Material mat = assetManager.loadMaterial("Textures/BumpMapTest/SimpleBump.j3m");
sphere.setMaterial(mat);
TangentBinormalGenerator.generate(sphere);
rootNode.attachChild(sphere);
lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
rootNode.attachChild(lightMdl);
pl = new PointLight();
pl.setColor(ColorRGBA.White);
pl.setPosition(new Vector3f(0f, 0f, 4f));
rootNode.addLight(pl);
// DirectionalLight dl = new DirectionalLight();
// dl.setDirection(new Vector3f(1, -1, -1).normalizeLocal());
// dl.setColor(new ColorRGBA(0.22f, 0.15f, 0.1f, 1.0f));
// rootNode.addLight(dl);
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class TestHoverTank method simpleInitApp.
@Override
public void simpleInitApp() {
Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
flyCam.setEnabled(false);
ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
chaseCam.setSmoothMotion(true);
chaseCam.setMaxDistance(100000);
chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
Geometry tankGeom = (Geometry) tank.getChild(0);
LodControl control = new LodControl();
tankGeom.addControl(control);
rootNode.attachChild(tank);
Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
DirectionalLight dl = new DirectionalLight();
dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
dl.setDirection(lightDir);
Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
DirectionalLight dl2 = new DirectionalLight();
dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
dl2.setDirection(lightDir2);
rootNode.addLight(dl);
rootNode.addLight(dl2);
rootNode.attachChild(tank);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
bf.setBloomIntensity(2.0f);
bf.setExposurePower(1.3f);
fpp.addFilter(bf);
BloomUI bui = new BloomUI(inputManager, bf);
viewPort.addProcessor(fpp);
}
use of com.jme3.math.ColorRGBA in project jmonkeyengine by jMonkeyEngine.
the class DirectionalLightShadowRendererVR method init.
private void init(int nbSplits, int shadowMapSize) {
nbShadowMaps = Math.max(Math.min(nbSplits, 4), 1);
if (nbShadowMaps != nbSplits) {
throw new IllegalArgumentException("Number of splits must be between 1 and 4. Given value : " + nbSplits);
}
splits = new ColorRGBA();
splitsArray = new float[nbSplits + 1];
shadowCam = new Camera(shadowMapSize, shadowMapSize);
shadowCam.setParallelProjection(true);
for (int i = 0; i < points.length; i++) {
points[i] = new Vector3f();
}
}
Aggregations