From 2fc9aeb53bf326ff3c7b02c89e4ea5d191faa070 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Fri, 2 Feb 2024 17:29:47 -0600 Subject: [PATCH] custom transform changes --- Source/Core/VideoCommon/ConstantManager.h | 2 ++ Source/Core/VideoCommon/ShaderGenCommon.h | 1 + Source/Core/VideoCommon/VertexShaderGen.cpp | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/ConstantManager.h b/Source/Core/VideoCommon/ConstantManager.h index 14c8732580..ab399f3a4e 100644 --- a/Source/Core/VideoCommon/ConstantManager.h +++ b/Source/Core/VideoCommon/ConstantManager.h @@ -103,6 +103,8 @@ struct alignas(16) VertexShaderConstants u32 vertex_offset_posmtx; std::array vertex_offset_colors; std::array vertex_offset_texcoords; + // For custom meshes (TODO: move) + std::array custom_transform; }; enum class VSExpand : u32 diff --git a/Source/Core/VideoCommon/ShaderGenCommon.h b/Source/Core/VideoCommon/ShaderGenCommon.h index 4723cbfc79..5b19720df9 100644 --- a/Source/Core/VideoCommon/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/ShaderGenCommon.h @@ -319,6 +319,7 @@ static const char s_shader_uniforms[] = "\tuint components;\n" "\tuint vertex_offset_rawcolor0;\n" "\tuint vertex_offset_rawcolor1;\n" "\tuint4 vertex_offset_rawtex[2];\n" // std140 is pain + "\tfloat4 custom_transform[4];\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" diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 41512cd489..1ab2725bc7 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -406,8 +406,12 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho "float3 N2 = " I_POSNORMALMATRIX "[5].xyz;\n"); } + out.Write( + "// Multiply the position vector by the custom transform matrix\n" + "float4 pos = float4(dot(rawpos, custom_transform[0]), dot(rawpos, custom_transform[1]), " + "dot(rawpos, custom_transform[2]), dot(rawpos, custom_transform[3]));\n"); out.Write("// Multiply the position vector by the position matrix\n" - "float4 pos = float4(dot(P0, rawpos), dot(P1, rawpos), dot(P2, rawpos), 1.0);\n"); + "pos = float4(dot(P0, pos), dot(P1, pos), dot(P2, pos), 1.0);\n"); if ((uid_data->components & VB_HAS_NORMAL) == 0) out.Write("float3 rawnormal = " I_CACHED_NORMAL ".xyz;\n"); if ((uid_data->components & VB_HAS_TANGENT) == 0)