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]);
}
}
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;
}
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();
}
}
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);
}
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;
}
Aggregations