I dont know

This commit is contained in:
Gamemaker1998
2025-01-24 23:32:16 +01:00
parent 2c5c624378
commit 9370e4125a
4 changed files with 8 additions and 14 deletions
-4
View File
@@ -46,13 +46,9 @@ struct AABB
} }
bool intersects(Ray ray, float tmin, float tmax) bool intersects(Ray ray, float tmin, float tmax)
{ {
std::cout << "Hello1" << std::endl;
glm::vec3 invD = 1.0f / ray.direction; glm::vec3 invD = 1.0f / ray.direction;
std::cout << "Hello2: " << min.x << " " << min.y << " " << min.z << " " << max.x << " " << max.y << " " << max.z << " " << std::endl;
glm::vec3 t0s = glm::vec3(min - ray.origin) * invD; glm::vec3 t0s = glm::vec3(min - ray.origin) * invD;
std::cout << "Hello3" << std::endl;
glm::vec3 t1s = glm::vec3(max - ray.origin) * invD; glm::vec3 t1s = glm::vec3(max - ray.origin) * invD;
std::cout << "Hello4" << std::endl;
glm::vec3 tsmaller = glm::min(t0s, t1s); glm::vec3 tsmaller = glm::min(t0s, t1s);
glm::vec3 tbigger = glm::max(t0s, t1s); glm::vec3 tbigger = glm::max(t0s, t1s);
+4 -4
View File
@@ -14,14 +14,14 @@ void BVH::addModel(PModel model, glm::mat4 transform)
void BVH::addModels(std::vector<PModel> _models, glm::mat4 transform) void BVH::addModels(std::vector<PModel> _models, glm::mat4 transform)
{ {
for (int i = 0; i < _models.size(); ++i) for (auto & _model : _models)
{ {
_models[i]->boundingBox.transform(transform); _model->boundingBox.transform(transform);
for (auto& point : _models[i]->positions) for (auto& point : _model->positions)
{ {
point = glm::vec3(transform * glm::vec4(point, 1)); point = glm::vec3(transform * glm::vec4(point, 1));
} }
models.push_back(std::move(_models[i])); models.push_back(std::move(_model));
} }
} }
+1 -3
View File
@@ -46,12 +46,10 @@ void Scene::render(Camera cam, RenderParameter params)
{ {
Ray r = Ray{ Ray r = Ray{
.origin = glm::vec3(0.0f), .origin = glm::vec3(0.0f),
.direction = glm::vec3(0.0f, 0.0f, 1.0f) .direction = glm::normalize(glm::vec3((float)std::rand() / RAND_MAX, (float)std::rand() / RAND_MAX, (float)std::rand() / RAND_MAX))
}; };
bvh.traceRay(r); bvh.traceRay(r);
std::cout << "HELLO" << std::endl;
accumulator[w + h * params.width] += accumulator[w + h * params.width] +=
glm::vec3(w / float(params.width * params.numSamples), h / float(params.height * params.numSamples), 0); glm::vec3(w / float(params.width * params.numSamples), h / float(params.height * params.numSamples), 0);
} }
+3 -3
View File
@@ -7,9 +7,9 @@ std::optional<IntersectionInfo> Model::intersect(const Ray ray)
for(size_t posIndex=0, eIndex=0, normalIndex=0; posIndex <indices.size(); posIndex+=3, eIndex+=2, normalIndex++) for(size_t posIndex=0, eIndex=0, normalIndex=0; posIndex <indices.size(); posIndex+=3, eIndex+=2, normalIndex++)
{ {
const auto p0 = positions[posIndex]; const auto p0 = positions[indices[posIndex]];
const auto p1 = positions[posIndex +1]; const auto p1 = positions[indices[posIndex+1]];
const auto p2 = positions[posIndex +2]; const auto p2 = positions[indices[posIndex+2]];
const auto e0 = es[eIndex]; const auto e0 = es[eIndex];
const auto e1 = es[eIndex +1]; const auto e1 = es[eIndex +1];