diff --git a/.gitignore b/.gitignore index ba963a8..b7bb668 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ include/ # Imported mesh files *.mesh +external/embree3 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e284d38..866ed7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,20 @@ cmake_minimum_required(VERSION 3.1) project(MiyukiRenderer) set(CMAKE_CXX_STANDARD 17) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + IF(WIN32) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target x86_64-pc-windows-gnu -femulated-tls ") + ENDIF() +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") +endif() + find_package(Python3 REQUIRED) find_package(PythonLibs 3 REQUIRED) - include_directories(${PYTHON_INCLUDE_DIRS}) include_directories(src) -add_subdirectory(external/pybind11) add_subdirectory(external/fmt) include_directories(external/pybind11/include) include_directories(external/linalg) @@ -35,6 +41,8 @@ file(GLOB libcoreSource src/core/*.cpp external/lodepng/lodepng.cpp ) +#include(ExternalProject) +#include(${PROJECT_SOURCE_DIR}/cmake/cmake-embree) add_library(core ${MiyukiAPI} ${libcoreSource}) target_link_libraries(core fmt) add_executable(myk-cli src/standalone-renderer/main.cpp ${MiyukiAPI}) diff --git a/cmake/cmake-embree b/cmake/cmake-embree new file mode 100644 index 0000000..85cec9d --- /dev/null +++ b/cmake/cmake-embree @@ -0,0 +1,78 @@ +# I'm not famiilar with cmake +# Largely based on https://github.com/AirGuanZ/Atrc/blob/master/cmake/cmake-embree +IF(MSVC) + SET(EMBREE_IGNORE_CMAKE_CXX_FLAGS "-DEMBREE_IGNORE_CMAKE_CXX_FLAGS=ON") +ELSE() + SET(EMBREE_IGNORE_CMAKE_CXX_FLAGS "-DEMBREE_IGNORE_CMAKE_CXX_FLAGS=OFF") +ENDIF() + +if(NOT DEFINED EMBREE_MAX_ISA) + set(EMBREE_MAX_ISA AVX2) +endif() + +set(Embree3_VERSION "3.6.1") + + +ExternalProject_Add( + Embree3 + PREFIX "${PROJECT_SOURCE_DIR}/external/embree3" + URL "https://github.com/embree/embree/archive/v${Embree3_VERSION}.tar.gz" + URL_MD5 d6e043321df048a427eff337eba04cf1 + CMAKE_ARGS + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" + "-DEMBREE_TUTORIALS=OFF" + "-DEMBREE_FILTER_FUNCTION=OFF" + "-DEMBREE_RAY_PACKETS=OFF" + "-DEMBREE_TASKING_SYSTEM=INTERNAL" + "-DEMBREE_GEOMETRY_QUAD=OFF" + "-DEMBREE_GEOMETRY_CURVE=OFF" + "-DEMBREE_GEOMETRY_SUBDIVISION=OFF" + "-DEMBREE_GEOMETRY_INSTANCE=OFF" + "-DEMBREE_GEOMETRY_USER=OFF" + "-DEMBREE_GEOMETRY_POINT=OFF" + "-DEMBREE_ISPC_SUPPORT=OFF" + "-DEMBREE_STATIC_LIB=ON" + "-DEMBREE_MAX_ISA=${EMBREE_MAX_ISA}" + "${EMBREE_IGNORE_CMAKE_CXX_FLAGS}" + "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" + INSTALL_COMMAND "" +) + +set(EMBREE_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/external/embree3//src/Embree3/include/) + +IF(WIN32) + SET(EMBREE_LIBRARIES + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/embree3.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/embree_sse42.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/embree_avx.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/embree_avx2.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/lexers.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/math.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/simd.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/tasking.lib" + optimized "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Release/sys.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/embree3.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/embree_sse42.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/embree_avx.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/embree_avx2.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/lexers.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/math.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/simd.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/tasking.lib" + debug "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/Debug/sys.lib" + ) +ELSE() + SET(EMBREE_LIBRARIES + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libembree3.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libembree_sse42.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libembree_avx.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libembree_avx2.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/liblexers.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libmath.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libsimd.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libtasking.a" + "${PROJECT_SOURCE_DIR}/lib/embree3/src/Embree3-build/libsys.a" + ) +ENDIF() \ No newline at end of file diff --git a/data/fireplace_room/out.png b/data/fireplace_room/out.png index f2ad26f..e7f8949 100644 Binary files a/data/fireplace_room/out.png and b/data/fireplace_room/out.png differ diff --git a/external/embree3/src/Embree3-build/CMakeFiles/3.15.3/CMakeDetermineCompilerABI_C.bin b/external/embree3/src/Embree3-build/CMakeFiles/3.15.3/CMakeDetermineCompilerABI_C.bin new file mode 100644 index 0000000..16b4f86 Binary files /dev/null and b/external/embree3/src/Embree3-build/CMakeFiles/3.15.3/CMakeDetermineCompilerABI_C.bin differ diff --git a/external/embree3/src/Embree3-build/CMakeFiles/3.15.3/CMakeDetermineCompilerABI_CXX.bin b/external/embree3/src/Embree3-build/CMakeFiles/3.15.3/CMakeDetermineCompilerABI_CXX.bin new file mode 100644 index 0000000..a0cc434 Binary files /dev/null and b/external/embree3/src/Embree3-build/CMakeFiles/3.15.3/CMakeDetermineCompilerABI_CXX.bin differ diff --git a/external/embree3/src/Embree3-build/CMakeFiles/CMakeError.log b/external/embree3/src/Embree3-build/CMakeFiles/CMakeError.log new file mode 100644 index 0000000..2bd05ab --- /dev/null +++ b/external/embree3/src/Embree3-build/CMakeFiles/CMakeError.log @@ -0,0 +1,70 @@ +Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. +Compiler: C:/msys64/mingw64/bin/clang++.exe +Build flags: ;--verbose;-target;x86_64-pc-windows-gnu;-stdlib=libc++;-pthread +Id flags: + +The output was: +1 +clang version 9.0.0 (https://github.com/msys2/MINGW-packages.git fdafa4d8c4022588676c8ec0985dafaf834258ae) +Target: x86_64-pc-windows-gnu +Thread model: posix +InstalledDir: C:/msys64/mingw64/bin + "C:\\msys64\\mingw64\\bin\\clang++.exe" -cc1 -triple x86_64-pc-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CMakeCXXCompilerId.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -v -resource-dir "C:\\msys64\\mingw64\\lib\\clang\\9.0.0" -internal-isystem "C:/msys64/mingw64\\x86_64-w64-mingw32\\include\\c++\\v1" -internal-isystem "C:/msys64/mingw64\\include\\c++\\v1" -internal-isystem "C:\\msys64\\mingw64\\lib\\clang\\9.0.0\\include" -internal-isystem "C:/msys64/mingw64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:/msys64/mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "C:/msys64/mingw64\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Users\\xiaoc\\source\\repos\\shiinamiyuki\\miyuki-renderer\\external\\embree3\\src\\Embree3-build\\CMakeFiles\\3.15.3\\CompilerIdCXX" -ferror-limit 19 -fmessage-length 0 -pthread -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fseh-exceptions -fdiagnostics-show-option -faddrsig -o "C:\\Users\\xiaoc\\AppData\\Local\\Temp\\CMakeCXXCompilerId-d050cd.o" -x c++ CMakeCXXCompilerId.cpp +clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-w64-windows-gnu +ignoring nonexistent directory "C:/msys64/mingw64\x86_64-w64-mingw32\include\c++\v1" +ignoring nonexistent directory "C:/msys64/mingw64\include\c++\v1" +ignoring nonexistent directory "C:/msys64/mingw64\x86_64-w64-mingw32/sys-root/mingw/include" +#include "..." search starts here: +#include <...> search starts here: + C:\msys64\mingw64\lib\clang\9.0.0\include + C:/msys64/mingw64\x86_64-w64-mingw32\include + C:/msys64/mingw64\include +End of search list. + "C:/msys64/mingw64/bin\\ld" -m i386pep -Bdynamic -o a.exe "C:/msys64/mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "C:/msys64/mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\crtbegin.o" "-LC:/msys64/mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0" "-LC:/msys64/mingw64\\x86_64-w64-mingw32\\lib" "-LC:/msys64/mingw64\\lib" "-LC:/msys64/mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" "C:\\Users\\xiaoc\\AppData\\Local\\Temp\\CMakeCXXCompilerId-d050cd.o" -lc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt "C:/msys64/mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\crtend.o" +C:/msys64/mingw64/bin\ld: cannot find -lc++ +clang++: error: linker command failed with exit code 1 (use -v to see invocation) + + +Determining if the CXX compiler works failed with the following output: +Change Dir: C:/Users/xiaoc/source/repos/shiinamiyuki/miyuki-renderer/external/embree3/src/Embree3-build/CMakeFiles/CMakeTmp + +Run Build Command(s):C:/msys64/mingw64/bin/mingw32-make.exe cmTC_ac1bb/fast && mingw32-make.exe[4]: Entering directory 'C:/Users/xiaoc/source/repos/shiinamiyuki/miyuki-renderer/external/embree3/src/Embree3-build/CMakeFiles/CMakeTmp' +C:/msys64/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_ac1bb.dir\build.make CMakeFiles/cmTC_ac1bb.dir/build +mingw32-make.exe[5]: Entering directory 'C:/Users/xiaoc/source/repos/shiinamiyuki/miyuki-renderer/external/embree3/src/Embree3-build/CMakeFiles/CMakeTmp' +Building CXX object CMakeFiles/cmTC_ac1bb.dir/testCXXCompiler.cxx.obj +C:\msys64\mingw64\bin\clang++.exe --verbose -target x86_64-pc-windows-gnu -stdlib=libc++ -pthread -o CMakeFiles\cmTC_ac1bb.dir\testCXXCompiler.cxx.obj -c C:\Users\xiaoc\source\repos\shiinamiyuki\miyuki-renderer\external\embree3\src\Embree3-build\CMakeFiles\CMakeTmp\testCXXCompiler.cxx +clang version 9.0.0 (https://github.com/msys2/MINGW-packages.git fdafa4d8c4022588676c8ec0985dafaf834258ae) +Target: x86_64-pc-windows-gnu +Thread model: posix +InstalledDir: C:\msys64\mingw64\bin + "C:\\msys64\\mingw64\\bin\\clang++.exe" -cc1 -triple x86_64-pc-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name testCXXCompiler.cxx -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file "C:\\Users\\xiaoc\\source\\repos\\shiinamiyuki\\miyuki-renderer\\external\\embree3\\src\\Embree3-build\\CMakeFiles\\CMakeTmp\\CMakeFiles\\cmTC_ac1bb.dir\\testCXXCompiler.cxx.gcno" -resource-dir "C:\\msys64\\mingw64\\lib\\clang\\9.0.0" -internal-isystem "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\v1" -internal-isystem "C:\\msys64\\mingw64\\include\\c++\\v1" -internal-isystem "C:\\msys64\\mingw64\\lib\\clang\\9.0.0\\include" -internal-isystem "C:\\msys64\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\msys64\\mingw64\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Users\\xiaoc\\source\\repos\\shiinamiyuki\\miyuki-renderer\\external\\embree3\\src\\Embree3-build\\CMakeFiles\\CMakeTmp" -ferror-limit 19 -fmessage-length 0 -pthread -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fseh-exceptions -fdiagnostics-show-option -faddrsig -o "CMakeFiles\\cmTC_ac1bb.dir\\testCXXCompiler.cxx.obj" -x c++ "C:\\Users\\xiaoc\\source\\repos\\shiinamiyuki\\miyuki-renderer\\external\\embree3\\src\\Embree3-build\\CMakeFiles\\CMakeTmp\\testCXXCompiler.cxx" +clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-w64-windows-gnu +ignoring nonexistent directory "C:\msys64\mingw64\x86_64-w64-mingw32\include\c++\v1" +ignoring nonexistent directory "C:\msys64\mingw64\include\c++\v1" +ignoring nonexistent directory "C:\msys64\mingw64\x86_64-w64-mingw32/sys-root/mingw/include" +#include "..." search starts here: +#include <...> search starts here: + C:\msys64\mingw64\lib\clang\9.0.0\include + C:\msys64\mingw64\x86_64-w64-mingw32\include + C:\msys64\mingw64\include +End of search list. +Linking CXX executable cmTC_ac1bb.exe +"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_ac1bb.dir\link.txt --verbose=1 +"C:\Program Files\JetBrains\CLion 2019.2.4\bin\cmake\win\bin\cmake.exe" -E remove -f CMakeFiles\cmTC_ac1bb.dir/objects.a +C:\msys64\mingw64\bin\ar.exe cr CMakeFiles\cmTC_ac1bb.dir/objects.a @CMakeFiles\cmTC_ac1bb.dir\objects1.rsp +C:\msys64\mingw64\bin\clang++.exe --verbose -target x86_64-pc-windows-gnu -stdlib=libc++ -pthread -Wl,--whole-archive CMakeFiles\cmTC_ac1bb.dir/objects.a -Wl,--no-whole-archive -o cmTC_ac1bb.exe -Wl,--out-implib,libcmTC_ac1bb.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\cmTC_ac1bb.dir\linklibs.rsp +clang version 9.0.0 (https://github.com/msys2/MINGW-packages.git fdafa4d8c4022588676c8ec0985dafaf834258ae) +Target: x86_64-pc-windows-gnu +Thread model: posix +InstalledDir: C:\msys64\mingw64\bin +clang++: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument] + "C:\\msys64\\mingw64\\bin\\ld" -m i386pep -Bdynamic -o cmTC_ac1bb.exe "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\crtbegin.o" "-LC:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0" "-LC:\\msys64\\mingw64\\x86_64-w64-mingw32\\lib" "-LC:\\msys64\\mingw64\\lib" "-LC:\\msys64\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" --whole-archive "CMakeFiles\\cmTC_ac1bb.dir/objects.a" --no-whole-archive --out-implib libcmTC_ac1bb.dll.a --major-image-version 0 --minor-image-version 0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -lc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\crtend.o" +C:\msys64\mingw64\bin\ld: cannot find -lc++ +clang++: error: linker command failed with exit code 1 (use -v to see invocation) +mingw32-make.exe[5]: *** [CMakeFiles\cmTC_ac1bb.dir\build.make:88: cmTC_ac1bb.exe] Error 1 +mingw32-make.exe[5]: Leaving directory 'C:/Users/xiaoc/source/repos/shiinamiyuki/miyuki-renderer/external/embree3/src/Embree3-build/CMakeFiles/CMakeTmp' +mingw32-make.exe[4]: *** [Makefile:120: cmTC_ac1bb/fast] Error 2 +mingw32-make.exe[4]: Leaving directory 'C:/Users/xiaoc/source/repos/shiinamiyuki/miyuki-renderer/external/embree3/src/Embree3-build/CMakeFiles/CMakeTmp' + + + diff --git a/external/embree3/src/Embree3-build/CMakeFiles/Progress/1 b/external/embree3/src/Embree3-build/CMakeFiles/Progress/1 new file mode 100644 index 0000000..7b4d68d --- /dev/null +++ b/external/embree3/src/Embree3-build/CMakeFiles/Progress/1 @@ -0,0 +1 @@ +empty \ No newline at end of file diff --git a/external/embree3/src/Embree3-build/CMakeFiles/Progress/2 b/external/embree3/src/Embree3-build/CMakeFiles/Progress/2 new file mode 100644 index 0000000..7b4d68d --- /dev/null +++ b/external/embree3/src/Embree3-build/CMakeFiles/Progress/2 @@ -0,0 +1 @@ +empty \ No newline at end of file diff --git a/external/embree3/src/Embree3-stamp/Embree3-download b/external/embree3/src/Embree3-stamp/Embree3-download new file mode 100644 index 0000000..e69de29 diff --git a/external/embree3/src/Embree3-stamp/Embree3-mkdir b/external/embree3/src/Embree3-stamp/Embree3-mkdir new file mode 100644 index 0000000..e69de29 diff --git a/external/embree3/src/Embree3-stamp/Embree3-patch b/external/embree3/src/Embree3-stamp/Embree3-patch new file mode 100644 index 0000000..e69de29 diff --git a/external/embree3/src/Embree3-stamp/Embree3-update b/external/embree3/src/Embree3-stamp/Embree3-update new file mode 100644 index 0000000..e69de29 diff --git a/external/embree3/src/v3.6.1.tar.gz b/external/embree3/src/v3.6.1.tar.gz new file mode 100644 index 0000000..401232c Binary files /dev/null and b/external/embree3/src/v3.6.1.tar.gz differ diff --git a/src/api/defs.h b/src/api/defs.h index 0889e0f..2dc911e 100644 --- a/src/api/defs.h +++ b/src/api/defs.h @@ -76,7 +76,7 @@ namespace miyuki{ #define MIYUKI_ASSERT(expr) _assert(expr, fmt::format("{} failed at {}:{}",#expr, __FILE__,__LINE__)) -#ifdef _MSV_VER +#ifdef _MSC_VER #define MYK_PUBLIC_API __declspec(dllexport) #elif defined(__GNUC__) || defined(__MINGW32__) diff --git a/src/api/mesh.h b/src/api/mesh.h index 4638953..02c3e7c 100644 --- a/src/api/mesh.h +++ b/src/api/mesh.h @@ -89,7 +89,8 @@ namespace miyuki::core { if (t < isct.distance) { isct.distance = t; isct.Ng = Ng; - isct.Ns = lerp3(vertex(0), vertex(1), vertex(2), u, v).normalized(); + isct.uv = Point2f(u, v); + isct.Ns = normalAt(isct.uv); isct.shape = this; return true; } @@ -133,7 +134,7 @@ namespace miyuki::core { } [[nodiscard]] Normal3f normalAt(const Point2f &uv) const { - return lerp3(normal(0), normal(1), normal(2), uv[0], uv[1]); + return lerp3(normal(0), normal(1), normal(2), uv[0], uv[1]).normalized(); } [[nodiscard]] Point2f texCoordAt(const Point2f &uv) const { @@ -160,11 +161,11 @@ namespace miyuki::core { MYK_AUTO_INIT(filename, materials) - bool intersect(const Ray &ray, Intersection &isct) const { + bool intersect(const Ray &ray, Intersection &isct) const override { return accelerator->intersect(ray, isct); } - [[nodiscard]] Bounds3f getBoundingBox() const { + [[nodiscard]] Bounds3f getBoundingBox() const override { return accelerator->getBoundingBox(); } @@ -197,7 +198,7 @@ namespace miyuki::core { MYK_AUTO_SER(transform, mesh) - bool intersect(const Ray &ray, Intersection &isct) const { + 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(); diff --git a/src/api/profiler.h b/src/api/profiler.h new file mode 100644 index 0000000..b2d04e1 --- /dev/null +++ b/src/api/profiler.h @@ -0,0 +1,45 @@ +// MIT License +// +// Copyright (c) 2019 椎名深雪 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef MIYUKIRENDERER_PROFILER_H +#define MIYUKIRENDERER_PROFILER_H + +#include + + +namespace miyuki { + class Profiler { + std::chrono::high_resolution_clock::time_point start; + public: + Profiler() { + start = std::chrono::high_resolution_clock::now(); + } + + template + std::chrono::duration elapsed() const { + return std::chrono::high_resolution_clock::now() - start; + } + }; +} + + +#endif //MIYUKIRENDERER_PROFILER_H diff --git a/src/api/ray.h b/src/api/ray.h index da8ae84..4ab3a61 100644 --- a/src/api/ray.h +++ b/src/api/ray.h @@ -60,7 +60,7 @@ namespace miyuki::core { } void computeLocalFrame() { - localFrame = CoordinateSystem(Ng); + localFrame = CoordinateSystem(Ns); } [[nodiscard]] Vec3f worldToLocal(const Vec3f &v) const { diff --git a/src/api/scene.h b/src/api/scene.h index bcf88f8..7189860 100644 --- a/src/api/scene.h +++ b/src/api/scene.h @@ -28,17 +28,30 @@ #include #include #include +#include #include + namespace miyuki::core { class Scene { std::shared_ptr accelerator; + std::atomic rayCounter = 0; public: std::vector> lights; std::vector> shapes; - bool intersect(const Ray&ray, Intersection& isct); + + bool intersect(const Ray &ray, Intersection &isct); + void preprocess(); + + size_t getRayCounter() const { + return rayCounter; + } + + void resetRayCounter() { + rayCounter = 0; + } }; } #endif //MIYUKIRENDERER_SCENE_H diff --git a/src/api/serialize.hpp b/src/api/serialize.hpp index 1260105..b720db0 100644 --- a/src/api/serialize.hpp +++ b/src/api/serialize.hpp @@ -309,7 +309,7 @@ namespace cereal { try { ar(CEREAL_NVP_(name, val)); } catch (cereal::Exception &e) { - // + (void)e;// } } } diff --git a/src/api/shape.h b/src/api/shape.h index db304d7..b49b5fd 100644 --- a/src/api/shape.h +++ b/src/api/shape.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace miyuki::core { diff --git a/src/core/export.h b/src/core/export.h index 66f953e..a8ce817 100644 --- a/src/core/export.h +++ b/src/core/export.h @@ -23,8 +23,9 @@ #ifndef MIYUKIRENDERER_EXPORT_H #define MIYUKIRENDERER_EXPORT_H +#include namespace miyuki::core{ - void Initialize(); - void Finalize(); + MYK_PUBLIC_API void Initialize(); + MYK_PUBLIC_API void Finalize(); } #endif //MIYUKIRENDERER_EXPORT_H diff --git a/src/core/integrators/rtao.cpp b/src/core/integrators/rtao.cpp index 6c91ac7..a9e9f6d 100644 --- a/src/core/integrators/rtao.cpp +++ b/src/core/integrators/rtao.cpp @@ -28,11 +28,14 @@ #include #include #include +#include namespace miyuki::core { void RTAO::render(const std::shared_ptr &scene, const std::shared_ptr &camera, const std::shared_ptr &_sampler, Film &film) { + scene->resetRayCounter(); + Profiler profiler; ParallelFor(0, film.height, [=, &film](int64_t j, uint64_t) { auto sampler = _sampler->clone(); for (int i = 0; i < film.width; i++) { @@ -48,7 +51,6 @@ namespace miyuki::core { Intersection isct; if (scene->intersect(sample.ray, isct)) { isct.computeLocalFrame(); - // film.addSample(sample.pFilm, isct.Ng, 1); auto wo = isct.worldToLocal(-sample.ray.d); auto w = CosineHemisphereSampling(sampler->next2D()); if (wo.y * w.y < 0) { @@ -67,5 +69,9 @@ namespace miyuki::core { } } }); + auto duration = profiler.elapsed(); + log::log("Rendering done in {}secs, traced {} rays, {} M rays/sec\n", duration.count(), + scene->getRayCounter(), + scene->getRayCounter() / duration.count() / 1e6f); } } diff --git a/src/core/parallel.cpp b/src/core/parallel.cpp index 0f763c2..7987332 100644 --- a/src/core/parallel.cpp +++ b/src/core/parallel.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace miyuki { class ParallelForContext { diff --git a/src/core/scene.cpp b/src/core/scene.cpp index c1be326..0ebe949 100644 --- a/src/core/scene.cpp +++ b/src/core/scene.cpp @@ -30,7 +30,7 @@ namespace miyuki::core { accelerator = std::make_shared(); auto setLight = [=](MeshTriangle *triangle) { auto mat = triangle->getMaterial(); - if (mat->emission != nullptr) { + if (mat && mat->emission != nullptr) { auto light = std::make_shared(); light->setTriangle(triangle); lights.emplace_back(light); @@ -46,6 +46,7 @@ namespace miyuki::core { } bool Scene::intersect(const miyuki::core::Ray &ray, miyuki::core::Intersection &isct) { + rayCounter++; if (accelerator->intersect(ray, isct)) { isct.p = ray.o + isct.distance * ray.d; return true; diff --git a/src/core/shapes/mesh.cpp b/src/core/shapes/mesh.cpp index 35d5b31..be96b10 100644 --- a/src/core/shapes/mesh.cpp +++ b/src/core/shapes/mesh.cpp @@ -83,8 +83,12 @@ namespace miyuki::core { } _materials.clear(); for (const auto &name : _names) { - auto mat = materials.at(name); - _materials.emplace_back(mat); + if(materials.find(name)!=materials.end()) { + auto mat = materials.at(name); + _materials.emplace_back(mat); + }else{ + _materials.emplace_back(nullptr); + } } accelerator = std::dynamic_pointer_cast(CreateEntity("BVHAccelerator")); accelerator->build(this);