Adding support for windows and fixing some errors
This commit is contained in:
parent
2722a25036
commit
34a8d4eafd
84 changed files with 168 additions and 255 deletions
|
|
@ -9,6 +9,10 @@
|
|||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
using namespace tp;
|
||||
|
||||
void writeImage(const RayTracer::RenderBuffer& output, const char* name) {
|
||||
|
|
@ -37,22 +41,19 @@ void writeImage(const RayTracer::RenderBuffer& output, const char* name) {
|
|||
}
|
||||
}
|
||||
|
||||
static void* printStatus(void* arg) {
|
||||
auto percentage = (const halnf*) arg;
|
||||
void printStatus(const halnf* percentage) {
|
||||
auto old = *percentage;
|
||||
while (*percentage < 0.99f) {
|
||||
sleep(500);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
if (old != *percentage && (*percentage - old) > 0.01) {
|
||||
printf("Progress - %f\n", (*percentage) * 100);
|
||||
std::cout << "Progress - " << (*percentage) * 100 << std::endl;
|
||||
old = *percentage;
|
||||
}
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void renderCommand(const String& scenePath) {
|
||||
Scene scene;
|
||||
|
||||
RayTracer::RenderSettings settings;
|
||||
|
||||
loadScene(scene, scenePath, settings);
|
||||
|
|
@ -60,16 +61,9 @@ void renderCommand(const String& scenePath) {
|
|||
RayTracer::OutputBuffers output;
|
||||
RayTracer rayt;
|
||||
|
||||
pthread_t my_thread;
|
||||
int ret;
|
||||
std::thread statusThread(printStatus, &rayt.mProgress.percentage);
|
||||
|
||||
printf("\nStarting Render:\n\n");
|
||||
|
||||
ret = pthread_create(&my_thread, NULL, &printStatus, &rayt.mProgress.percentage);
|
||||
if (ret != 0) {
|
||||
printf("Error: pthread_create() failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
std::cout << "\nStarting Render:\n\n";
|
||||
|
||||
auto start = get_time();
|
||||
|
||||
|
|
@ -77,9 +71,9 @@ void renderCommand(const String& scenePath) {
|
|||
|
||||
auto end = get_time();
|
||||
|
||||
pthread_join(my_thread, NULL);
|
||||
statusThread.join();
|
||||
|
||||
printf("\nRender finished with average render time per sample - %i (ms)\n", end - start);
|
||||
std::cout << "\nRender finished with average render time per sample - " << (end - start) << " (ms)\n";
|
||||
|
||||
writeImage(output.normals, "normals.png");
|
||||
writeImage(output.color, "color.png");
|
||||
|
|
@ -97,4 +91,4 @@ int main(int argc, const char** argv) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
#include "MathCommon.hpp"
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#include "CommandLine.hpp"
|
||||
#include "Module.hpp"
|
||||
|
|
@ -48,10 +47,10 @@ ModuleManifest* sDependencies[] = { &gModuleMath, &gModuleCommandLine, &gModuleC
|
|||
|
||||
ModuleManifest tp::gModuleRayTracer = ModuleManifest("RayTracer", nullptr, nullptr, sDependencies);
|
||||
|
||||
void RayTracer::castRay(const Ray& ray, RayCastData& out, alnf far) {
|
||||
void RayTracer::castRay(const Ray& ray, RayCastData& out, alnf farVal) {
|
||||
out.hit = false;
|
||||
|
||||
far *= far;
|
||||
farVal *= farVal;
|
||||
|
||||
for (auto obj : mScene->mObjects) {
|
||||
for (auto trig : obj->mCache.TrigCaches) {
|
||||
|
|
@ -60,13 +59,13 @@ void RayTracer::castRay(const Ray& ray, RayCastData& out, alnf far) {
|
|||
|
||||
auto dist = (trig->getHitPos() - ray.pos).length2();
|
||||
|
||||
if (far > dist && dist > EPSILON) {
|
||||
if (farVal > dist && dist > EPSILON) {
|
||||
out.trig = &trig.data();
|
||||
out.hitPos = trig->getHitPos();
|
||||
out.obj = &obj.data();
|
||||
out.hit = true;
|
||||
|
||||
far = dist;
|
||||
farVal = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue