Skip to content

Commit

Permalink
client: render: gl_studio_init: added proper handling of null normals…
Browse files Browse the repository at this point in the history
… in studiomodels
  • Loading branch information
SNMetamorph committed Jun 15, 2022
1 parent bfb71ee commit 869fbdf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/render/gl_studio_init.cpp
Expand Up @@ -1249,6 +1249,19 @@ void CStudioModelRenderer :: SetupSubmodelVerts( const mstudiomodel_t *pSubModel
m_arrayxvert[m_nNumArrayVerts].vertex = pstudioverts[ptricmds[0]];
m_arrayxvert[m_nNumArrayVerts].normal = pstudionorms[ptricmds[1]];

// replace null normals with random ones, because null normals causes NaNs in vertex shader
// after normalizing. therefore we should avoid null normals in studiomodels
// TODO: warn about null normals in studiomodel on loading stage
if (m_arrayxvert[m_nNumArrayVerts].normal.Length() < 0.1f)
{
vec3_t randomDirection = vec3_t(
RANDOM_FLOAT(-1.0f, 1.0f),
RANDOM_FLOAT(-1.0f, 1.0f),
RANDOM_FLOAT(-1.0f, 1.0f)
);
m_arrayxvert[m_nNumArrayVerts].normal = randomDirection.Normalize();
}

if( m_iTBNState == TBNSTATE_GENERATE || use_fan_sequence )
{
// transformed vertices to build TBN
Expand Down

0 comments on commit 869fbdf

Please sign in to comment.