Skip to content

Commit 9b14f8a

Browse files
committed
TOWN-100 PBR
1 parent 979db3c commit 9b14f8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1596
-54
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ add_subdirectory(Src/EngineLauncher)
7878
set_target_properties(Core PROPERTIES FOLDER ${ENGINE_PROJECT_DIR})
7979
set_target_properties(RHI PROPERTIES FOLDER ${ENGINE_PROJECT_DIR})
8080
set_target_properties(Engine PROPERTIES FOLDER ${ENGINE_PROJECT_DIR})
81+
82+
if (MSVC)
83+
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT EngineLauncher)
84+
set_target_properties(EngineLauncher PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "--project ${CMAKE_CURRENT_SOURCE_DIR}/Projects/Sandbox/sandbox.project")
85+
endif()
86+

Projects/Sandbox/Resources/Config/imgui.ini

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Window][DockSpaceViewport_11111111]
2-
Pos=0,29
3-
Size=1920,1051
2+
Pos=0,23
3+
Size=1920,1057
44
Collapsed=0
55

66
[Window][Debug##Default]
@@ -9,8 +9,8 @@ Size=400,400
99
Collapsed=0
1010

1111
[Window][Viewport]
12-
Pos=250,29
13-
Size=1275,1051
12+
Pos=249,23
13+
Size=1277,1057
1414
Collapsed=0
1515
DockId=0x00000002,0
1616

@@ -26,19 +26,19 @@ Collapsed=0
2626
DockId=0x00000001,0
2727

2828
[Window][Entities]
29-
Pos=0,29
30-
Size=247,1051
29+
Pos=0,23
30+
Size=247,1057
3131
Collapsed=0
3232
DockId=0x00000003,0
3333

3434
[Window][Components]
35-
Pos=1528,29
36-
Size=392,1051
35+
Pos=1528,23
36+
Size=392,1057
3737
Collapsed=0
3838
DockId=0x00000006,0
3939

4040
[Docking][Data]
41-
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,29 Size=1920,1051 Split=X
41+
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,23 Size=1920,1057 Split=X
4242
DockNode ID=0x00000005 Parent=0x8B93E3BD SizeRef=1525,1051 Split=X
4343
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=247,1051 Selected=0xA628E342
4444
DockNode ID=0x00000004 Parent=0x00000005 SizeRef=1275,1051 Split=X

Resources/Materials/pbr.material

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "pbr",
3+
"version": 0,
4+
"shader": "/System/Shaders/pbr.glsl",
5+
"offscreen": true,
6+
"depthCompareOp": "LESS",
7+
"cullMode": "BACK",
8+
"attachments": [
9+
{
10+
"loadOperation": "CLEAR",
11+
"storeOperation": "STORE"
12+
}
13+
],
14+
"depthAttachment":
15+
{
16+
"loadOperation": "CLEAR",
17+
"storeOperation": "STORE"
18+
}
19+
}

Resources/Materials/skybox.material

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"storeOperation": "STORE",
1212
"dependency":
1313
{
14-
"path": "/System/Materials/basic_3d.material",
14+
"path": "/System/Materials/pbr.material",
1515
"index": 0
1616
}
1717
}
@@ -22,7 +22,7 @@
2222
"storeOperation": "STORE",
2323
"dependency":
2424
{
25-
"path": "/System/Materials/basic_3d.material",
25+
"path": "/System/Materials/pbr.material",
2626
"index": 0
2727
}
2828
}

Resources/Models/sphere.fbx

40.5 KB
Binary file not shown.

Resources/Shaders/envmap_prefilter.glslc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// Pre-filters environment cube map using GGX NDF importance sampling.
88
// Part of specular IBL split-sum approximation.
99

10-
1110
const uint NumSamples = 1024;
1211
const float InvNumSamples = 1.0 / float(NumSamples);
1312

@@ -16,7 +15,6 @@ vec2 SampleHammersley(uint i)
1615
return vec2(i * InvNumSamples, RadicalInverse_VdC(i));
1716
}
1817

19-
const int NumMipLevels = 1;
2018
layout(binding = 0, rgba32f) restrict writeonly uniform imageCube outputTexture;
2119
layout(binding = 1) uniform samplerCube inputTexture;
2220

@@ -25,16 +23,15 @@ layout (push_constant) uniform Uniforms
2523
float Roughness;
2624
} u_Uniforms;
2725

28-
#define PARAM_LEVEL 0
2926
#define PARAM_ROUGHNESS u_Uniforms.Roughness
3027

31-
3228
layout(local_size_x=32, local_size_y=32, local_size_z=1) in;
3329
void main(void)
3430
{
3531
// Make sure we won't write past output when computing higher mipmap levels.
3632
ivec2 outputSize = imageSize(outputTexture);
37-
if(gl_GlobalInvocationID.x >= outputSize.x || gl_GlobalInvocationID.y >= outputSize.y) {
33+
if (gl_GlobalInvocationID.x >= outputSize.x || gl_GlobalInvocationID.y >= outputSize.y)
34+
{
3835
return;
3936
}
4037

@@ -55,7 +52,7 @@ void main(void)
5552

5653
// Convolve environment map using GGX NDF importance sampling.
5754
// Weight by cosine term since Epic claims it generally improves quality.
58-
for(uint i = 0; i < NumSamples; i++)
55+
for (uint i = 0; i < NumSamples; i++)
5956
{
6057
vec2 u = SampleHammersley(i);
6158
vec3 Lh = TangentToWorld(SampleGGX(u.x, u.y, PARAM_ROUGHNESS), N, S, T);
@@ -64,7 +61,8 @@ void main(void)
6461
vec3 Li = 2.0 * dot(Lo, Lh) * Lh - Lo;
6562

6663
float cosLi = dot(N, Li);
67-
if(cosLi > 0.0) {
64+
if (cosLi > 0.0)
65+
{
6866
// Use Mipmap Filtered Importance Sampling to improve convergence.
6967
// See: https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch20.html, section 20.4
7068

Resources/Shaders/pbr.glsl

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#pragma stage vertex
2+
#version 450 core
3+
layout(location = 0) in vec3 aPosition;
4+
layout(location = 1) in vec3 aNormal;
5+
layout(location = 2) in vec2 aUv;
6+
layout(location = 3) in vec3 aTangent;
7+
layout(location = 4) in vec3 aBiTangent;
8+
9+
layout(push_constant) uniform constants
10+
{
11+
mat4 cTransform;
12+
} Transform;
13+
14+
layout(binding = 1) uniform CameraUB
15+
{
16+
mat4 u_ViewProjection;
17+
vec4 u_CameraPosition;
18+
};
19+
20+
struct VertexOutput
21+
{
22+
vec2 UV;
23+
vec3 Normal;
24+
vec3 WorldPos;
25+
mat3 TBN;
26+
vec4 CameraPosition;
27+
};
28+
29+
layout(location = 0) out VertexOutput Output;
30+
31+
void main()
32+
{
33+
Output.UV = aUv;
34+
Output.Normal = transpose(inverse(mat3(Transform.cTransform))) * aNormal;
35+
Output.WorldPos = vec3(Transform.cTransform * vec4(aPosition, 1.0));
36+
37+
vec3 T = normalize(vec3(Transform.cTransform * vec4(aTangent, 0.0)));
38+
vec3 B = normalize(vec3(Transform.cTransform * vec4(aBiTangent, 0.0)));
39+
vec3 N = normalize(vec3(Transform.cTransform * vec4(aNormal, 0.0)));
40+
mat3 TBN = mat3(T, B, N);
41+
Output.TBN = TBN;
42+
Output.CameraPosition = u_CameraPosition;
43+
44+
gl_Position = u_ViewProjection * vec4(Output.WorldPos, 1.0);
45+
}
46+
47+
#pragma stage end
48+
49+
#pragma stage fragment
50+
#version 450 core
51+
layout (location = 0) out vec4 aAlbedo;
52+
53+
struct VertexOutput
54+
{
55+
vec2 UV;
56+
vec3 Normal;
57+
vec3 WorldPos;
58+
mat3 TBN;
59+
vec4 CameraPosition;
60+
};
61+
62+
layout(location = 0) in VertexOutput Output;
63+
64+
layout(binding = 3) uniform sampler2D u_Albedo;
65+
layout(binding = 4) uniform sampler2D u_Normal;
66+
layout(binding = 5) uniform sampler2D u_Metallic;
67+
layout(binding = 6) uniform sampler2D u_Rougness;
68+
layout(binding = 7) uniform sampler2D u_AO;
69+
layout(binding = 8) uniform samplerCube u_IrradianceMap;
70+
layout(binding = 9) uniform samplerCube u_PrefilterMap;
71+
layout(binding = 10) uniform sampler2D u_BRDFLUT;
72+
73+
struct Light
74+
{
75+
vec4 color;
76+
vec4 position;
77+
vec4 rotation;
78+
float intensity;
79+
int type;
80+
float radiusInner;
81+
float radiusOuter;
82+
};
83+
84+
const float PI = 3.14159265359;
85+
86+
vec3 getNormalFromMap()
87+
{
88+
vec3 tangentNormal = texture(u_Normal, Output.UV).xyz;
89+
tangentNormal = tangentNormal * 2.0 - 1.0;
90+
return normalize(Output.TBN * tangentNormal);
91+
}
92+
93+
// ----------------------------------------------------------------------------
94+
float DistributionGGX(vec3 N, vec3 H, float roughness)
95+
{
96+
float a = roughness*roughness;
97+
float a2 = a*a;
98+
float NdotH = max(dot(N, H), 0.0);
99+
float NdotH2 = NdotH*NdotH;
100+
101+
float nom = a2;
102+
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
103+
denom = PI * denom * denom;
104+
105+
return nom / denom;
106+
}
107+
// ----------------------------------------------------------------------------
108+
float GeometrySchlickGGX(float NdotV, float roughness)
109+
{
110+
float r = (roughness + 1.0);
111+
float k = (r*r) / 8.0;
112+
113+
float nom = NdotV;
114+
float denom = NdotV * (1.0 - k) + k;
115+
116+
return nom / denom;
117+
}
118+
// ----------------------------------------------------------------------------
119+
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
120+
{
121+
float NdotV = max(dot(N, V), 0.0);
122+
float NdotL = max(dot(N, L), 0.0);
123+
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
124+
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
125+
126+
return ggx1 * ggx2;
127+
}
128+
// ----------------------------------------------------------------------------
129+
vec3 fresnelSchlick(float cosTheta, vec3 F0)
130+
{
131+
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
132+
}
133+
// ----------------------------------------------------------------------------
134+
vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
135+
{
136+
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
137+
}
138+
139+
void main()
140+
{
141+
vec3 albedo = pow(texture(u_Albedo, Output.UV).rgb, vec3(2.2));
142+
float metallic = 0.0f;
143+
float roughness = 1.0f;
144+
float ao = 1.0f;
145+
146+
vec3 N = getNormalFromMap();
147+
148+
vec3 V = normalize(Output.CameraPosition.xyz - Output.WorldPos);
149+
vec3 R = reflect(-V, N);
150+
151+
// calculate reflectance at normal incidence; if dia-electric (like plastic) use F0
152+
// of 0.04 and if it's a metal, use the albedo color as F0 (metallic workflow)
153+
vec3 F0 = vec3(0.04);
154+
F0 = mix(F0, albedo, metallic);
155+
156+
// reflectance equation
157+
vec3 Lo = vec3(0.0);
158+
159+
int u_LightsAmount = 1;
160+
Light u_Light[1] = Light[](Light(vec4(1, 1, 1, 1), vec4(0, 0, 0, 0), vec4(0), 300, 0, 10, 1000));
161+
162+
for (int i = 0; i < u_LightsAmount; ++i)
163+
{
164+
// calculate per-light radiance
165+
vec3 L = normalize(vec3(u_Light[i].position) - Output.WorldPos);
166+
vec3 H = normalize(V + L);
167+
float distance = length(vec3(u_Light[i].position) - Output.WorldPos);
168+
float attenuation = 1.0 / (distance * distance);
169+
170+
vec3 radiance = vec3(u_Light[i].color) * u_Light[i].intensity * attenuation;
171+
172+
// Cook-Torrance BRDF
173+
float NDF = DistributionGGX(N, H, roughness);
174+
float G = GeometrySmith(N, V, L, roughness);
175+
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
176+
177+
vec3 numerator = NDF * G * F;
178+
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001;// + 0.0001 to prevent divide by zero
179+
vec3 specular = numerator / denominator;
180+
181+
// kS is equal to Fresnel
182+
vec3 kS = F;
183+
// for energy conservation, the diffuse and specular light can't
184+
// be above 1.0 (unless the surface emits light); to preserve this
185+
// relationship the diffuse component (kD) should equal 1.0 - kS.
186+
vec3 kD = vec3(1.0) - kS;
187+
// multiply kD by the inverse metalness such that only non-metals
188+
// have diffuse lighting, or a linear blend if partly metal (pure metals
189+
// have no diffuse light).
190+
kD *= 1.0 - metallic;
191+
192+
// scale light by NdotL
193+
float NdotL = max(dot(N, L), 0.0);
194+
195+
// add to outgoing radiance Lo
196+
Lo += (kD * albedo / PI + specular) * radiance * NdotL;// note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again
197+
}
198+
199+
vec3 F = fresnelSchlickRoughness(max(dot(N, V), 0.0), F0, roughness);
200+
vec3 kS = F;
201+
vec3 kD = 1.0 - kS;
202+
kD *= 1.0 - metallic;
203+
204+
vec3 irradiance = texture(u_IrradianceMap, N).rgb;
205+
vec3 diffuse = irradiance * albedo;
206+
207+
const float MAX_REFLECTION_LOD = 4.0;
208+
vec3 prefilteredColor = textureLod(u_PrefilterMap, R, roughness * MAX_REFLECTION_LOD).rgb;
209+
vec2 brdf = texture(u_BRDFLUT, vec2(max(dot(N, V), 0.0), roughness)).rg;
210+
vec3 specular = prefilteredColor * (F * brdf.x + brdf.y);
211+
212+
vec3 ambient = (kD * diffuse + specular) * ao;
213+
214+
vec3 color = ambient + Lo;
215+
216+
// HDR tonemapping
217+
color = color / (color + vec3(1.0));
218+
// gamma correct
219+
color = pow(color, vec3(1.0/2.2));
220+
221+
aAlbedo = vec4(color, 1.0);
222+
}
223+
224+
#pragma stage end

Resources/Textures/normal_map.png

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from conans.errors import ConanException
21
from conan.tools.files import copy
32
import os
43

54
def deploy(graph, output_folder, **kwargs):
65
for name, dep in graph.root.conanfile.dependencies.items():
76
if (dep.folders.package_folder is None):
87
continue
9-
copy(graph.root.conanfile, "*.dll", dep.folders.package_folder, os.path.join(output_folder, "dll", str(dep)))
8+
copy(graph.root.conanfile, "*.dll", dep.folders.package_folder, os.path.join(output_folder, ".build/Win/dll", str(dep)))

0 commit comments

Comments
 (0)