/** * Initialize this ProjectedDepthTexture with the renderer * * @param r */ public void init(final Renderer r) { // already initialized ? if (textureRenderer != null) { return; } textureRenderer = ImageUtil.createTextureRenderer(0, 0, r, true); if (isParallel) { textureRenderer.getCamera().setProjectionMode(Camera.ProjectionMode.Parallel); } // Enforce performance enhancing states on the renderer. // No textures or colors are required since we're only // interested in recording depth. // Also only need front faces when rendering the shadow maps // turn off clipping ClipState noClip = new ClipState(); noClip.setEnabled(false); textureRenderer.enforceState(noClip); // turn off texturing TextureState noTexture = new TextureState(); noTexture.setEnabled(false); textureRenderer.enforceState(noTexture); // turn off colors ColorMaskState colorDisabled = new ColorMaskState(); colorDisabled.setAll(false); textureRenderer.enforceState(colorDisabled); // cull back faces CullState cullFace = new CullState(); cullFace.setEnabled(true); cullFace.setCullFace(CullState.Face.Back); textureRenderer.enforceState(cullFace); // turn off lights LightState noLights = new LightState(); noLights.setEnabled(false); textureRenderer.enforceState(noLights); // use flat shading ShadingState flat = new ShadingState(); flat.setShadingMode(ShadingMode.Flat); textureRenderer.enforceState(flat); // disable GLSLShaderObjectsState GLSLShaderObjectsState glsl = new GLSLShaderObjectsState(); glsl.setEnabled(false); textureRenderer.enforceState(glsl); // enforce the shadow offset parameters textureRenderer.enforceState(offsetState); if (texture == null) { createTexture(); } textureRenderer.setupTexture(texture); }
private void copyLightState(final LightState pkLState, final LightState lightState) { lightState.setTwoSidedLighting(pkLState.getTwoSidedLighting()); lightState.setLocalViewer(pkLState.getLocalViewer()); lightState.setSeparateSpecular(pkLState.getSeparateSpecular()); lightState.setEnabled(pkLState.isEnabled()); for (int i = 0, maxL = pkLState.getLightList().size(); i < maxL; i++) { final Light pkLight = pkLState.get(i); if (pkLight != null) { lightState.attach(pkLight); } } }
@Override public RenderState extract(final Stack<? extends RenderState> stack, final Spatial spat) { if (spat == null) { return stack.peek(); } final LightCombineMode mode = spat.getLightCombineMode(); final Mesh mesh = (Mesh) spat; LightState lightState = mesh.getLightState(); if (lightState == null) { lightState = new LightState(); mesh.setLightState(lightState); } lightState.detachAll(); if (mode == LightCombineMode.Replace || (mode != LightCombineMode.Off && stack.size() == 1)) { // todo: use dummy state if off? final LightState copyLightState = (LightState) stack.peek(); copyLightState(copyLightState, lightState); } else { // accumulate the lights in the stack into a single LightState object final Object states[] = stack.toArray(); boolean foundEnabled = false; switch (mode) { case CombineClosest: case CombineClosestEnabled: for (int iIndex = states.length - 1; iIndex >= 0; iIndex--) { final LightState pkLState = (LightState) states[iIndex]; if (!pkLState.isEnabled()) { if (mode == LightCombineMode.CombineClosestEnabled) { break; } continue; } foundEnabled = true; copyLightState(pkLState, lightState); } break; case CombineFirst: for (int iIndex = 0, max = states.length; iIndex < max; iIndex++) { final LightState pkLState = (LightState) states[iIndex]; if (!pkLState.isEnabled()) { continue; } foundEnabled = true; copyLightState(pkLState, lightState); } break; case Off: break; } lightState.setEnabled(foundEnabled); } return lightState; }