Flutter Impeller
material.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <memory>
8 
10 #include "impeller/core/texture.h"
13 #include "impeller/scene/importer/scene_flatbuffers.h"
15 
16 namespace impeller {
17 namespace scene {
18 
19 class SceneContext;
20 struct SceneContextOptions;
21 class Geometry;
22 
23 class UnlitMaterial;
24 class PhysicallyBasedMaterial;
25 
26 class Material {
27  public:
28  struct BlendConfig {
35  };
36 
37  struct StencilConfig {
40  };
41 
42  static std::unique_ptr<Material> MakeFromFlatbuffer(
43  const fb::Material& material,
44  const std::vector<std::shared_ptr<Texture>>& textures);
45 
46  static std::unique_ptr<UnlitMaterial> MakeUnlit();
47  static std::unique_ptr<PhysicallyBasedMaterial> MakePhysicallyBased();
48 
49  virtual ~Material();
50 
51  void SetVertexColorWeight(Scalar weight);
52  void SetBlendConfig(BlendConfig blend_config);
53  void SetStencilConfig(StencilConfig stencil_config);
54 
55  void SetTranslucent(bool is_translucent);
56 
58 
59  virtual MaterialType GetMaterialType() const = 0;
60 
61  virtual void BindToCommand(const SceneContext& scene_context,
62  HostBuffer& buffer,
63  Command& command) const = 0;
64 
65  protected:
69  bool is_translucent_ = false;
70 };
71 
72 class UnlitMaterial final : public Material {
73  public:
74  static std::unique_ptr<UnlitMaterial> MakeFromFlatbuffer(
75  const fb::Material& material,
76  const std::vector<std::shared_ptr<Texture>>& textures);
77 
79 
80  void SetColor(Color color);
81 
82  void SetColorTexture(std::shared_ptr<Texture> color_texture);
83 
84  // |Material|
85  MaterialType GetMaterialType() const override;
86 
87  // |Material|
88  void BindToCommand(const SceneContext& scene_context,
89  HostBuffer& buffer,
90  Command& command) const override;
91 
92  private:
93  Color color_ = Color::White();
94  std::shared_ptr<Texture> color_texture_;
95 };
96 
97 class PhysicallyBasedMaterial final : public Material {
98  public:
99  static std::unique_ptr<PhysicallyBasedMaterial> MakeFromFlatbuffer(
100  const fb::Material& material,
101  const std::vector<std::shared_ptr<Texture>>& textures);
102 
104 
105  void SetAlbedo(Color albedo);
106  void SetRoughness(Scalar roughness);
107  void SetMetallic(Scalar metallic);
108 
109  void SetAlbedoTexture(std::shared_ptr<Texture> albedo_texture);
111  std::shared_ptr<Texture> metallic_roughness_texture);
112  void SetNormalTexture(std::shared_ptr<Texture> normal_texture);
113  void SetOcclusionTexture(std::shared_ptr<Texture> occlusion_texture);
114 
115  void SetEnvironmentMap(std::shared_ptr<Texture> environment_map);
116 
117  // |Material|
118  MaterialType GetMaterialType() const override;
119 
120  // |Material|
121  void BindToCommand(const SceneContext& scene_context,
122  HostBuffer& buffer,
123  Command& command) const override;
124 
125  private:
126  Color albedo_ = Color::White();
127  Scalar metallic_ = 0.5;
128  Scalar roughness_ = 0.5;
129 
130  std::shared_ptr<Texture> albedo_texture_;
131  std::shared_ptr<Texture> metallic_roughness_texture_;
132  std::shared_ptr<Texture> normal_texture_;
133  std::shared_ptr<Texture> occlusion_texture_;
134 
135  std::shared_ptr<Texture> environment_map_;
136 };
137 
138 } // namespace scene
139 } // namespace impeller
impeller::Command
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Definition: command.h:99
impeller::scene::PhysicallyBasedMaterial::SetEnvironmentMap
void SetEnvironmentMap(std::shared_ptr< Texture > environment_map)
Definition: material.cc:211
impeller::scene::Material::GetMaterialType
virtual MaterialType GetMaterialType() const =0
pipeline_key.h
impeller::scene::Material::StencilConfig
Definition: material.h:37
impeller::Scalar
float Scalar
Definition: scalar.h:15
impeller::scene::PhysicallyBasedMaterial::SetMetallic
void SetMetallic(Scalar metallic)
Definition: material.cc:187
impeller::scene::PhysicallyBasedMaterial::SetMetallicRoughnessTexture
void SetMetallicRoughnessTexture(std::shared_ptr< Texture > metallic_roughness_texture)
Definition: material.cc:196
impeller::scene::Material::BlendConfig::color_op
BlendOperation color_op
Definition: material.h:29
impeller::BlendFactor
BlendFactor
Definition: formats.h:152
impeller::Color
Definition: color.h:122
impeller::BlendFactor::kOneMinusSourceAlpha
@ kOneMinusSourceAlpha
impeller::HostBuffer
Definition: host_buffer.h:20
impeller::scene::Material::BlendConfig::alpha_op
BlendOperation alpha_op
Definition: material.h:32
impeller::scene::PhysicallyBasedMaterial::SetAlbedo
void SetAlbedo(Color albedo)
Definition: material.cc:179
impeller::scene::UnlitMaterial::~UnlitMaterial
~UnlitMaterial()
formats.h
impeller::scene::UnlitMaterial::SetColorTexture
void SetColorTexture(std::shared_ptr< Texture > color_texture)
Definition: material.cc:100
impeller::scene::Material::MakePhysicallyBased
static std::unique_ptr< PhysicallyBasedMaterial > MakePhysicallyBased()
Definition: material.cc:42
impeller::scene::Material::BlendConfig::destination_alpha_factor
BlendFactor destination_alpha_factor
Definition: material.h:34
impeller::scene::Material::SetBlendConfig
void SetBlendConfig(BlendConfig blend_config)
Definition: material.cc:50
impeller::scene::SceneContext
Definition: scene_context.h:39
impeller::scene::Material::blend_config_
BlendConfig blend_config_
Definition: material.h:67
impeller::scene::Material::GetContextOptions
SceneContextOptions GetContextOptions(const RenderPass &pass) const
Definition: material.cc:62
impeller::StencilOperation
StencilOperation
Definition: formats.h:505
impeller::scene::Material::BindToCommand
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, Command &command) const =0
impeller::scene::PhysicallyBasedMaterial
Definition: material.h:97
impeller::scene::UnlitMaterial::GetMaterialType
MaterialType GetMaterialType() const override
Definition: material.cc:105
impeller::scene::UnlitMaterial::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, Command &command) const override
Definition: material.cc:110
impeller::scene::SceneContextOptions
Definition: scene_context.h:17
impeller::scene::Material::BlendConfig::source_color_factor
BlendFactor source_color_factor
Definition: material.h:30
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
impeller::scene::MaterialType
MaterialType
Definition: pipeline_key.h:17
impeller::scene::Material::StencilConfig::operation
StencilOperation operation
Definition: material.h:38
render_pass.h
impeller::scene::Material::BlendConfig::source_alpha_factor
BlendFactor source_alpha_factor
Definition: material.h:33
impeller::scene::Material::SetVertexColorWeight
void SetVertexColorWeight(Scalar weight)
Definition: material.cc:46
impeller::scene::Material::StencilConfig::compare
CompareFunction compare
Definition: material.h:39
impeller::scene::UnlitMaterial::SetColor
void SetColor(Color color)
Definition: material.cc:96
impeller::BlendOperation::kAdd
@ kAdd
impeller::scene::Material::SetStencilConfig
void SetStencilConfig(StencilConfig stencil_config)
Definition: material.cc:54
impeller::scene::PhysicallyBasedMaterial::SetNormalTexture
void SetNormalTexture(std::shared_ptr< Texture > normal_texture)
Definition: material.cc:201
impeller::scene::Material::BlendConfig
Definition: material.h:28
impeller::scene::Material::is_translucent_
bool is_translucent_
Definition: material.h:69
impeller::Color::White
static constexpr Color White()
Definition: color.h:254
impeller::scene::PhysicallyBasedMaterial::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, Command &command) const override
Definition: material.cc:223
impeller::BlendFactor::kOne
@ kOne
impeller::scene::Material::BlendConfig::destination_color_factor
BlendFactor destination_color_factor
Definition: material.h:31
impeller::scene::UnlitMaterial::MakeFromFlatbuffer
static std::unique_ptr< UnlitMaterial > MakeFromFlatbuffer(const fb::Material &material, const std::vector< std::shared_ptr< Texture >> &textures)
Definition: material.cc:71
impeller::scene::PhysicallyBasedMaterial::SetOcclusionTexture
void SetOcclusionTexture(std::shared_ptr< Texture > occlusion_texture)
Definition: material.cc:206
impeller::scene::PhysicallyBasedMaterial::GetMaterialType
MaterialType GetMaterialType() const override
Definition: material.cc:217
impeller::scene::Material::MakeFromFlatbuffer
static std::unique_ptr< Material > MakeFromFlatbuffer(const fb::Material &material, const std::vector< std::shared_ptr< Texture >> &textures)
Definition: material.cc:27
scalar.h
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
impeller::scene::PhysicallyBasedMaterial::SetRoughness
void SetRoughness(Scalar roughness)
Definition: material.cc:183
impeller::BlendOperation
BlendOperation
Definition: formats.h:170
impeller::scene::Material::~Material
virtual ~Material()
impeller::CompareFunction
CompareFunction
Definition: formats.h:486
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
impeller::scene::Material::MakeUnlit
static std::unique_ptr< UnlitMaterial > MakeUnlit()
Definition: material.cc:38
impeller::scene::PhysicallyBasedMaterial::SetAlbedoTexture
void SetAlbedoTexture(std::shared_ptr< Texture > albedo_texture)
Definition: material.cc:191
texture.h
impeller::scene::Material::vertex_color_weight_
Scalar vertex_color_weight_
Definition: material.h:66
impeller::scene::UnlitMaterial
Definition: material.h:72
impeller::scene::PhysicallyBasedMaterial::~PhysicallyBasedMaterial
~PhysicallyBasedMaterial()
impeller::scene::PhysicallyBasedMaterial::MakeFromFlatbuffer
static std::unique_ptr< PhysicallyBasedMaterial > MakeFromFlatbuffer(const fb::Material &material, const std::vector< std::shared_ptr< Texture >> &textures)
Definition: material.cc:137
impeller::scene::Material::stencil_config_
StencilConfig stencil_config_
Definition: material.h:68
impeller
Definition: aiks_context.cc:10
impeller::scene::Material::SetTranslucent
void SetTranslucent(bool is_translucent)
Definition: material.cc:58
impeller::scene::Material
Definition: material.h:26