mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 22:50:45 +00:00
Move light grid sampling origins around if in solid like q3map1 did
This commit is contained in:
parent
b0238772a8
commit
5c03286448
5 changed files with 114 additions and 21 deletions
|
@ -263,7 +263,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
{
|
||||
float v;
|
||||
|
||||
v = lightOrigin[i] * ( 1.0f / lightGridSize[i] );
|
||||
v = lightOrigin[i] * ( 1.0 / lightGridSize[i] );
|
||||
gridCoord[i] = int( floor( v ) );
|
||||
frac[ i ] = v - gridCoord[ i ];
|
||||
|
||||
|
@ -314,7 +314,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
|
||||
for( int j = 0; j < 3; j++ )
|
||||
{
|
||||
if( cornerOffsets[ i ][ j ] > 0.0f )
|
||||
if( cornerOffsets[ i ][ j ] > 0.0 )
|
||||
{
|
||||
factor *= frac[ j ];
|
||||
|
||||
|
@ -322,7 +322,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
}
|
||||
else
|
||||
{
|
||||
factor *= ( 1.0f - frac[ j ] );
|
||||
factor *= ( 1.0 - frac[ j ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,14 +331,21 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
atlasOffset.x = ( gridCoord2[0] * gridStep[0] + gridCoord2[2] * gridStep[1] ) * invXZ;
|
||||
atlasOffset.y = ( gridCoord2[1] * invY );
|
||||
|
||||
irradiance += tex2D( samp7, normalizedOctCoordZeroOne + atlasOffset ).rgb * factor;
|
||||
float3 color = tex2D( samp7, normalizedOctCoordZeroOne + atlasOffset ).rgb;
|
||||
|
||||
if( ( color.r + color.g + color.b ) < 0.0001 )
|
||||
{
|
||||
// ignore samples in walls
|
||||
continue;
|
||||
}
|
||||
|
||||
irradiance += color * factor;
|
||||
totalFactor += factor;
|
||||
}
|
||||
|
||||
if( totalFactor > 0.0 && totalFactor < 0.9999 )
|
||||
{
|
||||
totalFactor = 1.0f / totalFactor;
|
||||
totalFactor = 1.0 / totalFactor;
|
||||
|
||||
irradiance *= totalFactor;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2014-2016 Robert Beckebans
|
||||
Copyright (C) 2014-2021 Robert Beckebans
|
||||
Copyright (C) 2014-2016 Kot in Action Creative Artel
|
||||
Copyright (C) 2016-2017 Dustin Land
|
||||
|
||||
|
@ -1809,7 +1809,7 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
}
|
||||
|
||||
const int numColors = 7;
|
||||
static idVec4 colors[numColors] = { colorBlack, colorBlue, colorCyan, colorGreen, colorYellow, colorRed, colorWhite };
|
||||
static idVec4 colors[numColors] = { colorBrown, colorBlue, colorCyan, colorGreen, colorYellow, colorRed, colorWhite };
|
||||
|
||||
for( int a = 0; a < tr.primaryWorld->NumAreas(); a++ )
|
||||
{
|
||||
|
@ -1832,7 +1832,7 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
for( int i = 0; i < area->lightGrid.lightGridPoints.Num(); i++ )
|
||||
{
|
||||
lightGridPoint_t* gridPoint = &area->lightGrid.lightGridPoints[i];
|
||||
if( !gridPoint->valid )
|
||||
if( !gridPoint->valid && r_showLightGrid.GetInteger() < 3 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -1893,7 +1893,16 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
{
|
||||
renderProgManager.BindShader_Color();
|
||||
|
||||
idVec4 color = colors[ a % numColors ];
|
||||
idVec4 color;
|
||||
if( !gridPoint->valid )
|
||||
{
|
||||
color = colorPurple;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = colors[ a % numColors ];
|
||||
}
|
||||
|
||||
GL_Color( color );
|
||||
}
|
||||
else
|
||||
|
|
|
@ -518,7 +518,7 @@ static const int LIGHTGRID_IRRADIANCE_SIZE = 32;
|
|||
struct calcLightGridPointParms_t
|
||||
{
|
||||
// input
|
||||
byte* buffers[6]; // HDR RGB16F standard OpenGL cubemap sides
|
||||
byte* radiance[6]; // HDR RGB16F standard OpenGL cubemap sides
|
||||
int gridCoord[3];
|
||||
|
||||
int outWidth; // LIGHTGRID_IRRADIANCE_SIZE
|
||||
|
|
|
@ -5500,7 +5500,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" {\n"
|
||||
" float v;\n"
|
||||
"\n"
|
||||
" v = lightOrigin[i] * ( 1.0f / lightGridSize[i] );\n"
|
||||
" v = lightOrigin[i] * ( 1.0 / lightGridSize[i] );\n"
|
||||
" gridCoord[i] = int( floor( v ) );\n"
|
||||
" frac[ i ] = v - gridCoord[ i ];\n"
|
||||
"\n"
|
||||
|
@ -5551,7 +5551,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
" for( int j = 0; j < 3; j++ )\n"
|
||||
" {\n"
|
||||
" if( cornerOffsets[ i ][ j ] > 0.0f )\n"
|
||||
" if( cornerOffsets[ i ][ j ] > 0.0 )\n"
|
||||
" {\n"
|
||||
" factor *= frac[ j ];\n"
|
||||
"\n"
|
||||
|
@ -5559,7 +5559,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" factor *= ( 1.0f - frac[ j ] );\n"
|
||||
" factor *= ( 1.0 - frac[ j ] );\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
|
@ -5568,14 +5568,21 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" atlasOffset.x = ( gridCoord2[0] * gridStep[0] + gridCoord2[2] * gridStep[1] ) * invXZ;\n"
|
||||
" atlasOffset.y = ( gridCoord2[1] * invY );\n"
|
||||
"\n"
|
||||
" irradiance += tex2D( samp7, normalizedOctCoordZeroOne + atlasOffset ).rgb * factor;\n"
|
||||
" float3 color = tex2D( samp7, normalizedOctCoordZeroOne + atlasOffset ).rgb;\n"
|
||||
"\n"
|
||||
" if( ( color.r + color.g + color.b ) < 0.0001 )\n"
|
||||
" {\n"
|
||||
" // ignore samples in walls\n"
|
||||
" continue;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" irradiance += color * factor;\n"
|
||||
" totalFactor += factor;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" if( totalFactor > 0.0 && totalFactor < 0.9999 )\n"
|
||||
" {\n"
|
||||
" totalFactor = 1.0f / totalFactor;\n"
|
||||
" totalFactor = 1.0 / totalFactor;\n"
|
||||
"\n"
|
||||
" irradiance *= totalFactor;\n"
|
||||
" }\n"
|
||||
|
|
|
@ -32,7 +32,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
|
||||
#include "RenderCommon.h"
|
||||
|
||||
static const int MAX_LIGHTGRID_ATLAS_SIZE = 4096;
|
||||
static const int MAX_LIGHTGRID_ATLAS_SIZE = 1024;
|
||||
static const int MAX_AREA_LIGHTGRID_POINTS = ( MAX_LIGHTGRID_ATLAS_SIZE / LIGHTGRID_IRRADIANCE_SIZE ) * ( MAX_LIGHTGRID_ATLAS_SIZE / LIGHTGRID_IRRADIANCE_SIZE );
|
||||
|
||||
LightGrid::LightGrid()
|
||||
|
@ -266,7 +266,77 @@ void LightGrid::CalculateLightGridPointPositions( const idRenderWorld* world, in
|
|||
gridPoint->valid = ( world->PointInArea( gridPoint->origin ) != -1 );
|
||||
if( !gridPoint->valid )
|
||||
{
|
||||
invalidCount++;
|
||||
idVec3 origin;
|
||||
idVec3 baseOrigin;
|
||||
int step;
|
||||
|
||||
baseOrigin = gridPoint->origin;
|
||||
|
||||
// RB: do what q3map1 did - try to nudge the origin around to find a valid point
|
||||
for( step = 9; step <= 18; step += 9 )
|
||||
{
|
||||
for( int c = 0; c < 8; c++ )
|
||||
{
|
||||
origin = baseOrigin;
|
||||
if( c & 1 )
|
||||
{
|
||||
origin[0] += step;
|
||||
}
|
||||
else
|
||||
{
|
||||
origin[0] -= step;
|
||||
}
|
||||
if( c & 2 )
|
||||
{
|
||||
origin[1] += step;
|
||||
}
|
||||
else
|
||||
{
|
||||
origin[1] -= step;
|
||||
}
|
||||
if( c & 4 )
|
||||
{
|
||||
origin[2] += step;
|
||||
}
|
||||
else
|
||||
{
|
||||
origin[2] -= step;
|
||||
}
|
||||
|
||||
if( world->PointInArea( origin ) != -1 )
|
||||
{
|
||||
// point is not in the void
|
||||
gridPoint->valid = true;
|
||||
gridPoint->origin = origin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( i != 8 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if( step > 18 )
|
||||
{
|
||||
// can't find a valid point at all
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
gridPoint->ambient[i] = 0;
|
||||
gridPoint->directed[i] = 0;
|
||||
}
|
||||
gridPoint->latLong[0] = 0;
|
||||
gridPoint->latLong[1] = 0;
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
if( !gridPoint->valid )
|
||||
{
|
||||
invalidCount++;
|
||||
}
|
||||
}
|
||||
|
||||
p++;
|
||||
|
@ -369,7 +439,7 @@ void CalculateLightGridPointJob( calcLightGridPointParms_t* parms )
|
|||
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
buffers[ i ] = ( halfFloat_t* ) parms->buffers[ i ];
|
||||
buffers[ i ] = ( halfFloat_t* ) parms->radiance[ i ];
|
||||
}
|
||||
|
||||
const float invDstSize = 1.0f / float( parms->outHeight );
|
||||
|
@ -760,7 +830,7 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL )
|
|||
//tr.TakeScreenshot( size, size, fullname, blends, &ref, EXR );
|
||||
byte* float16FRGB = tr.CaptureRenderToBuffer( captureSize, captureSize, &ref );
|
||||
|
||||
jobParms->buffers[ side ] = float16FRGB;
|
||||
jobParms->radiance[ side ] = float16FRGB;
|
||||
|
||||
#if 0
|
||||
if( i < 3 )
|
||||
|
@ -859,9 +929,9 @@ CONSOLE_COMMAND( bakeLightGrids, "Bake irradiance/vis light grid data", NULL )
|
|||
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
if( job->buffers[i] )
|
||||
if( job->radiance[i] )
|
||||
{
|
||||
Mem_Free( job->buffers[i] );
|
||||
Mem_Free( job->radiance[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue