Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * The MIT License (MIT)
   *
   * Copyright (c) 2014 Christian Gärtner
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
  * The above copyright notice and this permission notice shall be included in all
  * copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
 
 package org.achtern.AchternEngine.core.rendering.shadow;
 
 
 public class BasicShadowRenderer extends Shadow {
 
     protected FrameBuffer shadowMap;
 
     protected Camera camera;
 
     protected Matrix4f bias;
 
     @Override
     public void init(RenderEngine renderEngine) {
          = new FrameBuffer(new Dimension(1024, 1024));
         .setDepthTarget(new Texture(
                 new Dimension(1024, 1024),
                 ..,
                 .,
                 .,
                 false
         ));
 
         renderEngine.addTexture("shadowMap".getDepthTarget().getTexture());
 
         Node holder = new Node();
          = new Camera();
         holder.add();
 
          = new Matrix4f().initScale(0.5f, 0.5f, 0.5f);
          = .mul(new Matrix4f().initTranslation(1, 1, 1));
 
     }
 
     @Override
     public void pre(Node nodeRenderPass passRenderEngine renderEngine) {
 
         if (pass instanceof BaseLight) {
             ShadowInfo shadowInfo = ((BaseLightpass).getShadowInfo();
 
             if (shadowInfo != null) {
 
                 renderEngine.getDataBinder().bindAsRenderTarget();
 
                 renderEngine.getState().clear(falsetruefalse);
 
                 .setProjection(shadowInfo.getMatrix());
 
                 .getTransform().setPosition(
                         ((BaseLightpass).getTransform().getTransformedPosition()
                 );
                 .getTransform().setRotation(
                         ((BaseLightpass).getTransform().getTransformedRotation()
                 );
 
                 .getTransform().rotate(.getTransform().getRotation().getUp(), 180);
 
                 renderEngine.addMatrix("shadowMatrix".mul(.getViewProjection()));
 
                 // Store a copy of the main camera/renderpass/cullface
                Camera mainC = renderEngine.getCamera();
                RenderPass mainRP = renderEngine.getActiveRenderPass();
                Face cullFace = null;
                if (renderEngine.getState().isEnabled(.) && shadowInfo.getCullFace() != null) {
                    cullFace = renderEngine.getState().getCullFace();
                    renderEngine.getState().cullFace(shadowInfo.getCullFace());
                }
                renderEngine.setCamera();
                renderEngine.setActiveRenderPass(this);
                renderEngine.getDataBinder().bind(ShadowGenerator.getInstance());
                node.render(renderEngine);
                // Reset it
                if (cullFace != null) {
                    renderEngine.getState().cullFace(cullFace);
                }
                renderEngine.setCamera(mainC);
                renderEngine.setActiveRenderPass(mainRP);
            }
            renderEngine.getRenderTarget().bindAsRenderTarget(renderEngine.getDataBinder());
        }
    }

    
Returns the shader to get set on draw.

Returns:
the shader
    @Override
    public Shader getShader() {
        return ShadowGenerator.getInstance();
    }
New to GrepCode? Check out our FAQ X