| 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 #ifndef FLUTTER_IMPELLER_SCENE_MATERIAL_H_
6 #define FLUTTER_IMPELLER_SCENE_MATERIAL_H_
7
8 #include <memory>
9
10 #include "impeller/core/formats.h"
11 #include "impeller/core/texture.h"
12 #include "impeller/geometry/scalar.h"
13 #include "impeller/renderer/render_pass.h"
14 #include "impeller/scene/importer/scene_flatbuffers.h"
15 #include "impeller/scene/pipeline_key.h"
16
17 namespace impeller {
18 namespace scene {
19
20 class SceneContext;
21 struct SceneContextOptions;
22 class Geometry;
23
24 class UnlitMaterial;
25 class PhysicallyBasedMaterial;
26
27 class Material {
28 public:
29 struct BlendConfig {
30 BlendOperation color_op = BlendOperation::kAdd;
31 BlendFactor source_color_factor = BlendFactor::kOne;
32 BlendFactor destination_color_factor = BlendFactor::kOneMinusSourceAlpha;
33 BlendOperation alpha_op = BlendOperation::kAdd;
34 BlendFactor source_alpha_factor = BlendFactor::kOne;
35 BlendFactor destination_alpha_factor = BlendFactor::kOneMinusSourceAlpha;
36 };
37
38 struct StencilConfig {
39 StencilOperation operation = StencilOperation::kKeep;
40 CompareFunction compare = CompareFunction::kAlways;
41 };
42
43 static std::unique_ptr<Material> MakeFromFlatbuffer(
44 const fb::Material& material,
45 const std::vector<std::shared_ptr<Texture>>& textures);
46
47 static std::unique_ptr<UnlitMaterial> MakeUnlit();
48 static std::unique_ptr<PhysicallyBasedMaterial> MakePhysicallyBased();
49
50 virtual ~Material();
51
52 void SetVertexColorWeight(Scalar weight);
53 void SetBlendConfig(BlendConfig blend_config);
54 void SetStencilConfig(StencilConfig stencil_config);
55
56 void SetTranslucent(bool is_translucent);
57
58 SceneContextOptions GetContextOptions(const RenderPass& pass) const;
59
60 virtual MaterialType GetMaterialType() const = 0;
61
62 virtual void BindToCommand(const SceneContext& scene_context,
63 HostBuffer& buffer,
64 RenderPass& pass) const = 0;
65
66 protected:
67 Scalar vertex_color_weight_ = 1;
68 BlendConfig blend_config_;
69 StencilConfig stencil_config_;
70 bool is_translucent_ = false;
71 };
72
73 class UnlitMaterial final : public Material {
74 public:
75 static std::unique_ptr<UnlitMaterial> MakeFromFlatbuffer(
76 const fb::Material& material,
77 const std::vector<std::shared_ptr<Texture>>& textures);
78
79 ~UnlitMaterial();
80
81 void SetColor(Color color);
82
83 void SetColorTexture(std::shared_ptr<Texture> color_texture);
84
85 // |Material|
86 MaterialType GetMaterialType() const override;
87
88 // |Material|
89 void BindToCommand(const SceneContext& scene_context,
90 HostBuffer& buffer,
91 RenderPass& pass) const override;
92
93 private:
94 Color color_ = Color::White();
95 std::shared_ptr<Texture> color_texture_;
96 };
97
98 class PhysicallyBasedMaterial final : public Material {
99 public:
100 static std::unique_ptr<PhysicallyBasedMaterial> MakeFromFlatbuffer(
101 const fb::Material& material,
102 const std::vector<std::shared_ptr<Texture>>& textures);
103
104 ~PhysicallyBasedMaterial();
105
106 void SetAlbedo(Color albedo);
107 void SetRoughness(Scalar roughness);
108 void SetMetallic(Scalar metallic);
109
110 void SetAlbedoTexture(std::shared_ptr<Texture> albedo_texture);
111 void SetMetallicRoughnessTexture(
112 std::shared_ptr<Texture> metallic_roughness_texture);
113 void SetNormalTexture(std::shared_ptr<Texture> normal_texture);
114 void SetOcclusionTexture(std::shared_ptr<Texture> occlusion_texture);
115
116 void SetEnvironmentMap(std::shared_ptr<Texture> environment_map);
117
118 // |Material|
119 MaterialType GetMaterialType() const override;
120
121 // |Material|
122 void BindToCommand(const SceneContext& scene_context,
123 HostBuffer& buffer,
124 RenderPass& pass) const override;
125
126 private:
127 Color albedo_ = Color::White();
128 Scalar metallic_ = 0.5;
129 Scalar roughness_ = 0.5;
130
131 std::shared_ptr<Texture> albedo_texture_;
132 std::shared_ptr<Texture> metallic_roughness_texture_;
133 std::shared_ptr<Texture> normal_texture_;
134 std::shared_ptr<Texture> occlusion_texture_;
135
136 std::shared_ptr<Texture> environment_map_;
137 };
138
139 } // namespace scene
140 } // namespace impeller
141
142 #endif // FLUTTER_IMPELLER_SCENE_MATERIAL_H_
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:38
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::scene::PhysicallyBasedMaterial::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const override
Definition: material.cc:223
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:30
impeller::BlendFactor
BlendFactor
Definition: formats.h:178
impeller::Color
Definition: color.h:124
impeller::BlendFactor::kOneMinusSourceAlpha
@ kOneMinusSourceAlpha
impeller::HostBuffer
Definition: host_buffer.h:28
impeller::scene::Material::BlendConfig::alpha_op
BlendOperation alpha_op
Definition: material.h:33
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
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:35
impeller::scene::Material::SetBlendConfig
void SetBlendConfig(BlendConfig blend_config)
Definition: material.cc:50
impeller::scene::SceneContext
Definition: scene_context.h:41
impeller::scene::Material::blend_config_
BlendConfig blend_config_
Definition: material.h:68
impeller::scene::Material::GetContextOptions
SceneContextOptions GetContextOptions(const RenderPass &pass) const
Definition: material.cc:62
impeller::scene::PhysicallyBasedMaterial
Definition: material.h:98
impeller::scene::UnlitMaterial::GetMaterialType
MaterialType GetMaterialType() const override
Definition: material.cc:105
impeller::StencilOperation
StencilOperation
Definition: formats.h:565
impeller::scene::SceneContextOptions
Definition: scene_context.h:19
impeller::scene::Material::BlendConfig::source_color_factor
BlendFactor source_color_factor
Definition: material.h:31
impeller::scene::MaterialType
MaterialType
Definition: pipeline_key.h:18
impeller::CompareFunction
CompareFunction
Definition: formats.h:546
impeller::scene::Material::StencilConfig::operation
StencilOperation operation
Definition: material.h:39
render_pass.h
impeller::scene::Material::BlendConfig::source_alpha_factor
BlendFactor source_alpha_factor
Definition: material.h:34
impeller::scene::Material::SetVertexColorWeight
void SetVertexColorWeight(Scalar weight)
Definition: material.cc:46
impeller::scene::Material::StencilConfig::compare
CompareFunction compare
Definition: material.h:40
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:29
impeller::scene::Material::is_translucent_
bool is_translucent_
Definition: material.h:70
impeller::Color::White
static constexpr Color White()
Definition: color.h:266
impeller::BlendFactor::kOne
@ kOne
impeller::scene::Material::BlendConfig::destination_color_factor
BlendFactor destination_color_factor
Definition: material.h:32
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::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
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:33
impeller::scene::PhysicallyBasedMaterial::SetRoughness
void SetRoughness(Scalar roughness)
Definition: material.cc:183
impeller::BlendOperation
BlendOperation
Definition: formats.h:196
impeller::scene::Material::~Material
virtual ~Material()
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::UnlitMaterial::BindToCommand
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const override
Definition: material.cc:110
color
DlColor color
Definition: dl_golden_blur_unittests.cc:23
impeller::scene::Material::vertex_color_weight_
Scalar vertex_color_weight_
Definition: material.h:67
impeller::scene::Material::BindToCommand
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const =0
impeller::scene::UnlitMaterial
Definition: material.h:73
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:69
impeller
Definition: aiks_blend_unittests.cc:18
impeller::scene::Material::SetTranslucent
void SetTranslucent(bool is_translucent)
Definition: material.cc:58
impeller::scene::Material
Definition: material.h:27