mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Portal viewing angle teleportation
This commit is contained in:
@ -29,6 +29,6 @@ Pos=1556,610
|
|||||||
Size=284,382
|
Size=284,382
|
||||||
|
|
||||||
[Window][Settings]
|
[Window][Settings]
|
||||||
Pos=83,57
|
Pos=1567,9
|
||||||
Size=336,330
|
Size=340,941
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class Camera
|
|||||||
void processKeyboard(bool forward, bool backward, bool left, bool right, bool up, bool down);
|
void processKeyboard(bool forward, bool backward, bool left, bool right, bool up, bool down);
|
||||||
|
|
||||||
void updateCameraVectors();
|
void updateCameraVectors();
|
||||||
|
void updateCameraDirections();
|
||||||
|
|
||||||
int portalTeleport(Scene *scene, float delta_time);
|
int portalTeleport(Scene *scene, float delta_time);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ class Window
|
|||||||
Window(Scene *scene, int width, int height, const char *title, int sleep, Arguments &args);
|
Window(Scene *scene, int width, int height, const char *title, int sleep, Arguments &args);
|
||||||
~Window(void);
|
~Window(void);
|
||||||
|
|
||||||
|
void updateDeltaTime();
|
||||||
void display();
|
void display();
|
||||||
void pollEvents();
|
void pollEvents();
|
||||||
bool shouldClose();
|
bool shouldClose();
|
||||||
|
@ -45,16 +45,10 @@ class Portal : public Object
|
|||||||
_up = glm::vec3(x1, y1, z1);
|
_up = glm::vec3(x1, y1, z1);
|
||||||
_right = glm::vec3(x2, y2, z2);
|
_right = glm::vec3(x2, y2, z2);
|
||||||
|
|
||||||
// glm::vec3 temp_right = _right;
|
|
||||||
// _right = _invert_normal ? _up : _right;
|
|
||||||
// _up = _invert_normal ? temp_right : _up;
|
|
||||||
|
|
||||||
glm::vec3 right = glm::normalize(_right);
|
glm::vec3 right = glm::normalize(_right);
|
||||||
glm::vec3 up = glm::normalize(_up);
|
glm::vec3 up = glm::normalize(_up);
|
||||||
glm::vec3 forward = glm::normalize(glm::cross(right, up));
|
glm::vec3 forward = glm::normalize(glm::cross(right, up));
|
||||||
|
|
||||||
// up = normalize(glm::cross(forward, right));
|
|
||||||
|
|
||||||
_rotation = glm::mat3(right, up, forward);
|
_rotation = glm::mat3(right, up, forward);
|
||||||
_normal = forward * (_invert_normal ? -1.0f : 1.0f);
|
_normal = forward * (_invert_normal ? -1.0f : 1.0f);
|
||||||
|
|
||||||
@ -72,10 +66,6 @@ class Portal : public Object
|
|||||||
glm::vec3 right_dir = glm::normalize(_right);
|
glm::vec3 right_dir = glm::normalize(_right);
|
||||||
glm::vec3 up_dir = glm::normalize(_up);
|
glm::vec3 up_dir = glm::normalize(_up);
|
||||||
|
|
||||||
// glm::vec3 temp_right = right_dir;
|
|
||||||
// right_dir = _invert_normal ? right_dir : up_dir;
|
|
||||||
// up_dir = _invert_normal ? up_dir : temp_right;
|
|
||||||
|
|
||||||
float right_length = glm::length(_right) + extension;
|
float right_length = glm::length(_right) + extension;
|
||||||
float up_length = glm::length(_up) + extension;
|
float up_length = glm::length(_up) + extension;
|
||||||
|
|
||||||
@ -84,7 +74,7 @@ class Portal : public Object
|
|||||||
|
|
||||||
glm::vec3 right = right_dir * right_length;
|
glm::vec3 right = right_dir * right_length;
|
||||||
glm::vec3 up = up_dir * up_length;
|
glm::vec3 up = up_dir * up_length;
|
||||||
// position += 10;
|
|
||||||
return (new Quad(position, right, up, _normal, 1, _mat_index));
|
return (new Quad(position, right, up, _normal, 1, _mat_index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ cu 0 10 0 5 5 5 3
|
|||||||
sp 0 10 0 1 4
|
sp 0 10 0 1 4
|
||||||
|
|
||||||
|
|
||||||
OBJ obj/lambo.obj 0 1.5 0 1 0 0 0
|
OBJ scenes/obj/lambo.obj 0 1.5 0 1 0 0 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
CAM -2.43549 3.10568 -6.50845 -16.4 53.8007 0 1 90 5
|
CAM -3.31413 5.09653 9.67312 -19.6 -74.7992 0 1 90 5
|
||||||
|
|
||||||
MAT 100 200 100 0.0 0.0 0.0 // 0
|
MAT 100 200 100 0.0 0.0 0.0 // 0
|
||||||
MAT 200 200 200 0.0 0.0 0.0 // 1
|
MAT 200 200 200 0.0 0.0 0.0 // 1
|
||||||
@ -36,4 +36,14 @@ qu 9.5 3 -1 3 0 0 0 0 2 0 1
|
|||||||
|
|
||||||
# #small tunnel entrace behind
|
# #small tunnel entrace behind
|
||||||
# po 9.5 2 -1 3 0 0 0 3 0 1 5
|
# po 9.5 2 -1 3 0 0 0 3 0 1 5
|
||||||
# po -1.5 2 -4 3 0 0 0 3 0 0 5
|
# po -1.5 2 -4 3 0 0 0 3 0 0 5
|
||||||
|
|
||||||
|
#top portals
|
||||||
|
|
||||||
|
po -6 1 0 3 0 0 0 0 3 1 1
|
||||||
|
po -10 1 0 0 3 0 0 0 3 0 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
po -1 1.5 10 0 1.5 0 1.5 0 0 0 1
|
||||||
|
po 1 1.5 10 0 0 1.5 1.5 0 0 0 1
|
@ -187,16 +187,14 @@ vec3 pathtrace(Ray ray, inout uint rng_state)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (hit.obj_index == -1)
|
||||||
float miss_condition = float(hit.obj_index == -1);
|
{
|
||||||
light += miss_condition * transmittance * GetEnvironmentLight(ray);
|
light += transmittance * GetEnvironmentLight(ray);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
float p = max(color.r, max(color.g, color.b));
|
float p = max(color.r, max(color.g, color.b));
|
||||||
float rr_continue = float(randomValue(rng_state) <= p);
|
if (randomValue(rng_state) >= p) break;
|
||||||
|
|
||||||
float break_condition = miss_condition + (1.0 - rr_continue);
|
|
||||||
if (break_condition > 0.0) break;
|
|
||||||
|
|
||||||
color /= max(p, 0.001);
|
color /= max(p, 0.001);
|
||||||
|
|
||||||
GPUMaterial mat = materials[hit.mat_index];
|
GPUMaterial mat = materials[hit.mat_index];
|
||||||
|
@ -104,6 +104,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
while (!window.shouldClose())
|
while (!window.shouldClose())
|
||||||
{
|
{
|
||||||
|
window.updateDeltaTime();
|
||||||
|
|
||||||
glUseProgram(shader.getProgramCompute());
|
glUseProgram(shader.getProgramCompute());
|
||||||
|
|
||||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, materialSSBO);
|
glBindBuffer(GL_SHADER_STORAGE_BUFFER, materialSSBO);
|
||||||
|
@ -36,6 +36,19 @@ void Camera::updateCameraVectors()
|
|||||||
_up = glm::normalize(glm::cross(_right, _forward));
|
_up = glm::normalize(glm::cross(_right, _forward));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Camera::updateCameraDirections()
|
||||||
|
{
|
||||||
|
glm::vec3 forward_xz = glm::normalize(glm::vec3(_forward.x, 0.0f, _forward.z));
|
||||||
|
_pitch = glm::degrees(asin(_forward.y));
|
||||||
|
|
||||||
|
_yaw = glm::degrees(atan2(-_forward.x, _forward.z));
|
||||||
|
|
||||||
|
_yaw = fmod(_yaw + 360.0f, 360.0f);
|
||||||
|
_pitch = glm::clamp(_pitch, -89.0f, 89.0f);
|
||||||
|
|
||||||
|
_yaw += 90;
|
||||||
|
}
|
||||||
|
|
||||||
void Camera::update(Scene *scene, float delta_time)
|
void Camera::update(Scene *scene, float delta_time)
|
||||||
{
|
{
|
||||||
// delta_time = std::min(delta_time, 0.01f);
|
// delta_time = std::min(delta_time, 0.01f);
|
||||||
@ -83,11 +96,35 @@ int Camera::portalTeleport(Scene *scene, float delta_time)
|
|||||||
float distance_future_pos = glm::length(future_pos - _position);
|
float distance_future_pos = glm::length(future_pos - _position);
|
||||||
float distance_portal = glm::length(point_projected - _position);
|
float distance_portal = glm::length(point_projected - _position);
|
||||||
|
|
||||||
|
float imprecision = 0.1f;
|
||||||
|
|
||||||
if (distance_portal <= distance_future_pos && glm::dot(glm::normalize(future_pos - _position), obj.normal) > 0.0f)
|
if (distance_portal <= distance_future_pos && glm::dot(glm::normalize(future_pos - _position), obj.normal) > 0.0f)
|
||||||
{
|
{
|
||||||
GPUObject linked_portal = scene->getObjectData()[obj.radius];
|
GPUObject linked_portal = scene->getObjectData()[obj.radius];
|
||||||
_position = (linked_portal.position) + (_position - obj.position) - (((distance_future_pos - distance_portal)) * linked_portal.normal);
|
|
||||||
|
glm::mat4 portal_transform = linked_portal.transform * glm::inverse(obj.transform);
|
||||||
|
|
||||||
|
//teleportation
|
||||||
|
|
||||||
|
glm::vec3 relative_pos = _position - obj.position;
|
||||||
|
glm::vec3 transformed_relative_pos = glm::vec3(portal_transform * glm::vec4(relative_pos, 1.0f));
|
||||||
|
|
||||||
|
float remaining_distance = distance_future_pos - distance_portal + imprecision;
|
||||||
|
glm::vec3 new_movement = remaining_distance * glm::vec3(portal_transform * glm::vec4(linked_portal.normal, 0.0f));
|
||||||
|
|
||||||
|
_position = linked_portal.position + transformed_relative_pos - new_movement;
|
||||||
|
// _position = (linked_portal.position) + (_position - obj.position) - (((distance_future_pos - distance_portal + imprecision)) * linked_portal.normal);
|
||||||
|
|
||||||
|
// view direction
|
||||||
|
|
||||||
|
_forward = glm::vec3(portal_transform * glm::vec4(_forward, 1.0f));
|
||||||
|
_up = glm::vec3(portal_transform * glm::vec4(_up, 1.0f));
|
||||||
|
_right = glm::vec3(portal_transform * glm::vec4(_right, 1.0f));
|
||||||
|
|
||||||
|
updateCameraDirections();
|
||||||
|
|
||||||
|
_velocity = glm::vec3(portal_transform * glm::vec4(_velocity, 0.0f));
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ void Window::keyCallback(GLFWwindow *window, int key, int scancode, int action,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::display()
|
void Window::updateDeltaTime()
|
||||||
{
|
{
|
||||||
static double lastTime = glfwGetTime();
|
static double lastTime = glfwGetTime();
|
||||||
double currentTime = glfwGetTime();
|
double currentTime = glfwGetTime();
|
||||||
@ -146,6 +146,12 @@ void Window::display()
|
|||||||
|
|
||||||
if (accumulate)
|
if (accumulate)
|
||||||
_frameCount++;
|
_frameCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::display()
|
||||||
|
{
|
||||||
|
if (accumulate)
|
||||||
|
_frameCount++;
|
||||||
|
|
||||||
if (_scene->getCamera()->getVelocity() > 0.0f)
|
if (_scene->getCamera()->getVelocity() > 0.0f)
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
|
Reference in New Issue
Block a user