Skip to content

Commit

Permalink
Add support for mat3 to shader compiler (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
bghgary authored Sep 27, 2023
1 parent 71a89f7 commit c84cc68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Plugins/NativeEngine/Source/NativeEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ namespace Babylon

assert(matrix.size() == size * size);

if constexpr (size < 4)
if constexpr (size < 3)
{
std::array<float, 16> matrixValues{};
size_t index = 0;
Expand Down
13 changes: 13 additions & 0 deletions Plugins/NativeEngine/Source/ShaderCompilerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ namespace Babylon::ShaderCompilerCommon
case NonSamplerUniformsInfo::Uniform::TypeEnum::Mat4:
bgfxType = bgfx::UniformType::Mat4;
break;
case NonSamplerUniformsInfo::Uniform::TypeEnum::Mat3:
bgfxType = bgfx::UniformType::Mat3;
break;
default:
throw std::runtime_error{"Unrecognized uniform type."};
}
Expand Down Expand Up @@ -98,6 +101,11 @@ namespace Babylon::ShaderCompilerCommon
uniform.Type = NonSamplerUniformsInfo::Uniform::TypeEnum::Mat4;
uniform.RegisterSize = 4;
}
else if (spirType.columns == 3 && spirType.vecsize == 3)
{
uniform.Type = NonSamplerUniformsInfo::Uniform::TypeEnum::Mat3;
uniform.RegisterSize = 4;
}
else
{
throw std::runtime_error{"Unrecognized uniform type."};
Expand Down Expand Up @@ -137,6 +145,11 @@ namespace Babylon::ShaderCompilerCommon
uniform.Type = NonSamplerUniformsInfo::Uniform::TypeEnum::Mat4;
uniform.RegisterSize = 4;
}
else if (type.columns == 3 && type.vecsize == 3)
{
uniform.Type = NonSamplerUniformsInfo::Uniform::TypeEnum::Mat3;
uniform.RegisterSize = 4;
}
else
{
throw std::runtime_error{"Unrecognized uniform type."};
Expand Down
3 changes: 2 additions & 1 deletion Plugins/NativeEngine/Source/ShaderCompilerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace Babylon::ShaderCompilerCommon
enum class TypeEnum
{
Vec4,
Mat4
Mat4,
Mat3,
};

std::string Name{};
Expand Down

0 comments on commit c84cc68

Please sign in to comment.