Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
HLSL reflection fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Mar 26, 2017
1 parent e88c5a6 commit 8fb5445
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
8 changes: 4 additions & 4 deletions include/hecl/Backend/HLSL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions lib/Backend/GLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<unsigned int> vertBlob;
std::vector<unsigned int> fragBlob;
Expand Down Expand Up @@ -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 =
Expand Down
18 changes: 11 additions & 7 deletions lib/Backend/HLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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<ID3DBlob> vertBlob;
ComPtr<ID3DBlob> fragBlob;
ComPtr<ID3DBlob> pipelineBlob;
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions lib/Backend/Metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 8fb5445

Please sign in to comment.