Added background colour to consts.h
This commit is contained in:
parent
a5c66fc6ca
commit
9afd242121
|
|
@ -30,6 +30,7 @@ __device__ Point3 d_cameraPos;
|
||||||
__device__ Vec3 d_cameraDir;
|
__device__ Vec3 d_cameraDir;
|
||||||
__device__ Vec3 d_cameraUp;
|
__device__ Vec3 d_cameraUp;
|
||||||
__device__ Point3 d_lightPos;
|
__device__ Point3 d_lightPos;
|
||||||
|
__device__ Color3 d_backgroundColor;
|
||||||
|
|
||||||
// Point3 h_cameraPos = Point3::init(300.0f, 200.0f, -700.0f); // Camera for full data set
|
// Point3 h_cameraPos = Point3::init(300.0f, 200.0f, -700.0f); // Camera for full data set
|
||||||
Point3 h_cameraPos = Point3::init(50.0f, -50.0f, -75.0f); // Camera for partially trimmed data set (TODO: Probably upside down atm)
|
Point3 h_cameraPos = Point3::init(50.0f, -50.0f, -75.0f); // Camera for partially trimmed data set (TODO: Probably upside down atm)
|
||||||
|
|
@ -37,6 +38,7 @@ Vec3 center = Vec3::init((float)VOLUME_WIDTH/2.0f, (float)VOLUME_HEIGHT/2.0f, (f
|
||||||
Vec3 h_cameraDir = (center - h_cameraPos).normalize();
|
Vec3 h_cameraDir = (center - h_cameraPos).normalize();
|
||||||
Vec3 h_cameraUp = Vec3::init(0.0, 0.0, 1.0).normalize();
|
Vec3 h_cameraUp = Vec3::init(0.0, 0.0, 1.0).normalize();
|
||||||
Point3 h_lightPos = Point3::init(1.5, 2.0, -1.0);
|
Point3 h_lightPos = Point3::init(1.5, 2.0, -1.0);
|
||||||
|
Color3 h_backgroundColor = Color3::init(0.1f, 0.1f, 0.1f);
|
||||||
|
|
||||||
|
|
||||||
// Copy the above values to the device
|
// Copy the above values to the device
|
||||||
|
|
@ -52,4 +54,5 @@ void copyConstantsToDevice() {
|
||||||
cudaMemcpyToSymbol(d_cameraDir, &h_cameraDir, sizeof(Vec3));
|
cudaMemcpyToSymbol(d_cameraDir, &h_cameraDir, sizeof(Vec3));
|
||||||
cudaMemcpyToSymbol(d_cameraUp, &h_cameraUp, sizeof(Vec3));
|
cudaMemcpyToSymbol(d_cameraUp, &h_cameraUp, sizeof(Vec3));
|
||||||
cudaMemcpyToSymbol(d_lightPos, &h_lightPos, sizeof(Point3));
|
cudaMemcpyToSymbol(d_lightPos, &h_lightPos, sizeof(Point3));
|
||||||
|
cudaMemcpyToSymbol(d_backgroundColor, &h_backgroundColor, sizeof(Color3));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ const float stepSize = 0.02f;
|
||||||
|
|
||||||
|
|
||||||
// --------------------------- Illumination Constants ---------------------------
|
// --------------------------- Illumination Constants ---------------------------
|
||||||
|
// Shading consts
|
||||||
const double ambientStrength = 0.3;
|
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;
|
||||||
|
|
@ -47,6 +48,8 @@ extern __device__ Vec3 d_cameraDir;
|
||||||
extern __device__ Vec3 d_cameraUp;
|
extern __device__ Vec3 d_cameraUp;
|
||||||
extern __device__ Point3 d_lightPos;
|
extern __device__ Point3 d_lightPos;
|
||||||
|
|
||||||
|
// Background color
|
||||||
|
extern __device__ Color3 d_backgroundColor;
|
||||||
|
|
||||||
// --------------------------- Transfer Function Constants ---------------------------
|
// --------------------------- Transfer Function Constants ---------------------------
|
||||||
struct ColorStop {
|
struct ColorStop {
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,9 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer) {
|
||||||
|
|
||||||
if (tNear > tFar) {
|
if (tNear > tFar) {
|
||||||
// No intersection -> Set to brackground color (multiply by SAMPLES_PER_PIXEL because we divide by it later)
|
// No intersection -> Set to brackground color (multiply by SAMPLES_PER_PIXEL because we divide by it later)
|
||||||
accumR = 0.1f * (float)SAMPLES_PER_PIXEL;
|
accumR = d_backgroundColor.x * (float)SAMPLES_PER_PIXEL;
|
||||||
accumG = 0.1f * (float)SAMPLES_PER_PIXEL;
|
accumG = d_backgroundColor.y * (float)SAMPLES_PER_PIXEL;
|
||||||
accumB = 0.1f * (float)SAMPLES_PER_PIXEL;
|
accumB = d_backgroundColor.z * (float)SAMPLES_PER_PIXEL;
|
||||||
accumA = 1.0f * (float)SAMPLES_PER_PIXEL;
|
accumA = 1.0f * (float)SAMPLES_PER_PIXEL;
|
||||||
} else {
|
} else {
|
||||||
if (tNear < 0.0f) tNear = 0.0f;
|
if (tNear < 0.0f) tNear = 0.0f;
|
||||||
|
|
@ -119,11 +119,11 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer) {
|
||||||
accumB += colorB;
|
accumB += colorB;
|
||||||
accumA += alphaAccum;
|
accumA += alphaAccum;
|
||||||
|
|
||||||
// Blend with background (for transparency) // TODO: Put background colour in a constant
|
// Blend with background (for transparency)
|
||||||
float leftover = 1.0 - alphaAccum;
|
float leftover = 1.0 - alphaAccum;
|
||||||
accumR = accumR + leftover * 0.1f;
|
accumR = accumR + leftover * d_backgroundColor.x;
|
||||||
accumG = accumG + leftover * 0.1f;
|
accumG = accumG + leftover * d_backgroundColor.y;
|
||||||
accumB = accumB + leftover * 0.1f;
|
accumB = accumB + leftover * d_backgroundColor.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue