Skip to content

Commit

Permalink
Merge branch 'reactionmerge'
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileTheory committed Feb 5, 2013
2 parents 80b0792 + 9bace5b commit 649f0c3
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 226 deletions.
133 changes: 44 additions & 89 deletions code/rend2/tr_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ void GL_BindToTMU( image_t *image, int tmu )
** GL_Cull
*/
void GL_Cull( int cullType ) {
#ifdef REACTION
// Makro - flip culling if needed
qboolean flip = (backEnd.currentEntity != NULL && backEnd.currentEntity->mirrored != qfalse && cullType != CT_TWO_SIDED);
cullType ^= flip; // this assumes CT_BACK_SIDED and CT_FRONT_SIDED are 0 or 1
#endif

if ( glState.faceCulling == cullType ) {
return;
}
Expand All @@ -176,6 +170,11 @@ void GL_Cull( int cullType ) {
cullFront = !cullFront;
}

if ( backEnd.currentEntity && backEnd.currentEntity->mirrored )
{
cullFront = !cullFront;
}

qglCullFace( cullFront ? GL_FRONT : GL_BACK );
}
}
Expand Down Expand Up @@ -548,10 +547,6 @@ void RB_BeginDrawingView (void) {
// we will only draw a sun if there was sky rendered in this view
backEnd.skyRenderedThisView = qfalse;

#ifdef REACTION
backEnd.viewHasSunFlare = qfalse;
#endif

// clip to the plane of the portal
if ( backEnd.viewParms.isPortal ) {
#if 0
Expand Down Expand Up @@ -594,9 +589,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
FBO_t* fbo = NULL;
qboolean inQuery = qfalse;

#if 1 //def REACTION
float depth[2];
#endif


// save original time for entity shader offsets
Expand All @@ -616,10 +609,8 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
oldSort = -1;
depthRange = qfalse;

#if 1 //def REACTION
depth[0] = 0.f;
depth[1] = 1.f;
#endif

backEnd.pc.c_surfaces += numDrawSurfs;

Expand Down Expand Up @@ -662,22 +653,6 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
qboolean sunflare = qfalse;
depthRange = isCrosshair = qfalse;

#ifdef REACTION
// if we were rendering to a FBO and the previous entity was a sunflare
// and the current one isn't, switch back to the main fbo
if (oldEntityNum != -1 && fbo && !backEnd.depthFill &&
RF_SUNFLARE == (backEnd.refdef.entities[oldEntityNum].e.renderfx & RF_SUNFLARE) &&
0 == (backEnd.refdef.entities[entityNum].e.renderfx & RF_SUNFLARE))
{
if (inQuery) {
inQuery = qfalse;
qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
}
FBO_Bind(fbo);
qglDepthRange(depth[0], depth[1]);
}
#endif

if ( entityNum != REFENTITYNUM_WORLD ) {
backEnd.currentEntity = &backEnd.refdef.entities[entityNum];
backEnd.refdef.floatTime = originalTime - backEnd.currentEntity->e.shaderTime;
Expand All @@ -693,31 +668,6 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
R_TransformDlights( backEnd.refdef.num_dlights, backEnd.refdef.dlights, &backEnd.or );
}

#ifdef REACTION
// if the current entity is a sunflare
if(backEnd.currentEntity->e.renderfx & RF_SUNFLARE && !backEnd.depthFill) {
// if we're rendering to a fbo
if (fbo) {
VectorCopy(backEnd.currentEntity->e.origin, backEnd.sunFlarePos);
// switch FBO
FBO_Bind(tr.godRaysFbo);

qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
qglClear( GL_COLOR_BUFFER_BIT );

qglDepthRange(1.f, 1.f);
if (glRefConfig.occlusionQuery && !inQuery && !backEnd.viewHasSunFlare) {
inQuery = qtrue;
tr.sunFlareQueryActive[tr.sunFlareQueryIndex] = qtrue;
qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, tr.sunFlareQuery[tr.sunFlareQueryIndex]);
}
sunflare = qtrue;
} else {
depthRange = qtrue;
}
}
#endif

if(backEnd.currentEntity->e.renderfx & RF_DEPTHHACK)
{
// hack the depth range to prevent view model from poking into walls
Expand Down Expand Up @@ -766,14 +716,12 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
}
}

