working crafter math
This commit is contained in:
parent
84099f07ed
commit
809617e6c4
4 changed files with 21 additions and 20 deletions
|
|
@ -3,13 +3,19 @@ module;
|
|||
#include <cstdint>
|
||||
#include "VulkanBuffer.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <iostream>
|
||||
#include <format>
|
||||
|
||||
module Crafter.Graphics;
|
||||
import Crafter.Math;
|
||||
using namespace Crafter;
|
||||
|
||||
Camera::Camera(float fov, float aspectRatio, float near, float far) {
|
||||
projection = Matrix<float, 4, 4, 1>::Projection(fov, aspectRatio, near, far);
|
||||
view = Matrix<float, 4, 4, 1>::Idenity();
|
||||
projectionView = camera.matrices.perspective*camera.matrices.view;
|
||||
projection = MatrixRowMajor<float, 4, 4, 1>::Perspective(fov, aspectRatio, near, far);
|
||||
view = MatrixRowMajor<float, 4, 4, 1>::Rotation(0, 0, ToRadian(180.0f))*MatrixRowMajor<float, 4, 4, 1>::Translation(1.0f, 0.0f, -10.0f);
|
||||
Update();
|
||||
}
|
||||
|
||||
void Camera::Update() {
|
||||
projectionView = projection*view;
|
||||
}
|
||||
|
|
@ -10,9 +10,10 @@ import Crafter.Math;
|
|||
namespace Crafter {
|
||||
export class Camera : public Component {
|
||||
public:
|
||||
Matrix<float, 4, 4, 1> projection;
|
||||
Matrix<float, 4, 4, 1> view;
|
||||
Matrix<float, 4, 4, 1> projectionView;
|
||||
MatrixRowMajor<float, 4, 4, 1> projection;
|
||||
MatrixRowMajor<float, 4, 4, 1> view;
|
||||
MatrixRowMajor<float, 4, 4, 1> projectionView;
|
||||
Camera(float fov, float aspectRatio, float near, float far);
|
||||
void Update();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ import Crafter.Component;
|
|||
import :Mesh;
|
||||
import :Camera;
|
||||
import :VulkanPipeline;
|
||||
|
||||
import Crafter.Math;
|
||||
|
||||
namespace Crafter {
|
||||
export template <typename VertexType>
|
||||
class MeshShader {
|
||||
public:
|
||||
//glm::mat4 transform;
|
||||
MatrixRowMajor<float, 4, 4, 1> transform;
|
||||
ComponentRefOwning<Mesh<VertexType>> mesh;
|
||||
ComponentRefOwning<Camera> camera;
|
||||
Buffer<float> mvp;
|
||||
Buffer<MatrixRowMajor<float, 4, 4, 1>> mvp;
|
||||
std::uint32_t threadCount;
|
||||
MeshShader(Mesh<VertexType>* mesh, Camera* camera) : threadCount(std::ceil(static_cast<double>(mesh->indexCount)/64/3)), mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera) {
|
||||
|
||||
transform = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
||||
}
|
||||
void WriteDescriptors(DescriptorSet& set) {
|
||||
set.Write(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &mvp.descriptor);
|
||||
|
|
@ -31,7 +31,7 @@ namespace Crafter {
|
|||
set.Write(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, &mesh.component->indicies.descriptor);
|
||||
}
|
||||
void Update() {
|
||||
//mvp.value[0] = camera.component->projectionView*transform;
|
||||
*mvp.value = camera.component->projectionView*transform;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
12
main.cpp
12
main.cpp
|
|
@ -2,16 +2,10 @@
|
|||
#include <exception>
|
||||
#include <thread>
|
||||
#include <vulkan/vulkan.h>
|
||||
#define GLM_FORCE_RADIANS
|
||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
import Crafter.Graphics;
|
||||
import Crafter.Asset;
|
||||
import Crafter.Event;
|
||||
import Crafter.Math;
|
||||
using namespace Crafter;
|
||||
|
||||
typedef VulkanShader<"MeshShaderXYZUV.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 3, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2}}}> MeshVulkanShader;
|
||||
|
|
@ -29,14 +23,14 @@ int main() {
|
|||
Asset asset;
|
||||
asset.LoadFull("cannon.cras");
|
||||
|
||||
Camera camera;
|
||||
Camera camera(1.57079633, 16 / 9, 0.01, 512);
|
||||
camera.Update();
|
||||
Mesh<VertexUV>* mesh = Mesh<VertexUV>::FromAssetUV(asset.entries[0].data.data());
|
||||
DescriptorSet descriptors;
|
||||
Pipeline::GetDescriptorSet(descriptors);
|
||||
|
||||
MeshShader<VertexUV> meshShader(mesh, &camera);
|
||||
meshShader.WriteDescriptors(descriptors);
|
||||
meshShader.transform = glm::mat4(1.0f);
|
||||
meshShader.Update();
|
||||
|
||||
Asset asset2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue