Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Commits
3c7a8784
Verified
Commit
3c7a8784
authored
3 years ago
by
Josch Morgenstern
Browse files
Options
Downloads
Patches
Plain Diff
[
#111
] add params as push constant, add keybindings
parent
40f5932d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!95
Resolve "Wassersimulation mit Interaktion"
Pipeline
#27408
passed
3 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/sph/src/main.cpp
+77
-14
77 additions, 14 deletions
projects/sph/src/main.cpp
with
77 additions
and
14 deletions
projects/sph/src/main.cpp
+
77
−
14
View file @
3c7a8784
...
@@ -4,7 +4,9 @@
...
@@ -4,7 +4,9 @@
#include
<vkcv/camera/CameraManager.hpp>
#include
<vkcv/camera/CameraManager.hpp>
#include
<chrono>
#include
<chrono>
#include
<random>
#include
<random>
#include
<glm/glm.hpp>
#include
<glm/gtc/matrix_access.hpp>
#include
<glm/gtc/matrix_access.hpp>
#include
<glm/gtc/matrix_transform.hpp>
#include
<time.h>
#include
<time.h>
#include
<vkcv/shader/GLSLCompiler.hpp>
#include
<vkcv/shader/GLSLCompiler.hpp>
#include
"BloomAndFlares.hpp"
#include
"BloomAndFlares.hpp"
...
@@ -21,7 +23,7 @@ int main(int argc, const char **argv) {
...
@@ -21,7 +23,7 @@ int main(int argc, const char **argv) {
{
VK_KHR_SWAPCHAIN_EXTENSION_NAME
}
{
VK_KHR_SWAPCHAIN_EXTENSION_NAME
}
);
);
vkcv
::
WindowHandle
windowHandle
=
core
.
createWindow
(
applicationName
,
800
,
60
0
,
true
);
vkcv
::
WindowHandle
windowHandle
=
core
.
createWindow
(
applicationName
,
1920
,
108
0
,
true
);
vkcv
::
Window
&
window
=
core
.
getWindow
(
windowHandle
);
vkcv
::
Window
&
window
=
core
.
getWindow
(
windowHandle
);
vkcv
::
camera
::
CameraManager
cameraManager
(
window
);
vkcv
::
camera
::
CameraManager
cameraManager
(
window
);
...
@@ -45,6 +47,20 @@ int main(int argc, const char **argv) {
...
@@ -45,6 +47,20 @@ int main(int argc, const char **argv) {
vkcv
::
PassConfig
computePassDefinition
({});
vkcv
::
PassConfig
computePassDefinition
({});
vkcv
::
PassHandle
computePass
=
core
.
createPass
(
computePassDefinition
);
vkcv
::
PassHandle
computePass
=
core
.
createPass
(
computePassDefinition
);
//rotation
float
rotationx
=
0
;
float
rotationy
=
0
;
// params
float
param_h
=
0.20
;
float
param_mass
=
0.03
;
float
param_gasConstant
=
3500
;
float
param_offset
=
200
;
float
param_gravity
=
-
5000
;
float
param_viscosity
=
10
;
float
param_ABSORBTION
=
0.5
;
float
param_dt
=
0.0005
;
if
(
!
particlePass
||
!
computePass
)
if
(
!
particlePass
||
!
computePass
)
{
{
std
::
cout
<<
"Error. Could not create renderpass. Exiting."
<<
std
::
endl
;
std
::
cout
<<
"Error. Could not create renderpass. Exiting."
<<
std
::
endl
;
...
@@ -128,13 +144,13 @@ int main(int argc, const char **argv) {
...
@@ -128,13 +144,13 @@ int main(int argc, const char **argv) {
1
1
);
);
int
numberParticles
=
5
0000
;
int
numberParticles
=
2
0000
;
std
::
vector
<
Particle
>
particles
;
std
::
vector
<
Particle
>
particles
;
for
(
int
i
=
0
;
i
<
numberParticles
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numberParticles
;
i
++
)
{
const
float
lo
=
-
0.
2
;
const
float
lo
=
0.
6
;
const
float
hi
=
0.
2
;
const
float
hi
=
0.
9
;
const
float
vlo
=
0
;
const
float
vlo
=
0
;
const
float
vhi
=
10
0
;
const
float
vhi
=
7
0
;
float
x
=
lo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
hi
-
lo
)));
float
x
=
lo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
hi
-
lo
)));
float
y
=
lo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
hi
-
lo
)));
float
y
=
lo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
hi
-
lo
)));
float
z
=
lo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
hi
-
lo
)));
float
z
=
lo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
hi
-
lo
)));
...
@@ -142,8 +158,8 @@ int main(int argc, const char **argv) {
...
@@ -142,8 +158,8 @@ int main(int argc, const char **argv) {
float
vy
=
vlo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
vhi
-
vlo
)));
float
vy
=
vlo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
vhi
-
vlo
)));
float
vz
=
vlo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
vhi
-
vlo
)));
float
vz
=
vlo
+
static_cast
<
float
>
(
rand
())
/
(
static_cast
<
float
>
(
RAND_MAX
/
(
vhi
-
vlo
)));
glm
::
vec3
pos
=
glm
::
vec3
(
x
,
y
,
z
);
glm
::
vec3
pos
=
glm
::
vec3
(
x
,
y
,
z
);
//
glm::vec3 vel = glm::vec3(vx,vy,vz);
glm
::
vec3
vel
=
glm
::
vec3
(
vx
,
vy
,
vz
);
glm
::
vec3
vel
=
glm
::
vec3
(
0.0
,
0.0
,
0.0
);
//
glm::vec3 vel = glm::vec3(0.0,0.0,0.0);
particles
.
push_back
(
Particle
(
pos
,
vel
));
particles
.
push_back
(
Particle
(
pos
,
vel
));
}
}
...
@@ -192,7 +208,6 @@ int main(int argc, const char **argv) {
...
@@ -192,7 +208,6 @@ int main(int argc, const char **argv) {
auto
pos
=
glm
::
vec2
(
0.
f
);
auto
pos
=
glm
::
vec2
(
0.
f
);
auto
spawnPosition
=
glm
::
vec3
(
0.
f
);
auto
spawnPosition
=
glm
::
vec3
(
0.
f
);
std
::
vector
<
glm
::
mat4
>
modelMatrices
;
std
::
vector
<
vkcv
::
DrawcallInfo
>
drawcalls
;
std
::
vector
<
vkcv
::
DrawcallInfo
>
drawcalls
;
drawcalls
.
push_back
(
vkcv
::
DrawcallInfo
(
renderMesh
,
{
descriptorUsage
},
numberParticles
));
drawcalls
.
push_back
(
vkcv
::
DrawcallInfo
(
renderMesh
,
{
descriptorUsage
},
numberParticles
));
...
@@ -207,8 +222,8 @@ int main(int argc, const char **argv) {
...
@@ -207,8 +222,8 @@ int main(int argc, const char **argv) {
cameraManager
.
setActiveCamera
(
1
);
cameraManager
.
setActiveCamera
(
1
);
cameraManager
.
getCamera
(
camIndex0
).
setPosition
(
glm
::
vec3
(
0
,
0
,
-
2
));
cameraManager
.
getCamera
(
camIndex0
).
setPosition
(
glm
::
vec3
(
0
,
0
,
-
2
.5
));
cameraManager
.
getCamera
(
camIndex1
).
setPosition
(
glm
::
vec3
(
0.0
f
,
0.0
f
,
-
2.
0
f
));
cameraManager
.
getCamera
(
camIndex1
).
setPosition
(
glm
::
vec3
(
0.0
f
,
0.0
f
,
-
2.
5
f
));
cameraManager
.
getCamera
(
camIndex1
).
setCenter
(
glm
::
vec3
(
0.0
f
,
0.0
f
,
0.0
f
));
cameraManager
.
getCamera
(
camIndex1
).
setCenter
(
glm
::
vec3
(
0.0
f
,
0.0
f
,
0.0
f
));
auto
swapchainExtent
=
core
.
getSwapchain
(
window
.
getSwapchainHandle
()).
getExtent
();
auto
swapchainExtent
=
core
.
getSwapchain
(
window
.
getSwapchainHandle
()).
getExtent
();
...
@@ -259,16 +274,64 @@ int main(int argc, const char **argv) {
...
@@ -259,16 +274,64 @@ int main(int argc, const char **argv) {
glm
::
mat4
view
;
glm
::
mat4
view
;
glm
::
mat4
projection
;
glm
::
mat4
projection
;
}
renderingMatrices
;
}
renderingMatrices
;
glm
::
vec3
gravityDir
=
glm
::
rotate
(
glm
::
mat4
(
1.0
),
glm
::
radians
(
rotationx
),
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
))
*
glm
::
vec4
(
0.
f
,
1.
f
,
0.
f
,
0.
f
);
gravityDir
=
glm
::
rotate
(
glm
::
mat4
(
1.0
),
glm
::
radians
(
rotationy
),
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
))
*
glm
::
vec4
(
gravityDir
,
0.
f
);
renderingMatrices
.
view
=
cameraManager
.
getActiveCamera
().
getView
();
renderingMatrices
.
view
=
cameraManager
.
getActiveCamera
().
getView
();
renderingMatrices
.
view
=
glm
::
rotate
(
renderingMatrices
.
view
,
glm
::
radians
(
rotationx
),
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
renderingMatrices
.
view
=
glm
::
rotate
(
renderingMatrices
.
view
,
glm
::
radians
(
rotationy
),
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
));
renderingMatrices
.
projection
=
cameraManager
.
getActiveCamera
().
getProjection
();
renderingMatrices
.
projection
=
cameraManager
.
getActiveCamera
().
getProjection
();
// keybindings rotation
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_LEFT
)
==
GLFW_PRESS
)
rotationx
+=
deltatime
*
50
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_RIGHT
)
==
GLFW_PRESS
)
rotationx
-=
deltatime
*
50
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_UP
)
==
GLFW_PRESS
)
rotationy
+=
deltatime
*
50
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_DOWN
)
==
GLFW_PRESS
)
rotationy
-=
deltatime
*
50
;
// keybindings params
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_T
)
==
GLFW_PRESS
)
param_h
+=
deltatime
*
0.2
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_G
)
==
GLFW_PRESS
)
param_h
-=
deltatime
*
0.2
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_Y
)
==
GLFW_PRESS
)
param_mass
+=
deltatime
*
0.2
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_H
)
==
GLFW_PRESS
)
param_mass
-=
deltatime
*
0.2
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_U
)
==
GLFW_PRESS
)
param_gasConstant
+=
deltatime
*
1500.0
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_J
)
==
GLFW_PRESS
)
param_gasConstant
-=
deltatime
*
1500.0
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_I
)
==
GLFW_PRESS
)
param_offset
+=
deltatime
*
400.0
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_K
)
==
GLFW_PRESS
)
param_offset
-=
deltatime
*
400.0
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_O
)
==
GLFW_PRESS
)
param_viscosity
=
50
;
if
(
glfwGetKey
(
window
.
getWindow
(),
GLFW_KEY_L
)
==
GLFW_PRESS
)
param_viscosity
=
1200
;
auto
cmdStream
=
core
.
createCommandStream
(
vkcv
::
QueueType
::
Graphics
);
auto
cmdStream
=
core
.
createCommandStream
(
vkcv
::
QueueType
::
Graphics
);
//deltatime wird noch nicht genutzt
glm
::
vec4
pushData
[
3
]
=
{
glm
::
vec2
pushData
=
glm
::
vec2
(
deltatime
,
(
float
)
numberParticles
);
glm
::
vec4
(
param_h
,
param_mass
,
param_gasConstant
,
param_offset
),
glm
::
vec4
(
param_gravity
,
param_viscosity
,
param_ABSORBTION
,
param_dt
),
glm
::
vec4
(
gravityDir
.
x
,
gravityDir
.
y
,
gravityDir
.
z
,(
float
)
numberParticles
)
};
std
::
cout
<<
"h: "
<<
param_h
<<
" | mass: "
<<
param_mass
<<
" | gasConstant: "
<<
param_gasConstant
<<
" | offset: "
<<
param_offset
<<
" | viscosity: "
<<
param_viscosity
<<
std
::
endl
;
vkcv
::
PushConstants
pushConstantsCompute
(
sizeof
(
glm
::
vec2
));
vkcv
::
PushConstants
pushConstantsCompute
(
sizeof
(
pushData
));
pushConstantsCompute
.
appendDrawcall
(
pushData
);
pushConstantsCompute
.
appendDrawcall
(
pushData
);
uint32_t
computeDispatchCount
[
3
]
=
{
static_cast
<
uint32_t
>
(
std
::
ceil
(
numberParticles
/
256.
f
)),
1
,
1
};
uint32_t
computeDispatchCount
[
3
]
=
{
static_cast
<
uint32_t
>
(
std
::
ceil
(
numberParticles
/
256.
f
)),
1
,
1
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment