Skip to content

Commit

Permalink
Add r_cubeProbeSize
Browse files Browse the repository at this point in the history
Add a cvar to set static reflections cubemaps size.
  • Loading branch information
VReaperV committed Sep 19, 2024
1 parent 90e1611 commit 763ae70
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
50 changes: 28 additions & 22 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6507,7 +6507,6 @@ void R_BuildCubeMaps()
bool flipy;
int x, y, xy, xy2;

byte temp[ REF_CUBEMAP_SIZE * REF_CUBEMAP_SIZE * 4 ];
byte *dest;

int startTime, endTime;
Expand All @@ -6522,13 +6521,20 @@ void R_BuildCubeMaps()
return;
}

const int cubeMapSize = r_cubeProbeSize.Get();
if ( cubeMapSize > glConfig2.maxCubeMapTextureSize ) {
Log::Warn( "Cube probe size exceeds max cubemap texture size (%i/%i)", cubeMapSize, glConfig2.maxCubeMapTextureSize );
return;
}

startTime = ri.Milliseconds();

refdef_t rf{};

byte* temp = ( byte* ) Z_Malloc( cubeMapSize * cubeMapSize * 4 );
for ( i = 0; i < 6; i++ )
{
tr.cubeTemp[ i ] = (byte*) Z_Malloc( REF_CUBEMAP_SIZE * REF_CUBEMAP_SIZE * 4 );
tr.cubeTemp[ i ] = (byte*) Z_Malloc( cubeMapSize * cubeMapSize * 4 );
}

// calculate origins for our probes
Expand Down Expand Up @@ -6625,8 +6631,8 @@ void R_BuildCubeMaps()
rf.fov_y = 90;
rf.x = 0;
rf.y = 0;
rf.width = REF_CUBEMAP_SIZE;
rf.height = REF_CUBEMAP_SIZE;
rf.width = cubeMapSize;
rf.height = cubeMapSize;
rf.time = 0;

rf.gradingWeights[0] = 0.0;
Expand Down Expand Up @@ -6741,9 +6747,9 @@ void R_BuildCubeMaps()
}

tr.refdef.pixelTarget = tr.cubeTemp[ i ];
memset( tr.cubeTemp[ i ], 255, REF_CUBEMAP_SIZE * REF_CUBEMAP_SIZE * 4 );
tr.refdef.pixelTargetWidth = REF_CUBEMAP_SIZE;
tr.refdef.pixelTargetHeight = REF_CUBEMAP_SIZE;
memset( tr.cubeTemp[ i ], 255, cubeMapSize * cubeMapSize * 4 );
tr.refdef.pixelTargetWidth = cubeMapSize;
tr.refdef.pixelTargetHeight = cubeMapSize;

