10 #include "impeller/scene/importer/scene_flatbuffers.h"
13 #include "impeller/scene/shaders/unlit.frag.h"
27 const fb::Material& material,
28 const std::vector<std::shared_ptr<Texture>>& textures) {
29 switch (material.type()) {
30 case fb::MaterialType::kUnlit:
32 case fb::MaterialType::kPhysicallyBased:
38 return std::make_unique<UnlitMaterial>();
42 return std::make_unique<PhysicallyBasedMaterial>();
71 const fb::Material& material,
72 const std::vector<std::shared_ptr<Texture>>& textures) {
73 if (material.type() != fb::MaterialType::kUnlit) {
74 VALIDATION_LOG <<
"Cannot unpack unlit material because the ipscene "
75 "material type is not unlit.";
81 if (material.base_color_factor()) {
85 if (material.base_color_texture() >= 0 &&
86 material.base_color_texture() <
static_cast<int32_t
>(textures.size())) {
87 result->SetColorTexture(textures[material.base_color_texture()]);
100 color_texture_ = std::move(color_texture);
113 UnlitFragmentShader::FragInfo info;
116 UnlitFragmentShader::BindFragInfo(command, buffer.
EmplaceUniform(info));
120 sampler_descriptor.
label =
"Trilinear";
124 UnlitFragmentShader::BindBaseColorTexture(
127 scene_context.
GetContext()->GetSamplerLibrary()->GetSampler(
128 sampler_descriptor));
135 std::unique_ptr<PhysicallyBasedMaterial>
137 const fb::Material& material,
138 const std::vector<std::shared_ptr<Texture>>& textures) {
139 if (material.type() != fb::MaterialType::kPhysicallyBased) {
140 VALIDATION_LOG <<
"Cannot unpack unlit material because the ipscene "
141 "material type is not unlit.";
147 result->SetAlbedo(material.base_color_factor()
150 result->SetRoughness(material.roughness_factor());
151 result->SetMetallic(material.metallic_factor());
153 if (material.base_color_texture() >= 0 &&
154 material.base_color_texture() <
static_cast<int32_t
>(textures.size())) {
155 result->SetAlbedoTexture(textures[material.base_color_texture()]);
156 result->SetVertexColorWeight(0);
158 if (material.metallic_roughness_texture() >= 0 &&
159 material.metallic_roughness_texture() <
160 static_cast<int32_t
>(textures.size())) {
161 result->SetMetallicRoughnessTexture(
162 textures[material.metallic_roughness_texture()]);
164 if (material.normal_texture() >= 0 &&
165 material.normal_texture() <
static_cast<int32_t
>(textures.size())) {
166 result->SetNormalTexture(textures[material.normal_texture()]);
168 if (material.occlusion_texture() >= 0 &&
169 material.occlusion_texture() <
static_cast<int32_t
>(textures.size())) {
170 result->SetOcclusionTexture(textures[material.occlusion_texture()]);
183 roughness_ = roughness;
187 metallic_ = metallic;
191 std::shared_ptr<Texture> albedo_texture) {
192 albedo_texture_ = std::move(albedo_texture);
196 std::shared_ptr<Texture> metallic_roughness_texture) {
197 metallic_roughness_texture_ = std::move(metallic_roughness_texture);
201 std::shared_ptr<Texture> normal_texture) {
202 normal_texture_ = std::move(normal_texture);
206 std::shared_ptr<Texture> occlusion_texture) {
207 occlusion_texture_ = std::move(occlusion_texture);
211 std::shared_ptr<Texture> environment_map) {
212 environment_map_ = std::move(environment_map);