diff --git a/Editor/Editor/Editor.cpp b/Editor/Editor/Editor.cpp index 1d2ae00..7d8c16d 100644 --- a/Editor/Editor/Editor.cpp +++ b/Editor/Editor/Editor.cpp @@ -23,8 +23,7 @@ namespace engine3d{ //! @note Handle Events. // m_EditorScene->OnUpdate(); m_EditorScene->OnMoveCamUpdate(); - // Renderer::RecordSceneGameObjects(m_EditorScene->GetSceneObjects(), m_EditorScene->GetCameraObject()); - Renderer::RecordSceneGameObjects(m_EditorScene->GetAllSceneObjects()); + Renderer::RecordSceneGameObjects(m_EditorScene->GetSceneObjects(), m_EditorScene->GetCameraObject()); } ApplicationInstance* InitializeApplication(){ diff --git a/Editor/Editor/EditorScene.cpp b/Editor/Editor/EditorScene.cpp index f3fb4af..e925225 100644 --- a/Editor/Editor/EditorScene.cpp +++ b/Editor/Editor/EditorScene.cpp @@ -9,6 +9,56 @@ #include namespace engine3d{ + static Mesh CreateCubeMesh(glm::vec3 offset){ + std::vector vertices = { // left face (white) + {{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}}, + {{-.5f, .5f, .5f}, {.9f, .9f, .9f}}, + {{-.5f, -.5f, .5f}, {.9f, .9f, .9f}}, + {{-.5f, .5f, -.5f}, {.9f, .9f, .9f}}, + + // right face (yellow) + {{.5f, -.5f, -.5f}, {.8f, .8f, .1f}}, + {{.5f, .5f, .5f}, {.8f, .8f, .1f}}, + {{.5f, -.5f, .5f}, {.8f, .8f, .1f}}, + {{.5f, .5f, -.5f}, {.8f, .8f, .1f}}, + + // top face (orange, remember y axis points down) + {{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}}, + {{.5f, -.5f, .5f}, {.9f, .6f, .1f}}, + {{-.5f, -.5f, .5f}, {.9f, .6f, .1f}}, + {{.5f, -.5f, -.5f}, {.9f, .6f, .1f}}, + + // bottom face (red) + {{-.5f, .5f, -.5f}, {.8f, .1f, .1f}}, + {{.5f, .5f, .5f}, {.8f, .1f, .1f}}, + {{-.5f, .5f, .5f}, {.8f, .1f, .1f}}, + {{.5f, .5f, -.5f}, {.8f, .1f, .1f}}, + + // nose face (blue) + {{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}}, + {{.5f, .5f, 0.5f}, {.1f, .1f, .8f}}, + {{-.5f, .5f, 0.5f}, {.1f, .1f, .8f}}, + {{.5f, -.5f, 0.5f}, {.1f, .1f, .8f}}, + + // tail face (green) + {{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}}, + {{.5f, .5f, -0.5f}, {.1f, .8f, .1f}}, + {{-.5f, .5f, -0.5f}, {.1f, .8f, .1f}}, + {{.5f, -.5f, -0.5f}, {.1f, .8f, .1f}}, + }; + for (auto& v : vertices) { + v.Position += offset; + } + + std::vector indices = {0, 1, 2, 0, 3, 1, 4, 5, 6, 4, 7, 5, 8, 9, 10, 8, 11, 9, + 12, 13, 14, 12, 15, 13, 16, 17, 18, 16, 19, 17, 20, 21, 22, 20, 23, 21}; + + Ref vb = VertexBuffer::Create(vertices); + Ref ib = IndexBuffer::Create(indices); + // return VertexBuffer::Create(vertices); + return Mesh(vb, ib); + } + EditorScene::EditorScene(){ m_Scene = new Scene(); @@ -17,21 +67,20 @@ namespace engine3d{ // auto cube_mesh = CreateCubeMesh({.0f, .0f, .0f}); //! @note Instead of loading in primitive cubes by hand, we load in .obj's instead. - auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/smooth_vase.obj"); + // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/smooth_vase.obj"); // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/colored_cube.obj"); - // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/sphere.obj"); + auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/sphere.obj"); + //! @note Make this scene object as part of our current scene. // ----------------------------- // Camera Scene Object Creation // ----------------------------- - SceneObject* m_CameraObject = new SceneObject(m_Scene); + m_CameraObject = new SceneObject(m_Scene); m_CameraObject->AddComponent(); auto& camera_transform = m_CameraObject->SceneGetComponent(); camera_transform.m_Position = {-1.f, -2.f, -20.f}; auto camera = m_CameraObject->SceneGetComponent(); - m_CameraObjects.push_back(m_CameraObject); - // ----------------------------- // Cube 1 Scene object Creation @@ -39,7 +88,7 @@ namespace engine3d{ SceneObject* cube1 = new SceneObject(m_Scene); auto& cube1_transform = cube1->SceneGetComponent(); cube1_transform.m_Position = {.0f, .0f, 2.5}; - cube1_transform.m_Scale = {10.5f, 10.5f, 10.5}; + cube1_transform.m_Scale = {.5f, .5f, 0.5}; cube1->SetMesh(cube_mesh); // ----------------------------- @@ -49,41 +98,100 @@ namespace engine3d{ auto& cube2_transform = cube2->SceneGetComponent(); // auto aspect_ratio = ApplicationInstance::GetWindow().GetAspectRatio(); cube2_transform.m_Position = {5.f, .0f, -7.f}; - cube2_transform.m_Scale = {5.5f.f, 5.5f, 5.5}; - + cube2_transform.m_Scale = {.5f, .5f, 0.5}; cube2->SetMesh(cube_mesh); - SceneObject* sphere_point_light = new SceneObject(m_Scene); - Mesh mesh = Mesh::LoadModel("3d_models/tutorial/sphere.obj"); - auto& sphere_transform = sphere_point_light->SceneGetComponent(); - sphere_transform.m_Position = {-10.0, 3.0, -1.0}; - sphere_transform.m_Scale = {1.f, 1.f, 1.f}; - sphere_point_light->SetMesh(mesh); //! @note Then we add them to our vector. m_SceneObjects.push_back(cube1); m_SceneObjects.push_back(cube2); - m_PointLightObjects.push_back(sphere_point_light); - m_AllSceneObjecs.insert({"SceneObjects", m_SceneObjects}); - m_AllSceneObjecs.insert({"PointLights", m_PointLightObjects}); - m_AllSceneObjecs.insert({"PointRadioLights", m_PointRadioLights}); - m_AllSceneObjecs.insert({"Cameras", m_CameraObjects}); + } + void EditorScene::OnCreate(){ } - void EditorScene::OnMoveCamUpdate(){ + void EditorScene::OnUpdate(){ + // glm::vec3 m_MoveDirection{0.f}; + // glm::vec3 m_Rotation{0}; - auto& cameraObject = m_AllSceneObjecs["Cameras"].at(0); - auto& transform = cameraObject->SceneGetComponent(); - auto& camera = cameraObject->SceneGetComponent(); + // for(const auto& obj : m_SceneObjects){ + // // auto& transform_compoent = obj->SceneGetComponent(); + // auto& camera_component = obj->SceneGetComponent(); + // camera_component.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 50.f); + // } + } + + void EditorScene::OnMoveCamUpdate(){ + auto& transform = m_CameraObject->SceneGetComponent(); + auto& camera = m_CameraObject->SceneGetComponent(); auto cube_transform = m_SceneObjects[0]->SceneGetComponent(); // float tempDt_Y; glm::vec2 temp_position = {0.f, 0.f}; constexpr float sensitivity = 2.0f; constexpr float pos_sensitivity = 2.f; constexpr glm::vec2 invert_pos = {1, -1}; + // ConsoleLogInfo("x = {}, y = {}, z = {}", transform.m_Position.x, transform.m_Position.y, transform.m_Position.z); + // ConsoleLogInfo("x = {}, y = {}, z = {}\n", cube_transform.m_Position.x, cube_transform.m_Position.y, cube_transform.m_Position.z); + + /* + move-right = D + move-left = A + move-forward = W + move-backward = S + + move-up = E + move-down = Q + + look-left = LEFT + look-right = RIGHT + look-up = UP + look-down = DOWN + */ + + /* + for(const auto& obj : m_SceneObjects){ + glm::vec3 rotate{0}; + if(InputPoll::IsKeyPressed(ENGINE_KEY_LEFT)) rotate.y += 1.f; + if(InputPoll::IsKeyPressed(ENGINE_KEY_RIGHT)) rotate.y -= 1.f; + if(InputPoll::IsKeyPressed(ENGINE_KEY_UP)) rotate.x += 1.f; + if(InputPoll::IsKeyPressed(ENGINE_KEY_DOWN)) rotate.x -= 1.f; + + auto& transform = obj->SceneGetComponent(); + auto& camera = obj->SceneGetComponent(); + + if(glm::dot(rotate, rotate) > std::numeric_limits::epsilon()){ + transform.m_AxisRotation += m_LookSpeed * SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime * glm::normalize(rotate); + } + + transform.m_AxisRotation.x = glm::clamp(transform.m_AxisRotation.x, -1.5f, 1.5f); + transform.m_AxisRotation.y = glm::mod(transform.m_AxisRotation.y, glm::two_pi()); + + float yaw = transform.m_AxisRotation.y; + const glm::vec3 forward_dir{sin(yaw), 0.f, cos(yaw)}; + const glm::vec3 right_dir{forward_dir.z, 0.f, -forward_dir.y}; + const glm::vec3 up_dir{0.f, -1.f, 0.f}; + + glm::vec3 move_dir{0.f}; + + if(InputPoll::IsKeyPressed(ENGINE_KEY_W)) move_dir += forward_dir; // FORWARD + if(InputPoll::IsKeyPressed(ENGINE_KEY_S)) move_dir -= forward_dir; // BACKWARD + if(InputPoll::IsKeyPressed(ENGINE_KEY_D)) move_dir += right_dir; // RIGHT + if(InputPoll::IsKeyPressed(ENGINE_KEY_A)) move_dir -= right_dir; // LEFT + if(InputPoll::IsKeyPressed(ENGINE_KEY_E)) move_dir += up_dir; // UP + if(InputPoll::IsKeyPressed(ENGINE_KEY_Q)) move_dir -= up_dir; // DOWN + + if(glm::dot(move_dir, move_dir) > std::numeric_limits::epsilon()){ + transform.m_Position += m_MoveSpeed * (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * glm::normalize(move_dir); + } + + // camera.SetViewTarget({-1.f, -2.f, -20.f}, transform.m_Position); + // camera.SetViewTarget({0.f, 0.f, 0.f}, transform.m_Position); + camera.SetViewXYZ(transform.m_Position, transform.m_AxisRotation); + } + */ + glm::vec3 rotate{0}; //! @note Make sure that our mouse controls how camera rotates. @@ -107,7 +215,7 @@ namespace engine3d{ float yaw = transform.m_AxisRotation.y; const glm::vec3 forward_dir{sin(yaw), 0.f, cos(yaw)}; - const glm::vec3 right_dir{forward_dir.z, 0.f, -forward_dir.x}; + const glm::vec3 right_dir{forward_dir.z, 0.f, -forward_dir.y}; const glm::vec3 up_dir{0.f, -1.f, 0.f}; glm::vec3 move_dir{0.f}; @@ -129,4 +237,10 @@ namespace engine3d{ camera.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 100.f); } + + // void EditorScene::OnCameraUpdate(){ + // for(const auto& obj : m_SceneObjects){ + // obj->SceneGetComponent().OnUpdate(); + // } + // } }; \ No newline at end of file diff --git a/Editor/Editor/EditorScene.hpp b/Editor/Editor/EditorScene.hpp index b7f3fc7..c03f4fa 100644 --- a/Editor/Editor/EditorScene.hpp +++ b/Editor/Editor/EditorScene.hpp @@ -3,7 +3,6 @@ // #include #include #include -#include namespace engine3d{ class EditorScene{ @@ -16,23 +15,14 @@ namespace engine3d{ void OnMoveCamUpdate(); - // std::vector& GetSceneObjects() { return m_SceneObjects; } + std::vector& GetSceneObjects() { return m_SceneObjects; } - std::unordered_map>& GetAllSceneObjects() { return m_AllSceneObjecs; } - - // SceneObject* GetCameraObject() const { return m_CameraObject; } + SceneObject* GetCameraObject() const { return m_CameraObject; } private: std::vector m_SceneObjects; - std::vector m_PointLightObjects; - std::vector m_CameraObjects; - std::vector m_PointRadioLights; - - - //! @note All scene objects within the scene. - std::unordered_map> m_AllSceneObjecs; Scene* m_Scene; - // SceneObject* m_CameraObject; + SceneObject* m_CameraObject; glm::vec2 m_MousePosition; float m_MoveSpeed = {3.f}; float m_LookSpeed = {1.5f}; diff --git a/engine3d/Core/Renderer/Renderer.hpp b/engine3d/Core/Renderer/Renderer.hpp index 86508b3..4e3a83a 100644 --- a/engine3d/Core/Renderer/Renderer.hpp +++ b/engine3d/Core/Renderer/Renderer.hpp @@ -16,7 +16,6 @@ namespace engine3d{ //! @note Currently the record command buffers just does what "simple_render_system.hpp/.cpp" does already //! @note In the future I'll add API's for submitting draw calls. static void RecordSceneGameObjects(std::vector& p_SceneObjects, SceneObject* p_CameraObject); - static void RecordSceneGameObjects(std::unordered_map>& p_AllSceneObjects); static void EndFrame(); template diff --git a/sim_shader_transforms/simple_shader.frag b/sim_shader_transforms/simple_shader.frag index 08d4ac9..2c2e18e 100644 --- a/sim_shader_transforms/simple_shader.frag +++ b/sim_shader_transforms/simple_shader.frag @@ -2,13 +2,13 @@ layout(location = 0) in vec3 fragColor; -layout(location = 0) out vec4 outColor; +layout(location = 0) out vec4 outColor; layout(push_constant) uniform Push { - mat4 Transform; // proj * view * model - mat4 ModelMatrix; - vec3 LightTransform; + mat4 transform; + vec2 iResolution; + vec3 color; } push; void main(){ diff --git a/sim_shader_transforms/simple_shader.frag.spv b/sim_shader_transforms/simple_shader.frag.spv index 39bdcf5..c07daa5 100644 Binary files a/sim_shader_transforms/simple_shader.frag.spv and b/sim_shader_transforms/simple_shader.frag.spv differ diff --git a/sim_shader_transforms/simple_shader.vert b/sim_shader_transforms/simple_shader.vert index 4978d1c..709464b 100644 --- a/sim_shader_transforms/simple_shader.vert +++ b/sim_shader_transforms/simple_shader.vert @@ -3,33 +3,45 @@ //! @note Position and Color used in the Vertex class. layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Color; -layout(location = 2) in vec3 Normals; -layout(location = 3) in vec2 Uv; - layout(location = 0) out vec3 fragColor; layout(push_constant) uniform Push { - mat4 Transform; // proj * view * model - mat4 ModelMatrix; - vec3 LightTransform; + mat4 transform; + mat4 Projection; + vec2 iResolution; + vec3 color; } push; -// const vec3 dir_to_light = normalize(vec3(1.0, -3.0, -1.0)); -// vec3 light_transform = vec3(1.0, -3.0, -1.0); -// const vec3 dir_to_light = normalize(vec3(1.0, -3.0, -1.0)); -// vec3 dir_to_light = normalize(push.LightTransform); -// const vec3 dir_to_light = normalize(); -vec3 dir_to_light = normalize(push.LightTransform); - void main(){ - // vec4 worldPositionSpace = push.ModelMatrix * vec3(Position, 1.0); - gl_Position = push.Transform * vec4(Position, 1.0); - - // mat3 normal_mat = transpose(inverse(mat3(push.ModelMatrix))); - vec3 normalize_world_space = normalize(mat3(push.ModelMatrix) * Normals); - float LightIntensity = max(dot(normalize_world_space, dir_to_light), 0) / 1.5f; - - // fragColor = Color; - fragColor = LightIntensity * Color; -} \ No newline at end of file + // gl_Position = vec4(Position, 0.0, 1.0); + // mat2 p = (push.transform * 1.f); + // p[0] *= (push.iResolution.y / push.iResolution.x); + // p[1] *= (push.iResolution.y / push.iResolution.x); + // gl_Position = vec4(p * Position + push.offset, 0.0, 1.0); + // mat4 p = push.transform; + // p[0] /= (push.iResolution.x / push.iResolution.y); + // p[1] /= (push.iResolution.x / push.iResolution.y); + // p[2] /= (push.iResolution.x / push.iResolution.y); + // gl_Position = p * vec4(Position, 1.0); + gl_Position = push.transform * vec4(Position, 1.0); + fragColor = Color; +} + +// layout(location = 0) in vec2 Position; +// layout(location = 1) in vec3 Color; + +// // layout(location = 0) out vec3 fragColor; + +// layout(push_constant) uniform Push { +// mat2 transform; +// vec2 offset; +// vec2 iResolution; +// vec3 color; +// } push; + +// void main(){ +// // gl_Position = vec4(Position, 0.0, 1.0); +// gl_Position = vec4(push.transform * Position + push.offset, 0.0, 1.0); +// // fragColor = Color; +// } diff --git a/sim_shader_transforms/simple_shader.vert.spv b/sim_shader_transforms/simple_shader.vert.spv index ef88cd1..1689897 100644 Binary files a/sim_shader_transforms/simple_shader.vert.spv and b/sim_shader_transforms/simple_shader.vert.spv differ diff --git a/src/engine3d/Core/GraphicDrivers/Mesh.cpp b/src/engine3d/Core/GraphicDrivers/Mesh.cpp index 23aeab4..10c8cad 100644 --- a/src/engine3d/Core/GraphicDrivers/Mesh.cpp +++ b/src/engine3d/Core/GraphicDrivers/Mesh.cpp @@ -52,11 +52,18 @@ namespace engine3d{ attrib.vertices[3 * index.vertex_index + 2] }; - vertex.Color = { - attrib.colors[3 * index.vertex_index + 0], - attrib.colors[3 * index.vertex_index + 1], - attrib.colors[3 * index.vertex_index + 2] - }; + //! @note Setting the colors + auto color_idx = 3 * index.vertex_index + 2; + if(color_idx < attrib.colors.size()){ + vertex.Color = { + attrib.colors[color_idx - 2], + attrib.colors[color_idx - 1], + attrib.colors[color_idx - 0] + }; + } + else{ + vertex.Color = {0.f, 0.f, 0.f}; + } } if(index.normal_index >= 0){ diff --git a/src/engine3d/Core/Renderer/Renderer.cpp b/src/engine3d/Core/Renderer/Renderer.cpp index 0e87c42..dfbfcba 100644 --- a/src/engine3d/Core/Renderer/Renderer.cpp +++ b/src/engine3d/Core/Renderer/Renderer.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #define GLM_FORCE_RADIANS #define GLM_FORCE_DEPTH_ZERO_TO_ONE @@ -33,9 +32,8 @@ namespace engine3d{ //! @note vk::VulkanModal is how shaders are going to be struct SimplePushConstantData{ glm::mat4 Transform{1.f}; - glm::mat4 ModelMatrix{1.f}; - glm::vec3 LightTransform{1.0, -3.0, -1.0}; - // alignas(16) glm::vec3 Color; + glm::vec2 iResolution; + alignas(16) glm::vec3 Color; }; void Renderer::Initialize(const std::string& p_DebugName){ @@ -168,82 +166,30 @@ namespace engine3d{ //! @note Starts when to start rendering!! vkCmdBindPipeline(current_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Shader->GetGraphicsPipeline()); float delta_time = SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime; + // ConsoleLogWarn("Delta Time = {:.7}", delta_time); + // auto projection_view = + auto camera_component = p_CameraObject->SceneGetComponent(); //! @note Only for testing purposes for mesh data. - // auto point_light_obj = p_Objects[2]; - // auto point_light_position = point_light_obj->SceneGetComponent().m_Position; - - // for(size_t i = 0; i <= p_Objects.size()-1; i++){ - // ConsoleLogWarn("Index (i <= 1) = {}", i); - for(const auto& obj : p_Objects){ - // auto obj = p_Objects[i]; - + for(auto& obj : p_Objects){ + // auto camera_component = obj->SceneGetComponent(); auto proj_view = camera_component.GetProjection() * camera_component.GetView(); - auto model_matrix = obj->toMat4(); - - SimplePushConstantData push = { - .Transform = proj_view * model_matrix, - .ModelMatrix = model_matrix, - // .LightTransform = point_light_position - }; - - vkCmdPushConstants( - current_cmd_buffer, - g_PipelineLayout, - VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, - 0, - sizeof(SimplePushConstantData), - &push - ); - - auto& vb = obj->GetMesh().GetVertices(); - auto ib = obj->GetMesh().GetIndices(); - vb->Bind(current_cmd_buffer); - - if(ib != nullptr){ - ib->Bind(current_cmd_buffer); - if(ib->HasIndicesPresent()){ - ib->Draw(GetCurrentCommandBuffer()); - } - else{ - vb->Draw(GetCurrentCommandBuffer()); - } - } - else{ - vb->Draw(GetCurrentCommandBuffer()); - } - - } - } - - void Renderer::RecordSceneGameObjects(std::unordered_map>& p_AllSceneObjects){ - - auto current_cmd_buffer = GetCurrentCommandBuffer(); - - //! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i]) - //! @note Starts when to start rendering!! - vkCmdBindPipeline(current_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Shader->GetGraphicsPipeline()); - float delta_time = SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime; - auto cameraObject = p_AllSceneObjects["Cameras"][0]; - auto camera_component = cameraObject->SceneGetComponent(); - - //! @note Only for testing purposes for mesh data. - // auto point_light_obj = p_Objects[2]; - // auto point_light_position = point_light_obj->SceneGetComponent().m_Position; - auto& position = p_AllSceneObjects["Cameras"][0]->SceneGetComponent().m_Position; - - for(const auto& obj : p_AllSceneObjects.at("SceneObjects")){ - - auto proj_view = camera_component.GetProjection() * camera_component.GetView(); + // obj.m_Transform2D.rotation.y = glm::mod(obj.GetTransform().rotation.y + 0.001f, glm::two_pi()); + // float x = obj->GetRotation().x; + // float y = glm::mod(obj->GetRotation().y + (0.1f * delta_time), glm::two_pi()); + // float x = glm::mod(obj->GetRotation().x + (0.05f * delta_time), glm::two_pi()); + // float z = obj->GetRotation().z; - auto model_matrix = obj->toMat4(); + // glm::vec3 new_position = {x, y, z}; + // new_position = glm::normalize(new_position); + // obj->SetRotation(new_position); SimplePushConstantData push = { - .Transform = proj_view * model_matrix, - .ModelMatrix = model_matrix, - .LightTransform = position + .Transform = proj_view * obj->toMat4(), + // .iResolution = {ApplicationInstance::GetWindow().GetWidth(), ApplicationInstance::GetWindow().GetHeight()}, + // .Color = obj.GetColor(), }; vkCmdPushConstants( @@ -255,9 +201,19 @@ namespace engine3d{ &push ); + // obj->GetModel()->Bind(current_cmd_buffer); + // obj->GetModel()->Draw(current_cmd_buffer); auto& vb = obj->GetMesh().GetVertices(); auto ib = obj->GetMesh().GetIndices(); vb->Bind(current_cmd_buffer); + // ib->Bind(current_cmd_buffer); + + // if(ib->HasIndicesPresent()){ + // ib->Draw(current_cmd_buffer); + // } + // else{ + // vb->Draw(current_cmd_buffer); + // } if(ib != nullptr){ ib->Bind(current_cmd_buffer); diff --git a/src/engine3d/Core/internal/Vulkan2Showcase/Shaders/VulkanShader.cpp b/src/engine3d/Core/internal/Vulkan2Showcase/Shaders/VulkanShader.cpp index 3edefdc..ee91c4e 100644 --- a/src/engine3d/Core/internal/Vulkan2Showcase/Shaders/VulkanShader.cpp +++ b/src/engine3d/Core/internal/Vulkan2Showcase/Shaders/VulkanShader.cpp @@ -121,12 +121,22 @@ namespace engine3d::vk{ } std::vector VulkanShader::GetVertexAttributeDescriptions(){ - std::vector attribute_description{}; + std::vector attribute_description(2); + attribute_description[0] = { + .location = 0, // // layout(location = 0) + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + // .offset = 0 + .offset = offsetof(Vertex, Position) + }; + + attribute_description[1] = { + .location = 1, // layout(location = 1) + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(Vertex, Color) + }; - attribute_description.push_back({0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, Position)}); - attribute_description.push_back({1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, Color)}); - attribute_description.push_back({2, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, Normals)}); - attribute_description.push_back({3, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(Vertex, Uv)}); return attribute_description; } @@ -166,7 +176,18 @@ namespace engine3d::vk{ .offset = {0, 0}, .extent = {p_Width, p_Height} }; - + + // config.PipelineViewportCreateInfo = { + // VkPipelineViewportStateCreateInfo PipelineViewportCreateInfo = { + // .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, + // .pNext = nullptr, + // .flags = 0, + // .viewportCount = 1, + // .pViewports = &config.Viewport, + // .scissorCount = 1, + // .pScissors = &config.Scissor + // }; + config.PipelineRasterizationCreateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, .pNext = nullptr,