From b6af26fa91cc504814c39c479da99769bced91f4 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 7 Feb 2019 21:55:39 -1000 Subject: [PATCH] addColor term for standard shader model --- hecl/lib/Backend/GLSL.cpp | 12 ++++++++---- hecl/lib/Backend/HLSL.cpp | 15 +++++++++------ hecl/lib/Backend/Metal.cpp | 21 +++++++++++++-------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index e058ac188..a75dc9111 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -234,6 +234,7 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph "const vec4 colorReg1 = vec4(1.0);\n" "const vec4 colorReg2 = vec4(1.0);\n" "const vec4 mulColor = vec4(1.0);\n" + "const vec4 addColor = vec4(0.0);\n" "\n"; std::string texMapDecl; @@ -274,9 +275,10 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph std::string reflectionExpr = GenerateReflectionExpr(reflectionType); if (m_alphaExpr.size()) - retval += " colorOut = vec4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ") * mulColor;\n"; + retval += " colorOut = vec4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + + ") * mulColor + addColor;\n"; else - retval += " colorOut = vec4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0) * mulColor;\n"; + retval += " colorOut = vec4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0) * mulColor + addColor;\n"; return retval + (alphaTest ? GenerateAlphaTest() : "") + "}\n"; } @@ -293,6 +295,7 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph "const vec4 colorReg1 = vec4(1.0);\n" "const vec4 colorReg2 = vec4(1.0);\n" "const vec4 mulColor = vec4(1.0);\n" + "const vec4 addColor = vec4(0.0);\n" "\n"; std::string postSrc; @@ -351,9 +354,10 @@ std::string GLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph if (m_alphaExpr.size()) retval += " colorOut = " + postEntry + "(vec4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + - ")) * mulColor;\n"; + ")) * mulColor + addColor;\n"; else - retval += " colorOut = " + postEntry + "(vec4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor;\n"; + retval += " colorOut = " + postEntry + "(vec4(" + m_colorExpr + " + " + reflectionExpr + + ", 1.0)) * mulColor + addColor;\n"; return retval + (alphaTest ? GenerateAlphaTest() : "") + "}\n"; } diff --git a/hecl/lib/Backend/HLSL.cpp b/hecl/lib/Backend/HLSL.cpp index f15453e8a..261100244 100644 --- a/hecl/lib/Backend/HLSL.cpp +++ b/hecl/lib/Backend/HLSL.cpp @@ -232,7 +232,8 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph "static const float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0);\n" "static const float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0);\n" "static const float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0);\n" - "static const float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n"; + "static const float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n" + "static const float4 addColor = float4(0.0, 0.0, 0.0, 0.0);\n"; std::string texMapDecl; if (m_texMapEnd) @@ -270,9 +271,10 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph retval += " float4 colorOut;\n"; if (m_alphaExpr.size()) - retval += " colorOut = float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ") * mulColor;\n"; + retval += " colorOut = float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + + ") * mulColor + addColor;\n"; else - retval += " colorOut = float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0) * mulColor;\n"; + retval += " colorOut = float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0) * mulColor + addColor;\n"; return retval + (alphaTest ? GenerateAlphaTest() : "") + " return colorOut;\n}\n"; } @@ -288,7 +290,8 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph "static const float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0);\n" "static const float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0);\n" "static const float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0);\n" - "static const float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n"; + "static const float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n" + "static const float4 addColor = float4(0.0, 0.0, 0.0, 0.0);\n"; std::string postSrc; if (!post.m_source.empty()) @@ -345,10 +348,10 @@ std::string HLSL::makeFrag(size_t blockCount, const char** blockNames, bool alph retval += " float4 colorOut;\n"; if (m_alphaExpr.size()) retval += " colorOut = " + postEntry + "(" + (postEntry.size() ? "vtf, " : "") + "float4(" + m_colorExpr + - " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor;\n"; + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor + addColor;\n"; else retval += " colorOut = " + postEntry + "(" + (postEntry.size() ? "vtf, " : "") + "float4(" + m_colorExpr + - " + " + reflectionExpr + ", 1.0)) * mulColor;\n"; + " + " + reflectionExpr + ", 1.0)) * mulColor + addColor;\n"; return retval + (alphaTest ? GenerateAlphaTest() : "") + " return colorOut;\n}\n"; } diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index c1d362284..ca951066b 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -270,13 +270,15 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp " float4 colorReg0 = block0.colorReg0;\n" " float4 colorReg1 = block0.colorReg1;\n" " float4 colorReg2 = block0.colorReg2;\n" - " float4 mulColor = block0.mulColor;\n"; + " float4 mulColor = block0.mulColor;\n" + " float4 addColor = block0.addColor;\n"; } else { retval += " float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0);\n" " float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0);\n" " float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0);\n" - " float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n"; + " float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n" + " float4 addColor = float4(0.0, 0.0, 0.0, 0.0);\n"; } if (m_lighting) { @@ -295,9 +297,10 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp std::string reflectionExpr = GenerateReflectionExpr(reflectionType); if (m_alphaExpr.size()) - retval += " out.color = float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ") * mulColor;\n"; + retval += " out.color = float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + + ") * mulColor + addColor;\n"; else - retval += " out.color = float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0) * mulColor;\n"; + retval += " out.color = float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0) * mulColor + addColor;\n"; return retval + (alphaTest ? GenerateAlphaTest() : "") + " //out.depth = 1.0 - float(int((1.0 - vtf.mvpPos.z) * 16777216.0)) / 16777216.0;\n" @@ -382,13 +385,15 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp " float4 colorReg0 = block0.colorReg0;\n" " float4 colorReg1 = block0.colorReg1;\n" " float4 colorReg2 = block0.colorReg2;\n" - " float4 mulColor = block0.mulColor;\n"; + " float4 mulColor = block0.mulColor;\n" + " float4 addColor = block0.addColor;\n"; } else { retval += " float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0);\n" " float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0);\n" " float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0);\n" - " float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n"; + " float4 mulColor = float4(1.0, 1.0, 1.0, 1.0);\n" + " float4 addColor = float4(0.0, 0.0, 0.0, 0.0);\n"; } if (m_lighting) { @@ -417,7 +422,7 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp ? (extTexCall.size() ? ("samp, clampSamp," + extTexCall + ", ") : "") : "")) : "") + - "float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor;\n"; + "float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor + addColor;\n"; } else { retval += " out.color = " + postEntry + "(" + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + @@ -425,7 +430,7 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp ? (extTexCall.size() ? ("samp, clampSamp," + extTexCall + ", ") : "") : "")) : "") + - "float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor;\n"; + "float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor + addColor;\n"; } return retval + (alphaTest ? GenerateAlphaTest() : "") +