mirror of https://github.com/AxioDL/metaforce.git
Macros for shader extensions to determine blend factors
This commit is contained in:
parent
808e46a4ef
commit
a230eeb3b1
|
@ -31,6 +31,11 @@ def write_out_material(writebuf, mat, mesh_obj):
|
|||
transparent = True
|
||||
writebuf(struct.pack('b', int(transparent)))
|
||||
|
||||
# If this returns true, the material geometry will be split into contiguous faces
|
||||
def should_split_into_contiguous_faces(mat):
|
||||
return mat.game_settings.alpha_blend != 'OPAQUE' and \
|
||||
'retro_depth_sort' in mat and mat['retro_depth_sort']
|
||||
|
||||
# Takes a Blender 'Mesh' object (not the datablock)
|
||||
# and performs a one-shot conversion process to HMDL
|
||||
def cook(writebuf, mesh_obj, output_mode, max_skin_banks, use_luv=False):
|
||||
|
@ -125,7 +130,7 @@ def cook(writebuf, mesh_obj, output_mode, max_skin_banks, use_luv=False):
|
|||
# Generate material meshes (if opaque)
|
||||
for mat_idx in sorted_material_idxs:
|
||||
mat = mesh_obj.data.materials[mat_idx]
|
||||
if mat.game_settings.alpha_blend != 'OPAQUE':
|
||||
if should_split_into_contiguous_faces(mat):
|
||||
continue
|
||||
mat_faces_rem = []
|
||||
for face in bm_master.faces:
|
||||
|
@ -161,7 +166,7 @@ def cook(writebuf, mesh_obj, output_mode, max_skin_banks, use_luv=False):
|
|||
# Generate island meshes (if transparent)
|
||||
for mat_idx in sorted_material_idxs:
|
||||
mat = mesh_obj.data.materials[mat_idx]
|
||||
if mat.game_settings.alpha_blend == 'OPAQUE':
|
||||
if not should_split_into_contiguous_faces(mat):
|
||||
continue
|
||||
mat_faces_rem = []
|
||||
for face in bm_master.faces:
|
||||
|
|
|
@ -16,10 +16,12 @@ struct GLSL : ProgrammableCommon
|
|||
const TextureInfo* extTexs, ReflectionType reflectionType) const;
|
||||
std::string makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest, ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting=Function()) const;
|
||||
std::string makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest,
|
||||
ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting,
|
||||
const Function& post,
|
||||
size_t extTexCount, const TextureInfo* extTexs) const;
|
||||
|
|
|
@ -13,9 +13,11 @@ struct HLSL : ProgrammableCommon
|
|||
const TextureInfo* extTexs, ReflectionType reflectionType) const;
|
||||
std::string makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest, ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting=Function()) const;
|
||||
std::string makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest, ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting,
|
||||
const Function& post, size_t extTexCount,
|
||||
const TextureInfo* extTexs) const;
|
||||
|
|
|
@ -13,9 +13,12 @@ struct Metal : ProgrammableCommon
|
|||
const TextureInfo* extTexs, ReflectionType reflectionType) const;
|
||||
std::string makeFrag(size_t blockCount, const char** blockNames, bool alphaTest,
|
||||
ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting=Function()) const;
|
||||
std::string makeFrag(size_t blockCount, const char** blockNames, bool alphaTest,
|
||||
ReflectionType reflectionType, const Function& lighting,
|
||||
ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting,
|
||||
const Function& post, size_t extTexCount,
|
||||
const TextureInfo* extTexs) const;
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ struct ProgrammableCommon : IBackend
|
|||
using IBackend::reset;
|
||||
void reset(const IR& ir, Diagnostics& diag, const char* backendName);
|
||||
|
||||
static const char* BlendFactorToDefine(BlendFactor factor, BlendFactor defaultFactor);
|
||||
|
||||
private:
|
||||
unsigned addTexCoordGen(TexGenSrc src, int uvIdx, int mtx, bool normalize);
|
||||
unsigned addTexSampling(unsigned mapIdx, unsigned tcgIdx);
|
||||
|
|
|
@ -79,7 +79,8 @@ public:
|
|||
{
|
||||
return m_backend.makeFrag(m_extension.blockCount, m_extension.blockNames,
|
||||
m_tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha,
|
||||
m_tag.getReflectionType(), m_extension.lighting, m_extension.post,
|
||||
m_tag.getReflectionType(), m_backend.m_blendSrc, m_backend.m_blendDst,
|
||||
m_extension.lighting, m_extension.post,
|
||||
m_extension.texCount, m_extension.texs);
|
||||
}
|
||||
const hecl::Backend::ShaderTag& getTag() const { return m_tag; }
|
||||
|
|
|
@ -221,7 +221,8 @@ std::string GLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
}
|
||||
|
||||
std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alphaTest,
|
||||
ReflectionType reflectionType, const Function& lighting) const
|
||||
ReflectionType reflectionType, BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting) const
|
||||
{
|
||||
std::string lightingSrc;
|
||||
if (!lighting.m_source.empty())
|
||||
|
@ -246,6 +247,8 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph
|
|||
|
||||
std::string retval =
|
||||
std::string("#extension GL_ARB_shader_image_load_store: enable\n") +
|
||||
"#define BLEND_SRC_" + BlendFactorToDefine(srcFactor, m_blendSrc) + "\n" +
|
||||
"#define BLEND_DST_" + BlendFactorToDefine(dstFactor, m_blendDst) + "\n" +
|
||||
GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) +
|
||||
(!alphaTest ?
|
||||
"#ifdef GL_ARB_shader_image_load_store\n"
|
||||
|
@ -285,6 +288,7 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph
|
|||
std::string GLSL::makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest,
|
||||
ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting,
|
||||
const Function& post,
|
||||
size_t extTexCount, const TextureInfo* extTexs) const
|
||||
|
@ -327,6 +331,8 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames,
|
|||
|
||||
std::string retval =
|
||||
std::string("#extension GL_ARB_shader_image_load_store: enable\n") +
|
||||
"#define BLEND_SRC_" + BlendFactorToDefine(srcFactor, m_blendSrc) + "\n" +
|
||||
"#define BLEND_DST_" + BlendFactorToDefine(dstFactor, m_blendDst) + "\n" +
|
||||
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) +
|
||||
(!alphaTest ?
|
||||
"\n#ifdef GL_ARB_shader_image_load_store\n"
|
||||
|
|
|
@ -216,6 +216,7 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
|
||||
std::string HLSL::makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest, ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting) const
|
||||
{
|
||||
std::string lightingSrc;
|
||||
|
@ -238,6 +239,8 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames,
|
|||
texMapDecl += hecl::Format("Texture2D reflectionTex : register(t%u);\n",
|
||||
m_texMapEnd);
|
||||
std::string retval =
|
||||
std::string("#define BLEND_SRC_") + BlendFactorToDefine(srcFactor, m_blendSrc) + "\n" +
|
||||
"#define BLEND_DST_" + BlendFactorToDefine(dstFactor, m_blendDst) + "\n" +
|
||||
"SamplerState samp : register(s0);\n"
|
||||
"SamplerState clampSamp : register(s1);\n"
|
||||
"SamplerState reflectSamp : register(s2);\n" +
|
||||
|
@ -275,6 +278,7 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames,
|
|||
|
||||
std::string HLSL::makeFrag(size_t blockCount, const char** blockNames,
|
||||
bool alphaTest, ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting,
|
||||
const Function& post, size_t extTexCount,
|
||||
const TextureInfo* extTexs) const
|
||||
|
@ -315,6 +319,8 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames,
|
|||
}
|
||||
|
||||
std::string retval =
|
||||
std::string("#define BLEND_SRC_") + BlendFactorToDefine(srcFactor, m_blendSrc) + "\n" +
|
||||
"#define BLEND_DST_" + BlendFactorToDefine(dstFactor, m_blendDst) + "\n" +
|
||||
"SamplerState samp : register(s0);\n"
|
||||
"SamplerState clampSamp : register(s1);\n"
|
||||
"SamplerState reflectSamp : register(s2);\n" +
|
||||
|
|
|
@ -222,7 +222,9 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
}
|
||||
|
||||
std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alphaTest,
|
||||
ReflectionType reflectionType, const Function& lighting) const
|
||||
ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting) const
|
||||
{
|
||||
std::string lightingSrc;
|
||||
if (!lighting.m_source.empty())
|
||||
|
@ -249,7 +251,9 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
blockCall += hecl::Format("block%" PRISize, i);
|
||||
}
|
||||
|
||||
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n" +
|
||||
std::string retval = std::string("#include <metal_stdlib>\nusing namespace metal;\n") +
|
||||
"#define BLEND_SRC_" + BlendFactorToDefine(srcFactor, m_blendSrc) + "\n" +
|
||||
"#define BLEND_DST_" + BlendFactorToDefine(dstFactor, m_blendDst) + "\n" +
|
||||
GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) + "\n" +
|
||||
GenerateFragOutStruct() + "\n" +
|
||||
lightingSrc + "\n" +
|
||||
|
@ -301,7 +305,9 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
}
|
||||
|
||||
std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alphaTest,
|
||||
ReflectionType reflectionType, const Function& lighting,
|
||||
ReflectionType reflectionType,
|
||||
BlendFactor srcFactor, BlendFactor dstFactor,
|
||||
const Function& lighting,
|
||||
const Function& post, size_t extTexCount,
|
||||
const TextureInfo* extTexs) const
|
||||
{
|
||||
|
@ -361,7 +367,9 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
blockCall += hecl::Format("block%" PRISize, i);
|
||||
}
|
||||
|
||||
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n" +
|
||||
std::string retval = std::string("#include <metal_stdlib>\nusing namespace metal;\n") +
|
||||
"#define BLEND_SRC_" + BlendFactorToDefine(srcFactor, m_blendSrc) + "\n" +
|
||||
"#define BLEND_DST_" + BlendFactorToDefine(dstFactor, m_blendDst) + "\n" +
|
||||
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" +
|
||||
GenerateFragOutStruct() + "\n" +
|
||||
lightingSrc + "\n" +
|
||||
|
|
|
@ -4,6 +4,39 @@
|
|||
namespace hecl::Backend
|
||||
{
|
||||
|
||||
const char* ProgrammableCommon::BlendFactorToDefine(BlendFactor factor, BlendFactor defaultFactor)
|
||||
{
|
||||
switch (factor)
|
||||
{
|
||||
case BlendFactor::Zero:
|
||||
return "ZERO";
|
||||
case BlendFactor::One:
|
||||
return "ONE";
|
||||
case BlendFactor::SrcColor:
|
||||
return "SRCCOLOR";
|
||||
case BlendFactor::InvSrcColor:
|
||||
return "INVSRCCOLOR";
|
||||
case BlendFactor::DstColor:
|
||||
return "DSTCOLOR";
|
||||
case BlendFactor::InvDstColor:
|
||||
return "INVDSTCOLOR";
|
||||
case BlendFactor::SrcAlpha:
|
||||
return "SRCALPHA";
|
||||
case BlendFactor::InvSrcAlpha:
|
||||
return "INVSRCALPHA";
|
||||
case BlendFactor::DstAlpha:
|
||||
return "DSTALPHA";
|
||||
case BlendFactor::InvDstAlpha:
|
||||
return "INVDSTALPHA";
|
||||
case BlendFactor::SrcColor1:
|
||||
return "SRCCOLOR1";
|
||||
case BlendFactor::InvSrcColor1:
|
||||
return "INVSRCCOLOR1";
|
||||
default:
|
||||
return BlendFactorToDefine(defaultFactor, BlendFactor::Zero);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned ProgrammableCommon::addTexCoordGen(TexGenSrc src, int uvIdx, int mtx, bool normalize)
|
||||
{
|
||||
for (unsigned i=0 ; i<m_tcgs.size() ; ++i)
|
||||
|
|
Loading…
Reference in New Issue