if ( glConfig2.materialSystemAvailable ) {
tr.refdef.pixelTarget = nullptr;
Expand All @@ -6762,14 +6768,14 @@ void R_BuildCubeMaps()
if ( flipx )
{
dest = tr.cubeTemp[ i ];
memcpy( temp, dest, REF_CUBEMAP_SIZE * REF_CUBEMAP_SIZE * 4 );
memcpy( temp, dest, cubeMapSize * cubeMapSize * 4 );

for ( y = 0; y < REF_CUBEMAP_SIZE; y++ )
for ( y = 0; y < cubeMapSize; y++ )
{
for ( x = 0; x < REF_CUBEMAP_SIZE; x++ )
for ( x = 0; x < cubeMapSize; x++ )
{
xy = ( ( y * REF_CUBEMAP_SIZE ) + x ) * 4;
xy2 = ( ( y * REF_CUBEMAP_SIZE ) + ( ( REF_CUBEMAP_SIZE - 1 ) - x ) ) * 4;
xy = ( ( y * cubeMapSize ) + x ) * 4;
xy2 = ( ( y * cubeMapSize ) + ( ( cubeMapSize - 1 ) - x ) ) * 4;
dest[ xy2 + 0 ] = temp[ xy + 0 ];
dest[ xy2 + 1 ] = temp[ xy + 1 ];
dest[ xy2 + 2 ] = temp[ xy + 2 ];
Expand All @@ -6781,14 +6787,14 @@ void R_BuildCubeMaps()
if ( flipy )
{
dest = tr.cubeTemp[ i ];
memcpy( temp, dest, REF_CUBEMAP_SIZE * REF_CUBEMAP_SIZE * 4 );
memcpy( temp, dest, cubeMapSize * cubeMapSize * 4 );

for ( y = 0; y < REF_CUBEMAP_SIZE; y++ )
for ( y = 0; y < cubeMapSize; y++ )
{
for ( x = 0; x < REF_CUBEMAP_SIZE; x++ )
for ( x = 0; x < cubeMapSize; x++ )
{
xy = ( ( y * REF_CUBEMAP_SIZE ) + x ) * 4;
xy2 = ( ( ( ( REF_CUBEMAP_SIZE - 1 ) - y ) * REF_CUBEMAP_SIZE ) + x ) * 4;
xy = ( ( y * cubeMapSize ) + x ) * 4;
xy2 = ( ( ( ( cubeMapSize - 1 ) - y ) * cubeMapSize ) + x ) * 4;
dest[ xy2 + 0 ] = temp[ xy + 0 ];
dest[ xy2 + 1 ] = temp[ xy + 1 ];
dest[ xy2 + 2 ] = temp[ xy + 2 ];
Expand All @@ -6802,11 +6808,11 @@ void R_BuildCubeMaps()

dest = tr.cubeTemp[ i ];

for ( y = 0; y < REF_CUBEMAP_SIZE; y++ )
for ( y = 0; y < cubeMapSize; y++ )
{
for ( x = 0; x < REF_CUBEMAP_SIZE; x++ )
for ( x = 0; x < cubeMapSize; x++ )
{
xy = ( ( y * REF_CUBEMAP_SIZE ) + x ) * 4;
xy = ( ( y * cubeMapSize ) + x ) * 4;

r = dest[ xy + 0 ];
g = dest[ xy + 1 ];
Expand Down Expand Up @@ -6840,8 +6846,8 @@ void R_BuildCubeMaps()

cubeProbe->cubemap->type = GL_TEXTURE_CUBE_MAP;

cubeProbe->cubemap->width = REF_CUBEMAP_SIZE;
cubeProbe->cubemap->height = REF_CUBEMAP_SIZE;
cubeProbe->cubemap->width = cubeMapSize;
cubeProbe->cubemap->height = cubeMapSize;

cubeProbe->cubemap->bits = IF_NOPICMIP;
cubeProbe->cubemap->filterType = filterType_t::FT_LINEAR;
Expand Down
3 changes: 3 additions & 0 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cvar_t *r_reliefMapping;
cvar_t *r_glowMapping;
cvar_t *r_reflectionMapping;
Cvar::Range<Cvar::Cvar<int>> r_cubeProbeSize( "r_cubeProbeSize", "Size of the static reflections cubemaps", Cvar::NONE,
32, 1, 32768 );

cvar_t *r_halfLambertLighting;
cvar_t *r_rimLighting;
Expand Down Expand Up @@ -1220,6 +1222,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
r_reliefMapping = Cvar_Get( "r_reliefMapping", "0", CVAR_LATCH | CVAR_ARCHIVE );
r_glowMapping = Cvar_Get( "r_glowMapping", "1", CVAR_LATCH );
r_reflectionMapping = Cvar_Get( "r_reflectionMapping", "0", CVAR_LATCH | CVAR_ARCHIVE );
Cvar::Latch( r_cubeProbeSize );

r_halfLambertLighting = Cvar_Get( "r_halfLambertLighting", "1", CVAR_LATCH | CVAR_ARCHIVE );
r_rimLighting = Cvar_Get( "r_rimLighting", "0", CVAR_LATCH | CVAR_ARCHIVE );
Expand Down
6 changes: 4 additions & 2 deletions src/engine/renderer/tr_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,16 @@ void RE_RenderScene( const refdef_t *fd )
const int faceID = globalID % 6;
showCubeProbe = true;

const int cubeMapSize = r_cubeProbeSize.Get();

VectorCopy( tr.cubeProbes[probeID]->origin, refdef.vieworg );

refdef.fov_x = 90;
refdef.fov_y = 90;
refdef.x = 0;
refdef.y = 0;
refdef.width = REF_CUBEMAP_SIZE;
refdef.height = REF_CUBEMAP_SIZE;
refdef.width = cubeMapSize;
refdef.height = cubeMapSize;
refdef.time = fd->time;
VectorCopy( fd->gradingWeights, refdef.gradingWeights );

Expand Down

0 comments on commit 763ae70

Please sign in to comment.