1+ /*
2+ This file is part of Vulkan-Engine, a simple to use Vulkan based 3D library
3+
4+ MIT License
5+
6+ Copyright (c) 2023 Antonio Espinosa Garcia
7+
8+ */
9+ #ifndef SKIN_H
10+ #define SKIN_H
11+
12+ #include < engine/core/materials/material.h>
13+ #include < engine/graphics/descriptors.h>
14+
15+ VULKAN_ENGINE_NAMESPACE_BEGIN
16+
17+ namespace Core {
18+
19+ // / SSSS
20+ /*
21+ ///////////////////
22+ W I P
23+
24+ ///////////////////
25+ */
26+ class SkinMaterial : public IMaterial
27+ {
28+ protected:
29+ Vec2 m_tileUV = {1 .0f , 1 .0f };
30+
31+ Vec4 m_albedo = {0.5 , 0.5 , 0.5 , 1.0 }; // w for opacity
32+ float m_albedoWeight = 1 .0f ; // Weight between parameter and albedo texture
33+
34+ float m_roughness = 0 .75f ;
35+ float m_roughnessWeight = 1 .0f ; // Weight between parameter and roughness texture
36+
37+ float m_occlusion = 1 .0f ;
38+ float m_occlusionWeight = 1 .0f ; // Weight between parameter and occlusion texture
39+
40+ bool m_isReflective = false ;
41+ bool m_temporalReuse = false ;
42+
43+ // Query
44+ bool m_hasAlbedoTexture = false ;
45+ bool m_hasNormalTexture = false ;
46+ bool m_useNormalTexture = true ;
47+ bool m_hasRoughnessTexture = false ;
48+ bool m_hasAOTexture = false ;
49+ bool m_hasMaskTexture = false ;
50+
51+ enum Textures
52+ {
53+ ALBEDO = 0 ,
54+ NORMAL = 1 ,
55+ ROUGHNESS = 2 ,
56+ AO = 3 ,
57+ MASK = 4 ,
58+ };
59+
60+ std::unordered_map<int , ITexture*> m_textures{{ALBEDO, nullptr },
61+ {NORMAL, nullptr },
62+ {ROUGHNESS, nullptr },
63+ {AO, nullptr },
64+ {MASK, nullptr }};
65+
66+ std::unordered_map<int , bool > m_textureBindingState;
67+
68+ virtual std::unordered_map<int , bool > get_texture_binding_state () const {
69+ return m_textureBindingState;
70+ }
71+ virtual void set_texture_binding_state (int id, bool state) {
72+ m_textureBindingState[id] = state;
73+ }
74+
75+ public:
76+ virtual Graphics::MaterialUniforms get_uniforms () const ;
77+ virtual inline std::unordered_map<int , ITexture*> get_textures () const {
78+ return m_textures;
79+ }
80+ SkinMaterial (Vec4 albedo = Vec4(1 .0f , 1 .0f , 0 .5f , 1 .0f ))
81+ : IMaterial(" skin" )
82+ , m_albedo(albedo) {
83+ }
84+ SkinMaterial (Vec4 albedo, MaterialSettings params)
85+ : IMaterial(" skin" , params)
86+ , m_albedo(albedo) {
87+ }
88+
89+ inline Vec2 get_tile () const {
90+ return m_tileUV;
91+ }
92+ inline void set_tile (Vec2 tile) {
93+ m_tileUV = tile;
94+ m_isDirty = true ;
95+ }
96+
97+ inline Vec3 get_albedo () const {
98+ return Vec3 (m_albedo);
99+ }
100+ inline void set_albedo (Vec3 c) {
101+ m_albedo = Vec4 (c, m_albedo.w );
102+ m_isDirty = true ;
103+ }
104+
105+ // Weight between parameter and albedo texture
106+ virtual inline float get_albedo_weight () const {
107+ return m_albedoWeight;
108+ }
109+ // Weight between parameter and albedo texture
110+ virtual inline void set_albedo_weight (float w) {
111+ m_albedoWeight = w;
112+ m_isDirty = true ;
113+ }
114+
115+ inline float get_opacity () const {
116+ return m_albedo.a ;
117+ }
118+ inline void set_opacity (float op) {
119+ m_albedo.a = op;
120+ m_isDirty = true ;
121+ }
122+ inline bool reflective () const {
123+ return m_isReflective;
124+ }
125+ inline void reflective (bool op) {
126+ m_isReflective = op;
127+ }
128+ inline float get_roughness () const {
129+ return m_roughness;
130+ }
131+ inline void set_roughness (float r) {
132+ m_roughness = r;
133+ m_isDirty = true ;
134+ }
135+ // Weight between parameter and roughness texture
136+ virtual inline float get_roughness_weight () const {
137+ return m_roughnessWeight;
138+ }
139+ // Weight between parameter and roughness texture
140+ virtual inline void set_roughness_weight (float w) {
141+ m_roughnessWeight = w;
142+ m_isDirty = true ;
143+ }
144+
145+ inline float get_occlusion () const {
146+ return m_occlusion;
147+ }
148+ inline void set_occlusion (float r) {
149+ m_occlusion = r;
150+ m_isDirty = true ;
151+ }
152+
153+ // Weight between parameter and occlusion texture
154+ virtual inline float get_occlusion_weight () const {
155+ return m_occlusionWeight;
156+ }
157+ // Weight between parameter and occlusion texture
158+ virtual inline void set_occlusion_weight (float w) {
159+ m_occlusionWeight = w;
160+ m_isDirty = true ;
161+ }
162+
163+ inline ITexture* get_albedo_texture () {
164+ return m_textures[ALBEDO];
165+ }
166+ inline void set_albedo_texture (ITexture* t) {
167+ m_hasAlbedoTexture = t ? true : false ;
168+ m_textureBindingState[ALBEDO] = false ;
169+ m_textures[ALBEDO] = t;
170+ m_isDirty = true ;
171+ }
172+
173+ inline ITexture* get_normal_texture () {
174+ return m_textures[NORMAL];
175+ }
176+ inline void set_normal_texture (ITexture* t) {
177+ m_hasNormalTexture = t ? true : false ;
178+ m_textureBindingState[NORMAL] = false ;
179+ m_textures[NORMAL] = t;
180+ m_isDirty = true ;
181+ }
182+
183+ /*
184+ Sets mask texture. Support for some presets of commercial game engines.
185+ */
186+ inline ITexture* get_mask_texture () {
187+ return m_textures[MASK];
188+ }
189+ inline void set_mask_texture (ITexture* t) {
190+ m_hasMaskTexture = t ? true : false ;
191+ m_textureBindingState[MASK] = false ;
192+ m_textures[MASK] = t;
193+ m_isDirty = true ;
194+ }
195+
196+ inline ITexture* get_roughness_texture () {
197+ return m_textures[ROUGHNESS];
198+ }
199+ inline void set_roughness_texture (ITexture* t) {
200+ m_hasRoughnessTexture = t ? true : false ;
201+ m_textureBindingState[ROUGHNESS] = false ;
202+ m_textures[ROUGHNESS] = t;
203+ m_isDirty = true ;
204+ }
205+ inline ITexture* get_occlusion_texture () {
206+ return m_textures[AO];
207+ }
208+ inline void set_occlusion_texture (ITexture* t) {
209+ m_hasAOTexture = t ? true : false ;
210+ m_textureBindingState[AO] = false ;
211+ m_textures[AO] = t;
212+ m_isDirty = true ;
213+ }
214+ inline void use_normal_texture (bool op) {
215+ m_useNormalTexture = op;
216+ }
217+ inline bool use_normal_texture () const {
218+ return m_useNormalTexture;
219+ }
220+ inline void use_temporal_reuse (bool op) {
221+ m_temporalReuse = op;
222+ }
223+ inline bool use_temporal_reuse () const {
224+ return m_temporalReuse;
225+ }
226+ };
227+ } // namespace Core
228+ VULKAN_ENGINE_NAMESPACE_END
229+ #endif
0 commit comments