mirror of https://github.com/AxioDL/metaforce.git
HLSL reflection fix
This commit is contained in:
parent
b860d962ae
commit
21e2a26e36
|
@ -16,15 +16,15 @@ struct HLSL : ProgrammableCommon
|
||||||
const TextureInfo* extTexs, ReflectionType reflectionType) const;
|
const TextureInfo* extTexs, ReflectionType reflectionType) const;
|
||||||
std::string makeFrag(bool alphaTest, ReflectionType reflectionType,
|
std::string makeFrag(bool alphaTest, ReflectionType reflectionType,
|
||||||
const ShaderFunction& lighting=ShaderFunction()) const;
|
const ShaderFunction& lighting=ShaderFunction()) const;
|
||||||
std::string makeFrag(bool alphaTest, const ShaderFunction& lighting,
|
std::string makeFrag(bool alphaTest, ReflectionType reflectionType,
|
||||||
ReflectionType reflectionType,
|
const ShaderFunction& lighting,
|
||||||
const ShaderFunction& post, size_t extTexCount,
|
const ShaderFunction& post, size_t extTexCount,
|
||||||
const TextureInfo* extTexs) const;
|
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;
|
||||||
std::string GenerateVertToFragStruct(size_t extTexCount, ReflectionType reflectionType) const;
|
std::string GenerateVertToFragStruct(size_t extTexCount, bool reflectionCoords) const;
|
||||||
std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, ReflectionType reflectionType) const;
|
std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const;
|
||||||
std::string GenerateAlphaTest() const;
|
std::string GenerateAlphaTest() const;
|
||||||
std::string GenerateReflectionExpr(ReflectionType type) const;
|
std::string GenerateReflectionExpr(ReflectionType type) const;
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ std::string GLSL::GenerateReflectionExpr(ReflectionType type) const
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ReflectionType::None:
|
case ReflectionType::None:
|
||||||
|
default:
|
||||||
return "vec3(0.0, 0.0, 0.0);\n";
|
return "vec3(0.0, 0.0, 0.0);\n";
|
||||||
case ReflectionType::Simple:
|
case ReflectionType::Simple:
|
||||||
return "texture(reflectionTex, vtf.reflectTcgs[1]).rgb * vtf.reflectAlpha;\n";
|
return "texture(reflectionTex, vtf.reflectTcgs[1]).rgb * vtf.reflectAlpha;\n";
|
||||||
|
@ -637,10 +638,12 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
std::string vertSource =
|
std::string vertSource =
|
||||||
m_backend.makeVert("#version 330",
|
m_backend.makeVert("#version 330",
|
||||||
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
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",
|
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<unsigned int> vertBlob;
|
std::vector<unsigned int> vertBlob;
|
||||||
std::vector<unsigned int> fragBlob;
|
std::vector<unsigned int> fragBlob;
|
||||||
|
@ -762,11 +765,12 @@ struct SPIRVBackendFactory : IShaderBackendFactory
|
||||||
std::string vertSource =
|
std::string vertSource =
|
||||||
m_backend.makeVert("#version 330",
|
m_backend.makeVert("#version 330",
|
||||||
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,
|
||||||
|
tag.getReflectionType());
|
||||||
|
|
||||||
std::string fragSource = m_backend.makeFrag("#version 330",
|
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,
|
||||||
slot.lighting, slot.post, slot.texCount, slot.texs);
|
tag.getReflectionType(), 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 =
|
||||||
|
|
|
@ -61,7 +61,7 @@ std::string HLSL::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) co
|
||||||
return retval + "};\n";
|
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 =
|
std::string retval =
|
||||||
"struct VertToFrag\n"
|
"struct VertToFrag\n"
|
||||||
|
@ -82,7 +82,7 @@ std::string HLSL::GenerateVertToFragStruct(size_t extTexCount, ReflectionType re
|
||||||
return retval + "};\n";
|
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)
|
if (skinSlots == 0)
|
||||||
skinSlots = 1;
|
skinSlots = 1;
|
||||||
|
@ -129,6 +129,7 @@ std::string HLSL::GenerateReflectionExpr(ReflectionType type) const
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ReflectionType::None:
|
case ReflectionType::None:
|
||||||
|
default:
|
||||||
return "float3(0.0, 0.0, 0.0);\n";
|
return "float3(0.0, 0.0, 0.0);\n";
|
||||||
case ReflectionType::Simple:
|
case ReflectionType::Simple:
|
||||||
return "reflectionTex.Sample(samp, vtf.reflectTcgs[1]).rgb * vtf.reflectAlpha;\n";
|
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());
|
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"
|
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.reflectTcgs[1] = mul(reflectMtx, float4(v.posIn, 1.0)).xy;\n"
|
||||||
" vtf.reflectAlpha = reflectAlpha;\n";
|
" vtf.reflectAlpha = reflectAlpha;\n";
|
||||||
|
@ -358,9 +359,11 @@ struct HLSLBackendFactory : IShaderBackendFactory
|
||||||
|
|
||||||
std::string vertSource =
|
std::string vertSource =
|
||||||
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
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<ID3DBlob> vertBlob;
|
ComPtr<ID3DBlob> vertBlob;
|
||||||
ComPtr<ID3DBlob> fragBlob;
|
ComPtr<ID3DBlob> fragBlob;
|
||||||
ComPtr<ID3DBlob> pipelineBlob;
|
ComPtr<ID3DBlob> pipelineBlob;
|
||||||
|
@ -495,10 +498,11 @@ struct HLSLBackendFactory : IShaderBackendFactory
|
||||||
{
|
{
|
||||||
std::string vertSource =
|
std::string vertSource =
|
||||||
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
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,
|
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();
|
pipeBlobs.emplace_back();
|
||||||
Blobs& thisPipeBlobs = pipeBlobs.back();
|
Blobs& thisPipeBlobs = pipeBlobs.back();
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,7 @@ std::string Metal::GenerateReflectionExpr(ReflectionType type) const
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ReflectionType::None:
|
case ReflectionType::None:
|
||||||
|
default:
|
||||||
return "float3(0.0, 0.0, 0.0);\n";
|
return "float3(0.0, 0.0, 0.0);\n";
|
||||||
case ReflectionType::Simple:
|
case ReflectionType::Simple:
|
||||||
return "reflectionTex.sample(samp, vtf.reflectTcgs1).rgb * vtf.reflectAlpha;\n";
|
return "reflectionTex.sample(samp, vtf.reflectTcgs1).rgb * vtf.reflectAlpha;\n";
|
||||||
|
|
Loading…
Reference in New Issue