Skip to content

Commit

Permalink
VideoCommon: Rename norm0/norm1/norm2 to normal/tangent/binormal
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Apr 22, 2022
1 parent 88134a6 commit 04fdadd
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 91 deletions.
5 changes: 3 additions & 2 deletions Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoBackends/D3D12/DX12VertexFormat.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/OGLNativeVertexFormat.cpp
Expand Up @@ -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]);
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp
Expand Up @@ -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++)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Software/SWVertexLoader.cpp
Expand Up @@ -89,10 +89,10 @@ 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)
if (VertexLoaderManager::g_current_components & VB_HAS_NORMAL)
{
TransformUnit::TransformNormal(
&m_vertex, (VertexLoaderManager::g_current_components & VB_HAS_NRM2) != 0, outVertex);
&m_vertex, (VertexLoaderManager::g_current_components & VB_HAS_BINORMAL) != 0, outVertex);
}
TransformUnit::TransformColor(&m_vertex, outVertex);
TransformUnit::TransformTexCoord(&m_vertex, outVertex);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/Vulkan/VKVertexFormat.cpp
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/VideoCommon/LightingShaderGen.cpp
Expand Up @@ -27,11 +27,11 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
case AttenuationFunc::Dir:
object.Write("ldir = normalize(" LIGHT_POS ".xyz - pos.xyz);\n", LIGHT_POS_PARAMS(index));
object.Write("attn = 1.0;\n");
object.Write("if (length(ldir) == 0.0)\n\t ldir = _norm0;\n");
object.Write("if (length(ldir) == 0.0)\n\t ldir = _normal;\n");
break;
case AttenuationFunc::Spec:
object.Write("ldir = normalize(" LIGHT_POS ".xyz - pos.xyz);\n", LIGHT_POS_PARAMS(index));
object.Write("attn = (dot(_norm0, ldir) >= 0.0) ? max(0.0, dot(_norm0, " LIGHT_DIR
object.Write("attn = (dot(_normal, ldir) >= 0.0) ? max(0.0, dot(_normal, " LIGHT_DIR
".xyz)) : 0.0;\n",
LIGHT_DIR_PARAMS(index));
object.Write("cosAttn = " LIGHT_COSATT ".xyz;\n", LIGHT_COSATT_PARAMS(index));
Expand Down Expand Up @@ -64,7 +64,8 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
break;
case DiffuseFunc::Sign:
case DiffuseFunc::Clamp:
object.Write("lacc.{} += int{}(round(attn * {}dot(ldir, _norm0)) * float{}(" LIGHT_COL ")));\n",
object.Write("lacc.{} += int{}(round(attn * {}dot(ldir, _normal)) * float{}(" LIGHT_COL
")));\n",
swizzle, swizzle_components, diffusefunc != DiffuseFunc::Sign ? "max(0.0," : "(",
swizzle_components, LIGHT_COL_PARAMS(index, swizzle));
break;
Expand Down
7 changes: 3 additions & 4 deletions Source/Core/VideoCommon/NativeVertexFormat.h
Expand Up @@ -25,10 +25,9 @@ enum
VB_HAS_TEXMTXIDXALL = (0xff << 2),

// VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
VB_HAS_NRM0 = (1 << 10),
VB_HAS_NRM1 = (1 << 11),
VB_HAS_NRM2 = (1 << 12),
VB_HAS_NRMALL = (7 << 10),
VB_HAS_NORMAL = (1 << 10),
VB_HAS_TANGENT = (1 << 11),
VB_HAS_BINORMAL = (1 << 12),

VB_COL_SHIFT = 13,
VB_HAS_COL0 = (1 << 13),
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/PixelShaderGen.cpp
Expand Up @@ -1132,7 +1132,7 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos

if (per_pixel_lighting)
{
out.Write("\tfloat3 _norm0 = normalize(Normal.xyz);\n\n"
out.Write("\tfloat3 _normal = normalize(Normal.xyz);\n\n"
"\tfloat3 pos = WorldPos;\n");

out.Write("\tint4 lacc;\n"
Expand Down
71 changes: 36 additions & 35 deletions Source/Core/VideoCommon/UberShaderVertex.cpp
Expand Up @@ -57,9 +57,9 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
{
out.Write("ATTRIBUTE_LOCATION({}) in float4 rawpos;\n", SHADER_POSITION_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in uint4 posmtx;\n", SHADER_POSMTX_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnorm0;\n", SHADER_NORM0_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnorm1;\n", SHADER_NORM1_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnorm2;\n", SHADER_NORM2_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float3 rawnormal;\n", SHADER_NORMAL_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float3 rawtangent;\n", SHADER_TANGENT_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float3 rawbinormal;\n", SHADER_BINORMAL_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor0;\n", SHADER_COLOR0_ATTRIB);
out.Write("ATTRIBUTE_LOCATION({}) in float4 rawcolor1;\n", SHADER_COLOR1_ATTRIB);
for (int i = 0; i < 8; ++i)
Expand Down Expand Up @@ -106,9 +106,9 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
out.Write("VS_OUTPUT main(\n");

// inputs
out.Write(" float3 rawnorm0 : NORMAL0,\n"
" float3 rawnorm1 : NORMAL1,\n"
" float3 rawnorm2 : NORMAL2,\n"
out.Write(" float3 rawnormal : NORMAL,\n"
" float3 rawtangent : TANGENT,\n"
" float3 rawbinormal : BINORMAL,\n"
" float4 rawcolor0 : COLOR0,\n"
" float4 rawcolor1 : COLOR1,\n");
for (int i = 0; i < 8; ++i)
Expand All @@ -131,7 +131,7 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
"float3 N1;\n"
"float3 N2;\n"
"\n"
"if ((components & {}u) != 0u) {{// VB_HAS_POSMTXIDX\n",
"if ((components & {}u) != 0u) {{ // VB_HAS_POSMTXIDX\n",
VB_HAS_POSMTXIDX);
out.Write(" // Vertex format has a per-vertex matrix\n"
" int posidx = int(posmtx.r);\n"
Expand Down Expand Up @@ -159,21 +159,22 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
"[1], pos), dot(" I_PROJECTION "[2], pos), dot(" I_PROJECTION "[3], pos));\n"
"\n"
"// Only the first normal gets normalized (TODO: why?)\n"
"float3 _norm0 = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_NRM0\n",
VB_HAS_NRM0);
out.Write(
" _norm0 = normalize(float3(dot(N0, rawnorm0), dot(N1, rawnorm0), dot(N2, rawnorm0)));\n"
"\n"
"float3 _norm1 = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_NRM1\n",
VB_HAS_NRM1);
out.Write(" _norm1 = float3(dot(N0, rawnorm1), dot(N1, rawnorm1), dot(N2, rawnorm1));\n"
"float3 _normal = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_NORMAL\n",
VB_HAS_NORMAL);
out.Write(" _normal = normalize(float3(dot(N0, rawnormal), dot(N1, rawnormal), dot(N2, "
"rawnormal)));\n"
"\n"
"float3 _tangent = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_TANGENT\n",
VB_HAS_TANGENT);
out.Write(" _tangent = float3(dot(N0, rawtangent), dot(N1, rawtangent), dot(N2, rawtangent));\n"
"\n"
"float3 _norm2 = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_NRM2\n",
VB_HAS_NRM2);
out.Write(" _norm2 = float3(dot(N0, rawnorm2), dot(N1, rawnorm2), dot(N2, rawnorm2));\n"
"float3 _binormal = float3(0.0, 0.0, 0.0);\n"
"if ((components & {}u) != 0u) // VB_HAS_BINORMAL\n",
VB_HAS_BINORMAL);
out.Write(" _binormal = float3(dot(N0, rawbinormal), dot(N1, rawbinormal), dot(N2, "
"rawbinormal));\n"
"\n");

// Hardware Lighting
Expand Down Expand Up @@ -209,7 +210,7 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
"}}\n"
"\n");

WriteVertexLighting(out, api_type, "pos.xyz", "_norm0", "vertex_color_0", "vertex_color_1",
WriteVertexLighting(out, api_type, "pos.xyz", "_normal", "vertex_color_0", "vertex_color_1",
"o.colors_0", "o.colors_1");

// Texture Coordinates
Expand Down Expand Up @@ -247,7 +248,7 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config

if (per_pixel_lighting)
{
out.Write("o.Normal = _norm0;\n"
out.Write("o.Normal = _normal;\n"
"o.WorldPos = pos.xyz;\n");
}

Expand Down Expand Up @@ -394,19 +395,19 @@ static void GenVertexShaderTexGens(APIType api_type, u32 num_texgen, ShaderCode&
out.Write(" coord.xyz = rawpos.xyz;\n");
out.Write(" break;\n\n");
out.Write(" case {:s}:\n", SourceRow::Normal);
out.Write(
" coord.xyz = ((components & {}u /* VB_HAS_NRM0 */) != 0u) ? rawnorm0.xyz : coord.xyz;",
VB_HAS_NRM0);
out.Write(" coord.xyz = ((components & {}u /* VB_HAS_NORMAL */) != 0u) ? rawnormal.xyz : "
"coord.xyz;",
VB_HAS_NORMAL);
out.Write(" break;\n\n");
out.Write(" case {:s}:\n", SourceRow::BinormalT);
out.Write(
" coord.xyz = ((components & {}u /* VB_HAS_NRM1 */) != 0u) ? rawnorm1.xyz : coord.xyz;",
VB_HAS_NRM1);
out.Write(" coord.xyz = ((components & {}u /* VB_HAS_TANGENT */) != 0u) ? rawtangent.xyz : "
"coord.xyz;",
VB_HAS_TANGENT);
out.Write(" break;\n\n");
out.Write(" case {:s}:\n", SourceRow::BinormalB);
out.Write(
" coord.xyz = ((components & {}u /* VB_HAS_NRM2 */) != 0u) ? rawnorm2.xyz : coord.xyz;",
VB_HAS_NRM2);
out.Write(" coord.xyz = ((components & {}u /* VB_HAS_BINORMAL */) != 0u) ? rawbinormal.xyz : "
"coord.xyz;",
VB_HAS_BINORMAL);
out.Write(" break;\n\n");
for (u32 i = 0; i < 8; i++)
{
Expand Down Expand Up @@ -449,10 +450,10 @@ static void GenVertexShaderTexGens(APIType api_type, u32 num_texgen, ShaderCode&
out.Write(" case {}u: output_tex.xyz = o.tex{}; break;\n", i, i);
out.Write(" default: output_tex.xyz = float3(0.0, 0.0, 0.0); break;\n"
" }}\n");
out.Write(" if ((components & {}u) != 0u) {{ // VB_HAS_NRM1 | VB_HAS_NRM2\n",
VB_HAS_NRM1 | VB_HAS_NRM2); // Should this be VB_HAS_NRM1 | VB_HAS_NRM2
out.Write(" if ((components & {}u) != 0u) {{ // VB_HAS_TANGENT | VB_HAS_BINORMAL\n",
VB_HAS_TANGENT | VB_HAS_BINORMAL);
out.Write(" float3 ldir = normalize(" I_LIGHTS "[light].pos.xyz - pos.xyz);\n"
" output_tex.xyz += float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0);\n"
" output_tex.xyz += float3(dot(ldir, _tangent), dot(ldir, _binormal), 0.0);\n"
" }}\n"
" }}\n"
" break;\n\n");
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/VertexLoaderBase.cpp
Expand Up @@ -151,9 +151,9 @@ u32 VertexLoaderBase::GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& v
// Vertices always have positions; thus there is no VB_HAS_POS as it would always be set
if (vtx_desc.low.Normal != VertexComponentFormat::NotPresent)
{
components |= VB_HAS_NRM0;
components |= VB_HAS_NORMAL;
if (vtx_attr.g0.NormalElements == NormalComponentCount::NBT)
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
components |= VB_HAS_TANGENT | VB_HAS_BINORMAL;
}
for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++)
{
Expand Down

0 comments on commit 04fdadd

Please sign in to comment.