11 #include "impeller/scene/importer/scene_flatbuffers.h"
14 #include "impeller/scene/shaders/unlit.frag.h"
28 const fb::Material& material,
29 const std::vector<std::shared_ptr<Texture>>&
textures) {
30 switch (material.type()) {
31 case fb::MaterialType::kUnlit:
33 case fb::MaterialType::kPhysicallyBased:
39 return std::make_unique<UnlitMaterial>();
43 return std::make_unique<PhysicallyBasedMaterial>();
72 const fb::Material& material,
73 const std::vector<std::shared_ptr<Texture>>&
textures) {
74 if (material.type() != fb::MaterialType::kUnlit) {
75 VALIDATION_LOG <<
"Cannot unpack unlit material because the ipscene "
76 "material type is not unlit.";
82 if (material.base_color_factor()) {
86 if (material.base_color_texture() >= 0 &&
87 material.base_color_texture() <
static_cast<int32_t
>(
textures.size())) {
88 result->SetColorTexture(
textures[material.base_color_texture()]);
101 color_texture_ = std::move(color_texture);
114 UnlitFragmentShader::FragInfo info;
117 UnlitFragmentShader::BindFragInfo(pass, buffer.
EmplaceUniform(info));
121 sampler_descriptor.
label =
"Trilinear";
125 UnlitFragmentShader::BindBaseColorTexture(
128 scene_context.
GetContext()->GetSamplerLibrary()->GetSampler(
129 sampler_descriptor));
136 std::unique_ptr<PhysicallyBasedMaterial>
138 const fb::Material& material,
139 const std::vector<std::shared_ptr<Texture>>&
textures) {
140 if (material.type() != fb::MaterialType::kPhysicallyBased) {
141 VALIDATION_LOG <<
"Cannot unpack unlit material because the ipscene "
142 "material type is not unlit.";
148 result->SetAlbedo(material.base_color_factor()
151 result->SetRoughness(material.roughness_factor());
152 result->SetMetallic(material.metallic_factor());
154 if (material.base_color_texture() >= 0 &&
155 material.base_color_texture() <
static_cast<int32_t
>(
textures.size())) {
156 result->SetAlbedoTexture(
textures[material.base_color_texture()]);
157 result->SetVertexColorWeight(0);
159 if (material.metallic_roughness_texture() >= 0 &&
160 material.metallic_roughness_texture() <
161 static_cast<int32_t
>(
textures.size())) {
162 result->SetMetallicRoughnessTexture(
163 textures[material.metallic_roughness_texture()]);
165 if (material.normal_texture() >= 0 &&
166 material.normal_texture() <
static_cast<int32_t
>(
textures.size())) {
167 result->SetNormalTexture(
textures[material.normal_texture()]);
169 if (material.occlusion_texture() >= 0 &&
170 material.occlusion_texture() <
static_cast<int32_t
>(
textures.size())) {
171 result->SetOcclusionTexture(
textures[material.occlusion_texture()]);
184 roughness_ = roughness;
188 metallic_ = metallic;
192 std::shared_ptr<Texture> albedo_texture) {
193 albedo_texture_ = std::move(albedo_texture);
197 std::shared_ptr<Texture> metallic_roughness_texture) {
198 metallic_roughness_texture_ = std::move(metallic_roughness_texture);
202 std::shared_ptr<Texture> normal_texture) {
203 normal_texture_ = std::move(normal_texture);
207 std::shared_ptr<Texture> occlusion_texture) {
208 occlusion_texture_ = std::move(occlusion_texture);
212 std::shared_ptr<Texture> environment_map) {
213 environment_map_ = std::move(environment_map);