Compare commits
389 Commits
master
...
devel_36_P
Author | SHA1 | Date | |
---|---|---|---|
11ca8e7fdf | |||
02ac76e5bd | |||
39aa63aa0a | |||
d73966b1d0 | |||
c9b99dd125 | |||
ea6c009c70 | |||
6080422f3a | |||
6ca0cd2987 | |||
bd0a3d8be1 | |||
d810540b81 | |||
3259f1af4c | |||
62d370e508 | |||
2c67990daa | |||
620d05c6ff | |||
d1f1124302 | |||
e9d5b369bf | |||
71c0c7e627 | |||
2f34d556e4 | |||
b9fbab56f1 | |||
4614562929 | |||
9450d92784 | |||
d7f7a7d095 | |||
59fc27c864 | |||
bbbd8b06c2 | |||
efd9a447fb | |||
5e8957b78b | |||
99264b5b0a | |||
8ebbd674b2 | |||
72ceffeda2 | |||
726a8ec635 | |||
cf2efd69b9 | |||
e35abf0051 | |||
e02aaf812d | |||
ca6d99b6fb | |||
3f37fec8a8 | |||
7dc4bb9d76 | |||
3fc9971cf7 | |||
442e52e17c | |||
8245d83309 | |||
a9526ce956 | |||
410b94a127 | |||
f4e16276ff | |||
8880df8862 | |||
0a5fb750fa | |||
3589376b79 | |||
9443dd5942 | |||
c0e4c7fe7e | |||
ee9bd06f35 | |||
421f5f8134 | |||
5213651054 | |||
3768507169 | |||
7f074c6c79 | |||
2137725bd2 | |||
f7a0e97e49 | |||
d5234316ae | |||
c3a1266da6 | |||
e18a6e7a4a | |||
741e0e8ade | |||
f2a6c61c25 | |||
28fcdb6216 | |||
412ed6f3f2 | |||
03f7237db3 | |||
f79410e434 | |||
eef7f58575 | |||
bd4fc34cbb | |||
0c669807d7 | |||
8f0cd9f35b | |||
416b7bfcb3 | |||
fdf073376c | |||
1a15b93e15 | |||
898d01ac62 | |||
d11b84222f | |||
a04752b391 | |||
30bb77d437 | |||
8ebb3095a7 | |||
6571a27f41 | |||
5855b2eb5b | |||
ba7be3ff17 | |||
006929e86f | |||
25957d8d32 | |||
c29346887c | |||
69b9556ca1 | |||
390bd14c7c | |||
dcce45a5ce | |||
1f7c8fa25b | |||
0ba4674126 | |||
94a0e03c44 | |||
eb70cb1ea4 | |||
7903ac32c1 | |||
ac03ae4e44 | |||
a5fe26b2f0 | |||
3a6ec1f589 | |||
910a8fa51b | |||
cfc3ac8250 | |||
9121ebd11b | |||
107251c9ad | |||
04b77cadf9 | |||
0137ef6e0c | |||
fafe6c077b | |||
09e9e71d59 | |||
a22e802c77 | |||
1b5d4aabb0 | |||
af5988d96e | |||
56b8798122 | |||
2f49e80122 | |||
806bf5dfdd | |||
90a4f1d49f | |||
3927b3c788 | |||
6b9ac3220b | |||
4251493415 | |||
686372b60f | |||
150b27c6e6 | |||
c61e4dfdb8 | |||
23197e147c | |||
f1f0843bee | |||
8d45c87cfd | |||
781e108aa3 | |||
1abe8770d7 | |||
8f9ccc3aa1 | |||
cd01c45980 | |||
941f5ee6ec | |||
66fbe5571e | |||
4fcdd42ce4 | |||
d83f04faab | |||
b71c912fd5 | |||
2efb9c83bf | |||
7b0a185a45 | |||
0a025f0464 | |||
7f8fbbd3a0 | |||
cd4733a491 | |||
c1d54628d1 | |||
0da0290fc6 | |||
01bb4b2153 | |||
66ef3160e1 | |||
16ae849809 | |||
8788b3dd6a | |||
bba5a660a3 | |||
aa853fbdfb | |||
c780662ff6 | |||
611a9fe61d | |||
90152ca74e | |||
22868dafab | |||
6ce713aed5 | |||
ac0d1bee59 | |||
bf7c6bdeac | |||
cc80fe7f39 | |||
55001843ea | |||
8cdf88e2fd | |||
ca8e36687f | |||
86ff7517d9 | |||
742fe201ad | |||
8bb97ef2de | |||
9947d46ab8 | |||
bf5e401566 | |||
0dcf004f4c | |||
8d3cd8d561 | |||
6740764f07 | |||
a5e76988c7 | |||
08a348392d | |||
0dfb7220b5 | |||
4a94d78c1f | |||
9a4e495027 | |||
6de3cf789a | |||
299d3bd019 | |||
78b1982849 | |||
8a0215aee6 | |||
419e0e2574 | |||
cfd67e1a42 | |||
c49feac2e6 | |||
bf50333f5b | |||
40ce978f85 | |||
e27442a0b4 | |||
ecb47dae4d | |||
6892a64393 | |||
3af753ee36 | |||
f31437bf67 | |||
14fbbd6fa6 | |||
4e6adcd765 | |||
ead4ba65c1 | |||
310cc151fa | |||
03491dbed8 | |||
40094a7529 | |||
6ad3b9edb7 | |||
21a63f4a9b | |||
11ebb841be | |||
ad330f3a42 | |||
bbf94767fe | |||
6dba761a80 | |||
5391f0f4aa | |||
a1bf9336a3 | |||
9c6c37c07a | |||
3bbbe18c40 | |||
d8140ae64e | |||
acb69d3bf5 | |||
f0c47cd4f1 | |||
0b1a0cadae | |||
8633a18e01 | |||
2bc6246dc0 | |||
0a752446b0 | |||
c32f56fbe2 | |||
b100b4b9cb | |||
d20e9cf1e3 | |||
621e056315 | |||
4fc74d38ba | |||
f00cb0b815 | |||
e1d45a7c83 | |||
c5b8dbe8f6 | |||
172ee7bb7b | |||
d41530dad3 | |||
6efb50c977 | |||
f4493b09e5 | |||
af8f62ddb4 | |||
fff7fd3af0 | |||
2fdd7e7bd5 | |||
4ebc8a3260 | |||
5892b075c3 | |||
07a478a2ac | |||
8c51d3a52b | |||
c1183d351d | |||
d4c1dd312e | |||
3c22b48f3c | |||
02169963de | |||
ac81e4f8f0 | |||
1d3bec4098 | |||
3252d1581c | |||
01bf8b3dd2 | |||
1c03e838e5 | |||
0f38f94139 | |||
0639440a13 | |||
8492b886c9 | |||
a60ffbb7da | |||
b48ef1ac30 | |||
c363a6fa51 | |||
c873271f6e | |||
68ff8a472c | |||
60ba3e4df2 | |||
35b7c9651f | |||
89b9735f99 | |||
7f744d1207 | |||
b9f5c69f85 | |||
c469fde84a | |||
dd6b2f4fb3 | |||
ba8b44659b | |||
13b2ca0575 | |||
9d704eb33d | |||
86c3b65a42 | |||
f6e61e70ce | |||
5347ac7091 | |||
f56928d734 | |||
f3a59c1bb3 | |||
5188d4149c | |||
d4096735f5 | |||
4fafd938b1 | |||
f0848541c2 | |||
cc9e756ece | |||
cdedc81f9f | |||
c229259623 | |||
2c2f11f47e | |||
c8b3ed0286 | |||
2ce36ec26c | |||
5ba3c1790d | |||
3874d771d3 | |||
49eb8f42f0 | |||
c355f96f9b | |||
dc3d7b7792 | |||
5f1c60a24a | |||
ff6a644e8f | |||
b9e70426a1 | |||
a7af276a44 | |||
8b82c6c25c | |||
a8d68c295d | |||
f666d5b248 | |||
55c27a883b | |||
6a7f8e7754 | |||
1dbf8ae5c7 | |||
8dbc1d899c | |||
d010ee4278 | |||
4aeb28c571 | |||
775e031422 | |||
deefdf1416 | |||
ba2d479f05 | |||
b16341c0f9 | |||
d5eeb081e1 | |||
4bb66d2746 | |||
625a7387ae | |||
c4deceebd9 | |||
4ed0e281b2 | |||
9369ad115b | |||
7788459109 | |||
a58589f01f | |||
240b6fb0e3 | |||
b72a924853 | |||
b781ff41a3 | |||
4ee6962d04 | |||
7eff39b3b0 | |||
6b13c159d8 | |||
2f560a28a7 | |||
8ba171efda | |||
317635877b | |||
255c7859f1 | |||
ae85d3fc66 | |||
a5830e18cb | |||
ae88a65315 | |||
77b0266cdc | |||
c99934fdf9 | |||
aa6071a948 | |||
6f58475abd | |||
cfed14d746 | |||
27c409c7fd | |||
bee48890cb | |||
a2669d2123 | |||
737438aaed | |||
8a5711154f | |||
3dd308aff1 | |||
bead8128b7 | |||
019e9964fa | |||
7ca81f38e8 | |||
03750832c8 | |||
018a72c09a | |||
55fee1e5d7 | |||
c5dd359d18 | |||
85ec666989 | |||
9a5cead33e | |||
695f1a22a8 | |||
237c1a469b | |||
5ede824522 | |||
46781b9627 | |||
aaff0c23c9 | |||
3a3f9d10b7 | |||
b6e391762b | |||
b262fdc645 | |||
5e795c4a7f | |||
0524c51feb | |||
8dc9846ae8 | |||
1d866abb48 | |||
ece7912f3c | |||
4ef37a430e | |||
1f91ec94e1 | |||
86123827cb | |||
19df201ab5 | |||
921d6d157f | |||
c0e4128365 | |||
8fe5e8dd55 | |||
3393a90127 | |||
9b5157594f | |||
10d4f2f04a | |||
a1e7b105f7 | |||
67cf89fef1 | |||
e95cbb28a4 | |||
c9d6774bd3 | |||
78946994bb | |||
1a63fa8c76 | |||
db766f33ac | |||
3db94948c5 | |||
cefea7229d | |||
45f50b3bc0 | |||
dbea7764fb | |||
1101bcae9d | |||
6c7f9ea9d1 | |||
253d113375 | |||
ca1bb80b5f | |||
922fc2661b | |||
e9a8e5bbf2 | |||
bba00534ba | |||
c15fbf8252 | |||
9a7e711658 | |||
65c3d5cad1 | |||
7d9192051a | |||
22099b6b84 | |||
322d24c4ca | |||
5230fbc27f | |||
f901708b6c | |||
2487cb1f36 | |||
7805494ca9 | |||
ac4c97d33a | |||
a87a35b5f8 | |||
d456c2bf92 | |||
12e18b517b | |||
2f00aa8e1e | |||
4e144072e4 | |||
907cb3c852 | |||
eb51df8dd0 | |||
ed9ba3876f | |||
97290ce54c | |||
bebac2284f | |||
d5d6a6bc74 | |||
5559178e7c | |||
f58ce4f98b | |||
5c2f136689 |
14
.gitmodules
vendored
14
.gitmodules
vendored
@@ -1,21 +1,21 @@
|
||||
[submodule "CMCMakeModule"]
|
||||
path = CMCMakeModule
|
||||
url = https://github.com/hyzboy/CMCMakeModule
|
||||
url = http://www.hyzgame.com:3000/hyzboy/CMCMakeModule
|
||||
[submodule "CMCore"]
|
||||
path = CMCore
|
||||
url = https://github.com/hyzboy/CMCore
|
||||
url = http://www.hyzgame.com:3000/hyzboy/CMCore
|
||||
[submodule "CMPlatform"]
|
||||
path = CMPlatform
|
||||
url = https://github.com/hyzboy/CMPlatform
|
||||
url = http://www.hyzgame.com:3000/hyzboy/CMPlatform
|
||||
[submodule "CMAssetsManage"]
|
||||
path = CMAssetsManage
|
||||
url = https://github.com/hyzboy/CMAssetsManage.git
|
||||
url = http://www.hyzgame.com:3000/hyzboy/CMAssetsManage.git
|
||||
[submodule "res"]
|
||||
path = res
|
||||
url = https://github.com/hyzboy/RuntimeData.git
|
||||
url = http://www.hyzgame.com:3000/hyzboy/RuntimeData.git
|
||||
[submodule "CMSceneGraph"]
|
||||
path = CMSceneGraph
|
||||
url = https://github.com/hyzboy/CMSceneGraph.git
|
||||
url = http://www.hyzgame.com:3000/hyzboy/CMSceneGraph.git
|
||||
[submodule "CMUtil"]
|
||||
path = CMUtil
|
||||
url = https://github.com/hyzboy/CMUtil.git
|
||||
url = http://www.hyzgame.com:3000/hyzboy/CMUtil.git
|
||||
|
Submodule CMAssetsManage updated: 9582bfafcc...0fae462338
Submodule CMCMakeModule updated: ca9aece201...737fe5c80d
2
CMCore
2
CMCore
Submodule CMCore updated: 072153aa91...9dd89aa5a3
Submodule CMPlatform updated: 5e8b83cce4...aa7abe4763
Submodule CMSceneGraph updated: bde86e8016...2370ba12d7
2
CMUtil
2
CMUtil
Submodule CMUtil updated: c0990c52eb...57ff3a70c9
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
PROJECT(ULRE)
|
||||
|
||||
@@ -26,7 +26,7 @@ SET(ULRE CMCore
|
||||
ULRE.Util
|
||||
ULRE.ShaderGen
|
||||
ULRE.SceneGraph
|
||||
${HGL_GLM_LIB}
|
||||
${HGL_MATH_LIB}
|
||||
${RENDER_LIBRARY}
|
||||
${Vulkan_LIBRARIES})
|
||||
|
||||
|
20
README.md
20
README.md
@@ -1,25 +1,33 @@
|
||||
# ULRE
|
||||
experiment project - Ultra Lightweight Rendering Engine
|
||||
|
||||
ULRE is a project of experimental nature,Used to experiment with various rendering related techniques,And do some examples.
|
||||
ULRE is a project of an experimental nature. Used to experiment with various rendering-related techniques And do some examples.
|
||||
|
||||
In the future, its compilicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
|
||||
In the future, its complicated version will be integrated into CMGameEngine.Used to replace the old rendering engine.
|
||||
|
||||
Platform: Windows,Linux (WIP: Android,macOS,iOS)
|
||||
Platform: Windows, Linux (WIP: Android, macOS, iOS)
|
||||
|
||||
Graphics API: Vulkan
|
||||
|
||||
Milestone:
|
||||
|
||||
On May 6 of 2023, a test was completed, and the entire scene was drawn with only one DrawCall. Although it still has a lot of unfinished work, it is still a very important milestone.
|
||||
2. Texture2DArray was integrated into material instances.
|
||||
Multiple render instances of the same model use different material instances and textures but are still merged into one render.
|
||||
Although the changes this time are small, they are more significant.
|
||||
|
||||
1. a test was completed, and the entire scene was drawn with only one DrawCall.
|
||||
Although it still has a lot of unfinished work, it is still a significant milestone.
|
||||
|
||||
#
|
||||
ULRE是一个试验性质的工程,用于试验各种渲染相关的技术,以及做一些范例。在未来它的复杂化版本会被整合到CMGameEngine中,用于替代旧的渲染引擎。
|
||||
|
||||
平台: Windows,Linux (开发中: Android,macOS,iOS)
|
||||
平台: Windows, Linux (开发中: Android, macOS, iOS)
|
||||
|
||||
图形API: Vulkan
|
||||
|
||||
里程碑:
|
||||
|
||||
2023年5月6日,完成了一个测试,只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作,但它依然是一个非常重要的里程碑。
|
||||
2. Texture2DArray集成在材质实例中。同一个模型的多个渲染实例使用不同的材质实例以及不同的纹理,
|
||||
但它们依然被合并成一次渲染。这次的改变虽小,但意义更为重大。
|
||||
|
||||
1. 完成了一个测试,只用了一次DrawCall就绘制出了整个场景。虽然它还有很多未完成的工作,但它依然是一个非常重要的里程碑。
|
||||
|
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
@@ -0,0 +1,11 @@
|
||||
mat4 GetJointMatrix()
|
||||
{
|
||||
// Joint数据分Joint ID和Joint Weight两部分
|
||||
// Joint ID是一个uvec4,在shader中为整数。在C++端可使用RGBA8UI或是RGBA16UI来传递。
|
||||
// Joint Weight是权重,在shader中为浮点。在C++端使用RGBA8或RGBA4来传递。
|
||||
|
||||
return joint.mats[JointID.x]*JointWeight.x+
|
||||
joint.mats[JointID.y]*JointWeight.y+
|
||||
joint.mats[JointID.z]*JointWeight.z+
|
||||
joint.mats[JointID.w]*JointWeight.w;
|
||||
}
|
9
ShaderLibrary/Normal.glsl
Normal file
9
ShaderLibrary/Normal.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
mat3 GetNormalMatrix()
|
||||
{
|
||||
return mat3(camera.view*GetLocalToWorld());
|
||||
}
|
||||
|
||||
vec3 GetNormal(mat3 normal_matrix,vec3 normal)
|
||||
{
|
||||
return normalize(normal_matrix*normal);
|
||||
}
|
38
ShaderLibrary/Std2D/PureColor2D.mtl
Normal file
38
ShaderLibrary/Std2D/PureColor2D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor2D
|
||||
Base Std2D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
39
ShaderLibrary/Std2D/PureTexture2D.mtl
Normal file
39
ShaderLibrary/Std2D/PureTexture2D.mtl
Normal file
@@ -0,0 +1,39 @@
|
||||
#Material
|
||||
Name PureTexture2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
68
ShaderLibrary/Std2D/RectTexture2D.mtl
Normal file
@@ -0,0 +1,68 @@
|
||||
#Material
|
||||
Name RectTexture2D
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
79
ShaderLibrary/Std2D/RectTexture2DArray.mtl
Normal file
@@ -0,0 +1,79 @@
|
||||
#Material
|
||||
Name RectTexture2DArray
|
||||
Base Std2D
|
||||
Prim SolidRectangles,WireRectangles
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
uvec4 id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec4 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
in points
|
||||
out triangle_strip,4
|
||||
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
vec2 vlt=gl_in[0].gl_Position.xy;
|
||||
vec2 vrb=gl_in[0].gl_Position.zw;
|
||||
vec2 tlt=Input[0].TexCoord.xy;
|
||||
vec2 trb=Input[0].TexCoord.zw;
|
||||
|
||||
HandoverMI();gl_Position=vec4(vlt, vec2(0,1));Output.TexCoord=tlt; EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vlt.x, vrb.y, vec2(0,1));Output.TexCoord=vec2(tlt.x,trb.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb.x, vlt.y, vec2(0,1));Output.TexCoord=vec2(trb.x,tlt.y); EmitVertex();
|
||||
HandoverMI();gl_Position=vec4(vrb, vec2(0,1));Output.TexCoord=trb; EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=texture(TextureBaseColor,vec3(Input.TexCoord,mi.id.x));
|
||||
}
|
||||
}
|
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
37
ShaderLibrary/Std2D/VertexColor2D.mtl
Normal file
@@ -0,0 +1,37 @@
|
||||
#Material
|
||||
Name VertexColor2D
|
||||
Base Std2D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition2D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
82
ShaderLibrary/Std3D/Billboard/FixedSize.mtl
Normal file
82
ShaderLibrary/Std3D/Billboard/FixedSize.mtl
Normal file
@@ -0,0 +1,82 @@
|
||||
#Material
|
||||
Name BillboardFixedSize
|
||||
Base Std3D/Billboard
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#MaterialInstance
|
||||
Length 8
|
||||
Stage Vertex
|
||||
|
||||
Code
|
||||
{
|
||||
uvec2 BillboardSize;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 BillboardSize
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.BillboardSize=mi.BillboardSize/viewport.canvas_resolution;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
gl_Position/=gl_Position.w;
|
||||
}
|
||||
}
|
||||
|
||||
#Geometry
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
const vec2 BillboardVertex[4]=vec2[]
|
||||
(
|
||||
vec2(-0.5,-0.5),
|
||||
vec2(-0.5, 0.5),
|
||||
vec2( 0.5,-0.5),
|
||||
vec2( 0.5, 0.5)
|
||||
);
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
gl_Position=gl_in[0].gl_Position;
|
||||
gl_Position.xy+=BillboardVertex[i]*Input[0].BillboardSize;
|
||||
|
||||
Output.TexCoord=BillboardVertex[i]+vec2(0.5);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
@@ -0,0 +1,2 @@
|
||||
vec4 direction;
|
||||
vec4 color;
|
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
92
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColor.mtl
Normal file
@@ -0,0 +1,92 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec3 Color;
|
||||
float Gloss;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,mi.Gloss)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
100
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColorTexture.mtl
Normal file
100
ShaderLibrary/Std3D/BlinnPhong/SunLightPureColorTexture.mtl
Normal file
@@ -0,0 +1,100 @@
|
||||
#Material
|
||||
Name BlinnPhong+HalfLambert shading model only color
|
||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||
Base Std3D/BlinnPhong
|
||||
|
||||
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||
Require LocalToWorld
|
||||
Require Camera
|
||||
|
||||
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 32
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
uint tex_id;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Position;
|
||||
vec3 Normal;
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Normal =GetNormal();
|
||||
Output.Position =GetPosition3D();
|
||||
Output.TexCoord =TexCoord;
|
||||
|
||||
HandoverMI();
|
||||
|
||||
gl_Position =Output.Position;
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2DArray TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
#define HAVE_SPECULAR
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
vec4 texture_color=texture(TextureBaseColor,vec3(Input.TexCoord,mi.tex_id));
|
||||
|
||||
//点乘法线和光照
|
||||
float intensity=0.5*max(dot(Input.Normal,sun.direction.xyz),0.0)+0.5;
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =intensity*sun.color.rgb*mi.Color.rgb*texture_color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
FragColor=vec4(direct_color,1.0);
|
||||
#else
|
||||
|
||||
vec3 spec_color=vec3(0.0);
|
||||
|
||||
if(intensity>0.0)
|
||||
{
|
||||
vec3 half_vector=normalize(sun.direction.xyz+normalize(Input.Position.xyz+camera.pos));
|
||||
|
||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||
|
||||
spec_color=specular*pow(specular,8)*sun.color.rgb;
|
||||
}
|
||||
|
||||
FragColor=vec4(direct_color+spec_color,1.0);
|
||||
#endif//HAVE_SPECULAR
|
||||
}
|
||||
}
|
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
87
ShaderLibrary/Std3D/MetricCellsGrid.mtl
Normal file
@@ -0,0 +1,87 @@
|
||||
#Material
|
||||
Name MetricCellsGrid
|
||||
Base Std3D
|
||||
Reference https://www.shadertoy.com/view/wdSXzm
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#MaterialInstance
|
||||
Length 120
|
||||
Stage Fragment
|
||||
|
||||
Code
|
||||
{
|
||||
vec4 x_color;
|
||||
vec4 y_color;
|
||||
vec4 x_axis_color;
|
||||
vec4 y_axis_color;
|
||||
vec4 center_color;
|
||||
|
||||
vec2 lum; //x=0.1 sub cell line,y=0.2 big cell line
|
||||
vec2 cell_step;
|
||||
vec2 big_cell_step;
|
||||
vec2 scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
float edge=viewport.inv_viewport_resolution.y;
|
||||
|
||||
float x=(Input.TexCoord.x-0.5)*mi.scale.x;
|
||||
float y=(Input.TexCoord.y-0.5)*mi.scale.y;
|
||||
|
||||
vec4 color=vec4(0,0,0,1);
|
||||
|
||||
// ======= Lines + Bold lines
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.x, fract(x / mi.cell_step.x )) * mi.x_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.x, fract(x / mi.big_cell_step.x)) * mi.x_color.rgb * mi.lum.y;
|
||||
|
||||
color.xyz += step(1.0 - 1.0 / mi.cell_step.y, fract(y / mi.cell_step.y )) * mi.y_color.rgb * mi.lum.x;
|
||||
color.xyz += step(1.0 - 1.0 / mi.big_cell_step.y, fract(y / mi.big_cell_step.y)) * mi.y_color.rgb * mi.lum.y;
|
||||
|
||||
// ======= AXES
|
||||
float xb = step(abs(x) - mi.axis_line_width, 0.0);
|
||||
float yb = step(abs(y) - mi.axis_line_width, 0.0);
|
||||
|
||||
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
|
||||
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
|
||||
|
||||
// ======= CENTER
|
||||
float cb = length(vec2(x,y))-mi.center_radius;
|
||||
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*mi.scale.y,abs(cb)));
|
||||
|
||||
FragColor=color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/PureColor3D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name PureColor3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#Vertex
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=mi.Color;
|
||||
}
|
||||
}
|
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
38
ShaderLibrary/Std3D/VertexColor3D.mtl
Normal file
@@ -0,0 +1,38 @@
|
||||
#Material
|
||||
Name VertexColor3D
|
||||
Base Std3D
|
||||
|
||||
#VertexInput
|
||||
vec4 Color
|
||||
|
||||
#Vertex
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
47
ShaderLibrary/Std3D/VertexLum3D.mtl
Normal file
@@ -0,0 +1,47 @@
|
||||
#Material
|
||||
Name VertexLum3D
|
||||
Base Std3D
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Vertex
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
float Luminance
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec4 Color
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.Color=Luminance*mi.Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=Input.Color;
|
||||
}
|
||||
}
|
34
doc/AssetFileFormat.md
Normal file
34
doc/AssetFileFormat.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# 为什么我们使用INI/TOML做为资产文件格式?
|
||||
|
||||
大部分的数据文件,我们会将其分为属性文本部分与二进制数据部分。
|
||||
|
||||
其中属性部分,我们会使用INI/TOML方式编写。这样利于git/hg/svn等版本控制系统进行差异合并。
|
||||
|
||||
比如一个纹理贴图,它的二进制部分首先是有它的“原始位图数据阵列”,它的属性部分包含“宽、高、象素格式”这样的不可更改数据,也包括“sRGB/Linear色彩空间、纹理分组、建议过滤方式、特定平台建议的压缩算法”等可调整数据。还有资产使用过程中产生的“引用资产列表”和“被引用资产列表”。
|
||||
|
||||
而这些可调整数据,我们可能是会随时修改的,甚至是不同的人可能会修改不同的部分。
|
||||
|
||||
如果我们将这些数据,全部放入一个二进制文件中,比如png/jpeg中。那么每修改一个小小的属性,都需要向git/svn仓库提交整个二进制文件。这是相当愚蠢和不合理的。
|
||||
|
||||
而众所周知:不管是免费的git/hg/svn,还是收费的p4,它们针对文本文件都会有一系列的差异化比较合并功能。而这个差异化自动合并,都是基于文本行的。
|
||||
所以,我们的所有资产文件,都会分裂成二进制数据文件和属性文本文件。而在这个属性文本文件中,对于每一项属性,是使用独立的行来保存数据的。
|
||||
|
||||
|
||||
# Why do we use the INI/TOML as an asset file format?
|
||||
For most files, we will split into the attributes text part and binary data part.
|
||||
|
||||
We will use the INI/TOML format to write the properties part. Because the format easily merges diff by git/hg/svn.
|
||||
|
||||
For example a texture. It's binary data includes "Raw bitmap data".
|
||||
Its attributes part include "width, height, pixel format", they can't change.
|
||||
Also, "sRGB/Linear colour space", "texture group", "recommend filter type" and "recommend compress format of special platform".
|
||||
|
||||
We may modify this data at any time. Even many people modify different parts at the same time.
|
||||
|
||||
If we use a binary file that it includes all data. for example, .png or .jpeg.
|
||||
We need commit whole binary data after changed a few attributes. This behaviour is quite stupid and irrational.
|
||||
|
||||
Most people know this knowledge: Free git/hg/svn and commercial p4. They both include a merge-diff tool, which is text based.
|
||||
so, we all asset files, they should split into the attributes text part and binary data part.
|
||||
In this attribute's text file, a separate line is used to save data for each attribute.
|
||||
|
BIN
doc/BlenderGizmo/Move.png
Normal file
BIN
doc/BlenderGizmo/Move.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
BIN
doc/BlenderGizmo/Rotate.png
Normal file
BIN
doc/BlenderGizmo/Rotate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 KiB |
BIN
doc/BlenderGizmo/Scale.png
Normal file
BIN
doc/BlenderGizmo/Scale.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 180 KiB |
BIN
doc/Gizmo.odg
Normal file
BIN
doc/Gizmo.odg
Normal file
Binary file not shown.
@@ -10,4 +10,6 @@
|
||||
endmacro()
|
||||
|
||||
CreateProject(00.line line.cpp)
|
||||
CreateProject(01.roundbox roundbox.cpp)
|
||||
CreateProject(01.LerpLine LerpLine.cpp)
|
||||
|
||||
CreateProject(02.roundbox roundbox.cpp)
|
||||
|
121
example/2dVector/LerpLine.cpp
Normal file
121
example/2dVector/LerpLine.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// 主要用于测试几种2D插值算法
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/math/HalfFloat.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
-1.0, 0.0,
|
||||
1.0, 0.0,
|
||||
};
|
||||
|
||||
constexpr VkFormat PositionFormat=VF_V2F;
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT*4]=
|
||||
{ 1,0,0,1,
|
||||
0,1,0,1,
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
constexpr VkFormat ColorFormat=VF_V4F;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Lines);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -116,7 +116,7 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
@@ -138,7 +138,7 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
212
example/Basic/BillboardTest.cpp
Normal file
212
example/Basic/BillboardTest.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
// Billboard
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[3]=
|
||||
{
|
||||
0,0,0
|
||||
};
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
MaterialInstance * mi_billboard =nullptr;
|
||||
Pipeline * pipeline_billboard =nullptr;
|
||||
Renderable * ro_billboard =nullptr;
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitPlaneGridMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
{
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBillboardMP()
|
||||
{
|
||||
mtl::BillboardMaterialCreateConfig cfg(device->GetDeviceAttribute(),"Billboard2D",Prim::Billboard);
|
||||
|
||||
{
|
||||
cfg.fixed_size=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateBillboard2D(&cfg);
|
||||
|
||||
mi_billboard=db->CreateMaterialInstance(mci);
|
||||
if(!mi_billboard)return(false);
|
||||
|
||||
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D,Prim::Billboard);
|
||||
if(!pipeline_billboard)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!mi_billboard->GetMaterial()->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
Vector2u texture_size(texture->GetWidth(),texture->GetHeight());
|
||||
|
||||
mi_billboard->WriteMIData(texture_size);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.Add(new SceneNode(ri));
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(500,500);
|
||||
pgci.sub_count.Set(5,5);
|
||||
|
||||
pgci.lum=128;
|
||||
pgci.sub_lum=192;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mi_billboard->GetVIL());
|
||||
|
||||
pc.Init("Billboard",1);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position,VF_V3F,position_data))
|
||||
return(false);
|
||||
|
||||
ro_billboard=db->CreateRenderable(&pc,mi_billboard,pipeline_billboard);
|
||||
if(!ro_billboard)
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
|
||||
render_root.Add(new SceneNode(ro_billboard));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitPlaneGridMP())
|
||||
return(false);
|
||||
|
||||
if(!InitBillboardMP())
|
||||
return(false);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1920,1080);
|
||||
}
|
18
example/Basic/CMakeLists.txt
Normal file
18
example/Basic/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
|
||||
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
|
||||
CreateProject(03_auto_instance auto_instance.cpp)
|
||||
CreateProject(04_auto_merge_material_instance auto_merge_material_instance.cpp)
|
||||
|
||||
CreateProject(05_Billboard BillboardTest.cpp)
|
@@ -1,12 +1,10 @@
|
||||
// AutoInstance
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
// 该范例主要演示使用RenderList系统绘制多个三角形,并利用RenderList进行排序以及自动合并进行Instance渲染
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -17,6 +15,8 @@ constexpr uint32_t SCREEN_HEIGHT=1024;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr uint32_t TRIANGLE_NUMBER=12;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT*2]=
|
||||
{
|
||||
0.0, 0.0,
|
||||
@@ -25,7 +25,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{ {255,0,0,255},
|
||||
{
|
||||
{255,0,0,255},
|
||||
{0,255,0,255},
|
||||
{0,0,255,255}
|
||||
};
|
||||
@@ -47,7 +48,7 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
@@ -72,18 +73,28 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
|
||||
if(!render_obj)
|
||||
return(false);
|
||||
|
||||
double rad;
|
||||
Matrix4f mat;
|
||||
|
||||
for(uint i=0;i<12;i++)
|
||||
render_root.CreateSubNode(rotate(deg2rad(30*i),Vector3f(0,0,1)),render_obj);
|
||||
for(uint i=0;i<TRIANGLE_NUMBER;i++)
|
||||
{
|
||||
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||
mat=rotate(rad,Vector3f(0,0,1));
|
||||
|
||||
render_root.Add(new SceneNode(mat,render_obj));
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
@@ -98,10 +109,10 @@ public:
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
@@ -117,7 +128,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
@@ -127,12 +138,5 @@ public:
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
// AutoMergeMaterialInstance
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
// 该范例主要演示使用一个材质下的不同材质实例传递颜色参数绘制三角形,并依赖RenderList中的自动合并功能,让同一材质下所有不同材质实例的对象一次渲染完成。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
@@ -26,6 +24,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
|
||||
constexpr uint DRAW_OBJECT_COUNT=12;
|
||||
|
||||
#define USE_MATERIAL_FILE true //是否使用材质文件
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
@@ -48,14 +48,17 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg);
|
||||
|
||||
#ifndef USE_MATERIAL_FILE
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureColor2D(&cfg); //走程序内置材质创建函数
|
||||
material=db->CreateMaterial(mci);
|
||||
#else
|
||||
material=db->LoadMaterial("Std2D/PureColor2D",&cfg); //走材质文件加载
|
||||
#endif//USE_MATERIAL_FILE
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
@@ -69,7 +72,7 @@ private:
|
||||
|
||||
Color4f color=GetColor4f((COLOR)(i+int(COLOR::Blue)),1.0);
|
||||
|
||||
render_obj[i].mi->WriteMIData(color,sizeof(Color4f)); //设置MaterialInstance的数据
|
||||
render_obj[i].mi->WriteMIData(color); //设置MaterialInstance的数据
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,20 +81,34 @@ private:
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!pc.Init("Triangle",VERTEX_COUNT))
|
||||
return(false);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position, VF_V2F, position_data))
|
||||
return(false);
|
||||
|
||||
Primitive *prim=pc.Create();
|
||||
if(!prim)
|
||||
return(false);
|
||||
|
||||
db->Add(prim);
|
||||
|
||||
Matrix4f mat;
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
render_obj[i].r=rpc.Create(render_obj[i].mi,pipeline);
|
||||
render_obj[i].r=db->CreateRenderable(prim,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
render_root.CreateSubNode(rotate(deg2rad(360/DRAW_OBJECT_COUNT*i),Vector3f(0,0,1)),render_obj[i].r);
|
||||
mat=rotate(deg2rad<double>(double(360/DRAW_OBJECT_COUNT*i)),AxisVector::Z);
|
||||
|
||||
render_root.Add(new SceneNode(mat,render_obj[i].r));
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
@@ -118,7 +135,7 @@ public:
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
@@ -126,7 +143,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
@@ -1,14 +1,10 @@
|
||||
// first_triangle
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/math/HalfFloat.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -87,7 +83,7 @@ private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d");
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
@@ -109,24 +105,26 @@ private:
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_HALF_FLOAT_POSITION
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
InitVIL();
|
||||
@@ -146,7 +144,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
@@ -156,12 +154,5 @@ public:
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||
}
|
133
example/Basic/draw_triangle_use_UBO.cpp
Normal file
133
example/Basic/draw_triangle_use_UBO.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
static float position_data_float[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0.5, 0.25},
|
||||
{0.75, 0.75},
|
||||
{0.25, 0.75}
|
||||
};
|
||||
|
||||
static uint16 position_data_u16[VERTEX_COUNT][2]={};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT*4]=
|
||||
{
|
||||
255,0,0,255,
|
||||
0,255,0,255,
|
||||
0,0,255,255
|
||||
};
|
||||
|
||||
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
|
||||
cfg.position_format =VAT_UVEC2; //这里指定shader中使用uvec2当做顶点输入格式
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
// v
|
||||
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VAB中使用RG16U当做顶点数据格式
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
#else //使用ortho坐标系
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
#ifndef USE_ZERO2ONE_COORD
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data_u16[i][0]=position_data_float[i][0]*w;
|
||||
position_data_u16[i][1]=position_data_float[i][1]*h;
|
||||
}
|
||||
#endif//
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
@@ -2,6 +2,11 @@
|
||||
|
||||
SET(VULKAN_APP_FRAMEWORK ${CMAKE_CURRENT_SOURCE_DIR}/common/VulkanAppFramework.h)
|
||||
|
||||
add_subdirectory(Basic)
|
||||
add_subdirectory(Texture)
|
||||
add_subdirectory(LightBasic)
|
||||
add_subdirectory(Gizmo)
|
||||
|
||||
add_subdirectory(Vulkan)
|
||||
add_subdirectory(2dVector)
|
||||
add_subdirectory(GUI)
|
||||
@@ -17,4 +22,3 @@ macro(CreateProject name)
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example")
|
||||
endmacro()
|
||||
|
||||
CreateProject(MaterialCreaterTest MaterialCreaterTest.cpp)
|
||||
|
@@ -11,3 +11,4 @@ endmacro()
|
||||
|
||||
CreateProject(00.control_point_2d control_point_2d.cpp)
|
||||
CreateProject(01.align_test align_test.cpp)
|
||||
CreateProject(02.TextDrawTest DrawText.cpp)
|
@@ -1,4 +1,4 @@
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/io/LoadString.h>
|
||||
#include<hgl/graph/font/TextRender.h>
|
||||
#include"VulkanAppFramework.h"
|
||||
|
||||
@@ -8,7 +8,7 @@ using namespace hgl::graph;
|
||||
constexpr uint32_t SCREEN_WIDTH =1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=SCREEN_WIDTH/16*9;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
|
||||
bool InitTextRenderable()
|
||||
{
|
||||
UTF16String str;
|
||||
U16String str;
|
||||
|
||||
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));
|
||||
|
||||
@@ -61,16 +61,21 @@ public:
|
||||
if(!InitTextRenderable())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32_t index)
|
||||
{
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
30
example/Gizmo/BlenderAxis.cpp
Normal file
30
example/Gizmo/BlenderAxis.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Blender axis
|
||||
/**
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* 0+---------->>>> X
|
||||
* 1|
|
||||
* 2|
|
||||
* 3| +--+
|
||||
* 4| +--+
|
||||
* 5|
|
||||
* 6V
|
||||
* 7V
|
||||
*
|
||||
* 坐标轴参考Blender设计
|
||||
*
|
||||
* 单方向坐标轴长度为8
|
||||
* 最终箭头长度为2
|
||||
*
|
||||
* 负责2D平移的方块尺寸为1,位置在3-4
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 缩放工具
|
||||
*/
|
||||
class GizmoScale
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
};//class GizmoScale
|
25
example/Gizmo/CMakeLists.txt
Normal file
25
example/Gizmo/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(02_RayPicking RayPicking.cpp)
|
||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||
|
||||
CreateProject(04_Gizmo3DTest GizmoTest.cpp
|
||||
Gizmo.h
|
||||
GizmoResource.h
|
||||
GizmoResource.cpp
|
||||
Gizmo3DMove.cpp
|
||||
Gizmo3DScale.cpp
|
||||
Gizmo3DRotate.cpp)
|
||||
|
||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
43
example/Gizmo/Gizmo.h
Normal file
43
example/Gizmo/Gizmo.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
enum class GizmoColor:uint
|
||||
{
|
||||
Black=0,
|
||||
White,
|
||||
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
|
||||
Yellow,
|
||||
|
||||
ENUM_CLASS_RANGE(Black,Yellow)
|
||||
};
|
||||
|
||||
enum class GizmoShape:uint
|
||||
{
|
||||
Square=0, //方块
|
||||
Circle, //圆
|
||||
Cube, //立方体
|
||||
Sphere, //球
|
||||
Cone, //圆锥
|
||||
Cylinder, //圆柱
|
||||
Torus, //圆环
|
||||
|
||||
ENUM_CLASS_RANGE(Square,Torus)
|
||||
};
|
||||
|
||||
bool InitGizmoResource(RenderResource *);
|
||||
void FreeGizmoResource();
|
||||
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color);
|
||||
|
||||
StaticMesh *GetGizmoMoveStaticMesh();
|
||||
StaticMesh *GetGizmoScaleStaticMesh();
|
||||
StaticMesh *GetGizmoRotateStaticMesh();
|
||||
|
||||
VK_NAMESPACE_END
|
152
example/Gizmo/Gizmo3DMove.cpp
Normal file
152
example/Gizmo/Gizmo3DMove.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Gizmo move
|
||||
|
||||
ref: Blender 4
|
||||
|
||||
|
||||
0 9-10
|
||||
*----------------->>>>
|
||||
|
|
||||
|
|
||||
| 5+
|
||||
| +6
|
||||
|
|
||||
|
|
||||
v
|
||||
|
||||
假设轴尺寸为10
|
||||
箭头长度为2,直径为2
|
||||
双轴调节正方形,长宽为1,位置为5,5
|
||||
|
||||
中心球半径为1
|
||||
*/
|
||||
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
static StaticMesh *sm_gizmo_move=nullptr;
|
||||
}//namespace
|
||||
|
||||
StaticMesh *GetGizmoMoveStaticMesh()
|
||||
{
|
||||
return sm_gizmo_move;
|
||||
}
|
||||
|
||||
void ClearGizmoMoveStaticMesh()
|
||||
{
|
||||
SAFE_CLEAR(sm_gizmo_move);
|
||||
}
|
||||
|
||||
bool InitGizmoMoveStaticMesh()
|
||||
{
|
||||
Renderable *sphere=GetGizmoRenderable(GizmoShape::Sphere,GizmoColor::White);
|
||||
Renderable *cylinder[3]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Renderable *cone[3]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Renderable *circle[3]=
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Circle,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!sphere)
|
||||
return(false);
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(!cylinder[i])
|
||||
return(false);
|
||||
|
||||
if(!cone[i])
|
||||
return(false);
|
||||
|
||||
if(!circle[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *root_node=new SceneNode();
|
||||
|
||||
root_node->Add(new SceneNode(sphere));
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
const Vector3f one_scale(1);
|
||||
const Vector3f circle_scale(2);
|
||||
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,cone[2])); //Z 向上圆锥
|
||||
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
||||
root_node->Add(new SceneNode(tm,circle[2]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::Y,90);
|
||||
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
|
||||
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
||||
root_node->Add(new SceneNode(tm,cone[0])); //X 向右圆锥
|
||||
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,circle[0]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::X,-90);
|
||||
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
|
||||
|
||||
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
||||
root_node->Add(new SceneNode(tm,cone[1])); //Y 向前圆锥
|
||||
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,circle[1]));
|
||||
}
|
||||
}
|
||||
|
||||
sm_gizmo_move=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_move)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
80
example/Gizmo/Gizmo3DRotate.cpp
Normal file
80
example/Gizmo/Gizmo3DRotate.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/TransformFaceToCamera.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
static StaticMesh *sm_gizmo_rotate=nullptr;
|
||||
}//namespace
|
||||
|
||||
StaticMesh *GetGizmoRotateStaticMesh()
|
||||
{
|
||||
return sm_gizmo_rotate;
|
||||
}
|
||||
|
||||
void ClearGizmoRotateStaticMesh()
|
||||
{
|
||||
SAFE_CLEAR(sm_gizmo_rotate);
|
||||
}
|
||||
|
||||
bool InitGizmoRotateStaticMesh()
|
||||
{
|
||||
Renderable *torus[4]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Blue),
|
||||
|
||||
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White),
|
||||
};
|
||||
|
||||
for(auto *r:torus)
|
||||
{
|
||||
if(!r)
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *root_node=new SceneNode();
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
tm.SetScale(GIZMO_ARROW_LENGTH);
|
||||
|
||||
root_node->Add(new SceneNode(tm,torus[0]));
|
||||
|
||||
tm.SetRotation(AXIS::Z,90);
|
||||
root_node->Add(new SceneNode(tm,torus[1]));
|
||||
|
||||
tm.SetRotation(AXIS::Y,90);
|
||||
root_node->Add(new SceneNode(tm,torus[2]));
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *white_torus=new SceneNode(scale(13),torus[3]);
|
||||
|
||||
white_torus->SetLocalNormal(AxisVector::X);
|
||||
|
||||
TransformFaceToCamera *rotate_white_torus_tfc=new TransformFaceToCamera();
|
||||
|
||||
//暂时因为无法传入Camera所以无法正确计算朝向,正在设计Actor/World结构
|
||||
|
||||
white_torus->GetTransform().AddTransform(rotate_white_torus_tfc);
|
||||
|
||||
root_node->Add(white_torus);
|
||||
}
|
||||
|
||||
sm_gizmo_rotate=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_rotate)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
152
example/Gizmo/Gizmo3DScale.cpp
Normal file
152
example/Gizmo/Gizmo3DScale.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Gizmo move
|
||||
|
||||
ref: Blender 4
|
||||
|
||||
|
||||
0 9-10
|
||||
*----------------->>>>
|
||||
|
|
||||
|
|
||||
| 5+
|
||||
| +6
|
||||
|
|
||||
|
|
||||
v
|
||||
|
||||
假设轴尺寸为10
|
||||
箭头长度为2,直径为2
|
||||
双轴调节正方形,长宽为1,位置为5,5
|
||||
|
||||
中心球半径为1
|
||||
*/
|
||||
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
static StaticMesh *sm_gizmo_scale=nullptr;
|
||||
}//namespace
|
||||
|
||||
StaticMesh *GetGizmoScaleStaticMesh()
|
||||
{
|
||||
return sm_gizmo_scale;
|
||||
}
|
||||
|
||||
void ClearGizmoScaleStaticMesh()
|
||||
{
|
||||
SAFE_CLEAR(sm_gizmo_scale);
|
||||
}
|
||||
|
||||
bool InitGizmoScaleStaticMesh()
|
||||
{
|
||||
Renderable *center_cube=GetGizmoRenderable(GizmoShape::Cube,GizmoColor::White);
|
||||
Renderable *cylinder[3]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Renderable *cube[3]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Renderable *square[3]=
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Square,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!center_cube)
|
||||
return(false);
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(!cylinder[i])
|
||||
return(false);
|
||||
|
||||
if(!cube[i])
|
||||
return(false);
|
||||
|
||||
if(!square[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *root_node=new SceneNode();
|
||||
|
||||
root_node->Add(new SceneNode(scale(GIZMO_CENTER_SPHERE_RADIUS*2),center_cube));
|
||||
|
||||
{
|
||||
Transform tm;
|
||||
|
||||
const Vector3f one_scale(1);
|
||||
const Vector3f plane_scale(2);
|
||||
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,cylinder[2])); //Z 向上圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,cube[2])); //Z 向上圆锥
|
||||
|
||||
tm.SetScale(plane_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
||||
root_node->Add(new SceneNode(tm,square[2]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::Y,90);
|
||||
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
|
||||
root_node->Add(new SceneNode(tm,cylinder[0])); //X 向右圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
||||
root_node->Add(new SceneNode(tm,cube[0])); //X 向右圆锥
|
||||
|
||||
tm.SetScale(plane_scale);
|
||||
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,square[0]));
|
||||
}
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetRotation(AxisVector::X,-90);
|
||||
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
|
||||
|
||||
root_node->Add(new SceneNode(tm,cylinder[1])); //Y 向前圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
||||
root_node->Add(new SceneNode(tm,cube[1])); //Y 向前圆锥
|
||||
|
||||
tm.SetScale(plane_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
||||
root_node->Add(new SceneNode(tm,square[1]));
|
||||
}
|
||||
}
|
||||
|
||||
sm_gizmo_scale=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_scale)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
331
example/Gizmo/GizmoResource.cpp
Normal file
331
example/Gizmo/GizmoResource.cpp
Normal file
@@ -0,0 +1,331 @@
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include"GizmoResource.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool InitGizmoMoveStaticMesh();
|
||||
void ClearGizmoMoveStaticMesh();
|
||||
|
||||
bool InitGizmoScaleStaticMesh();
|
||||
void ClearGizmoScaleStaticMesh();
|
||||
|
||||
bool InitGizmoRotateStaticMesh();
|
||||
void ClearGizmoRotateStaticMesh();
|
||||
|
||||
namespace
|
||||
{
|
||||
static RenderResource * gizmo_rr=nullptr;
|
||||
|
||||
struct GizmoResource
|
||||
{
|
||||
Material * mtl;
|
||||
MaterialInstance * mi[size_t(GizmoColor::RANGE_SIZE)];
|
||||
Pipeline * pipeline;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
PrimitiveCreater * prim_creater;
|
||||
};
|
||||
|
||||
static GizmoResource gizmo_line{};
|
||||
static GizmoResource gizmo_triangle{};
|
||||
|
||||
struct GizmoRenderable
|
||||
{
|
||||
Primitive *prim;
|
||||
|
||||
Renderable *renderable[size_t(GizmoColor::RANGE_SIZE)];
|
||||
};
|
||||
|
||||
GizmoRenderable gizmo_rederable[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||
|
||||
void InitGizmoRenderable(const GizmoShape &gs,Primitive *prim,Pipeline *p)
|
||||
{
|
||||
if(!prim)
|
||||
return;
|
||||
|
||||
GizmoRenderable *gr=gizmo_rederable+size_t(gs);
|
||||
|
||||
gr->prim=prim;
|
||||
|
||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||
gr->renderable[i]=CreateRenderable(prim,gizmo_triangle.mi[i],p);
|
||||
}
|
||||
|
||||
bool InitMI(GizmoResource *gr)
|
||||
{
|
||||
if(!gr||!gr->mtl)
|
||||
return(false);
|
||||
|
||||
Color4f color;
|
||||
|
||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||
{
|
||||
color=GetColor4f(gizmo_color[i],1.0);
|
||||
|
||||
gr->mi[i]=gizmo_rr->CreateMaterialInstance(gr->mtl,nullptr,&color);
|
||||
if(!gr->mi[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitGizmoResource2D(GPUDevice *device)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(false);
|
||||
|
||||
RenderPass *render_pass=device->GetRenderPass();
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(&cfg);
|
||||
|
||||
if(!mci)
|
||||
return(false);
|
||||
|
||||
gizmo_line.mtl=gizmo_rr->CreateMaterial(mci);
|
||||
if(!gizmo_line.mtl)
|
||||
return(false);
|
||||
|
||||
gizmo_line.mtl->Update();
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!gizmo_line.pipeline)
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!InitMI(&gizmo_line))
|
||||
return(false);
|
||||
|
||||
{
|
||||
gizmo_line.vdm=new VertexDataManager(device,gizmo_line.mtl->GetDefaultVIL());
|
||||
|
||||
if(!gizmo_line.vdm)
|
||||
return(false);
|
||||
|
||||
if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
||||
HGL_SIZE_1MB, //最大索引数量
|
||||
IndexType::U16)) //索引类型
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitGizmoResource3D(GPUDevice *device)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(false);
|
||||
|
||||
RenderPass *render_pass=device->GetRenderPass();
|
||||
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"Gizmo3D",Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.material_instance=true;
|
||||
|
||||
mtl::MaterialCreateInfo *mci=CreateMaterialGizmo3D(&cfg);
|
||||
|
||||
if(!mci)
|
||||
return(false);
|
||||
|
||||
gizmo_triangle.mtl=gizmo_rr->CreateMaterial(mci);
|
||||
if(!gizmo_triangle.mtl)
|
||||
return(false);
|
||||
|
||||
gizmo_triangle.mtl->Update();
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
if(!gizmo_triangle.pipeline)
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!InitMI(&gizmo_triangle))
|
||||
return(false);
|
||||
|
||||
{
|
||||
gizmo_triangle.vdm=new VertexDataManager(device,gizmo_triangle.mtl->GetDefaultVIL());
|
||||
|
||||
if(!gizmo_triangle.vdm)
|
||||
return(false);
|
||||
|
||||
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
||||
HGL_SIZE_1MB, //最大索引数量
|
||||
IndexType::U16)) //索引类型
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_triangle.prim_creater=new PrimitiveCreater(gizmo_triangle.vdm);
|
||||
|
||||
if(!gizmo_triangle.prim_creater)
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
InitGizmoRenderable(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
CircleCreateInfo cci;
|
||||
|
||||
cci.center=Vector2f(0,0);
|
||||
cci.radius=Vector2f(0.5,0.5);
|
||||
cci.field_count=16;
|
||||
cci.has_center=false;
|
||||
|
||||
InitGizmoRenderable(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
CubeCreateInfo cci;
|
||||
|
||||
cci.normal=true;
|
||||
cci.tangent=false;
|
||||
cci.tex_coord=false;
|
||||
|
||||
InitGizmoRenderable(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
ConeCreateInfo cci;
|
||||
|
||||
cci.radius =GIZMO_CONE_RADIUS; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=3; //圆锥高度分割数
|
||||
|
||||
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =1; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1; //圆柱半径
|
||||
|
||||
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
struct TorusCreateInfo tci;
|
||||
|
||||
tci.innerRadius=0.975;
|
||||
tci.outerRadius=1.0;
|
||||
tci.numberSlices=64;
|
||||
tci.numberStacks=8;
|
||||
|
||||
InitGizmoRenderable(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
ENUM_CLASS_FOR(GizmoShape,int,i)
|
||||
{
|
||||
if(!gizmo_rederable[i].prim)
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
}//namespace
|
||||
|
||||
bool InitGizmoResource(RenderResource *rr)
|
||||
{
|
||||
if(!rr)
|
||||
return(false);
|
||||
|
||||
if(gizmo_rr)
|
||||
return(false);
|
||||
|
||||
gizmo_rr=rr;
|
||||
|
||||
GPUDevice *device=gizmo_rr->GetDevice();
|
||||
|
||||
if(!InitGizmoResource3D(device))
|
||||
return(false);
|
||||
|
||||
if(!InitGizmoResource2D(device))
|
||||
return(false);
|
||||
|
||||
InitGizmoMoveStaticMesh();
|
||||
InitGizmoScaleStaticMesh();
|
||||
InitGizmoRotateStaticMesh();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void FreeGizmoResource()
|
||||
{
|
||||
ClearGizmoRotateStaticMesh();
|
||||
ClearGizmoScaleStaticMesh();
|
||||
ClearGizmoMoveStaticMesh();
|
||||
|
||||
for(GizmoRenderable &gr:gizmo_rederable)
|
||||
{
|
||||
SAFE_CLEAR(gr.prim)
|
||||
SAFE_CLEAR_OBJECT_ARRAY(gr.renderable)
|
||||
}
|
||||
|
||||
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
||||
SAFE_CLEAR(gizmo_triangle.vdm);
|
||||
|
||||
SAFE_CLEAR(gizmo_line.prim_creater);
|
||||
SAFE_CLEAR(gizmo_line.vdm);
|
||||
}
|
||||
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(nullptr);
|
||||
|
||||
RANGE_CHECK_RETURN_NULLPTR(shape)
|
||||
RANGE_CHECK_RETURN_NULLPTR(color)
|
||||
|
||||
return gizmo_rederable[size_t(shape)].renderable[size_t(color)];
|
||||
}
|
||||
|
||||
StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node)
|
||||
{
|
||||
if(!root_node)
|
||||
return(nullptr);
|
||||
|
||||
if(root_node->IsEmpty())
|
||||
return(nullptr);
|
||||
|
||||
return(new StaticMesh(root_node));
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
42
example/Gizmo/GizmoResource.h
Normal file
42
example/Gizmo/GizmoResource.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class SceneNode;
|
||||
class PrimitiveCreater;
|
||||
class StaticMesh;
|
||||
|
||||
constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
|
||||
{
|
||||
COLOR::MozillaCharcoal,
|
||||
COLOR::BlanchedAlmond,
|
||||
|
||||
COLOR::BlenderAxisRed,
|
||||
COLOR::BlenderAxisGreen,
|
||||
COLOR::BlenderAxisBlue,
|
||||
|
||||
COLOR::BlenderYellow,
|
||||
};
|
||||
|
||||
constexpr const float GIZMO_ARROW_LENGTH =10.0f; ///<箭头整体长度
|
||||
constexpr const float GIZMO_CENTER_SPHERE_RADIUS=1.0f; ///<中心球半径
|
||||
|
||||
constexpr const float GIZMO_CONE_LENGTH =1.0f; ///<圆锥高度
|
||||
constexpr const float GIZMO_CONE_RADIUS =1.0f; ///<圆锥底部半径
|
||||
constexpr const float GIZMO_CONE_OFFSET =GIZMO_ARROW_LENGTH-(GIZMO_CONE_LENGTH/2.0f); ///<圆锥偏移量
|
||||
|
||||
constexpr const float GIZMO_CYLINDER_RADIUS =0.25f; ///<圆柱半径
|
||||
constexpr const float GIZMO_CYLINDER_LENGTH =GIZMO_ARROW_LENGTH-GIZMO_CENTER_SPHERE_RADIUS-GIZMO_CONE_LENGTH; ///<圆柱长度
|
||||
|
||||
constexpr const float GIZMO_CYLINDER_HALF_LENGTH=GIZMO_CYLINDER_LENGTH/2.0f; ///<圆柱一半长度
|
||||
constexpr const float GIZMO_CYLINDER_OFFSET =GIZMO_CYLINDER_HALF_LENGTH+GIZMO_CENTER_SPHERE_RADIUS; ///<圆柱偏移量
|
||||
|
||||
constexpr const float GIZMO_TWO_AXIS_OFFSET =5.0F; ///<二轴调节点偏移量(方片或圆)
|
||||
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &gs,const GizmoColor &);
|
||||
|
||||
StaticMesh *CreateGizmoStaticMesh(SceneNode *);
|
||||
|
||||
VK_NAMESPACE_END
|
145
example/Gizmo/GizmoTest.cpp
Normal file
145
example/Gizmo/GizmoTest.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include"VulkanAppFramework.h"
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/graph/Ray.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
const Vector3f GizmoPosition(0,0,0);
|
||||
|
||||
|
||||
///**
|
||||
//* 一种永远转向正面的变换节点
|
||||
//*/
|
||||
//class TransformBillboard:public TransformBase
|
||||
//{
|
||||
// CameraInfo *camera_info=nullptr;
|
||||
// bool face_to_camera=false;
|
||||
//
|
||||
// ViewportInfo *viewport_info=nullptr;
|
||||
// float fixed_scale=1.0;
|
||||
//
|
||||
//public:
|
||||
//
|
||||
// virtual void SetCameraInfo (CameraInfo * ci ){camera_info =ci;}
|
||||
// virtual void SetViewportInfo(ViewportInfo * vi ){viewport_info =vi;}
|
||||
//
|
||||
// virtual void SetFaceToCamera(bool ftc ){face_to_camera=ftc;}
|
||||
// virtual void SetFixedScale (const float size){fixed_scale =size;}
|
||||
//
|
||||
// virtual bool RefreshTransform(const Transform &tf=IdentityTransform) override
|
||||
// {
|
||||
// if(!camera_info)
|
||||
// {
|
||||
// return SceneNode::RefreshTransform(tf);
|
||||
// }
|
||||
//
|
||||
// if(face_to_camera)
|
||||
// {
|
||||
// LocalTransform.SetRotation(CalculateFacingRotationQuat(GetWorldPosition(),camera_info->view,AxisVector::X));
|
||||
// }
|
||||
//
|
||||
// if(viewport_info)
|
||||
// {
|
||||
// const float screen_height=viewport_info->GetViewportHeight();
|
||||
//
|
||||
// const Vector4f pos=camera_info->Project(GetWorldPosition());
|
||||
//
|
||||
// LocalTransform.SetScale(pos.w*fixed_scale/screen_height);
|
||||
// }
|
||||
//
|
||||
// return SceneNode::RefreshTransform(tf);
|
||||
// }
|
||||
//};//class BillboardSceneNode:public SceneNode
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
SceneNode root;
|
||||
|
||||
StaticMesh *sm_move=nullptr;
|
||||
StaticMesh *sm_rotate=nullptr;
|
||||
StaticMesh *sm_scale=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitGizmo()
|
||||
{
|
||||
if(!InitGizmoResource(db))
|
||||
return(false);
|
||||
|
||||
sm_move =GetGizmoMoveStaticMesh();
|
||||
sm_rotate =GetGizmoRotateStaticMesh();
|
||||
sm_scale =GetGizmoScaleStaticMesh();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void InitGizmoSceneTree()
|
||||
{
|
||||
camera_control->Refresh();
|
||||
CameraInfo *ci=camera_control->GetCameraInfo();
|
||||
|
||||
root.Clear();
|
||||
|
||||
//root.Add(Duplication(sm_move->GetScene()));
|
||||
root.Add(Duplication(sm_rotate->GetScene()));
|
||||
//root.CreateSubNode(sm_scale->GetScene());
|
||||
|
||||
root.RefreshMatrix();
|
||||
render_list->SetCamera(ci);
|
||||
render_list->Expend(&root);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitGizmo())
|
||||
return(false);
|
||||
|
||||
InitGizmoSceneTree();
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
FreeGizmoResource();
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
camera_control->Refresh();
|
||||
|
||||
const CameraInfo *ci=camera_control->GetCameraInfo();
|
||||
const ViewportInfo *vi=GetViewportInfo();
|
||||
|
||||
const float screen_height=vi->GetViewportHeight();
|
||||
|
||||
const Vector4f pos=ci->Project(GizmoPosition);
|
||||
|
||||
//{
|
||||
// Transform tm;
|
||||
|
||||
// tm.SetScale(pos.w*16.0f/screen_height);
|
||||
|
||||
// root.SetLocalTransform(tm);
|
||||
//}
|
||||
|
||||
root.RefreshMatrix();
|
||||
render_list->UpdateLocalToWorld();
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
};//class TestApp:public SceneAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1024,1024);
|
||||
}
|
147
example/Gizmo/MetricCellsGrid.cpp
Normal file
147
example/Gizmo/MetricCellsGrid.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// Metric Cells Grid
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
struct MetricCellsGridData
|
||||
{
|
||||
Color4f x_color;
|
||||
Color4f y_color;
|
||||
Color4f x_axis_color;
|
||||
Color4f y_axis_color;
|
||||
Color4f center_color;
|
||||
|
||||
Vector2f lum;
|
||||
Vector2f cell_step;
|
||||
Vector2f big_cell_step;
|
||||
Vector2f scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
};
|
||||
|
||||
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
|
||||
|
||||
constexpr const float PLANE_SIZE=1024;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MetricCellsGridData mcg_data;
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"MetricCellsGrid",Prim::Fan);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
{
|
||||
mcg_data.x_color=Color4f(1,1,1,1);
|
||||
mcg_data.y_color=Color4f(1,1,1,1);
|
||||
|
||||
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
|
||||
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
|
||||
|
||||
mcg_data.center_color=Color4f(1,1,0,1);
|
||||
|
||||
mcg_data.lum =Vector2f(0.1,0.2);
|
||||
mcg_data.cell_step =Vector2f(8,8);
|
||||
mcg_data.big_cell_step =Vector2f(32,32);
|
||||
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
|
||||
|
||||
mcg_data.axis_line_width=1.0;
|
||||
mcg_data.center_radius =4.0;
|
||||
}
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Fan);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
ro_plane=inline_geometry::CreatePlaneSqaure(&pc);
|
||||
|
||||
if(ro_plane)
|
||||
db->Add(ro_plane);
|
||||
|
||||
return ro_plane;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(ro_plane,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
|
||||
|
||||
camera->pos=Vector3f(PLANE_SIZE/4,PLANE_SIZE/2,PLANE_SIZE/4);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
135
example/Gizmo/PlaneGrid3D.cpp
Normal file
135
example/Gizmo/PlaneGrid3D.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
// PlaneGrid3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
||||
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
GridColor=GetColor4f(ce,1.0);
|
||||
|
||||
material_instance[i]=db->CreateMaterialInstance(material,&vil_config,&GridColor);
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=180;
|
||||
pgci.sub_lum=255;
|
||||
|
||||
PrimitiveCreater pc(device,material_instance[0]->GetVIL());
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
|
||||
|
||||
return prim_plane_grid;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(prim_plane_grid,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.Add(new SceneNode(mat,ri));
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance[0],Matrix4f(1.0f));
|
||||
Add(material_instance[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(material_instance[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
204
example/Gizmo/RayPicking.cpp
Normal file
204
example/Gizmo/RayPicking.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
// RayPicking
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Material * mtl_line =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
Pipeline * pipeline_line =nullptr;
|
||||
Primitive * prim_line =nullptr;
|
||||
VABMap * prim_line_vab_map =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance2D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
{
|
||||
cfg.mtl_name="VertexLuminance2D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
VILConfig vil_config;
|
||||
|
||||
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
{
|
||||
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl_line=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_line)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(mtl_line,nullptr,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline_line=CreatePipeline(mtl_line,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline_line)
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.Add(new SceneNode(ri));
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=128;
|
||||
pgci.sub_lum=196;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mtl_line->GetDefaultVIL());
|
||||
|
||||
if(!pc.Init("Line",2))
|
||||
return(false);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position, VF_V3F,position_data))return(false);
|
||||
if(!pc.WriteVAB(VAN::Luminance,VF_V1F,lumiance_data))return(false);
|
||||
|
||||
prim_line=pc.Create();
|
||||
|
||||
prim_line_vab_map=prim_line->GetVABMap(VAN::Position);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
Add(prim_line,mi_line,pipeline_line);
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
SAFE_CLEAR(prim_line);
|
||||
}
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
const CameraInfo *ci=GetCameraInfo();
|
||||
const ViewportInfo *vi=GetViewportInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),ci,vi); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
prim_line_vab_map->Write(&pos, //更新VAB上这个点的位置
|
||||
1); //这里的1代表的数据数量,不是字节数
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
333
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
333
example/LightBasic/BlinnPhongDirectionLight.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
// BlinnPhong direction light
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/BlinnPhong.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
|
||||
static mtl::blinnphong::SunLight sun_light=
|
||||
{
|
||||
Vector4f(1,1,1,0), //direction
|
||||
Vector4f(1,0.95,0.9,1) //color
|
||||
};
|
||||
|
||||
constexpr const COLOR AxisColor[4]=
|
||||
{
|
||||
//COLOR::Red, //X轴颜色
|
||||
//COLOR::Green, //Y轴颜色
|
||||
//COLOR::Blue, //Z轴颜色
|
||||
COLOR::White, //全局颜色
|
||||
COLOR::GhostWhite,
|
||||
COLOR::BlanchedAlmond,
|
||||
COLOR::AntiqueWhite
|
||||
};
|
||||
|
||||
constexpr const os_char *tex_filename[]=
|
||||
{
|
||||
OS_TEXT("eucalyptus-cross-versailles.Tex2D"),
|
||||
OS_TEXT("tints-ashton-green-stretcher.Tex2D"),
|
||||
OS_TEXT("worn-clay-cobble-in-desert-stretcher.Tex2D"),
|
||||
OS_TEXT("plain-grey-sheer.Tex2D"),
|
||||
};
|
||||
|
||||
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private: //plane grid
|
||||
|
||||
Material * mtl_vertex_lum =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * p_line =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
DeviceBuffer * ubo_sun =nullptr;
|
||||
|
||||
|
||||
Texture2DArray * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
PrimitiveCreater * pc_blinnphong =nullptr;
|
||||
VertexDataManager * vdm_blinnphong =nullptr;
|
||||
|
||||
MaterialInstance * mi_blinnphong[4]{};
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
Primitive * prim_sphere =nullptr;
|
||||
Primitive * prim_cone =nullptr;
|
||||
Primitive * prim_cylinder =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( "SeamlessBackground",
|
||||
256,256, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
|
||||
if(!texture)return(false);
|
||||
|
||||
OSString filename;
|
||||
|
||||
for(uint i=0;i<TexCount;i++)
|
||||
{
|
||||
filename=filesystem::MergeFilename(OS_TEXT("res/image/seamless"),tex_filename[i]);
|
||||
|
||||
if(!db->LoadTexture2DToArray(texture,i,filename))
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
mtl_vertex_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_vertex_lum)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vertex_lum,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
p_line=CreatePipeline(mtl_vertex_lum,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!p_line)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateBlinnPhongUBO()
|
||||
{
|
||||
ubo_sun=db->CreateUBO("sun",sizeof(sun_light),&sun_light);
|
||||
if(!ubo_sun)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBlinnPhongSunLightMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.material_instance=true;
|
||||
|
||||
mtl_blinnphong=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColorTexture",&cfg);
|
||||
if(!mtl_blinnphong)return(false);
|
||||
|
||||
mtl_blinnphong->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_blinnphong->Update();
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!mtl_blinnphong->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
struct MIData
|
||||
{
|
||||
Color4f color;
|
||||
uint32 tex_id[4];
|
||||
}mi_data;
|
||||
|
||||
constexpr const uint MIDataStride=sizeof(MIData);
|
||||
|
||||
for(uint i=0;i<4;i++)
|
||||
{
|
||||
mi_data.color=GetColor4f(AxisColor[i],4);
|
||||
mi_data.tex_id[0]=i;
|
||||
|
||||
mi_blinnphong[i]=db->CreateMaterialInstance(mtl_blinnphong, //材质
|
||||
nullptr, //顶点输入配置,这里使用nullptr,即代表会使用默认配置,那么结果将等同于上面的mtl_blinnphong->GetDefaultVIL()
|
||||
&mi_data); //材质实例参数
|
||||
if(!mi_blinnphong[i])return(false);
|
||||
}
|
||||
|
||||
p_blinnphong=CreatePipeline(mtl_blinnphong,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVDMAndPC()
|
||||
{
|
||||
vdm_blinnphong=new VertexDataManager(device,mtl_blinnphong->GetDefaultVIL());
|
||||
if(!vdm_blinnphong->Init( 1024*1024, //VAB最大容量
|
||||
1024*1024, //索引最大容量
|
||||
IndexType::U16)) //索引类型
|
||||
{
|
||||
delete vdm_blinnphong;
|
||||
vdm_blinnphong=nullptr;
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
pc_blinnphong=new PrimitiveCreater(vdm_blinnphong);
|
||||
//pc_blinnphong=new PrimitiveCreater(device,mtl_blinnphong->GetDefaultVIL());
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
//Plane Grid
|
||||
//{
|
||||
// struct PlaneGridCreateInfo pgci;
|
||||
|
||||
// pgci.grid_size.Set(32,32);
|
||||
// pgci.sub_count.Set(8,8);
|
||||
|
||||
// pgci.lum=0.5;
|
||||
// pgci.sub_lum=0.75;
|
||||
|
||||
// prim_plane_grid=CreatePlaneGrid(pc_blinnphong,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
//}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(pc_blinnphong,16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
struct ConeCreateInfo cci;
|
||||
|
||||
cci.radius =1; //圆锥半径
|
||||
cci.halfExtend =1; //圆锤一半高度
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =1.25; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
||||
{
|
||||
if(!r)
|
||||
return(nullptr);
|
||||
if(!mi)
|
||||
return(nullptr);
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR("Create Renderable failed! Primitive: "+r->GetName());
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
//Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
|
||||
Add(prim_sphere, mi_blinnphong[0],p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
|
||||
Add(prim_cone, mi_blinnphong[1],p_blinnphong);
|
||||
Add(prim_cylinder, mi_blinnphong[2],p_blinnphong,translate(Vector3f(0,0,-5)));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
//if(!InitVertexLumMP())
|
||||
// return(false);
|
||||
|
||||
if(!CreateBlinnPhongUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
if(!InitVDMAndPC())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_cone)
|
||||
SAFE_CLEAR(prim_cylinder)
|
||||
SAFE_CLEAR(prim_sphere)
|
||||
SAFE_CLEAR(prim_plane_grid)
|
||||
|
||||
SAFE_CLEAR(pc_blinnphong)
|
||||
SAFE_CLEAR(vdm_blinnphong)
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
13
example/LightBasic/CMakeLists.txt
Normal file
13
example/LightBasic/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Light Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_BlinnPhongDirectionLight BlinnPhongDirectionLight.cpp)
|
@@ -1,126 +0,0 @@
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
using namespace hgl::shadergen;
|
||||
|
||||
bool PureColor2DMaterial()
|
||||
{
|
||||
MaterialCreateInfo mc("PureColor2D",1,false); //一个新材质,1个RT输出,默认使用Vertex/Fragment shader
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mc.GetVS(); //获取vertex shader creater
|
||||
|
||||
//以下代码会被展开为
|
||||
/*
|
||||
layout(location=?) in vec3 Position; //位置属性
|
||||
*/
|
||||
vsc->AddInput("vec2","Position"); //添加一个vec3类型的position属性输入
|
||||
|
||||
vsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
gl_Position=vec4(Position,0,1);
|
||||
})");
|
||||
}
|
||||
|
||||
//添加一个名称为ColorMaterial的UBO定义,其内部有一个vec4 color的属性
|
||||
//该代码会被展开为
|
||||
/*
|
||||
struct ColorMaterial
|
||||
{
|
||||
vec4 color;
|
||||
};
|
||||
*/
|
||||
mc.AddStruct("ColorMaterial","vec4 color;");
|
||||
|
||||
//添加一个UBO,该代码会被展开为
|
||||
/*
|
||||
layout(set=?,binding=?) uniform ColorMaterial mtl;
|
||||
*/
|
||||
mc.AddUBO( VK_SHADER_STAGE_FRAGMENT_BIT, //这个UBO出现在fragment shader
|
||||
DescriptorSetType::PerMaterial, //它属于材质合集
|
||||
"ColorMaterial", //UBO名称为ColorMaterial
|
||||
"mtl"); //UBO变量名称为mtl
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mc.GetFS(); //获取fragment shader creater
|
||||
|
||||
//以下代码会被展开为
|
||||
/*
|
||||
layout(location=?) out vec4 Color; //颜色输出
|
||||
*/
|
||||
fsc->AddOutput("vec4","Color"); //添加一个vec4类型的color属性输出
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Color=mtl.color;
|
||||
})");
|
||||
}
|
||||
|
||||
mc.CreateShader();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool VertexColor2DMaterial()
|
||||
{
|
||||
MaterialCreateInfo mc("VertexColor2D",1,false);
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mc.GetVS();
|
||||
|
||||
vsc->AddInput("vec2","Position");
|
||||
vsc->AddInput("vec4","Color");
|
||||
|
||||
vsc->AddOutput("vec4","Color");
|
||||
|
||||
vsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
gl_Position=vec4(Position,0,1);
|
||||
})");
|
||||
}
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mc.GetFS();
|
||||
|
||||
fsc->AddOutput("vec4","Color");
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
void main()
|
||||
{
|
||||
Color=Input.Color;
|
||||
})");
|
||||
}
|
||||
|
||||
mc.CreateShader();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
namespace glsl_compiler
|
||||
{
|
||||
bool Init();
|
||||
void Close();
|
||||
}//namespace glsl_compiler
|
||||
|
||||
int main()
|
||||
{
|
||||
if(!glsl_compiler::Init())
|
||||
return -1;
|
||||
|
||||
PureColor2DMaterial();
|
||||
VertexColor2DMaterial();
|
||||
|
||||
glsl_compiler::Close();
|
||||
|
||||
return 0;
|
||||
}
|
16
example/Texture/CMakeLists.txt
Normal file
16
example/Texture/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} ${VULKAN_APP_FRAMEWORK})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(MSVC)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
set_property(TARGET ${name} PROPERTY VS_DPI_AWARE "PerMonitor")
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Texture")
|
||||
endmacro()
|
||||
|
||||
CreateProject(05_texture_format texture_format_list.cpp)
|
||||
CreateProject(06_texture_quad texture_quad.cpp)
|
||||
CreateProject(07_texture_rect texture_rect.cpp)
|
||||
CreateProject(08_texture_rect_array texture_rect_array.cpp)
|
@@ -9,32 +9,6 @@ using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_USING;
|
||||
|
||||
constexpr char *texture_compress_name[]=
|
||||
{
|
||||
"NONE",
|
||||
"S3TC",
|
||||
"PVRTC",
|
||||
"ETC1",
|
||||
"ETC2",
|
||||
"EAC",
|
||||
"ATC",
|
||||
"ASTC",
|
||||
"YUV"
|
||||
};
|
||||
|
||||
constexpr char *data_type_name[]
|
||||
{
|
||||
"NONE",
|
||||
"UNORM",
|
||||
"SNORM",
|
||||
"USCALED",
|
||||
"SSCALED",
|
||||
"UINT",
|
||||
"SINT",
|
||||
"UFLOAT",
|
||||
"SFLOAT",
|
||||
"SRGB"
|
||||
};//
|
||||
|
||||
VulkanInstance *InitVulkanInstance()
|
||||
{
|
||||
@@ -92,14 +66,14 @@ int main(int,char **)
|
||||
std::cout<<"Format [ID:"<<std::setw(10)<<vf->format<<"]["<<std::setw(16)<<vf->name<<"]";
|
||||
|
||||
if(vf->depth!=VulkanBaseType::NONE)
|
||||
std::cout<<"[ Depth:"<<std::setw(8)<<data_type_name[size_t(vf->depth)]<<"]";
|
||||
std::cout<<"[ Depth:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->depth)]<<"]";
|
||||
|
||||
if(vf->stencil!=VulkanBaseType::NONE)
|
||||
std::cout<<"[Stencil:"<<std::setw(8)<<data_type_name[size_t(vf->stencil)]<<"]";
|
||||
std::cout<<"[Stencil:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->stencil)]<<"]";
|
||||
|
||||
if((vf->depth==VulkanBaseType::NONE)
|
||||
&&(vf->stencil==VulkanBaseType::NONE))
|
||||
std::cout<<"[ Color:"<<std::setw(8)<<data_type_name[size_t(vf->color)]<<"]";
|
||||
std::cout<<"[ Color:"<<std::setw(8)<<VulkanBaseTypeName[size_t(vf->color)]<<"]";
|
||||
|
||||
{
|
||||
const VkFormatProperties fp=physical_device->GetFormatProperties(vf->format);
|
||||
@@ -114,7 +88,7 @@ int main(int,char **)
|
||||
}
|
||||
|
||||
if(vf->compress_type!=TextureCompressType::NONE)
|
||||
std::cout<<" use "<<texture_compress_name[size_t(vf->compress_type)]<<" compress.";
|
||||
std::cout<<" use "<<TextureCompressTypeName[size_t(vf->compress_type)]<<" compress.";
|
||||
else
|
||||
std::cout<<std::setw(4)<<vf->bytes<<" bytes/pixel.";
|
||||
|
@@ -1,10 +1,11 @@
|
||||
// 2.texture_rect
|
||||
// 该示例是1.indices_rect的进化,演示在矩形上贴上贴图
|
||||
// 画一个带纹理的四边形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -21,26 +22,18 @@ constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0, 0},
|
||||
{SCREEN_WIDTH, 0},
|
||||
{0, SCREEN_HEIGHT},
|
||||
{SCREEN_WIDTH, SCREEN_HEIGHT}
|
||||
{-1, -1},
|
||||
{ 1, -1},
|
||||
{ 1, 1},
|
||||
{-1, 1},
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{1,0},
|
||||
{0,1},
|
||||
{1,1}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
|
||||
constexpr uint16 index_data[INDEX_COUNT]=
|
||||
{
|
||||
0,1,3,
|
||||
0,3,2
|
||||
{1,1},
|
||||
{0,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
@@ -49,22 +42,28 @@ private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * renderable =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/Texture2D"));
|
||||
if(!material_instance)return(false);
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2D",Prim::Fan);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material=db->LoadMaterial("Std2D/PureTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::Fan); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
@@ -73,23 +72,28 @@ private:
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Quad",VERTEX_COUNT);
|
||||
|
||||
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V2F,VERTEX_COUNT,tex_coord_data)))return(false);
|
||||
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
|
||||
if(!rpc.WriteVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -105,16 +109,16 @@ public:
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
136
example/Texture/texture_rect.cpp
Normal file
136
example/Texture/texture_rect.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
constexpr float position_data[4]=
|
||||
{
|
||||
0, //left
|
||||
0, //top
|
||||
1, //right
|
||||
1 //bottom
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,
|
||||
1,1
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D",Prim::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
material=db->LoadMaterial("Std2D/RectTexture2D",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Rectangle",1);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
216
example/Texture/texture_rect_array.cpp
Normal file
216
example/Texture/texture_rect_array.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
// 画一个带纹理的矩形,2D模式专用
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/Filename.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
//Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
float position_data[4]=
|
||||
{
|
||||
0, //left
|
||||
0, //top
|
||||
1, //right
|
||||
1 //bottom
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,
|
||||
1,1
|
||||
};
|
||||
|
||||
constexpr const os_char *tex_filename[]=
|
||||
{
|
||||
OS_TEXT("001-online resume.Tex2D"),
|
||||
OS_TEXT("002-salary.Tex2D"),
|
||||
OS_TEXT("003-application.Tex2D"),
|
||||
OS_TEXT("004-job interview.Tex2D")
|
||||
};
|
||||
|
||||
constexpr const size_t TexCount=sizeof(tex_filename)/sizeof(os_char *);
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Texture2DArray * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
Material * material =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
DeviceBuffer * tex_id_ubo =nullptr;
|
||||
Primitive * prim_rectangle =nullptr;
|
||||
|
||||
struct
|
||||
{
|
||||
MaterialInstance * mi;
|
||||
Renderable * r;
|
||||
}render_obj[TexCount]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->CreateTexture2DArray( "freepik icons",
|
||||
512,512, ///<纹理尺寸
|
||||
TexCount, ///<纹理层数
|
||||
PF_BC1_RGBAUN, ///<纹理格式
|
||||
false); ///<是否自动产生mipmaps
|
||||
|
||||
if(!texture)return(false);
|
||||
|
||||
OSString filename;
|
||||
|
||||
for(uint i=0;i<TexCount;i++)
|
||||
{
|
||||
filename=filesystem::MergeFilename(OS_TEXT("res/image/icon/freepik"),tex_filename[i]);
|
||||
|
||||
if(!db->LoadTexture2DToArray(texture,i,filename))
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2DArray",Prim::SolidRectangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std2D/RectTexture2DArray",&cfg);
|
||||
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid2D,Prim::SolidRectangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].mi=db->CreateMaterialInstance(material);
|
||||
|
||||
if(!render_obj[i].mi)
|
||||
return(false);
|
||||
|
||||
render_obj[i].mi->WriteMIData(i); //设置MaterialInstance的数据
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBOAndRenderList()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material->GetDefaultVIL());
|
||||
|
||||
rpc.Init("Rectangle",1);
|
||||
|
||||
position_data[2]=1.0f/float(TexCount);
|
||||
|
||||
if(!rpc.WriteVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.WriteVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
prim_rectangle=rpc.Create();
|
||||
|
||||
Vector3f offset(1.0f/float(TexCount),0,0);
|
||||
|
||||
for(uint32_t i=0;i<TexCount;i++)
|
||||
{
|
||||
render_obj[i].r=db->CreateRenderable(prim_rectangle,render_obj[i].mi,pipeline);
|
||||
|
||||
if(!render_obj[i].r)
|
||||
return(false);
|
||||
|
||||
offset.x=position_data[2]*float(i);
|
||||
|
||||
render_root.CreateSubNode(translate(offset),render_obj[i].r);
|
||||
}
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_rectangle);
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH*TexCount,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -10,22 +10,11 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Vulkan/${group}")
|
||||
endmacro()
|
||||
|
||||
CreateProject("Basic" 1st_draw_triangle_in_NDC first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_draw_triangle_use_UBO second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_AutoInstance third_triangle.cpp)
|
||||
CreateProject("Basic" 4th_AutoMergeMaterialInstance fourth_triangle.cpp)
|
||||
|
||||
#CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
#CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
#CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
|
||||
#CreateProject("Basic" InstanceTriangle InstanceTriangle.cpp)
|
||||
|
||||
CreateProject("Texture" TextureFormat TextureFormat.cpp)
|
||||
#CreateProject("Texture" texture_rect texture_rect.cpp)
|
||||
#CreateProject("Texture" HQFilterTexture HQFilterTexture.cpp)
|
||||
#CreateProject(06.Geometry2D Geometry2D.cpp)
|
||||
|
||||
#CreateProject("Geometry2D" RectanglePrimitive RectanglePrimitive.cpp)
|
||||
#CreateProject("Tile" DrawTile DrawTile.cpp)
|
||||
#CreateProject("Tile" DrawText DrawText.cpp)
|
||||
|
||||
|
@@ -1,87 +0,0 @@
|
||||
// 全屏三角形
|
||||
// 该范例用于演示使用索引画一个覆盖全屏的三角形,但是不传递任何顶点信息,顶点坐标在vertex shader中通过gl_VertexIndex计算出来。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable *renderable =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/fullscreen"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(3);
|
||||
if(!primitive)return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,160 +0,0 @@
|
||||
// 4.Geometry3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
void CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.coord[0]=Vector3f(-100,-100,0);
|
||||
pgci.coord[1]=Vector3f( 100,-100,0);
|
||||
pgci.coord[2]=Vector3f( 100, 100,0);
|
||||
pgci.coord[3]=Vector3f(-100, 100,0);
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.5,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid[0]=CreatePlaneGrid(db,vil,&pgci);
|
||||
|
||||
pgci.color.Set(0,0.5,0,1);
|
||||
pgci.side_color.Set(0,1,0,1);
|
||||
|
||||
ro_plane_grid[1]=CreatePlaneGrid(db,vil,&pgci);
|
||||
|
||||
pgci.color.Set(0,0,0.5,1);
|
||||
pgci.side_color.Set(0,0,1,1);
|
||||
ro_plane_grid[2]=CreatePlaneGrid(db,vil,&pgci);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid[0],Matrix4f(1.0f));
|
||||
Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(200,200,200);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,103 +0,0 @@
|
||||
// Instance Triangle
|
||||
|
||||
// 基本的Instance绘制测试用例,不使用场景树
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_SIZE=512;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{0.25,-0.75},
|
||||
{0,-1}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data )))return(false);
|
||||
if(!primitive->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data )))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,191 +0,0 @@
|
||||
// 18.RayPicking
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
static float position_data[2][3]=
|
||||
{
|
||||
{100,100,100},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static float color_data[2][4]=
|
||||
{
|
||||
{1,1,0,1},
|
||||
{1,1,0,1}
|
||||
};
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.coord[0]=Vector3f(-100,-100,0);
|
||||
pgci.coord[1]=Vector3f( 100,-100,0);
|
||||
pgci.coord[2]=Vector3f( 100, 100,0);
|
||||
pgci.coord[3]=Vector3f(-100, 100,0);
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.25,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid=CreatePlaneGrid(db,vil,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
ro_line=db->CreatePrimitive(2);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid,Matrix4f(1.0f));
|
||||
Add(ro_line,Matrix4f(1.0f));
|
||||
|
||||
camera->pos=Vector3f(100,100,50);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
const CameraInfo &ci=GetCameraInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),&ci); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(ci,&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
// 2.RectanglePrimivate
|
||||
// 该示例是texture_rect的进化,演示使用GeometryShader画矩形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKSampler.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Texture2D *CreateTexture2DFromFile(GPUDevice *device,const OSString &filename);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
constexpr uint32_t SCREEN_SIZE=512;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=1;
|
||||
|
||||
constexpr float BORDER=0.1f;
|
||||
|
||||
constexpr float position_data[4]=
|
||||
{
|
||||
SCREEN_SIZE*BORDER, SCREEN_SIZE*BORDER,
|
||||
SCREEN_SIZE*(1.0-BORDER), SCREEN_SIZE*(1.0-BORDER)
|
||||
};
|
||||
|
||||
constexpr float tex_coord_data[4]=
|
||||
{
|
||||
0,0,1,1
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Primitive * primitive =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/TextureRect2D"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::SolidRectangles);
|
||||
if(!pipeline)return(false);
|
||||
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"));
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
|
||||
if(!primitive)return(false);
|
||||
|
||||
primitive->Set(VAN::Position,db->CreateVBO(VF_V4F,VERTEX_COUNT,position_data));
|
||||
primitive->Set(VAN::TexCoord,db->CreateVBO(VF_V4F,VERTEX_COUNT,tex_coord_data));
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(render_obj);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_SIZE,SCREEN_SIZE))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
// indices_rect
|
||||
// 该示例演示使用索引数据画一个矩形,并使用了颜色材质
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=256;
|
||||
constexpr uint32_t SCREEN_HEIGHT=256;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
static Vector4f color(1,1,1,1);
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0,0},
|
||||
{SCREEN_WIDTH,0},
|
||||
{0,SCREEN_HEIGHT},
|
||||
{SCREEN_WIDTH,SCREEN_HEIGHT}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
|
||||
constexpr uint16 index_data[INDEX_COUNT]=
|
||||
{
|
||||
0,1,3,
|
||||
0,3,2
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable *renderable =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/FragColor"));
|
||||
if(!material_instance)return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(db->CreateIBO16(INDEX_COUNT,index_data)))return(false);
|
||||
|
||||
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(renderable);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
return 0xff;
|
||||
#endif//
|
||||
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,131 +0,0 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
static float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{0.5, 0.25},
|
||||
{0.75, 0.75},
|
||||
{0.25, 0.75}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{
|
||||
{1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
//#define USE_ZERO2ONE_COORD //使用左上角0,0右下角1,1的坐标系
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
db->global_descriptor.Bind(material_instance->GetMaterial());
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||
|
||||
#ifndef USE_ZERO2ONE_COORD //使用ortho坐标系
|
||||
|
||||
for(uint i=0;i<VERTEX_COUNT;i++)
|
||||
{
|
||||
position_data[i][0]*=SCREEN_WIDTH;
|
||||
position_data[i][1]*=SCREEN_HEIGHT;
|
||||
}
|
||||
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4F, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -19,6 +19,9 @@
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#ifdef _DEBUG
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#endif//_DEBUG
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/color/Color.h>
|
||||
@@ -51,15 +54,10 @@ protected:
|
||||
protected:
|
||||
|
||||
GPUDevice * device =nullptr;
|
||||
RenderPass * device_render_pass =nullptr;
|
||||
RTSwapchain * sc_render_target =nullptr;
|
||||
SwapchainRenderTarget * sc_render_target =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
int32_t swap_chain_count =0;
|
||||
|
||||
RenderCmdBuffer ** cmd_buf =nullptr;
|
||||
|
||||
Color4f clear_color;
|
||||
|
||||
protected:
|
||||
@@ -73,6 +71,14 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
virtual void BindRenderResource(RenderResource *rr)
|
||||
{
|
||||
if(!rr)
|
||||
return;
|
||||
|
||||
rr->static_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
}
|
||||
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
CloseShaderCompiler();
|
||||
@@ -80,21 +86,20 @@ public:
|
||||
win->Unjoin(this);
|
||||
|
||||
SAFE_CLEAR(db);
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
|
||||
SAFE_CLEAR(device);
|
||||
SAFE_CLEAR(win);
|
||||
SAFE_CLEAR(inst);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
virtual bool Init(uint w,uint h)
|
||||
{
|
||||
logger::InitLogger(OS_TEXT("VulkanTest"));
|
||||
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
clear_color.Set(0,0,0,1);
|
||||
SetClearColor(COLOR::MozillaCharcoal);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!CheckStrideBytesByFormat())
|
||||
@@ -126,36 +131,50 @@ public:
|
||||
return(false);
|
||||
}
|
||||
|
||||
device=CreateRenderDevice(inst,win);
|
||||
{
|
||||
VulkanHardwareRequirement vh_req;
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
vh_req.wideLines=VulkanHardwareRequirement::SupportLevel::Want;
|
||||
|
||||
device_render_pass=device->GetRenderPass();
|
||||
device=CreateRenderDevice(inst,win,&vh_req);
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
|
||||
sc_render_target=device->GetSwapchainRT();
|
||||
}
|
||||
|
||||
db=new RenderResource(device);
|
||||
|
||||
InitCommandBuffer();
|
||||
|
||||
win->Join(this);
|
||||
|
||||
{
|
||||
vp_info.Set(w,h);
|
||||
|
||||
ubo_vp_info=db->CreateUBO(sizeof(ViewportInfo),&vp_info);
|
||||
|
||||
db->global_descriptor.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
ubo_vp_info=db->CreateUBO("Viewport",sizeof(ViewportInfo),&vp_info);
|
||||
}
|
||||
|
||||
BindRenderResource(db);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void Resize(int w,int h)
|
||||
virtual void Resize(uint w,uint h)
|
||||
{
|
||||
vp_info.Set(w,h);
|
||||
ubo_vp_info->Write(&vp_info);
|
||||
}
|
||||
|
||||
ViewportInfo *GetViewportInfo()
|
||||
{
|
||||
return &vp_info;
|
||||
}
|
||||
|
||||
DeviceBuffer *GetViewportInfoBuffer()
|
||||
{
|
||||
return ubo_vp_info;
|
||||
}
|
||||
|
||||
void SetClearColor(const Color4f &cc)
|
||||
{
|
||||
clear_color=cc;
|
||||
@@ -171,73 +190,53 @@ public:
|
||||
if(w>0&&h>0)
|
||||
device->Resize(w,h);
|
||||
|
||||
InitCommandBuffer();
|
||||
sc_render_target=device->GetSwapchainRT();
|
||||
|
||||
Resize(w,h);
|
||||
}
|
||||
|
||||
void InitCommandBuffer()
|
||||
{
|
||||
if(cmd_buf)
|
||||
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
||||
|
||||
sc_render_target=device->GetSwapchainRT();
|
||||
|
||||
swap_chain_count=sc_render_target->GetImageCount();
|
||||
{
|
||||
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||
|
||||
cmd_buf=hgl_zero_new<RenderCmdBuffer *>(swap_chain_count);
|
||||
|
||||
for(int32_t i=0;i<swap_chain_count;i++)
|
||||
cmd_buf[i]=device->CreateRenderCommandBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,RenderPass *rp,Framebuffer *fb,Renderable *ri)
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,Framebuffer *fb,Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
const VertexInputData *vid=ri->GetVertexInputData();
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(rp,fb);
|
||||
cb->BindFramebuffer(fb);
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
cb->BindPipeline(ri->GetPipeline());
|
||||
cb->BindDescriptorSets(ri->GetMaterial());
|
||||
cb->BindVBO(ri);
|
||||
|
||||
if (vid->index_buffer->buffer)
|
||||
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
|
||||
else
|
||||
cb->Draw(vid->vertex_count);
|
||||
|
||||
cb->BindDataBuffer(ri->GetDataBuffer());
|
||||
cb->Draw(ri->GetDataBuffer(),ri->GetRenderData());
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BuildCommandBuffer(RenderCmdBuffer *cb,RenderTarget *rt,Renderable *ri)
|
||||
bool BuildCommandBuffer(RenderCmdBuffer *cb,RenderTarget *rt,Renderable *ri)
|
||||
{
|
||||
if(!cb||!rt||!ri)
|
||||
return;
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(cb,rt->GetRenderPass(),rt->GetFramebuffer(),ri);
|
||||
return BuildCommandBuffer(cb,rt->GetFramebuffer(),ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(uint32_t index,Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
return BuildCommandBuffer(cmd_buf[index],sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index),ri);
|
||||
IRenderTarget *rt=sc_render_target->GetCurrentFrameRenderTarget();
|
||||
|
||||
return BuildCommandBuffer(rt->GetRenderCmdBuffer(),
|
||||
rt->GetFramebuffer(),
|
||||
ri);
|
||||
}
|
||||
|
||||
bool BuildCommandBuffer(Renderable *ri)
|
||||
{
|
||||
if(!ri)return(false);
|
||||
|
||||
for(int32_t i=0;i<swap_chain_count;i++)
|
||||
for(uint32_t i=0;i<sc_render_target->GetFrameCount();i++)
|
||||
BuildCommandBuffer(i,ri);
|
||||
|
||||
return(true);
|
||||
@@ -254,10 +253,10 @@ public:
|
||||
{
|
||||
if(!rl)return;
|
||||
|
||||
RenderCmdBuffer *cb=cmd_buf[index];
|
||||
RenderCmdBuffer *cb=sc_render_target->GetRenderCmdBuffer(index);
|
||||
|
||||
cb->Begin();
|
||||
cb->BindFramebuffer(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
||||
cb->BindFramebuffer(sc_render_target->GetFramebuffer(index));
|
||||
cb->SetClearColor(0,clear_color);
|
||||
cb->BeginRenderPass();
|
||||
rl->Render(cb);
|
||||
@@ -267,7 +266,7 @@ public:
|
||||
|
||||
void BuildCommandBuffer(RenderList *rl)
|
||||
{
|
||||
for(int32_t i=0;i<swap_chain_count;i++)
|
||||
for(uint32_t i=0;i<sc_render_target->GetFrameCount();i++)
|
||||
BuildCommandBuffer(i,rl);
|
||||
}
|
||||
|
||||
@@ -277,7 +276,22 @@ public:
|
||||
}
|
||||
|
||||
template<typename ...ARGS>
|
||||
Pipeline *CreatePipeline(ARGS...args){return device_render_pass->CreatePipeline(args...);}
|
||||
Pipeline *CreatePipeline(ARGS...args)
|
||||
{
|
||||
Pipeline *p=sc_render_target->GetRenderPass()->CreatePipeline(args...);
|
||||
|
||||
if(!p)
|
||||
return(nullptr);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
du->SetPipeline(*p,"Pipeline:"+p->GetName());
|
||||
#endif//_DEBUG
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -286,11 +300,9 @@ public:
|
||||
return sc_render_target->AcquireNextImage();
|
||||
}
|
||||
|
||||
virtual void SubmitDraw(int index)
|
||||
virtual void SubmitDraw()
|
||||
{
|
||||
VkCommandBuffer cb=*cmd_buf[index];
|
||||
|
||||
sc_render_target->Submit(cb);
|
||||
sc_render_target->Submit();
|
||||
sc_render_target->PresentBackbuffer();
|
||||
sc_render_target->WaitQueue();
|
||||
sc_render_target->WaitFence();
|
||||
@@ -300,9 +312,9 @@ public:
|
||||
{
|
||||
int index=AcquireNextImage();
|
||||
|
||||
if(index<0||index>=swap_chain_count)return;
|
||||
if(index<0||index>=sc_render_target->GetFrameCount())return;
|
||||
|
||||
SubmitDraw(index);
|
||||
SubmitDraw();
|
||||
}
|
||||
|
||||
bool Run()
|
||||
@@ -368,7 +380,7 @@ class CameraMouseControl:public MouseEvent
|
||||
Vector2f mouse_pos;
|
||||
Vector2f mouse_last_pos;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
bool OnPressed(int x,int y,MouseButton) override
|
||||
{
|
||||
@@ -426,6 +438,7 @@ public:
|
||||
{
|
||||
camera=wc;
|
||||
cur_time=0;
|
||||
last_time=0;
|
||||
}
|
||||
|
||||
const Vector2f &GetMouseCoord()const{return mouse_pos;}
|
||||
@@ -438,7 +451,6 @@ public:
|
||||
|
||||
class CameraAppFramework:public VulkanApplicationFramework
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
Camera * camera =nullptr;
|
||||
@@ -454,6 +466,15 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
virtual void BindRenderResource(RenderResource *rr) override
|
||||
{
|
||||
if(!rr)return;
|
||||
|
||||
VulkanApplicationFramework::BindRenderResource(rr);
|
||||
|
||||
rr->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual ~CameraAppFramework()
|
||||
{
|
||||
SAFE_CLEAR(ckc);
|
||||
@@ -461,17 +482,23 @@ public:
|
||||
SAFE_CLEAR(camera);
|
||||
}
|
||||
|
||||
virtual bool Init(int w,int h)
|
||||
virtual bool Init(uint w,uint h) override
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
InitCamera(w,h);
|
||||
|
||||
BindRenderResource(db);
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void InitCamera(int w,int h)
|
||||
{
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera_control=new FirstPersonCameraControl(&vp_info,camera);
|
||||
|
||||
camera_control->Refresh(); //更新矩阵计算
|
||||
@@ -482,25 +509,21 @@ public:
|
||||
win->Join(ckc);
|
||||
win->Join(cmc);
|
||||
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
|
||||
RefreshCameraInfo(camera_control->GetCameraInfo(),&vp_info,camera);
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera_control->GetCameraInfo());
|
||||
ubo_camera_info=db->CreateUBO("CameraInfo",sizeof(CameraInfo),camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
vp_info.Set(w,h);
|
||||
|
||||
camera_control->Refresh();
|
||||
|
||||
ubo_camera_info->Write(&camera_control->GetCameraInfo());
|
||||
ubo_camera_info->Write(camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
const CameraInfo &GetCameraInfo()
|
||||
CameraInfo *GetCameraInfo()
|
||||
{
|
||||
return camera_control->GetCameraInfo();
|
||||
}
|
||||
@@ -510,26 +533,72 @@ public:
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(MaterialInstance *mi)
|
||||
{
|
||||
return mi->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
{
|
||||
camera_control->Refresh(); //更新相机矩阵
|
||||
|
||||
ubo_camera_info->Write(&camera_control->GetCameraInfo()); //写入缓冲区
|
||||
ubo_camera_info->Write(camera_control->GetCameraInfo()); //写入缓冲区
|
||||
|
||||
const uint32_t index=AcquireNextImage();
|
||||
|
||||
BuildCommandBuffer(index);
|
||||
|
||||
SubmitDraw(index);
|
||||
SubmitDraw();
|
||||
|
||||
ckc->Update();
|
||||
cmc->Update();
|
||||
}
|
||||
};//class CameraAppFramework
|
||||
};//class CameraAppFramework
|
||||
|
||||
class SceneAppFramework:public CameraAppFramework
|
||||
{
|
||||
protected:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
SceneAppFramework()=default;
|
||||
|
||||
virtual ~SceneAppFramework()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
virtual bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!CameraAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32 index) override
|
||||
{
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
||||
virtual void Resize(uint w,uint h) override
|
||||
{
|
||||
CameraAppFramework::Resize(w,h);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class SceneAppFramework:public CameraAppFramework
|
||||
|
||||
template<typename T> int RunApp(uint w,uint h)
|
||||
{
|
||||
T app;
|
||||
|
||||
if(!app.Init(w,h))
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@@ -7,7 +7,7 @@ namespace hgl
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 2Dλͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* 2D位图加载类
|
||||
*/
|
||||
class Bitmap2DLoader:public Texture2DLoader
|
||||
{
|
||||
@@ -20,8 +20,8 @@ namespace hgl
|
||||
Bitmap2DLoader():Texture2DLoader(){}
|
||||
~Bitmap2DLoader();
|
||||
|
||||
void *OnBegin(uint32 total_bytes) override;
|
||||
void OnEnd() override {}
|
||||
void *OnBegin(uint32 total_bytes,const VkFormat &) override;
|
||||
bool OnEnd() override {return(false);}
|
||||
|
||||
BitmapData *GetBitmap();
|
||||
};//class Bitmap2DLoader
|
||||
|
@@ -4,12 +4,15 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/math/Vector.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/Size2.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class PrimitiveCreater;
|
||||
|
||||
namespace inline_geometry
|
||||
{
|
||||
/**
|
||||
@@ -20,12 +23,12 @@ namespace hgl
|
||||
RectScope2f scope;
|
||||
};//struct RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci);
|
||||
Primitive *CreateRectangle(PrimitiveCreater *pc,const RectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 创建延迟渲染用全屏平面
|
||||
*/
|
||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil);
|
||||
Primitive *CreateGBufferCompositionRectangle(PrimitiveCreater *pc);
|
||||
|
||||
/**
|
||||
* 圆角矩形创建信息(扇形/线圈)
|
||||
@@ -36,7 +39,7 @@ namespace hgl
|
||||
uint32_t round_per; ///<圆角精度
|
||||
};//struct RoundRectangleCreateInfo:public RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci);
|
||||
Primitive *CreateRoundRectangle(PrimitiveCreater *pc,const RoundRectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 圆形创建信息
|
||||
@@ -45,9 +48,9 @@ namespace hgl
|
||||
{
|
||||
Vector2f center; ///<圆心坐标
|
||||
Vector2f radius; ///<半径
|
||||
uint field_count=8; ///<分段次数
|
||||
uint field_count=8; ///<分段数量
|
||||
|
||||
bool has_color =false;
|
||||
bool has_center; ///<是否有圆心点
|
||||
|
||||
Vector4f center_color; ///<圆心颜色
|
||||
Vector4f border_color; ///<边缘颜色
|
||||
@@ -56,44 +59,43 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个2D圆形(扇形/线圈)
|
||||
*/
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
|
||||
Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个3D圆形(扇形/圆形,XY,Z永远为0)
|
||||
*/
|
||||
Primitive *CreateCircle3D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息
|
||||
* 创建一个使用三角形绘制的3D圆形(扇形/圆形,XY,Z永远为0)
|
||||
*/
|
||||
Primitive *CreateCircle3DByIndexTriangles(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息<br>
|
||||
* 会创建一个在XY平面上居中的网格,单个格子尺寸为1。
|
||||
*/
|
||||
struct PlaneGridCreateInfo
|
||||
{
|
||||
Vector3f coord[4];
|
||||
Vector2u step;
|
||||
Size2u grid_size; ///<格子数量
|
||||
|
||||
Vector2u side_step; //到边界的步数
|
||||
Size2u sub_count; ///<细分格子数量
|
||||
|
||||
Color4f color; //一般线条颜色
|
||||
Color4f side_color; //边界线条颜色
|
||||
uint8 lum; ///<一般线条亮度
|
||||
uint8 sub_lum; ///<细分及边界线条亮度
|
||||
};//struct PlaneGridCreateInfo
|
||||
|
||||
/**
|
||||
* 创建一个平面网格(线条)
|
||||
*/
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
|
||||
Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci); //创建一个平面网格(线条)
|
||||
|
||||
struct PlaneCreateInfo
|
||||
{
|
||||
Vector2f tile;
|
||||
|
||||
public:
|
||||
|
||||
PlaneCreateInfo()
|
||||
{
|
||||
tile.x=1.0f;
|
||||
tile.y=1.0f;
|
||||
}
|
||||
};//struct PlaneCreateInfo
|
||||
Primitive *CreatePlaneGrid3D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci);
|
||||
|
||||
/**
|
||||
* 创建一个平面(三角形)
|
||||
* 创建一个平面正方形(三角形)
|
||||
*/
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil,const PlaneCreateInfo *pci);
|
||||
Primitive *CreatePlaneSqaure(PrimitiveCreater *pc);
|
||||
|
||||
struct CubeCreateInfo
|
||||
{
|
||||
@@ -129,7 +131,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个立方体(三角形)
|
||||
*/
|
||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci);
|
||||
Primitive *CreateCube(PrimitiveCreater *pc,const CubeCreateInfo *cci);
|
||||
|
||||
struct BoundingBoxCreateInfo
|
||||
{
|
||||
@@ -160,17 +162,17 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个绑定盒(线条)
|
||||
*/
|
||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci);
|
||||
Primitive *CreateBoundingBox(PrimitiveCreater *pc,const BoundingBoxCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个球心坐标为0,0,0,半径为1的球体(三角形)
|
||||
*/
|
||||
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices);
|
||||
Primitive *CreateSphere(PrimitiveCreater *,const uint numberSlices);
|
||||
|
||||
/**
|
||||
* 创建一个穹顶(三角形)
|
||||
*/
|
||||
Primitive *CreateDome(RenderResource *db,const VIL *vil, const uint numberSlices);
|
||||
Primitive *CreateDome(PrimitiveCreater *pc, const uint numberSlices);
|
||||
|
||||
struct TorusCreateInfo
|
||||
{
|
||||
@@ -186,7 +188,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆环(三角形)
|
||||
*/
|
||||
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci);
|
||||
Primitive *CreateTorus(PrimitiveCreater *pc,const TorusCreateInfo *tci);
|
||||
|
||||
struct CylinderCreateInfo
|
||||
{
|
||||
@@ -198,7 +200,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆柱(三角形)
|
||||
*/
|
||||
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci);
|
||||
Primitive *CreateCylinder(PrimitiveCreater *,const CylinderCreateInfo *cci);
|
||||
|
||||
struct ConeCreateInfo
|
||||
{
|
||||
@@ -211,7 +213,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆锥(三角形)
|
||||
*/
|
||||
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci);
|
||||
Primitive *CreateCone(PrimitiveCreater *,const ConeCreateInfo *cci);
|
||||
|
||||
struct AxisCreateInfo
|
||||
{
|
||||
@@ -232,7 +234,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个坐标线(线条)
|
||||
*/
|
||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci);
|
||||
Primitive *CreateAxis(PrimitiveCreater *pc,const AxisCreateInfo *aci);
|
||||
}//namespace inline_geometry
|
||||
}//namespace graph
|
||||
};//namespace hgl
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_LIGHT_INCLUDE
|
||||
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/Color4f.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
|
@@ -1,75 +1,125 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
#include<hgl/graph/VKVABList.h>
|
||||
#include<hgl/graph/VKIndirectCommandBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderAssignBuffer;
|
||||
class SceneNode;
|
||||
struct CameraInfo;
|
||||
|
||||
struct RenderPipelineIndex:public Comparator<RenderPipelineIndex>
|
||||
{
|
||||
Material *material;
|
||||
Pipeline *pipeline;
|
||||
|
||||
public:
|
||||
|
||||
const int compare(const RenderPipelineIndex &rli)const override
|
||||
{
|
||||
if(material<rli.material)return(-1);
|
||||
if(material>rli.material)return(1);
|
||||
|
||||
if(pipeline<rli.pipeline)return(-1);
|
||||
if(pipeline>rli.pipeline)return(1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
RenderPipelineIndex()
|
||||
{
|
||||
material=nullptr;
|
||||
pipeline=nullptr;
|
||||
}
|
||||
|
||||
RenderPipelineIndex(Material *m,Pipeline *p)
|
||||
{
|
||||
material=m;
|
||||
pipeline=p;
|
||||
}
|
||||
};//struct RenderPipelineIndex
|
||||
|
||||
/**
|
||||
* 同一材质的对象渲染列表
|
||||
* 同一材质与管线的渲染列表
|
||||
*/
|
||||
class MaterialRenderList
|
||||
{
|
||||
GPUDevice *device;
|
||||
RenderCmdBuffer *cmd_buf;
|
||||
|
||||
Material *mtl;
|
||||
RenderPipelineIndex rp_index;
|
||||
|
||||
CameraInfo *camera_info;
|
||||
|
||||
RenderNodeList rn_list;
|
||||
|
||||
RenderNodePointerList rn_update_l2w_list;
|
||||
|
||||
private:
|
||||
|
||||
RenderAssignBuffer *assign_buffer;
|
||||
|
||||
struct RenderItem
|
||||
{
|
||||
uint32_t first;
|
||||
uint32_t count;
|
||||
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
|
||||
uint32_t instance_count;
|
||||
|
||||
Pipeline * pipeline;
|
||||
MaterialInstance * mi;
|
||||
const VertexInputData * vid;
|
||||
MaterialInstance * mi;
|
||||
|
||||
const PrimitiveDataBuffer * pdb;
|
||||
const PrimitiveRenderData * prd;
|
||||
|
||||
public:
|
||||
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
MaterialInstanceSets mi_set;
|
||||
IndirectDrawBuffer *icb_draw;
|
||||
IndirectDrawIndexedBuffer *icb_draw_indexed;
|
||||
|
||||
void ReallocICB();
|
||||
void WriteICB(VkDrawIndirectCommand *,RenderItem *ri);
|
||||
void WriteICB(VkDrawIndexedIndirectCommand *,RenderItem *ri);
|
||||
|
||||
DataArray<RenderItem> ri_array;
|
||||
uint ri_count;
|
||||
|
||||
void StatMI();
|
||||
void Stat();
|
||||
|
||||
protected:
|
||||
|
||||
VBOList * vbo_list;
|
||||
VABList * vab_list;
|
||||
|
||||
const VIL * last_vil;
|
||||
Pipeline * last_pipeline;
|
||||
const VertexInputData * last_vid;
|
||||
uint last_index;
|
||||
const PrimitiveDataBuffer * last_data_buffer;
|
||||
const VDM * last_vdm;
|
||||
const PrimitiveRenderData * last_render_data;
|
||||
|
||||
void Bind(MaterialInstance *);
|
||||
bool Bind(const VertexInputData *,const uint);
|
||||
int first_indirect_draw_index=-1;
|
||||
uint indirect_draw_count=0;
|
||||
|
||||
bool BindVAB(const PrimitiveDataBuffer *,const uint);
|
||||
|
||||
void ProcIndirectRender();
|
||||
void Render(RenderItem *);
|
||||
|
||||
public:
|
||||
|
||||
MaterialRenderList(GPUDevice *d,Material *m);
|
||||
MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi);
|
||||
~MaterialRenderList();
|
||||
|
||||
void Add(Renderable *ri,const Matrix4f &mat);
|
||||
void Add(SceneNode *);
|
||||
|
||||
void Clear()
|
||||
{
|
||||
rn_list.Clear();
|
||||
}
|
||||
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
|
||||
|
||||
void Clear(){rn_list.Clear();}
|
||||
|
||||
void End();
|
||||
|
||||
void Render(RenderCmdBuffer *);
|
||||
|
||||
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
|
||||
void UpdateMaterialInstance(SceneNode *);
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -2,17 +2,20 @@
|
||||
#include<hgl/graph/MaterialRenderList.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
|
||||
class MaterialRenderMap:public ObjectMap<RenderPipelineIndex,MaterialRenderList>
|
||||
{
|
||||
public:
|
||||
|
||||
MaterialRenderMap()=default;
|
||||
virtual ~MaterialRenderMap()=default;
|
||||
|
||||
void Begin()
|
||||
void Begin(CameraInfo *ci)
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
{
|
||||
it->value->SetCameraInfo(ci);
|
||||
it->value->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void End()
|
||||
@@ -28,5 +31,11 @@ public:
|
||||
for(auto *it:data_list)
|
||||
it->value->Render(rcb);
|
||||
}
|
||||
|
||||
void UpdateLocalToWorld()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->UpdateLocalToWorld();
|
||||
}
|
||||
};//class MaterialRenderMap
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,85 +1,81 @@
|
||||
#ifndef HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#define HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
namespace hgl
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 可绘制原始图形创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
struct PrimitiveVertexBuffer
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
protected:
|
||||
|
||||
public:
|
||||
GPUDevice * device;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
~PrimitiveVertexBuffer()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct PrimitiveVertexBuffer
|
||||
const VIL * vil;
|
||||
|
||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
AnsiString prim_name;
|
||||
PrimitiveData * prim_data;
|
||||
|
||||
RenderResource *db;
|
||||
Material *mtl;
|
||||
uint32_t vertices_number; ///<顶点数量
|
||||
|
||||
const VIL *vil;
|
||||
bool has_index; ///<是否有索引
|
||||
uint32_t index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
const int InitVAB(const AnsiString &name,const VkFormat format,const void *data); ///<取得顶点属性索引
|
||||
|
||||
uint32 vertices_number;
|
||||
public:
|
||||
|
||||
IndexBuffer * ibo;
|
||||
PVBMap vbo_map;
|
||||
PrimitiveCreater(GPUDevice *,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
public:
|
||||
/**
|
||||
* 初始化一个原始图形创建
|
||||
* @parama name 原始图形名称
|
||||
* @parama vertices_count 顶点数量
|
||||
* @parama index_count 索引数量
|
||||
* @parama it 索引类型(注:当使用VDM时,此值无效)
|
||||
*/
|
||||
bool Init(const AnsiString &name,
|
||||
const uint32_t vertices_count,
|
||||
const uint32_t index_count=0,IndexType it=IndexType::AUTO);
|
||||
|
||||
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
||||
virtual ~PrimitiveCreater()=default;
|
||||
void Clear(); ///<清除创建器数据
|
||||
|
||||
virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量
|
||||
public: //顶点缓冲区
|
||||
|
||||
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
template<typename T>
|
||||
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
VABMap * GetVABMap (const AnsiString &name,const VkFormat format=VK_FORMAT_UNDEFINED);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat format,const void *data); ///<直接写入顶点属性数据
|
||||
|
||||
VAD *vad=this->CreateVAD(name);
|
||||
public: //索引缓冲区
|
||||
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
const bool hasIndex()const{return vdm?has_index:index_number>0;} ///<是否有索引缓冲区
|
||||
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
|
||||
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量
|
||||
|
||||
T *access=T::Create(vad);
|
||||
IBMap * GetIBMap();
|
||||
|
||||
access->Begin();
|
||||
bool WriteIBO(const void *data,const uint32_t count);
|
||||
|
||||
return access;
|
||||
}
|
||||
template<typename T>
|
||||
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
|
||||
|
||||
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
public: //创建可渲染对象
|
||||
|
||||
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
|
||||
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
|
||||
|
||||
virtual Primitive * Finish(); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
|
||||
};//class PrimitiveCreater
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -20,6 +20,8 @@ namespace hgl
|
||||
|
||||
GPUDevice * device;
|
||||
|
||||
CameraInfo * camera_info; ///<相机信息
|
||||
|
||||
uint renderable_count; ///<可渲染对象数量
|
||||
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
|
||||
|
||||
@@ -30,13 +32,17 @@ namespace hgl
|
||||
public:
|
||||
|
||||
RenderList(GPUDevice *);
|
||||
virtual ~RenderList();
|
||||
virtual ~RenderList()=default;
|
||||
|
||||
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
||||
virtual void SetCamera(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
|
||||
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
|
||||
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@@ -2,28 +2,42 @@
|
||||
#define HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Renderable;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class GPUDevice;
|
||||
struct VertexInputData;
|
||||
struct IndexBufferData;
|
||||
class SceneNode;
|
||||
|
||||
struct RenderNode
|
||||
struct RenderNode:public Comparator<RenderNode>
|
||||
{
|
||||
Matrix4f local_to_world;
|
||||
uint index; ///<在MaterialRenderList中的索引
|
||||
|
||||
Renderable *ri;
|
||||
SceneNode * scene_node;
|
||||
|
||||
uint32 l2w_version;
|
||||
uint32 l2w_index;
|
||||
|
||||
Vector3f world_position;
|
||||
float to_camera_distance;
|
||||
|
||||
public:
|
||||
|
||||
//该函数位于MaterialRenderList.cpp
|
||||
const int compare(const RenderNode &)const override;
|
||||
};
|
||||
|
||||
using RenderNodeList=List<RenderNode>;
|
||||
using RenderNodePointerList=List<RenderNode *>;
|
||||
|
||||
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
|
||||
using MaterialInstanceSets=SortedSet<MaterialInstance *>; ///<材质实例集合
|
||||
}//namespace graph
|
||||
|
||||
template<> inline const int ItemComparator<graph::RenderNode>::compare(const graph::RenderNode &a,const graph::RenderNode &b)
|
||||
{
|
||||
return a.compare(b);
|
||||
}
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE
|
||||
|
84
inc/hgl/graph/RenderResourceType.h
Normal file
84
inc/hgl/graph/RenderResourceType.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
enum class ResourceType
|
||||
{
|
||||
Unknown=0,
|
||||
|
||||
VkInstance,
|
||||
VkPhysicalDevice,
|
||||
VkDevice,
|
||||
|
||||
VertexInputLayout,
|
||||
Material,
|
||||
MaterialInstance,
|
||||
|
||||
FrameBuffer,
|
||||
|
||||
Texture,
|
||||
Sampler,
|
||||
|
||||
VertexBuffer,
|
||||
IndexBuffer,
|
||||
IndirectBuffer,
|
||||
UniformBuffer,
|
||||
StorageBuffer,
|
||||
|
||||
Skeleton, ///<骨骼信息
|
||||
SkeletonAnime, ///<骨骼动画信息
|
||||
|
||||
Primitive, ///<原始的单个模型数据,由多个VBO+Index组成
|
||||
RawMesh, ///<原始的静态模型数据,由一个Primitive和一个MaterialInstance组成
|
||||
StaticMesh, ///<静态模型数据,由一个或多个RawMesh组成
|
||||
SkeletonMesh, ///<骨骼模型数据,由一个或多个StaticMesh组成
|
||||
|
||||
Font,
|
||||
|
||||
Scene,
|
||||
Animation,
|
||||
Audio,
|
||||
Other,
|
||||
|
||||
ENUM_CLASS_RANGE(Unknown,Other)
|
||||
};
|
||||
|
||||
enum class ResourcePlace
|
||||
{
|
||||
Unknown=0,
|
||||
|
||||
Memory, ///<内存
|
||||
Device, ///<设备(如显存)
|
||||
Disk, ///<硬盘
|
||||
LAN, ///<局域网
|
||||
WAN, ///<广域网
|
||||
Other,
|
||||
|
||||
ENUM_CLASS_RANGE(Device,Other)
|
||||
};
|
||||
|
||||
struct RenderResourceID
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint device:1; ///<在设备
|
||||
uint memory:1; ///<在内存
|
||||
|
||||
uint disk:1; ///<在硬盘
|
||||
uint network:1; ///<在网络
|
||||
};
|
||||
|
||||
uint8 place; ///<数据所在位置
|
||||
};
|
||||
|
||||
uint16 resource_type; ///<资源类型,对应ResourceType枚举
|
||||
|
||||
uint16 thread_id; ///<线程ID
|
||||
|
||||
uint32 id; ///<资源ID
|
||||
};
|
||||
VK_NAMESPACE_END
|
@@ -1,38 +0,0 @@
|
||||
#ifndef HGL_GRAPH_SCENE_INFO_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_INFO_INCLUDE
|
||||
|
||||
#include<hgl/math/Matrix.h>
|
||||
#include<hgl/CompOperator.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* MVP矩阵
|
||||
*/
|
||||
struct MVPMatrix
|
||||
{
|
||||
Matrix4f model; ///< model: Local to World
|
||||
//Matrix4f normal; ///<transpose(inverse(mat3(model)));
|
||||
Matrix3x4f normal; ///<这里用3x4,在Shader中是3x3(但实际它是3x4保存)
|
||||
|
||||
Matrix4f mv; ///< view * model
|
||||
Matrix4f mvp; ///< projection * view * model
|
||||
|
||||
public:
|
||||
|
||||
void Set(const Matrix4f &local_to_world,const Matrix4f &view_projection,const Matrix4f &view)
|
||||
{
|
||||
model =local_to_world;
|
||||
normal =transpose(inverse(model));
|
||||
mv =view*model;
|
||||
mvp =view_projection*model;
|
||||
}
|
||||
|
||||
CompOperatorMemcmp(const MVPMatrix &);
|
||||
};//struct MVPMatrix
|
||||
|
||||
constexpr size_t MVPMatrixBytes=sizeof(MVPMatrix);
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_INFO_INCLUDE
|
31
inc/hgl/graph/SceneManager.h
Normal file
31
inc/hgl/graph/SceneManager.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 场景管理器<Br>
|
||||
* 管理一个场景中的所有资源与场景节点
|
||||
*/
|
||||
class SceneManager
|
||||
{
|
||||
SceneNode *root_node;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
SceneNode *GetSceneRoot() {return root_node;}
|
||||
const SceneNode *GetSceneRoot()const{return root_node;}
|
||||
|
||||
const uint GetNodeCount()const { return node_list.GetCount(); }
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
};//class SceneManager
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
116
inc/hgl/graph/SceneMatrix.h
Normal file
116
inc/hgl/graph/SceneMatrix.h
Normal file
@@ -0,0 +1,116 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/math/Transform.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 场景节点矩阵类<br>
|
||||
*
|
||||
* 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。<br>
|
||||
* 构成说明:<br>
|
||||
* <ul>
|
||||
* <li>LocalMatrix 一般用于描述当前节点相对上一级的变换矩阵</li>
|
||||
* <li>LocalToWorldMatrix 最终用于描述当前节点相对于世界的变换矩阵,在渲染时使用</li>
|
||||
*
|
||||
* <li>transform_manager 用于管理当前节点所有的变换情况,如果本节点不存在额外变换,数量为0。</li>
|
||||
* </ul>
|
||||
*
|
||||
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TransformMatrix<br>
|
||||
*/
|
||||
class SceneMatrix :public VersionData<Matrix4f>
|
||||
{
|
||||
protected:
|
||||
|
||||
Matrix4f parent_matrix;
|
||||
Matrix4f local_matrix;
|
||||
bool local_is_identity;
|
||||
|
||||
Vector3f local_normal;
|
||||
|
||||
TransformManager transform_manager;
|
||||
Matrix4f transform_matrix;
|
||||
|
||||
protected:
|
||||
|
||||
Vector3f OriginWorldPosition; //变换前世界坐标
|
||||
Vector3f FinalWorldPosition; //变换后世界坐标
|
||||
|
||||
Vector3f OriginWorldNormal; //变换前世界法线
|
||||
Vector3f FinalWorldNormal; //变换后世界法线
|
||||
|
||||
protected:
|
||||
|
||||
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
|
||||
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
|
||||
|
||||
void MakeNewestData(Matrix4f &local_to_world_matrix) override; ///<生成最新的数据(需要派生类重载)
|
||||
|
||||
public:
|
||||
|
||||
void Clear();
|
||||
|
||||
const Matrix4f &GetLocalMatrix()const{return local_matrix;} ///<取得本地矩阵
|
||||
const Vector3f &GetLocalNormal()const{return local_normal;} ///<取得本地法线
|
||||
|
||||
const Matrix4f &GetLocalToWorldMatrix(){return GetNewestVersionData();} ///<取得本地到世界矩阵
|
||||
const Matrix4f &GetInverseLocalToWorldMatrix(){UpdateNewestData();return inverse_local_to_world_matrix;} ///<取得世界到本地矩阵
|
||||
const Matrix4f &GetInverseTransposeLocalToWorldMatrix() ///<取得世界到本地矩阵的转置矩阵
|
||||
{
|
||||
UpdateNewestData();
|
||||
return inverse_transpose_local_to_world_matrix;
|
||||
}
|
||||
|
||||
TransformManager &GetTransform(){return transform_manager;} ///<取得变换管理器
|
||||
|
||||
const Vector3f &GetWorldPosition()const{return FinalWorldPosition;} ///<取得世界坐标
|
||||
const Vector3f &GetWorldNormal()const { return FinalWorldNormal; } ///<取得世界法线
|
||||
|
||||
public:
|
||||
|
||||
SceneMatrix():VersionData(Identity4f){Clear();}
|
||||
SceneMatrix(SceneMatrix &so);
|
||||
SceneMatrix(const Matrix4f &mat):VersionData(Identity4f)
|
||||
{
|
||||
SetLocalMatrix(mat);
|
||||
UpdateVersion();
|
||||
}
|
||||
|
||||
void SetLocalNormal(const Vector3f &normal)
|
||||
{
|
||||
//if(IsNearlyEqual(local_normal,normal))
|
||||
if(!hgl_cmp(local_normal,normal))
|
||||
return;
|
||||
|
||||
local_normal=normal;
|
||||
UpdateVersion();
|
||||
}
|
||||
|
||||
void SetLocalMatrix(const Matrix4f &mat)
|
||||
{
|
||||
//if (IsNearlyEqual(local_matrix,mat))
|
||||
if(!hgl_cmp(local_matrix,mat))
|
||||
return;
|
||||
|
||||
local_matrix=mat;
|
||||
local_is_identity=IsIdentityMatrix(mat);
|
||||
|
||||
UpdateVersion();
|
||||
}
|
||||
|
||||
void SetParentMatrix(const Matrix4f &pm)
|
||||
{
|
||||
//if (IsNearlyEqual(parent_matrix,pm))
|
||||
if(!hgl_cmp(parent_matrix,pm))
|
||||
return;
|
||||
|
||||
parent_matrix=pm;
|
||||
UpdateVersion();
|
||||
}
|
||||
|
||||
virtual void Update();
|
||||
};//class SceneMatrix
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -2,13 +2,16 @@
|
||||
#define HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/type/IDName.h>
|
||||
#include<hgl/graph/SceneOrient.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
using SceneNodeID =uint64;
|
||||
using SceneNodeName =U16IDName;
|
||||
|
||||
/**
|
||||
* 场景节点数据类<br>
|
||||
* 从场景坐标变换(SceneOrient)类继承,
|
||||
@@ -16,69 +19,80 @@ namespace hgl
|
||||
*/
|
||||
class SceneNode:public SceneOrient ///场景节点类
|
||||
{
|
||||
SceneNode *Owner; ///<上级节点
|
||||
|
||||
SceneNodeID NodeID; ///<节点ID
|
||||
SceneNodeName NodeName; ///<节点名称
|
||||
|
||||
protected:
|
||||
|
||||
AABB BoundingBox; ///<绑定盒
|
||||
AABB LocalBoundingBox; ///<本地坐标绑定盒
|
||||
AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
|
||||
Vector4f Center; ///<中心点
|
||||
Vector4f LocalCenter; ///<本地坐标中心点
|
||||
Vector4f WorldCenter; ///<世界坐标中心点
|
||||
//AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
|
||||
Renderable *render_obj=nullptr; ///<可渲染实例
|
||||
|
||||
protected:
|
||||
|
||||
ObjectList<SceneNode> ChildNode; ///<子节点
|
||||
|
||||
public:
|
||||
|
||||
ObjectList<SceneNode> SubNode; ///<子节点
|
||||
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
|
||||
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
|
||||
|
||||
const ObjectList<SceneNode> &GetChildNode()const { return ChildNode; } ///<取得子节点列表
|
||||
|
||||
public:
|
||||
|
||||
SceneNode()=default;
|
||||
SceneNode(const SceneNode &)=delete;
|
||||
SceneNode(const SceneNode *)=delete;
|
||||
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
|
||||
SceneNode( Renderable *ri ) {render_obj=ri;}
|
||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||
|
||||
public:
|
||||
|
||||
virtual ~SceneNode()=default;
|
||||
|
||||
void Clear()
|
||||
void Clear() override
|
||||
{
|
||||
SubNode.Clear();
|
||||
SceneOrient::Clear();
|
||||
|
||||
Owner=nullptr;
|
||||
|
||||
BoundingBox.SetZero();
|
||||
LocalBoundingBox.SetZero();
|
||||
|
||||
ChildNode.Clear();
|
||||
render_obj=nullptr;
|
||||
}
|
||||
|
||||
Renderable *GetRenderable(){return render_obj;}
|
||||
void SetRenderable(Renderable *);
|
||||
|
||||
SceneNode *CreateSubNode()
|
||||
const bool IsEmpty()const
|
||||
{
|
||||
SceneNode *sn=new SceneNode();
|
||||
if(render_obj)return(false);
|
||||
if(ChildNode.GetCount())return(false);
|
||||
|
||||
SubNode.Add(sn);
|
||||
return sn;
|
||||
return(true);
|
||||
}
|
||||
|
||||
SceneNode *CreateSubNode(Renderable *ri)
|
||||
void SetOwner(SceneNode *sn) {Owner=sn;}
|
||||
SceneNode * GetOwner() noexcept{return Owner;}
|
||||
const SceneNode * GetOwner()const noexcept{return Owner;}
|
||||
|
||||
void SetRenderable(Renderable *);
|
||||
Renderable *GetRenderable() noexcept{return render_obj;}
|
||||
const Renderable *GetRenderable()const noexcept{return render_obj;}
|
||||
|
||||
SceneNode *Add(SceneNode *sn)
|
||||
{
|
||||
SceneNode *sn=new SceneNode(ri);
|
||||
if(!sn)
|
||||
return(nullptr);
|
||||
|
||||
SubNode.Add(sn);
|
||||
return sn;
|
||||
}
|
||||
|
||||
SceneNode *CreateSubNode(const Matrix4f &mat)
|
||||
{
|
||||
SceneNode *sn=new SceneNode(mat);
|
||||
|
||||
SubNode.Add(sn);
|
||||
return sn;
|
||||
}
|
||||
|
||||
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
|
||||
{
|
||||
SceneNode *sn=new SceneNode(mat,ri);
|
||||
|
||||
SubNode.Add(sn);
|
||||
ChildNode.Add(sn);
|
||||
sn->SetOwner(this);
|
||||
return sn;
|
||||
}
|
||||
|
||||
@@ -86,17 +100,15 @@ namespace hgl
|
||||
|
||||
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
|
||||
|
||||
virtual void RefreshMatrix (const Matrix4f *mat=nullptr); ///<刷新世界变换矩阵
|
||||
virtual void RefreshMatrix () override; ///<刷新世界变换
|
||||
virtual void RefreshBoundingBox (); ///<刷新绑定盒
|
||||
|
||||
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
|
||||
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
|
||||
virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
|
||||
virtual const Vector4f & GetCenter ()const{return Center;} ///<取得中心点
|
||||
virtual const Vector4f & GetLocalCenter ()const{return LocalCenter;} ///<取得本地坐标中心点
|
||||
virtual const Vector4f & GetWorldCenter ()const{return WorldCenter;} ///<取得世界坐标中心点
|
||||
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
};//class SceneNode
|
||||
|
||||
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||
|
88
inc/hgl/graph/SceneNodeAttributes.h
Normal file
88
inc/hgl/graph/SceneNodeAttributes.h
Normal file
@@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
#include<hgl/type/DataType.h>
|
||||
#include<hgl/graph/ShadowPolicy.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
#pragma pack(push,1)
|
||||
/**
|
||||
* 场景节点变换属性<br>
|
||||
*/
|
||||
struct SceneNodeTransformAttributes
|
||||
{
|
||||
uint moveable:1; ///<可移动
|
||||
uint rotatable:1; ///<可旋转
|
||||
uint scalable:1; ///<可缩放
|
||||
|
||||
//为什么要 移动、旋转、缩放 三个分开而不是一个整体
|
||||
|
||||
// 一、不可移动、不可旋转、不可缩放的通常用于Lightmap等可以完全预计算的东西
|
||||
// 二、物理引擎对于可缩放是独立支持的,所以缩放要分开
|
||||
// 三、逻辑处理对移动一般有特别响应,但旋转不一定(也有可能只处理旋转),所以移动和旋转要分开
|
||||
|
||||
// 比如RTS中的激光坦克、电磁坦克,由于是圆形范围攻击的,所以不需要关心旋转属性,只需要关心移动属性即可
|
||||
// 同理,地面雷达,因为是扇形旋转扫描敌人的,所以只关心旋转
|
||||
// 而士兵、坦克等单位,既需要移动,又需要旋转,但不会缩放
|
||||
// 再比如风车,它不能移动,但可以旋转。但我们判断是否靠近是否看到,根本不需要关心旋转属性
|
||||
};
|
||||
|
||||
/**
|
||||
* 场景节点可视属性<br>
|
||||
*/
|
||||
struct SceneNodeVisualAttributes
|
||||
{
|
||||
uint visible:1; ///<是否可见
|
||||
|
||||
uint render_color:1; ///<渲染颜色
|
||||
uint render_normal:1; ///<渲染法线
|
||||
uint render_depth:1; ///<渲染深度
|
||||
|
||||
uint render_at_reflect:1; ///<在反射时渲染
|
||||
|
||||
uint cast_shadow:1; ///<投射阴影
|
||||
uint cast_static_shadow:1; ///<投射静态阴影(预计算阴影)
|
||||
uint cast_dynamic_shadow:1; ///<投射动态阴影
|
||||
|
||||
uint receive_static_shadow:1; ///<接收静态阴影
|
||||
uint receive_dynamic_shadow:1; ///<接收动态阴影
|
||||
|
||||
uint receive_static_light:1; ///<接收静态光照
|
||||
uint receive_dynamic_light:1; ///<接收动态光照
|
||||
|
||||
ObjectDynamicShadowPolicy dynamic_shadow_policy:8; ///<动态阴影策略
|
||||
|
||||
// uint8 light_channels; ///<接收的光通道
|
||||
};
|
||||
|
||||
constexpr const size_t SceneNodeVisualAttributesBytes=sizeof(SceneNodeVisualAttributes);
|
||||
|
||||
/**
|
||||
* 场景节点裁剪属性<br>
|
||||
*/
|
||||
struct SceneNodeCullAttribute
|
||||
{
|
||||
uint32 min_distance; ///<最小裁剪距离
|
||||
uint32 max_distance; ///<最大裁剪距离
|
||||
|
||||
uint32 min_volume; ///<最小裁剪体积
|
||||
uint32 max_volume; ///<最大裁剪体积
|
||||
};
|
||||
|
||||
struct SceneNodeAttributes
|
||||
{
|
||||
uint editor_only:1; ///<仅编辑器中使用
|
||||
uint can_tick:1; ///<可被Tick
|
||||
|
||||
SceneNodeTransformAttributes transform; ///<变换属性
|
||||
SceneNodeVisualAttributes visual; ///<可视属性
|
||||
|
||||
SceneNodeCullAttribute cull; ///<裁剪属性
|
||||
};
|
||||
|
||||
constexpr const size_t SceneNodeAttributesBytes=sizeof(SceneNodeAttributes);
|
||||
|
||||
#pragma pack(pop)
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -1,47 +1,53 @@
|
||||
#ifndef HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
#define HGL_GRAPH_SCENE_ORIENT_INCLUDE
|
||||
|
||||
//#include<hgl/type/List.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
//#include<hgl/graph/Transform.h>
|
||||
#include<hgl/graph/SceneMatrix.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 方向定位数据基类
|
||||
* 方向定位数据基类<br>
|
||||
*/
|
||||
class SceneOrient ///场景定位类
|
||||
class SceneOrient ///场景定位类
|
||||
{
|
||||
protected:
|
||||
|
||||
//ObjectList<Transform> TransformList;
|
||||
|
||||
Matrix4f LocalMatrix; ///<当前矩阵
|
||||
Matrix4f LocalToWorldMatrix; ///<当前到世界矩阵
|
||||
|
||||
Matrix4f InverseLocalMatrix; ///<反向当前矩阵
|
||||
Matrix4f InverseLocalToWorldMatrix; ///<反向当前到世界矩阵
|
||||
SceneMatrix scene_matrix;
|
||||
|
||||
public:
|
||||
|
||||
SceneOrient();
|
||||
SceneOrient(const Matrix4f &mat);
|
||||
SceneOrient()=default;
|
||||
SceneOrient(const SceneOrient &);
|
||||
SceneOrient(const Matrix4f &);
|
||||
virtual ~SceneOrient()=default;
|
||||
|
||||
Matrix4f & SetLocalMatrix (const Matrix4f &); ///<设定当前节点矩阵
|
||||
Matrix4f & SetLocalToWorldMatrix (const Matrix4f &); ///<设定当前节点到世界矩阵
|
||||
virtual void Clear()
|
||||
{
|
||||
scene_matrix.Clear();
|
||||
}
|
||||
|
||||
const Matrix4f & GetLocalMatrix ()const {return LocalMatrix;}
|
||||
const Matrix4f & GetLocalToWorldMatrix ()const {return LocalToWorldMatrix;}
|
||||
|
||||
const Matrix4f & GetInverseLocalMatrix ()const {return InverseLocalMatrix;}
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix()const {return InverseLocalToWorldMatrix;}
|
||||
void SetLocalNormal(const Vector3f &nor) {scene_matrix.SetLocalNormal(nor);} ///<设置本地法线
|
||||
void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵
|
||||
void SetParentMatrix(const Matrix4f &mat){scene_matrix.SetParentMatrix(mat);} ///<设置上级到世界空间变换矩阵
|
||||
|
||||
public:
|
||||
|
||||
virtual void RefreshLocalToWorldMatrix (const Matrix4f *); ///<刷新到世界空间矩阵
|
||||
const uint32 GetLocalToWorldMatrixVersion()const {return scene_matrix.GetNewestVersion();} ///<取得版本号
|
||||
|
||||
const Vector3f & GetWorldPosition() const {return scene_matrix.GetWorldPosition();} ///<取得世界坐标
|
||||
const Matrix4f & GetLocalMatrix ()const {return scene_matrix.GetLocalMatrix();} ///<取得本地矩阵
|
||||
|
||||
TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器
|
||||
|
||||
const Matrix4f & GetLocalToWorldMatrix () {return scene_matrix.GetLocalToWorldMatrix();} ///<取得本地到世界矩阵
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix () {return scene_matrix.GetInverseLocalToWorldMatrix();}
|
||||
const Matrix4f & GetInverseTransposeLocalToWorldMatrix () {return scene_matrix.GetInverseTransposeLocalToWorldMatrix();}
|
||||
|
||||
public:
|
||||
|
||||
virtual void RefreshMatrix();
|
||||
};//class SceneOrient
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
43
inc/hgl/graph/ShadowPolicy.h
Normal file
43
inc/hgl/graph/ShadowPolicy.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 全局动态阴影策略
|
||||
*/
|
||||
enum class GlobalDynamicShadowPolicy
|
||||
{
|
||||
None, ///<不产生全局动态阴影
|
||||
|
||||
Cascade, ///<级联阴影
|
||||
ParallelSplit, ///<平行分割阴影
|
||||
Virtual, ///<虚拟阴影
|
||||
|
||||
ENUM_CLASS_RANGE(None,Virtual)
|
||||
};
|
||||
|
||||
/**
|
||||
* 对象动态阴影策略<br>
|
||||
* 注:动态阴影会使用屏幕空间技术,不管使用以下何种技术,会全部合成到一个屏幕空间shadow map,再统一做blur之类的操作
|
||||
*/
|
||||
enum class ObjectDynamicShadowPolicy
|
||||
{
|
||||
None, ///<不产生动态阴影
|
||||
|
||||
Global, ///<使用全局动态阴影
|
||||
|
||||
PerObject, ///<独立对象阴影(就是每个物件独立走普通shadowmap得到一张深度图,缓存到硬盘)
|
||||
|
||||
Plane, ///<压片阴影(极少三角面的片状物体专用)
|
||||
Capsule, ///<胶囊体阴影(一般用于骨骼动画模型阴影,每根骨骼一个胶囊)
|
||||
Cube, ///<立方体阴影(一般用于一些建筑物,比如楼房直接使用一个Cube做Raymarch)
|
||||
MeshSDF, ///<模型3D距离场阴影
|
||||
|
||||
ENUM_CLASS_RANGE(None,MeshSDF)
|
||||
};
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
46
inc/hgl/graph/StaticMesh.h
Normal file
46
inc/hgl/graph/StaticMesh.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/graph/StaticMeshLODPolicy.h>
|
||||
#include<hgl/graph/ShadowPolicy.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class SceneNode;
|
||||
|
||||
class StaticMesh
|
||||
{
|
||||
protected:
|
||||
|
||||
StaticMeshLODPolicy lod_policy; ///<LOD策略
|
||||
|
||||
SceneNode *root_node;
|
||||
|
||||
StaticMesh *shadow_proxy_static_mesh; ///<阴影代理静态网格
|
||||
StaticMesh *physic_proxy_static_mesh; ///<物理代理静态网格
|
||||
|
||||
protected:
|
||||
|
||||
bool two_side; ///<双面渲染
|
||||
|
||||
ObjectDynamicShadowPolicy recommend_dynamic_shadow_policy; ///<动态阴影策略(推荐项,最终可被取代)
|
||||
|
||||
public:
|
||||
|
||||
const StaticMeshLODPolicy GetLODPolicy()const { return lod_policy; } ///<取得LOD策略
|
||||
const ObjectDynamicShadowPolicy GetRecommendDynamicShadowPolicy()const { return recommend_dynamic_shadow_policy; } ///<取得推荐的动态阴影策略
|
||||
|
||||
public:
|
||||
|
||||
StaticMesh(SceneNode *);
|
||||
virtual ~StaticMesh();
|
||||
|
||||
public:
|
||||
|
||||
SceneNode *GetScene(){return root_node;}
|
||||
|
||||
SceneNode *GetShadowNode() { return shadow_proxy_static_mesh?shadow_proxy_static_mesh->GetScene():root_node; } ///<取得阴影渲染节点
|
||||
SceneNode *GetPhysicNode() { return physic_proxy_static_mesh?physic_proxy_static_mesh->GetScene():root_node; } ///<取得物理渲染节点
|
||||
|
||||
};//class StaticMesh
|
||||
VK_NAMESPACE_END
|
30
inc/hgl/graph/StaticMeshLODPolicy.h
Normal file
30
inc/hgl/graph/StaticMeshLODPolicy.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKNamespace.h>
|
||||
#include<hgl/TypeFunc.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 静态模型LOD策略
|
||||
*/
|
||||
enum class StaticMeshLODPolicy:uint8
|
||||
{
|
||||
None=0, ///<无LOD
|
||||
|
||||
DiscardDetail, ///<丢弃细节
|
||||
|
||||
AnotherMesh, ///<另一个模型
|
||||
|
||||
Billboard, ///<广告牌
|
||||
|
||||
//Voxel, ///<体素
|
||||
|
||||
//MeshSDF, ///<网格SDF
|
||||
|
||||
//MeshCard, ///<网格卡片
|
||||
|
||||
ENUM_CLASS_RANGE(None,Billboard)
|
||||
};//enum class StaticMeshLODPolicy
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -85,10 +85,16 @@ namespace hgl
|
||||
|
||||
protected:
|
||||
|
||||
virtual void *OnBegin(uint32)=0;
|
||||
virtual void OnEnd()=0;
|
||||
virtual void *OnBegin(uint32,const VkFormat &)=0;
|
||||
virtual bool OnEnd()=0;
|
||||
virtual void OnError(){}
|
||||
|
||||
public:
|
||||
|
||||
const TextureFileHeader & GetFileHeader ()const{return file_header;}
|
||||
const VkFormat & GetTextureFormat()const{return format;}
|
||||
const uint32 GetZeroMipmapBytes()const{return mipmap_zero_total_bytes;}
|
||||
|
||||
public:
|
||||
|
||||
TextureLoader()
|
||||
@@ -207,7 +213,7 @@ namespace hgl
|
||||
{
|
||||
protected: // override functions
|
||||
|
||||
uint32 GetPixelsCount()const override{return file_header.length;}
|
||||
uint32 GetPixelsCount()const override{return file_header.length*file_header.layers;}
|
||||
uint32 GetTotalBytes()const override
|
||||
{
|
||||
if(file_header.mipmaps<=1)
|
||||
@@ -230,7 +236,7 @@ namespace hgl
|
||||
{
|
||||
protected: // override functions
|
||||
|
||||
uint32 GetPixelsCount()const override{return file_header.width*file_header.height;}
|
||||
uint32 GetPixelsCount()const override{return file_header.width*file_header.height*file_header.layers;}
|
||||
uint32 GetTotalBytes()const override
|
||||
{
|
||||
if(file_header.mipmaps<=1)
|
||||
|
@@ -25,8 +25,8 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
|
||||
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
|
||||
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
|
||||
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
using BindingMapping=Map<uint32_t,int>;
|
||||
using BindingMap =Map<AnsiString,int>;
|
||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
class VulkanInstance;
|
||||
class GPUPhysicalDevice;
|
||||
@@ -37,7 +37,7 @@ class ImageView;
|
||||
class Framebuffer;
|
||||
struct Swapchain;
|
||||
class RenderTarget;
|
||||
class RTSwapchain;
|
||||
class SwapchainRenderTarget;
|
||||
|
||||
class Texture;
|
||||
class Texture1D;
|
||||
@@ -54,16 +54,16 @@ class DeviceMemory;
|
||||
class DeviceBuffer;
|
||||
struct DeviceBufferData;
|
||||
|
||||
struct PrimitiveDataBuffer;
|
||||
struct PrimitiveRenderData;
|
||||
|
||||
class VertexAttribBuffer;
|
||||
using VBO=VertexAttribBuffer;
|
||||
using VAB=VertexAttribBuffer;
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferData
|
||||
{
|
||||
IndexBuffer *buffer=nullptr;
|
||||
VkDeviceSize offset=0;
|
||||
};
|
||||
class VABMap;
|
||||
class IBMap;
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
@@ -78,7 +78,7 @@ class Semaphore;
|
||||
struct PipelineLayoutData;
|
||||
class DescriptorSet;
|
||||
|
||||
struct ShaderAttribute;
|
||||
struct VertexInputAttribute;
|
||||
|
||||
class ShaderResource;
|
||||
class ShaderModule;
|
||||
@@ -97,15 +97,26 @@ class VILConfig;
|
||||
class VertexInput;
|
||||
|
||||
struct VertexInputFormat;
|
||||
using VIF=VertexInputFormat;
|
||||
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
|
||||
class PrimitiveData;
|
||||
class Primitive;
|
||||
class Renderable;
|
||||
|
||||
class VertexDataManager;
|
||||
using VDM=VertexDataManager;
|
||||
|
||||
class IndirectDrawBuffer;
|
||||
class IndirectDrawIndexedBuffer;
|
||||
class IndirectDispatchBuffer;
|
||||
|
||||
class RenderResource;
|
||||
|
||||
class StaticMesh;
|
||||
|
||||
enum class SharingMode
|
||||
{
|
||||
Exclusive = 0,
|
||||
@@ -137,26 +148,25 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
|
||||
/**
|
||||
* 索引类型,等同于VkIndexType
|
||||
*/
|
||||
enum IndexType:uint
|
||||
enum IndexType:int
|
||||
{
|
||||
AUTO=-1,
|
||||
U16=0,
|
||||
U32,
|
||||
U8=VK_INDEX_TYPE_UINT8_EXT,
|
||||
|
||||
ERR=VK_INDEX_TYPE_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
* max-lengths:
|
||||
*
|
||||
256 bytes: nvidia,arm
|
||||
128 bytes: amd,intel,powervr,adreno
|
||||
*/
|
||||
struct PushConstant
|
||||
inline const bool IsIndexType(const IndexType it)
|
||||
{
|
||||
Matrix4f local_to_world;
|
||||
Matrix4f normal;
|
||||
};
|
||||
return it>=U16&&it<=U8;
|
||||
}
|
||||
|
||||
constexpr uint32_t MAX_PUSH_CONSTANT_BYTES=sizeof(PushConstant);
|
||||
//Push Constant max-lengths:
|
||||
//
|
||||
// 256 bytes: nvidia,arm
|
||||
// 128 bytes: amd,intel,powervr,adreno
|
||||
|
||||
inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
{
|
||||
|
@@ -23,6 +23,7 @@ private:
|
||||
friend class GPUDevice;
|
||||
friend class VertexAttribBuffer;
|
||||
friend class IndexBuffer;
|
||||
template<typename T> friend class IndirectCommandBuffer;
|
||||
|
||||
DeviceBuffer(VkDevice d,const DeviceBufferData &b)
|
||||
{
|
||||
@@ -36,16 +37,17 @@ public:
|
||||
|
||||
VkBuffer GetBuffer ()const{return buf.buffer;}
|
||||
DeviceMemory * GetMemory ()const{return buf.memory;}
|
||||
VkDeviceMemory GetVkMemory ()const{return buf.memory->operator VkDeviceMemory();}
|
||||
const VkDescriptorBufferInfo * GetBufferInfo ()const{return &buf.info;}
|
||||
|
||||
void * Map () {return buf.memory->Map();}
|
||||
virtual void * Map (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Map(start,size);}
|
||||
void Unmap () {return buf.memory->Unmap();}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);}
|
||||
void Flush (VkDeviceSize size) {return buf.memory->Flush(size);}
|
||||
virtual void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);}
|
||||
virtual void Flush (VkDeviceSize size) {return buf.memory->Flush(size);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
virtual bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
virtual bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
||||
};//class DeviceBuffer
|
||||
VK_NAMESPACE_END
|
||||
|
100
inc/hgl/graph/VKBufferMap.h
Normal file
100
inc/hgl/graph/VKBufferMap.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
template<typename T> class VKBufferMap
|
||||
{
|
||||
protected:
|
||||
|
||||
T *buffer;
|
||||
int32_t offset;
|
||||
uint32_t stride;
|
||||
uint32_t count;
|
||||
|
||||
void *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VKBufferMap()
|
||||
{
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
}
|
||||
|
||||
virtual ~VKBufferMap()
|
||||
{
|
||||
Unmap();
|
||||
}
|
||||
|
||||
void Set(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
|
||||
{
|
||||
buffer=buf;
|
||||
offset=off;
|
||||
stride=s;
|
||||
count=c;
|
||||
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
const int32_t GetOffset ()const{ return offset;}
|
||||
const uint32_t GetStride ()const{ return stride;}
|
||||
const uint32_t GetCount ()const{ return count; }
|
||||
|
||||
const bool IsValid()const{ return buffer; }
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Unmap();
|
||||
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
}
|
||||
|
||||
void *Map()
|
||||
{
|
||||
if(map_ptr)
|
||||
return(map_ptr);
|
||||
|
||||
if(!buffer)
|
||||
return(nullptr);
|
||||
|
||||
map_ptr=buffer->Map(offset,count);
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(buffer&&map_ptr)
|
||||
{
|
||||
buffer->Unmap();
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Write(const void *data,const uint32_t c)
|
||||
{
|
||||
if(!data||c==0||c>count)return(false);
|
||||
|
||||
if(!map_ptr)
|
||||
{
|
||||
if(!buffer)
|
||||
return(false);
|
||||
|
||||
/*
|
||||
* 注:这里的不管是offset还是c,都会走VAB/IndexBuffer的虚拟版本。
|
||||
* 其中的数据均为单元数据长度而非字节数。
|
||||
*
|
||||
* 如果需要传字节数,就需要buffer->DeviceBuffer::Write()这样操作
|
||||
*/
|
||||
return buffer->Write(data,offset,c);
|
||||
}
|
||||
|
||||
memcpy(map_ptr,data,stride*c);
|
||||
return(true);
|
||||
}
|
||||
};//class VKBufferMap
|
||||
VK_NAMESPACE_END
|
@@ -2,7 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKVBOList.h>
|
||||
#include<hgl/graph/VKVABList.h>
|
||||
#include<hgl/graph/VKPipeline.h>
|
||||
#include<hgl/graph/VKDescriptorSet.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
@@ -28,11 +28,11 @@ public:
|
||||
bool End(){return(vkEndCommandBuffer(cmd_buf)==VK_SUCCESS);}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void SetDebugName(const UTF8String &);
|
||||
void BeginRegion(const UTF8String &,const Color4f &);
|
||||
void SetDebugName(const AnsiString &);
|
||||
void BeginRegion(const AnsiString &,const Color4f &);
|
||||
void EndRegion();
|
||||
#else
|
||||
void BeginRegion(const UTF8String &,const Color4f &){}
|
||||
void BeginRegion(const AnsiString &,const Color4f &){}
|
||||
void EndRegion(){}
|
||||
#endif//_DEBUG
|
||||
};//class GPUCmdBuffer
|
||||
@@ -43,14 +43,13 @@ class RenderCmdBuffer:public GPUCmdBuffer
|
||||
VkClearValue *clear_values;
|
||||
VkRect2D render_area;
|
||||
VkViewport viewport;
|
||||
|
||||
float default_line_width;
|
||||
|
||||
Framebuffer *fbo;
|
||||
|
||||
RenderPassBeginInfo rp_begin;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
void SetFBO(Framebuffer *);
|
||||
private:
|
||||
|
||||
void SetClear();
|
||||
|
||||
public:
|
||||
|
||||
@@ -80,7 +79,7 @@ public:
|
||||
|
||||
//以上设定在Begin开始后即不可改变
|
||||
|
||||
bool BindFramebuffer(RenderPass *rp,Framebuffer *fb);
|
||||
bool BindFramebuffer(Framebuffer *);
|
||||
|
||||
bool BeginRenderPass();
|
||||
void NextSubpass(){vkCmdNextSubpass(cmd_buf,VK_SUBPASS_CONTENTS_INLINE);}
|
||||
@@ -156,31 +155,33 @@ public:
|
||||
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
|
||||
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
|
||||
|
||||
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets)
|
||||
void BindVAB(const uint32_t first,const uint32_t count,const VkBuffer *vab,const VkDeviceSize *offsets)
|
||||
{
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vab,offsets);
|
||||
}
|
||||
|
||||
bool BindVBO(VBOList *vbo_list)
|
||||
bool BindVAB(VABList *vab_list)
|
||||
{
|
||||
if(!vbo_list)return(false);
|
||||
if(!vab_list)return(false);
|
||||
|
||||
if(!vbo_list->IsFull())return(false);
|
||||
if(!vab_list->IsFull())return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vbo_list->binding_count,vbo_list->buffer_list,vbo_list->buffer_offset);
|
||||
vkCmdBindVertexBuffers(cmd_buf,
|
||||
0, //first binding
|
||||
vab_list->vab_count, //binding count
|
||||
vab_list->vab_list, //buffers
|
||||
vab_list->vab_offset); //buffer offsets
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BindIBO(const IndexBufferData *);
|
||||
void BindIBO(IndexBuffer *,const VkDeviceSize byte_offset=0);
|
||||
|
||||
bool BindVBO(Renderable *);
|
||||
bool BindDataBuffer(const PrimitiveDataBuffer *);
|
||||
|
||||
void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);}
|
||||
void SetScissor (uint32_t first,uint32_t count,const VkRect2D *sci) {vkCmdSetScissor(cmd_buf,first,count,sci);}
|
||||
|
||||
void SetLineWidth (float line_width) {vkCmdSetLineWidth(cmd_buf,line_width);}
|
||||
|
||||
void SetDepthBias (float constant_factor,float clamp,float slope_factor) {vkCmdSetDepthBias(cmd_buf,constant_factor,clamp,slope_factor);}
|
||||
void SetDepthBounds (float min_db,float max_db) {vkCmdSetDepthBounds(cmd_buf,min_db,max_db);}
|
||||
void SetBlendConstants (const float constants[4]) {vkCmdSetBlendConstants(cmd_buf,constants);}
|
||||
@@ -195,15 +196,26 @@ public: //draw
|
||||
void DrawIndexed (const uint32_t index_count ) {vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);}
|
||||
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
|
||||
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
|
||||
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count,const uint32_t firstIndex,const int32_t vertexOffset,const uint32_t firstInstance)
|
||||
{
|
||||
vkCmdDrawIndexed(cmd_buf,
|
||||
index_count,
|
||||
instance_count,
|
||||
firstIndex,
|
||||
vertexOffset,
|
||||
firstInstance);
|
||||
}
|
||||
|
||||
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
// template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
// template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
|
||||
void DrawIndirect (VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand ));
|
||||
void DrawIndexedIndirect(VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand ));
|
||||
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
||||
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
||||
|
||||
void Draw (const PrimitiveDataBuffer *prb,const PrimitiveRenderData *prd,const uint32_t instance_count=1,const uint32_t first_instance=0);
|
||||
|
||||
public: //dynamic state
|
||||
};//class RenderCmdBuffer:public GPUCmdBuffer
|
||||
|
||||
|
@@ -1,86 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DebugMakerFunction
|
||||
{
|
||||
PFN_vkDebugMarkerSetObjectTagEXT SetObjectTag;
|
||||
PFN_vkDebugMarkerSetObjectNameEXT SetObjectName;
|
||||
PFN_vkCmdDebugMarkerBeginEXT Begin;
|
||||
PFN_vkCmdDebugMarkerEndEXT End;
|
||||
PFN_vkCmdDebugMarkerInsertEXT Insert;
|
||||
};//struct DebugMakerFunction
|
||||
|
||||
class DebugMaker
|
||||
{
|
||||
VkDevice device;
|
||||
|
||||
DebugMakerFunction dmf;
|
||||
|
||||
protected:
|
||||
|
||||
void SetObjectName(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char *name);
|
||||
void SetObjectTag(uint64_t object, VkDebugReportObjectTypeEXT objectType, uint64_t name, size_t tagSize, const void* tag);
|
||||
|
||||
private:
|
||||
|
||||
friend DebugMaker *CreateDebugMaker(VkDevice device);
|
||||
|
||||
DebugMaker(VkDevice dev,const DebugMakerFunction &f)
|
||||
{
|
||||
device=dev;
|
||||
dmf=f;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void Begin(VkCommandBuffer cmdbuffer, const char * pMarkerName, const Color4f &color);
|
||||
void Insert(VkCommandBuffer cmdbuffer, const char *markerName, const Color4f &color);
|
||||
void End(VkCommandBuffer cmdBuffer);
|
||||
|
||||
#define DEBUG_MAKER_SET_FUNC(type,MNAME) void Set##type(Vk##type obj,const char *name){SetObjectName((uint64_t)obj,VK_DEBUG_REPORT_OBJECT_TYPE_##MNAME##_EXT,name);}
|
||||
|
||||
DEBUG_MAKER_SET_FUNC(Instance, INSTANCE)
|
||||
DEBUG_MAKER_SET_FUNC(PhysicalDevice, PHYSICAL_DEVICE)
|
||||
DEBUG_MAKER_SET_FUNC(Device, DEVICE)
|
||||
DEBUG_MAKER_SET_FUNC(Queue, QUEUE)
|
||||
DEBUG_MAKER_SET_FUNC(Semaphore, SEMAPHORE)
|
||||
DEBUG_MAKER_SET_FUNC(CommandBuffer, COMMAND_BUFFER)
|
||||
DEBUG_MAKER_SET_FUNC(Fence, FENCE)
|
||||
DEBUG_MAKER_SET_FUNC(DeviceMemory, DEVICE_MEMORY)
|
||||
DEBUG_MAKER_SET_FUNC(Buffer, BUFFER)
|
||||
DEBUG_MAKER_SET_FUNC(Image, IMAGE)
|
||||
DEBUG_MAKER_SET_FUNC(Event, EVENT)
|
||||
DEBUG_MAKER_SET_FUNC(QueryPool, QUERY_POOL)
|
||||
DEBUG_MAKER_SET_FUNC(BufferView, BUFFER_VIEW)
|
||||
DEBUG_MAKER_SET_FUNC(ShaderModule, SHADER_MODULE)
|
||||
DEBUG_MAKER_SET_FUNC(PipelineCache, PIPELINE_CACHE)
|
||||
DEBUG_MAKER_SET_FUNC(PipelineLayout, PIPELINE_LAYOUT)
|
||||
DEBUG_MAKER_SET_FUNC(RenderPass, RENDER_PASS)
|
||||
DEBUG_MAKER_SET_FUNC(Pipeline, PIPELINE)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorSetLayout, DESCRIPTOR_SET_LAYOUT)
|
||||
DEBUG_MAKER_SET_FUNC(Sampler, SAMPLER)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorPool, DESCRIPTOR_POOL)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorSet, DESCRIPTOR_SET)
|
||||
DEBUG_MAKER_SET_FUNC(Framebuffer, FRAMEBUFFER)
|
||||
DEBUG_MAKER_SET_FUNC(CommandPool, COMMAND_POOL)
|
||||
DEBUG_MAKER_SET_FUNC(SurfaceKHR, SURFACE_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(SwapchainKHR, SWAPCHAIN_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(DebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT)
|
||||
DEBUG_MAKER_SET_FUNC(DisplayKHR, DISPLAY_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(DisplayModeKHR, DISPLAY_MODE_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(ValidationCacheEXT, VALIDATION_CACHE_EXT)
|
||||
DEBUG_MAKER_SET_FUNC(SamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION)
|
||||
DEBUG_MAKER_SET_FUNC(DescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE)
|
||||
DEBUG_MAKER_SET_FUNC(CuModuleNVX, CU_MODULE_NVX)
|
||||
DEBUG_MAKER_SET_FUNC(CuFunctionNVX, CU_FUNCTION_NVX)
|
||||
DEBUG_MAKER_SET_FUNC(AccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR)
|
||||
DEBUG_MAKER_SET_FUNC(AccelerationStructureNV, ACCELERATION_STRUCTURE_NV)
|
||||
|
||||
#undef DEBUG_MAKER_SET_FUNC
|
||||
};//class DebugMaker
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_DEBUG_MAKER_INCLUDE
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DebugUtilsFunction
|
||||
@@ -92,6 +93,13 @@ public:
|
||||
// DU_FUNC(BufferCollectionFuchsia, BUFFER_COLLECTION_FUCHSIA)
|
||||
|
||||
#undef DU_FUNC
|
||||
|
||||
void SetTexture(Texture *tex,const AnsiString &info)
|
||||
{
|
||||
SetImage( tex->GetImage(), info+"_Image" );
|
||||
SetImageView( tex->GetVulkanImageView(), info+"_ImageView" );
|
||||
SetDeviceMemory(tex->GetDeviceMemory(), info+"_Memory" );
|
||||
}
|
||||
|
||||
void QueueBegin (VkQueue,const char *,const Color4f &color=Color4f(1,1,1,1));
|
||||
void QueueEnd (VkQueue q){duf.QueueEnd(q);}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#ifndef HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_DESCRIPTOR_BINDING_MANAGE_INCLUDE
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
namespace hgl
|
||||
{
|
||||
@@ -11,10 +12,15 @@ namespace hgl
|
||||
class DeviceBuffer;
|
||||
class Texture;
|
||||
class Material;
|
||||
class MaterialParameters;
|
||||
|
||||
/**
|
||||
* 描述符绑定器<Br>
|
||||
* 一般用于注册通用数据,为材质进行自动绑定。
|
||||
*/
|
||||
class DescriptorBinding
|
||||
{
|
||||
DescriptorSetType set_type;
|
||||
DescriptorSetType set_type; ///<描述符合集类型
|
||||
|
||||
Map<AnsiString,DeviceBuffer *> ubo_map;
|
||||
Map<AnsiString,DeviceBuffer *> ssbo_map;
|
||||
@@ -39,7 +45,7 @@ namespace hgl
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ubo_map,name);
|
||||
return GetObjectFromList(ubo_map,name);
|
||||
}
|
||||
|
||||
void RemoveUBO(DeviceBuffer *buf)
|
||||
@@ -61,7 +67,7 @@ namespace hgl
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(ssbo_map,name);
|
||||
return GetObjectFromList(ssbo_map,name);
|
||||
}
|
||||
|
||||
void RemoveSSBO(DeviceBuffer *buf)
|
||||
@@ -83,7 +89,7 @@ namespace hgl
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
return GetListObject(texture_map,name);
|
||||
return GetObjectFromList(texture_map,name);
|
||||
}
|
||||
|
||||
void RemoveTexture(Texture *tex)
|
||||
@@ -93,6 +99,12 @@ namespace hgl
|
||||
texture_map.DeleteByValue(tex);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void BindUBO(MaterialParameters *,const BindingMap &,bool dynamic);
|
||||
|
||||
public:
|
||||
|
||||
bool Bind(Material *);
|
||||
};//class DescriptorBinding
|
||||
}//namespace graph
|
||||
|
@@ -4,23 +4,23 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/ObjectList.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class DeviceBuffer;
|
||||
|
||||
class DescriptorSet
|
||||
{
|
||||
VkDevice device;
|
||||
int binding_count;
|
||||
int vab_count;
|
||||
VkDescriptorSet desc_set;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
|
||||
ObjectList<VkDescriptorBufferInfo> buffer_list;
|
||||
ObjectList<VkDescriptorBufferInfo> vab_list;
|
||||
ObjectList<VkDescriptorImageInfo> image_list;
|
||||
List<VkWriteDescriptorSet> wds_list;
|
||||
|
||||
SortedSets<uint32_t> binded_sets;
|
||||
SortedSet<uint32_t> binded_sets;
|
||||
|
||||
bool is_dirty;
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
DescriptorSet(VkDevice dev,const int bc,VkPipelineLayout pl,VkDescriptorSet ds)
|
||||
{
|
||||
device =dev;
|
||||
binding_count =bc;
|
||||
vab_count =bc;
|
||||
desc_set =ds;
|
||||
pipeline_layout =pl;
|
||||
|
||||
@@ -38,11 +38,11 @@ public:
|
||||
|
||||
~DescriptorSet()=default;
|
||||
|
||||
const uint32_t GetCount ()const{return binding_count;}
|
||||
const uint32_t GetCount ()const{return vab_count;}
|
||||
const VkDescriptorSet GetDescriptorSet ()const{return desc_set;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const{return pipeline_layout;}
|
||||
|
||||
const bool IsReady ()const{return wds_list.GetCount()==binding_count;}
|
||||
const bool IsReady ()const{return wds_list.GetCount()==vab_count;}
|
||||
|
||||
void Clear();
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
@@ -23,6 +22,11 @@ class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
class GPUArrayBuffer;
|
||||
class IndirectDrawBuffer;
|
||||
class IndirectDrawIndexedBuffer;
|
||||
class IndirectDispatchBuffer;
|
||||
|
||||
struct CopyBufferToImageInfo;
|
||||
|
||||
class GPUDevice
|
||||
{
|
||||
@@ -34,18 +38,17 @@ class GPUDevice
|
||||
private:
|
||||
|
||||
DeviceRenderPassManage *render_pass_manage;
|
||||
RenderPass *device_render_pass;
|
||||
|
||||
RTSwapchain *sc_rt;
|
||||
SwapchainRenderTarget *sc_rt;
|
||||
|
||||
RTSwapchain *CreateSwapchainRenderTarget();
|
||||
SwapchainRenderTarget *CreateSwapchainRenderTarget();
|
||||
|
||||
void InitRenderPassManage();
|
||||
void ClearRenderPassManage();
|
||||
|
||||
private:
|
||||
|
||||
VkCommandBuffer CreateCommandBuffer();
|
||||
VkCommandBuffer CreateCommandBuffer(const AnsiString &);
|
||||
|
||||
bool CreateSwapchainFBO(Swapchain *);
|
||||
|
||||
@@ -75,14 +78,16 @@ public:
|
||||
const VkColorSpaceKHR GetColorSpace ()const {return attr->surface_format.colorSpace;}
|
||||
VkQueue GetGraphicsQueue () {return attr->graphics_queue;}
|
||||
|
||||
RenderPass * GetRenderPass () {return device_render_pass;}
|
||||
RenderPass * GetRenderPass () {return sc_rt->GetRenderPass();}
|
||||
|
||||
RTSwapchain * GetSwapchainRT () {return sc_rt;}
|
||||
SwapchainRenderTarget * GetSwapchainRT () {return sc_rt;}
|
||||
|
||||
const VkExtent2D & GetSwapchainSize ()const {return sc_rt->GetExtent();}
|
||||
|
||||
void WaitIdle ()const {vkDeviceWaitIdle(attr->device);}
|
||||
|
||||
DebugUtils * GetDebugUtils (){return attr->debug_utils;}
|
||||
|
||||
public:
|
||||
|
||||
bool Resize (const VkExtent2D &);
|
||||
@@ -111,9 +116,11 @@ public: //Buffer相关
|
||||
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
|
||||
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
|
||||
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VAB * CreateVAB (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VAB * CreateVAB (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVAB(format,count,nullptr,sm);}
|
||||
|
||||
const IndexType ChooseIndexType (const VkDeviceSize &vertex_count)const; ///<求一个合适的索引类型
|
||||
const bool CheckIndexType (const IndexType,const VkDeviceSize &vertex_count)const; ///<检测一个索引类型是否合适
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
||||
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}
|
||||
@@ -144,6 +151,14 @@ public: //Buffer相关
|
||||
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||
|
||||
public: //间接绘制
|
||||
|
||||
bool CreateIndirectCommandBuffer(DeviceBufferData *,const uint32_t cmd_count,const uint32_t cmd_size,SharingMode sm=SharingMode::Exclusive);
|
||||
|
||||
IndirectDrawBuffer * CreateIndirectDrawBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
IndirectDrawIndexedBuffer * CreateIndirectDrawIndexedBuffer(const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
IndirectDispatchBuffer * CreateIndirectDispatchBuffer( const uint32_t cmd_count,SharingMode sm=SharingMode::Exclusive);
|
||||
|
||||
public: //Image
|
||||
|
||||
VkImage CreateImage (VkImageCreateInfo *);
|
||||
@@ -151,7 +166,15 @@ public: //Image
|
||||
|
||||
private: //texture
|
||||
|
||||
bool CommitTexture (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool CopyBufferToImage (const CopyBufferToImageInfo *info,VkPipelineStageFlags destinationStage);
|
||||
|
||||
bool CopyBufferToImage (Texture *,DeviceBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,1,dstStage);}
|
||||
bool CopyBufferToImage2D (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,1,dstStage);}
|
||||
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic_list,const int bic_count, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic_list, bic_count, 0,6,dstStage);}
|
||||
bool CopyBufferToImageCube (Texture *tex,DeviceBuffer *buf,const VkBufferImageCopy *bic, VkPipelineStageFlags dstStage){return CopyBufferToImage(tex,buf,bic, 1, 0,6,dstStage);}
|
||||
|
||||
bool CommitTexture2D (Texture2D *,DeviceBuffer *buf,VkPipelineStageFlags stage);
|
||||
bool CommitTexture2DMipmaps (Texture2D *,DeviceBuffer *buf,const VkExtent3D &,uint32_t);
|
||||
@@ -170,6 +193,10 @@ public: //Texture
|
||||
Texture2D *CreateTexture2D(TextureData *);
|
||||
Texture2D *CreateTexture2D(TextureCreateInfo *ci);
|
||||
|
||||
Texture2DArray *CreateTexture2DArray(TextureData *);
|
||||
Texture2DArray *CreateTexture2DArray(TextureCreateInfo *ci);
|
||||
Texture2DArray *CreateTexture2DArray(const uint32_t w,const uint32_t h,const uint32 l,const VkFormat fmt,const bool mipmaps);
|
||||
|
||||
TextureCube *CreateTextureCube(TextureData *);
|
||||
TextureCube *CreateTextureCube(TextureCreateInfo *ci);
|
||||
|
||||
@@ -179,6 +206,10 @@ public: //Texture
|
||||
bool ChangeTexture2D(Texture2D *,DeviceBuffer *buf, const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2D(Texture2D *,void *data,const uint32_t size,const RectScope2ui &, VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
// bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const List<Image2DRegion> &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,DeviceBuffer *buf, const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
bool ChangeTexture2DArray(Texture2DArray *,void *data,const uint32_t size,const RectScope2ui &, const uint32_t base_layer,const uint32_t layer_count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
public: //
|
||||
|
||||
Sampler *CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
@@ -194,8 +225,8 @@ public: //shader & material
|
||||
|
||||
public: //Command Buffer 相关
|
||||
|
||||
RenderCmdBuffer * CreateRenderCommandBuffer();
|
||||
TextureCmdBuffer *CreateTextureCommandBuffer();
|
||||
RenderCmdBuffer * CreateRenderCommandBuffer(const AnsiString &);
|
||||
TextureCmdBuffer *CreateTextureCommandBuffer(const AnsiString &);
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include<hgl/graph/VKDebugMaker.h>
|
||||
#include<hgl/graph/VKDebugUtils.h>
|
||||
#endif//_DEBUG
|
||||
|
||||
@@ -40,6 +39,9 @@ struct GPUDeviceAttribute
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
bool uint8_index_type=false;
|
||||
bool uint32_index_type=false;
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkCommandPool cmd_pool =VK_NULL_HANDLE;
|
||||
|
||||
@@ -48,7 +50,6 @@ struct GPUDeviceAttribute
|
||||
VkPipelineCache pipeline_cache =VK_NULL_HANDLE;
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugMaker * debug_maker =nullptr;
|
||||
DebugUtils * debug_utils =nullptr;
|
||||
#endif//_DEBUG
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user