I have noticed that the stereo rendering (r_stereoEnabled) does not generate an interlaced image, necessary for some 3d monitors (for example LG D2342P). This patch adds an extra functionality to the r_stereoEnabled cvar:
Setting it to 2 generates the interlaced image.
Known Issues:
Sometimes the screen blinks, relative to one of the eyes (just one eye gets wrong colors or empty screen). Seems to be related to some shaders OR camera displacement, not sure yet.
Created attachment 3059[details]
Patch for the renderer
This patch corrects the bug of flickering screen (it turned out to be some misspelling), plus adds a check to disable r_measureOverdraw if r_stereoEnabled is set to 2. Still need to be done a r_stereoEnabled mode 3 (or maybe a new cvar?) to reverse the eyes (some screens use even lines to left eye and odd ones to right eye; others use the other way around, so users must be able to switch this behavior), which currently renders even lines for left eye.
Created attachment 3060[details]
final version of r_stereoEnabled modification
Ok, sorry for the spam.
This is my last patch. It now enables the 4 modes for r_stereoEnabled:
r_stereoEnabled 0 : stereo rendering disabled
r_stereoEnabled 1 : old behavior
r_stereoEnabled 2 : left-right eye interlaced output
r_stereoEnabled 3 : right-left eye interlaced output
Comment 5Zachary J. Slater
2011-12-25 05:03:21 EST
Hi, I'd like to see this in ioquake3, but I have a few comments.
1. If SDL_GL_SetAttribute(SDL_GL_STEREO, 1), SDL requires the graphics card to be quad buffered, and ioquake3 won't start if it isn't. Does the interlaced stereo stuff really need quad buffers? It always seems to draw to:
+ qglDrawBuffer( GL_BACK );
so currently, when you set r_stereoEnabled to 2, in sdl_glimp.c it will call
SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
If the graphics card doesnt need quad buffers for interlaced stereo rendering, you should change sdl_glimp.c so that this does only get called when r_stereoEnabled == 1
2. You are using a RC_DRAW_BUFFER command to apply the stencil to the picture by hacking a check for GL_BACK_LEFT into RB_DrawBuffer. That's awful. You should add a new renderer command like RC_STENCIL and then add this via RE_BeginFrame in tr_cmds.c around line 428
3. Does the stencil stuff for the interlaced rendering not also conflict with stencil shadows in the q3 engine?
4. You're creating a new stencil in every frame. Wouldn't it suffice to write it once and then use it as often as you like?
5. Please document the change to the cvar in the README file
(In reply to comment #6)
> Hi, I'd like to see this in ioquake3, but I have a few comments.
>
> 1. If SDL_GL_SetAttribute(SDL_GL_STEREO, 1), SDL requires the graphics card to
> be quad buffered, and ioquake3 won't start if it isn't. Does the interlaced
> stereo stuff really need quad buffers? It always seems to draw to:
> + qglDrawBuffer( GL_BACK );
> so currently, when you set r_stereoEnabled to 2, in sdl_glimp.c it will call
> SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
>
> If the graphics card doesnt need quad buffers for interlaced stereo rendering,
> you should change sdl_glimp.c so that this does only get called when
> r_stereoEnabled == 1
>
> 2. You are using a RC_DRAW_BUFFER command to apply the stencil to the picture
> by hacking a check for GL_BACK_LEFT into RB_DrawBuffer. That's awful. You
> should add a new renderer command like RC_STENCIL and then add this via
> RE_BeginFrame in tr_cmds.c around line 428
>
> 3. Does the stencil stuff for the interlaced rendering not also conflict with
> stencil shadows in the q3 engine?
>
> 4. You're creating a new stencil in every frame. Wouldn't it suffice to write
> it once and then use it as often as you like?
>
> 5. Please document the change to the cvar in the README file
The code copies what would be rendered every frame to the stencil buffer, then every 2nd frame it renders the relevant content from that buffer to the screen. As it copies the content after everything is rendered, it should not interfere with stencil shadows (which should also be rendered in 3d), though I haven't tested both features turned on.
About the RC_STENCIL that should be created, yes, that is a good option; and I might also add a couple other modes, changing the behavior of the cvar: adding side-by-side rendering and top-and-bottom rendering. So when that is finished, I'll add everything to the README.
Forgot to comment: as stereo rendering drastically drops the framerate, requiring a somewhat recent video card for properly rendering and playable framerate, and those cards already support quad buffers, the code shouldn't really need to be changed, even though it can. But even considering those facts, I will add that check, it will save some VRAM.
After some testing, I've noticed that this interlaced patch does interfere with stencil shadows. Having this in mind and also the other proposed modifications (Side-by-Side and top-bottom stereo), I will have a look on GL_BACK_LEFT and GL_BACK_RIGHT and do some work with them.
Created attachment 3057 [details] patch for r_stereoEnabled
Created attachment 3059 [details] Patch for the renderer This patch corrects the bug of flickering screen (it turned out to be some misspelling), plus adds a check to disable r_measureOverdraw if r_stereoEnabled is set to 2. Still need to be done a r_stereoEnabled mode 3 (or maybe a new cvar?) to reverse the eyes (some screens use even lines to left eye and odd ones to right eye; others use the other way around, so users must be able to switch this behavior), which currently renders even lines for left eye.
Created attachment 3060 [details] final version of r_stereoEnabled modification Ok, sorry for the spam. This is my last patch. It now enables the 4 modes for r_stereoEnabled: r_stereoEnabled 0 : stereo rendering disabled r_stereoEnabled 1 : old behavior r_stereoEnabled 2 : left-right eye interlaced output r_stereoEnabled 3 : right-left eye interlaced output