@ -63,8 +63,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
private Texture2D filterTexture ;
private Texture2D filterTexture ;
private Texture2D depthTexture ;
private Texture2D depthTexture ;
private List < Filter > filters = new ArrayList < Filter > ( ) ;
private List < Filter > filters = new ArrayList < Filter > ( ) ;
private AssetManager assetManager ;
private AssetManager assetManager ;
private Camera filterCam = new Camera ( 1 , 1 ) ;
private Picture fsQuad ;
private Picture fsQuad ;
private boolean computeDepth = false ;
private boolean computeDepth = false ;
private FrameBuffer outputBuffer ;
private FrameBuffer outputBuffer ;
@ -78,7 +77,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
private int originalHeight ;
private int originalHeight ;
private int lastFilterIndex = - 1 ;
private int lastFilterIndex = - 1 ;
private boolean cameraInit = false ;
private boolean cameraInit = false ;
private boolean clearColor = tru e;
private boolean multiView = fals e;
/ * *
/ * *
* Create a FilterProcessor
* Create a FilterProcessor
@ -135,7 +134,9 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
renderer = rm . getRenderer ( ) ;
renderer = rm . getRenderer ( ) ;
viewPort = vp ;
viewPort = vp ;
fsQuad = new Picture ( "filter full screen quad" ) ;
fsQuad = new Picture ( "filter full screen quad" ) ;
fsQuad . setWidth ( 1 ) ;
fsQuad . setHeight ( 1 ) ;
Camera cam = vp . getCamera ( ) ;
Camera cam = vp . getCamera ( ) ;
//save view port diensions
//save view port diensions
@ -176,29 +177,23 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
* @param mat
* @param mat
* /
* /
private void renderProcessing ( Renderer r , FrameBuffer buff , Material mat ) {
private void renderProcessing ( Renderer r , FrameBuffer buff , Material mat ) {
if ( buff = = outputBuffer ) {
if ( buff = = outputBuffer & & multiView ) {
fsQuad . setWidth ( width ) ;
viewPort . getCamera ( ) . resize ( originalWidth , originalHeight , false ) ;
fsQuad . setHeight ( height ) ;
viewPort . getCamera ( ) . setViewPort ( left , right , bottom , top ) ;
filterCam . resize ( originalWidth , originalHeight , true ) ;
viewPort . getCamera ( ) . update ( ) ;
fsQuad . setPosition ( left * originalWidth , bottom * originalHeight ) ;
renderManager . setCamera ( viewPort . getCamera ( ) , false ) ;
} else {
fsQuad . setWidth ( buff . getWidth ( ) ) ;
fsQuad . setHeight ( buff . getHeight ( ) ) ;
filterCam . resize ( buff . getWidth ( ) , buff . getHeight ( ) , true ) ;
fsQuad . setPosition ( 0 , 0 ) ;
}
}
if ( mat . getAdditionalRenderState ( ) . isDepthWrite ( ) ) {
if ( mat . getAdditionalRenderState ( ) . isDepthWrite ( ) ) {
mat . getAdditionalRenderState ( ) . setDepthTest ( false ) ;
mat . getAdditionalRenderState ( ) . setDepthTest ( false ) ;
mat . getAdditionalRenderState ( ) . setDepthWrite ( false ) ;
mat . getAdditionalRenderState ( ) . setDepthWrite ( false ) ;
}
}
fsQuad . setMaterial ( mat ) ;
fsQuad . setMaterial ( mat ) ;
fsQuad . updateGeometricState ( ) ;
fsQuad . updateGeometricState ( ) ;
renderManager . setCamera ( filterCam , true ) ;
r . setFrameBuffer ( buff ) ;
r . setFrameBuffer ( buff ) ;
r . clearBuffers ( clearColor , true , true ) ;
r . clearBuffers ( true , true , true ) ;
renderManager . renderGeometry ( fsQuad ) ;
renderManager . renderGeometry ( fsQuad ) ;
}
}
@ -216,8 +211,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
}
}
}
}
}
}
Picture pic = new Picture ( "debug" ) ;
/ * *
/ * *
* iterate through the filter list and renders filters
* iterate through the filter list and renders filters
@ -317,11 +311,14 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
} else {
} else {
viewPort . setOutputFrameBuffer ( renderFrameBuffer ) ;
viewPort . setOutputFrameBuffer ( renderFrameBuffer ) ;
}
}
//init of the camera if it wasn't already
//if we are ina multiview situation we need to resize the camera
if ( ! cameraInit ) {
//to the viewportsize so that the backbuffer is rendered correctly
viewPort . getCamera ( ) . resize ( width , height , true ) ;
if ( multiView ) {
viewPort . getCamera ( ) . resize ( width , height , false ) ;
viewPort . getCamera ( ) . setViewPort ( 0 , 1 , 0 , 1 ) ;
viewPort . getCamera ( ) . setViewPort ( 0 , 1 , 0 , 1 ) ;
}
viewPort . getCamera ( ) . update ( ) ;
renderManager . setCamera ( viewPort . getCamera ( ) , false ) ;
}
}
}
for ( Iterator < Filter > it = filters . iterator ( ) ; it . hasNext ( ) ; ) {
for ( Iterator < Filter > it = filters . iterator ( ) ; it . hasNext ( ) ; ) {
@ -376,8 +373,8 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
}
}
public void reshape ( ViewPort vp , int w , int h ) {
public void reshape ( ViewPort vp , int w , int h ) {
//this has no effect at first init but is useful when resizing the canvas with multi views
Camera cam = vp . getCamera ( ) ;
Camera cam = vp . getCamera ( ) ;
//this has no effect at first init but is useful when resizing the canvas with multi views
cam . setViewPort ( left , right , bottom , top ) ;
cam . setViewPort ( left , right , bottom , top ) ;
//resizing the camera to fit the new viewport and saving original dimensions
//resizing the camera to fit the new viewport and saving original dimensions
cam . resize ( w , h , false ) ;
cam . resize ( w , h , false ) ;
@ -387,24 +384,20 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
bottom = cam . getViewPortBottom ( ) ;
bottom = cam . getViewPortBottom ( ) ;
originalWidth = w ;
originalWidth = w ;
originalHeight = h ;
originalHeight = h ;
cam . setViewPort ( 0 , 1 , 0 , 1 ) ;
//computing real dimension of the viewport and resizing he camera
//computing real dimension of the viewport and resizing t he camera
width = ( int ) ( w * ( Math . abs ( right - left ) ) ) ;
width = ( int ) ( w * ( Math . abs ( right - left ) ) ) ;
height = ( int ) ( h * ( Math . abs ( bottom - top ) ) ) ;
height = ( int ) ( h * ( Math . abs ( bottom - top ) ) ) ;
width = Math . max ( 1 , width ) ;
width = Math . max ( 1 , width ) ;
height = Math . max ( 1 , height ) ;
height = Math . max ( 1 , height ) ;
//Testing original versus actual viewport dimension.
//Testing original versus actual viewport dimension.
//If they are different we are in a multiview situation and color from other view port must not be cleared.
//If they are different we are in a multiview situation and
//However, not clearing the color can cause issues when AlphaToCoverage is active on the renderer.
//camera must be handled differently
if ( originalWidth ! = width | | originalHeight ! = height ) {
if ( originalWidth ! = width | | originalHeight ! = height ) {
clearColor = false ;
multiView = true ;
} else {
clearColor = true ;
}
}
cam . resize ( width , height , false ) ;
cameraInit = true ;
cameraInit = true ;
computeDepth = false ;
computeDepth = false ;