Added stencil zfail optimization aka Carmack's Reverse

This commit is contained in:
Robert Beckebans 2019-11-19 21:02:47 +01:00
parent 3632d200f9
commit f6701427dd
4 changed files with 13 additions and 4 deletions

View file

@ -166,9 +166,12 @@ any other Steam features.
The RBDOOM-3-BFG Edition GPL Source Code release includes functionality for rendering Bink Videos through FFmpeg or libbinkdec.
### Back End Rendering of Stencil Shadows
The Doom 3 BFG Edition GPL Source Code release does not include functionality enabling rendering
The RBOOM-3-BFG Edition GPL Source Code release includes functionality enabling rendering
of stencil shadows via the "depth fail" method, a functionality commonly known as "Carmack's Reverse".
This method was patented by Creative Labs and has finally expired on 2019-10-13.
(see https://patents.google.com/patent/US6384822B1/en for expiration status)
---
## License <a name="license"></a>
See docs/COPYING.txt for the GNU GENERAL PUBLIC LICENSE

View file

@ -1614,7 +1614,9 @@ void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const b
}
else
{
// Z-fail
// Z-fail (Carmack's Reverse)
glStencilOpSeparate( GL_FRONT, GL_KEEP, GL_DECR, GL_KEEP );
glStencilOpSeparate( GL_BACK, GL_KEEP, GL_INCR, GL_KEEP );
}
// get vertex buffer

View file

@ -42,7 +42,7 @@ If you have questions concerning this license or the applicable additional terms
idCVar r_drawEyeColor( "r_drawEyeColor", "0", CVAR_RENDERER | CVAR_BOOL, "Draw a colored box, red = left eye, blue = right eye, grey = non-stereo" );
idCVar r_motionBlur( "r_motionBlur", "0", CVAR_RENDERER | CVAR_INTEGER | CVAR_ARCHIVE, "1 - 5, log2 of the number of motion blur samples" );
idCVar r_forceZPassStencilShadows( "r_forceZPassStencilShadows", "0", CVAR_RENDERER | CVAR_BOOL, "force Z-pass rendering for performance testing" );
idCVar r_useStencilShadowPreload( "r_useStencilShadowPreload", "1", CVAR_RENDERER | CVAR_BOOL, "use stencil shadow preload algorithm instead of Z-fail" );
idCVar r_useStencilShadowPreload( "r_useStencilShadowPreload", "0", CVAR_RENDERER | CVAR_BOOL, "use stencil shadow preload algorithm instead of Z-fail" );
idCVar r_skipShaderPasses( "r_skipShaderPasses", "0", CVAR_RENDERER | CVAR_BOOL, "" );
idCVar r_skipInteractionFastPath( "r_skipInteractionFastPath", "1", CVAR_RENDERER | CVAR_BOOL, "" );
idCVar r_useLightStencilSelect( "r_useLightStencilSelect", "0", CVAR_RENDERER | CVAR_BOOL, "use stencil select pass" );

View file

@ -2321,7 +2321,11 @@ void idRenderBackend::DrawStencilShadowPass( const drawSurf_t* drawSurf, const b
}
else
{
// Z-fail
// Z-fail (Carmack's Reverse)
uint64 stencil = GLS_STENCIL_OP_FAIL_KEEP | GLS_STENCIL_OP_ZFAIL_DECR | GLS_STENCIL_OP_PASS_KEEP
| GLS_BACK_STENCIL_OP_FAIL_KEEP | GLS_BACK_STENCIL_OP_ZFAIL_INCR | GLS_BACK_STENCIL_OP_PASS_KEEP;
GL_State( ( glStateBits & ~GLS_STENCIL_OP_BITS ) | stencil );
}
// get vertex buffer