#if 1 //def REACTION
if(!oldDepthRange)
{
depth[0] = 0;
depth[1] = 0.3f;
qglDepthRange (depth[0], depth[1]);
}
#endif
}
else
{
Expand All @@ -784,10 +732,9 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {

if (!sunflare)
qglDepthRange (0, 1);
#if 1 //def REACTION

depth[0] = 0;
depth[1] = 1;
#endif
}

oldDepthRange = depthRange;
Expand All @@ -812,26 +759,15 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
inQuery = qfalse;
qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
}
#ifdef REACTION
// HACK: flip Z and render black to god rays buffer
if (backEnd.frameHasSunFlare && !backEnd.depthFill)
{
vec4_t black;
VectorSet4(black, 0, 0, 0, 1);
qglDepthRange (1, 1);
FBO_BlitFromTexture(tr.whiteImage, NULL, NULL, tr.godRaysFbo, NULL, NULL, black, GLS_DEPTHFUNC_GREATER);
}
#endif

if (glRefConfig.framebufferObject)
FBO_Bind(fbo);

// go back to the world modelview matrix

GL_SetModelviewMatrix( backEnd.viewParms.world.modelMatrix );
//if ( depthRange ) {
qglDepthRange (0, 1);
//}

qglDepthRange (0, 1);
}


Expand Down Expand Up @@ -1420,9 +1356,35 @@ const void *RB_DrawSurfs( const void *data ) {
{
RB_RenderDrawSurfList( cmd->drawSurfs, cmd->numDrawSurfs );

#if 0
RB_DrawSun();
#endif
if (r_drawSun->integer)
{
RB_DrawSun(0.1, tr.sunShader);
}

if (r_drawSunRays->integer)
{
FBO_t *oldFbo = glState.currentFBO;
FBO_Bind(tr.sunRaysFbo);

qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
qglClear( GL_COLOR_BUFFER_BIT );

if (glRefConfig.occlusionQuery)
{
tr.sunFlareQueryActive[tr.sunFlareQueryIndex] = qtrue;
qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, tr.sunFlareQuery[tr.sunFlareQueryIndex]);
}

RB_DrawSun(0.3, tr.sunFlareShader);

if (glRefConfig.occlusionQuery)
{
qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
}

FBO_Bind(oldFbo);
}

// darken down any stencil shadows
RB_ShadowFinish();

Expand Down Expand Up @@ -1672,9 +1634,6 @@ const void *RB_SwapBuffers( const void *data ) {

backEnd.framePostProcessed = qfalse;
backEnd.projection2D = qfalse;
#ifdef REACTION
backEnd.frameHasSunFlare = qfalse;
#endif

return (const void *)(cmd + 1);
}
Expand Down Expand Up @@ -1764,17 +1723,13 @@ const void *RB_PostProcess(const void *data)
}
}

#ifdef REACTION
if (1)
{
RB_GodRays();
if (r_drawSunRays->integer)
RB_SunRays();

if (1)
RB_BokehBlur(backEnd.refdef.blurFactor);
else
RB_GaussianBlur(backEnd.refdef.blurFactor);
}
#endif
if (1)
RB_BokehBlur(backEnd.refdef.blurFactor);
else
RB_GaussianBlur(backEnd.refdef.blurFactor);

