Search in sources :

Example 76 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class EnvironmentCamera method initialize.

@Override
protected void initialize(Application app) {
    this.backGroundColor = app.getViewPort().getBackgroundColor();
    final Camera[] cameras = new Camera[6];
    Texture2D[] textures = new Texture2D[6];
    viewports = new ViewPort[6];
    framebuffers = new FrameBuffer[6];
    buffers = new ByteBuffer[6];
    images = new Image[6];
    for (int i = 0; i < 6; i++) {
        cameras[i] = createOffCamera(size, position, axisX[i], axisY[i], axisZ[i]);
        viewports[i] = createOffViewPort("EnvView" + i, cameras[i]);
        framebuffers[i] = createOffScreenFrameBuffer(size, viewports[i]);
        textures[i] = new Texture2D(size, size, imageFormat);
        framebuffers[i].setColorTexture(textures[i]);
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Camera(com.jme3.renderer.Camera)

Example 77 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class EnvironmentCamera method createOffViewPort.

/**
     * creates an offsceen VP
     *
     * @param name
     * @param offCamera
     * @return
     */
protected ViewPort createOffViewPort(final String name, final Camera offCamera) {
    final ViewPort offView = new ViewPort(name, offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(backGroundColor);
    return offView;
}
Also used : ViewPort(com.jme3.renderer.ViewPort)

Example 78 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method renderFromControl.

/**
     * Callback from Control.render(), do not use.
     *
     * @param rm
     * @param vp
     */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();
    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;
        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }
    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();
        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Camera(com.jme3.renderer.Camera) TempVars(com.jme3.util.TempVars)

Example 79 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class ParticlePointMesh method updateParticleData.

@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
    VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
    FloatBuffer positions = (FloatBuffer) pvb.getData();
    VertexBuffer cvb = getBuffer(VertexBuffer.Type.Color);
    ByteBuffer colors = (ByteBuffer) cvb.getData();
    VertexBuffer svb = getBuffer(VertexBuffer.Type.Size);
    FloatBuffer sizes = (FloatBuffer) svb.getData();
    VertexBuffer tvb = getBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer texcoords = (FloatBuffer) tvb.getData();
    float sizeScale = emitter.getWorldScale().x;
    // update data in vertex buffers
    positions.rewind();
    colors.rewind();
    sizes.rewind();
    texcoords.rewind();
    for (int i = 0; i < particles.length; i++) {
        Particle p = particles[i];
        positions.put(p.position.x).put(p.position.y).put(p.position.z);
        sizes.put(p.size * sizeScale);
        colors.putInt(p.color.asIntABGR());
        int imgX = p.imageIndex % imagesX;
        int imgY = (p.imageIndex - imgX) / imagesY;
        float startX = ((float) imgX) / imagesX;
        float startY = ((float) imgY) / imagesY;
        float endX = startX + (1f / imagesX);
        float endY = startY + (1f / imagesY);
        texcoords.put(startX).put(startY).put(endX).put(endY);
    }
    positions.flip();
    colors.flip();
    sizes.flip();
    texcoords.flip();
    // force renderer to re-send data to GPU
    pvb.updateData(positions);
    cvb.updateData(colors);
    svb.updateData(sizes);
    tvb.updateData(texcoords);
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 80 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class LightProbeBlendingProcessor method computeBlendFactors.

private float computeBlendFactors(List<BlendFactor> blendFactors) {
    float sumBlendFactors = 0;
    for (Spatial scene : viewPort.getScenes()) {
        for (Light light : scene.getWorldLightList()) {
            if (light.getType() == Light.Type.Probe) {
                LightProbe p = (LightProbe) light;
                TempVars vars = TempVars.get();
                boolean intersect = p.intersectsFrustum(viewPort.getCamera(), vars);
                vars.release();
                //check if the probe is inside the camera frustum
                if (intersect) {
                    //is the poi inside the bounds of this probe
                    if (poi.getWorldBound().intersects(p.getBounds())) {
                        //computing the distance as we need it to check if th epoi in in the inner radius and later to compute the weight
                        float outerRadius = ((BoundingSphere) p.getBounds()).getRadius();
                        float innerRadius = outerRadius * 0.5f;
                        float distance = p.getBounds().getCenter().distance(poi.getWorldTranslation());
                        // if the poi in inside the inner range of this probe, then this probe is the only one that matters.
                        if (distance < innerRadius) {
                            blendFactors.clear();
                            blendFactors.add(new BlendFactor(p, 1.0f));
                            return 1.0f;
                        }
                        //else we need to compute the weight of this probe and collect it for blending
                        float ndf = (distance - innerRadius) / (outerRadius - innerRadius);
                        sumBlendFactors += ndf;
                        blendFactors.add(new BlendFactor(p, ndf));
                    }
                }
            }
        }
    }
    return sumBlendFactors;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Spatial(com.jme3.scene.Spatial) TempVars(com.jme3.util.TempVars)

Aggregations

Camera (com.jme3.renderer.Camera)63 Vector3f (com.jme3.math.Vector3f)51 Material (com.jme3.material.Material)26 Geometry (com.jme3.scene.Geometry)26 Quaternion (com.jme3.math.Quaternion)23 Spatial (com.jme3.scene.Spatial)19 TempVars (com.jme3.util.TempVars)16 Box (com.jme3.scene.shape.Box)13 ViewPort (com.jme3.renderer.ViewPort)11 Node (com.jme3.scene.Node)11 DirectionalLight (com.jme3.light.DirectionalLight)10 FrameBuffer (com.jme3.texture.FrameBuffer)10 Texture (com.jme3.texture.Texture)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Texture2D (com.jme3.texture.Texture2D)9 ArrayList (java.util.ArrayList)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)8 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)8 CameraNode (com.jme3.scene.CameraNode)7