PBR IBL
diff --git a/src/engine/GPURenderer/r_backend.cpp b/src/engine/GPURenderer/r_backend.cpp
index 981c655..2ac2101 100644
--- a/src/engine/GPURenderer/r_backend.cpp
+++ b/src/engine/GPURenderer/r_backend.cpp
@@ -942,25 +942,28 @@ const void* RB_StretchPic( const void* data )
RB_PrefilterEnvMap
=============
*/
-void RB_PrefilterEnvMap( sint numCubeMap )
+static const void* RB_PrefilterEnvMap( const void* data )
{
- cubemap_t* cubemap = &tr.cubemaps[backEnd.viewParms.targetFboCubemapIndex];
+ const convolveCubemapCommand_t* cmd = ( const convolveCubemapCommand_t* )data;
// finish any 2D drawing if needed
if( tess.numIndexes )
RB_EndSurface();
- if( !tr.world || tr.numCubemaps == 0 )
+ RB_SetGL2D();
+
+ cubemap_t* cubemap = &tr.cubemaps[cmd->cubemap];
+
+ if( !cubemap )
{
- // do nothing
- return;
+ return ( const void* )( cmd + 1 );
}
- sint cubeMipSize = r_cubemapSize->integer;
+ sint cubeMipSize = cubemap->image->width;
sint numMips = 0;
- sint width = r_cubemapSize->integer;
- sint height = r_cubemapSize->integer;
+ sint width = cubemap->image->width;
+ sint height = cubemap->image->height;
vec4_t quadVerts[4];
vec2_t texCoords[4];
@@ -984,11 +987,10 @@ void RB_PrefilterEnvMap( sint numCubeMap )
cubeMipSize >>= 1;
numMips++;
}
- numMips = MAX( 1, numMips - 4 );
+ numMips = MAX( 1, numMips - 2 );
FBO_Bind( tr.preFilterEnvMapFbo );
GL_BindToTMU( cubemap->image, TB_CUBEMAP );
- GL_State( GLS_DEPTHTEST_DISABLE );
GLSL_BindProgram( &tr.prefilterEnvMapShader );
@@ -996,27 +998,24 @@ void RB_PrefilterEnvMap( sint numCubeMap )
{
width = width / 2.0;
height = height / 2.0;
+
qglViewport( 0, 0, width, height );
qglScissor( 0, 0, width, height );
- for( sint j = 0; j < 6; j++ )
+
+ for( sint cubemapSide = 0; cubemapSide < 6; cubemapSide++ )
{
- //////////////////////////////////////////////////////////////////////////////////////////////
- {
- vec4_t viewInfo;
- VectorSet4( viewInfo, j, level, numMips, 0.0 );
- GLSL_SetUniformVec4( &tr.prefilterEnvMapShader, UNIFORM_VIEWINFO, viewInfo );
- }
- RB_InstantQuad2( quadVerts, texCoords ); //, color, shaderProgram, invTexRes);
- //////////////////////////////////////////////////////////////////////////////////////////////
- qglCopyTexSubImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, level, 0, 0, 0, 0, width, height );
+ vec4_t viewInfo;
+
+ VectorSet4( viewInfo, cubemapSide, level, numMips, 0.0 );
+ GLSL_SetUniformVec4( &tr.prefilterEnvMapShader, UNIFORM_VIEWINFO, viewInfo );
+ RB_InstantQuad2( quadVerts, texCoords );
+ qglCopyTexSubImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + cubemapSide, level, 0, 0, 0, 0, width, height );
}
}
- //cubemap->mipmapped++;
- qglActiveTexture( GL_TEXTURE0 );
+ //qglActiveTexture( GL_TEXTURE0 );
-
- return;
+ return ( const void* )( cmd + 1 );
}
@@ -1327,32 +1326,7 @@ const void* RB_DrawSurfs( const void* data )
FBO_Bind( nullptr );
GL_BindToTMU( cubemap->image, TB_CUBEMAP );
-
- // UGLY find a better way!
- if( cubemap->mipmapped < 10 )
- {
- if( r_pbr->integer == 0 || r_pbrIBL->integer == 0 )
- {
- qglGenerateMipmap( GL_TEXTURE_CUBE_MAP );
- cubemap->mipmapped++;
- }
- // else we mip-map elsewhere!
- else if( cubemap && cubemap->image )
- {
- qglGenerateTextureMipmapEXT( cubemap->image->texnum, GL_TEXTURE_CUBE_MAP );
- }
- }
- }
-
- if( r_pbr->integer && r_pbrIBL->integer )
- {
- cubemap_t* cubemap = &tr.cubemaps[backEnd.viewParms.targetFboCubemapIndex];
- // UGLY find a better way!
- if( cubemap && cubemap->mipmapped < 10 )
- {
- RB_PrefilterEnvMap( 0 );
- cubemap->mipmapped++;
- }
+ qglGenerateTextureMipmapEXT( cubemap->image->texnum, GL_TEXTURE_CUBE_MAP );
}
return ( const void* )( cmd + 1 );
@@ -2079,6 +2053,9 @@ void RB_ExecuteRenderCommands( const void* data )
case RC_CAPSHADOWMAP:
data = RB_CapShadowMap( data );
break;
+ case RC_CONVOLVECUBEMAP:
+ data = RB_PrefilterEnvMap( data );
+ break;
case RC_POSTPROCESS:
data = RB_PostProcess( data );
break;
diff --git a/src/engine/GPURenderer/r_bsp_tech3.cpp b/src/engine/GPURenderer/r_bsp_tech3.cpp
index 15e94e3..c335cae 100644
--- a/src/engine/GPURenderer/r_bsp_tech3.cpp
+++ b/src/engine/GPURenderer/r_bsp_tech3.cpp
@@ -2832,7 +2832,6 @@ void R_LoadCubemaps( void )
Com_sprintf( filename, MAX_QPATH, "cubemaps/%s/%03d.dds", tr.world->baseName, i );
cubemap->image = R_FindImageFile( filename, IMGTYPE_COLORALPHA, flags );
- cubemap->mipmapped = 0;
}
}
@@ -2854,7 +2853,6 @@ void R_RenderMissingCubemaps( void )
if( !tr.cubemaps[i].image )
{
tr.cubemaps[i].image = R_CreateImage( va( "*cubeMap%d", i ), nullptr, r_cubemapSize->integer, r_cubemapSize->integer, IMGTYPE_COLORALPHA, flags, cubemapFormat );
- tr.cubemaps[i].mipmapped = 0;
for( j = 0; j < 6; j++ )
{
@@ -2863,6 +2861,8 @@ void R_RenderMissingCubemaps( void )
R_IssuePendingRenderCommands();
R_InitNextFrame();
}
+
+ R_AddConvolveCubemapCmd( i );
}
}
}
diff --git a/src/engine/GPURenderer/r_cmds.cpp b/src/engine/GPURenderer/r_cmds.cpp
index 333984d..360c39d 100644
--- a/src/engine/GPURenderer/r_cmds.cpp
+++ b/src/engine/GPURenderer/r_cmds.cpp
@@ -274,6 +274,27 @@ void R_AddCapShadowmapCmd( sint map, sint cubeSide )
cmd->cubeSide = cubeSide;
}
+/*
+=============
+R_AddConvolveCubemapsCmd
+
+=============
+*/
+void R_AddConvolveCubemapCmd( sint cubemap )
+{
+ convolveCubemapCommand_t* cmd;
+
+ cmd = ( convolveCubemapCommand_t* )R_GetCommandBuffer( sizeof( *cmd ) );
+ if( !cmd )
+ {
+ return;
+ }
+ cmd->commandId = RC_CONVOLVECUBEMAP;
+
+ cmd->cubemap = cubemap;
+}
+
+
/*
=============
diff --git a/src/engine/GPURenderer/r_fbo.cpp b/src/engine/GPURenderer/r_fbo.cpp
index 86676f9..661cb49 100644
--- a/src/engine/GPURenderer/r_fbo.cpp
+++ b/src/engine/GPURenderer/r_fbo.cpp
@@ -455,7 +455,7 @@ void idRenderSystemLocal::FBOInit( void )
}
{
- for( sint i = 0; i < ARRAY_LEN( tr.glowImageScaled ); i++ )
+ for( i = 0; i < ARRAY_LEN( tr.glowImageScaled ); i++ )
{
tr.glowFboScaled[i] = FBO_Create( va( "*glowScaled%d", i ), tr.glowImageScaled[i]->width, tr.glowImageScaled[i]->height );
FBO_AttachImage( tr.glowFboScaled[i], tr.glowImageScaled[i], GL_COLOR_ATTACHMENT0, 0 );
@@ -463,7 +463,7 @@ void idRenderSystemLocal::FBOInit( void )
}
}
- if( ( r_pbr->integer == 1 ) && ( tr.renderCubeImage != nullptr ) )
+ if( tr.renderCubeImage != nullptr )
{
tr.preFilterEnvMapFbo = FBO_Create( "_preFilterEnvMapFbo", tr.renderCubeImage->width, tr.renderCubeImage->height );
FBO_AttachImage( tr.preFilterEnvMapFbo, tr.prefilterEnvMapImage, GL_COLOR_ATTACHMENT0, 0 );
diff --git a/src/engine/GPURenderer/r_glsl.cpp b/src/engine/GPURenderer/r_glsl.cpp
index e3a6b04..66dff51 100644
--- a/src/engine/GPURenderer/r_glsl.cpp
+++ b/src/engine/GPURenderer/r_glsl.cpp
[... diff too long, it was truncated ...]
GitHub
sha: 7b4e716a