Package net.anzix.fsz.sceneComponents

Source Code of net.anzix.fsz.sceneComponents.Shadow

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package net.anzix.fsz.sceneComponents;

import com.ardor3d.extension.shadow.map.ParallelSplitShadowMapPass;
import com.ardor3d.light.DirectionalLight;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.pass.BasicPassManager;
import com.ardor3d.renderer.pass.RenderPass;
import com.ardor3d.renderer.state.LightState;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.visitor.UpdateModelBoundVisitor;
import com.ardor3d.util.ReadOnlyTimer;

/**
*
* @author csiga
*/
public class Shadow {
    /** Pssm shadow map pass. */
    private ParallelSplitShadowMapPass _pssmPass;

    /** Pass manager. */
    //private BasicPassManager _passManager;

    /** Quads used for debug showing shadowmaps. */
    //private Quad _orthoQuad[];

    /** Temp vec for updating light pos. */
    private final Vector3 lightPosition = new Vector3(10000, 2000, 10000);

    /** Flag to make sure quads are updated on reinitialization of shadow renderer */
    private boolean _quadsDirty = true;

    public void registerPass( BasicPassManager passManager ) {

        // Setup some standard states for the scene.
        //final CullState cullFrontFace = new CullState();
        //cullFrontFace.setEnabled(true);
        //cullFrontFace.setCullFace(CullState.Face.Back);
        //_root.setRenderState(cullFrontFace);
       
        //final MaterialState ms = new MaterialState();
        //ms.setColorMaterial(ColorMaterial.Diffuse);
        //_root.setRenderState(ms);
       
        //_passManager = new BasicPassManager();

        // setup some quads for debug viewing.
        /*final RenderPass renderPass = new RenderPass();
        final int quadSize = _canvas.getCanvasRenderer().getCamera().getWidth() / 10;
        _orthoQuad = new Quad[ParallelSplitShadowMapPass._MAX_SPLITS];
        for (int i = 0; i < ParallelSplitShadowMapPass._MAX_SPLITS; i++) {
            _orthoQuad[i] = new Quad("OrthoQuad", quadSize, quadSize);
            _orthoQuad[i].setTranslation(new Vector3((quadSize / 2 + 5) + (quadSize + 5) * i, (quadSize / 2 + 5), 1));
            _orthoQuad[i].getSceneHints().setRenderBucketType(RenderBucketType.Ortho);
            _orthoQuad[i].getSceneHints().setLightCombineMode(LightCombineMode.Off);
            _orthoQuad[i].getSceneHints().setTextureCombineMode(TextureCombineMode.Replace);
            _orthoQuad[i].getSceneHints().setCullHint(CullHint.Never);
            renderPass.add(_orthoQuad[i]);
        }
        */

        //final RenderPass rootPass = new RenderPass();
        //rootPass.add(rootNode);

        //lightState.detachAll();
        final DirectionalLight light = new DirectionalLight();
        light.setDirection(lightPosition.normalize(null).negateLocal());

        // final PointLight light = new PointLight();
        light.setEnabled(true);
        //lightState.attach(light);
       
       
        //final Light light = _lightState.get(0);
        //if (light instanceof PointLight) {
        //    ((PointLight) light).setLocation(lightPosition);
        //} else if (light instanceof DirectionalLight) {
        //    ((DirectionalLight) light).setDirection(lightPosition.normalize(null).negateLocal());
        //}
       
       
       
       

        // Create pssm pass
        _pssmPass = new ParallelSplitShadowMapPass(light, 1024, 4);
        //_pssmPass.add(rootNode);
        _pssmPass.setUseSceneTexturing(true);
        _pssmPass.setUseObjectCullFace(true);

        //_pssmPass.addOccluder(occluders);

        // Populate passmanager with passes.
        passManager.add(_pssmPass);
        //_passManager.add(renderPass);
       

    }
    public void addAccepter(Node accepter) {
        _pssmPass.add(accepter);
         // Make sure all boundings are updated.
        accepter.acceptVisitor(new UpdateModelBoundVisitor(), false);  
    }
    public void addOccluder( Node occluder ) {
        _pssmPass.addOccluder(occluder);
    }  
   
    public void initShadowPass(final Renderer renderer) {
        if (!_pssmPass.isInitialised()) {
            _quadsDirty = false;
            _pssmPass.init(renderer);
        } else if (!_quadsDirty) {
            _quadsDirty = false;
            _pssmPass.reinit(renderer);
        }
    }
}
TOP

Related Classes of net.anzix.fsz.sceneComponents.Shadow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.