I have a filter with multiple passes that I apply to my scene and I’d like to access the framebuffer holding the result of the filter. Is there an easy way to do this?
So far I’ve tried:
Using the framebuffer’s in the postFrame() method of the filter class… which explicitly states this is not what I want
Creating a viewport, attaching the Filter, then attaching a SceneProcessor after that. In the scene processor’s postFrame() method I use the provided FrameBuffer out parameter
Using the same as attempt 2, but instead of using the out parameter, I grab the viewport’s outputFrameBuffer().
All ways have resulted in the frame buffer being filled with the scene before the filter passes are applied
/////EDIT/////
I have also tried accessing viewport.getOutputFrameBuffer() after each of these methods in the main update loop:
I don’t know if it will help. But I know sometimes these things are written and don’t capture the post effects and then get fixed to capture them. You could also look at the video capture state in the same package. I don’t know if they do it differently or not.
The thing is, if your filter is the last in the filter chain, it’s never rendered to a framebuffer, it’s rendered to the screen. Unless your viewport is setup to render to a framebuffer instead of the screen.
The way to do what you want is to create your own frameBuffer and set it to the viewport (viewport.setOutputFrameBuffer(yourFrameBuffer);). then add the filter post porcessor to this viewport.
The filters will be rendered to this frame buffer instead of the screen output.
Then you can do whatever you want with this frameBuffer
I tried your suggestion pspeed, but unfortunately the results were the same as I stated above. Looking at the source code it’s pretty much the same thing I am doing already.
Nehon:
I tried as you suggest, but it’s not working out how I expect. I’m not sure exactly what I am doing wrong, but here is the process I am using.
I set up pre viewport to which renders my root node into an MRT framebuffer
I set up another viewport, which takes the MRT and applies the filters, and set it output to another framebuffer
I use a screen processor to capture the output from the second viewport’s buffer using .getOutputFrameBuffer()
Result: The output of the framebuffer is just the clear colour of the viewport in step 2. Seemingly, the filters are not being applied and rendered into the getOutputFrameBuffer() framebuffer
Note: If instead of applying the filter to the viewport in step 2, I apply the filter the main viewport, the main rendering on screen is what I expect.
@bigstink said:
I tried your suggestion pspeed, but unfortunately the results were the same as I stated above. Looking at the source code it's pretty much the same thing I am doing already.
Didn't work how?
I'm not sure what else to say. ScreenshotAppState _definitely_ captures post-processing effects because I save screen shots that way all the time and they definitely have all post effects in them. So I must have misunderstood something and really nehon is the expert in this area.
pspeed - What’s happening is it’s capturing the scene after it’s initially rendered, but before any filters are applied to it. From what nehon said about the last filter being rendered to the screen, this makes sense. Since I only have 1 filter in my scene, it’s the last one and therefore it’s never actually getting rendered to any frame buffer, it’s going straight to the screen.
What’s confusing me now though, is in my current setup I’ve set up 3 viewports and still the results aren’t as I would hope:
FirstPassViewPort - Renders the rootnode to a MRT framebuffer I set up
WaterPassViewPort - Has a filter applied to it, which processes the MRT textures, and outputs the result (this is what I want to capture)
DefaultViewPort - The default viewport created in an app. The rootnode is detached. So what I am getting on screen is nothing… well, except the clear colour (in my case a blue colour)
Using this setup here are the results of screen captures:
FirstPassViewPort
The scene without any filter applies, this is expected since the filter is on the water viewport
I have four post-processing filters that are various levels of enabled or disabled at different times. The last one in the chain is a filter that just renders a radial fade over the entire scene.
If I attach the screen shot app state and take a screen shot with that last post-processing filter enabled, then I get a picture of it. Note the darkened screen in this screen shot:
So there must be something about my setup that’s different or there’s something specific to your setup that’s making it fail. I assume you tried taking a screen shot with the screenshot state and are referring to that when saying that it isn’t working.
…or this is all irrelevant and even if screen shots are taken correctly it’s a separate issue. I don’t know.
For those who have actually played the game, it’s an evil evil tease. :evil: When they right click on an object they get a menu without the “Physics” item.