if (0)
{
Expand All @@ -1800,7 +1755,7 @@ const void *RB_PostProcess(const void *data)
{
vec4i_t dstBox;
VectorSet4(dstBox, 256, glConfig.vidHeight - 256, 256, 256);
FBO_BlitFromTexture(tr.renderImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
FBO_BlitFromTexture(tr.sunRaysImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
}

backEnd.framePostProcessed = qtrue;
Expand Down
13 changes: 5 additions & 8 deletions code/rend2/tr_fbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,17 @@ void FBO_Init(void)
FBO_Bind(NULL);
}

#ifdef REACTION
if (r_drawSunRays->integer)
{
tr.godRaysFbo = FBO_Create("_godRays", tr.renderDepthImage->width, tr.renderDepthImage->height);
FBO_Bind(tr.godRaysFbo);
tr.sunRaysFbo = FBO_Create("_sunRays", tr.renderDepthImage->width, tr.renderDepthImage->height);
FBO_Bind(tr.sunRaysFbo);

//FBO_CreateBuffer(tr.godRaysFbo, GL_RGBA8, 0, multisample);
FBO_AttachTextureImage(tr.godRaysImage, 0);
FBO_AttachTextureImage(tr.sunRaysImage, 0);

//FBO_CreateBuffer(tr.godRaysFbo, GL_DEPTH_COMPONENT24_ARB, 0, multisample);
R_AttachFBOTextureDepth(tr.renderDepthImage->texnum);

R_CheckFBO(tr.godRaysFbo);
R_CheckFBO(tr.sunRaysFbo);
}
#endif

// FIXME: Don't use separate color/depth buffers for a shadow buffer
for( i = 0; i < MAX_DRAWN_PSHADOWS; i++)
Expand Down
6 changes: 3 additions & 3 deletions code/rend2/tr_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -2959,9 +2959,9 @@ void R_CreateBuiltinImages( void ) {
hdrFormat = GL_RGB16F_ARB;

tr.renderImage = R_CreateImage("_render", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, hdrFormat);
#ifdef REACTION
tr.godRaysImage = R_CreateImage("*godRays", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
#endif

if (r_drawSunRays->integer)
tr.sunRaysImage = R_CreateImage("*sunRays", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);

if (r_softOverbright->integer)
{
Expand Down
13 changes: 7 additions & 6 deletions code/rend2/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ cvar_t *r_forceSun;
cvar_t *r_forceSunMapLightScale;
cvar_t *r_forceSunLightScale;
cvar_t *r_forceSunAmbientScale;
cvar_t *r_drawSunRays;
cvar_t *r_sunShadows;
cvar_t *r_shadowFilter;
cvar_t *r_shadowMapSize;
Expand Down Expand Up @@ -1179,6 +1180,8 @@ void R_Register( void )
r_forceSunMapLightScale = ri.Cvar_Get( "r_forceSunMapLightScale", "0.5", CVAR_CHEAT );
r_forceSunLightScale = ri.Cvar_Get( "r_forceSunLightScale", "0.5", CVAR_CHEAT );
r_forceSunAmbientScale = ri.Cvar_Get( "r_forceSunAmbientScale", "0.2", CVAR_CHEAT );
r_drawSunRays = ri.Cvar_Get( "r_drawSunRays", "0", CVAR_ARCHIVE | CVAR_LATCH );

r_sunShadows = ri.Cvar_Get( "r_sunShadows", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowFilter = ri.Cvar_Get( "r_shadowFilter", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowMapSize = ri.Cvar_Get( "r_shadowMapSize", "1024", CVAR_ARCHIVE | CVAR_LATCH );
Expand Down Expand Up @@ -1300,19 +1303,17 @@ void R_InitQueries(void)
if (!glRefConfig.occlusionQuery)
return;

#ifdef REACTION
qglGenQueriesARB(ARRAY_LEN(tr.sunFlareQuery), tr.sunFlareQuery);
#endif
if (r_drawSunRays->integer)
qglGenQueriesARB(ARRAY_LEN(tr.sunFlareQuery), tr.sunFlareQuery);
}

void R_ShutDownQueries(void)
{
if (!glRefConfig.occlusionQuery)
return;

#ifdef REACTION
qglDeleteQueriesARB(ARRAY_LEN(tr.sunFlareQuery), tr.sunFlareQuery);
#endif
if (r_drawSunRays->integer)
qglDeleteQueriesARB(ARRAY_LEN(tr.sunFlareQuery), tr.sunFlareQuery);
}

/*
Expand Down
Loading

0 comments on commit 649f0c3

Please sign in to comment.