some changes for speed and usability with the fast version
This commit is contained in:
2
makefile
2
makefile
@@ -7,7 +7,7 @@ STB_DIR := ./stb
|
|||||||
|
|
||||||
# Compiler and flags
|
# Compiler and flags
|
||||||
CXX := g++
|
CXX := g++
|
||||||
BASE_CXXFLAGS = -std=c++23 -O3 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I$(STB_DIR)
|
BASE_CXXFLAGS = -std=c++23 -O3 -fopenmp -march=native -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I$(STB_DIR)
|
||||||
BASE_CXXFLAGS += `pkg-config --cflags glfw3`
|
BASE_CXXFLAGS += `pkg-config --cflags glfw3`
|
||||||
CFLAGS = $(BASE_CXXFLAGS)
|
CFLAGS = $(BASE_CXXFLAGS)
|
||||||
LDFLAGS := -L./imgui -limgui -lGL
|
LDFLAGS := -L./imgui -limgui -lGL
|
||||||
|
|||||||
@@ -1177,10 +1177,10 @@ public:
|
|||||||
Ray oray(origin, direction);
|
Ray oray(origin, direction);
|
||||||
|
|
||||||
float tMin, tMax;
|
float tMin, tMax;
|
||||||
// if (rayBoxIntersect(oray, root_->bounds, tMin, tMax)) {
|
if (rayBoxIntersect(oray, root_->bounds, tMin, tMax)) {
|
||||||
tMax = std::min(tMax, maxDist);
|
tMax = std::min(tMax, maxDist);
|
||||||
voxelTraverseRecursive(root_.get(), tMin, tMax, maxDist, enableLOD, oray, hit, invLodf);
|
voxelTraverseRecursive(root_.get(), tMin, tMax, maxDist, enableLOD, oray, hit, invLodf);
|
||||||
// }
|
}
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1255,15 +1255,18 @@ public:
|
|||||||
|
|
||||||
frame outFrame(width, height, colorformat);
|
frame outFrame(width, height, colorformat);
|
||||||
std::vector<float> colorBuffer;
|
std::vector<float> colorBuffer;
|
||||||
int channels;
|
colorBuffer.resize(width * height * 3);
|
||||||
channels = 3;
|
|
||||||
colorBuffer.resize(width * height * channels);
|
|
||||||
|
|
||||||
float aspect = static_cast<float>(width) / height;
|
const float aspect = static_cast<float>(width) / height;
|
||||||
float fovRad = cam.fovRad();
|
const float fovRad = cam.fovRad();
|
||||||
float tanHalfFov = tan(fovRad * 0.5f);
|
const float tanHalfFov = tan(fovRad * 0.5f);
|
||||||
float tanfovy = tanHalfFov;
|
const float tanfovy = tanHalfFov;
|
||||||
float tanfovx = tanHalfFov * aspect;
|
const float tanfovx = tanHalfFov * aspect;
|
||||||
|
|
||||||
|
const PointType globalLightDir = PointType(-3000.0f, 0.0f, 0.0f).normalized();
|
||||||
|
const float fogStart = 1000.0f;
|
||||||
|
const float fogEnd = 4000.0f;
|
||||||
|
const float minVisibility = 0.2f;
|
||||||
|
|
||||||
#pragma omp parallel for schedule(dynamic) collapse(2)
|
#pragma omp parallel for schedule(dynamic) collapse(2)
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
@@ -1283,19 +1286,28 @@ public:
|
|||||||
if (hit != nullptr) {
|
if (hit != nullptr) {
|
||||||
auto obj = hit;
|
auto obj = hit;
|
||||||
|
|
||||||
|
float t = 0.0f;
|
||||||
|
PointType normal, hitPoint;
|
||||||
|
|
||||||
|
rayCubeIntersect(ray, obj.get(), t, normal, hitPoint);
|
||||||
color = obj->color;
|
color = obj->color;
|
||||||
|
|
||||||
if (obj->light) {
|
if (obj->light) {
|
||||||
color = color * obj->emittance;
|
color = color * obj->emittance;
|
||||||
|
} else {
|
||||||
|
float diffuse = std::max(0.0f, normal.dot(globalLightDir));
|
||||||
|
float ambient = 0.35f;
|
||||||
|
float intensity = std::min(1.0f, ambient + diffuse * 0.65f);
|
||||||
|
color = color * intensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
PointType normal = -rayDir;
|
float fogFactor = std::clamp((fogEnd - t) / (fogEnd - fogStart), minVisibility, 1.0f);
|
||||||
|
|
||||||
// Simple directional lighting
|
color = color * fogFactor + backgroundColor_ * (1.0f - fogFactor);
|
||||||
float lightDot = std::max(0.2f, normal.dot(-rayDir));
|
|
||||||
color = color * lightDot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color = color.cwiseMax(0.0f).cwiseMin(1.0f);
|
||||||
|
|
||||||
colorBuffer[idx ] = color[0];
|
colorBuffer[idx ] = color[0];
|
||||||
colorBuffer[idx + 1] = color[1];
|
colorBuffer[idx + 1] = color[1];
|
||||||
colorBuffer[idx + 2] = color[2];
|
colorBuffer[idx + 2] = color[2];
|
||||||
|
|||||||
Reference in New Issue
Block a user