Update krov_engine_main.cu

This commit is contained in:
waternine9 2022-02-09 20:49:00 -05:00
parent f51d81ad6d
commit d8b69f01c8

View File

@ -21,6 +21,7 @@
#include <curand_kernel.h> #include <curand_kernel.h>
#include "cudamathOld.cuh" #include "cudamathOld.cuh"
#include <thrust/device_vector.h> #include <thrust/device_vector.h>
#include "OpenImageDenoise/oidn.hpp"
#define RESOLUTION 512 #define RESOLUTION 512
#define ALLOC_MEM_TRIS_NUM 800 #define ALLOC_MEM_TRIS_NUM 800
__host__ __device__ struct Triangle __host__ __device__ struct Triangle
@ -240,7 +241,7 @@ public:
int* g; int* g;
int* b; int* b;
}; };
bool loadFromObjectFile(std::string sFilename, std::vector<Triangle> &anyData) bool loadFromObjectFile(std::string sFilename, std::vector<Triangle>& anyData)
{ {
std::ifstream f(sFilename); std::ifstream f(sFilename);
if (!f.is_open()) if (!f.is_open())
@ -291,7 +292,7 @@ bool loadFromObjectFile(std::string sFilename, std::vector<Triangle> &anyData)
return true; return true;
} }
Wrapper helper(int y, float camX, float camY, float camZ, float sunX, float sunY, float sunZ, float playerX, float playerY, float playerZ, float degreesXZ, float degreesYZ, Triangle* tris, curandState *state, int depth) Wrapper helper(int y, float camX, float camY, float camZ, float sunX, float sunY, float sunZ, float playerX, float playerY, float playerZ, float degreesXZ, float degreesYZ, Triangle* tris, curandState* state, int depth)
{ {
Triangle* dev_tris = nullptr; Triangle* dev_tris = nullptr;
cudaMalloc(&dev_tris, sizeof(Triangle) * ALLOC_MEM_TRIS_NUM); cudaMalloc(&dev_tris, sizeof(Triangle) * ALLOC_MEM_TRIS_NUM);
@ -311,7 +312,7 @@ Wrapper helper(int y, float camX, float camY, float camZ, float sunX, float sunY
curandState* dev_state = nullptr; curandState* dev_state = nullptr;
cudaMalloc(&dev_state, sizeof(curandState)); cudaMalloc(&dev_state, sizeof(curandState));
cudaMemcpy(dev_state, state, sizeof(curandState), cudaMemcpyHostToDevice); cudaMemcpy(dev_state, state, sizeof(curandState), cudaMemcpyHostToDevice);
_draw_pix<<<RESOLUTION / 4, RESOLUTION>>>(y, camX, camY, camZ, sunX, sunY, sunZ, playerX, playerY, playerZ, degreesXZ, degreesYZ, dev_state, dev_tris, depth, dev_outputR, dev_outputG, dev_outputB); _draw_pix << <RESOLUTION / 4, RESOLUTION >> > (y, camX, camY, camZ, sunX, sunY, sunZ, playerX, playerY, playerZ, degreesXZ, degreesYZ, dev_state, dev_tris, depth, dev_outputR, dev_outputG, dev_outputB);
cudaDeviceSynchronize(); cudaDeviceSynchronize();
cudaMemcpy(outputR, dev_outputR, RESOLUTION * (RESOLUTION / 4) * sizeof(int), cudaMemcpyDeviceToHost); cudaMemcpy(outputR, dev_outputR, RESOLUTION * (RESOLUTION / 4) * sizeof(int), cudaMemcpyDeviceToHost);
cudaMemcpy(outputG, dev_outputG, RESOLUTION * (RESOLUTION / 4) * sizeof(int), cudaMemcpyDeviceToHost); cudaMemcpy(outputG, dev_outputG, RESOLUTION * (RESOLUTION / 4) * sizeof(int), cudaMemcpyDeviceToHost);
@ -355,6 +356,9 @@ void main()
float cameraDist = 4.0f; float cameraDist = 4.0f;
float depth_UNDERCOVER = 1.0f; float depth_UNDERCOVER = 1.0f;
int depth = 1.0f; int depth = 1.0f;
oidn::DeviceRef device = oidn::newDevice();
device.commit();
oidn::FilterRef filter = device.newFilter("RT"); // generic ray tracing filter
while (true) while (true)
{ {
frameCount++; frameCount++;
@ -440,6 +444,17 @@ void main()
} }
mesh.triangles = oldTris; mesh.triangles = oldTris;
std::cout << (clock() - s) / CLOCKS_PER_SEC << std::endl; std::cout << (clock() - s) / CLOCKS_PER_SEC << std::endl;
// Create a denoising filter
if (depth_UNDERCOVER > 4.0f)
{
canvas.convertTo(canvas, CV_32FC3);
filter.setImage("color", canvas.data, oidn::Format::Float3, RESOLUTION, RESOLUTION);
filter.setImage("output", canvas.data, oidn::Format::Float3, RESOLUTION, RESOLUTION);
filter.commit();
filter.execute();
}
cv::imshow("Output", canvas); cv::imshow("Output", canvas);
cv::setMouseCallback("Output", mouseCallback); cv::setMouseCallback("Output", mouseCallback);
cv::waitKey(1); cv::waitKey(1);