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

Commit

Permalink
???
Browse files Browse the repository at this point in the history
  • Loading branch information
椎名深雪 committed Dec 26, 2019
1 parent 0f8370b commit a4c8fd8
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if(MSVC)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target x86_64-pc-windows-gnu -femulated-tls ")
set(CXX_FS_LIBS stdc++fs)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
set(CXX_FS_LIBS)
ENDIF()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
Expand Down
Binary file added data/breakfast_room/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/breakfast_room/out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion data/breakfast_room/scene.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"integrator": {
"type": "PathTracer",
"props": {
"spp": 1024,
"spp": 32,
"occludeDistance": 2,
"minDepth": 3,
"maxDepth": 7
}
Expand Down
9 changes: 9 additions & 0 deletions include/miyuki.renderer/accelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <miyuki.renderer/shape.h>


namespace miyuki::core {
class Scene;

Expand All @@ -35,6 +36,14 @@ namespace miyuki::core {
virtual void build(Scene &scene) = 0;

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

virtual bool4 intersect4(const Ray4 &ray, Intersection4 &isct) {
MIYUKI_NOT_IMPLEMENTED();
}

virtual bool8 intersect8(const Ray8 &ray, Intersection8 &isct) {
MIYUKI_NOT_IMPLEMENTED();
}
};

}
Expand Down
28 changes: 27 additions & 1 deletion include/miyuki.renderer/ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <miyuki.foundation/defs.h>
#include <miyuki.foundation/math.hpp>
#include <miyuki.foundation/vectorize.hpp>

namespace miyuki::core {
struct Ray {
Expand All @@ -50,7 +51,7 @@ namespace miyuki::core {

struct Intersection {
const MeshTriangle *shape = nullptr;
const Material * material = nullptr;
const Material *material = nullptr;
float distance = MaxFloat;
Vec3f wo;
Point3f p;
Expand Down Expand Up @@ -84,5 +85,30 @@ namespace miyuki::core {
return Ray(this->p, (p - this->p), RayBias, 1);
}
};

MYK_VEC_STRUCT_BEGIN(Ray)
MYK_VEC_MEMBER(tMin)
MYK_VEC_MEMBER(tMax)
MYK_VEC_MEMBER(o)
MYK_VEC_MEMBER(d)
MYK_VEC_STRUCT_END

using Ray4 = TRay<4>;
using Ray8 = TRay<8>;

MYK_VEC_STRUCT_BEGIN(Intersection)
MYK_VEC_MEMBER(shape)
MYK_VEC_MEMBER(material)
MYK_VEC_MEMBER(distance)
MYK_VEC_MEMBER(wo)
MYK_VEC_MEMBER(p)
MYK_VEC_MEMBER(Ns)
MYK_VEC_MEMBER(Ng)
MYK_VEC_MEMBER(uv)
MYK_VEC_MEMBER(localFrame)
MYK_VEC_STRUCT_END

using Intersection4 = TIntersection<4>;
using Intersection8 = TIntersection<8>;
}
#endif //MIYUKIRENDERER_RAY_H
39 changes: 28 additions & 11 deletions src/core/accelerators/embree-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace miyuki::core {
RTCScene rtcScene = nullptr;
const Scene *scene;

public:
public:
Impl() {
device = rtcNewDevice(nullptr);
if (rtcGetDeviceError(device) != RTC_ERROR_NONE) {
Expand All @@ -45,7 +45,9 @@ namespace miyuki::core {
QUERY_PROP(RTC_DEVICE_PROPERTY_NATIVE_RAY8_SUPPORTED);
QUERY_PROP(RTC_DEVICE_PROPERTY_NATIVE_RAY16_SUPPORTED);
}

~Impl() { rtcReleaseDevice(device); }

void build(const Scene &scene) {
if (rtcScene != nullptr) {
rtcReleaseScene(rtcScene);
Expand All @@ -55,13 +57,16 @@ namespace miyuki::core {
int id = 0;
for (const auto &mesh : scene.meshes) {
auto geometry = rtcNewGeometry(device, RTC_GEOMETRY_TYPE_TRIANGLE);
auto vertices = (Float *)rtcSetNewGeometryBuffer(geometry, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3,
sizeof(Float) * 3, mesh->_vertex_data.position.size());
auto triangles = (uint32_t *)rtcSetNewGeometryBuffer(
geometry, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(uint32_t) * 3, mesh->triangles.size());
auto vertices = (Float *) rtcSetNewGeometryBuffer(geometry, RTC_BUFFER_TYPE_VERTEX, 0,
RTC_FORMAT_FLOAT3,
sizeof(Float) * 3,
mesh->_vertex_data.position.size());
auto triangles = (uint32_t *) rtcSetNewGeometryBuffer(
geometry, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(uint32_t) * 3,
mesh->triangles.size());
for (size_t i = 0; i < mesh->triangles.size(); i++) {
for (size_t j = 0; j < 3; j++) {
triangles[3 * i + j] =mesh->triangles[i].indices.position[j];
triangles[3 * i + j] = mesh->triangles[i].indices.position[j];
}
}
for (size_t i = 0; i < mesh->_vertex_data.position.size(); i++) {
Expand All @@ -75,6 +80,7 @@ namespace miyuki::core {
}
rtcCommitScene(rtcScene);
}

static inline RTCRay toRTCRay(const Ray &_ray) {
RTCRay ray;
auto _o = _ray.o;
Expand All @@ -89,6 +95,7 @@ namespace miyuki::core {
ray.flags = 0;
return ray;
}

bool intersect(const Ray &ray, Intersection &isct) {
RTCRayHit rayHit;
rayHit.ray = toRTCRay(ray);
Expand All @@ -110,20 +117,30 @@ namespace miyuki::core {
return true;
}
};

EmbreeAccelerator::EmbreeAccelerator() : impl(new Impl()) {}

void EmbreeAccelerator::build(Scene &scene) { impl->build(scene); }

bool EmbreeAccelerator::intersect(const Ray &ray, Intersection &isct) { return impl->intersect(ray, isct); }

EmbreeAccelerator::~EmbreeAccelerator() { delete impl; }

bool4 EmbreeAccelerator::intersect4(const Ray4 &ray, Intersection4 &isct) {
return Accelerator::intersect4(ray, isct);
}

bool8 EmbreeAccelerator::intersect8(const Ray8 &ray, Intersection8 &isct) {
return Accelerator::intersect8(ray, isct);
}

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

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

#endif
}
6 changes: 5 additions & 1 deletion src/core/accelerators/embree-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ namespace miyuki::core {

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

~EmbreeAccelerator();
bool4 intersect4(const Ray4 &ray, Intersection4 &isct) override;

bool8 intersect8(const Ray8 &ray, Intersection8 &isct) override;

~EmbreeAccelerator();

};

Expand Down
1 change: 1 addition & 0 deletions src/core/shaders/expr-shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <PerlinNoise.hpp>
#include <memory>
#include <miyuki.foundation/imageloader.h>
#include <sstream>

static const siv::PerlinNoise perlin(0);

Expand Down
2 changes: 1 addition & 1 deletion src/mesh-importer/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char **argv) {

auto outFile = fs::path(argv[1]).stem().string().append(".mesh");
result.mesh->writeToFile(outFile);
graph.shapes.emplace_back(result.mesh);
graph.shapes.push_back(result.mesh);
std::ofstream out(sceneFile);
out << serialize::toJson(*ctx, graph).dump(2) << std::endl;
}
Expand Down

0 comments on commit a4c8fd8

Please sign in to comment.