-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffuseShading.cpp
More file actions
73 lines (56 loc) · 2.39 KB
/
DiffuseShading.cpp
File metadata and controls
73 lines (56 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "DiffuseShading.hpp"
#include "entity/components/Transform.hpp"
#include "Mesh/Mesh.hpp"
#include "entity/components/MeshInterface.hpp"
#include "assets/AssetsManager.hpp"
#include "graphics/Renderer.hpp"
#include "graphics/RenderSystem.hpp"
#include "math/Matrix3.hpp"
namespace lve {
struct SimplePushConstantData {
mat4 transform{1.f};
mat4 normalMatrix{1.f};
};
DiffuseShading::DiffuseShading() : App("Camera Movement") {
}
DiffuseShading::~DiffuseShading() = default;
void DiffuseShading::start() {
scene->load("DiffuseShading/scene.json");
cameraID = scene->searchEntity("camera")->getId();
renderer->setupDrawResources();
VkPushConstantRange pushConstantRange{};
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
pushConstantRange.offset = 0;
pushConstantRange.size = sizeof(SimplePushConstantData);
renderSystem = std::make_unique<RenderSystem>(
renderer->getDevice(),
renderer->getRenderPass(),
"DiffuseShading",
std::vector<VkPushConstantRange>{pushConstantRange}
);
}
void DiffuseShading::onUpdate(float deltaTime) {
auto& transform = scene->getEntity(cameraID)->getComponent<Transform>();
cameraController.moveInPlaneZX(input, deltaTime, transform);
camera.setViewYXZ(transform.getTranslation(), transform.getRotation());
}
void DiffuseShading::onDrawEntity(VkPipelineLayout layout, VkCommandBuffer commandBuffer, id_t entityID) {
auto entity = scene->getEntity(entityID);
auto& transform = entity->getComponent<Transform>();
auto& meshInterface = entity->getComponent<MeshInterface>();
auto viewProjection = camera.getProjection() * camera.getView();
SimplePushConstantData push{};
auto modelMatrix = transform.worldTransform();
push.transform = viewProjection * modelMatrix;
push.normalMatrix = mat4(transform.normalMatrix());
vkCmdPushConstants(
commandBuffer,
layout,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
0,
sizeof(SimplePushConstantData),
&push);
meshInterface.bind(commandBuffer);
meshInterface.draw(commandBuffer);
}
} // namespace lv