5 #if defined(LUG_SYSTEM_ANDROID) 6 #include <android/asset_manager.h> 12 #include <shaderc/shaderc.hpp> 22 std::string shaderRoot,
27 case ::lug::Graphics::Render::Technique::Type::Forward:
40 #if defined(LUG_SYSTEM_ANDROID) 45 LUG_EXCEPT(FileNotFoundException,
"Can't open Android asset");
49 uint32_t size = AAsset_getLength(asset);
52 LUG_EXCEPT(FileNotFoundException,
"Android asset is empty");
59 AAsset_read(asset, reinterpret_cast<char*>(&content[0]), size);
62 std::ifstream file(filename);
65 LUG_EXCEPT(FileNotFoundException,
"Can't find shader file");
68 std::string content = std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
75 shaderc::Compiler compiler;
76 shaderc::CompileOptions options;
85 options.AddMacroDefinition(
"DISPLAY_MODE", std::to_string(static_cast<uint8_t>(extraPart.
displayMode)));
89 options.AddMacroDefinition(
"IN_POSITION", std::to_string(primitivePart.
positionVertexData));
90 options.AddMacroDefinition(
"IN_NORMAL", std::to_string(primitivePart.
normalVertexData));
91 options.AddMacroDefinition(
"IN_TANGENT", std::to_string(primitivePart.
tangentVertexData));
92 options.AddMacroDefinition(
"IN_UV", std::to_string(primitivePart.
countTexCoord));
93 options.AddMacroDefinition(
"IN_COLOR", std::to_string(primitivePart.
countColor));
98 options.AddMacroDefinition(
"TEXTURE_COLOR", materialPart.
baseColorInfo != 0b11 ?
"1" :
"0");
99 options.AddMacroDefinition(
"TEXTURE_COLOR_UV",
"inUV" + std::to_string(materialPart.
baseColorInfo));
101 options.AddMacroDefinition(
"TEXTURE_METALLIC_ROUGHNESS", materialPart.
metallicRoughnessInfo != 0b11 ?
"1" :
"0");
102 options.AddMacroDefinition(
"TEXTURE_METALLIC_ROUGHNESS_UV",
"inUV" + std::to_string(materialPart.
metallicRoughnessInfo));
104 options.AddMacroDefinition(
"TEXTURE_NORMAL", materialPart.
normalInfo != 0b11 ?
"1" :
"0");
105 options.AddMacroDefinition(
"TEXTURE_NORMAL_UV",
"inUV" + std::to_string(materialPart.
normalInfo));
107 options.AddMacroDefinition(
"TEXTURE_OCCLUSION", materialPart.
occlusionInfo != 0b11 ?
"1" :
"0");
108 options.AddMacroDefinition(
"TEXTURE_OCCLUSION_UV",
"inUV" + std::to_string(materialPart.
occlusionInfo));
110 options.AddMacroDefinition(
"TEXTURE_EMISSIVE", materialPart.
emissiveInfo != 0b11 ?
"1" :
"0");
111 options.AddMacroDefinition(
"TEXTURE_EMISSIVE_UV",
"inUV" + std::to_string(materialPart.
emissiveInfo));
116 options.AddMacroDefinition(
"TEXTURE_IRRADIANCE_MAP", extraPart.
irradianceMapInfo ?
"1" :
"0");
117 options.AddMacroDefinition(
"TEXTURE_PREFILTERED_MAP", extraPart.
prefilteredMapInfo ?
"1" :
"0");
122 uint8_t location = 2;
125 options.AddMacroDefinition(
"IN_TANGENT_LOCATION", std::to_string(location++));
129 options.AddMacroDefinition(
"IN_UV_" + std::to_string(i) +
"_LOCATION", std::to_string(location++));
132 for (uint8_t i = 0; i < primitivePart.
countColor; ++i) {
133 options.AddMacroDefinition(
"IN_COLOR_" + std::to_string(i) +
"_LOCATION", std::to_string(location++));
136 options.AddMacroDefinition(
"IN_FREE_LOCATION", std::to_string(location++));
144 options.AddMacroDefinition(
"TEXTURE_COLOR_BINDING", std::to_string(binding++));
148 options.AddMacroDefinition(
"TEXTURE_METALLIC_ROUGHNESS_BINDING", std::to_string(binding++));
152 options.AddMacroDefinition(
"TEXTURE_NORMAL_BINDING", std::to_string(binding++));
156 options.AddMacroDefinition(
"TEXTURE_OCCLUSION_BINDING", std::to_string(binding++));
160 options.AddMacroDefinition(
"TEXTURE_EMISSIVE_BINDING", std::to_string(binding++));
164 options.AddMacroDefinition(
"TEXTURE_IRRADIANCE_MAP_BINDING", std::to_string(binding++));
168 options.AddMacroDefinition(
"TEXTURE_BRDF_LUT_BINDING", std::to_string(binding++));
169 options.AddMacroDefinition(
"TEXTURE_PREFILTERED_MAP_BINDING", std::to_string(binding++));
177 return shaderc_glsl_vertex_shader;
179 return shaderc_glsl_fragment_shader;
182 return shaderc_shader_kind{};
185 shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(content, kind, filename.c_str(), options);
187 if (module.GetCompilationStatus() != shaderc_compilation_status_success) {
188 LUG_EXCEPT(InternalErrorException, module.GetErrorMessage());
191 std::vector<uint32_t> result(module.cbegin(), module.cend());
Id of the Pipeline. It's a concatenation of three parts: PrimitivePart, MaterialPart and PipelinePart...
Describes the material. How is the material composed, with textures, no textures, etc...
uint32_t occlusionInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
uint32_t countColor
The number of colors (maximum 3).
uint32_t baseColorInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
uint32_t positionVertexData
0 if no attribute position.
static std::vector< uint32_t > buildShaderFromFile(std::string filename, Type type, Pipeline::Id id)
static ANativeActivity * activity
static std::vector< uint32_t > buildShaderFromString(std::string filename, std::string content, Type type, Pipeline::Id id)
static std::vector< uint32_t > buildShader(std::string shaderRoot, ::lug::Graphics::Render::Technique::Type technique, Type type, Pipeline::Id id)
uint32_t emissiveInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
uint32_t normalVertexData
0 if no attribute normal.
uint32_t metallicRoughnessInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
#define LUG_EXCEPT(type, desc)
uint32_t normalInfo
0b00 texture with UV0, 0b01 texture with UV1, 0b10 texture with UV2, 0b11 no texture.
uint32_t tangentVertexData
0 if no attribute tangeant.
uint32_t countTexCoord
The number of texcoord (maximum 3).