diff --git a/src/consts.cu b/src/consts.cu new file mode 100644 index 0000000..18cf40a --- /dev/null +++ b/src/consts.cu @@ -0,0 +1,18 @@ +#include "consts.h" + +__device__ Point3 d_cameraPos; +__device__ Vec3 d_cameraDir; +__device__ Vec3 d_cameraUp; +__device__ Point3 d_lightPos; + +Point3 h_cameraPos = Point3::init(-0.7, -1.0, -2.0); +Vec3 h_cameraDir = Vec3::init(0.4, 0.6, 1.0).normalize(); +Vec3 h_cameraUp = Vec3::init(0.0, 1.0, 0.0).normalize(); +Point3 h_lightPos = Point3::init(1.5, 2.0, -1.0); + +void copyConstantsToDevice() { + cudaMemcpyToSymbol(d_cameraPos, &h_cameraPos, sizeof(Point3)); + cudaMemcpyToSymbol(d_cameraDir, &h_cameraDir, sizeof(Vec3)); + cudaMemcpyToSymbol(d_cameraUp, &h_cameraUp, sizeof(Vec3)); + cudaMemcpyToSymbol(d_lightPos, &h_lightPos, sizeof(Point3)); +} \ No newline at end of file diff --git a/src/consts.h b/src/consts.h index ba3b389..774c297 100644 --- a/src/consts.h +++ b/src/consts.h @@ -2,6 +2,7 @@ #define CONSTS_H #include "linalg/vec.h" +#include // --------------------------- Basic Constants --------------------------- const int VOLUME_WIDTH = 49; @@ -21,7 +22,7 @@ const int SAMPLES_PER_PIXEL = 8; // TODO: Right now uses simple variance, consi const float alphaAcumLimit = 0.65f; // TODO: Idk what a good accumulation value is const float minAllowedDensity = 0.001f; -float stepSize = 0.002f; +const float stepSize = 0.002f; // --------------------------- Illumination Constants --------------------------- @@ -29,12 +30,15 @@ const double ambientStrength = 0.3; const double diffuseStrength = 0.8; const double specularStrength = 0.5; const int shininess = 32; +const float fov = 60.0f * (M_PI / 180.0f); // Camera and Light -Point3 cameraPos(-0.7, -1.0, -2.0); -Vec3 cameraDir = Vec3(0.4, 0.6, 1.0).normalize(); -Vec3 cameraUp = Vec3(0.0, 1.0, 0.0).normalize(); -float fov = 60.0f * (M_PI / 180.0f); -Point3 lightPos(1.5, 2.0, -1.0); +extern __device__ Point3 d_cameraPos; +extern __device__ Vec3 d_cameraDir; +extern __device__ Vec3 d_cameraUp; +extern __device__ Point3 d_lightPos; + +// --------------------------- Functions for handling external constants --------------------------- +void copyConstantsToDevice(); #endif // CONSTS_H \ No newline at end of file