Skip to content

Commit 9161f78

Browse files
committed
Add r_materialSeparatePerShader to debug materials
This can reveal bugs caused by merging materials that are not really the same.
1 parent 2b80fa9 commit 9161f78

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/engine/renderer/Material.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,11 @@ void MaterialSystem::AddStage( MaterialSurface* surface, shaderStage_t* pStage,
11841184
return;
11851185
}
11861186

1187+
if ( r_materialSeparatePerShader.Get() )
1188+
{
1189+
continue;
1190+
}
1191+
11871192
if ( pStage->shaderBinder != pStage2->shaderBinder ) {
11881193
continue;
11891194
}

src/engine/renderer/Material.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4444

4545
static constexpr uint32_t MAX_DRAWCOMMAND_TEXTURES = 64;
4646

47+
extern Cvar::Cvar<bool> r_materialSeparatePerShader;
48+
4749
struct GLIndirectCommand {
4850
GLuint count;
4951
GLuint instanceCount;
@@ -155,6 +157,11 @@ struct Material {
155157
std::vector<Texture*> textures;
156158

157159
bool operator==( const Material& other ) {
160+
if ( r_materialSeparatePerShader.Get() )
161+
{
162+
return refStage == other.refStage;
163+
}
164+
158165
return program == other.program && stateBits == other.stateBits
159166
&& fog == other.fog && cullType == other.cullType && usePolygonOffset == other.usePolygonOffset;
160167
}

src/engine/renderer/tr_init.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9797
Cvar::Cvar<bool> r_gpuFrustumCulling( "r_gpuFrustumCulling", "Use frustum culling on the GPU for the Material System", Cvar::NONE, true );
9898
Cvar::Cvar<bool> r_gpuOcclusionCulling( "r_gpuOcclusionCulling", "Use occlusion culling on the GPU for the Material System", Cvar::NONE, false );
9999
Cvar::Cvar<bool> r_materialSystemSkip( "r_materialSystemSkip", "Temporarily skip Material System rendering, using only core renderer instead", Cvar::NONE, false );
100+
Cvar::Cvar<bool> r_materialSeparatePerShader("r_materialSeparatePerShader", "generate a material for every q3shader stage (to debug merging)", Cvar::NONE, false);
100101
cvar_t *r_lightStyles;
101102
cvar_t *r_exportTextures;
102103
cvar_t *r_heatHaze;
@@ -1269,7 +1270,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
12691270
r_showBspNodes = Cvar_Get( "r_showBspNodes", "0", CVAR_CHEAT );
12701271
Cvar::Latch( r_showGlobalMaterials );
12711272
Cvar::Latch( r_materialDebug );
1272-
1273+
Cvar::Latch( r_materialSeparatePerShader );
12731274
Cvar::Latch( r_profilerRenderSubGroups );
12741275
}
12751276

0 commit comments

Comments
 (0)