From e2ec1f69a35d02b0ffb3f8ef70272ebb21d51f99 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 7 Nov 2018 14:53:00 -1000 Subject: [PATCH] Vertex shaders do rigging computations in object space --- hecl/extern/boo | 2 +- hecl/include/hecl/Backend/Backend.hpp | 26 ++++++--- hecl/include/hecl/Pipeline.hpp | 4 +- hecl/lib/Backend/GLSL.cpp | 69 ++++++++++++++-------- hecl/lib/Backend/HLSL.cpp | 71 +++++++++++++++-------- hecl/lib/Backend/Metal.cpp | 82 +++++++++++++++++---------- 6 files changed, 164 insertions(+), 90 deletions(-) diff --git a/hecl/extern/boo b/hecl/extern/boo index b6d40fde9..54676aff9 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit b6d40fde97a4d2cafd4dd15bb8300cd62154484a +Subproject commit 54676aff916dfee736132bfd06cd4ad71ac45b81 diff --git a/hecl/include/hecl/Backend/Backend.hpp b/hecl/include/hecl/Backend/Backend.hpp index 51b9d1034..a67b0ae01 100644 --- a/hecl/include/hecl/Backend/Backend.hpp +++ b/hecl/include/hecl/Backend/Backend.hpp @@ -94,27 +94,34 @@ class ShaderTag : public Hash bool m_depthTest:1; bool m_depthWrite:1; bool m_backfaceCulling:1; + bool m_alphaTest:1; }; }; public: ShaderTag() = default; 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), 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;} 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), 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;} 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), 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;} ShaderTag(uint64_t comphashin, uint64_t meta) : Hash(comphashin), m_meta(meta) {} @@ -128,6 +135,7 @@ public: bool getDepthTest() const {return m_depthTest;} bool getDepthWrite() const {return m_depthWrite;} bool getBackfaceCulling() const {return m_backfaceCulling;} + bool getAlphaTest() const {return m_alphaTest;} uint64_t getMetaData() const {return m_meta;} std::vector vertexFormat() const @@ -191,6 +199,7 @@ struct ExtensionSlot bool noAlphaWrite = false; bool noAlphaOverwrite = false; bool noReflection = false; + bool forceAlphaTest = false; ExtensionSlot(size_t blockCount = 0, const char** blockNames = nullptr, @@ -204,11 +213,12 @@ struct ExtensionSlot bool noColorWrite = false, bool noAlphaWrite = false, bool noAlphaOverwrite = false, - bool noReflection = false) + bool noReflection = false, + bool forceAlphaTest = false) : blockCount(blockCount), blockNames(blockNames), texCount(texCount), texs(texs), srcFactor(srcFactor), dstFactor(dstFactor), depthTest(depthTest), cullMode(cullMode), noDepthWrite(noDepthWrite), noColorWrite(noColorWrite), noAlphaWrite(noAlphaWrite), - noAlphaOverwrite(noAlphaOverwrite), noReflection(noReflection) {} + noAlphaOverwrite(noAlphaOverwrite), noReflection(noReflection), forceAlphaTest(forceAlphaTest) {} mutable uint64_t m_hash = 0; void calculateHash() const diff --git a/hecl/include/hecl/Pipeline.hpp b/hecl/include/hecl/Pipeline.hpp index 6fa5bd859..19aec165a 100644 --- a/hecl/include/hecl/Pipeline.hpp +++ b/hecl/include/hecl/Pipeline.hpp @@ -78,8 +78,8 @@ public: std::string makeFrag() const { 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_backend.m_blendSrc, m_backend.m_blendDst, + m_tag.getAlphaTest() || m_extension.forceAlphaTest, m_tag.getReflectionType(), + m_backend.m_blendSrc, m_backend.m_blendDst, m_extension.lighting, m_extension.post, m_extension.texCount, m_extension.texs); } diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index b4a64a152..9cf76ac4c 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -14,9 +14,9 @@ std::string GLSL::EmitTexGenSource2(TexGenSrc src, int uvIdx) const switch (src) { case TexGenSrc::Position: - return "vtf.mvPos.xy"; + return "objPos.xy"; case TexGenSrc::Normal: - return "vtf.mvNorm.xy"; + return "objNorm.xy"; case TexGenSrc::UV: return hecl::Format("uvIn[%u]", uvIdx); default: break; @@ -29,9 +29,9 @@ std::string GLSL::EmitTexGenSource4(TexGenSrc src, int uvIdx) const switch (src) { case TexGenSrc::Position: - return "vec4(vtf.mvPos.xyz, 1.0)"; + return "vec4(objPos.xyz, 1.0)"; case TexGenSrc::Normal: - return "vec4(vtf.mvNorm.xyz, 1.0)"; + return "vec4(objNorm.xyz, 1.0)"; case TexGenSrc::UV: return hecl::Format("vec4(uvIn[%u], 0.0, 1.0)", uvIdx); 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 retval; if (skinSlots == 0) - skinSlots = 1; - std::string retval = hecl::Format("UBINDING0 uniform HECLVertUniform\n" - "{\n" - " mat4 mv[%u];\n" - " mat4 mvInv[%u];\n" - " mat4 proj;\n" - "};\n", - skinSlots, skinSlots); + { + retval = "UBINDING0 uniform HECLVertUniform\n" + "{\n" + " mat4 mv;\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" + "};\n", + skinSlots, skinSlots); + } retval += "struct HECLTCGMatrix\n" "{\n" @@ -164,22 +177,25 @@ std::string GLSL::makeVert(unsigned col, unsigned uv, unsigned w, if (s) { /* skinned */ - retval += " vec4 posAccum = vec4(0.0,0.0,0.0,0.0);\n" - " vec4 normAccum = vec4(0.0,0.0,0.0,0.0);\n"; + retval += " vec4 objPos = 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 tex%u [[ texture(%u) ]]", extTex.mapIdx, extTex.mapIdx); - extTexBits |= 1 << extTex.mapIdx; + if (!(extTexBits2 & (1 << extTex.mapIdx))) + { + if (extTexCall.size()) + extTexCall += ", "; + extTexCall += hecl::Format("tex%u", extTex.mapIdx); + texMapDecl += hecl::Format(",\ntexture2d tex%u [[ texture(%u) ]]", extTex.mapIdx, extTex.mapIdx); + extTexBits2 |= 1 << extTex.mapIdx; + } } std::string blockCall;