mirror of https://github.com/AxioDL/metaforce.git
Add perspective division to texture matrix processing
This commit is contained in:
parent
8b952894b1
commit
7c3bac2951
|
@ -1 +1 @@
|
|||
Subproject commit 71b8893dde162f0b902b241adf30b5b19c9462c0
|
||||
Subproject commit 2a49a8d4475bd97125bffacbe77b73e3724a45be
|
|
@ -186,6 +186,8 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig
|
|||
" gl_Position = proj * vtf.mvPos;\n";
|
||||
}
|
||||
|
||||
retval += " vec4 tmpProj;\n";
|
||||
|
||||
int tcgIdx = 0;
|
||||
for (const TexCoordGen& tcg : m_tcgs)
|
||||
{
|
||||
|
@ -193,9 +195,10 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig
|
|||
retval += hecl::Format(" vtf.tcgs[%u] = %s;\n", tcgIdx,
|
||||
EmitTexGenSource2(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||
else
|
||||
retval += hecl::Format(" vtf.tcgs[%u] = (texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n",
|
||||
tcgIdx, tcg.m_mtx, tcg.m_norm ? "normalize" : "",
|
||||
tcg.m_mtx, EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||
retval += hecl::Format(" tmpProj = texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0);\n"
|
||||
" vtf.tcgs[%u] = (tmpProj / tmpProj.w).xy;\n",
|
||||
tcg.m_mtx, tcg.m_norm ? "normalize" : "",
|
||||
tcg.m_mtx, EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str(), tcgIdx);
|
||||
++tcgIdx;
|
||||
}
|
||||
|
||||
|
@ -206,9 +209,10 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig
|
|||
retval += hecl::Format(" vtf.extTcgs[%u] = %s;\n", i,
|
||||
EmitTexGenSource2(extTex.src, extTex.uvIdx).c_str());
|
||||
else
|
||||
retval += hecl::Format(" vtf.extTcgs[%u] = (texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n",
|
||||
i, extTex.mtxIdx, extTex.normalize ? "normalize" : "",
|
||||
extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
|
||||
retval += hecl::Format(" tmpProj = texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0);\n"
|
||||
" vtf.extTcgs[%u] = (tmpProj / tmpProj.w).xy;\n",
|
||||
extTex.mtxIdx, extTex.normalize ? "normalize" : "",
|
||||
extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str(), i);
|
||||
}
|
||||
|
||||
if (reflectionType != ReflectionType::None)
|
||||
|
|
|
@ -179,6 +179,8 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
" vtf.mvpPos = mul(proj, vtf.mvPos);\n";
|
||||
}
|
||||
|
||||
retval += " float4 tmpProj;\n";
|
||||
|
||||
int tcgIdx = 0;
|
||||
for (const TexCoordGen& tcg : m_tcgs)
|
||||
{
|
||||
|
@ -186,8 +188,10 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
retval += hecl::Format(" vtf.tcgs[%u] = %s;\n", tcgIdx,
|
||||
EmitTexGenSource2(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||
else
|
||||
retval += hecl::Format(" vtf.tcgs[%u] = mul(texMtxs[%u].postMtx, float4(%s(mul(texMtxs[%u].mtx, %s).xyz), 1.0)).xy;\n", tcgIdx, tcg.m_mtx,
|
||||
tcg.m_norm ? "normalize" : "", tcg.m_mtx, EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||
retval += hecl::Format(" tmpProj = mul(texMtxs[%u].postMtx, float4(%s(mul(texMtxs[%u].mtx, %s).xyz), 1.0));\n"
|
||||
" vtf.tcgs[%u] = (tmpProj / tmpProj.w).xy;\n", tcg.m_mtx,
|
||||
tcg.m_norm ? "normalize" : "", tcg.m_mtx,
|
||||
EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str(), tcgIdx);
|
||||
++tcgIdx;
|
||||
}
|
||||
|
||||
|
@ -198,9 +202,10 @@ std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
retval += hecl::Format(" vtf.extTcgs[%u] = %s;\n", i,
|
||||
EmitTexGenSource2(extTex.src, extTex.uvIdx).c_str());
|
||||
else
|
||||
retval += hecl::Format(" vtf.extTcgs[%u] = mul(texMtxs[%u].postMtx, float4(%s(mul(texMtxs[%u].mtx, %s).xyz), 1.0)).xy;\n",
|
||||
i, extTex.mtxIdx, extTex.normalize ? "normalize" : "",
|
||||
extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
|
||||
retval += hecl::Format(" tmpProj = mul(texMtxs[%u].postMtx, float4(%s(mul(texMtxs[%u].mtx, %s).xyz), 1.0));\n"
|
||||
" vtf.extTcgs[%u] = (tmpProj / tmpProj.w).xy;\n",
|
||||
extTex.mtxIdx, extTex.normalize ? "normalize" : "", extTex.mtxIdx,
|
||||
EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str(), i);
|
||||
}
|
||||
|
||||
if (reflectionType != ReflectionType::None)
|
||||
|
@ -235,7 +240,8 @@ std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType,
|
|||
texMapDecl += hecl::Format("Texture2D reflectionTex : register(t%u);\n",
|
||||
m_texMapEnd);
|
||||
std::string retval =
|
||||
"SamplerState samp : register(s0);\n" +
|
||||
"SamplerState samp : register(s0);\n"
|
||||
"SamplerState clampSamp : register(s1);\n" +
|
||||
GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) +
|
||||
texMapDecl + "\n" +
|
||||
lightingSrc + "\n" +
|
||||
|
@ -246,7 +252,7 @@ std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType,
|
|||
if (m_lighting)
|
||||
{
|
||||
if (lighting.m_entry)
|
||||
retval += hecl::Format(" float4 lighting = %s(vtf.mvPos, vtf.mvNorm);\n", lighting.m_entry);
|
||||
retval += hecl::Format(" float4 lighting = %s(vtf.mvPos, vtf.mvNorm, vtf);\n", lighting.m_entry);
|
||||
else
|
||||
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
||||
}
|
||||
|
@ -308,7 +314,8 @@ std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType,
|
|||
}
|
||||
|
||||
std::string retval =
|
||||
"SamplerState samp : register(s0);\n" +
|
||||
"SamplerState samp : register(s0);\n"
|
||||
"SamplerState clampSamp : register(s1);\n" +
|
||||
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) +
|
||||
texMapDecl + "\n" +
|
||||
lightingSrc + "\n" +
|
||||
|
@ -320,7 +327,7 @@ std::string HLSL::makeFrag(bool alphaTest, ReflectionType reflectionType,
|
|||
if (m_lighting)
|
||||
{
|
||||
if (lighting.m_entry)
|
||||
retval += hecl::Format(" float4 lighting = %s(vtf.mvPos, vtf.mvNorm);\n", lighting.m_entry);
|
||||
retval += hecl::Format(" float4 lighting = %s(vtf.mvPos, vtf.mvNorm, vtf);\n", lighting.m_entry);
|
||||
else
|
||||
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "hecl/Backend/Metal.hpp"
|
||||
#if BOO_HAS_METAL
|
||||
#include "hecl/Runtime.hpp"
|
||||
#include <athena/MemoryReader.hpp>
|
||||
#include <athena/MemoryWriter.hpp>
|
||||
#include <boo/graphicsdev/Metal.hpp>
|
||||
|
@ -190,6 +189,8 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
" vtf.mvpPos = vu.proj * vtf.mvPos;\n";
|
||||
}
|
||||
|
||||
retval += " float4 tmpProj;\n";
|
||||
|
||||
int tcgIdx = 0;
|
||||
for (const TexCoordGen& tcg : m_tcgs)
|
||||
{
|
||||
|
@ -197,8 +198,10 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
retval += hecl::Format(" vtf.tcgs%u = %s;\n", tcgIdx,
|
||||
EmitTexGenSource2(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||
else
|
||||
retval += hecl::Format(" vtf.tcgs%u = (texMtxs[%u].postMtx * float4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n", tcgIdx, tcg.m_mtx,
|
||||
tcg.m_norm ? "normalize" : "", tcg.m_mtx, EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||
retval += hecl::Format(" tmpProj = texMtxs[%u].postMtx * float4(%s((texMtxs[%u].mtx * %s).xyz), 1.0);\n"
|
||||
" vtf.tcgs%u = (tmpProj / tmpProj.w).xy;\n", tcg.m_mtx,
|
||||
tcg.m_norm ? "normalize" : "", tcg.m_mtx,
|
||||
EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str(), tcgIdx);
|
||||
++tcgIdx;
|
||||
}
|
||||
|
||||
|
@ -209,8 +212,10 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||
retval += hecl::Format(" vtf.extTcgs%u = %s;\n", i,
|
||||
EmitTexGenSource2(extTex.src, extTex.uvIdx).c_str());
|
||||
else
|
||||
retval += hecl::Format(" vtf.extTcgs%u = (texMtxs[%u].postMtx * float4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n", i, extTex.mtxIdx,
|
||||
extTex.normalize ? "normalize" : "", extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
|
||||
retval += hecl::Format(" tmpProj = texMtxs[%u].postMtx * float4(%s((texMtxs[%u].mtx * %s).xyz), 1.0);\n"
|
||||
" vtf.extTcgs%u = (tmpProj / tmpProj.w).xy;\n", extTex.mtxIdx,
|
||||
extTex.normalize ? "normalize" : "", extTex.mtxIdx,
|
||||
EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str(), i);
|
||||
}
|
||||
|
||||
if (reflectionType != ReflectionType::None)
|
||||
|
@ -250,7 +255,8 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
}
|
||||
|
||||
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n"
|
||||
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n" +
|
||||
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n"
|
||||
"constexpr sampler clampSamp(address::clamp_to_border, border_color::opaque_white, filter::linear, mip_filter::linear);\n" +
|
||||
GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) + "\n" +
|
||||
GenerateFragOutStruct() + "\n" +
|
||||
lightingSrc + "\n" +
|
||||
|
@ -276,7 +282,7 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
if (m_lighting)
|
||||
{
|
||||
if (lighting.m_entry)
|
||||
retval += hecl::Format(" float4 lighting = %s(%s, vtf.mvPos, vtf.mvNorm);\n", lighting.m_entry, blockCall.c_str());
|
||||
retval += hecl::Format(" float4 lighting = %s(%s, vtf.mvPos, vtf.mvNorm, vtf);\n", lighting.m_entry, blockCall.c_str());
|
||||
else
|
||||
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
||||
}
|
||||
|
@ -312,6 +318,10 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
if (post.m_source)
|
||||
postSrc = post.m_source;
|
||||
|
||||
std::string lightingEntry;
|
||||
if (lighting.m_entry)
|
||||
lightingEntry = lighting.m_entry;
|
||||
|
||||
std::string postEntry;
|
||||
if (post.m_entry)
|
||||
postEntry = post.m_entry;
|
||||
|
@ -357,7 +367,8 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
}
|
||||
|
||||
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n"
|
||||
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n" +
|
||||
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n"
|
||||
"constexpr sampler clampSamp(address::clamp_to_border, border_color::opaque_white, filter::linear, mip_filter::linear);\n" +
|
||||
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" +
|
||||
GenerateFragOutStruct() + "\n" +
|
||||
lightingSrc + "\n" +
|
||||
|
@ -384,7 +395,12 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
|||
if (m_lighting)
|
||||
{
|
||||
if (lighting.m_entry)
|
||||
retval += hecl::Format(" float4 lighting = %s(%s, vtf.mvPos, vtf.mvNorm);\n", lighting.m_entry, blockCall.c_str());
|
||||
{
|
||||
if (!strncmp(lighting.m_entry, "EXT", 3))
|
||||
retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf, " + (extTexCall.size() ? (extTexCall + ", ") : "") + ");\n";
|
||||
else
|
||||
retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf);\n";
|
||||
}
|
||||
else
|
||||
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
||||
}
|
||||
|
|
|
@ -98,7 +98,8 @@ struct HECLApplicationCallback : boo::IApplicationCallback
|
|||
gfxF->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||
{
|
||||
boo::SWindowRect mainWindowRect = m_mainWindow->getWindowFrame();
|
||||
renderTex = ctx.newRenderTexture(mainWindowRect.size[0], mainWindowRect.size[1], false, false);
|
||||
renderTex = ctx.newRenderTexture(mainWindowRect.size[0], mainWindowRect.size[1],
|
||||
boo::TextureClampMode::Repeat, 0, 0);
|
||||
|
||||
/* Generate meta structure (usually statically serialized) */
|
||||
hecl::HMDLMeta testMeta;
|
||||
|
@ -149,7 +150,7 @@ struct HECLApplicationCallback : boo::IApplicationCallback
|
|||
tex[i][j][3] = 0xff;
|
||||
}
|
||||
boo::ITexture* texture =
|
||||
ctx.newStaticTexture(256, 256, 1, boo::TextureFormat::RGBA8, tex, 256*256*4);
|
||||
ctx.newStaticTexture(256, 256, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, tex, 256*256*4);
|
||||
|
||||
/* Make vertex uniform buffer */
|
||||
vubo = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(VertexUBO), 1);
|
||||
|
|
Loading…
Reference in New Issue