Skip to content

Commit

Permalink
use namespace
Browse files Browse the repository at this point in the history
fix warnings
project preproc for unsecured functions
change resolution to use int instead for float
  • Loading branch information
CedricGuillemet committed Jan 3, 2019
1 parent f0de4e3 commit 48af68e
Show file tree
Hide file tree
Showing 27 changed files with 1,536 additions and 1,480 deletions.
6 changes: 3 additions & 3 deletions Nvidia-SBVH/src/linear_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct Vec3i

Vec3i(int _x = 0, int _y = 0, int _z = 0) : x(_x), y(_y), z(_z) {}
Vec3i(const Vec3i& v) : x(v.x), y(v.y), z(v.z) {}
Vec3i(const Vec3f& vf) : x(vf.x), y(vf.y), z(vf.z) {}
Vec3i(const Vec3f& vf) : x(int(vf.x)), y(int(vf.y)), z(int(vf.z)) {}

inline bool operator==(const Vec3i& v){ return x == v.x && y == v.y && z == v.z; }
};
Expand Down Expand Up @@ -127,8 +127,8 @@ inline float distance(const Vec3f& v1, const Vec3f& v2){ return sqrtf((v1.x - v2
inline Vec3f powf(const Vec3f& v1, const Vec3f& v2){ return Vec3f(powf(v1.x, v2.x), powf(v1.y, v2.y), powf(v1.z, v2.z)); }
inline Vec3f expf(const Vec3f& v){ return Vec3f(expf(v.x), expf(v.y), expf(v.z)); }
inline float clampf(float a, float lo, float hi){ return a < lo ? lo : a > hi ? hi : a; }
inline Vec3f mixf(const Vec3f& v1, const Vec3f& v2, float a){ return v1 * (1.0 - a) + v2 * a; }
inline float smoothstep(float edge0, float edge1, float x){ float t; t = clampf((x - edge0) / (edge1 - edge0), 0.0, 1.0); return t * t * (3.0 - 2.0 * t); }
inline Vec3f mixf(const Vec3f& v1, const Vec3f& v2, float a){ return v1 * (1.0f - a) + v2 * a; }
inline float smoothstep(float edge0, float edge1, float x){ float t; t = clampf((x - edge0) / (edge1 - edge0), 0.0f, 1.0f); return t * t * (3.0f - 2.0f * t); }

//-------------------------------------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions PathTracer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 15.0.28010.2019
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PathTracer", "PathTracer\PathTracer.vcxproj", "{59EF80B0-FFD2-42B9-8792-E5E8A1C74FD0}"
ProjectSection(ProjectDependencies) = postProject
{2253D157-033A-47C7-B7C5-997C9BC5F29F} = {2253D157-033A-47C7-B7C5-997C9BC5F29F}
{C32FB2B4-500C-43CD-A099-EECCE079D3F1} = {C32FB2B4-500C-43CD-A099-EECCE079D3F1}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Nvidia-SBVH", "Nvidia-SBVH\Nvidia-SBVH.vcxproj", "{2253D157-033A-47C7-B7C5-997C9BC5F29F}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions PathTracer/PathTracer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>GLM_FORCE_RADIANS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;GLM_FORCE_RADIANS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalUsingDirectories>
</AdditionalUsingDirectories>
</ClCompile>
Expand Down Expand Up @@ -204,7 +204,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>GLM_FORCE_RADIANS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;GLM_FORCE_RADIANS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalUsingDirectories>
</AdditionalUsingDirectories>
</ClCompile>
Expand Down
68 changes: 35 additions & 33 deletions PathTracer/src/Camera.cpp
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));
}
}
32 changes: 17 additions & 15 deletions PathTracer/src/Camera.h
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;
};
}
109 changes: 56 additions & 53 deletions PathTracer/src/GPUBVH.cpp
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());
}
}
41 changes: 22 additions & 19 deletions PathTracer/src/GPUBVH.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
#include <glm/glm.hpp>
#include <vector>

struct GPUBVHNode
namespace GLSLPathTracer
{
glm::vec3 BBoxMin;
glm::vec3 BBoxMax;
glm::vec3 LRLeaf;
};
struct GPUBVHNode
{
glm::vec3 BBoxMin;
glm::vec3 BBoxMax;
glm::vec3 LRLeaf;
};

struct TriIndexData
{
glm::vec4 indices;
};
struct TriIndexData
{
glm::vec4 indices;
};

class GPUBVH
{
public:
GPUBVH(const BVH *bvh);
void createGPUBVH();
int traverseBVH(BVHNode *root);
GPUBVHNode *gpuNodes;
const BVH *bvh;
std::vector<TriIndexData> bvhTriangleIndices;
};
class GPUBVH
{
public:
GPUBVH(const BVH *bvh);
void createGPUBVH();
int traverseBVH(BVHNode *root);
GPUBVHNode *gpuNodes;
const BVH *bvh;
std::vector<TriIndexData> bvhTriangleIndices;
};
}
Loading

0 comments on commit 48af68e

Please sign in to comment.