Added constants + exported external variables

This commit is contained in:
Martin Opat 2024-12-30 12:08:29 +01:00
parent 8e4c5290d7
commit 32d0f3a0fb
2 changed files with 28 additions and 6 deletions

18
src/consts.cu Normal file
View File

@ -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));
}

View File

@ -2,6 +2,7 @@
#define CONSTS_H #define CONSTS_H
#include "linalg/vec.h" #include "linalg/vec.h"
#include <cmath>
// --------------------------- Basic Constants --------------------------- // --------------------------- Basic Constants ---------------------------
const int VOLUME_WIDTH = 49; 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 alphaAcumLimit = 0.65f; // TODO: Idk what a good accumulation value is
const float minAllowedDensity = 0.001f; const float minAllowedDensity = 0.001f;
float stepSize = 0.002f; const float stepSize = 0.002f;
// --------------------------- Illumination Constants --------------------------- // --------------------------- Illumination Constants ---------------------------
@ -29,12 +30,15 @@ const double ambientStrength = 0.3;
const double diffuseStrength = 0.8; const double diffuseStrength = 0.8;
const double specularStrength = 0.5; const double specularStrength = 0.5;
const int shininess = 32; const int shininess = 32;
const float fov = 60.0f * (M_PI / 180.0f);
// Camera and Light // Camera and Light
Point3 cameraPos(-0.7, -1.0, -2.0); extern __device__ Point3 d_cameraPos;
Vec3 cameraDir = Vec3(0.4, 0.6, 1.0).normalize(); extern __device__ Vec3 d_cameraDir;
Vec3 cameraUp = Vec3(0.0, 1.0, 0.0).normalize(); extern __device__ Vec3 d_cameraUp;
float fov = 60.0f * (M_PI / 180.0f); extern __device__ Point3 d_lightPos;
Point3 lightPos(1.5, 2.0, -1.0);
// --------------------------- Functions for handling external constants ---------------------------
void copyConstantsToDevice();
#endif // CONSTS_H #endif // CONSTS_H