summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends
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
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')
-rw-r--r--Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp5
-rw-r--r--Source/Core/VideoBackends/D3D12/DX12VertexFormat.cpp3
-rw-r--r--Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp2
-rw-r--r--Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp6
-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
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKVertexFormat.cpp2
8 files changed, 36 insertions, 27 deletions
diff --git a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp
index b7aeab512c..b4da7fc354 100644
--- a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp
+++ b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp
@@ -115,11 +115,12 @@ D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration& vtx_decl)
for (int i = 0; i < 3; i++)
{
+ static constexpr std::array<const char*, 3> NAMES = {"NORMAL", "TANGENT", "BINORMAL"};
format = &vtx_decl.normals[i];
if (format->enable)
{
- m_elems[m_num_elems].SemanticName = "NORMAL";
- m_elems[m_num_elems].SemanticIndex = i;
+ m_elems[m_num_elems].SemanticName = NAMES[i];
+ m_elems[m_num_elems].SemanticIndex = 0;
m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
diff --git a/Source/Core/VideoBackends/D3D12/DX12VertexFormat.cpp b/Source/Core/VideoBackends/D3D12/DX12VertexFormat.cpp
index bd818d1a66..2d1a3028e0 100644
--- a/Source/Core/VideoBackends/D3D12/DX12VertexFormat.cpp
+++ b/Source/Core/VideoBackends/D3D12/DX12VertexFormat.cpp
@@ -92,7 +92,8 @@ void DXVertexFormat::MapAttributes()
{
if (m_decl.normals[i].enable)
{
- AddAttribute("NORMAL", i, 0,
+ static constexpr std::array<const char*, 3> NAMES = {"NORMAL", "TANGENT", "BINORMAL"};
+ AddAttribute(NAMES[i], 0, 0,
VarToDXGIFormat(m_decl.normals[i].type, m_decl.normals[i].components,
m_decl.normals[i].integer),
m_decl.normals[i].offset);
diff --git a/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp
index d21a40ebc1..1913b6dcd3 100644
--- a/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp
+++ b/Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp
@@ -68,7 +68,7 @@ GLVertexFormat::GLVertexFormat(const PortableVertexDeclaration& vtx_decl)
SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position);
for (int i = 0; i < 3; i++)
- SetPointer(SHADER_NORM0_ATTRIB + i, vertex_stride, vtx_decl.normals[i]);
+ SetPointer(SHADER_NORMAL_ATTRIB + i, vertex_stride, vtx_decl.normals[i]);
for (int i = 0; i < 2; i++)
SetPointer(SHADER_COLOR0_ATTRIB + i, vertex_stride, vtx_decl.colors[i]);
diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
index 659882d015..817f894296 100644
--- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
+++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
@@ -139,9 +139,9 @@ void SHADER::SetProgramBindings(bool is_compute)
glBindAttribLocation(glprogid, SHADER_COLOR0_ATTRIB, "rawcolor0");
glBindAttribLocation(glprogid, SHADER_COLOR1_ATTRIB, "rawcolor1");
- glBindAttribLocation(glprogid, SHADER_NORM0_ATTRIB, "rawnorm0");
- glBindAttribLocation(glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
- glBindAttribLocation(glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
+ glBindAttribLocation(glprogid, SHADER_NORMAL_ATTRIB, "rawnormal");
+ glBindAttribLocation(glprogid, SHADER_TANGENT_ATTRIB, "rawtangent");
+ glBindAttribLocation(glprogid, SHADER_BINORMAL_ATTRIB, "rawbinormal");
}
for (int i = 0; i < 8; i++)
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
diff --git a/Source/Core/VideoBackends/Vulkan/VKVertexFormat.cpp b/Source/Core/VideoBackends/Vulkan/VKVertexFormat.cpp
index 5f53547066..6aa5ea14f1 100644
--- a/Source/Core/VideoBackends/Vulkan/VKVertexFormat.cpp
+++ b/Source/Core/VideoBackends/Vulkan/VKVertexFormat.cpp
@@ -73,7 +73,7 @@ void VertexFormat::MapAttributes()
for (uint32_t i = 0; i < 3; i++)
{
if (m_decl.normals[i].enable)
- AddAttribute(SHADER_NORM0_ATTRIB + i, 0,
+ AddAttribute(SHADER_NORMAL_ATTRIB + i, 0,
VarToVkFormat(m_decl.normals[i].type, m_decl.normals[i].components,
m_decl.normals[i].integer),
m_decl.normals[i].offset);