Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10477 from Pokechu22/light-dir-double-normalize
Sanitize and use increased precision when normalizing light directions
  • Loading branch information
Tilka committed Aug 4, 2022
2 parents f59f1a2 + 8129874 commit ceae42b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Source/Core/VideoCommon/VertexShaderManager.cpp
Expand Up @@ -172,14 +172,22 @@ void VertexShaderManager::SetConstants(const std::vector<std::string>& textures)
dstlight.pos[1] = light.dpos[1];
dstlight.pos[2] = light.dpos[2];

// TODO: Hardware testing is needed to confirm that this normalization is correct
auto sanitize = [](float f) {
if (std::isnan(f))
return 0.0f;
else if (std::isinf(f))
return f > 0.0f ? 1.0f : -1.0f;
else
return f;
};
double norm = double(light.ddir[0]) * double(light.ddir[0]) +
double(light.ddir[1]) * double(light.ddir[1]) +
double(light.ddir[2]) * double(light.ddir[2]);
norm = 1.0 / sqrt(norm);
float norm_float = static_cast<float>(norm);
dstlight.dir[0] = light.ddir[0] * norm_float;
dstlight.dir[1] = light.ddir[1] * norm_float;
dstlight.dir[2] = light.ddir[2] * norm_float;
dstlight.dir[0] = sanitize(static_cast<float>(light.ddir[0] * norm));
dstlight.dir[1] = sanitize(static_cast<float>(light.ddir[1] * norm));
dstlight.dir[2] = sanitize(static_cast<float>(light.ddir[2] * norm));
}
dirty = true;

Expand Down

0 comments on commit ceae42b

Please sign in to comment.