diff options
| author | Tilka <tilkax@gmail.com> | 2022-08-04 18:30:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-04 18:30:30 +0100 |
| commit | ceae42b754c479dd60461323afa5a8bc90a4dfc2 (patch) | |
| tree | 412da853e600901bfc50e72ab1b844023ee18e56 /Source/Core | |
| parent | f59f1a2a35afe18e1c01ae5b41c689659a0b00f1 (diff) | |
| parent | 8129874d11c7f7d9c514cfab6e4d1dcf54b4a80d (diff) | |
Merge pull request #10477 from Pokechu22/light-dir-double-normalize
Sanitize and use increased precision when normalizing light directions
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderManager.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index 555819e072..ce43235977 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -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; |
