Search in sources :

Example 61 with ColorRGBA

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

the class TestPostWater method createBox.

private void createBox() {
    //creating a transluscent box
    box = new Geometry("box", new Box(50, 50, 50));
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(1.0f, 0, 0, 0.3f));
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    //mat.getAdditionalRenderState().setDepthWrite(false);
    //mat.getAdditionalRenderState().setDepthTest(false);
    box.setMaterial(mat);
    box.setQueueBucket(Bucket.Translucent);
    //creating a post view port
    //        ViewPort post=renderManager.createPostView("transpPost", cam);
    //        post.setClearFlags(false, true, true);
    box.setLocalTranslation(-600, 0, 300);
    //attaching the box to the post viewport
    //Don't forget to updateGeometricState() the box in the simpleUpdate
    //  post.attachScene(box);
    rootNode.attachChild(box);
}
Also used : Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 62 with ColorRGBA

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

the class TerrainGridSerializationTest method simpleInitApp.

@Override
public void simpleInitApp() {
    File file = new File("TerrainGridTestData.zip");
    if (!file.exists()) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/TerrainGridTestData.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("TerrainGridTestData.zip", ZipLocator.class);
    }
    this.flyCam.setMoveSpeed(100f);
    ScreenshotAppState state = new ScreenshotAppState();
    this.stateManager.attach(state);
    this.terrain = (TerrainGrid) assetManager.loadModel("TerrainGrid/TerrainGrid.j3o");
    this.rootNode.attachChild(this.terrain);
    TerrainLodControl control = new TerrainGridLodControl(this.terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
    this.terrain.addControl(control);
    final BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    this.getCamera().setLocation(new Vector3f(0, 256, 0));
    this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
    if (usePhysics) {
        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1);
        player3 = new CharacterControl(capsuleShape, 0.5f);
        player3.setJumpSpeed(20);
        player3.setFallSpeed(10);
        player3.setGravity(10);
        player3.setPhysicsLocation(new Vector3f(cam.getLocation().x, 256, cam.getLocation().z));
        bulletAppState.getPhysicsSpace().add(player3);
        terrain.addListener(new TerrainGridListener() {

            public void gridMoved(Vector3f newCenter) {
            }

            public void tileAttached(Vector3f cell, TerrainQuad quad) {
                //workaround for bugged test j3o's
                while (quad.getControl(RigidBodyControl.class) != null) {
                    quad.removeControl(RigidBodyControl.class);
                }
                quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0));
                bulletAppState.getPhysicsSpace().add(quad);
            }

            public void tileDetached(Vector3f cell, TerrainQuad quad) {
                if (quad.getControl(RigidBodyControl.class) != null) {
                    bulletAppState.getPhysicsSpace().remove(quad);
                    quad.removeControl(RigidBodyControl.class);
                }
            }
        });
    }
    this.initKeys();
}
Also used : CharacterControl(com.jme3.bullet.control.CharacterControl) TerrainGridListener(com.jme3.terrain.geomipmap.TerrainGridListener) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) TerrainGridLodControl(com.jme3.terrain.geomipmap.TerrainGridLodControl) ColorRGBA(com.jme3.math.ColorRGBA) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) HeightfieldCollisionShape(com.jme3.bullet.collision.shapes.HeightfieldCollisionShape) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) ScreenshotAppState(com.jme3.app.state.ScreenshotAppState) File(java.io.File) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad)

Example 63 with ColorRGBA

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

the class TerrainTestModifyHeight method simpleInitApp.

@Override
public void simpleInitApp() {
    loadHintText();
    initCrossHairs();
    setupKeys();
    createMarker();
    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    createTerrain();
    //createTerrainGrid();
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);
    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);
    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1f, 0).normalizeLocal(), Vector3f.UNIT_X);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) AmbientLight(com.jme3.light.AmbientLight)

Example 64 with ColorRGBA

use of com.jme3.math.ColorRGBA 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;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) TextureCubeMap(com.jme3.texture.TextureCubeMap) Vector3f(com.jme3.math.Vector3f) ByteBuffer(java.nio.ByteBuffer)

Example 65 with ColorRGBA

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

the class EnvMapUtils method prefilterEnvMapTexel.

private static Vector3f prefilterEnvMapTexel(CubeMapWrapper envMapReader, float roughness, Vector3f N, int numSamples, Vector3f store) {
    Vector3f prefilteredColor = store;
    float totalWeight = 0.0f;
    TempVars vars = TempVars.get();
    Vector4f Xi = vars.vect4f1;
    Vector3f H = vars.vect1;
    Vector3f tmp = vars.vect2;
    ColorRGBA c = vars.color;
    // 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, vars);
        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;
        }
    }
    vars.release();
    return prefilteredColor.divideLocal(totalWeight);
}
Also used : Vector4f(com.jme3.math.Vector4f) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Aggregations

ColorRGBA (com.jme3.math.ColorRGBA)98 Vector3f (com.jme3.math.Vector3f)65 Material (com.jme3.material.Material)44 DirectionalLight (com.jme3.light.DirectionalLight)42 Geometry (com.jme3.scene.Geometry)23 ParticleEmitter (com.jme3.effect.ParticleEmitter)14 PointLight (com.jme3.light.PointLight)14 Quaternion (com.jme3.math.Quaternion)14 Spatial (com.jme3.scene.Spatial)14 AmbientLight (com.jme3.light.AmbientLight)13 Sphere (com.jme3.scene.shape.Sphere)12 Node (com.jme3.scene.Node)11 KeyTrigger (com.jme3.input.controls.KeyTrigger)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)10 Texture (com.jme3.texture.Texture)9 BulletAppState (com.jme3.bullet.BulletAppState)8 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)7 Quad (com.jme3.scene.shape.Quad)7 TextureCubeMap (com.jme3.texture.TextureCubeMap)7 EmitterSphereShape (com.jme3.effect.shapes.EmitterSphereShape)6