Skip to content

Commit 4d63f4d

Browse files
VReaperVillwieckz
authored andcommitted
Set vertex colour attr correctly with material system
1 parent 2e911d3 commit 4d63f4d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/engine/renderer/Material.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,12 @@ void ProcessMaterialGeneric3D( Material* material, shaderStage_t* pStage, drawSu
12721272
material->tcGen_Lightmap = pStage->tcGen_Lightmap;
12731273
material->deformIndex = pStage->deformIndex;
12741274

1275+
colorGen_t rgbGen = SetRgbGen( pStage );
1276+
alphaGen_t alphaGen = SetAlphaGen( pStage );
1277+
1278+
material->useAttrColor = rgbGen == colorGen_t::CGEN_VERTEX || rgbGen == colorGen_t::CGEN_ONE_MINUS_VERTEX
1279+
|| alphaGen == alphaGen_t::AGEN_VERTEX || alphaGen == alphaGen_t::AGEN_ONE_MINUS_VERTEX;
1280+
12751281
gl_generic3DShaderMaterial->SetTCGenEnvironment( pStage->tcGen_Environment );
12761282
gl_generic3DShaderMaterial->SetTCGenLightmap( pStage->tcGen_Lightmap );
12771283

@@ -1299,6 +1305,12 @@ void ProcessMaterialLightMapping( Material* material, shaderStage_t* pStage, dra
12991305

13001306
DAEMON_ASSERT( !( enableDeluxeMapping && enableGridDeluxeMapping ) );
13011307

1308+
colorGen_t rgbGen = SetRgbGen( pStage );
1309+
alphaGen_t alphaGen = SetAlphaGen( pStage );
1310+
1311+
material->useAttrColor = rgbGen == colorGen_t::CGEN_VERTEX || rgbGen == colorGen_t::CGEN_ONE_MINUS_VERTEX
1312+
|| alphaGen == alphaGen_t::AGEN_VERTEX || alphaGen == alphaGen_t::AGEN_ONE_MINUS_VERTEX;
1313+
13021314
material->enableDeluxeMapping = enableDeluxeMapping;
13031315
material->enableGridLighting = enableGridLighting;
13041316
material->enableGridDeluxeMapping = enableGridDeluxeMapping;
@@ -2142,6 +2154,12 @@ void MaterialSystem::RenderMaterial( Material& material, const uint32_t viewID )
21422154

21432155
backEnd.currentEntity = &tr.worldEntity;
21442156

2157+
if ( material.useAttrColor ) {
2158+
material.shader->AddVertexAttribBit( ATTR_COLOR );
2159+
} else {
2160+
material.shader->DelVertexAttribBit( ATTR_COLOR );
2161+
}
2162+
21452163
GL_State( stateBits );
21462164
if ( material.usePolygonOffset ) {
21472165
glEnable( GL_POLYGON_OFFSET_FILL );

src/engine/renderer/Material.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ struct Material {
108108
bool enableSpecularMapping;
109109
bool enablePhysicalMapping;
110110

111+
bool useAttrColor = false;
112+
111113
cullType_t cullType;
112114

113115
uint32_t sort;
@@ -126,7 +128,8 @@ struct Material {
126128

127129
bool operator==( const Material& other ) {
128130
return program == other.program && stateBits == other.stateBits && vbo == other.vbo && ibo == other.ibo
129-
&& fog == other.fog && cullType == other.cullType && usePolygonOffset == other.usePolygonOffset;
131+
&& fog == other.fog && cullType == other.cullType && usePolygonOffset == other.usePolygonOffset
132+
&& useAttrColor == other.useAttrColor;
130133
}
131134

132135
void AddTexture( Texture* texture ) {

0 commit comments

Comments
 (0)