basically there is in later drivers support for EXT framebuffer functions (still not ARB :( ) which allows you to create separate buffers to draw into, this patch enables a framebuffer rendering route. this allows the buffered to be bound to a texture and then redrawn to the main screen with special 'post-process' effects, in this code here i have implemented GLSL bloom and a GLSL rotoscope effect.
I havn't tested this yet on any ones setup but mine (Linux, nvidia drivers with a geforce 6200) but really it *should* work with any ones setup that has opengl2.0 support. basically it requires:
GL_EXT_framebuffer_object
GL_ARB_fragment_shader
GL_ARB_shading_language_100
GL_ARB_vertex_shader
GL_ARB_fragment_program
GL_ARB_vertex_program
GL_ARB_texture_non_power_of_two
GL_EXT_packed_depth_stencil
for some reason the sdl opengl headers only provide GL_DEPTH_STENCIL_NV instead of GL_DEPTH_STENCIL_EXT is this something that needs to be fixed upstream? because of this i am not sure weather it will work on ati cards at the mo.
there are a few noticeable graphical bugs at the moment. for example because i am not sure about how RB_ExecuteRenderCommands there is some ambiguity with regards to STRETCH_PIC and such. which seems to lead to the post processing effects getting applied to normal textures sometimes (explosions have a box around them from blooming the texture) and some textures seem to randomly disappear too. can anyone shed some enlightenment on this?
it would also be nice if the effects were only applied to 3D rendered stuff instead of the entire frame (so that the console isn't bloomed and such) but am not sure how to go forward with this.
with the multiplatform sdl code this should hopefully compile on everything :)
to enable it (to quickly test it) you just need to set the following cvars
r_framebuffer 1
r_framebuffer_bloom 1
r_framebuffer_rotoscope 1
(r_framebuffer_bloom/rotoscope arn't needed but it will look the same as normal otherwise). generally there is some fps loss from using framebuffers but if its excessive it would be nice to know. (about 18-40fps on my geforce 6200 with just bloom enabled, cards with better gpu texture bandwidth should do *much* better)
-- gord allott (gordallott@gmail.com)
Created attachment 1576[details]
bugfixes
fixes:
-missing textures
-missing brushes
-video playback
everything should be working properly now (ie: obvious bugs are corrected)
based on svn revision 1212.
Created attachment 1579[details]
bugfixes - cleanup - small additions to framebuffer patch
few more bug fixes, cleaned up the code so it all works nicer with the actual engine (better extension detection, made a few defines more future proof). added a new mode for rotoscope where the edge detection is based on the zbuffer not the colour information.
Created attachment 1580[details]
smallbug fix to fbuffer patch
left in a silly bug by mistake that would cause a segfault on systems without the required extensions but whom still enable r_framebuffer
Created attachment 1592[details]
framebuffer refactor
refactored the framebuffer code, should be quicker and more compatible
added proper ogl testing instead of extension based testing, should be more compatible with dodgy drivers and drivers/cards in the future.
better memory handling, should fix some problems with shutdown/startups
(In reply to comment #9)
> I would like to note that this patch breaks NVIDIA Full-Screen Anti-Aliasing.
> This means diminished performance with no anti-aliasing effect.
>
framebuffer objects by default do not support anti-aliasing and since this is an outside influance (forcing anti-aliasing via a driver config option) i wouldn't count it as a bug or anything. if someone were to add in engine support to the engine for anti-aliasing it could theoretically work.
I recently integrated this patch into my ioq3-based project, and found that sometimes a vid_restart will turn the screen black - the console can still be used and I can quit safely, but the application is obviously unusable. Was this the "vid-restart bug" you mentioned earlier? If so, any ideas on how to fix it?
(In reply to comment #11)
> I recently integrated this patch into my ioq3-based project, and found that
> sometimes a vid_restart will turn the screen black - the console can still be
> used and I can quit safely, but the application is obviously unusable. Was
> this the "vid-restart bug" you mentioned earlier? If so, any ideas on how to
> fix it?
>
its been nearly a year since i touched this code so i'm not sure if its the same bug (i don't even remember what it is) but for sanities sake i took apart the codebase to figure out where the bug was at least.
It seems to be localised to creating a new framebuffer after a gl context switch, essentially gl doesn't like creating some framebuffers and then creating a new context and creating some more framebuffers
I don't really have the time to delve deap into the q3 source to figure out how to make it play nice at the moment so i would suggest that you just disable the framebuffer path on a vid_restart (just have a variable check how many times the init function is called, if its more than once just return from the endframe/init/shutdown functions stright away) - its not perfect but it would at least leave you with a screen you can see rather than blackness.
If you do manage to fix it don't forget to post the fix here :)
Comment 14Guillaume Bougard
2009-11-16 19:08:40 EST
Created attachment 2201[details]
Enhanced fbuffer-refactor fix
Thank you Gord Allott for this work.
Okay I know, this feature won't be included in ioquake3, but I really wanted it for our ioQuake3 based Smokin'Guns engine. So I took it and tried to enhanced it as much as I could.
Firstly I upgraded the patch to last rev1752. Then I found and tried to fix few issues. I fixed few crash cases, and few black screen cases. I changed some API so it re-uses better ioQuake3 API, like the ones to malloc and free memory, and also the one to check existing OpenGL extension. I added few error reporting thanks to OpenGL wiki. I also tried to include multisample support (re-using r_ext_multisample cvar) but this part doesn't work for some reasons I don't know (I'm really not an OpenGL programmer, so maybe Gord Allott or anyother people may try to fix that part).
Last but not least, I didn't really like how the patch was applying effect also on the UI part. So I fixed also this part and I think every cases are covered (okay I didn't have time to check every possible cases, but cinematics, main UI, ingame UI and portal view (here with effect applied) seems working perfectly as expected.
Finally, I implemented the patch with a FRAMEBUFFER_AND_GLSL_SUPPORT define and I adapted the Makefile to support that. So to try it, just export ioQ3 r1752, apply the patch, and build it with "make FRAMEBUFFER_AND_GLSL_SUPPORT=1" or add "FRAMEBUFFER_AND_GLSL_SUPPORT = 1" in your Makefile.local file and build it as usual.
I currently only tested the binary on my linux x84_64 system (Fedora 11) with a Nvidia 9400 video card. I still obtain easily 100 FPS.
Also I put a video on youtube, thanks to ioquake3 video command ;). Check it at http://www.youtube.com/watch?v=F9zMo9-zchQ. I used the "four" quake3 demo with different settings. Even the one with rotoscope based on z-edge, with bloom effect and in greyscale looks pretty ;)
And to conclude, if this patch is not suitable for ioQuake3, you may want to put it on http://ioquake3.org/extras/patches/ page.
Comment 15Guillaume Bougard
2009-11-16 19:13:44 EST
Just forgot to say, I also renamed the cvars with "r_ext_" prefix so it matches better renderer conventions.
Comment 16Guillaume Bougard
2009-12-19 20:08:12 EST
Created attachment 2227[details]
Enhanced fbuffer-refactor v2
Here is another update.
This version includes:
1. Important framebuffer initialization refactor so you can set r_ext_framebuffer* cvars from UI without crashing the client.
2. Don't set multisample by SDL when r_ext_framebuffer is set
3. Now GLSL programs can be loaded from files, even in a developer mode
4. Few minor bug a typo fixes
I published screenshots at http://www.moddb.com/members/sg-tequila/blog/fbo-effects-in-smokinguns
Tequila
Smokin'Guns team
Comment 17Guillaume Bougard
2009-12-19 20:12:50 EST
Created attachment 2228[details]
PK3 files with GLSL programs
With last patch, here is a PK3 file you can edit to tune GLSL programs. You may also extract them next to q3config.cfg file, change extension from .glsl to .cfg and start the engine with "+set developer 1".
Created attachment 1570 [details] adds fbuffer support to ioq3
Created attachment 1576 [details] bugfixes fixes: -missing textures -missing brushes -video playback everything should be working properly now (ie: obvious bugs are corrected) based on svn revision 1212.
Created attachment 1579 [details] bugfixes - cleanup - small additions to framebuffer patch few more bug fixes, cleaned up the code so it all works nicer with the actual engine (better extension detection, made a few defines more future proof). added a new mode for rotoscope where the edge detection is based on the zbuffer not the colour information.
Created attachment 1580 [details] smallbug fix to fbuffer patch left in a silly bug by mistake that would cause a segfault on systems without the required extensions but whom still enable r_framebuffer
Created attachment 1581 [details] above patch is wrong one uploaded the wrong patch by mistake
Created attachment 1590 [details] fbuffer patch - ati fixes (hopefully) fixed problems with ati cards. better ext_ detection. Updated to revision 1214.
Created attachment 1592 [details] framebuffer refactor refactored the framebuffer code, should be quicker and more compatible added proper ogl testing instead of extension based testing, should be more compatible with dodgy drivers and drivers/cards in the future. better memory handling, should fix some problems with shutdown/startups
Created attachment 1600 [details] fbuffer-refactor fix fixes vid-restart bug
Created attachment 2228 [details] PK3 files with GLSL programs With last patch, here is a PK3 file you can edit to tune GLSL programs. You may also extract them next to q3config.cfg file, change extension from .glsl to .cfg and start the engine with "+set developer 1".