custom transform changes

This commit is contained in:
iwubcode 2024-02-02 17:29:47 -06:00
commit 2fc9aeb53b
3 changed files with 8 additions and 1 deletions

View file

@ -103,6 +103,8 @@ struct alignas(16) VertexShaderConstants
u32 vertex_offset_posmtx;
std::array<u32, 2> vertex_offset_colors;
std::array<u32, 8> vertex_offset_texcoords;
// For custom meshes (TODO: move)
std::array<float4, 4> custom_transform;
};
enum class VSExpand : u32

View file

@ -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"

View file

@ -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)