mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-06-10 23:13:29 +00:00
Vertex shaders do rigging computations in object space
This commit is contained in:
parent
e140b16af8
commit
e2ec1f69a3
2
hecl/extern/boo
vendored
2
hecl/extern/boo
vendored
@ -1 +1 @@
|
|||||||
Subproject commit b6d40fde97a4d2cafd4dd15bb8300cd62154484a
|
Subproject commit 54676aff916dfee736132bfd06cd4ad71ac45b81
|
@ -94,27 +94,34 @@ class ShaderTag : public Hash
|
|||||||
bool m_depthTest:1;
|
bool m_depthTest:1;
|
||||||
bool m_depthWrite:1;
|
bool m_depthWrite:1;
|
||||||
bool m_backfaceCulling:1;
|
bool m_backfaceCulling:1;
|
||||||
|
bool m_alphaTest:1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
ShaderTag() = default;
|
ShaderTag() = default;
|
||||||
ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
|
ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
|
||||||
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling)
|
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling,
|
||||||
|
bool alphaTest)
|
||||||
: Hash(source), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
|
: Hash(source), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
|
||||||
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
|
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
|
||||||
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling)
|
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling),
|
||||||
|
m_alphaTest(alphaTest)
|
||||||
{hash ^= m_meta;}
|
{hash ^= m_meta;}
|
||||||
ShaderTag(const hecl::Frontend::IR& ir, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
|
ShaderTag(const hecl::Frontend::IR& ir, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
|
||||||
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling)
|
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling,
|
||||||
|
bool alphaTest)
|
||||||
: Hash(ir.m_hash), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
|
: Hash(ir.m_hash), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
|
||||||
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
|
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
|
||||||
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling)
|
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling),
|
||||||
|
m_alphaTest(alphaTest)
|
||||||
{hash ^= m_meta;}
|
{hash ^= m_meta;}
|
||||||
ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
|
ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
|
||||||
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling)
|
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling,
|
||||||
|
bool alphaTest)
|
||||||
: Hash(hashin), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
|
: Hash(hashin), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
|
||||||
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
|
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
|
||||||
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling)
|
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling),
|
||||||
|
m_alphaTest(alphaTest)
|
||||||
{hash ^= m_meta;}
|
{hash ^= m_meta;}
|
||||||
ShaderTag(uint64_t comphashin, uint64_t meta)
|
ShaderTag(uint64_t comphashin, uint64_t meta)
|
||||||
: Hash(comphashin), m_meta(meta) {}
|
: Hash(comphashin), m_meta(meta) {}
|
||||||
@ -128,6 +135,7 @@ public:
|
|||||||
bool getDepthTest() const {return m_depthTest;}
|
bool getDepthTest() const {return m_depthTest;}
|
||||||
bool getDepthWrite() const {return m_depthWrite;}
|
bool getDepthWrite() const {return m_depthWrite;}
|
||||||
bool getBackfaceCulling() const {return m_backfaceCulling;}
|
bool getBackfaceCulling() const {return m_backfaceCulling;}
|
||||||
|
bool getAlphaTest() const {return m_alphaTest;}
|
||||||
uint64_t getMetaData() const {return m_meta;}
|
uint64_t getMetaData() const {return m_meta;}
|
||||||
|
|
||||||
std::vector<boo::VertexElementDescriptor> vertexFormat() const
|
std::vector<boo::VertexElementDescriptor> vertexFormat() const
|
||||||
@ -191,6 +199,7 @@ struct ExtensionSlot
|
|||||||
bool noAlphaWrite = false;
|
bool noAlphaWrite = false;
|
||||||
bool noAlphaOverwrite = false;
|
bool noAlphaOverwrite = false;
|
||||||
bool noReflection = false;
|
bool noReflection = false;
|
||||||
|
bool forceAlphaTest = false;
|
||||||
|
|
||||||
ExtensionSlot(size_t blockCount = 0,
|
ExtensionSlot(size_t blockCount = 0,
|
||||||
const char** blockNames = nullptr,
|
const char** blockNames = nullptr,
|
||||||
@ -204,11 +213,12 @@ struct ExtensionSlot
|
|||||||
bool noColorWrite = false,
|
bool noColorWrite = false,
|
||||||
bool noAlphaWrite = false,
|
bool noAlphaWrite = false,
|
||||||
bool noAlphaOverwrite = false,
|
bool noAlphaOverwrite = false,
|
||||||
bool noReflection = false)
|
bool noReflection = false,
|
||||||
|
bool forceAlphaTest = false)
|
||||||
: blockCount(blockCount), blockNames(blockNames), texCount(texCount), texs(texs),
|
: blockCount(blockCount), blockNames(blockNames), texCount(texCount), texs(texs),
|
||||||
srcFactor(srcFactor), dstFactor(dstFactor), depthTest(depthTest), cullMode(cullMode),
|
srcFactor(srcFactor), dstFactor(dstFactor), depthTest(depthTest), cullMode(cullMode),
|
||||||
noDepthWrite(noDepthWrite), noColorWrite(noColorWrite), noAlphaWrite(noAlphaWrite),
|
noDepthWrite(noDepthWrite), noColorWrite(noColorWrite), noAlphaWrite(noAlphaWrite),
|
||||||
noAlphaOverwrite(noAlphaOverwrite), noReflection(noReflection) {}
|
noAlphaOverwrite(noAlphaOverwrite), noReflection(noReflection), forceAlphaTest(forceAlphaTest) {}
|
||||||
|
|
||||||
mutable uint64_t m_hash = 0;
|
mutable uint64_t m_hash = 0;
|
||||||
void calculateHash() const
|
void calculateHash() const
|
||||||
|
@ -78,8 +78,8 @@ public:
|
|||||||
std::string makeFrag() const
|
std::string makeFrag() const
|
||||||
{
|
{
|
||||||
return m_backend.makeFrag(m_extension.blockCount, m_extension.blockNames,
|
return m_backend.makeFrag(m_extension.blockCount, m_extension.blockNames,
|
||||||
m_tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha,
|
m_tag.getAlphaTest() || m_extension.forceAlphaTest, m_tag.getReflectionType(),
|
||||||
m_tag.getReflectionType(), m_backend.m_blendSrc, m_backend.m_blendDst,
|
m_backend.m_blendSrc, m_backend.m_blendDst,
|
||||||
m_extension.lighting, m_extension.post,
|
m_extension.lighting, m_extension.post,
|
||||||
m_extension.texCount, m_extension.texs);
|
m_extension.texCount, m_extension.texs);
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ std::string GLSL::EmitTexGenSource2(TexGenSrc src, int uvIdx) const
|
|||||||
switch (src)
|
switch (src)
|
||||||
{
|
{
|
||||||
case TexGenSrc::Position:
|
case TexGenSrc::Position:
|
||||||
return "vtf.mvPos.xy";
|
return "objPos.xy";
|
||||||
case TexGenSrc::Normal:
|
case TexGenSrc::Normal:
|
||||||
return "vtf.mvNorm.xy";
|
return "objNorm.xy";
|
||||||
case TexGenSrc::UV:
|
case TexGenSrc::UV:
|
||||||
return hecl::Format("uvIn[%u]", uvIdx);
|
return hecl::Format("uvIn[%u]", uvIdx);
|
||||||
default: break;
|
default: break;
|
||||||
@ -29,9 +29,9 @@ std::string GLSL::EmitTexGenSource4(TexGenSrc src, int uvIdx) const
|
|||||||
switch (src)
|
switch (src)
|
||||||
{
|
{
|
||||||
case TexGenSrc::Position:
|
case TexGenSrc::Position:
|
||||||
return "vec4(vtf.mvPos.xyz, 1.0)";
|
return "vec4(objPos.xyz, 1.0)";
|
||||||
case TexGenSrc::Normal:
|
case TexGenSrc::Normal:
|
||||||
return "vec4(vtf.mvNorm.xyz, 1.0)";
|
return "vec4(objNorm.xyz, 1.0)";
|
||||||
case TexGenSrc::UV:
|
case TexGenSrc::UV:
|
||||||
return hecl::Format("vec4(uvIn[%u], 0.0, 1.0)", uvIdx);
|
return hecl::Format("vec4(uvIn[%u], 0.0, 1.0)", uvIdx);
|
||||||
default: break;
|
default: break;
|
||||||
@ -88,15 +88,28 @@ std::string GLSL::GenerateVertToFragStruct(size_t extTexCount, bool reflectionCo
|
|||||||
|
|
||||||
std::string GLSL::GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const
|
std::string GLSL::GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const
|
||||||
{
|
{
|
||||||
|
std::string retval;
|
||||||
if (skinSlots == 0)
|
if (skinSlots == 0)
|
||||||
skinSlots = 1;
|
{
|
||||||
std::string retval = hecl::Format("UBINDING0 uniform HECLVertUniform\n"
|
retval = "UBINDING0 uniform HECLVertUniform\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" mat4 mv[%u];\n"
|
" mat4 mv;\n"
|
||||||
" mat4 mvInv[%u];\n"
|
" mat4 mvInv;\n"
|
||||||
|
" mat4 proj;\n"
|
||||||
|
"};\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retval = hecl::Format("UBINDING0 uniform HECLVertUniform\n"
|
||||||
|
"{\n"
|
||||||
|
" mat4 objs[%u];\n"
|
||||||
|
" mat4 objsInv[%u];\n"
|
||||||
|
" mat4 mv;\n"
|
||||||
|
" mat4 mvInv;\n"
|
||||||
" mat4 proj;\n"
|
" mat4 proj;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
skinSlots, skinSlots);
|
skinSlots, skinSlots);
|
||||||
|
}
|
||||||
|
|
||||||
retval += "struct HECLTCGMatrix\n"
|
retval += "struct HECLTCGMatrix\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
@ -164,22 +177,25 @@ std::string GLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
/* skinned */
|
/* skinned */
|
||||||
retval += " vec4 posAccum = vec4(0.0,0.0,0.0,0.0);\n"
|
retval += " vec4 objPos = vec4(0.0,0.0,0.0,0.0);\n"
|
||||||
" vec4 normAccum = vec4(0.0,0.0,0.0,0.0);\n";
|
" vec4 objNorm = vec4(0.0,0.0,0.0,0.0);\n";
|
||||||
for (size_t i=0 ; i<s ; ++i)
|
for (size_t i=0 ; i<s ; ++i)
|
||||||
retval += hecl::Format(" posAccum += (mv[%" PRISize "] * vec4(posIn, 1.0)) * weightIn[%" PRISize "][%" PRISize "];\n"
|
retval += hecl::Format(" objPos += (objs[%" PRISize "] * vec4(posIn, 1.0)) * weightIn[%" PRISize "][%" PRISize "];\n"
|
||||||
" normAccum += (mvInv[%" PRISize "] * vec4(normIn, 1.0)) * weightIn[%" PRISize "][%" PRISize "];\n",
|
" objNorm += (objsInv[%" PRISize "] * vec4(normIn, 1.0)) * weightIn[%" PRISize "][%" PRISize "];\n",
|
||||||
i, i/4, i%4, i, i/4, i%4);
|
i, i/4, i%4, i, i/4, i%4);
|
||||||
retval += " posAccum[3] = 1.0;\n"
|
retval += " objPos[3] = 1.0;\n"
|
||||||
" vtf.mvPos = posAccum;\n"
|
" objNorm = vec4(normalize(objNorm.xyz), 0.0);\n"
|
||||||
" vtf.mvNorm = vec4(normalize(normAccum.xyz), 0.0);\n"
|
" vtf.mvPos = mv * objPos;\n"
|
||||||
" gl_Position = proj * posAccum;\n";
|
" vtf.mvNorm = vec4(normalize((mvInv * objNorm).xyz), 0.0);\n"
|
||||||
|
" gl_Position = proj * vtf.mvPos;\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* non-skinned */
|
/* non-skinned */
|
||||||
retval += " vtf.mvPos = mv[0] * vec4(posIn, 1.0);\n"
|
retval += " vec4 objPos = vec4(posIn, 1.0);\n"
|
||||||
" vtf.mvNorm = mvInv[0] * vec4(normIn, 0.0);\n"
|
" vec4 objNorm = vec4(normIn, 0.0);\n"
|
||||||
|
" vtf.mvPos = mv * objPos;\n"
|
||||||
|
" vtf.mvNorm = mvInv * objNorm;\n"
|
||||||
" gl_Position = proj * vtf.mvPos;\n";
|
" gl_Position = proj * vtf.mvPos;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,11 +338,16 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames,
|
|||||||
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D reflectionTex;\n",
|
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D reflectionTex;\n",
|
||||||
m_texMapEnd);
|
m_texMapEnd);
|
||||||
|
|
||||||
|
uint32_t extTexBits = 0;
|
||||||
for (int i=0 ; i<extTexCount ; ++i)
|
for (int i=0 ; i<extTexCount ; ++i)
|
||||||
{
|
{
|
||||||
const TextureInfo& extTex = extTexs[i];
|
const TextureInfo& extTex = extTexs[i];
|
||||||
|
if (!(extTexBits & (1 << extTex.mapIdx)))
|
||||||
|
{
|
||||||
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D extTex%u;\n",
|
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D extTex%u;\n",
|
||||||
extTex.mapIdx, extTex.mapIdx);
|
extTex.mapIdx, extTex.mapIdx);
|
||||||
|
extTexBits |= (1 << extTex.mapIdx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string retval =
|
std::string retval =
|
||||||
|
@ -14,9 +14,9 @@ std::string HLSL::EmitTexGenSource2(TexGenSrc src, int uvIdx) const
|
|||||||
switch (src)
|
switch (src)
|
||||||
{
|
{
|
||||||
case TexGenSrc::Position:
|
case TexGenSrc::Position:
|
||||||
return "vtf.mvPos.xy\n";
|
return "objPos.xy\n";
|
||||||
case TexGenSrc::Normal:
|
case TexGenSrc::Normal:
|
||||||
return "vtf.mvNorm.xy\n";
|
return "objNorm.xy\n";
|
||||||
case TexGenSrc::UV:
|
case TexGenSrc::UV:
|
||||||
return hecl::Format("v.uvIn[%u]", uvIdx);
|
return hecl::Format("v.uvIn[%u]", uvIdx);
|
||||||
default: break;
|
default: break;
|
||||||
@ -29,9 +29,9 @@ std::string HLSL::EmitTexGenSource4(TexGenSrc src, int uvIdx) const
|
|||||||
switch (src)
|
switch (src)
|
||||||
{
|
{
|
||||||
case TexGenSrc::Position:
|
case TexGenSrc::Position:
|
||||||
return "float4(vtf.mvPos.xyz, 1.0)\n";
|
return "float4(objPos.xyz, 1.0)\n";
|
||||||
case TexGenSrc::Normal:
|
case TexGenSrc::Normal:
|
||||||
return "float4(vtf.mvNorm.xyz, 1.0)\n";
|
return "float4(objNorm.xyz, 1.0)\n";
|
||||||
case TexGenSrc::UV:
|
case TexGenSrc::UV:
|
||||||
return hecl::Format("float4(v.uvIn[%u], 0.0, 1.0)", uvIdx);
|
return hecl::Format("float4(v.uvIn[%u], 0.0, 1.0)", uvIdx);
|
||||||
default: break;
|
default: break;
|
||||||
@ -82,15 +82,28 @@ std::string HLSL::GenerateVertToFragStruct(size_t extTexCount, bool reflectionCo
|
|||||||
|
|
||||||
std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const
|
std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const
|
||||||
{
|
{
|
||||||
|
std::string retval;
|
||||||
if (skinSlots == 0)
|
if (skinSlots == 0)
|
||||||
skinSlots = 1;
|
{
|
||||||
std::string retval = hecl::Format("cbuffer HECLVertUniform : register(b0)\n"
|
retval = "cbuffer HECLVertUniform : register(b0)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4x4 mv[%u];\n"
|
" float4x4 mv;\n"
|
||||||
" float4x4 mvInv[%u];\n"
|
" float4x4 mvInv;\n"
|
||||||
|
" float4x4 proj;\n"
|
||||||
|
"};\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retval = hecl::Format("cbuffer HECLVertUniform : register(b0)\n"
|
||||||
|
"{\n"
|
||||||
|
" float4x4 objs[%u];\n"
|
||||||
|
" float4x4 objsInv[%u];\n"
|
||||||
|
" float4x4 mv;\n"
|
||||||
|
" float4x4 mvInv;\n"
|
||||||
" float4x4 proj;\n"
|
" float4x4 proj;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
skinSlots, skinSlots);
|
skinSlots, skinSlots);
|
||||||
|
}
|
||||||
retval += "struct TCGMtx\n"
|
retval += "struct TCGMtx\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4x4 mtx;\n"
|
" float4x4 mtx;\n"
|
||||||
@ -157,23 +170,26 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
/* skinned */
|
/* skinned */
|
||||||
retval += " float4 posAccum = float4(0.0,0.0,0.0,0.0);\n"
|
retval += " float4 objPos = float4(0.0,0.0,0.0,0.0);\n"
|
||||||
" float4 normAccum = float4(0.0,0.0,0.0,0.0);\n";
|
" float4 objNorm = float4(0.0,0.0,0.0,0.0);\n";
|
||||||
for (size_t i=0 ; i<s ; ++i)
|
for (size_t i=0 ; i<s ; ++i)
|
||||||
retval += hecl::Format(" posAccum += mul(mv[%" PRISize "], float4(v.posIn, 1.0)) * v.weightIn[%" PRISize "][%" PRISize "];\n"
|
retval += hecl::Format(" objPos += mul(mv[%" PRISize "], float4(v.posIn, 1.0)) * v.weightIn[%" PRISize "][%" PRISize "];\n"
|
||||||
" normAccum += mul(mvInv[%" PRISize "], float4(v.normIn, 1.0)) * v.weightIn[%" PRISize "][%" PRISize "];\n",
|
" objNorm += mul(mvInv[%" PRISize "], float4(v.normIn, 1.0)) * v.weightIn[%" PRISize "][%" PRISize "];\n",
|
||||||
i, i/4, i%4, i, i/4, i%4);
|
i, i/4, i%4, i, i/4, i%4);
|
||||||
retval += " posAccum[3] = 1.0;\n"
|
retval += " objPos[3] = 1.0;\n"
|
||||||
" vtf.mvPos = posAccum;\n"
|
" objNorm = float4(normalize(objNorm.xyz), 0.0);\n"
|
||||||
" vtf.mvNorm = float4(normalize(normAccum.xyz), 0.0);\n"
|
" vtf.mvPos = mul(mv, objPos);\n"
|
||||||
" vtf.mvpPos = mul(proj, posAccum);\n";
|
" vtf.mvNorm = float4(normalize(mul(mvInv, objNorm).xyz), 0.0);\n"
|
||||||
|
" vtf.mvpPos = mul(proj, vtf.mvPos);\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* non-skinned */
|
/* non-skinned */
|
||||||
retval += " vtf.mvPos = mul(mv[0], float4(v.posIn, 1.0));\n"
|
retval += " float4 objPos = float4(posIn, 1.0);\n"
|
||||||
" vtf.mvNorm = mul(mvInv[0], float4(v.normIn, 0.0));\n"
|
" float4 objNorm = float4(normIn, 0.0);\n"
|
||||||
" vtf.mvpPos = mul(proj, vtf.mvPos);\n";
|
" vtf.mvPos = mul(mv, objPos);\n"
|
||||||
|
" vtf.mvNorm = mul(mvInv, objNorm);\n"
|
||||||
|
" gl_Position = mul(proj, vtf.mvPos);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
retval += " float4 tmpProj;\n";
|
retval += " float4 tmpProj;\n";
|
||||||
@ -311,11 +327,16 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames,
|
|||||||
texMapDecl += hecl::Format("Texture2D reflectionTex : register(t%u);\n",
|
texMapDecl += hecl::Format("Texture2D reflectionTex : register(t%u);\n",
|
||||||
m_texMapEnd);
|
m_texMapEnd);
|
||||||
|
|
||||||
|
uint32_t extTexBits = 0;
|
||||||
for (int i=0 ; i<extTexCount ; ++i)
|
for (int i=0 ; i<extTexCount ; ++i)
|
||||||
{
|
{
|
||||||
const TextureInfo& extTex = extTexs[i];
|
const TextureInfo& extTex = extTexs[i];
|
||||||
|
if (!(extTexBits & (1 << extTex.mapIdx)))
|
||||||
|
{
|
||||||
texMapDecl += hecl::Format("Texture2D extTex%u : register(t%u);\n",
|
texMapDecl += hecl::Format("Texture2D extTex%u : register(t%u);\n",
|
||||||
extTex.mapIdx, extTex.mapIdx);
|
extTex.mapIdx, extTex.mapIdx);
|
||||||
|
extTexBits |= (1 << extTex.mapIdx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string retval =
|
std::string retval =
|
||||||
|
@ -13,9 +13,9 @@ std::string Metal::EmitTexGenSource2(TexGenSrc src, int uvIdx) const
|
|||||||
switch (src)
|
switch (src)
|
||||||
{
|
{
|
||||||
case TexGenSrc::Position:
|
case TexGenSrc::Position:
|
||||||
return "vtf.mvPos.xy\n";
|
return "objPos.xy\n";
|
||||||
case TexGenSrc::Normal:
|
case TexGenSrc::Normal:
|
||||||
return "vtf.mvNorm.xy\n";
|
return "objNorm.xy\n";
|
||||||
case TexGenSrc::UV:
|
case TexGenSrc::UV:
|
||||||
return hecl::Format("v.uvIn%u", uvIdx);
|
return hecl::Format("v.uvIn%u", uvIdx);
|
||||||
default: break;
|
default: break;
|
||||||
@ -28,9 +28,9 @@ std::string Metal::EmitTexGenSource4(TexGenSrc src, int uvIdx) const
|
|||||||
switch (src)
|
switch (src)
|
||||||
{
|
{
|
||||||
case TexGenSrc::Position:
|
case TexGenSrc::Position:
|
||||||
return "float4(vtf.mvPos.xyz, 1.0)\n";
|
return "float4(objPos.xyz, 1.0)\n";
|
||||||
case TexGenSrc::Normal:
|
case TexGenSrc::Normal:
|
||||||
return "float4(vtf.mvNorm.xyz, 1.0)\n";
|
return "float4(objNorm.xyz, 1.0)\n";
|
||||||
case TexGenSrc::UV:
|
case TexGenSrc::UV:
|
||||||
return hecl::Format("float4(v.uvIn%u, 0.0, 1.0)", uvIdx);
|
return hecl::Format("float4(v.uvIn%u, 0.0, 1.0)", uvIdx);
|
||||||
default: break;
|
default: break;
|
||||||
@ -94,17 +94,32 @@ std::string Metal::GenerateVertToFragStruct(size_t extTexCount, bool reflectionC
|
|||||||
|
|
||||||
std::string Metal::GenerateVertUniformStruct(unsigned skinSlots) const
|
std::string Metal::GenerateVertUniformStruct(unsigned skinSlots) const
|
||||||
{
|
{
|
||||||
|
std::string retval;
|
||||||
if (skinSlots == 0)
|
if (skinSlots == 0)
|
||||||
skinSlots = 1;
|
{
|
||||||
std::string retval = hecl::Format("struct HECLVertUniform\n"
|
retval = "struct HECLVertUniform\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4x4 mv[%u];\n"
|
" float4x4 mv;\n"
|
||||||
" float4x4 mvInv[%u];\n"
|
" float4x4 mvInv;\n"
|
||||||
|
" float4x4 proj;\n"
|
||||||
|
"};\n"
|
||||||
|
"struct TexMtxs {float4x4 mtx; float4x4 postMtx;};\n"
|
||||||
|
"struct ReflectTexMtxs {float4x4 indMtx; float4x4 reflectMtx; float reflectAlpha;};\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retval = hecl::Format("struct HECLVertUniform\n"
|
||||||
|
"{\n"
|
||||||
|
" float4x4 objs[%u];\n"
|
||||||
|
" float4x4 objsInv[%u];\n"
|
||||||
|
" float4x4 mv;\n"
|
||||||
|
" float4x4 mvInv;\n"
|
||||||
" float4x4 proj;\n"
|
" float4x4 proj;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"struct TexMtxs {float4x4 mtx; float4x4 postMtx;};\n"
|
"struct TexMtxs {float4x4 mtx; float4x4 postMtx;};\n"
|
||||||
"struct ReflectTexMtxs {float4x4 indMtx; float4x4 reflectMtx; float reflectAlpha;};\n",
|
"struct ReflectTexMtxs {float4x4 indMtx; float4x4 reflectMtx; float reflectAlpha;};\n",
|
||||||
skinSlots, skinSlots);
|
skinSlots, skinSlots);
|
||||||
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,23 +180,26 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
/* skinned */
|
/* skinned */
|
||||||
retval += " float4 posAccum = float4(0.0,0.0,0.0,0.0);\n"
|
retval += " float4 objPos = float4(0.0,0.0,0.0,0.0);\n"
|
||||||
" float4 normAccum = float4(0.0,0.0,0.0,0.0);\n";
|
" float4 objNorm = float4(0.0,0.0,0.0,0.0);\n";
|
||||||
for (size_t i=0 ; i<s ; ++i)
|
for (size_t i=0 ; i<s ; ++i)
|
||||||
retval += hecl::Format(" posAccum += (vu.mv[%" PRISize "] * float4(v.posIn, 1.0)) * v.weightIn%" PRISize "[%" PRISize "];\n"
|
retval += hecl::Format(" objPos += (vu.mv[%" PRISize "] * float4(v.posIn, 1.0)) * v.weightIn%" PRISize "[%" PRISize "];\n"
|
||||||
" normAccum += (vu.mvInv[%" PRISize "] * float4(v.normIn, 1.0)) * v.weightIn%" PRISize "[%" PRISize "];\n",
|
" objNorm += (vu.mvInv[%" PRISize "] * float4(v.normIn, 1.0)) * v.weightIn%" PRISize "[%" PRISize "];\n",
|
||||||
i, i/4, i%4, i, i/4, i%4);
|
i, i/4, i%4, i, i/4, i%4);
|
||||||
retval += " posAccum[3] = 1.0;\n"
|
retval += " objPos[3] = 1.0;\n"
|
||||||
" vtf.mvPos = posAccum;\n"
|
" objNorm = float4(normalize(objNorm.xyz), 0.0);\n"
|
||||||
" vtf.mvNorm = float4(normalize(normAccum.xyz), 0.0);\n"
|
" vtf.mvPos = mv * objPos;\n"
|
||||||
" vtf.mvpPos = vu.proj * posAccum;\n";
|
" vtf.mvNorm = float4(normalize((mvInv * objNorm).xyz), 0.0);\n"
|
||||||
|
" vtf.mvpPos = proj * vtf.mvPos;\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* non-skinned */
|
/* non-skinned */
|
||||||
retval += " vtf.mvPos = vu.mv[0] * float4(v.posIn, 1.0);\n"
|
retval += " float4 objPos = float4(posIn, 1.0);\n"
|
||||||
" vtf.mvNorm = vu.mvInv[0] * float4(v.normIn, 0.0);\n"
|
" float4 objNorm = float4(normIn, 0.0);\n"
|
||||||
" vtf.mvpPos = vu.proj * vtf.mvPos;\n";
|
" vtf.mvPos = mv * objPos;\n"
|
||||||
|
" vtf.mvNorm = mvInv * objNorm;\n"
|
||||||
|
" vtf.mvpPos = proj * vtf.mvPos;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
retval += " float4 tmpProj;\n";
|
retval += " float4 tmpProj;\n";
|
||||||
@ -348,14 +366,18 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||||||
m_texMapEnd);
|
m_texMapEnd);
|
||||||
|
|
||||||
std::string extTexCall;
|
std::string extTexCall;
|
||||||
|
int extTexBits2 = 0;
|
||||||
for (int i=0 ; i<extTexCount ; ++i)
|
for (int i=0 ; i<extTexCount ; ++i)
|
||||||
{
|
{
|
||||||
const TextureInfo& extTex = extTexs[i];
|
const TextureInfo& extTex = extTexs[i];
|
||||||
|
if (!(extTexBits2 & (1 << extTex.mapIdx)))
|
||||||
|
{
|
||||||
if (extTexCall.size())
|
if (extTexCall.size())
|
||||||
extTexCall += ", ";
|
extTexCall += ", ";
|
||||||
extTexCall += hecl::Format("tex%u", extTex.mapIdx);
|
extTexCall += hecl::Format("tex%u", extTex.mapIdx);
|
||||||
texMapDecl += hecl::Format(",\ntexture2d<float> tex%u [[ texture(%u) ]]", extTex.mapIdx, extTex.mapIdx);
|
texMapDecl += hecl::Format(",\ntexture2d<float> tex%u [[ texture(%u) ]]", extTex.mapIdx, extTex.mapIdx);
|
||||||
extTexBits |= 1 << extTex.mapIdx;
|
extTexBits2 |= 1 << extTex.mapIdx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string blockCall;
|
std::string blockCall;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user