Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 300 additions & 0 deletions INSTRUCTION.md

Large diffs are not rendered by default.

299 changes: 41 additions & 258 deletions README.md

Large diffs are not rendered by default.

Binary file added img/grass.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/grassdiscull.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/helicopter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/interesting.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/lamb.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/orientcull.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/show.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/viewfrustum.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/Blades.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <array>
#include "Model.h"

constexpr static unsigned int NUM_BLADES = 1 << 13;
constexpr static float MIN_HEIGHT = 1.3f;
constexpr static float MAX_HEIGHT = 2.5f;
constexpr static float MIN_WIDTH = 0.1f;
constexpr static float MAX_WIDTH = 0.14f;
constexpr static unsigned int NUM_BLADES = 1 << 20;
constexpr static float MIN_HEIGHT = 2.3f;
constexpr static float MAX_HEIGHT = 4.5f;
constexpr static float MIN_WIDTH = 0.2f;
constexpr static float MAX_WIDTH = 0.24f;
constexpr static float MIN_BEND = 7.0f;
constexpr static float MAX_BEND = 13.0f;

Expand Down
2,102 changes: 1,136 additions & 966 deletions src/Renderer.cpp

Large diffs are not rendered by default.

218 changes: 156 additions & 62 deletions src/Renderer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,91 @@
//#pragma once
//
//#include "Device.h"
//#include "SwapChain.h"
//#include "Scene.h"
//#include "Camera.h"
//
//class Renderer {
//public:
// Renderer() = delete;
// Renderer(Device* device, SwapChain* swapChain, Scene* scene, Camera* camera);
// ~Renderer();
//
// void CreateCommandPools();
//
// void CreateRenderPass();
//
// void CreateCameraDescriptorSetLayout();
// void CreateModelDescriptorSetLayout();
// void CreateTimeDescriptorSetLayout();
// void CreateComputeDescriptorSetLayout();
// void CreateGrassDescriptorSetLayout();
//
// void CreateDescriptorPool();
//
// void CreateCameraDescriptorSet();
// void CreateModelDescriptorSets();
// void CreateGrassDescriptorSets();
// void CreateTimeDescriptorSet();
// void CreateComputeDescriptorSets();
//
// void CreateGraphicsPipeline();
// void CreateGrassPipeline();
// void CreateComputePipeline();
//
// void CreateFrameResources();
// void DestroyFrameResources();
// void RecreateFrameResources();
//
// void RecordCommandBuffers();
// void RecordComputeCommandBuffer();
//
// void Frame();
//
//private:
// Device* device;
// VkDevice logicalDevice;
// SwapChain* swapChain;
// Scene* scene;
// Camera* camera;
//
// VkCommandPool graphicsCommandPool;
// VkCommandPool computeCommandPool;
//
// VkRenderPass renderPass;
//
// VkDescriptorSetLayout cameraDescriptorSetLayout;
// VkDescriptorSetLayout modelDescriptorSetLayout;
// VkDescriptorSetLayout timeDescriptorSetLayout;
// VkDescriptorSetLayout computeDescriptorLayout;
// VkDescriptorSetLayout grassDescriptorLayout;
//
// VkDescriptorPool descriptorPool;
//
// VkDescriptorSet cameraDescriptorSet;
// std::vector<VkDescriptorSet> modelDescriptorSets;
// VkDescriptorSet timeDescriptorSet;
// std::vector<VkDescriptorSet> computeDescriptorSets;
// std::vector<VkDescriptorSet> grassDescriptorSets;
//
// VkPipelineLayout graphicsPipelineLayout;
// VkPipelineLayout grassPipelineLayout;
// VkPipelineLayout computePipelineLayout;
//
// VkPipeline graphicsPipeline;
// VkPipeline grassPipeline;
// VkPipeline computePipeline;
//
// std::vector<VkImageView> imageViews;
// VkImage depthImage;
// VkDeviceMemory depthImageMemory;
// VkImageView depthImageView;
// std::vector<VkFramebuffer> framebuffers;
//
// std::vector<VkCommandBuffer> commandBuffers;
// VkCommandBuffer computeCommandBuffer;
//};

#pragma once

#include "Device.h"
Expand All @@ -7,76 +95,82 @@

