summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2022-04-22 23:24:22 -0400
committerGitHub <noreply@github.com>2022-04-22 23:24:22 -0400
commit56bb965ab944bd01bf511df31b7c9d91f8e62bd4 (patch)
treea6078a76e52a86d89ec2f53b94bab9aeb0894bd0 /Source/Core/VideoBackends/Software
parent2e01dc0c82b5f73215e3425ab45ff6c7ee50b389 (diff)
parent784079853d9daa4d5e4de0b49b610ec0e58a2b0c (diff)
Merge pull request #10584 from Pokechu22/emboss-single-normal-v2
VideoCommon: Handle emboss texgen with only a single normal
Diffstat (limited to 'Source/Core/VideoBackends/Software')
-rw-r--r--Source/Core/VideoBackends/Software/SWVertexLoader.cpp20
-rw-r--r--Source/Core/VideoBackends/Software/TransformUnit.cpp23
-rw-r--r--Source/Core/VideoBackends/Software/TransformUnit.h2
3 files changed, 26 insertions, 19 deletions
diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
index 287fcf4a4b..4b9825132e 100644
--- a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
+++ b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
@@ -25,6 +25,7 @@
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VertexLoaderBase.h"
#include "VideoCommon/VertexLoaderManager.h"
+#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"
@@ -89,11 +90,8 @@ void SWVertexLoader::DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_
OutputVertexData* outVertex = m_setup_unit.GetVertex();
TransformUnit::TransformPosition(&m_vertex, outVertex);
outVertex->normal = {};
- if (VertexLoaderManager::g_current_components & VB_HAS_NRM0)
- {
- TransformUnit::TransformNormal(
- &m_vertex, (VertexLoaderManager::g_current_components & VB_HAS_NRM2) != 0, outVertex);
- }
+ if (VertexLoaderManager::g_current_components & VB_HAS_NORMAL)
+ TransformUnit::TransformNormal(&m_vertex, outVertex);
TransformUnit::TransformColor(&m_vertex, outVertex);
TransformUnit::TransformTexCoord(&m_vertex, outVertex);
@@ -230,6 +228,18 @@ void SWVertexLoader::ParseVertex(const PortableVertexDeclaration& vdec, int inde
{
ReadVertexAttribute<float>(&m_vertex.normal[i][0], src, vdec.normals[i], 0, 3, false);
}
+ if (!vdec.normals[1].enable)
+ {
+ m_vertex.normal[1][0] = VertexShaderManager::constants.cached_tangent[0];
+ m_vertex.normal[1][1] = VertexShaderManager::constants.cached_tangent[1];
+ m_vertex.normal[1][2] = VertexShaderManager::constants.cached_tangent[2];
+ }
+ if (!vdec.normals[2].enable)
+ {
+ m_vertex.normal[2][0] = VertexShaderManager::constants.cached_binormal[0];
+ m_vertex.normal[2][1] = VertexShaderManager::constants.cached_binormal[1];
+ m_vertex.normal[2][2] = VertexShaderManager::constants.cached_binormal[2];
+ }
ParseColorAttributes(&m_vertex, src, vdec);
diff --git a/Source/Core/VideoBackends/Software/TransformUnit.cpp b/Source/Core/VideoBackends/Software/TransformUnit.cpp
index bf56307025..6fcf42df9e 100644
--- a/Source/Core/VideoBackends/Software/TransformUnit.cpp
+++ b/Source/Core/VideoBackends/Software/TransformUnit.cpp
@@ -90,22 +90,19 @@ void TransformPosition(const InputVertexData* src, OutputVertexData* dst)
}
}
-void TransformNormal(const InputVertexData* src, bool nbt, OutputVertexData* dst)
+void TransformNormal(const InputVertexData* src, OutputVertexData* dst)
{
const float* mat = &xfmem.normalMatrices[(src->posMtx & 31) * 3];
- if (nbt)
- {
- MultiplyVec3Mat33(src->normal[0], mat, dst->normal[0]);
- MultiplyVec3Mat33(src->normal[1], mat, dst->normal[1]);
- MultiplyVec3Mat33(src->normal[2], mat, dst->normal[2]);
- dst->normal[0].Normalize();
- }
- else
- {
- MultiplyVec3Mat33(src->normal[0], mat, dst->normal[0]);
- dst->normal[0].Normalize();
- }
+ MultiplyVec3Mat33(src->normal[0], mat, dst->normal[0]);
+ MultiplyVec3Mat33(src->normal[1], mat, dst->normal[1]);
+ MultiplyVec3Mat33(src->normal[2], mat, dst->normal[2]);
+ // The scale of the transform matrix is used to control the size of the emboss map effect, by
+ // changing the scale of the transformed binormals (which only get used by emboss map texgens).
+ // By normalising the first transformed normal (which is used by lighting calculations and needs
+ // to be unit length), the same transform matrix can do double duty, scaling for emboss mapping,
+ // and not scaling for lighting.
+ dst->normal[0].Normalize();
}
static void TransformTexCoordRegular(const TexMtxInfo& texinfo, int coordNum,
diff --git a/Source/Core/VideoBackends/Software/TransformUnit.h b/Source/Core/VideoBackends/Software/TransformUnit.h
index e764127ec4..59152250b0 100644
--- a/Source/Core/VideoBackends/Software/TransformUnit.h
+++ b/Source/Core/VideoBackends/Software/TransformUnit.h
@@ -9,7 +9,7 @@ struct OutputVertexData;
namespace TransformUnit
{
void TransformPosition(const InputVertexData* src, OutputVertexData* dst);
-void TransformNormal(const InputVertexData* src, bool nbt, OutputVertexData* dst);
+void TransformNormal(const InputVertexData* src, OutputVertexData* dst);
void TransformColor(const InputVertexData* src, OutputVertexData* dst);
void TransformTexCoord(const InputVertexData* src, OutputVertexData* dst);
} // namespace TransformUnit