mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #10584 from Pokechu22/emboss-single-normal-v2
VideoCommon: Handle emboss texgen with only a single normal
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -90,6 +90,9 @@ struct VertexShaderConstants
|
||||
|
||||
// .x - texMtxInfo, .y - postMtxInfo, [0..1].z = color, [0..1].w = alpha
|
||||
std::array<uint4, 8> xfmem_pack1;
|
||||
|
||||
float4 cached_tangent;
|
||||
float4 cached_binormal;
|
||||
};
|
||||
|
||||
struct GeometryShaderConstants
|
||||
|
||||
@@ -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));
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -296,6 +296,8 @@ void WriteSwitch(ShaderCode& out, APIType ApiType, std::string_view variable,
|
||||
#define I_POSTTRANSFORMMATRICES "cpostmtx"
|
||||
#define I_PIXELCENTERCORRECTION "cpixelcenter"
|
||||
#define I_VIEWPORT_SIZE "cviewport"
|
||||
#define I_CACHED_TANGENT "ctangent"
|
||||
#define I_CACHED_BINORMAL "cbinormal"
|
||||
|
||||
#define I_STEREOPARAMS "cstereo"
|
||||
#define I_LINEPTPARAMS "clinept"
|
||||
@@ -317,6 +319,8 @@ static const char s_shader_uniforms[] = "\tuint components;\n"
|
||||
"\tfloat4 " I_PIXELCENTERCORRECTION ";\n"
|
||||
"\tfloat2 " I_VIEWPORT_SIZE ";\n"
|
||||
"\tuint4 xfmem_pack1[8];\n"
|
||||
"\tfloat4 " I_CACHED_TANGENT ";\n"
|
||||
"\tfloat4 " I_CACHED_BINORMAL ";\n"
|
||||
"\t#define xfmem_texMtxInfo(i) (xfmem_pack1[(i)].x)\n"
|
||||
"\t#define xfmem_postMtxInfo(i) (xfmem_pack1[(i)].y)\n"
|
||||
"\t#define xfmem_color(i) (xfmem_pack1[(i)].z)\n"
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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"
|
||||
@@ -153,26 +153,38 @@ ShaderCode GenVertexShader(APIType api_type, const ShaderHostConfig& host_config
|
||||
" N2 = " I_POSNORMALMATRIX "[5].xyz;\n"
|
||||
"}}\n"
|
||||
"\n"
|
||||
"// Multiply the position vector by the position matrix\n"
|
||||
"float4 pos = float4(dot(P0, rawpos), dot(P1, rawpos), dot(P2, rawpos), 1.0);\n"
|
||||
"o.pos = float4(dot(" I_PROJECTION "[0], pos), dot(" I_PROJECTION
|
||||
"[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"
|
||||
"// The scale of the transform matrix is used to control the size of the emboss map\n"
|
||||
"// effect by changing the scale of the transformed binormals (which only get used by\n"
|
||||
"// emboss map texgens). By normalising the first transformed normal (which is used\n"
|
||||
"// by lighting calculations and needs to be unit length), the same transform matrix\n"
|
||||
"// can do double duty, scaling for emboss mapping, and not scaling for lighting.\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 _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 _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"
|
||||
"else\n"
|
||||
" _tangent = float3(dot(N0, " I_CACHED_TANGENT ".xyz), dot(N1, " I_CACHED_TANGENT
|
||||
".xyz), dot(N2, " I_CACHED_TANGENT ".xyz));\n"
|
||||
"\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"
|
||||
"else\n"
|
||||
" _binormal = float3(dot(N0, " I_CACHED_BINORMAL ".xyz), dot(N1, " I_CACHED_BINORMAL
|
||||
".xyz), dot(N2, " I_CACHED_BINORMAL ".xyz));\n"
|
||||
"\n");
|
||||
|
||||
// Hardware Lighting
|
||||
@@ -208,7 +220,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
|
||||
@@ -246,7 +258,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");
|
||||
}
|
||||
|
||||
@@ -393,19 +405,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++)
|
||||
{
|
||||
@@ -447,12 +459,9 @@ static void GenVertexShaderTexGens(APIType api_type, u32 num_texgen, ShaderCode&
|
||||
for (u32 i = 0; i < num_texgen; i++)
|
||||
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(" float3 ldir = normalize(" I_LIGHTS "[light].pos.xyz - pos.xyz);\n"
|
||||
" output_tex.xyz += float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0);\n"
|
||||
" }}\n"
|
||||
" float3 ldir = normalize(" I_LIGHTS "[light].pos.xyz - pos.xyz);\n"
|
||||
" output_tex.xyz += float3(dot(ldir, _tangent), dot(ldir, _binormal), 0.0);\n"
|
||||
" }}\n"
|
||||
" break;\n\n");
|
||||
out.Write(" case {:s}:\n", TexGenType::Color0);
|
||||
|
||||
@@ -22,8 +22,8 @@ u8* g_vertex_manager_write_ptr;
|
||||
static void PosMtx_ReadDirect_UByte(VertexLoader* loader)
|
||||
{
|
||||
u32 posmtx = DataRead<u8>() & 0x3f;
|
||||
if (loader->m_counter < 3)
|
||||
VertexLoaderManager::position_matrix_index[loader->m_counter + 1] = posmtx;
|
||||
if (loader->m_remaining < 3)
|
||||
VertexLoaderManager::position_matrix_index_cache[loader->m_remaining] = posmtx;
|
||||
DataWrite<u32>(posmtx);
|
||||
PRIM_LOG("posmtx: {}, ", posmtx);
|
||||
}
|
||||
@@ -257,7 +257,7 @@ int VertexLoader::RunVertices(DataReader src, DataReader dst, int count)
|
||||
m_numLoadedVertices += count;
|
||||
m_skippedVertices = 0;
|
||||
|
||||
for (m_counter = count - 1; m_counter >= 0; m_counter--)
|
||||
for (m_remaining = count - 1; m_remaining >= 0; m_remaining--)
|
||||
{
|
||||
m_tcIndex = 0;
|
||||
m_colIndex = 0;
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
int m_texmtxread;
|
||||
bool m_vertexSkip;
|
||||
int m_skippedVertices;
|
||||
int m_counter;
|
||||
int m_remaining;
|
||||
|
||||
private:
|
||||
// Pipeline.
|
||||
|
||||
@@ -14,7 +14,7 @@ using namespace Arm64Gen;
|
||||
|
||||
constexpr ARM64Reg src_reg = ARM64Reg::X0;
|
||||
constexpr ARM64Reg dst_reg = ARM64Reg::X1;
|
||||
constexpr ARM64Reg count_reg = ARM64Reg::W2;
|
||||
constexpr ARM64Reg remaining_reg = ARM64Reg::W2;
|
||||
constexpr ARM64Reg skipped_reg = ARM64Reg::W17;
|
||||
constexpr ARM64Reg scratch1_reg = ARM64Reg::W16;
|
||||
constexpr ARM64Reg scratch2_reg = ARM64Reg::W15;
|
||||
@@ -209,12 +209,24 @@ int VertexLoaderARM64::ReadVertex(VertexComponentFormat attribute, ComponentForm
|
||||
// Z-Freeze
|
||||
if (native_format == &m_native_vtx_decl.position)
|
||||
{
|
||||
CMP(count_reg, 3);
|
||||
FixupBranch dont_store = B(CC_GT);
|
||||
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::position_cache);
|
||||
ADD(EncodeRegTo64(scratch1_reg), EncodeRegTo64(scratch2_reg), EncodeRegTo64(count_reg),
|
||||
ArithOption(EncodeRegTo64(count_reg), ShiftType::LSL, 4));
|
||||
m_float_emit.STUR(write_size, coords, EncodeRegTo64(scratch1_reg), -16);
|
||||
CMP(remaining_reg, 3);
|
||||
FixupBranch dont_store = B(CC_GE);
|
||||
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::position_cache.data());
|
||||
m_float_emit.STR(128, coords, EncodeRegTo64(scratch2_reg), ArithOption(remaining_reg, true));
|
||||
SetJumpTarget(dont_store);
|
||||
}
|
||||
else if (native_format == &m_native_vtx_decl.normals[1])
|
||||
{
|
||||
FixupBranch dont_store = CBNZ(remaining_reg);
|
||||
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::tangent_cache.data());
|
||||
m_float_emit.STR(128, IndexType::Unsigned, coords, EncodeRegTo64(scratch2_reg), 0);
|
||||
SetJumpTarget(dont_store);
|
||||
}
|
||||
else if (native_format == &m_native_vtx_decl.normals[2])
|
||||
{
|
||||
FixupBranch dont_store = CBNZ(remaining_reg);
|
||||
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::binormal_cache.data());
|
||||
m_float_emit.STR(128, IndexType::Unsigned, coords, EncodeRegTo64(scratch2_reg), 0);
|
||||
SetJumpTarget(dont_store);
|
||||
}
|
||||
|
||||
@@ -403,7 +415,7 @@ void VertexLoaderARM64::GenerateVertexLoader()
|
||||
AlignCode16();
|
||||
if (IsIndexed(m_VtxDesc.low.Position))
|
||||
MOV(skipped_reg, ARM64Reg::WZR);
|
||||
MOV(saved_count, count_reg);
|
||||
ADD(saved_count, remaining_reg, 1);
|
||||
|
||||
MOVP2R(stride_reg, g_main_cp_state.array_strides.data());
|
||||
MOVP2R(arraybase_reg, VertexLoaderManager::cached_arraybases.data());
|
||||
@@ -420,10 +432,10 @@ void VertexLoaderARM64::GenerateVertexLoader()
|
||||
STR(IndexType::Unsigned, scratch1_reg, dst_reg, m_dst_ofs);
|
||||
|
||||
// Z-Freeze
|
||||
CMP(count_reg, 3);
|
||||
FixupBranch dont_store = B(CC_GT);
|
||||
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::position_matrix_index);
|
||||
STR(IndexType::Unsigned, scratch1_reg, EncodeRegTo64(scratch2_reg), 0);
|
||||
CMP(remaining_reg, 3);
|
||||
FixupBranch dont_store = B(CC_GE);
|
||||
MOVP2R(EncodeRegTo64(scratch2_reg), VertexLoaderManager::position_matrix_index_cache.data());
|
||||
STR(scratch1_reg, EncodeRegTo64(scratch2_reg), ArithOption(remaining_reg, true));
|
||||
SetJumpTarget(dont_store);
|
||||
|
||||
m_native_vtx_decl.posmtx.components = 4;
|
||||
@@ -583,8 +595,8 @@ void VertexLoaderARM64::GenerateVertexLoader()
|
||||
const u8* cont = GetCodePtr();
|
||||
ADD(src_reg, src_reg, m_src_ofs);
|
||||
|
||||
SUB(count_reg, count_reg, 1);
|
||||
CBNZ(count_reg, loop_start);
|
||||
SUBS(remaining_reg, remaining_reg, 1);
|
||||
B(CCFlags::CC_GE, loop_start);
|
||||
|
||||
if (IsIndexed(m_VtxDesc.low.Position))
|
||||
{
|
||||
@@ -611,5 +623,5 @@ int VertexLoaderARM64::RunVertices(DataReader src, DataReader dst, int count)
|
||||
{
|
||||
m_numLoadedVertices += count;
|
||||
return ((int (*)(u8 * src, u8 * dst, int count)) region)(src.GetPointer(), dst.GetPointer(),
|
||||
count);
|
||||
count - 1);
|
||||
}
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -31,11 +31,12 @@
|
||||
|
||||
namespace VertexLoaderManager
|
||||
{
|
||||
float position_cache[3][4];
|
||||
|
||||
// The counter added to the address of the array is 1, 2, or 3, but never zero.
|
||||
// So only index 1 - 3 are used.
|
||||
u32 position_matrix_index[4];
|
||||
// Used by zfreeze
|
||||
std::array<u32, 3> position_matrix_index_cache;
|
||||
// 3 vertices, 4 floats each to allow SIMD overwrite
|
||||
alignas(sizeof(std::array<float, 4>)) std::array<std::array<float, 4>, 3> position_cache;
|
||||
alignas(sizeof(std::array<float, 4>)) std::array<float, 4> tangent_cache;
|
||||
alignas(sizeof(std::array<float, 4>)) std::array<float, 4> binormal_cache;
|
||||
|
||||
static NativeVertexFormatMap s_native_vertex_map;
|
||||
static NativeVertexFormat* s_current_vtx_fmt;
|
||||
@@ -251,8 +252,9 @@ static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = fal
|
||||
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, DataReader src,
|
||||
bool is_preprocess)
|
||||
{
|
||||
if (!count)
|
||||
if (count == 0)
|
||||
return 0;
|
||||
ASSERT(count > 0);
|
||||
|
||||
VertexLoaderBase* loader = RefreshLoader(vtx_attr_group, is_preprocess);
|
||||
|
||||
|
||||
@@ -53,8 +53,12 @@ void UpdateVertexArrayPointers();
|
||||
|
||||
// Position cache for zfreeze (3 vertices, 4 floats each to allow SIMD overwrite).
|
||||
// These arrays are in reverse order.
|
||||
extern float position_cache[3][4];
|
||||
extern u32 position_matrix_index[4];
|
||||
extern std::array<std::array<float, 4>, 3> position_cache;
|
||||
extern std::array<u32, 3> position_matrix_index_cache;
|
||||
// Store the tangent and binormal vectors for games that use emboss texgens when the vertex format
|
||||
// doesn't include them (e.g. RS2 and RS3). These too are 4 floats each for SIMD overwrites.
|
||||
extern std::array<float, 4> tangent_cache;
|
||||
extern std::array<float, 4> binormal_cache;
|
||||
|
||||
// VB_HAS_X. Bitmask telling what vertex components are present.
|
||||
extern u32 g_current_components;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user