1 /* 2 * To change this template, choose Tools | Templates 3 * and open the template in the editor. 4 */ 5 package com.jme3.water; 6 7 import com.jme3.math.Plane; 8 import com.jme3.post.SceneProcessor; 9 import com.jme3.renderer.Camera; 10 import com.jme3.renderer.RenderManager; 11 import com.jme3.renderer.ViewPort; 12 import com.jme3.renderer.queue.RenderQueue; 13 import com.jme3.texture.FrameBuffer; 14 15 /** 16 * Reflection Processor 17 * Used to render the reflected scene in an off view port 18 */ 19 public class ReflectionProcessor implements SceneProcessor { 20 21 private RenderManager rm; 22 private ViewPort vp; 23 private Camera reflectionCam; 24 private FrameBuffer reflectionBuffer; 25 private Plane reflectionClipPlane; 26 27 /** 28 * Creates a ReflectionProcessor 29 * @param reflectionCam the cam to use for reflection 30 * @param reflectionBuffer the FrameBuffer to render to 31 * @param reflectionClipPlane the clipping plane 32 */ 33 public ReflectionProcessor(Camera reflectionCam, FrameBuffer reflectionBuffer, Plane reflectionClipPlane) { 34 this.reflectionCam = reflectionCam; 35 this.reflectionBuffer = reflectionBuffer; 36 this.reflectionClipPlane = reflectionClipPlane; 37 } 38 39 public void initialize(RenderManager rm, ViewPort vp) { 40 this.rm = rm; 41 this.vp = vp; 42 } 43 44 public void reshape(ViewPort vp, int w, int h) { 45 } 46 47 public boolean isInitialized() { 48 return rm != null; 49 } 50 51 public void preFrame(float tpf) { 52 } 53 54 public void postQueue(RenderQueue rq) { 55 //we need special treatement for the sky because it must not be clipped 56 rm.getRenderer().setFrameBuffer(reflectionBuffer); 57 reflectionCam.setProjectionMatrix(null); 58 rm.setCamera(reflectionCam, false); 59 rm.getRenderer().clearBuffers(true, true, true); 60 //Rendering the sky whithout clipping 61 rm.getRenderer().setDepthRange(1, 1); 62 vp.getQueue().renderQueue(RenderQueue.Bucket.Sky, rm, reflectionCam, true); 63 rm.getRenderer().setDepthRange(0, 1); 64 //setting the clip plane to the cam 65 reflectionCam.setClipPlane(reflectionClipPlane, Plane.Side.Positive);//,1 66 rm.setCamera(reflectionCam, false); 67 68 } 69 70 public void postFrame(FrameBuffer out) { 71 } 72 73 public void cleanup() { 74 } 75 76 /** 77 * Internal use only<br> 78 * returns the frame buffer 79 * @return 80 */ 81 public FrameBuffer getReflectionBuffer() { 82 return reflectionBuffer; 83 } 84 85 /** 86 * Internal use only<br> 87 * sets the frame buffer 88 * @param reflectionBuffer 89 */ 90 public void setReflectionBuffer(FrameBuffer reflectionBuffer) { 91 this.reflectionBuffer = reflectionBuffer; 92 } 93 94 /** 95 * returns the reflection cam 96 * @return 97 */ 98 public Camera getReflectionCam() { 99 return reflectionCam; 100 } 101 102 /** 103 * sets the reflection cam 104 * @param reflectionCam 105 */ 106 public void setReflectionCam(Camera reflectionCam) { 107 this.reflectionCam = reflectionCam; 108 } 109 110 /** 111 * returns the reflection clip plane 112 * @return 113 */ 114 public Plane getReflectionClipPlane() { 115 return reflectionClipPlane; 116 } 117 118 /** 119 * Sets the reflection clip plane 120 * @param reflectionClipPlane 121 */ 122 public void setReflectionClipPlane(Plane reflectionClipPlane) { 123 this.reflectionClipPlane = reflectionClipPlane; 124 } 125 } 126