Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 5: Michael Mason #22

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/build
/bin
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ELSE(USE_D2D_WSI)
find_package(XCB REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")
ENDIF(USE_D2D_WSI)
# Todo : android?
ENDIF(WIN32)

# Set preprocessor defines
Expand Down
55 changes: 49 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,55 @@
Vulkan Grass Rendering
==================================

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 5**
https://github.com/user-attachments/assets/a1ca7be8-5007-4135-999c-f40fa03c1052

* (TODO) YOUR NAME HERE
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
> University of Pennsylvania, CIS 5650: GPU Programming and Architecture, Project 3 - CUDA Path Tracer
> * Michael Mason
> + [Personal Website](https://www.michaelmason.xyz/)
> * Tested on: Windows 11, Ryzen 9 5900HS @ 3.00GHz 16GB, RTX 3080 (Laptop) 8192MB

### (TODO: Your README)
This is a small Vulkan project that implements a grass simulation.

*DO NOT* leave the README to the last minute! It is a crucial part of the
project, and we will not be able to grade you without a good README.
The implementation is based on [Responsive Real-Time Grass Rendering for General 3D Scenes](https://www.cg.tuwien.ac.at/research/publications/2017/JAHRMANN-2017-RRTG/JAHRMANN-2017-RRTG-draft.pdf) by Jahrmann & Wimmer.

## Physics Sim / Forces

### Gravity + Recovery

![Recording 2024-10-31 at 22 18 32](https://github.com/user-attachments/assets/96a571f0-5c65-4d2d-bc6f-f72b95c32ce9)

### Wind

![Recording 2024-10-31 at 22 20 15](https://github.com/user-attachments/assets/1cb92ce7-4e38-4c13-bf8f-5f9b2eff712d)

## Culling Methods

### Orientation

![Recording 2024-10-31 at 22 24 01](https://github.com/user-attachments/assets/2515cba0-8f11-4f7b-bb7b-0d3ad1076ec5)

### Frustum

![Recording 2024-10-31 at 22 26 36](https://github.com/user-attachments/assets/9fbfd865-eecf-4029-ad20-36e0261bd344)

### Distance

![Recording 2024-10-31 at 22 28 39](https://github.com/user-attachments/assets/7fd976c0-e2a6-47be-a788-72a9ee0b03fe)

## Performance Analysis

*Lower is Better*

![No Culling, Orientation, Frustum and Distance](https://github.com/user-attachments/assets/5de8f739-49cc-4c7d-829b-6b7c59614f9d)

The graph above represents the effect of different culling methods for rendering grass in Vulkan. We measured miliseconds per frame against number of grass blades.

Culling by Orientation: this represents the culling occurs when grass blades (which are infinitely flat) are perpendicular to the camera. In the shader, we cull those grass blades within a certain threshold of 90 degrees

Culling by Frustum: This represents culling that occurs when grass blades are outside of the camera frustum. In the shader we cull those blades.

Culling by distance: This represents culling grass blades that are of a certain distance. After 10 units, every 10th blade is culled. After 40 units, every 2nd blade is culled and after 50 units, all blades are culled.

Without any culling, rendering times increase sharply with blade count, reaching 178.32 milliseconds at 4,194,304 blades. Orientation Culling, which removes blades perpendicular to the camera, provides moderate improvement, reducing the time to 123.23 milliseconds at the highest count. Frustum Culling, which discards blades outside the camera's view, achieves a similar but slightly less effective reduction to 156.2 milliseconds. Distance Culling, however, proves to be the most impactful, reducing the frame time to 75.89 milliseconds by progressively removing distant blades, especially effective in large fields where far-off details contribute minimally to visual quality.

While distance culling appears to be the winner here, be mindful that the tests done are dependant on the camera's position and orientation to the grass. It's likely more tests are needed to accurately measure performance of culling.
4 changes: 2 additions & 2 deletions src/Blades.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Blades::Blades(Device* device, VkCommandPool commandPool, float planeDim) : Mode
indirectDraw.firstVertex = 0;
indirectDraw.firstInstance = 0;

BufferUtils::CreateBufferFromData(device, commandPool, blades.data(), NUM_BLADES * sizeof(Blade), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, bladesBuffer, bladesBufferMemory);
BufferUtils::CreateBuffer(device, NUM_BLADES * sizeof(Blade), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, culledBladesBuffer, culledBladesBufferMemory);
BufferUtils::CreateBufferFromData(device, commandPool, blades.data(), getBladesBufferSize(), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, bladesBuffer, bladesBufferMemory);
BufferUtils::CreateBuffer(device, getBladesBufferSize(), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, culledBladesBuffer, culledBladesBufferMemory);
BufferUtils::CreateBufferFromData(device, commandPool, &indirectDraw, sizeof(BladeDrawIndirect), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, numBladesBuffer, numBladesBufferMemory);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Blades.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <array>
#include "Model.h"

constexpr static unsigned int NUM_BLADES = 1 << 13;
constexpr static unsigned int NUM_BLADES = 1 << 16; // 1 < 13
constexpr static float MIN_HEIGHT = 1.3f;
constexpr static float MAX_HEIGHT = 2.5f;
constexpr static float MIN_WIDTH = 0.1f;
Expand Down Expand Up @@ -84,5 +84,8 @@ class Blades : public Model {
VkBuffer GetBladesBuffer() const;
VkBuffer GetCulledBladesBuffer() const;
VkBuffer GetNumBladesBuffer() const;
static constexpr size_t getBladesBufferSize() {
return NUM_BLADES * sizeof(Blade);
}
~Blades();
};
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ foreach(SHADER_SOURCE ${SHADER_SOURCES})
ExternalTarget("Shaders" ${fname}.spv)
add_dependencies(vulkan_grass_rendering ${fname}.spv)
endif(WIN32)

# TODO: Build shaders on not windows
endforeach()

target_link_libraries(vulkan_grass_rendering ${ASSIMP_LIBRARIES} Vulkan::Vulkan glfw)
Expand Down
Loading