forked from knightcrawler25/GLSL-PathTracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix warnings project preproc for unsecured functions change resolution to use int instead for float
- Loading branch information
1 parent
f0de4e3
commit 48af68e
Showing
27 changed files
with
1,536 additions
and
1,480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
#include <Camera.h> | ||
#include <iostream> | ||
Camera::Camera(glm::vec3 pos, glm::vec3 lookAt, float fov) | ||
{ | ||
position = pos; | ||
worldUp = glm::vec3(0, 1, 0); | ||
glm::vec3 dir = glm::normalize(lookAt - position); | ||
pitch = glm::degrees(asin(dir.y)); | ||
yaw = glm::degrees(atan2(dir.z, dir.x)); | ||
|
||
this->fov = glm::radians(fov); | ||
focalDist = 0.1f; | ||
aperture = 0.0; | ||
updateCamera(); | ||
} | ||
|
||
void Camera::offsetOrientation(float x,float y) | ||
namespace GLSLPathTracer | ||
{ | ||
pitch -= y; | ||
yaw += x; | ||
updateCamera(); | ||
} | ||
Camera::Camera(glm::vec3 pos, glm::vec3 lookAt, float fov) | ||
{ | ||
position = pos; | ||
worldUp = glm::vec3(0, 1, 0); | ||
glm::vec3 dir = glm::normalize(lookAt - position); | ||
pitch = glm::degrees(asin(dir.y)); | ||
yaw = glm::degrees(atan2(dir.z, dir.x)); | ||
|
||
void Camera::offsetPosition(glm::vec3 newPos) | ||
{ | ||
position += newPos; | ||
updateCamera(); | ||
} | ||
this->fov = glm::radians(fov); | ||
focalDist = 0.1f; | ||
aperture = 0.0; | ||
updateCamera(); | ||
} | ||
|
||
void Camera::updateCamera() | ||
{ | ||
glm::vec3 forward_temp; | ||
forward_temp.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); | ||
forward_temp.y = sin(glm::radians(pitch)); | ||
forward_temp.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); | ||
forward = glm::normalize(forward_temp); | ||
void Camera::offsetOrientation(float x, float y) | ||
{ | ||
pitch -= y; | ||
yaw += x; | ||
updateCamera(); | ||
} | ||
|
||
right = glm::normalize(glm::cross(forward, worldUp)); | ||
up = glm::normalize(glm::cross(right, forward)); | ||
} | ||
void Camera::offsetPosition(glm::vec3 newPos) | ||
{ | ||
position += newPos; | ||
updateCamera(); | ||
} | ||
|
||
void Camera::updateCamera() | ||
{ | ||
glm::vec3 forward_temp; | ||
forward_temp.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); | ||
forward_temp.y = sin(glm::radians(pitch)); | ||
forward_temp.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); | ||
forward = glm::normalize(forward_temp); | ||
|
||
right = glm::normalize(glm::cross(forward, worldUp)); | ||
up = glm::normalize(glm::cross(right, forward)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
#pragma once | ||
#include <glm/glm.hpp> | ||
#include <glm/gtc/matrix_transform.hpp> | ||
|
||
class Camera | ||
namespace GLSLPathTracer | ||
{ | ||
public: | ||
Camera(glm::vec3 pos, glm::vec3 lookAt, float fov); | ||
class Camera | ||
{ | ||
public: | ||
Camera(glm::vec3 pos, glm::vec3 lookAt, float fov); | ||
|
||
void offsetOrientation(float x, float y); | ||
void offsetPosition(glm::vec3 val); | ||
void updateCamera(); | ||
glm::vec3 position; | ||
glm::vec3 up; | ||
glm::vec3 right; | ||
glm::vec3 forward; | ||
glm::vec3 worldUp; | ||
float pitch, yaw, fov, focalDist, aperture; | ||
bool isMoving; | ||
}; | ||
void offsetOrientation(float x, float y); | ||
void offsetPosition(glm::vec3 val); | ||
void updateCamera(); | ||
glm::vec3 position; | ||
glm::vec3 up; | ||
glm::vec3 right; | ||
glm::vec3 forward; | ||
glm::vec3 worldUp; | ||
float pitch, yaw, fov, focalDist, aperture; | ||
bool isMoving; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,60 @@ | ||
#include "GPUBVH.h" | ||
#include <iostream> | ||
|
||
static int current; | ||
|
||
int GPUBVH::traverseBVH(BVHNode *root) | ||
{ | ||
AABB *cbox = &root->m_bounds; | ||
gpuNodes[current].BBoxMin[0] = cbox->min().x; | ||
gpuNodes[current].BBoxMin[1] = cbox->min().y; | ||
gpuNodes[current].BBoxMin[2] = cbox->min().z; | ||
|
||
gpuNodes[current].BBoxMax[0] = cbox->max().x; | ||
gpuNodes[current].BBoxMax[1] = cbox->max().y; | ||
gpuNodes[current].BBoxMax[2] = cbox->max().z; | ||
|
||
gpuNodes[current].LRLeaf[2] = 0.0f; | ||
|
||
int index = current; | ||
|
||
if (root->isLeaf()) | ||
{ | ||
const LeafNode* leaf = reinterpret_cast<const LeafNode*>(root); | ||
int start = bvhTriangleIndices.size(); | ||
|
||
gpuNodes[current].LRLeaf[0] = start; | ||
gpuNodes[current].LRLeaf[1] = leaf->m_hi - leaf->m_lo; | ||
gpuNodes[current].LRLeaf[2] = 1.0f; | ||
|
||
for (int i = leaf->m_lo; i < leaf->m_hi; i++) | ||
{ | ||
int index = bvh->getTriIndices()[i]; | ||
const Vec3i& vtxInds = bvh->getScene()->getTriangle(index).vertices; | ||
bvhTriangleIndices.push_back(TriIndexData{ glm::vec4(vtxInds.x,vtxInds.y,vtxInds.z, index) }); | ||
} | ||
} | ||
else | ||
{ | ||
current++; | ||
gpuNodes[index].LRLeaf[0] = traverseBVH(root->getChildNode(0)); | ||
current++; | ||
gpuNodes[index].LRLeaf[1] = traverseBVH(root->getChildNode(1)); | ||
} | ||
return index; | ||
} | ||
|
||
GPUBVH::GPUBVH(const BVH* bvh) | ||
{ | ||
this->bvh = bvh; | ||
createGPUBVH(); | ||
} | ||
|
||
void GPUBVH::createGPUBVH() | ||
namespace GLSLPathTracer | ||
{ | ||
gpuNodes = new GPUBVHNode[bvh->getNumNodes()]; | ||
traverseBVH(bvh->getRoot()); | ||
} | ||
static int current; | ||
|
||
int GPUBVH::traverseBVH(BVHNode *root) | ||
{ | ||
AABB *cbox = &root->m_bounds; | ||
gpuNodes[current].BBoxMin[0] = cbox->min().x; | ||
gpuNodes[current].BBoxMin[1] = cbox->min().y; | ||
gpuNodes[current].BBoxMin[2] = cbox->min().z; | ||
|
||
gpuNodes[current].BBoxMax[0] = cbox->max().x; | ||
gpuNodes[current].BBoxMax[1] = cbox->max().y; | ||
gpuNodes[current].BBoxMax[2] = cbox->max().z; | ||
|
||
gpuNodes[current].LRLeaf[2] = 0.0f; | ||
|
||
int index = current; | ||
|
||
if (root->isLeaf()) | ||
{ | ||
const LeafNode* leaf = reinterpret_cast<const LeafNode*>(root); | ||
int start = int(bvhTriangleIndices.size()); | ||
|
||
gpuNodes[current].LRLeaf[0] = float(start); // strange cast here. loss of data for big numbers | ||
gpuNodes[current].LRLeaf[1] = float(leaf->m_hi - leaf->m_lo); | ||
gpuNodes[current].LRLeaf[2] = 1.0f; | ||
|
||
for (int i = leaf->m_lo; i < leaf->m_hi; i++) | ||
{ | ||
int index = bvh->getTriIndices()[i]; | ||
const Vec3i& vtxInds = bvh->getScene()->getTriangle(index).vertices; | ||
bvhTriangleIndices.push_back(TriIndexData{ glm::vec4(vtxInds.x,vtxInds.y,vtxInds.z, index) }); | ||
} | ||
} | ||
else | ||
{ | ||
current++; | ||
gpuNodes[index].LRLeaf[0] = float(traverseBVH(root->getChildNode(0))); | ||
current++; | ||
gpuNodes[index].LRLeaf[1] = float(traverseBVH(root->getChildNode(1))); | ||
} | ||
return index; | ||
} | ||
|
||
GPUBVH::GPUBVH(const BVH* bvh) | ||
{ | ||
this->bvh = bvh; | ||
createGPUBVH(); | ||
} | ||
|
||
void GPUBVH::createGPUBVH() | ||
{ | ||
gpuNodes = new GPUBVHNode[bvh->getNumNodes()]; | ||
traverseBVH(bvh->getRoot()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.