Skip to content

Commit 6b7a7dd

Browse files
committed
Do autosprite calcs with CPU, not GLSL
Get rid of vertexSprite_vp.glsl/USE_VERTEX_SPRITE and return to doing deformvertexes autosprite/autosprite2 vertex calculations on the CPU (like it was until 2015). This fixes various bugs with autosprite[2] BSP surfaces. Also it fixes some particle systems which were broken for unknown reasons. One problem with the vertex sprite GLSL is that it always applied depth fade, regardless of whether it was requested. Depth fade means the alpha will be reduced if there is something close behind the particle within a certain depth (judging by the z buffer). With autosprite1, this depth parameter was set equal to the size of the sprite. So it is like a cube-shaped cloud (which matters when part of the cloud is inside a wall). The shader-specified fade depth, if any, was ignored. With autosprite2, the shader used a negative depth parameter, which just breaks everything. By removing unwanted depth fade for BSP surfaces, this fixes #997 (non-opaque autosprite2 BSP surfaces do not show up, as seen with the various flames on KOsAD's metro map). Also depth fade will no longer be automatically applied to all particles. I believe we have just 3 Unvanquished shaders configured with depth fade: acid tube acid, booster effect, and grenade smoke. Any other particles could potentially look different due to removing depth fade. So we may need some asset changes to adjust to this change. Another issue is that USE_VERTEX_SPRITE was not available for lightmap shaders. This meant that vertex positions were out of sync between the generic and lightmap shaders, and the lightmap shader failed to render anything. So this commit fixes #1246 (wrong lighting for autosprite[2] BSP surfaces with lightmaps, as seen on map "defenxe") by calculating the final vertex positions before uploading them, which ensures they are the same for all GLSL shaders used. With this commit, some particles that were previously not visible are now rendered, for example: - ones with the gfx/players/alien_base/green_acid shader which are emitted upon evolving, or damaging or destroying an alien buildable - orange glowing "mark" (which is actually a particle) added at impact point of several weapons (rifle, shotgun...) I believe the problem with green_acid must have been that Tess_AddSprite oriented the triangles backward (CW instead of CCW or vice versa). And unlike most particle shaders, the acid one fails to specify double-sided culling, so it would disappear if oriented backward. The problem with the orange mark (and some other impact particles) is that it is positioned very close to the surface. The alpha more or less goes to zero when using depth fade, if you are looking from a direction close to the impact surface's normal. The impact mark particle was only visible from tangential angles. To implement CPU-side autosprite/autosprite2 transformations, I took the code from an old (~2015) version of the file. But I ended up completely writing the autosprite2 one. When autosprites were first implemented in GLSL, there was also a change in how the polygon is positioned: in the GLSL implementation it faces towards the viewer, rather than Tremulous' behavior to face opposite the view direction. I decided that the GLSL behavior is superior for autosprite2 and reimplemented the CPU version that way (but you can get the old behavior by setting the r_autosprite2Style cvar). For autosprite the old behavior seems good enough so it once again faces opposing the view direction. This commit makes autosprite2 surfaces work with material system enabled for the first time, by virtue of rendering them without using the material system.
1 parent 3f4477d commit 6b7a7dd

22 files changed

+258
-512
lines changed

src.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ set(GLSLSOURCELIST
159159
${ENGINE_DIR}/renderer/glsl_source/vertexAnimation_vp.glsl
160160
${ENGINE_DIR}/renderer/glsl_source/vertexSimple_vp.glsl
161161
${ENGINE_DIR}/renderer/glsl_source/vertexSkinning_vp.glsl
162-
${ENGINE_DIR}/renderer/glsl_source/vertexSprite_vp.glsl
163162
${ENGINE_DIR}/renderer/glsl_source/blurX_fp.glsl
164163
${ENGINE_DIR}/renderer/glsl_source/blurX_vp.glsl
165164
${ENGINE_DIR}/renderer/glsl_source/blurY_fp.glsl

src/engine/renderer/Material.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, Material& material, drawSu
247247
gl_genericShaderMaterial->SetUniform_ColorMapBindless( BindAnimatedImage( 0, &pStage->bundle[TB_COLORMAP] ) );
248248
}
249249

