Added samples per pixel gui param
This commit is contained in:
parent
91c9aa193c
commit
2c6594244e
|
|
@ -55,3 +55,6 @@ __device__ float d_alphaAcumLimit;
|
||||||
__device__ int d_tfComboSelected;
|
__device__ int d_tfComboSelected;
|
||||||
__device__ int d_tfComboSelectedColor;
|
__device__ int d_tfComboSelectedColor;
|
||||||
__device__ float d_opacityConst;
|
__device__ float d_opacityConst;
|
||||||
|
|
||||||
|
// ----------------------- Raycasting -----------------------
|
||||||
|
__device__ int d_samplesPerPixel;
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,6 @@ const float MAX_SPEED = 14.0f;
|
||||||
|
|
||||||
|
|
||||||
// --------------------------- Raycasting Constants ---------------------------
|
// --------------------------- Raycasting Constants ---------------------------
|
||||||
const int SAMPLES_PER_PIXEL = 4;
|
|
||||||
|
|
||||||
// const float alphaAcumLimit = 0.4f; // TODO: Atm, this only works with sigmoid
|
|
||||||
const float minAllowedDensity = 0.001f;
|
const float minAllowedDensity = 0.001f;
|
||||||
|
|
||||||
const float stepSize = 0.02f;
|
const float stepSize = 0.02f;
|
||||||
|
|
@ -74,6 +71,8 @@ extern __device__ int d_tfComboSelected;
|
||||||
extern __device__ int d_tfComboSelectedColor;
|
extern __device__ int d_tfComboSelectedColor;
|
||||||
// constant opacity option
|
// constant opacity option
|
||||||
extern __device__ float d_opacityConst;
|
extern __device__ float d_opacityConst;
|
||||||
|
// samples per pixel
|
||||||
|
extern __device__ int d_samplesPerPixel;
|
||||||
|
|
||||||
const int lenStopsPythonLike = 5;
|
const int lenStopsPythonLike = 5;
|
||||||
const int lenStopsGrayscale = 2;
|
const int lenStopsGrayscale = 2;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ Widget::Widget(GLFWwindow* window) {
|
||||||
this->fps = (char*)malloc(512*sizeof(char));
|
this->fps = (char*)malloc(512*sizeof(char));
|
||||||
this->paused = true;
|
this->paused = true;
|
||||||
this->renderOnce = false;
|
this->renderOnce = false;
|
||||||
|
this->samplesPerPixel = 1;
|
||||||
|
|
||||||
this->opacityK = 0;
|
this->opacityK = 0;
|
||||||
this->sigmoidShift = 0.5f;
|
this->sigmoidShift = 0.5f;
|
||||||
|
|
@ -101,6 +102,7 @@ void Widget::tick(double fps) {
|
||||||
}
|
}
|
||||||
sprintf(this->fps, "%.3f fps\n", fps);
|
sprintf(this->fps, "%.3f fps\n", fps);
|
||||||
ImGui::Text(this->fps);
|
ImGui::Text(this->fps);
|
||||||
|
ImGui::DragInt("Samples per pixel", &this->samplesPerPixel, 1, 1, 16, "%d", ImGuiSliderFlags_AlwaysClamp);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Begin("Camera Controls");
|
ImGui::Begin("Camera Controls");
|
||||||
|
|
@ -126,6 +128,8 @@ void Widget::copyToDevice() {
|
||||||
cudaMemcpyToSymbol(&d_lightPos, &this->lightPos, sizeof(Point3));
|
cudaMemcpyToSymbol(&d_lightPos, &this->lightPos, sizeof(Point3));
|
||||||
cudaMemcpyToSymbol(&d_backgroundColor, &this->bgColor, sizeof(Color3));
|
cudaMemcpyToSymbol(&d_backgroundColor, &this->bgColor, sizeof(Color3));
|
||||||
|
|
||||||
|
cudaMemcpyToSymbol(&d_samplesPerPixel, &this->samplesPerPixel, sizeof(int));
|
||||||
|
|
||||||
// cudaMemcpyToSymbol(&d_opacityK, &this->opacityK, sizeof(float));
|
// cudaMemcpyToSymbol(&d_opacityK, &this->opacityK, sizeof(float));
|
||||||
this->opacityKReal = std::pow(10.0f, (-10 + 0.1 * this->opacityK));
|
this->opacityKReal = std::pow(10.0f, (-10 + 0.1 * this->opacityK));
|
||||||
cudaMemcpyToSymbol(&d_opacityK, &this->opacityKReal, sizeof(float));
|
cudaMemcpyToSymbol(&d_opacityK, &this->opacityKReal, sizeof(float));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public:
|
||||||
bool paused;
|
bool paused;
|
||||||
bool renderOnce;
|
bool renderOnce;
|
||||||
char* fps;
|
char* fps;
|
||||||
|
int samplesPerPixel;
|
||||||
|
|
||||||
int tfComboSelected;
|
int tfComboSelected;
|
||||||
int tfComboSelectedColor;
|
int tfComboSelectedColor;
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,14 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer, const
|
||||||
float accumR = 0.0f;
|
float accumR = 0.0f;
|
||||||
float accumG = 0.0f;
|
float accumG = 0.0f;
|
||||||
float accumB = 0.0f;
|
float accumB = 0.0f;
|
||||||
float accumA = 1.0f * (float)SAMPLES_PER_PIXEL;
|
float accumA = 1.0f * (float)d_samplesPerPixel;
|
||||||
|
|
||||||
// Initialize random state for ray scattering
|
// Initialize random state for ray scattering
|
||||||
curandState randState;
|
curandState randState;
|
||||||
curand_init(1234, px + py * width, 0, &randState);
|
curand_init(1234, px + py * width, 0, &randState);
|
||||||
|
|
||||||
// Multiple samples per pixel
|
// Multiple samples per pixel
|
||||||
for (int s = 0; s < SAMPLES_PER_PIXEL; s++) {
|
for (int s = 0; s < d_samplesPerPixel; s++) {
|
||||||
// Map to [-1, 1]
|
// Map to [-1, 1]
|
||||||
float jitterU = (curand_uniform(&randState) - 0.5f) / width;
|
float jitterU = (curand_uniform(&randState) - 0.5f) / width;
|
||||||
float jitterV = (curand_uniform(&randState) - 0.5f) / height;
|
float jitterV = (curand_uniform(&randState) - 0.5f) / height;
|
||||||
|
|
@ -71,11 +71,11 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer, const
|
||||||
intersectAxis(d_cameraPos.z, rayDir.z, 0.0f, (float)VOLUME_DEPTH);
|
intersectAxis(d_cameraPos.z, rayDir.z, 0.0f, (float)VOLUME_DEPTH);
|
||||||
|
|
||||||
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 d_samplesPerPixel because we divide by it later)
|
||||||
accumR = d_backgroundColor.x * (float)SAMPLES_PER_PIXEL;
|
accumR = d_backgroundColor.x * (float)d_samplesPerPixel;
|
||||||
accumG = d_backgroundColor.y * (float)SAMPLES_PER_PIXEL;
|
accumG = d_backgroundColor.y * (float)d_samplesPerPixel;
|
||||||
accumB = d_backgroundColor.z * (float)SAMPLES_PER_PIXEL;
|
accumB = d_backgroundColor.z * (float)d_samplesPerPixel;
|
||||||
accumA = 1.0f * (float)SAMPLES_PER_PIXEL;
|
accumA = 1.0f * (float)d_samplesPerPixel;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (tNear < 0.0f) tNear = 0.0f;
|
if (tNear < 0.0f) tNear = 0.0f;
|
||||||
|
|
@ -130,10 +130,10 @@ __global__ void raycastKernel(float* volumeData, FrameBuffer framebuffer, const
|
||||||
|
|
||||||
|
|
||||||
// Average samples
|
// Average samples
|
||||||
accumR /= (float)SAMPLES_PER_PIXEL;
|
accumR /= (float)d_samplesPerPixel;
|
||||||
accumG /= (float)SAMPLES_PER_PIXEL;
|
accumG /= (float)d_samplesPerPixel;
|
||||||
accumB /= (float)SAMPLES_PER_PIXEL;
|
accumB /= (float)d_samplesPerPixel;
|
||||||
accumA /= (float)SAMPLES_PER_PIXEL;
|
accumA /= (float)d_samplesPerPixel;
|
||||||
|
|
||||||
// Final colour
|
// Final colour
|
||||||
framebuffer.writePixel(px, py, accumR, accumG, accumB, accumA);
|
framebuffer.writePixel(px, py, accumR, accumG, accumB, accumA);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue