mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-29 07:32:25 +00:00
Make r_showDepth use currentDepthImage, unless r_skipDepthCapture is 1
This commit is contained in:
parent
5ff59547a4
commit
580257b47e
2 changed files with 61 additions and 24 deletions
|
@ -983,7 +983,8 @@ extern idCVar r_materialOverride; // override all materials
|
||||||
|
|
||||||
extern idCVar r_debugRenderToTexture;
|
extern idCVar r_debugRenderToTexture;
|
||||||
|
|
||||||
extern idCVar r_glDebugContext;
|
extern idCVar r_glDebugContext; // DG: use debug context to call logging callbacks on GL errors
|
||||||
|
extern idCVar r_skipDepthCapture; // DG: disable capturing depth buffer, used for soft particles
|
||||||
|
|
||||||
/*
|
/*
|
||||||
====================================================================
|
====================================================================
|
||||||
|
|
|
@ -437,7 +437,6 @@ Draw the depth buffer as colors
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void RB_ShowDepthBuffer( void ) {
|
void RB_ShowDepthBuffer( void ) {
|
||||||
void *depthReadback;
|
|
||||||
|
|
||||||
if ( !r_showDepth.GetBool() ) {
|
if ( !r_showDepth.GetBool() ) {
|
||||||
return;
|
return;
|
||||||
|
@ -450,39 +449,76 @@ void RB_ShowDepthBuffer( void ) {
|
||||||
qglLoadIdentity();
|
qglLoadIdentity();
|
||||||
qglOrtho( 0, 1, 0, 1, -1, 1 );
|
qglOrtho( 0, 1, 0, 1, -1, 1 );
|
||||||
qglRasterPos2f( 0, 0 );
|
qglRasterPos2f( 0, 0 );
|
||||||
qglPopMatrix();
|
|
||||||
qglMatrixMode( GL_MODELVIEW );
|
|
||||||
qglPopMatrix();
|
|
||||||
|
|
||||||
GL_State( GLS_DEPTHFUNC_ALWAYS );
|
GL_State( GLS_DEPTHFUNC_ALWAYS );
|
||||||
qglColor3f( 1, 1, 1 );
|
qglColor3f( 1, 1, 1 );
|
||||||
globalImages->BindNull();
|
|
||||||
|
|
||||||
depthReadback = R_StaticAlloc( glConfig.vidWidth * glConfig.vidHeight*4 );
|
if ( !r_skipDepthCapture.GetBool() ) {
|
||||||
memset( depthReadback, 0, glConfig.vidWidth * glConfig.vidHeight*4 );
|
globalImages->currentDepthImage->Bind();
|
||||||
|
|
||||||
qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_DEPTH_COMPONENT , GL_FLOAT, depthReadback );
|
const float x=0, y=0, w=1, h=1;
|
||||||
|
// debug values:
|
||||||
|
//const float x = 0.1, y = 0.1, w = 0.8, h = 0.8;
|
||||||
|
//qglColor4f( 0.0f, 0.0f, 0.5f, 1.0f );
|
||||||
|
|
||||||
|
const float tx=0, ty=0;
|
||||||
|
// the actual texturesize of currentDepthImage is the next bigger power of two (POT),
|
||||||
|
// so the normalized width/height of the part of it we actually wanna show is the following
|
||||||
|
const float tw = float(glConfig.vidWidth) / float(globalImages->currentDepthImage->uploadWidth);
|
||||||
|
const float th = float(glConfig.vidHeight) / float(globalImages->currentDepthImage->uploadHeight);
|
||||||
|
|
||||||
for ( int i = 0 ; i < glConfig.vidWidth * glConfig.vidHeight ; i++ ) {
|
qglBegin( GL_QUADS );
|
||||||
float& px = ((float *)depthReadback)[i];
|
qglTexCoord2f(tx, ty);
|
||||||
float d = px;
|
qglVertex2f( x, y ); // ( 0,0 );
|
||||||
// the following calculation is based on how the TDM soft particle shader translates the depth value to doom units
|
|
||||||
|
|
||||||
// 0.9995 is practically infinite distance, clamping to 0.9994 clamps to max 30k doom units,
|
qglTexCoord2f(tx, ty+th);
|
||||||
// which is more than enough (and prevents a potential division by 0 below)
|
qglVertex2f( x, y+h ); // ( 0,1 );
|
||||||
d = (d < 0.9994f) ? d : 0.9994f;
|
|
||||||
|
|
||||||
d = d - 0.9995f; // d is now negative, between -0.0001 and -0.9995
|
qglTexCoord2f(tx+tw, ty+th);
|
||||||
d = 1.0f / d;
|
qglVertex2f( x+w, y+h ); // ( 1,1 );
|
||||||
// d *= -3.0f; // this would translate d to distance in doom units, doing it together with the next step
|
|
||||||
|
|
||||||
d *= (-3.0f / 3000.0f); // now 3000 units is 1.0, i.e. completely white (=> more details for closer distances)
|
qglTexCoord2f(tx+tw, ty);
|
||||||
px = d;
|
qglVertex2f( x+w, y ); // ( 1,0 );
|
||||||
|
qglEnd();
|
||||||
|
|
||||||
|
// TODO: probably a shader transforming this to something viewable
|
||||||
|
|
||||||
|
qglPopMatrix();
|
||||||
|
qglMatrixMode( GL_MODELVIEW );
|
||||||
|
qglPopMatrix();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
qglPopMatrix();
|
||||||
|
qglMatrixMode( GL_MODELVIEW );
|
||||||
|
qglPopMatrix();
|
||||||
|
globalImages->BindNull();
|
||||||
|
|
||||||
|
void* depthReadback = R_StaticAlloc( glConfig.vidWidth * glConfig.vidHeight*4 );
|
||||||
|
memset( depthReadback, 0, glConfig.vidWidth * glConfig.vidHeight*4 );
|
||||||
|
|
||||||
|
qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_DEPTH_COMPONENT , GL_FLOAT, depthReadback );
|
||||||
|
#if 0 // the following looks better, but is different from the !r_skipDepthCapture.GetBool() case above
|
||||||
|
// (which draws the captured depth buffer unaltered, unless we add a shader)
|
||||||
|
for ( int i = 0, n=glConfig.vidWidth * glConfig.vidHeight; i < n ; i++ ) {
|
||||||
|
float& px = ((float *)depthReadback)[i];
|
||||||
|
float d = px;
|
||||||
|
// the following calculation is based on how the TDM soft particle shader translates the depth value to doom units
|
||||||
|
|
||||||
|
// 0.9995 is practically infinite distance, clamping to 0.9994 clamps to max 30k doom units,
|
||||||
|
// which is more than enough (and prevents a potential division by 0 below)
|
||||||
|
d = (d < 0.9994f) ? d : 0.9994f;
|
||||||
|
|
||||||
|
d = d - 0.9995f; // d is now negative, between -0.0001 and -0.9995
|
||||||
|
d = 1.0f / d;
|
||||||
|
// d *= -3.0f; // this would translate d to distance in doom units, doing it together with the next step
|
||||||
|
|
||||||
|
d *= (-3.0f / 3000.0f); // now 3000 units is 1.0, i.e. completely white (=> more details for closer distances)
|
||||||
|
px = d;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
qglDrawPixels( glConfig.vidWidth, glConfig.vidHeight, GL_LUMINANCE, GL_FLOAT, depthReadback );
|
||||||
|
R_StaticFree( depthReadback );
|
||||||
}
|
}
|
||||||
|
|
||||||
qglDrawPixels( glConfig.vidWidth, glConfig.vidHeight, GL_LUMINANCE, GL_FLOAT, depthReadback );
|
|
||||||
R_StaticFree( depthReadback );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue