Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

Commit

Permalink
rewrite accel
Browse files Browse the repository at this point in the history
  • Loading branch information
椎名深雪 committed Nov 5, 2019
1 parent 5509699 commit 19d10d6
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 454 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

link_libraries(stdc++)
find_package(Python3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)

Expand Down
4 changes: 3 additions & 1 deletion src/api/accelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
namespace miyuki::core {
class Scene;

class Accelerator {
class Accelerator : public Entity{
public:
virtual void build(Scene &scene) = 0;

virtual bool intersect(const Ray &ray, Intersection &isct) = 0;
};

}
Expand Down
44 changes: 4 additions & 40 deletions src/api/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ namespace miyuki::core {
};


class Mesh final : public Shape {
class Mesh final : public Entity {
bool _loaded = false;
public:
std::shared_ptr<Accelerator> accelerator;
std::vector<MeshTriangle> triangles;
VertexData _vertex_data;
std::vector<Point3i> _indices;
Expand All @@ -161,14 +160,6 @@ namespace miyuki::core {

MYK_AUTO_INIT(filename, materials)

bool intersect(const Ray &ray, Intersection &isct) const override {
return accelerator->intersect(ray, isct);
}

[[nodiscard]] Bounds3f getBoundingBox() const override {
return accelerator->getBoundingBox();
}

// TODO: set import directory
bool importFromFile(const std::string &filename);

Expand All @@ -177,7 +168,7 @@ namespace miyuki::core {

void fromBinary(const std::vector<char> &buffer);

void foreach(const std::function<void(MeshTriangle *)> &func) override;
void foreach(const std::function<void(MeshTriangle *)> &func) ;

bool loadFromFile(const std::string &filename);

Expand All @@ -189,7 +180,7 @@ namespace miyuki::core {
};


class MeshInstance final : public Shape {
class MeshInstance final : public Entity {
public:
MYK_DECL_CLASS(MeshInstance, "MeshInstance", interface = "Shape")

Expand All @@ -198,34 +189,7 @@ namespace miyuki::core {

MYK_AUTO_SER(transform, mesh)

bool intersect(const Ray &ray, Intersection &isct) const override {
auto o = invTransform(ray.o);
auto p = invTransform(ray.o + ray.d);
Float k = (p - o).length();
Ray transformedRay(o, (p - o).normalized(), k * ray.tMin, k * ray.tMax);
Intersection localIsct;
if (mesh->intersect(transformedRay, localIsct)) {
Float t = localIsct.distance / k;
if (t < isct.distance) {
isct = localIsct;
isct.distance = t;
isct.Ng = transform(isct.Ng);
isct.Ns = transform(isct.Ns);
isct.shape = localIsct.shape;
return true;
}
}
return false;
}

[[nodiscard]] Bounds3f getBoundingBox() const override {
Bounds3f box;
box = box.unionOf(transform(mesh->getBoundingBox().pMin));
box = box.unionOf(transform(mesh->getBoundingBox().pMax));
return box;
}

void foreach(const std::function<void(MeshTriangle *)> &func) override {
void foreach(const std::function<void(MeshTriangle *)> &func) {
mesh->foreach(func);
}

Expand Down
7 changes: 4 additions & 3 deletions src/api/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
namespace miyuki::core {

class Scene {
std::shared_ptr<TopLevelBVHAccelerator> accelerator;
std::atomic<size_t> rayCounter = 0;
std::shared_ptr<Accelerator> accelerator;
std::atomic<size_t> rayCounter = 0;
public:
std::vector<std::shared_ptr<Light>> lights;
std::vector<std::shared_ptr<Shape>> shapes;
std::vector<std::shared_ptr<Mesh>> meshes;
std::vector<std::shared_ptr<MeshInstance>> instances;

bool intersect(const Ray &ray, Intersection &isct);

Expand Down
43 changes: 12 additions & 31 deletions src/core/accelerators/embree-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,30 @@

#include "embree-backend.h"
#include <embree3/rtcore.h>
#ifdef MYK_USE_EMBREE

namespace miyuki::core{

void EmbreeAccelerator::build(const Mesh *mesh) {
#ifdef MYK_USE_EMBREE

namespace miyuki::core {
void miyuki::core::EmbreeAccelerator::build(miyuki::core::Scene &scene) {
MIYUKI_NOT_IMPLEMENTED();
}

bool EmbreeAccelerator::intersect(const Ray &ray, Intersection &isct) const {
bool miyuki::core::EmbreeAccelerator::intersect(const miyuki::core::Ray &ray, miyuki::core::Intersection &isct) {
MIYUKI_NOT_IMPLEMENTED();
return false;
}

Bounds3f EmbreeAccelerator::getBoundingBox() const {
return miyuki::Bounds3f();
}

void EmbreeTopLevelAccelerator::build(const std::vector<Shape *> &vector) {

}

bool EmbreeTopLevelAccelerator::intersect(const Ray &ray, Intersection &isct) const {
return false;
}

Bounds3f EmbreeTopLevelAccelerator::getBoundingBox() const {
return miyuki::Bounds3f();
}
}
#else
namespace miyuki::core{

void EmbreeAccelerator::build(const Mesh *mesh) {
void miyuki::core::EmbreeAccelerator::build(miyuki::core::Scene &scene) {
MIYUKI_NOT_IMPLEMENTED();
}

bool EmbreeAccelerator::intersect(const Ray &ray, Intersection &isct) const {
bool miyuki::core::EmbreeAccelerator::intersect(const miyuki::core::Ray &ray, miyuki::core::Intersection &isct) {
MIYUKI_NOT_IMPLEMENTED();
return false;
}
return false;

Bounds3f EmbreeAccelerator::getBoundingBox() const {
MIYUKI_NOT_IMPLEMENTED();
return miyuki::Bounds3f();
}
}
#endif

#endif
}
14 changes: 2 additions & 12 deletions src/core/accelerators/embree-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,11 @@ namespace miyuki::core {
public:
MYK_DECL_CLASS(EmbreeAccelerator, "EmbreeAccelerator", interface = "Accelerator")

void build(const Mesh *mesh) override;
void build(Scene &scene) override;

bool intersect(const Ray &ray, Intersection &isct) const override;
bool intersect(const Ray &ray, Intersection &isct) override;

Bounds3f getBoundingBox() const override;
};
class EmbreeTopLevelAccelerator final : public TopLevelAccelerator{
public:
MYK_DECL_CLASS(EmbreeTopLevelAccelerator, "EmbreeTopLevelAccelerator", interface = "TopLevelAccelerator")

void build(const std::vector<Shape *> &vector) override;

bool intersect(const Ray &ray, Intersection &isct) const override;

Bounds3f getBoundingBox() const override;
};
}
#endif //MIYUKIRENDERER_EMBREE_BACKEND_H
Loading

0 comments on commit 19d10d6

Please sign in to comment.