mirror of https://github.com/AxioDL/metaforce.git
Fixes for extended shaders
This commit is contained in:
parent
0acf4865ca
commit
9531d2bb02
|
@ -1 +1 @@
|
||||||
Subproject commit bec368dfe7722d348c6eb0411e349a3c731ffd58
|
Subproject commit 0ee594438714f38e4de982a4d51fdeaf689dd5c6
|
|
@ -20,11 +20,29 @@ enum class TexGenSrc
|
||||||
UV
|
UV
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class BlendFactor
|
||||||
|
{
|
||||||
|
Zero,
|
||||||
|
One,
|
||||||
|
SrcColor,
|
||||||
|
InvSrcColor,
|
||||||
|
DstColor,
|
||||||
|
InvDstColor,
|
||||||
|
SrcAlpha,
|
||||||
|
InvSrcAlpha,
|
||||||
|
DstAlpha,
|
||||||
|
InvDstAlpha,
|
||||||
|
SrcColor1,
|
||||||
|
InvSrcColor1,
|
||||||
|
Original = 0xff
|
||||||
|
};
|
||||||
|
|
||||||
struct TextureInfo
|
struct TextureInfo
|
||||||
{
|
{
|
||||||
TexGenSrc src;
|
TexGenSrc src;
|
||||||
|
int mapIdx;
|
||||||
int uvIdx;
|
int uvIdx;
|
||||||
int mtx;
|
int mtxIdx;
|
||||||
bool normalize;
|
bool normalize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ struct GLSL : ProgrammableCommon
|
||||||
std::string makeFrag(const char* glslVer,
|
std::string makeFrag(const char* glslVer,
|
||||||
const ShaderFunction& lighting,
|
const ShaderFunction& lighting,
|
||||||
const ShaderFunction& post,
|
const ShaderFunction& post,
|
||||||
size_t extTexCount) const;
|
size_t extTexCount, const TextureInfo* extTexs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;
|
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "Backend.hpp"
|
#include "Backend.hpp"
|
||||||
#include "hecl/Runtime.hpp"
|
#include "hecl/Runtime.hpp"
|
||||||
#include <athena/DNA.hpp>
|
#include <athena/DNA.hpp>
|
||||||
#include <boo/graphicsdev/IGraphicsDataFactory.hpp>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -20,8 +19,8 @@ struct ProgrammableCommon : IBackend
|
||||||
|
|
||||||
std::string m_colorExpr;
|
std::string m_colorExpr;
|
||||||
std::string m_alphaExpr;
|
std::string m_alphaExpr;
|
||||||
boo::BlendFactor m_blendSrc;
|
BlendFactor m_blendSrc;
|
||||||
boo::BlendFactor m_blendDst;
|
BlendFactor m_blendDst;
|
||||||
bool m_lighting = false;
|
bool m_lighting = false;
|
||||||
|
|
||||||
struct TexSampling
|
struct TexSampling
|
||||||
|
|
|
@ -133,6 +133,8 @@ public:
|
||||||
const char** blockNames = nullptr;
|
const char** blockNames = nullptr;
|
||||||
size_t texCount = 0;
|
size_t texCount = 0;
|
||||||
const Backend::TextureInfo* texs = nullptr;
|
const Backend::TextureInfo* texs = nullptr;
|
||||||
|
Backend::BlendFactor srcFactor = Backend::BlendFactor::Original;
|
||||||
|
Backend::BlendFactor dstFactor = Backend::BlendFactor::Original;
|
||||||
};
|
};
|
||||||
std::vector<ExtensionSlot> m_extensionSlots;
|
std::vector<ExtensionSlot> m_extensionSlots;
|
||||||
|
|
||||||
|
@ -146,7 +148,8 @@ public:
|
||||||
/* Strings must remain resident!! (intended to be stored static const) */
|
/* Strings must remain resident!! (intended to be stored static const) */
|
||||||
unsigned registerExtensionSlot(Function lighting, Function post,
|
unsigned registerExtensionSlot(Function lighting, Function post,
|
||||||
size_t blockCount, const char** blockNames,
|
size_t blockCount, const char** blockNames,
|
||||||
size_t texCount, const Backend::TextureInfo* texs)
|
size_t texCount, const Backend::TextureInfo* texs,
|
||||||
|
Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor)
|
||||||
{
|
{
|
||||||
m_extensionSlots.emplace_back();
|
m_extensionSlots.emplace_back();
|
||||||
ExtensionSlot& slot = m_extensionSlots.back();
|
ExtensionSlot& slot = m_extensionSlots.back();
|
||||||
|
@ -156,6 +159,8 @@ public:
|
||||||
slot.blockNames = blockNames;
|
slot.blockNames = blockNames;
|
||||||
slot.texCount = texCount;
|
slot.texCount = texCount;
|
||||||
slot.texs = texs;
|
slot.texs = texs;
|
||||||
|
slot.srcFactor = srcFactor;
|
||||||
|
slot.dstFactor = dstFactor;
|
||||||
return m_extensionSlots.size() - 1;
|
return m_extensionSlots.size() - 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -169,14 +169,13 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig
|
||||||
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 (extTex.mtx < 0)
|
if (extTex.mtxIdx < 0)
|
||||||
retval += hecl::Format(" vtf.extTcgs[%u] = %s;\n", extIdx,
|
retval += hecl::Format(" vtf.extTcgs[%u] = %s;\n", extIdx,
|
||||||
EmitTexGenSource2(extTex.src, extTex.uvIdx).c_str());
|
EmitTexGenSource2(extTex.src, extTex.uvIdx).c_str());
|
||||||
else
|
else
|
||||||
retval += hecl::Format(" vtf.extTcgs[%u] = (texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n",
|
retval += hecl::Format(" vtf.extTcgs[%u] = (texMtxs[%u].postMtx * vec4(%s((texMtxs[%u].mtx * %s).xyz), 1.0)).xy;\n",
|
||||||
extIdx, extTex.mtx,
|
extIdx, extTex.mtxIdx, extTex.normalize ? "normalize" : "",
|
||||||
extTex.normalize ? "normalize" : "", extTex.mtx,
|
extTex.mtxIdx, EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
|
||||||
EmitTexGenSource4(extTex.src, extTex.uvIdx).c_str());
|
|
||||||
++extIdx;
|
++extIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +226,7 @@ std::string GLSL::makeFrag(const char* glslVer,
|
||||||
std::string GLSL::makeFrag(const char* glslVer,
|
std::string GLSL::makeFrag(const char* glslVer,
|
||||||
const ShaderFunction& lighting,
|
const ShaderFunction& lighting,
|
||||||
const ShaderFunction& post,
|
const ShaderFunction& post,
|
||||||
size_t extTexCount) const
|
size_t extTexCount, const TextureInfo* extTexs) const
|
||||||
{
|
{
|
||||||
std::string lightingSrc;
|
std::string lightingSrc;
|
||||||
if (lighting.m_source)
|
if (lighting.m_source)
|
||||||
|
@ -245,6 +244,13 @@ std::string GLSL::makeFrag(const char* glslVer,
|
||||||
for (unsigned i=0 ; i<m_texMapEnd ; ++i)
|
for (unsigned i=0 ; i<m_texMapEnd ; ++i)
|
||||||
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n", i, i);
|
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n", i, i);
|
||||||
|
|
||||||
|
for (int i=0 ; i<extTexCount ; ++i)
|
||||||
|
{
|
||||||
|
const TextureInfo& extTex = extTexs[i];
|
||||||
|
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n",
|
||||||
|
extTex.mapIdx, extTex.mapIdx);
|
||||||
|
}
|
||||||
|
|
||||||
std::string retval = std::string(glslVer) + "\n" BOO_GLSL_BINDING_HEAD +
|
std::string retval = std::string(glslVer) + "\n" BOO_GLSL_BINDING_HEAD +
|
||||||
GenerateVertToFragStruct(extTexCount) +
|
GenerateVertToFragStruct(extTexCount) +
|
||||||
"\nlayout(location=0) out vec4 colorOut;\n" +
|
"\nlayout(location=0) out vec4 colorOut;\n" +
|
||||||
|
@ -324,9 +330,10 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
||||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
m_backend.m_texMapEnd, STD_TEXNAMES,
|
m_backend.m_texMapEnd, STD_TEXNAMES,
|
||||||
2, STD_BLOCKNAMES,
|
2, STD_BLOCKNAMES,
|
||||||
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
|
boo::BlendFactor(m_backend.m_blendSrc),
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
boo::BlendFactor(m_backend.m_blendDst),
|
||||||
tag.getBackfaceCulling());
|
tag.getPrimType(), tag.getDepthTest(),
|
||||||
|
tag.getDepthWrite(), tag.getBackfaceCulling());
|
||||||
if (!objOut)
|
if (!objOut)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
|
|
||||||
|
@ -397,16 +404,17 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
||||||
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
||||||
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount,
|
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount,
|
||||||
slot.texs),
|
slot.texs),
|
||||||
m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount));
|
m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount, slot.texs));
|
||||||
cachedSz += sources.back().first.size() + 1;
|
cachedSz += sources.back().first.size() + 1;
|
||||||
cachedSz += sources.back().second.size() + 1;
|
cachedSz += sources.back().second.size() + 1;
|
||||||
boo::IShaderPipeline* ret =
|
boo::IShaderPipeline* ret =
|
||||||
static_cast<boo::GLDataFactory::Context&>(ctx).
|
static_cast<boo::GLDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(),
|
newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(),
|
||||||
m_backend.m_texMapEnd, STD_TEXNAMES, bc, bn,
|
8, STD_TEXNAMES, bc, bn,
|
||||||
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
|
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendSrc : slot.srcFactor),
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendDst : slot.dstFactor),
|
||||||
tag.getBackfaceCulling());
|
tag.getPrimType(), tag.getDepthTest(),
|
||||||
|
tag.getDepthWrite(), tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
returnFunc(ret);
|
returnFunc(ret);
|
||||||
|
@ -434,8 +442,8 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
||||||
const ShaderTag& tag = data.m_tag;
|
const ShaderTag& tag = data.m_tag;
|
||||||
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
||||||
atUint8 texMapEnd = r.readUByte();
|
atUint8 texMapEnd = r.readUByte();
|
||||||
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte());
|
||||||
boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte());
|
hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte());
|
||||||
|
|
||||||
if (texMapEnd > 8)
|
if (texMapEnd > 8)
|
||||||
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
|
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
|
||||||
|
@ -455,9 +463,10 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
||||||
boo::IShaderPipeline* ret =
|
boo::IShaderPipeline* ret =
|
||||||
static_cast<boo::GLDataFactory::Context&>(ctx).
|
static_cast<boo::GLDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
texMapEnd, STD_TEXNAMES, bc, bn,
|
8, STD_TEXNAMES, bc, bn,
|
||||||
blendSrc, blendDst, tag.getPrimType(),
|
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
|
||||||
|
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
tag.getBackfaceCulling());
|
tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
|
@ -500,8 +509,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
static_cast<boo::VulkanDataFactory::Context&>(ctx).
|
static_cast<boo::VulkanDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(ctx),
|
vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(ctx),
|
||||||
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
|
boo::BlendFactor(m_backend.m_blendSrc), boo::BlendFactor(m_backend.m_blendDst),
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
tag.getBackfaceCulling());
|
tag.getBackfaceCulling());
|
||||||
if (!objOut)
|
if (!objOut)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
|
@ -609,7 +618,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
||||||
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs);
|
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs);
|
||||||
|
|
||||||
std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount);
|
std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount, slot.texs);
|
||||||
pipeBlobs.emplace_back();
|
pipeBlobs.emplace_back();
|
||||||
Blobs& pipeBlob = pipeBlobs.back();
|
Blobs& pipeBlob = pipeBlobs.back();
|
||||||
boo::IShaderPipeline* ret =
|
boo::IShaderPipeline* ret =
|
||||||
|
@ -617,8 +626,11 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
pipeBlob.vert, pipeBlob.frag, pipeBlob.pipeline,
|
pipeBlob.vert, pipeBlob.frag, pipeBlob.pipeline,
|
||||||
tag.newVertexFormat(ctx),
|
tag.newVertexFormat(ctx),
|
||||||
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
|
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ?
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
m_backend.m_blendSrc : slot.srcFactor),
|
||||||
|
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ?
|
||||||
|
m_backend.m_blendDst : slot.dstFactor),
|
||||||
|
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
tag.getBackfaceCulling());
|
tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
|
@ -676,8 +688,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
const ShaderTag& tag = data.m_tag;
|
const ShaderTag& tag = data.m_tag;
|
||||||
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
||||||
size_t texCount = size_t(r.readByte());
|
size_t texCount = size_t(r.readByte());
|
||||||
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte());
|
||||||
boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte());
|
hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte());
|
||||||
|
|
||||||
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
|
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
|
||||||
{
|
{
|
||||||
|
@ -701,8 +713,9 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
newShaderPipeline(nullptr, nullptr,
|
newShaderPipeline(nullptr, nullptr,
|
||||||
vertBlob, fragBlob, pipelineBlob,
|
vertBlob, fragBlob, pipelineBlob,
|
||||||
tag.newVertexFormat(ctx),
|
tag.newVertexFormat(ctx),
|
||||||
blendSrc, blendDst, tag.getPrimType(),
|
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
|
||||||
|
tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
tag.getBackfaceCulling());
|
tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
|
|
|
@ -267,19 +267,19 @@ void ProgrammableCommon::reset(const IR& ir, Diagnostics& diag, const char* back
|
||||||
bool doAlpha = false;
|
bool doAlpha = false;
|
||||||
if (!rootCall.m_call.m_name.compare("HECLOpaque"))
|
if (!rootCall.m_call.m_name.compare("HECLOpaque"))
|
||||||
{
|
{
|
||||||
m_blendSrc = boo::BlendFactor::One;
|
m_blendSrc = BlendFactor::One;
|
||||||
m_blendDst = boo::BlendFactor::Zero;
|
m_blendDst = BlendFactor::Zero;
|
||||||
}
|
}
|
||||||
else if (!rootCall.m_call.m_name.compare("HECLAlpha"))
|
else if (!rootCall.m_call.m_name.compare("HECLAlpha"))
|
||||||
{
|
{
|
||||||
m_blendSrc = boo::BlendFactor::SrcAlpha;
|
m_blendSrc = BlendFactor::SrcAlpha;
|
||||||
m_blendDst = boo::BlendFactor::InvSrcAlpha;
|
m_blendDst = BlendFactor::InvSrcAlpha;
|
||||||
doAlpha = true;
|
doAlpha = true;
|
||||||
}
|
}
|
||||||
else if (!rootCall.m_call.m_name.compare("HECLAdditive"))
|
else if (!rootCall.m_call.m_name.compare("HECLAdditive"))
|
||||||
{
|
{
|
||||||
m_blendSrc = boo::BlendFactor::SrcAlpha;
|
m_blendSrc = BlendFactor::SrcAlpha;
|
||||||
m_blendDst = boo::BlendFactor::One;
|
m_blendDst = BlendFactor::One;
|
||||||
doAlpha = true;
|
doAlpha = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue