Skip to content

Commit b0aa8a2

Browse files
committed
-Dev: Starting with skin material
1 parent b5333f4 commit b0aa8a2

File tree

14 files changed

+45550
-15
lines changed

14 files changed

+45550
-15
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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

include/engine/tools/controller.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ class Controller
126126
inline void set_window(Core::IWindow* w) {
127127
m_windowPtr = w;
128128
}
129+
inline Vec3 get_orbital_center() const {
130+
return m_orbitalCenter;
131+
}
132+
inline void set_orbital_center(Vec3 orbitalCenter) {
133+
m_orbitalCenter = orbitalCenter;
134+
}
135+
129136
/*Not insert as GLFW callback!*/
130137
virtual void handle_keyboard(int key, int action, const float deltaTime);
131138
virtual void handle_mouse(float xpos, float ypos, bool constrainPitch = true);

resources/shaders/deferred/composition.glsl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,45 @@ void main()
271271
if(g_material.w == HAIR_STRAND_MATERIAL){
272272
//TBD ....
273273
}
274+
//////////////////////////////////////
275+
// SKIN
276+
//////////////////////////////////////
277+
if(g_material.w == SKIN_MATERIAL){
278+
// //Direct Component ________________________
279+
// for(int i = 0; i < scene.numLights; i++) {
280+
// //If inside liught area influence
281+
// if(isInAreaOfInfluence(scene.lights[i].position, g_pos,scene.lights[i].areaEffect,int(scene.lights[i].type))){
282+
283+
// //Direct Component ________________________
284+
// vec3 lighting = vec3(0.0);
285+
// lighting = evalCookTorranceBRDF(
286+
// scene.lights[i].type != DIRECTIONAL_LIGHT ? normalize(scene.lights[i].position - g_pos) : normalize(-scene.lights[i].position.xyz), //wi
287+
// normalize(-g_pos), //wo
288+
// scene.lights[i].color * computeAttenuation(scene.lights[i].position, g_pos,scene.lights[i].areaEffect,int(scene.lights[i].type)) * scene.lights[i].intensity, //radiance
289+
// brdf
290+
// );
291+
292+
// //Visibility Component ________________________
293+
// if(scene.lights[i].shadowCast == 1) {
294+
// if(scene.lights[i].shadowType == 0) //Classic
295+
// lighting *= computeShadow(shadowMap, scene.lights[i], i, modelPos);
296+
// if(scene.lights[i].shadowType == 1) //VSM
297+
// lighting *= computeVarianceShadow(shadowMap, scene.lights[i], i, modelPos);
298+
// if(scene.lights[i].shadowType == 2) //Raytraced
299+
// lighting *= computeRaytracedShadow(
300+
// TLAS,
301+
// samplerMap,
302+
// modelPos,
303+
// scene.lights[i].type != DIRECTIONAL_LIGHT ? scene.lights[i].worldPosition.xyz - modelPos : -scene.lights[i].shadowData.xyz,
304+
// int(scene.lights[i].shadowData.w),
305+
// scene.lights[i].area,
306+
// scene.lights[i].type != DIRECTIONAL_LIGHT ? length(scene.lights[i].worldPosition.xyz - modelPos) : 30.0,
307+
// 0);
308+
// }
309+
// direct += lighting;
310+
// }
311+
// }
312+
}
274313

275314

276315

resources/shaders/deferred/geometry.glsl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ layout(location = 0) out vec4 outPos;
8080
layout(location = 1) out vec4 outNormal;
8181
layout(location = 2) out vec4 outAlbedo;
8282
layout(location = 3) out vec4 outMaterial; //U8
83-
layout(location = 4) out vec4 outEmissionF; //F32
83+
layout(location = 4) out vec4 outMaterial2; //F32
8484
// layout(location = 5) out vec4 outTemporal;
8585

8686
#define EPSILON 0.1
@@ -92,7 +92,7 @@ vec3 g_albedo = vec3(0.0);
9292
float g_opacity = 1.0;
9393
vec3 g_normal = vec3(0.0);
9494
vec4 g_material = vec4(0.0);
95-
vec3 g_emisison = vec3(0.0);
95+
vec3 g_material2 = vec3(0.0);
9696
float g_fresnelThreshold = 0.0;
9797

9898
void setupSurfaceProperties(){
@@ -125,8 +125,8 @@ void setupSurfaceProperties(){
125125
g_material.b = material.slot5.w== 1 ? mix(material.slot4.y, texture(materialText3, v_uv).r, material.slot4.z) : material.slot4.y; //AO
126126
}
127127

128-
g_emisison = material.slot6.w == 1 ? mix(material.slot7.rgb, texture(materialText4, v_uv).rgb, material.slot7.w) : material.slot7.rgb;
129-
g_emisison *= material.slot8.x;
128+
g_material2 = material.slot6.w == 1 ? mix(material.slot7.rgb, texture(materialText4, v_uv).rgb, material.slot7.w) : material.slot7.rgb;
129+
g_material2 *= material.slot8.x;
130130

131131
g_fresnelThreshold = material.slot8.y;
132132

@@ -145,6 +145,20 @@ void setupSurfaceProperties(){
145145
// TBD .........
146146
g_material.w = PHONG_MATERIAL;
147147
}
148+
if(material.slot8.w == SKIN_MATERIAL){
149+
150+
//Setting skin surface properties
151+
g_albedo = int(material.slot4.w)== 1 ? mix(material.slot1.rgb, texture(albedoTex, v_uv).rgb, material.slot3.x) : material.slot1.rgb;
152+
g_normal = int(material.slot5.x)== 1 ? normalize((v_TBN * (texture(normalTex, v_uv).rgb * 2.0 - 1.0))) : normalize( v_normal );
153+
154+
g_material.r = material.slot5.y== 1 ? mix(material.slot3.w, texture(materialText1, v_uv).r, material.slot4.x) : material.slot3.w; //Roughness
155+
g_material.g = material.slot6.x== 1 ? texture(materialText3, v_uv).r : 0.0 ;
156+
g_material.b = material.slot5.w== 1 ? mix(material.slot4.y, texture(materialText2, v_uv).r, material.slot4.z) : material.slot4.y; //AO
157+
158+
g_fresnelThreshold = material.slot8.y;
159+
160+
g_material.w = SKIN_MATERIAL;
161+
}
148162

149163

150164
}
@@ -162,7 +176,7 @@ void main() {
162176
outNormal = vec4( g_normal , 1.0f );
163177
outAlbedo = vec4(g_albedo,g_opacity);
164178
outMaterial = g_material; //w material ID
165-
outEmissionF = vec4(g_emisison,g_fresnelThreshold); //w Fresnel Threshold
179+
outMaterial2 = vec4(g_material2,g_fresnelThreshold); //w Fresnel Threshold
166180
// outTemporal = vec4(0.0); //TBD
167181

168182
}

resources/shaders/include/material_defines.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
#define PHONG_MATERIAL 0.3
33
#define HAIR_STRAND_MATERIAL 0.4
44
#define HAIR_MATERIAL 0.5
5+
#define SKIN_MATERIAL 0.6
56
#define UNLIT_MATERIAL 1.0

src/core/materials/skin.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "engine/core/materials/skin.h"
2+
3+
VULKAN_ENGINE_NAMESPACE_BEGIN
4+
namespace Core {
5+
Graphics::MaterialUniforms SkinMaterial::get_uniforms() const {
6+
7+
Graphics::MaterialUniforms uniforms;
8+
uniforms.dataSlot1 = m_albedo;
9+
uniforms.dataSlot2 = {m_tileUV.x, m_tileUV.y, m_settings.alphaTest, m_settings.blending};
10+
uniforms.dataSlot3 = {m_albedoWeight, 0.0, 0.0, m_roughness};
11+
uniforms.dataSlot4 = {m_roughnessWeight, m_occlusion, m_occlusionWeight, m_hasAlbedoTexture};
12+
uniforms.dataSlot5 = {m_hasNormalTexture && m_useNormalTexture, m_hasRoughnessTexture, 0.0, m_hasAOTexture};
13+
uniforms.dataSlot6 = {m_hasMaskTexture, 0.0, 0.0, 0.0};
14+
uniforms.dataSlot7 = Vec4(0.0);
15+
uniforms.dataSlot8 = Vec4{m_temporalReuse, m_isReflective, 0.0f, 0.0f}; // W = Material ID
16+
17+
return uniforms;
18+
}
19+
} // namespace Core
20+
VULKAN_ENGINE_NAMESPACE_END

tests/procedural-sky/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <iostream>
2-
#include "application.h"
2+
#include "test.h"
33

44
int main(int argc, char* argv[])
55
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "application.h"
1+
#include "test.h"
22
#include <filesystem>
33

44
void Application::init(Systems::RendererSettings settings) {

tests/resources/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:/Dev/Vulkan-Engine/tests/resources/** filter=lfs diff=lfs merge=lfs -text

0 commit comments

Comments
 (0)