mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
~ | Camera FOV and Bounce
This commit is contained in:
@ -21,6 +21,9 @@ struct GPUCamera
|
||||
alignas(16) glm::vec3 camera_position;
|
||||
float aperture_size;
|
||||
float focus_distance;
|
||||
float fov;
|
||||
|
||||
int bounce;
|
||||
};
|
||||
|
||||
class Camera
|
||||
@ -39,16 +42,22 @@ class Camera
|
||||
|
||||
glm::vec3 getPosition();
|
||||
glm::vec2 getDirection();
|
||||
glm::vec2 getDOV();
|
||||
glm::vec3 getViewSetting();
|
||||
glm::mat4 getViewMatrix();
|
||||
|
||||
int getBounce();
|
||||
|
||||
float getFov();
|
||||
float getVelocity();
|
||||
|
||||
|
||||
GPUCamera getGPUData();
|
||||
|
||||
void setPosition(glm::vec3 position);
|
||||
void setDirection(float pitch, float yaw);
|
||||
void setDOV(float aperture, float focus);
|
||||
void setBounce(int b);
|
||||
void setFov(float fov);
|
||||
|
||||
private:
|
||||
|
||||
@ -70,6 +79,9 @@ class Camera
|
||||
|
||||
float _aperture_size = 0.0f;
|
||||
float _focus_distance = 1.0f;
|
||||
float _fov = 90.0f;
|
||||
|
||||
int _bounce = 5;
|
||||
};
|
||||
|
||||
#endif
|
@ -41,7 +41,7 @@ class Cylinder : public Object
|
||||
|
||||
_position = glm::vec3(x, y, z);
|
||||
|
||||
_radius = radius / 2.0;
|
||||
_radius = radius;
|
||||
_height = height;
|
||||
|
||||
_rotation = glm::mat3(glm::eulerAngleXYZ(pitch, yaw, roll));
|
||||
|
97
scenes/pillard.rt
Normal file
97
scenes/pillard.rt
Normal file
@ -0,0 +1,97 @@
|
||||
CAM 18.2756 8.40071 48.9905 -0.2 -470.601 0 1 45 5
|
||||
|
||||
MAT 255 050 050 1.0 0.0 0.0 // 0 red
|
||||
MAT 050 255 050 1.0 0.0 0.0 // 1 green
|
||||
MAT 050 050 255 1.0 0.0 0.0 // 2 blue
|
||||
|
||||
sp +0.000 +17.00 +20.00 4.0 0
|
||||
sp +0.000 +17.00 +0.000 4.0 1
|
||||
sp +0.000 +17.00 -20.00 4.0 2
|
||||
|
||||
|
||||
MAT 250 250 250 0.0 1.7 0.0 DIE // 3 white 0 0 1
|
||||
MAT 250 250 250 0.0 1.0 1.0 // 4 white 0 1 0
|
||||
MAT 250 250 250 0.0 0.0 0.0 // 5 white 1 0 0
|
||||
|
||||
sp +10.00 +9.000 -25.00 6.0 3
|
||||
sp +10.00 +8.700 -15.00 5.4 3
|
||||
sp +10.00 +8.400 -5.000 4.8 3
|
||||
sp +10.00 +8.100 +5.000 4.2 3
|
||||
sp +10.00 +7.800 +15.00 3.6 3
|
||||
sp +10.00 +7.500 +25.00 3.0 3
|
||||
|
||||
sp +24.00 +3.500 +7.000 7.0 4
|
||||
sp +15.00 +2.700 +25.00 5.4 4
|
||||
sp +3.000 +2.500 +16.00 5.0 4
|
||||
sp +1.000 +3.000 +27.00 6.0 4
|
||||
sp -15.00 +3.000 +5.000 6.0 4
|
||||
|
||||
sp +25.00 +1.800 +25.00 3.6 4
|
||||
sp +18.00 +2.000 +31.00 4.0 4
|
||||
sp +3.000 +2.300 +37.00 4.6 4
|
||||
sp -19.00 +2.100 +14.00 4.2 4
|
||||
sp +31.00 +2.200 -24.00 4.4 4
|
||||
|
||||
sp +9.000 +1.400 +30.00 2.8 5
|
||||
sp +16.00 +1.700 +11.00 3.4 5
|
||||
sp -15.00 +1.900 -11.00 3.8 5
|
||||
sp -14.00 +1.800 +26.00 3.6 5
|
||||
sp +12.00 +1.500 -29.00 3.0 5
|
||||
|
||||
|
||||
cy -10.00 +0.300 -25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +19.70 -25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +0.300 -15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +19.70 -15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +0.300 -5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +19.70 -5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +0.300 +5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +19.70 +5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +0.300 +15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +19.70 +15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +0.300 +25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +19.70 +25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
|
||||
cy +10.00 +0.300 -25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +5.700 -25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +0.300 -15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +5.700 -15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +0.300 -5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +5.700 -5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +0.300 +5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +5.700 +5.000 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +0.300 +15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +5.700 +15.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +0.300 +25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +5.700 +25.00 2.0 0.6 +0.000 +1.000 +0.000 5
|
||||
|
||||
MAT 050 050 050 0.0 0.0 0.0 // 6 grey
|
||||
|
||||
cy +0.000 +19.50 +20.00 0.5 1.0 +0.000 +1.000 +0.000 6
|
||||
cy +0.000 +19.50 +0.000 0.5 1.0 +0.000 +1.000 +0.000 6
|
||||
cy +0.000 +19.50 -20.00 0.5 1.0 +0.000 +1.000 +0.000 6
|
||||
|
||||
cy -10.00 +10.00 -15.00 1.5 18. +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +10.00 -25.00 1.5 18. +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +10.00 -5.000 1.5 18. +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +10.00 +5.000 1.5 18. +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +10.00 +15.00 1.5 18. +0.000 +1.000 +0.000 5
|
||||
cy -10.00 +10.00 +25.00 1.5 18. +0.000 +1.000 +0.000 5
|
||||
|
||||
cy +10.00 +3.000 -25.00 1.5 4.8 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +3.000 -15.00 1.5 4.8 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +3.000 -5.000 1.5 4.8 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +3.000 +5.000 1.5 4.8 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +3.000 +15.00 1.5 4.8 +0.000 +1.000 +0.000 5
|
||||
cy +10.00 +3.000 +25.00 1.5 4.8 +0.000 +1.000 +0.000 5
|
||||
|
||||
|
||||
cu +0.000 +10.00 -40.00 70.0 20.0 20.0 5
|
||||
cu 40.00 +10.00 +0.000 20.0 20.0 70.0 5
|
||||
cu -40.00 +10.00 +0.000 20.0 20.0 70.0 5
|
||||
cu 0 +30.00 +0.000 70.0 20.0 70.0 5
|
||||
cu 0 -10.000 +0.000 70.0 20.0 70.0 5
|
||||
# cu +35.00 +10.00 +0.000 -X 80.0 20.0 5
|
||||
# cu -35.00 +10.00 +0.000 +X 80.0 20.0 5
|
||||
# cu +0.000 +20.00 +0.000 -Y 70.0 80.0 5
|
||||
# cu +0.000 +0.000 +0.000 +Y 70.0 80.0 5
|
@ -1,4 +1,4 @@
|
||||
CAM -0.0970577 1.63916 1.69444 -13.6 -84 0 4
|
||||
CAM 1.43879 3.42554 1.94198 -44.6001 -139.599 0.2 4 90 5
|
||||
|
||||
|
||||
MAT 200 200 200 0.0 0.0 0.0 //white
|
||||
|
@ -34,8 +34,12 @@ struct GPUCamera
|
||||
{
|
||||
mat4 view_matrix;
|
||||
vec3 position;
|
||||
|
||||
float aperture_size;
|
||||
float focus_distance;
|
||||
float fov;
|
||||
|
||||
int bounce;
|
||||
};
|
||||
|
||||
layout(std430, binding = 1) buffer ObjectBuffer
|
||||
@ -142,7 +146,7 @@ vec3 pathtrace(Ray ray, inout uint rng_state)
|
||||
|
||||
float closest_t = 1e30;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (int i = 0; i < camera.bounce; i++)
|
||||
{
|
||||
hitInfo hit = traceRay(ray);
|
||||
if (hit.obj_index == -1)
|
||||
@ -176,7 +180,7 @@ vec3 pathtrace(Ray ray, inout uint rng_state)
|
||||
|
||||
Ray initRay(vec2 uv, inout uint rng_state)
|
||||
{
|
||||
float fov = 90.0;
|
||||
float fov = camera.fov;
|
||||
float focal_length = 1.0 / tan(radians(fov) / 2.0);
|
||||
|
||||
vec3 origin = camera.position;
|
||||
|
@ -100,19 +100,23 @@ glm::vec2 Camera::getDirection()
|
||||
return (glm::vec2(_pitch, _yaw));
|
||||
}
|
||||
|
||||
glm::vec2 Camera::getDOV()
|
||||
glm::vec3 Camera::getViewSetting()
|
||||
{
|
||||
return (glm::vec2(_aperture_size, _focus_distance));
|
||||
return (glm::vec3(_aperture_size, _focus_distance, _fov));
|
||||
}
|
||||
|
||||
GPUCamera Camera::getGPUData()
|
||||
{
|
||||
GPUCamera data;
|
||||
|
||||
data.view_matrix = getViewMatrix();
|
||||
data.camera_position = _position;
|
||||
|
||||
data.aperture_size = _aperture_size;
|
||||
data.focus_distance = _focus_distance;
|
||||
data.camera_position = _position;
|
||||
data.view_matrix = getViewMatrix();
|
||||
data.fov = _fov;
|
||||
|
||||
data.bounce = _bounce;
|
||||
|
||||
return (data);
|
||||
}
|
||||
@ -122,6 +126,11 @@ float Camera::getVelocity()
|
||||
return (glm::length(_velocity));
|
||||
}
|
||||
|
||||
int Camera::getBounce()
|
||||
{
|
||||
return (_bounce);
|
||||
}
|
||||
|
||||
void Camera::setPosition(glm::vec3 position)
|
||||
{
|
||||
_position = position;
|
||||
@ -138,3 +147,13 @@ void Camera::setDOV(float aperture, float focus)
|
||||
_aperture_size = aperture;
|
||||
_focus_distance = focus;
|
||||
}
|
||||
|
||||
void Camera::setBounce(int bounce)
|
||||
{
|
||||
_bounce = bounce;
|
||||
}
|
||||
|
||||
void Camera::setFov(float fov)
|
||||
{
|
||||
_fov = fov;
|
||||
}
|
@ -93,7 +93,8 @@ void SceneParser::parseCamera(std::stringstream &line)
|
||||
{
|
||||
float x,y,z;
|
||||
float yaw, pitch;
|
||||
float aperture, focus;
|
||||
float aperture, focus, fov;
|
||||
int bounce;
|
||||
|
||||
if (!(line >> x >> y >> z))
|
||||
throw std::runtime_error("Camera: Missing camera properties");
|
||||
@ -104,17 +105,25 @@ void SceneParser::parseCamera(std::stringstream &line)
|
||||
pitch = -90;
|
||||
}
|
||||
|
||||
if (!(line >> aperture >> focus))
|
||||
if (!(line >> aperture >> focus >> fov))
|
||||
{
|
||||
aperture = 0.0;
|
||||
focus = 1.0;
|
||||
fov = 90.0f;
|
||||
}
|
||||
|
||||
if (!(line >> bounce))
|
||||
bounce = 5;
|
||||
|
||||
_scene->getCamera()->setPosition(glm::vec3(x, y, z));
|
||||
_scene->getCamera()->setDirection(yaw, pitch);
|
||||
_scene->getCamera()->setDOV(aperture, focus);
|
||||
|
||||
_scene->getCamera()->updateCameraVectors();
|
||||
|
||||
_scene->getCamera()->setDOV(aperture, focus);
|
||||
_scene->getCamera()->setFov(fov);
|
||||
|
||||
_scene->getCamera()->setBounce(bounce);
|
||||
|
||||
}
|
||||
|
||||
bool SceneParser::parseLine(const std::string &line)
|
||||
|
@ -113,11 +113,12 @@ void Window::keyCallback(GLFWwindow *window, int key, int scancode, int action,
|
||||
{
|
||||
glm::vec3 pos = win->_scene->getCamera()->getPosition();
|
||||
glm::vec2 dir = win->_scene->getCamera()->getDirection();
|
||||
glm::vec2 dov = win->_scene->getCamera()->getDOV();
|
||||
glm::vec3 settings = win->_scene->getCamera()->getViewSetting();
|
||||
int bounce = win->_scene->getCamera()->getBounce();
|
||||
|
||||
std::cout << "\nCAM\t" << pos.x << " " << pos.y << " " << pos.z << "\t"
|
||||
<< dir.x << " " << dir.y << " " << "\t"
|
||||
<< dov.x << " " << dov.y << " " << "\t"
|
||||
<< settings.x << " " << settings.y << " " << settings.z << "\t" << bounce
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user