From 21e2a26e368272ab9dfa53d74693840fdccdfd61 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 26 Mar 2017 08:21:01 -1000 Subject: [PATCH] HLSL reflection fix --- hecl/include/hecl/Backend/HLSL.hpp | 8 ++++---- hecl/lib/Backend/GLSL.cpp | 12 ++++++++---- hecl/lib/Backend/HLSL.cpp | 18 +++++++++++------- hecl/lib/Backend/Metal.cpp | 1 + 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/hecl/include/hecl/Backend/HLSL.hpp b/hecl/include/hecl/Backend/HLSL.hpp index a8faf75c1..3de01c274 100644 --- a/hecl/include/hecl/Backend/HLSL.hpp +++ b/hecl/include/hecl/Backend/HLSL.hpp @@ -16,15 +16,15 @@ struct HLSL : ProgrammableCommon const TextureInfo* extTexs, ReflectionType reflectionType) const; std::string makeFrag(bool alphaTest, ReflectionType reflectionType, const ShaderFunction& lighting=ShaderFunction()) const; - std::string makeFrag(bool alphaTest, const ShaderFunction& lighting, - ReflectionType reflectionType, + std::string makeFrag(bool alphaTest, ReflectionType reflectionType, + const ShaderFunction& lighting, const ShaderFunction& post, size_t extTexCount, const TextureInfo* extTexs) const; private: std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const; - std::string GenerateVertToFragStruct(size_t extTexCount, ReflectionType reflectionType) const; - std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, ReflectionType reflectionType) const; + std::string GenerateVertToFragStruct(size_t extTexCount, bool reflectionCoords) const; + std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const; std::string GenerateAlphaTest() const; std::string GenerateReflectionExpr(ReflectionType type) const; diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index adcf17811..fe5af6b0f 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -136,6 +136,7 @@ std::string GLSL::GenerateReflectionExpr(ReflectionType type) const switch (type) { case ReflectionType::None: + default: return "vec3(0.0, 0.0, 0.0);\n"; case ReflectionType::Simple: return "texture(reflectionTex, vtf.reflectTcgs[1]).rgb * vtf.reflectAlpha;\n"; @@ -637,10 +638,12 @@ struct SPIRVBackendFactory : IShaderBackendFactory std::string vertSource = m_backend.makeVert("#version 330", tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), - tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr); + tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr, + tag.getReflectionType()); std::string fragSource = m_backend.makeFrag("#version 330", - tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha); + tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, + tag.getReflectionType()); std::vector vertBlob; std::vector fragBlob; @@ -762,11 +765,12 @@ struct SPIRVBackendFactory : IShaderBackendFactory std::string vertSource = m_backend.makeVert("#version 330", tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), - tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs); + tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs, + tag.getReflectionType()); std::string fragSource = m_backend.makeFrag("#version 330", tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, - slot.lighting, slot.post, slot.texCount, slot.texs); + tag.getReflectionType(), slot.lighting, slot.post, slot.texCount, slot.texs); pipeBlobs.emplace_back(); Blobs& pipeBlob = pipeBlobs.back(); boo::IShaderPipeline* ret = diff --git a/hecl/lib/Backend/HLSL.cpp b/hecl/lib/Backend/HLSL.cpp index d121d4183..a1ff6c0fd 100644 --- a/hecl/lib/Backend/HLSL.cpp +++ b/hecl/lib/Backend/HLSL.cpp @@ -61,7 +61,7 @@ std::string HLSL::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) co return retval + "};\n"; } -std::string HLSL::GenerateVertToFragStruct(size_t extTexCount, ReflectionType reflectionType) const +std::string HLSL::GenerateVertToFragStruct(size_t extTexCount, bool reflectionCoords) const { std::string retval = "struct VertToFrag\n" @@ -82,7 +82,7 @@ std::string HLSL::GenerateVertToFragStruct(size_t extTexCount, ReflectionType re return retval + "};\n"; } -std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, ReflectionType reflectionType) const +std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const { if (skinSlots == 0) skinSlots = 1; @@ -129,6 +129,7 @@ std::string HLSL::GenerateReflectionExpr(ReflectionType type) const switch (type) { case ReflectionType::None: + default: return "float3(0.0, 0.0, 0.0);\n"; case ReflectionType::Simple: return "reflectionTex.Sample(samp, vtf.reflectTcgs[1]).rgb * vtf.reflectAlpha;\n"; @@ -202,7 +203,7 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w, extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str()); } - if (reflectionCoords) + if (reflectionType != ReflectionType::None) retval += " vtf.reflectTcgs[0] = normalize(mul(indMtx, float4(v.posIn, 1.0)).xz) * float2(0.5, 0.5) + float2(0.5, 0.5);\n" " vtf.reflectTcgs[1] = mul(reflectMtx, float4(v.posIn, 1.0)).xy;\n" " vtf.reflectAlpha = reflectAlpha;\n"; @@ -358,9 +359,11 @@ struct HLSLBackendFactory : IShaderBackendFactory std::string vertSource = m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), - tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr); + tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr, + tag.getReflectionType()); - std::string fragSource = m_backend.makeFrag(tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha); + std::string fragSource = m_backend.makeFrag(tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, + tag.getReflectionType()); ComPtr vertBlob; ComPtr fragBlob; ComPtr pipelineBlob; @@ -495,10 +498,11 @@ struct HLSLBackendFactory : IShaderBackendFactory { std::string vertSource = m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), - tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs); + tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs, + tag.getReflectionType()); std::string fragSource = m_backend.makeFrag(tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha, - slot.lighting, slot.post, slot.texCount, slot.texs); + tag.getReflectionType(), slot.lighting, slot.post, slot.texCount, slot.texs); pipeBlobs.emplace_back(); Blobs& thisPipeBlobs = pipeBlobs.back(); diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index fe7e855a9..36ea80366 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -134,6 +134,7 @@ std::string Metal::GenerateReflectionExpr(ReflectionType type) const switch (type) { case ReflectionType::None: + default: return "float3(0.0, 0.0, 0.0);\n"; case ReflectionType::Simple: return "reflectionTex.sample(samp, vtf.reflectTcgs1).rgb * vtf.reflectAlpha;\n";