mirror of
https://github.com/MartinOpat/cuda-based-raytrace.git
synced 2025-06-07 02:13:10 +02:00
Merge branch 'finding-sany2' into gui
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Shader.h"
|
||||
#include "input/Widget.h"
|
||||
#include "cuda_error.h"
|
||||
|
||||
|
||||
Window::Window(unsigned int w, unsigned int h) {
|
||||
@@ -98,6 +99,7 @@ void Window::free(float* data) {
|
||||
|
||||
|
||||
void Window::tick() {
|
||||
std::cout << "tick tick\n";
|
||||
// manually track time diff
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
float diff = (float) std::chrono::duration_cast<std::chrono::milliseconds>(now - this->last_frame).count();
|
||||
@@ -111,6 +113,7 @@ void Window::tick() {
|
||||
this->widget->dateChanged = false;
|
||||
}
|
||||
|
||||
std::cout << "setting tick render\n";
|
||||
// tick render
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
@@ -138,11 +141,14 @@ void Window::tick() {
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6); // draw current frame to texture
|
||||
|
||||
// render ImGui context
|
||||
std::cout << "rendering\n";
|
||||
this->widget->render();
|
||||
std::cout << "done rendering\n";
|
||||
|
||||
// check for events
|
||||
glfwSwapBuffers(this->window);
|
||||
glfwPollEvents();
|
||||
std::cout << "done tick tick\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ void Quad::cuda_init(float* data) {
|
||||
|
||||
|
||||
void Quad::render() {
|
||||
check_cuda_errors(cudaGetLastError());
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
this->renderer->render();
|
||||
glBindTexture(GL_TEXTURE_2D, this->tex);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cstdio>
|
||||
#include <stdlib.h>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
// probably not the cleanest way to do this but it works
|
||||
void parseDate(char* string, int dayOfYear) {
|
||||
@@ -53,7 +54,7 @@ Widget::Widget(GLFWwindow* window) :
|
||||
opacityK(0),
|
||||
sigmoidShift(0.5f),
|
||||
sigmoidExp(-250.0f),
|
||||
tfComboSelected(0),
|
||||
tfComboSelected(2),
|
||||
dateChanged(false),
|
||||
paused(true),
|
||||
renderOnce(false),
|
||||
@@ -62,8 +63,8 @@ Widget::Widget(GLFWwindow* window) :
|
||||
samplesPerPixel(1),
|
||||
alphaAcumLimit(0.4f),
|
||||
opacityConst(100),
|
||||
showSilhouettes(true),
|
||||
silhouettesThreshold(0.2f)
|
||||
showSilhouettes(false),
|
||||
silhouettesThreshold(0.02f)
|
||||
{
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
@@ -72,6 +73,15 @@ Widget::Widget(GLFWwindow* window) :
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
this->cameraPos = Point3::init(59.0f, 77.5f, -18.0f); // Camera for partially trimmed data set
|
||||
this->pitch = 0.7;
|
||||
this->yaw = 4.85;
|
||||
this->roll = -0.010;
|
||||
this->cameraDir = Vec3::getDirectionFromEuler(pitch, yaw, roll);
|
||||
|
||||
this->bgColor = Color3::init(0.1f, 0.1f, 0.1f);
|
||||
this->lightPos = Point3::init(1.5, 2.0, -1.0);
|
||||
|
||||
this->fps = (char*)malloc(512*sizeof(char));
|
||||
this->dateString = (char*)malloc(512*sizeof(char));
|
||||
sprintf(this->dateString, "January 1st");
|
||||
@@ -84,6 +94,7 @@ Widget::Widget(GLFWwindow* window) :
|
||||
// TODO: can be marginally improved by only copying changed values to device - however we're dealing with individual floats here so i dont think the benefit would be all that obvious.
|
||||
// TODO: wrap basically all ImGui calls in if statements; better form + allows for checking return values / errors.
|
||||
void Widget::tick(double fps) {
|
||||
|
||||
if (this->renderOnce) {
|
||||
this->renderOnce = false;
|
||||
this->paused = true;
|
||||
@@ -169,12 +180,23 @@ void Widget::tick(double fps) {
|
||||
ImGui::DragScalar("X position", ImGuiDataType_Double, &this->cameraPos.x, 0.5f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("Y position", ImGuiDataType_Double, &this->cameraPos.z, 0.5f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("Z position", ImGuiDataType_Double, &this->cameraPos.y, 0.5f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("X direction", ImGuiDataType_Double, &this->cameraDir.x, 0.005f, &min, &max, "%.3f"); // TODO: should wrap around once fully rotated
|
||||
ImGui::DragScalar("Y direction", ImGuiDataType_Double, &this->cameraDir.z, 0.005f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("Z direction", ImGuiDataType_Double, &this->cameraDir.y, 0.005f, &min, &max, "%.3f");
|
||||
// ImGui::DragScalar("X direction", ImGuiDataType_Double, &this->cameraDir.x, 0.005f, &min, &max, "%.3f"); // TODO: should wrap around once fully rotated
|
||||
// ImGui::DragScalar("Y direction", ImGuiDataType_Double, &this->cameraDir.z, 0.005f, &min, &max, "%.3f");
|
||||
// ImGui::DragScalar("Z direction", ImGuiDataType_Double, &this->cameraDir.y, 0.005f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("Pitch", ImGuiDataType_Double, &this->pitch, 0.005f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("Yaw", ImGuiDataType_Double, &this->yaw, 0.005f, &min, &max, "%.3f");
|
||||
ImGui::DragScalar("Roll", ImGuiDataType_Double, &this->roll, 0.005f, &min, &max, "%.3f");
|
||||
if (ImGui::Button("Reset camera")) resetCamera();
|
||||
ImGui::End();
|
||||
|
||||
|
||||
this->cameraDir.setDirectionFromEuler(pitch, yaw, roll);
|
||||
|
||||
// Calculate upCamera
|
||||
Vec3 arbitraryVector = Vec3::init(1, 0, 0);
|
||||
cameraUp = arbitraryVector.cross(cameraDir);
|
||||
cameraUp.normalize();
|
||||
cameraUp.rotateAroundAxis(cameraDir, roll);
|
||||
|
||||
copyToDevice();
|
||||
}
|
||||
|
||||
@@ -198,6 +220,7 @@ void Widget::resetLight() {
|
||||
|
||||
void Widget::copyToDevice() {
|
||||
cudaMemcpyToSymbol(&d_cameraPos, &this->cameraPos, sizeof(Point3));
|
||||
cudaMemcpyToSymbol(&d_cameraUp, &this->cameraUp, sizeof(Point3));
|
||||
cudaMemcpyToSymbol(&d_cameraDir, &this->cameraDir, sizeof(Vec3));
|
||||
cudaMemcpyToSymbol(&d_lightPos, &this->lightPos, sizeof(Point3));
|
||||
cudaMemcpyToSymbol(&d_backgroundColor, &this->bgColor, sizeof(Color3));
|
||||
|
||||
@@ -24,6 +24,8 @@ private:
|
||||
// camera controls
|
||||
Point3 cameraDir;
|
||||
Vec3 cameraPos;
|
||||
double pitch, yaw, roll;
|
||||
Vec3 cameraUp;
|
||||
|
||||
// simulation cotnrols
|
||||
bool renderOnce;
|
||||
|
||||
Reference in New Issue
Block a user