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

HW 5 Submission #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Images for Readme
zedward23 committed Nov 2, 2022
commit 2fc5fc1687742519be5ab30ac925cfe3dca74632
Binary file not shown.
Binary file added img/FrustrumAndDistanceCulling.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/Graph1.png
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/Graph2.png
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/NoWind.png
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/grassWind.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.
2 changes: 1 addition & 1 deletion src/Blades.h
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
#include <array>
#include "Model.h"

constexpr static unsigned int NUM_BLADES = 1 << 13;
constexpr static unsigned int NUM_BLADES = 1 << 22;
constexpr static float MIN_HEIGHT = 1.3f;
constexpr static float MAX_HEIGHT = 2.5f;
constexpr static float MIN_WIDTH = 0.1f;
23 changes: 23 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
#include "Camera.h"
#include "Scene.h"
#include "Image.h"
#include <sstream>
#include <ostream>

Device* device;
SwapChain* swapChain;
@@ -143,10 +145,31 @@ int main() {
glfwSetMouseButtonCallback(GetGLFWWindow(), mouseDownCallback);
glfwSetCursorPosCallback(GetGLFWWindow(), mouseMoveCallback);

double fps = 0;
double timebase = 0;
int frame = 0;

while (!ShouldQuit()) {
glfwPollEvents();

frame++;
double time = glfwGetTime();

double delta = time - timebase;
if (delta > 1.0) {
fps = frame / (delta);
timebase = time;
frame = 0;
}

scene->UpdateTime();
renderer->Frame();

std::ostringstream ss;
ss << "(";
ss.precision(1);
ss << std::fixed << fps << " fps)" << applicationName;
glfwSetWindowTitle(GetGLFWWindow(), ss.str().c_str());
}

vkDeviceWaitIdle(device->GetVkDevice());
13 changes: 12 additions & 1 deletion src/shaders/compute.comp
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

#define WORKGROUP_SIZE 32
#define CULL 1
#define WIND 1
#define RESIST 1

layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in;

@@ -142,16 +144,25 @@ void main() {
vec3 gravity = front + environmental;

// recovery

vec3 v2_0 = v0 + bladeHeight * up;
#if RESIST
vec3 recovery = (v2_0 - v2) * stiffness;

#else
vec3 recovery = vec3(0,0,0);
#endif
// wind
vec3 windDir = fbm(v0, totalTime);
float fd = 1 - length(dot(normalize(windDir), normalize(v2 - v0)));
float fr = dot(normalize(v2 - v0), up) / bladeHeight;
float windAlignment = 3 * fd * fr;

#if WIND
vec3 wind = windDir * windAlignment;
#else
vec3 wind = vec3(0,0,0);
#endif

vec3 deltaV2 = (gravity + recovery + wind) * deltaTime;

v2 += deltaV2;