Expose camera position to shader
This commit is contained in:
@@ -19,6 +19,7 @@ namespace openVulkanoCpp
|
|||||||
float width, height, nearPlane, farPlane;
|
float width, height, nearPlane, farPlane;
|
||||||
|
|
||||||
Math::Matrix4f viewProjection, view, projection;
|
Math::Matrix4f viewProjection, view, projection;
|
||||||
|
Math::Vector4f camPosition;
|
||||||
|
|
||||||
Camera() : width(0), height(0), nearPlane(0), farPlane(0), projection(1), view(1), viewProjection(1) {}
|
Camera() : width(0), height(0), nearPlane(0), farPlane(0), projection(1), view(1), viewProjection(1) {}
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ namespace openVulkanoCpp
|
|||||||
{
|
{
|
||||||
Node::UpdateWorldMatrix(parentWorldMat);
|
Node::UpdateWorldMatrix(parentWorldMat);
|
||||||
view = Math::Utils::inverse(GetWorldMatrix());
|
view = Math::Utils::inverse(GetWorldMatrix());
|
||||||
|
camPosition = GetWorldMatrix()[3];
|
||||||
UpdateViewProjectionMatrix();
|
UpdateViewProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace openVulkanoCpp
|
|||||||
private:
|
private:
|
||||||
void CreatePipelineLayout()
|
void CreatePipelineLayout()
|
||||||
{
|
{
|
||||||
vk::PushConstantRange camPushConstantDesc = { vk::ShaderStageFlagBits::eVertex, 0, 3 * sizeof(Math::Matrix4f) };
|
vk::PushConstantRange camPushConstantDesc = { vk::ShaderStageFlagBits::eVertex, 0, 3 * sizeof(Math::Matrix4f) + sizeof(Math::Vector4f) };
|
||||||
vk::DescriptorSetLayoutBinding nodeLayoutBinding = { 0, vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex };
|
vk::DescriptorSetLayoutBinding nodeLayoutBinding = { 0, vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex };
|
||||||
std::array<vk::DescriptorSetLayoutBinding, 1> layoutBindings = { nodeLayoutBinding };
|
std::array<vk::DescriptorSetLayoutBinding, 1> layoutBindings = { nodeLayoutBinding };
|
||||||
vk::DescriptorSetLayoutCreateInfo dslci = { {}, layoutBindings.size(), layoutBindings.data() };
|
vk::DescriptorSetLayoutCreateInfo dslci = { {}, layoutBindings.size(), layoutBindings.data() };
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
vk::CommandBufferInheritanceInfo inheritance = { context.swapChainRenderPass.renderPass, 0, context.swapChainRenderPass.GetFrameBuffer()->GetCurrentFrameBuffer() };
|
vk::CommandBufferInheritanceInfo inheritance = { context.swapChainRenderPass.renderPass, 0, context.swapChainRenderPass.GetFrameBuffer()->GetCurrentFrameBuffer() };
|
||||||
cmdHelper->cmdBuffer.begin(vk::CommandBufferBeginInfo{ vk::CommandBufferUsageFlagBits::eOneTimeSubmit | vk::CommandBufferUsageFlagBits::eRenderPassContinue, &inheritance });
|
cmdHelper->cmdBuffer.begin(vk::CommandBufferBeginInfo{ vk::CommandBufferUsageFlagBits::eOneTimeSubmit | vk::CommandBufferUsageFlagBits::eRenderPassContinue, &inheritance });
|
||||||
shader->Record(cmdHelper->cmdBuffer, currentImageId);
|
shader->Record(cmdHelper->cmdBuffer, currentImageId);
|
||||||
cmdHelper->cmdBuffer.pushConstants(context.pipeline.pipelineLayout, vk::ShaderStageFlagBits::eVertex, 0, 3 * sizeof(Math::Matrix4f), &scene->GetCamera()->GetViewProjectionMatrix());
|
cmdHelper->cmdBuffer.pushConstants(context.pipeline.pipelineLayout, vk::ShaderStageFlagBits::eVertex, 0, 3 * sizeof(Math::Matrix4f) + sizeof(Math::Vector4f), &scene->GetCamera()->GetViewProjectionMatrix());
|
||||||
Scene::Drawable** drawablePointer;
|
Scene::Drawable** drawablePointer;
|
||||||
while((drawablePointer = jobQueue->Pop()) != nullptr)
|
while((drawablePointer = jobQueue->Pop()) != nullptr)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user