use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class BasicShadowRenderer method postQueue.
public void postQueue(RenderQueue rq) {
for (Spatial scene : viewPort.getScenes()) {
ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
}
// update frustum points based on current camera
Camera viewCam = viewPort.getCamera();
ShadowUtil.updateFrustumPoints(viewCam, viewCam.getFrustumNear(), viewCam.getFrustumFar(), 1.0f, points);
Vector3f frustaCenter = new Vector3f();
for (Vector3f point : points) {
frustaCenter.addLocal(point);
}
frustaCenter.multLocal(1f / 8f);
// update light direction
shadowCam.setProjectionMatrix(null);
shadowCam.setParallelProjection(true);
// shadowCam.setFrustumPerspective(45, 1, 1, 20);
shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y);
shadowCam.update();
shadowCam.setLocation(frustaCenter);
shadowCam.update();
shadowCam.updateViewProjection();
// render shadow casters to shadow map
ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
if (shadowOccluders.size() == 0) {
noOccluders = true;
return;
} else {
noOccluders = false;
}
Renderer r = renderManager.getRenderer();
renderManager.setCamera(shadowCam, false);
renderManager.setForcedMaterial(preshadowMat);
r.setFrameBuffer(shadowFB);
r.clearBuffers(true, true, true);
viewPort.getQueue().renderShadowQueue(shadowOccluders, renderManager, shadowCam, true);
r.setFrameBuffer(viewPort.getOutputFrameBuffer());
renderManager.setForcedMaterial(null);
renderManager.setCamera(viewCam, false);
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class TestAwtPanels method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setDragToRotate(true);
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", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
geom.setMaterial(mat);
rootNode.attachChild(geom);
/*
* Wait until both AWT panels are ready.
*/
try {
panelsAreReady.await();
} catch (InterruptedException exception) {
throw new RuntimeException("Interrupted while waiting for panels", exception);
}
panel.attachTo(true, viewPort);
guiViewPort.setClearFlags(true, true, true);
panel2.attachTo(false, guiViewPort);
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method syncScreenProcessing.
/**
* Sets the two views to use the list of {@link SceneProcessor processors}.
* @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
*/
public void syncScreenProcessing(ViewPort sourceViewport) {
if (rightViewport == null) {
return;
}
if (environment != null) {
if (environment.getApplication() != null) {
// setup post processing filters
if (rightPostProcessor == null) {
rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
}
// clear out all filters & processors, to start from scratch
rightPostProcessor.removeAllFilters();
leftPostProcessor.removeAllFilters();
leftViewport.clearProcessors();
rightViewport.clearProcessors();
// if we have no processors to sync, don't add the FilterPostProcessor
if (sourceViewport.getProcessors().isEmpty())
return;
// add post processors we just made, which are empty
leftViewport.addProcessor(leftPostProcessor);
rightViewport.addProcessor(rightPostProcessor);
// add them to the left viewport processor & clone them to the right
for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
if (sceneProcessor instanceof FilterPostProcessor) {
for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
if (f instanceof TranslucentBucketFilter) {
// just remove this filter, we will add it at the end manually
((FilterPostProcessor) sceneProcessor).removeFilter(f);
} else {
leftPostProcessor.addFilter(f);
// clone to the right
Filter f2;
if (f instanceof FogFilter) {
f2 = FilterUtil.cloneFogFilter((FogFilter) f);
} else if (f instanceof CartoonSSAO) {
f2 = new CartoonSSAO((CartoonSSAO) f);
} else if (f instanceof SSAOFilter) {
f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
} else if (f instanceof DirectionalLightShadowFilter) {
f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
} else {
// dof, bloom, lightscattering etc.
f2 = f;
}
rightPostProcessor.addFilter(f2);
}
}
} else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
// shadow processing
// TODO: make right shadow processor use same left shadow maps for performance
VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
dlsrRight.setLight(dlsr.getLight());
rightViewport.getProcessors().add(0, dlsrRight);
leftViewport.getProcessors().add(0, sceneProcessor);
}
}
// make sure each has a translucent filter renderer
leftPostProcessor.addFilter(new TranslucentBucketFilter());
rightPostProcessor.addFilter(new TranslucentBucketFilter());
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method setupVRScene.
/**
* Replaces rootNode as the main cameras scene with the distortion mesh
*/
private void setupVRScene() {
if (environment != null) {
if (environment.getApplication() != null) {
// no special scene to setup if we are doing instancing
if (environment.isInstanceRendering()) {
// distortion has to be done with compositor here... we want only one pass on our end!
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
setupMirrorBuffers(environment.getCamera(), dualEyeTex, true);
}
return;
}
leftEyeTexture = (Texture2D) leftViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
rightEyeTexture = (Texture2D) rightViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
leftEyeDepth = (Texture2D) leftViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
rightEyeDepth = (Texture2D) rightViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
// main viewport is either going to be a distortion scene or nothing
// mirroring is handled by copying framebuffers
Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
environment.getApplication().getViewPort().detachScene(spatialIter.next());
}
spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
environment.getApplication().getGuiViewPort().detachScene(spatialIter.next());
}
// only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
if (environment.getVRHardware().getCompositor() == null) {
Node distortionScene = new Node();
Material leftMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
leftMat.setTexture("Texture", leftEyeTexture);
Geometry leftEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, environment.getVRHardware()));
leftEye.setMaterial(leftMat);
distortionScene.attachChild(leftEye);
Material rightMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
rightMat.setTexture("Texture", rightEyeTexture);
Geometry rightEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, environment.getVRHardware()));
rightEye.setMaterial(rightMat);
distortionScene.attachChild(rightEye);
distortionScene.updateGeometricState();
environment.getApplication().getViewPort().attachScene(distortionScene);
//if( useCustomDistortion ) setupFinalFullTexture(app.getViewPort().getCamera());
}
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method setupMirrorBuffers.
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {
if (environment != null) {
if (environment.getApplication() != null) {
Camera clonecam = cam.clone();
ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
clonecam.setParallelProjection(true);
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
Picture pic = new Picture("fullscene");
pic.setLocalTranslation(-0.75f, -0.5f, 0f);
if (expand) {
pic.setLocalScale(3f, 1f, 1f);
} else {
pic.setLocalScale(1.5f, 1f, 1f);
}
pic.setQueueBucket(Bucket.Opaque);
pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false);
viewPort.attachScene(pic);
viewPort.setOutputFrameBuffer(null);
pic.updateGeometricState();
return viewPort;
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
Aggregations