250-
bool needDepthMap = pStage->hasDepthFade || shader->autoSpriteMode;
250+
bool needDepthMap = pStage->hasDepthFade;
251251
if ( needDepthMap ) {
252252
gl_genericShaderMaterial->SetUniform_DepthMapBindless( GL_BindToTMU( 1, tr.currentDepthImage ) );
253253
}
254254

255-
bool hasDepthFade = pStage->hasDepthFade && !shader->autoSpriteMode;
255+
bool hasDepthFade = pStage->hasDepthFade;
256256
if ( hasDepthFade ) {
257257
gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue );
258258
}
@@ -959,7 +959,7 @@ void MaterialSystem::GenerateWorldCommandBuffer() {
959959
}
960960

961961
shader = shader->remappedShader ? shader->remappedShader : shader;
962-
if ( shader->isSky || shader->isPortal ) {
962+
if ( shader->isSky || shader->isPortal || shader->autoSpriteMode ) {
963963
continue;
964964
}
965965

@@ -1067,13 +1067,12 @@ void BindShaderGeneric3D( Material* material ) {
10671067
gl_genericShaderMaterial->SetTCGenEnvironment( material->tcGenEnvironment );
10681068
gl_genericShaderMaterial->SetTCGenLightmap( material->tcGen_Lightmap );
10691069
gl_genericShaderMaterial->SetDepthFade( material->hasDepthFade );
1070-
gl_genericShaderMaterial->SetVertexSprite( material->vertexSprite );
10711070

10721071
// Bind shader program.
10731072
gl_genericShaderMaterial->BindProgram( material->deformIndex );
10741073

10751074
// Set shader uniforms.
1076-
if ( material->tcGenEnvironment || material->vertexSprite ) {
1075+
if ( material->tcGenEnvironment ) {
10771076
gl_genericShaderMaterial->SetUniform_ViewOrigin( backEnd.orientation.viewOrigin );
10781077
gl_genericShaderMaterial->SetUniform_ViewUp( backEnd.orientation.axis[2] );
10791078
}
@@ -1146,17 +1145,11 @@ void BindShaderScreen( Material* material ) {
11461145
void BindShaderHeatHaze( Material* material ) {
11471146
// Select shader permutation.
11481147
gl_heatHazeShaderMaterial->SetVertexAnimation( material->vertexAnimation );
1149-
gl_heatHazeShaderMaterial->SetVertexSprite( material->vertexSprite );
11501148

11511149
// Bind shader program.
11521150
gl_heatHazeShaderMaterial->BindProgram( material->deformIndex );
11531151

11541152
// Set shader uniforms.
1155-
if ( material->vertexSprite ) {
1156-
gl_heatHazeShaderMaterial->SetUniform_ViewOrigin( backEnd.orientation.viewOrigin );
1157-
gl_heatHazeShaderMaterial->SetUniform_ViewUp( backEnd.orientation.axis[2] );
1158-
}
1159-
11601153
gl_heatHazeShaderMaterial->SetUniform_ModelMatrix( backEnd.orientation.transformMatrix );
11611154
gl_heatHazeShaderMaterial->SetUniform_ModelViewProjectionMatrix( glState.modelViewProjectionMatrix[glState.stackIndex] );
11621155
}
@@ -1184,26 +1177,22 @@ void ProcessMaterialNOP( Material*, shaderStage_t*, drawSurf_t* ) {
11841177

11851178
// ProcessMaterial*() are essentially same as BindShader*(), but only set the GL program id to the material,
11861179
// without actually binding it
1187-
void ProcessMaterialGeneric3D( Material* material, shaderStage_t* pStage, drawSurf_t* drawSurf ) {
1188-
shader_t* shader = drawSurf->shader;
1189-
1180+
void ProcessMaterialGeneric3D( Material* material, shaderStage_t* pStage, drawSurf_t* ) {
11901181
material->shader = gl_genericShaderMaterial;
11911182

11921183
material->vertexAnimation = false;
11931184
material->tcGenEnvironment = pStage->tcGen_Environment;
11941185
material->tcGen_Lightmap = pStage->tcGen_Lightmap;
1195-
material->vertexSprite = shader->autoSpriteMode != 0;
11961186
material->deformIndex = pStage->deformIndex;
11971187

11981188
gl_genericShaderMaterial->SetVertexAnimation( false );
11991189

12001190
gl_genericShaderMaterial->SetTCGenEnvironment( pStage->tcGen_Environment );
12011191
gl_genericShaderMaterial->SetTCGenLightmap( pStage->tcGen_Lightmap );
12021192

1203-
bool hasDepthFade = pStage->hasDepthFade && !shader->autoSpriteMode;
1193+
bool hasDepthFade = pStage->hasDepthFade;
12041194
material->hasDepthFade = hasDepthFade;
12051195
gl_genericShaderMaterial->SetDepthFade( hasDepthFade );
1206-
gl_genericShaderMaterial->SetVertexSprite( shader->autoSpriteMode != 0 );
12071196

12081197
material->program = gl_genericShaderMaterial->GetProgram( pStage->deformIndex );
12091198
}
@@ -1286,21 +1275,13 @@ void ProcessMaterialScreen( Material* material, shaderStage_t* pStage, drawSurf_
12861275
material->program = gl_screenShaderMaterial->GetProgram( pStage->deformIndex );
12871276
}
12881277

1289-
void ProcessMaterialHeatHaze( Material* material, shaderStage_t* pStage, drawSurf_t* drawSurf ) {
1290-
shader_t* shader = drawSurf->shader;
1291-
1278+
void ProcessMaterialHeatHaze( Material* material, shaderStage_t* pStage, drawSurf_t* ) {
12921279
material->shader = gl_heatHazeShaderMaterial;
12931280

12941281
material->vertexAnimation = false;
12951282
material->deformIndex = pStage->deformIndex;
12961283

12971284
gl_heatHazeShaderMaterial->SetVertexAnimation( false );
1298-
if ( shader->autoSpriteMode ) {
1299-
gl_heatHazeShaderMaterial->SetVertexSprite( true );
1300-
} else {
1301-
gl_heatHazeShaderMaterial->SetVertexSprite( false );
1302-
}
1303-
13041285
material->program = gl_heatHazeShaderMaterial->GetProgram( pStage->deformIndex );
13051286
}
13061287

@@ -1447,7 +1428,7 @@ void MaterialSystem::GenerateWorldMaterials() {
14471428
}
14481429

14491430
shader = shader->remappedShader ? shader->remappedShader : shader;
1450-
if ( shader->isSky || shader->isPortal ) {
1431+
if ( shader->isSky || shader->isPortal || shader->autoSpriteMode ) {
14511432
continue;
14521433
}
14531434

@@ -1807,6 +1788,7 @@ void MaterialSystem::Free() {
18071788
generatedWorldCommandBuffer = false;
18081789

18091790
dynamicDrawSurfs.clear();
1791+
autospriteSurfaces.clear();
18101792
portalSurfaces.clear();
18111793
portalSurfacesTmp.clear();
18121794
portalBounds.clear();
@@ -1948,6 +1930,17 @@ void MaterialSystem::AddPortalSurfaces() {
19481930
portalSurfacesSSBO.AreaIncr();
19491931
}
19501932

1933+
// autosprite[2] is not implemented in material system, draw them old-fashionedly
1934+
void MaterialSystem::AddAutospriteSurfaces() {
1935+
tr.currentEntity = &tr.worldEntity;
1936+
1937+
for ( const drawSurf_t &drawSurf : autospriteSurfaces )
1938+
{
1939+
R_AddDrawSurf( drawSurf.surface, drawSurf.shader,
1940+
drawSurf.lightmapNum(), drawSurf.fogNum(), drawSurf.bspSurface );
1941+
}
1942+
}
1943+
19511944
void MaterialSystem::RenderMaterials( const shaderSort_t fromSort, const shaderSort_t toSort, const uint32_t viewID ) {
19521945
if ( !r_drawworld->integer ) {
19531946
return;

src/engine/renderer/Material.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ struct Material {
9898
bool tcGenEnvironment;
9999
bool tcGen_Lightmap;
100100
bool hasDepthFade;
101-
bool vertexSprite;
102101
bool alphaTest;
103102

104103
bool bspSurface;
@@ -217,6 +216,7 @@ class MaterialSystem {
217216

218217
std::vector<drawSurf_t*> portalSurfacesTmp;
219218
std::vector<drawSurf_t> portalSurfaces;
219+
std::vector<drawSurf_t> autospriteSurfaces;
220220
std::vector<PortalSurface> portalBounds;
221221
uint32_t totalPortals;
222222
std::vector<shader_t*> skyShaders;
@@ -250,6 +250,7 @@ class MaterialSystem {
250250
const GLuint count, const GLuint firstIndex );
251251

252252
void AddPortalSurfaces();
253+
void AddAutospriteSurfaces();
253254
void RenderMaterials( const shaderSort_t fromSort, const shaderSort_t toSort, const uint32_t viewID );
254255
void UpdateDynamicSurfaces();
255256

src/engine/renderer/gl_shader.cpp

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ bool GLCompileMacro_USE_REFLECTIVE_SPECULAR::HasConflictingMacros( size_t permut
15971597
{
15981598
for (const GLCompileMacro* macro : macros)
15991599
{
1600-
if ( ( permutation & macro->GetBit() ) != 0 && (macro->GetType() == USE_PHYSICAL_MAPPING || macro->GetType() == USE_VERTEX_SPRITE) )
1600+
if ( ( permutation & macro->GetBit() ) != 0 && macro->GetType() == USE_PHYSICAL_MAPPING )
16011601
{
16021602
//Log::Notice("conflicting macro! canceling '%s' vs. '%s'", GetName(), macro->GetName());
16031603
return true;
@@ -1612,7 +1612,7 @@ bool GLCompileMacro_USE_VERTEX_SKINNING::HasConflictingMacros( size_t permutatio
16121612
for (const GLCompileMacro* macro : macros)
16131613
{
16141614
//if(GLCompileMacro_USE_VERTEX_ANIMATION* m = dynamic_cast<GLCompileMacro_USE_VERTEX_ANIMATION*>(macro))
1615-
if ( ( permutation & macro->GetBit() ) != 0 && (macro->GetType() == USE_VERTEX_ANIMATION || macro->GetType() == USE_VERTEX_SPRITE) )
1615+
if ( ( permutation & macro->GetBit() ) != 0 && macro->GetType() == USE_VERTEX_ANIMATION )
16161616
{
16171617
//Log::Notice("conflicting macro! canceling '%s' vs. '%s'", GetName(), macro->GetName());
16181618
return true;
@@ -1631,7 +1631,7 @@ bool GLCompileMacro_USE_VERTEX_ANIMATION::HasConflictingMacros( size_t permutati
16311631
{
16321632
for (const GLCompileMacro* macro : macros)
16331633
{
1634-
if ( ( permutation & macro->GetBit() ) != 0 && (macro->GetType() == USE_VERTEX_SKINNING || macro->GetType() == USE_VERTEX_SPRITE) )
1634+
if ( ( permutation & macro->GetBit() ) != 0 && macro->GetType() == USE_VERTEX_SKINNING )
16351635
{
16361636
//Log::Notice("conflicting macro! canceling '%s' vs. '%s'", GetName(), macro->GetName());
16371637
return true;
@@ -1648,20 +1648,6 @@ uint32_t GLCompileMacro_USE_VERTEX_ANIMATION::GetRequiredVertexAttributes() cons
16481648
return attribs;
16491649
}
16501650

1651-
bool GLCompileMacro_USE_VERTEX_SPRITE::HasConflictingMacros( size_t permutation, const std::vector< GLCompileMacro * > &macros ) const
1652-
{
1653-
for (const GLCompileMacro* macro : macros)
1654-
{
1655-
if ( ( permutation & macro->GetBit() ) != 0 && (macro->GetType() == USE_VERTEX_SKINNING || macro->GetType() == USE_VERTEX_ANIMATION || macro->GetType() == USE_DEPTH_FADE))
1656-
{
1657-
//Log::Notice("conflicting macro! canceling '%s' vs. '%s'", GetName(), macro->GetName());
1658-
return true;
1659-
}
1660-
}
1661-
1662-
return false;
1663-
}
1664-
16651651
bool GLCompileMacro_USE_TCGEN_ENVIRONMENT::HasConflictingMacros( size_t permutation, const std::vector<GLCompileMacro*> &macros) const
16661652
{
16671653
for (const GLCompileMacro* macro : macros)
@@ -1690,20 +1676,6 @@ bool GLCompileMacro_USE_TCGEN_LIGHTMAP::HasConflictingMacros(size_t permutation,
16901676
return false;
16911677
}
16921678

1693-
bool GLCompileMacro_USE_DEPTH_FADE::HasConflictingMacros(size_t permutation, const std::vector<GLCompileMacro*> &macros) const
1694-
{
1695-
for (const GLCompileMacro* macro : macros)
1696-
{
1697-
if ((permutation & macro->GetBit()) != 0 && (macro->GetType() == USE_VERTEX_SPRITE))
1698-
{
1699-
//Log::Notice("conflicting macro! canceling '%s' vs. '%s'", GetName(), macro->GetName());
1700-
return true;
1701-
}
1702-
}
1703-
1704-
return false;
1705-
}
1706-
17071679
bool GLCompileMacro_USE_DELUXE_MAPPING::HasConflictingMacros(size_t permutation, const std::vector<GLCompileMacro*> &macros) const
17081680
{
17091681
for (const GLCompileMacro* macro : macros)
@@ -1967,7 +1939,7 @@ void GLShader::DispatchComputeIndirect( const GLintptr indirectBuffer ) {
19671939
glDispatchComputeIndirect( indirectBuffer );
19681940
}
19691941

1970-
void GLShader::SetRequiredVertexPointers( bool vertexSprite )
1942+
void GLShader::SetRequiredVertexPointers()
19711943
{
19721944
uint32_t macroVertexAttribs = 0;
19731945

@@ -1980,13 +1952,6 @@ void GLShader::SetRequiredVertexPointers( bool vertexSprite )
19801952
}
19811953

19821954
uint32_t attribs = _vertexAttribsRequired | _vertexAttribs | macroVertexAttribs; // & ~_vertexAttribsUnsupported);
1983-
1984-
if ( vertexSprite )
1985-
{
1986-
attribs &= ~ATTR_QTANGENT;
1987-
attribs |= ATTR_ORIENTATION;
1988-
}
1989-
19901955
GL_VertexAttribsState( attribs );
19911956
}
19921957

@@ -2045,7 +2010,6 @@ GLShader_generic::GLShader_generic( GLShaderManager *manager ) :
20452010
GLDeformStage( this ),
20462011
GLCompileMacro_USE_VERTEX_SKINNING( this ),
20472012
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
2048-
GLCompileMacro_USE_VERTEX_SPRITE( this ),
20492013
GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ),
20502014
GLCompileMacro_USE_TCGEN_LIGHTMAP( this ),
20512015
GLCompileMacro_USE_DEPTH_FADE( this )
@@ -2077,7 +2041,6 @@ GLShader_genericMaterial::GLShader_genericMaterial( GLShaderManager* manager ) :
20772041
GLDeformStage( this ),
20782042
// GLCompileMacro_USE_VERTEX_SKINNING( this ),
20792043
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
2080-
GLCompileMacro_USE_VERTEX_SPRITE( this ),
20812044
GLCompileMacro_USE_TCGEN_ENVIRONMENT( this ),
20822045
GLCompileMacro_USE_TCGEN_LIGHTMAP( this ),
20832046
GLCompileMacro_USE_DEPTH_FADE( this ) {
@@ -2620,8 +2583,7 @@ GLShader_heatHaze::GLShader_heatHaze( GLShaderManager *manager ) :
26202583
u_VertexInterpolation( this ),
26212584
GLDeformStage( this ),
26222585
GLCompileMacro_USE_VERTEX_SKINNING( this ),
2623-
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
2624-
GLCompileMacro_USE_VERTEX_SPRITE( this )
2586+
GLCompileMacro_USE_VERTEX_ANIMATION( this )
26252587
{
26262588
}
26272589

@@ -2652,8 +2614,8 @@ GLShader_heatHazeMaterial::GLShader_heatHazeMaterial( GLShaderManager* manager )
26522614
u_VertexInterpolation( this ),
26532615
GLDeformStage( this ),
26542616
// GLCompileMacro_USE_VERTEX_SKINNING( this ),
2655-
GLCompileMacro_USE_VERTEX_ANIMATION( this ),
2656-
GLCompileMacro_USE_VERTEX_SPRITE( this ) {
2617+
GLCompileMacro_USE_VERTEX_ANIMATION( this )
2618+
{
26572619
}
26582620

26592621
void GLShader_heatHazeMaterial::SetShaderProgramUniforms( shaderProgram_t* shaderProgram ) {

0 commit comments

Comments
 (0)