Java Code Examples for com.jme3.renderer.queue.RenderQueue#ShadowMode
The following examples show how to use
com.jme3.renderer.queue.RenderQueue#ShadowMode .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Helper function to distinguish between Occluders and Receivers * * @param shadowMode the ShadowMode tested * @param desired the desired ShadowMode * @return true if tested ShadowMode matches the desired one */ static private boolean checkShadowMode(RenderQueue.ShadowMode shadowMode, RenderQueue.ShadowMode desired) { if (shadowMode != RenderQueue.ShadowMode.Off) { switch (desired) { case Cast : return shadowMode==RenderQueue.ShadowMode.Cast || shadowMode==RenderQueue.ShadowMode.CastAndReceive; case Receive: return shadowMode==RenderQueue.ShadowMode.Receive || shadowMode==RenderQueue.ShadowMode.CastAndReceive; case CastAndReceive: return true; } } return false; }
Example 2
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Helper function used to recursively populate the outputGeometryList * with geometry children of scene node * * @param camera * @param scene * @param outputGeometryList */ private static void addGeometriesInCamFrustumFromNode(Camera camera, Node scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) { if (scene.getCullHint() == Spatial.CullHint.Always) return; camera.setPlaneState(0); if (camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside) { for (Spatial child: scene.getChildren()) { if (child instanceof Node) addGeometriesInCamFrustumFromNode(camera, (Node)child, mode, outputGeometryList); else if (child instanceof Geometry && child.getCullHint() != Spatial.CullHint.Always) { camera.setPlaneState(0); if (checkShadowMode(child.getShadowMode(), mode) && !((Geometry)child).isGrouped() && camera.contains(child.getWorldBound()) != Camera.FrustumIntersect.Outside) { outputGeometryList.add((Geometry)child); } } } } }
Example 3
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * If a spatial is not inside the eye frustum, it * is still rendered in the shadow frustum (shadow casting queue) * through this recursive method. */ private void renderShadow(Spatial s, RenderQueue rq) { if (s instanceof Node) { Node n = (Node) s; List<Spatial> children = n.getChildren(); for (int i = 0; i < children.size(); i++) { renderShadow(children.get(i), rq); } } else if (s instanceof Geometry) { Geometry gm = (Geometry) s; RenderQueue.ShadowMode shadowMode = s.getShadowMode(); if (shadowMode != RenderQueue.ShadowMode.Off && shadowMode != RenderQueue.ShadowMode.Receive) { //forcing adding to shadow cast mode, culled objects doesn't have to be in the receiver queue rq.addToShadowQueue(gm, RenderQueue.ShadowMode.Cast); } } }
Example 4
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * @return The shadow mode of this spatial, if the local shadow * mode is set to inherit, then the parent's shadow mode is returned. * * @see Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) * @see ShadowMode */ public RenderQueue.ShadowMode getShadowMode() { if (shadowMode != RenderQueue.ShadowMode.Inherit) { return shadowMode; } else if (parent != null) { return parent.getShadowMode(); } else { return ShadowMode.Off; } }
Example 5
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @return The shadow mode of this spatial, if the local shadow * mode is set to inherit, then the parent's shadow mode is returned. * * @see Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) * @see ShadowMode */ public RenderQueue.ShadowMode getShadowMode() { if (shadowMode != RenderQueue.ShadowMode.Inherit) { return shadowMode; } else if (parent != null) { return parent.getShadowMode(); } else { return ShadowMode.Off; } }
Example 6
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Helper function to recursively collect the geometries for getLitGeometriesInViewPort function. * * @param vpCamera the viewPort camera * @param cameras the camera array to check geometries against, representing the light viewspace * @param scene the Node to traverse or geometry to possibly add * @param outputGeometryList the output list of all geometries that are in the camera frustum */ private static void addGeometriesInCamFrustumAndViewPortFromNode(Camera vpCamera, Camera[] cameras, Spatial scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) { if (scene.getCullHint() == Spatial.CullHint.Always) return; boolean inFrustum = false; for (int j = 0; j < cameras.length && inFrustum == false; j++) { Camera camera = cameras[j]; int planeState = camera.getPlaneState(); camera.setPlaneState(0); inFrustum = camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside && scene.checkCulling(vpCamera); camera.setPlaneState(planeState); } if (inFrustum) { if (scene instanceof Node) { Node node = (Node)scene; for (Spatial child: node.getChildren()) { addGeometriesInCamFrustumAndViewPortFromNode(vpCamera, cameras, child, mode, outputGeometryList); } } else if (scene instanceof Geometry) { if (checkShadowMode(scene.getShadowMode(), mode) && !((Geometry)scene).isGrouped() ) { outputGeometryList.add((Geometry)scene); } } } }
Example 7
Source File: Spatial.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @return The shadow mode of this spatial, if the local shadow * mode is set to inherit, then the parent's shadow mode is returned. * * @see Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) * @see ShadowMode */ public RenderQueue.ShadowMode getShadowMode() { if (shadowMode != RenderQueue.ShadowMode.Inherit) { return shadowMode; } else if (parent != null) { return parent.getShadowMode(); } else { return ShadowMode.Off; } }
Example 8
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Flattens the given scene graph into the ViewPort's RenderQueue, * checking for culling as the call goes down the graph recursively. * <p> * First, the scene is checked for culling based on the <code>Spatial</code>s * {@link Spatial#setCullHint(com.jme3.scene.Spatial.CullHint) cull hint}, * if the camera frustum contains the scene, then this method is recursively * called on its children. * <p> * When the scene's leaves or {@link Geometry geometries} are reached, * they are each enqueued into the * {@link ViewPort#getQueue() ViewPort's render queue}. * <p> * In addition to enqueuing the visible geometries, this method * also scenes which cast or receive shadows, by putting them into the * RenderQueue's * {@link RenderQueue#addToShadowQueue(com.jme3.scene.Geometry, com.jme3.renderer.queue.RenderQueue.ShadowMode) * shadow queue}. Each Spatial which has its * {@link Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) shadow mode} * set to not off, will be put into the appropriate shadow queue, note that * this process does not check for frustum culling on any * {@link ShadowMode#Cast shadow casters}, as they don't have to be * in the eye camera frustum to cast shadows on objects that are inside it. * * @param scene The scene to flatten into the queue * @param vp The ViewPort provides the {@link ViewPort#getCamera() camera} * used for culling and the {@link ViewPort#getQueue() queue} used to * contain the flattened scene graph. */ public void renderScene(Spatial scene, ViewPort vp) { if (scene.getParent() == null) { vp.getCamera().setPlaneState(0); } // check culling first. if (!scene.checkCulling(vp.getCamera())) { // move on to shadow-only render if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint()!=Spatial.CullHint.Always) { renderShadow(scene, vp.getQueue()); } return; } scene.runControlRender(this, vp); if (scene instanceof Node) { // recurse for all children Node n = (Node) scene; List<Spatial> children = n.getChildren(); //saving cam state for culling int camState = vp.getCamera().getPlaneState(); for (int i = 0; i < children.size(); i++) { //restoring cam state before proceeding children recusively vp.getCamera().setPlaneState(camState); renderScene(children.get(i), vp); } } else if (scene instanceof Geometry) { // add to the render queue Geometry gm = (Geometry) scene; if (gm.getMaterial() == null) { throw new IllegalStateException("No material is set for Geometry: " + gm.getName()); } vp.getQueue().addToQueue(gm, scene.getQueueBucket()); // add to shadow queue if needed RenderQueue.ShadowMode shadowMode = scene.getShadowMode(); if (shadowMode != RenderQueue.ShadowMode.Off) { vp.getQueue().addToShadowQueue(gm, shadowMode); } } }
Example 9
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Populates the outputGeometryList with the rootScene children geometries * that are in the frustum of the given camera * * @param rootScene the rootNode of the scene to traverse * @param camera the camera to check geometries against * @param outputGeometryList the list of all geometries that are in the * camera frustum */ public static void getGeometriesInCamFrustum(Spatial rootScene, Camera camera, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) { if (rootScene != null && rootScene instanceof Node) { int planeState = camera.getPlaneState(); addGeometriesInCamFrustumFromNode(camera, (Node)rootScene, mode, outputGeometryList); camera.setPlaneState(planeState); } }
Example 10
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 2 votes |
/** * Sets the shadow mode of the spatial * The shadow mode determines how the spatial should be shadowed, * when a shadowing technique is used. See the * documentation for the class {@link ShadowMode} for more information. * * @see ShadowMode * * @param shadowMode The local shadow mode to set. */ public void setShadowMode(RenderQueue.ShadowMode shadowMode) { this.shadowMode = shadowMode; }
Example 11
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 2 votes |
/** * @return The locally set shadow mode * * @see Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) */ public RenderQueue.ShadowMode getLocalShadowMode() { return shadowMode; }
Example 12
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Sets the shadow mode of the spatial * The shadow mode determines how the spatial should be shadowed, * when a shadowing technique is used. See the * documentation for the class {@link ShadowMode} for more information. * * @see ShadowMode * * @param shadowMode The local shadow mode to set. */ public void setShadowMode(RenderQueue.ShadowMode shadowMode) { this.shadowMode = shadowMode; }
Example 13
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * @return The locally set shadow mode * * @see Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) */ public RenderQueue.ShadowMode getLocalShadowMode() { return shadowMode; }
Example 14
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Populates the outputGeometryList with the geometries of the children * of OccludersExtractor.rootScene node that are both in the frustum of the given vpCamera and some camera inside cameras array. * The array of cameras must be initialized to represent the light viewspace of some light like pointLight or spotLight * * @param rootScene * @param vpCamera the viewPort camera * @param cameras the camera array to check geometries against, representing the light viewspace * @param outputGeometryList the output list of all geometries that are in the camera frustum */ public static void getLitGeometriesInViewPort(Spatial rootScene, Camera vpCamera, Camera[] cameras, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) { if (rootScene != null && rootScene instanceof Node) { addGeometriesInCamFrustumAndViewPortFromNode(vpCamera, cameras, rootScene, mode, outputGeometryList); } }
Example 15
Source File: Spatial.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * Sets the shadow mode of the spatial * The shadow mode determines how the spatial should be shadowed, * when a shadowing technique is used. See the * documentation for the class {@link ShadowMode} for more information. * * @see ShadowMode * * @param shadowMode The local shadow mode to set. */ public void setShadowMode(RenderQueue.ShadowMode shadowMode) { this.shadowMode = shadowMode; }
Example 16
Source File: Spatial.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 2 votes |
/** * @return The locally set shadow mode * * @see Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) */ public RenderQueue.ShadowMode getLocalShadowMode() { return shadowMode; }