Fixed bad lighting with objects behind the area light grid bounds

This commit is contained in:
Robert Beckebans 2021-04-27 19:14:55 +02:00
parent b96b085d04
commit 167085385b
3 changed files with 21 additions and 6 deletions

View file

@ -263,15 +263,19 @@ void main( PS_IN fragment, out PS_OUT result )
{
float v;
v = lightOrigin[i] * ( 1.0 / lightGridSize[i] );
// walls can be sampled behind the grid sometimes so avoid negative weights
v = max( 0, lightOrigin[i] * ( 1.0 / lightGridSize[i] ) );
gridCoord[i] = int( floor( v ) );
frac[ i ] = v - gridCoord[ i ];
/*
if( gridCoord[i] < 0 )
{
gridCoord[i] = 0;
}
else if( gridCoord[i] >= lightGridBounds[i] - 1 )
else
*/
if( gridCoord[i] >= lightGridBounds[i] - 1 )
{
gridCoord[i] = lightGridBounds[i] - 1;
}
@ -326,6 +330,9 @@ void main( PS_IN fragment, out PS_OUT result )
}
}
// build P
//float3 P = lightGridOrigin + ( gridCoord2[0] * gridStep[0] + gridCoord2[1] * gridStep[1] + gridCoord2[2] * gridStep[2] );
float2 atlasOffset;
atlasOffset.x = ( gridCoord2[0] * gridStep[0] + gridCoord2[2] * gridStep[1] ) * invXZ;

View file

@ -5546,15 +5546,19 @@ static const cgShaderDef_t cg_renderprogs[] =
" {\n"
" float v;\n"
"\n"
" v = lightOrigin[i] * ( 1.0 / lightGridSize[i] );\n"
" // walls can be sampled behind the grid sometimes so avoid negative weights\n"
" v = max( 0, lightOrigin[i] * ( 1.0 / lightGridSize[i] ) );\n"
" gridCoord[i] = int( floor( v ) );\n"
" frac[ i ] = v - gridCoord[ i ];\n"
"\n"
" /*\n"
" if( gridCoord[i] < 0 )\n"
" {\n"
" gridCoord[i] = 0;\n"
" }\n"
" else if( gridCoord[i] >= lightGridBounds[i] - 1 )\n"
" else\n"
" */\n"
" if( gridCoord[i] >= lightGridBounds[i] - 1 )\n"
" {\n"
" gridCoord[i] = lightGridBounds[i] - 1;\n"
" }\n"
@ -5609,6 +5613,9 @@ static const cgShaderDef_t cg_renderprogs[] =
" }\n"
" }\n"
"\n"
" // build P\n"
" //float3 P = lightGridOrigin + ( gridCoord2[0] * gridStep[0] + gridCoord2[1] * gridStep[1] + gridCoord2[2] * gridStep[2] );\n"
"\n"
" float2 atlasOffset;\n"
"\n"
" atlasOffset.x = ( gridCoord2[0] * gridStep[0] + gridCoord2[2] * gridStep[1] ) * invXZ;\n"

View file

@ -35,6 +35,7 @@ If you have questions concerning this license or the applicable additional terms
#define LGRID_FILE_EXT "lightgrid"
#define LGRID_BINARYFILE_EXT "blightgrid"
#define LGRID_FILEID "LGRID"
const byte LGRID_VERSION = 3;
#define STORE_LIGHTGRID_SHDATA 0
@ -604,9 +605,9 @@ bool idRenderWorldLocal::LoadLightGridFile( const char* name )
lightGridVersion = atoi( token );
}
if( lightGridVersion != BLGRID_VERSION )
if( lightGridVersion != LGRID_VERSION )
{
common->Warning( "%s has version %i instead of %i", fileName.c_str(), lightGridVersion, BLGRID_VERSION );
common->Warning( "%s has version %i instead of %i", fileName.c_str(), lightGridVersion, LGRID_VERSION );
delete src;
return false;
}