Flutter Engine
The Flutter Engine
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
14#include "impeller/scene/importer/scene_flatbuffers.h"
16
17namespace impeller {
18namespace scene {
19
20class SceneContext;
21struct SceneContextOptions;
22class Geometry;
23
24class UnlitMaterial;
25class PhysicallyBasedMaterial;
26
27class Material {
28 public:
29 struct BlendConfig {
36 };
37
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
59
60 virtual MaterialType GetMaterialType() const = 0;
61
62 virtual void BindToCommand(const SceneContext& scene_context,
64 RenderPass& pass) const = 0;
65
66 protected:
70 bool is_translucent_ = false;
71};
72
73class 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
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,
91 RenderPass& pass) const override;
92
93 private:
94 Color color_ = Color::White();
95 std::shared_ptr<Texture> color_texture_;
96};
97
98class 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
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);
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,
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_
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
static std::unique_ptr< Material > MakeFromFlatbuffer(const fb::Material &material, const std::vector< std::shared_ptr< Texture > > &textures)
Definition: material.cc:27
void SetVertexColorWeight(Scalar weight)
Definition: material.cc:46
virtual void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const =0
void SetStencilConfig(StencilConfig stencil_config)
Definition: material.cc:54
void SetTranslucent(bool is_translucent)
Definition: material.cc:58
SceneContextOptions GetContextOptions(const RenderPass &pass) const
Definition: material.cc:62
static std::unique_ptr< PhysicallyBasedMaterial > MakePhysicallyBased()
Definition: material.cc:42
virtual MaterialType GetMaterialType() const =0
StencilConfig stencil_config_
Definition: material.h:69
void SetBlendConfig(BlendConfig blend_config)
Definition: material.cc:50
static std::unique_ptr< UnlitMaterial > MakeUnlit()
Definition: material.cc:38
BlendConfig blend_config_
Definition: material.h:68
void SetEnvironmentMap(std::shared_ptr< Texture > environment_map)
Definition: material.cc:211
void SetMetallicRoughnessTexture(std::shared_ptr< Texture > metallic_roughness_texture)
Definition: material.cc:196
static std::unique_ptr< PhysicallyBasedMaterial > MakeFromFlatbuffer(const fb::Material &material, const std::vector< std::shared_ptr< Texture > > &textures)
Definition: material.cc:137
MaterialType GetMaterialType() const override
Definition: material.cc:217
void SetNormalTexture(std::shared_ptr< Texture > normal_texture)
Definition: material.cc:201
void SetAlbedoTexture(std::shared_ptr< Texture > albedo_texture)
Definition: material.cc:191
void SetOcclusionTexture(std::shared_ptr< Texture > occlusion_texture)
Definition: material.cc:206
void SetRoughness(Scalar roughness)
Definition: material.cc:183
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const override
Definition: material.cc:223
static std::unique_ptr< UnlitMaterial > MakeFromFlatbuffer(const fb::Material &material, const std::vector< std::shared_ptr< Texture > > &textures)
Definition: material.cc:71
MaterialType GetMaterialType() const override
Definition: material.cc:105
void BindToCommand(const SceneContext &scene_context, HostBuffer &buffer, RenderPass &pass) const override
Definition: material.cc:110
void SetColorTexture(std::shared_ptr< Texture > color_texture)
Definition: material.cc:100
void SetColor(Color color)
Definition: material.cc:96
DlColor color
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
BlendFactor
Definition: formats.h:178
float Scalar
Definition: scalar.h:18
CompareFunction
Definition: formats.h:546
@ kAlways
Comparison test passes always passes.
StencilOperation
Definition: formats.h:565
@ kKeep
Don't modify the current stencil value.
BlendOperation
Definition: formats.h:196
static constexpr Color White()
Definition: color.h:266