Okay, figured out input, for real this time
This commit is contained in:
parent
df334c3941
commit
d945f49fca
@ -77,14 +77,17 @@ void Input::handleMovementKeys(Renderer& ren) {
|
|||||||
if (ImGui::GetIO().WantCaptureKeyboard)
|
if (ImGui::GetIO().WantCaptureKeyboard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto dir = ren.cam.dir();
|
||||||
glm::vec3 forward;
|
glm::vec3 forward;
|
||||||
if (ren.flycam)
|
if (ren.flycam)
|
||||||
forward = glm::vec3(glm::sin(ren.cam.theta)*glm::cos(ren.cam.phi), glm::cos(ren.cam.theta), glm::sin(ren.cam.theta)*glm::sin(ren.cam.phi));
|
forward = dir;
|
||||||
else
|
else
|
||||||
forward = glm::vec3(glm::cos(ren.cam.phi), 0.0, glm::sin(ren.cam.phi));
|
forward = glm::normalize(glm::vec3(dir.x, 0.0, dir.z));
|
||||||
const auto right = glm::cross(glm::vec3(0.0, 1.0, 0.0), forward);
|
|
||||||
const auto speed = glfwGetKey(in, GLFW_KEY_LEFT_SHIFT)? 2.0f : 1.0f;
|
|
||||||
|
|
||||||
|
const auto right = glm::normalize(glm::cross(forward, glm::vec3(0.0, 1.0, 0.0)));
|
||||||
|
const auto up = glm::normalize(glm::cross(right, forward));
|
||||||
|
|
||||||
|
const auto speed = glfwGetKey(in, GLFW_KEY_LEFT_SHIFT)? 2.0f : 1.0f;
|
||||||
|
|
||||||
if(glfwGetKey(in, GLFW_KEY_UP)) {
|
if(glfwGetKey(in, GLFW_KEY_UP)) {
|
||||||
ren.cam.theta -= 0.02;
|
ren.cam.theta -= 0.02;
|
||||||
|
|||||||
@ -324,10 +324,10 @@ void Renderer::draw() {
|
|||||||
auto sz = win.getDimensions();
|
auto sz = win.getDimensions();
|
||||||
|
|
||||||
uniform_buffer->upload(UniformData {
|
uniform_buffer->upload(UniformData {
|
||||||
.view = cam.view(),
|
.cam_pos = cam.pos,
|
||||||
.viewport = glm::vec2(viewport.width, viewport.y),
|
|
||||||
.time = time,
|
.time = time,
|
||||||
.focal_length = 2.0,
|
.viewport = glm::vec4(viewport.width, viewport.y, 0.0, 0.0),
|
||||||
|
.cam_dir = cam.dir(),
|
||||||
});
|
});
|
||||||
|
|
||||||
command_buffer->bind(*pipeline);
|
command_buffer->bind(*pipeline);
|
||||||
|
|||||||
@ -11,20 +11,19 @@
|
|||||||
|
|
||||||
/* Uniform:
|
/* Uniform:
|
||||||
*
|
*
|
||||||
* layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
* mat4 view;
|
vec3 cam_pos;
|
||||||
* vec2 viewport;
|
float time;
|
||||||
* float time;
|
vec4 viewport;
|
||||||
* float focal_length;
|
vec3 cam_dir;
|
||||||
* };
|
};
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct UniformData {
|
struct UniformData {
|
||||||
glm::mat4 view;
|
glm::vec3 cam_pos;
|
||||||
glm::vec2 viewport;
|
|
||||||
float time;
|
float time;
|
||||||
float focal_length = 2.0;
|
glm::vec4 viewport;
|
||||||
|
glm::vec3 cam_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UniformBuffer {
|
struct UniformBuffer {
|
||||||
|
|||||||
@ -15,11 +15,11 @@ struct Camera {
|
|||||||
glm::vec3 pos = glm::vec3(0.0f);
|
glm::vec3 pos = glm::vec3(0.0f);
|
||||||
|
|
||||||
inline glm::vec3 dir() {
|
inline glm::vec3 dir() {
|
||||||
return glm::normalize(glm::vec3(
|
return glm::vec3(
|
||||||
sin(theta) * cos(phi),
|
sin(theta) * cos(phi),
|
||||||
cos(theta),
|
cos(theta),
|
||||||
sin(theta) * sin(phi)
|
sin(theta) * sin(phi)
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline glm::mat4 view() {
|
inline glm::mat4 view() {
|
||||||
|
|||||||
@ -1,43 +1,48 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
mat4 view;
|
vec3 cam_pos;
|
||||||
vec2 viewport;
|
|
||||||
float time;
|
float time;
|
||||||
|
vec4 viewport;
|
||||||
|
vec3 cam_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout (location = 0) in vec3 pos;
|
layout (location = 0) in vec2 pos;
|
||||||
layout (location = 1) in vec3 dir;
|
|
||||||
|
|
||||||
layout (location = 0) out vec4 fragColor;
|
layout (location = 0) out vec4 fragColor;
|
||||||
|
|
||||||
|
|
||||||
float sphere(vec3 p, vec3 center, float r) {
|
float sphere(vec3 p, vec3 center, float r) {
|
||||||
return length(p) - r;
|
return length(p-center) - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdf(vec3 pos) {
|
float sdf(vec3 pos) {
|
||||||
return sphere(pos, vec3(0.0, 0.0, 10.0), 3.0);
|
return sphere(pos, vec3(0.0, 0.0, 0.0), 3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float raycast() {
|
float raycast(vec3 dir) {
|
||||||
float t = 0.0;
|
float t = 0.0;
|
||||||
for(int i = 0; i < 64; i++) {
|
for(int i = 0; i < 64; i++) {
|
||||||
float dt = sdf(pos + dir * t);
|
float dt = sdf(cam_pos + dir * t);
|
||||||
if(dt < 0.0001*t)
|
if(dt < 0.0001*t)
|
||||||
return t;
|
return float(i) / 64.0;
|
||||||
else if(dt > 200.0)
|
else if(dt > 200.0)
|
||||||
return -1;
|
return 1.0;
|
||||||
t += dt;
|
t += dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 raygen() {
|
||||||
|
vec3 forward = cam_dir;
|
||||||
|
vec3 right = normalize(cross(forward, vec3(0.0, 1.0, 0.0)));
|
||||||
|
vec3 up = normalize(cross(right, forward));
|
||||||
|
|
||||||
|
return normalize(pos.x * right + pos.y * up + forward * 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float d = raycast();
|
vec3 dir = raygen();
|
||||||
|
float d = raycast(dir);
|
||||||
|
|
||||||
vec3 col = vec3(1.0-d*0.075);
|
fragColor = vec4(d);
|
||||||
|
|
||||||
fragColor = vec4(col, 1.0);
|
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -2,21 +2,16 @@
|
|||||||
|
|
||||||
layout (location = 0) in vec2 aCoord;
|
layout (location = 0) in vec2 aCoord;
|
||||||
|
|
||||||
layout (location = 0) out vec3 pos;
|
layout (location = 0) out vec2 pos;
|
||||||
layout (location = 1) out vec3 dir;
|
|
||||||
|
|
||||||
layout (set = 0, binding = 0) uniform Matrices {
|
layout (set = 0, binding = 0) uniform Matrices {
|
||||||
mat4 view;
|
vec3 cam_pos;
|
||||||
vec2 viewport;
|
|
||||||
float time;
|
float time;
|
||||||
float focal_length;
|
vec4 viewport;
|
||||||
|
vec3 cam_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 p = view * vec4(aCoord.x * viewport.x/viewport.y, aCoord.y, 0.0, 1.0);
|
|
||||||
pos = p.xyz;
|
|
||||||
p-= view * vec4(0.0, 0.0, -focal_length, 1.0);
|
|
||||||
dir = normalize(p.xyz);
|
|
||||||
|
|
||||||
gl_Position = vec4(aCoord, 0.0, 1.0);
|
gl_Position = vec4(aCoord, 0.0, 1.0);
|
||||||
|
pos = vec2(aCoord.x * viewport.x / viewport.y, aCoord.y);
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user