diff --git a/src/ShaderGen/3d/Std3DMaterial.cpp b/src/ShaderGen/3d/Std3DMaterial.cpp index da9c9862..de680407 100644 --- a/src/ShaderGen/3d/Std3DMaterial.cpp +++ b/src/ShaderGen/3d/Std3DMaterial.cpp @@ -3,6 +3,7 @@ #include #include #include"common/MFGetPosition.h" +#include"common/MFGetNormal.h" #include"common/MFRectPrimitive.h" STD_MTL_NAMESPACE_BEGIN @@ -36,6 +37,13 @@ bool Std3DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc) else vsc->AddFunction(cfg->camera?func::GetPosition3DCamera:func::GetPosition3D); + //if(cfg->camera + // &&cfg->local_to_world) + //{ + // vsc->AddFunction(func::GetNormalMatrix); + // vsc->AddFunction(func::GetNormal); + //} + mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT, DescriptorSetType::Global, SBS_ViewportInfo); diff --git a/src/ShaderGen/CMakeLists.txt b/src/ShaderGen/CMakeLists.txt index da6be99a..6a5bb1e8 100644 --- a/src/ShaderGen/CMakeLists.txt +++ b/src/ShaderGen/CMakeLists.txt @@ -39,7 +39,9 @@ set(STD_MTL_HEADER_PATH ${ROOT_INCLUDE_PATH}/hgl/graph/mtl) SET(SHADERGEN_COMMON_FILES ${STD_MTL_HEADER_PATH}/UBOCommon.h ${STD_MTL_HEADER_PATH}/SamplerName.h common/MFCommon.h - common/MFGetPosition.h) + common/MFGetPosition.h + common/MFGetNormal.h +) SOURCE_GROUP("Common" FILES ${SHADERGEN_COMMON_FILES}) diff --git a/src/ShaderGen/common/MFGetNormal.h b/src/ShaderGen/common/MFGetNormal.h new file mode 100644 index 00000000..bf55395b --- /dev/null +++ b/src/ShaderGen/common/MFGetNormal.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +STD_MTL_NAMESPACE_BEGIN +namespace func +{ + constexpr const char *GetNormalMatrix=R"( +mat3 GetNormalMatrix() +{ + return mat3(camera.view*GetLocalToWorld()); +} +)"; + + constexpr const char *GetNormal=R"( +vec3 GetNormal(mat3 normal_matrix,vec3 normal) +{ + return normalize(normal_matrix*normal); +} +)"; +}//namespace func +STD_MTL_NAMESPACE_END