use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class TestRenderToCubemap method setupOffscreenView.
public Texture setupOffscreenView() {
Camera offCamera = new Camera(512, 512);
offView = renderManager.createPreView("Offscreen View", offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.DarkGray);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
//setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer's texture
TextureCubeMap offTex = new TextureCubeMap(512, 512, Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.Trilinear);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setMultiTarget(true);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
Box boxMesh = new Box(1, 1, 1);
Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
offBox = new Geometry("box", boxMesh);
offBox.setMaterial(material);
// attach the scene to the viewport to be rendered
offView.attachScene(offBox);
return offTex;
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class TestRenderToMemory method setupOffscreenView.
public void setupOffscreenView() {
offCamera = new Camera(width, height);
// create a pre-view. a view that is rendered before the main view
offView = renderManager.createPreView("Offscreen View", offCamera);
offView.setBackgroundColor(ColorRGBA.DarkGray);
offView.setClearFlags(true, true, true);
// this will let us know when the scene has been rendered to the
// frame buffer
offView.addProcessor(this);
// create offscreen framebuffer
offBuffer = new FrameBuffer(width, height, 1);
//setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer's texture
// offTex = new Texture2D(width, height, Format.RGBA8);
//setup framebuffer to use renderbuffer
// this is faster for gpu -> cpu copies
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorBuffer(Format.RGBA8);
// offBuffer.setColorTexture(offTex);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
Box boxMesh = new Box(1, 1, 1);
Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
offBox = new Geometry("box", boxMesh);
offBox.setMaterial(material);
// attach the scene to the viewport to be rendered
offView.attachScene(offBox);
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class TestRenderToTexture method setupOffscreenView.
public Texture setupOffscreenView() {
Camera offCamera = new Camera(512, 512);
offView = renderManager.createPreView("Offscreen View", offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.DarkGray);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
//setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer's texture
Texture2D offTex = new Texture2D(512, 512, Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.Trilinear);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorTexture(offTex);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
Box boxMesh = new Box(1, 1, 1);
Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
offBox = new Geometry("box", boxMesh);
offBox.setMaterial(material);
// attach the scene to the viewport to be rendered
offView.attachScene(offBox);
return offTex;
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class TestMultiRenderTarget method reshape.
public void reshape(ViewPort vp, int w, int h) {
diffuseData = new Texture2D(w, h, Format.RGBA8);
normalData = new Texture2D(w, h, Format.RGBA8);
specularData = new Texture2D(w, h, Format.RGBA8);
depthData = new Texture2D(w, h, Format.Depth);
mat = new Material(assetManager, "Common/MatDefs/Light/Deferred.j3md");
mat.setTexture("DiffuseData", diffuseData);
mat.setTexture("SpecularData", specularData);
mat.setTexture("NormalData", normalData);
mat.setTexture("DepthData", depthData);
display.setMaterial(mat);
display.setPosition(0, 0);
display.setWidth(w);
display.setHeight(h);
display1.setTexture(assetManager, diffuseData, false);
display2.setTexture(assetManager, normalData, false);
display3.setTexture(assetManager, specularData, false);
display4.setTexture(assetManager, depthData, false);
display1.setPosition(0, 0);
display2.setPosition(w / 2, 0);
display3.setPosition(0, h / 2);
display4.setPosition(w / 2, h / 2);
display1.setWidth(w / 2);
display1.setHeight(h / 2);
display2.setWidth(w / 2);
display2.setHeight(h / 2);
display3.setWidth(w / 2);
display3.setHeight(h / 2);
display4.setWidth(w / 2);
display4.setHeight(h / 2);
guiNode.updateGeometricState();
fb = new FrameBuffer(w, h, 1);
fb.setDepthTexture(depthData);
fb.addColorTexture(diffuseData);
fb.addColorTexture(normalData);
fb.addColorTexture(specularData);
fb.setMultiTarget(true);
/*
* Marks pixels in front of the far light boundary
Render back-faces of light volume
Depth test GREATER-EQUAL
Write to stencil on depth pass
Skipped for very small distant lights
*/
/*
* Find amount of lit pixels inside the volume
Start pixel query
Render front faces of light volume
Depth test LESS-EQUAL
Don’t write anything – only EQUAL stencil test
*/
/*
* Enable conditional rendering
Based on query results from previous stage
GPU skips rendering for invisible lights
*/
/*
* Render front-faces of light volume
Depth test - LESS-EQUAL
Stencil test - EQUAL
Runs only on marked pixels inside light
*/
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class TestNiftyToMesh method simpleInitApp.
public void simpleInitApp() {
ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
niftyView.setClearFlags(true, true, true);
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, niftyView);
nifty = niftyDisplay.getNifty();
nifty.fromXml("all/intro.xml", "start");
niftyView.addProcessor(niftyDisplay);
Texture2D depthTex = new Texture2D(1024, 768, Format.Depth);
FrameBuffer fb = new FrameBuffer(1024, 768, 1);
fb.setDepthTexture(depthTex);
Texture2D tex = new Texture2D(1024, 768, Format.RGBA8);
tex.setMinFilter(MinFilter.Trilinear);
tex.setMagFilter(MagFilter.Bilinear);
fb.setColorTexture(tex);
niftyView.setClearFlags(true, true, true);
niftyView.setOutputFrameBuffer(fb);
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", tex);
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
Aggregations