class Renderer {
public:
Renderer() = delete;
Renderer(Device* device, SwapChain* swapChain, Scene* scene, Camera* camera);
~Renderer();
Renderer() = delete;
Renderer(Device* device, SwapChain* swapChain, Scene* scene, Camera* camera);
~Renderer();

void CreateCommandPools();

void CreateCommandPools();
void CreateRenderPass();

void CreateRenderPass();
void CreateCameraDescriptorSetLayout();
void CreateModelDescriptorSetLayout();
void CreateGrassDescriptorSetLayout();
void CreateTimeDescriptorSetLayout();

void CreateCameraDescriptorSetLayout();
void CreateModelDescriptorSetLayout();
void CreateTimeDescriptorSetLayout();
void CreateComputeDescriptorSetLayout();
void CreateComputeDescriptorSetLayout();

void CreateDescriptorPool();
void CreateDescriptorPool();

void CreateCameraDescriptorSet();
void CreateModelDescriptorSets();
void CreateGrassDescriptorSets();
void CreateTimeDescriptorSet();
void CreateComputeDescriptorSets();
void CreateCameraDescriptorSet();
void CreateModelDescriptorSets();
void CreateGrassDescriptorSets();
void CreateTimeDescriptorSet();
void CreateComputeDescriptorSets();

void CreateGraphicsPipeline();
void CreateGrassPipeline();
void CreateComputePipeline();
void CreateGraphicsPipeline();
void CreateGrassPipeline();
void CreateComputePipeline();

void CreateFrameResources();
void DestroyFrameResources();
void RecreateFrameResources();
void CreateFrameResources();
void DestroyFrameResources();
void RecreateFrameResources();

void RecordCommandBuffers();
void RecordComputeCommandBuffer();
void RecordCommandBuffers();
void RecordComputeCommandBuffer();

void Frame();
void Frame();

private:
Device* device;
VkDevice logicalDevice;
SwapChain* swapChain;
Scene* scene;
Camera* camera;

VkCommandPool graphicsCommandPool;
VkCommandPool computeCommandPool;

VkRenderPass renderPass;

VkDescriptorSetLayout cameraDescriptorSetLayout;
VkDescriptorSetLayout modelDescriptorSetLayout;
VkDescriptorSetLayout timeDescriptorSetLayout;

VkDescriptorPool descriptorPool;

VkDescriptorSet cameraDescriptorSet;
std::vector<VkDescriptorSet> modelDescriptorSets;
VkDescriptorSet timeDescriptorSet;

VkPipelineLayout graphicsPipelineLayout;
VkPipelineLayout grassPipelineLayout;
VkPipelineLayout computePipelineLayout;

VkPipeline graphicsPipeline;
VkPipeline grassPipeline;
VkPipeline computePipeline;

std::vector<VkImageView> imageViews;
VkImage depthImage;
VkDeviceMemory depthImageMemory;
VkImageView depthImageView;
std::vector<VkFramebuffer> framebuffers;

std::vector<VkCommandBuffer> commandBuffers;
VkCommandBuffer computeCommandBuffer;
};
Device* device;
VkDevice logicalDevice;
SwapChain* swapChain;
Scene* scene;
Camera* camera;

VkCommandPool graphicsCommandPool;
VkCommandPool computeCommandPool;

VkRenderPass renderPass;

VkDescriptorSetLayout cameraDescriptorSetLayout;
VkDescriptorSetLayout modelDescriptorSetLayout;
VkDescriptorSetLayout grassDescriptorSetLayout;
VkDescriptorSetLayout timeDescriptorSetLayout;
VkDescriptorSetLayout computeDescriptorSetLayout;

VkDescriptorPool descriptorPool;

VkDescriptorSet cameraDescriptorSet;
std::vector<VkDescriptorSet> modelDescriptorSets;
VkDescriptorSet timeDescriptorSet;
std::vector<VkDescriptorSet> grassDescriptorSets;
std::vector<VkDescriptorSet> computeDescriptorSets;

VkPipelineLayout graphicsPipelineLayout;
VkPipelineLayout grassPipelineLayout;
VkPipelineLayout computePipelineLayout;

VkPipeline graphicsPipeline;
VkPipeline grassPipeline;
VkPipeline computePipeline;

std::vector<VkImageView> imageViews;
VkImage depthImage;
VkDeviceMemory depthImageMemory;
VkImageView depthImageView;
std::vector<VkFramebuffer> framebuffers;

std::vector<VkCommandBuffer> commandBuffers;
VkCommandBuffer computeCommandBuffer;
};
13 changes: 11 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace {

int main() {
static constexpr char* applicationName = "Vulkan Grass Rendering";
InitializeWindow(640, 480, applicationName);
InitializeWindow(1000, 720, applicationName);

unsigned int glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
Expand Down Expand Up @@ -116,7 +116,7 @@ int main() {
grassImageMemory
);

float planeDim = 15.f;
float planeDim = 25.f;
float halfWidth = planeDim * 0.5f;
Model* plane = new Model(device, transferCommandPool,
{
Expand All @@ -143,10 +143,19 @@ int main() {
glfwSetMouseButtonCallback(GetGLFWWindow(), mouseDownCallback);
glfwSetCursorPosCallback(GetGLFWWindow(), mouseMoveCallback);

int start = GetTickCount();
int frame = 0;

while (!ShouldQuit()) {
glfwPollEvents();
scene->UpdateTime();
renderer->Frame();
frame++;
if (frame == 500)
{
int total = GetTickCount() - start;
printf("ms per frame%f\n", float(total / 500.0));
}
}

vkDeviceWaitIdle(device->GetVkDevice());
Expand Down
Loading