Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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:
37
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_
SkColor4f color
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
std::vector< std::shared_ptr< FakeTexture > > textures
static const uint8_t buffer[]
float Scalar
Definition scalar.h:18
CompareFunction
Definition formats.h:534
@ kAlways
Comparison test passes always passes.
StencilOperation
Definition formats.h:553
@ kKeep
Don't modify the current stencil value.
BlendOperation
Definition formats.h:197
static constexpr Color White()
Definition color.h:256