Skip to content

Commit 0f09a57

Browse files
committed
CG raytracer all features except BVH
1 parent 489df1e commit 0f09a57

File tree

704 files changed

+305865
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

704 files changed

+305865
-10
lines changed

.clang-format

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: WebKit
4+
AccessModifierOffset: -4
5+
AlignAfterOpenBracket: DontAlign
6+
AlignConsecutiveMacros: false
7+
AlignConsecutiveAssignments: false
8+
AlignConsecutiveDeclarations: false
9+
AlignEscapedNewlines: Right
10+
AlignOperands: false
11+
AlignTrailingComments: false
12+
AllowAllArgumentsOnNextLine: true
13+
AllowAllConstructorInitializersOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: true
15+
AllowShortBlocksOnASingleLine: Empty
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: All
18+
AllowShortLambdasOnASingleLine: All
19+
AllowShortIfStatementsOnASingleLine: Never
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterDefinitionReturnType: None
22+
AlwaysBreakAfterReturnType: None
23+
AlwaysBreakBeforeMultilineStrings: false
24+
AlwaysBreakTemplateDeclarations: MultiLine
25+
BinPackArguments: true
26+
BinPackParameters: true
27+
BraceWrapping:
28+
AfterCaseLabel: false
29+
AfterClass: false
30+
AfterControlStatement: false
31+
AfterEnum: false
32+
AfterFunction: true
33+
AfterNamespace: false
34+
AfterObjCDeclaration: false
35+
AfterStruct: false
36+
AfterUnion: false
37+
AfterExternBlock: false
38+
BeforeCatch: false
39+
BeforeElse: false
40+
IndentBraces: false
41+
SplitEmptyFunction: true
42+
SplitEmptyRecord: true
43+
SplitEmptyNamespace: true
44+
BreakBeforeBinaryOperators: All
45+
BreakBeforeBraces: WebKit
46+
BreakBeforeInheritanceComma: false
47+
BreakInheritanceList: BeforeColon
48+
BreakBeforeTernaryOperators: true
49+
BreakConstructorInitializersBeforeComma: false
50+
BreakConstructorInitializers: BeforeComma
51+
BreakAfterJavaFieldAnnotations: false
52+
BreakStringLiterals: true
53+
ColumnLimit: 0
54+
CommentPragmas: '^ IWYU pragma:'
55+
CompactNamespaces: false
56+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
57+
ConstructorInitializerIndentWidth: 4
58+
ContinuationIndentWidth: 4
59+
Cpp11BracedListStyle: false
60+
DeriveLineEnding: true
61+
DerivePointerAlignment: false
62+
DisableFormat: false
63+
ExperimentalAutoDetectBinPacking: false
64+
FixNamespaceComments: false
65+
ForEachMacros:
66+
- foreach
67+
- Q_FOREACH
68+
- BOOST_FOREACH
69+
IncludeBlocks: Preserve
70+
IncludeCategories:
71+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
72+
Priority: 2
73+
SortPriority: 0
74+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
75+
Priority: 3
76+
SortPriority: 0
77+
- Regex: '.*'
78+
Priority: 1
79+
SortPriority: 0
80+
IncludeIsMainRegex: '(Test)?$'
81+
IncludeIsMainSourceRegex: ''
82+
IndentCaseLabels: false
83+
IndentGotoLabels: true
84+
IndentPPDirectives: None
85+
IndentWidth: 4
86+
IndentWrappedFunctionNames: false
87+
JavaScriptQuotes: Leave
88+
JavaScriptWrapImports: true
89+
KeepEmptyLinesAtTheStartOfBlocks: true
90+
MacroBlockBegin: ''
91+
MacroBlockEnd: ''
92+
MaxEmptyLinesToKeep: 1
93+
NamespaceIndentation: Inner
94+
ObjCBinPackProtocolList: Auto
95+
ObjCBlockIndentWidth: 4
96+
ObjCSpaceAfterProperty: true
97+
ObjCSpaceBeforeProtocolList: true
98+
PenaltyBreakAssignment: 2
99+
PenaltyBreakBeforeFirstCallParameter: 19
100+
PenaltyBreakComment: 300
101+
PenaltyBreakFirstLessLess: 120
102+
PenaltyBreakString: 1000
103+
PenaltyBreakTemplateDeclaration: 10
104+
PenaltyExcessCharacter: 1000000
105+
PenaltyReturnTypeOnItsOwnLine: 60
106+
PointerAlignment: Left
107+
ReflowComments: true
108+
SortIncludes: true
109+
SortUsingDeclarations: true
110+
SpaceAfterCStyleCast: false
111+
SpaceAfterLogicalNot: false
112+
SpaceAfterTemplateKeyword: true
113+
SpaceBeforeAssignmentOperators: true
114+
SpaceBeforeCpp11BracedList: true
115+
SpaceBeforeCtorInitializerColon: true
116+
SpaceBeforeInheritanceColon: true
117+
SpaceBeforeParens: ControlStatements
118+
SpaceBeforeRangeBasedForLoopColon: true
119+
SpaceInEmptyBlock: true
120+
SpaceInEmptyParentheses: false
121+
SpacesBeforeTrailingComments: 1
122+
SpacesInAngles: false
123+
SpacesInConditionalStatement: false
124+
SpacesInContainerLiterals: true
125+
SpacesInCStyleCastParentheses: false
126+
SpacesInParentheses: false
127+
SpacesInSquareBrackets: false
128+
SpaceBeforeSquareBrackets: false
129+
Standard: Latest
130+
StatementMacros:
131+
- Q_UNUSED
132+
- QT_REQUIRE_VERSION
133+
TabWidth: 8
134+
UseCRLF: false
135+
UseTab: Never
136+
...
137+

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,26 @@ _deps
5757
*.cubin
5858
*.fatbin
5959

60+
### VisualStudioCode ###
61+
.vscode/*
62+
!.vscode/settings.json
63+
!.vscode/tasks.json
64+
!.vscode/launch.json
65+
!.vscode/extensions.json
66+
!.vscode/*.code-snippets
67+
68+
# Local History for Visual Studio Code
69+
.history/
70+
71+
# Built Visual Studio Code Extensions
72+
*.vsix
73+
74+
### VisualStudioCode Patch ###
75+
# Ignore all local history of files
76+
.history
77+
.ionide
78+
6079
### Blobs ###
6180
/build
81+
/data
82+
assignment.html

.vscode/settings.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"files.associations": {
3+
"algorithm": "cpp",
4+
"array": "cpp",
5+
"atomic": "cpp",
6+
"bit": "cpp",
7+
"cctype": "cpp",
8+
"charconv": "cpp",
9+
"chrono": "cpp",
10+
"clocale": "cpp",
11+
"cmath": "cpp",
12+
"compare": "cpp",
13+
"concepts": "cpp",
14+
"cstdarg": "cpp",
15+
"cstddef": "cpp",
16+
"cstdint": "cpp",
17+
"cstdio": "cpp",
18+
"cstdlib": "cpp",
19+
"cstring": "cpp",
20+
"ctime": "cpp",
21+
"cwchar": "cpp",
22+
"deque": "cpp",
23+
"exception": "cpp",
24+
"filesystem": "cpp",
25+
"format": "cpp",
26+
"forward_list": "cpp",
27+
"fstream": "cpp",
28+
"functional": "cpp",
29+
"initializer_list": "cpp",
30+
"iomanip": "cpp",
31+
"ios": "cpp",
32+
"iosfwd": "cpp",
33+
"iostream": "cpp",
34+
"istream": "cpp",
35+
"iterator": "cpp",
36+
"limits": "cpp",
37+
"list": "cpp",
38+
"locale": "cpp",
39+
"map": "cpp",
40+
"memory": "cpp",
41+
"mutex": "cpp",
42+
"new": "cpp",
43+
"numeric": "cpp",
44+
"optional": "cpp",
45+
"ostream": "cpp",
46+
"queue": "cpp",
47+
"random": "cpp",
48+
"ranges": "cpp",
49+
"ratio": "cpp",
50+
"span": "cpp",
51+
"sstream": "cpp",
52+
"stack": "cpp",
53+
"stdexcept": "cpp",
54+
"stop_token": "cpp",
55+
"streambuf": "cpp",
56+
"string": "cpp",
57+
"system_error": "cpp",
58+
"thread": "cpp",
59+
"tuple": "cpp",
60+
"type_traits": "cpp",
61+
"typeinfo": "cpp",
62+
"unordered_map": "cpp",
63+
"utility": "cpp",
64+
"variant": "cpp",
65+
"vector": "cpp",
66+
"xfacet": "cpp",
67+
"xhash": "cpp",
68+
"xiosbase": "cpp",
69+
"xlocale": "cpp",
70+
"xlocbuf": "cpp",
71+
"xlocinfo": "cpp",
72+
"xlocmes": "cpp",
73+
"xlocmon": "cpp",
74+
"xlocnum": "cpp",
75+
"xloctime": "cpp",
76+
"xmemory": "cpp",
77+
"xstring": "cpp",
78+
"xtr1common": "cpp",
79+
"xtree": "cpp",
80+
"xutility": "cpp"
81+
}
82+
}

CMakeLists.txt

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,71 @@
11
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
2-
project(CudaHello LANGUAGES CUDA CXX)
3-
add_executable(hello hello.cu)
2+
project(ComputerGraphics C CXX CUDA)
43

4+
option(USE_PREBUILT_INTERSECT "Enable using prebuilt intersection library" OFF)
5+
6+
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/framework")
7+
# Create framework library and include CMake scripts (compiler warnings, sanitizers and static analyzers).
8+
add_subdirectory("framework")
9+
set(REFERENCE_MODE OFF)
10+
else()
11+
# During development the framework lives in parent folder.
12+
add_subdirectory("../../../framework/" "${CMAKE_BINARY_DIR}/framework/")
13+
set(REFERENCE_MODE ON)
14+
endif()
15+
16+
find_package(OpenGL REQUIRED)
17+
find_package(OpenMP REQUIRED)
18+
19+
add_library(CGFinProjLib
20+
"src/scene.cpp"
21+
"src/draw.cpp"
22+
"src/screen.cpp"
23+
"src/bounding_volume_hierarchy.cpp"
24+
"src/bvh_interface.cpp"
25+
"src/light.cpp"
26+
"src/config.cpp"
27+
"src/texture.cpp"
28+
"src/shading.cpp"
29+
"src/interpolate.cpp"
30+
"src/render.cpp"
31+
"src/utils.cpp"
32+
)
33+
34+
if (REFERENCE_MODE)
35+
target_sources(CGFinProjLib PRIVATE
36+
"src/extra/motion_blur.cpp"
37+
"src/extra/multiple_rays.cpp"
38+
"src/extra/bloom_effect.cpp"
39+
"src/extra/glossy_reflection.cpp"
40+
)
41+
endif()
42+
43+
target_include_directories(CGFinProjLib PUBLIC "src")
44+
target_link_libraries(CGFinProjLib PUBLIC CGFramework OpenGL::GLU OpenMP::OpenMP_CXX)
45+
target_compile_features(CGFinProjLib PUBLIC cxx_std_20)
46+
enable_sanitizers(CGFinProjLib)
47+
set_project_warnings(CGFinProjLib)
48+
49+
if (USE_PREBUILT_INTERSECT)
50+
add_library(Intersect2 STATIC IMPORTED)
51+
if (WIN32)
52+
set_target_properties(Intersect2 PROPERTIES IMPORTED_LOCATION_DEBUG "${CMAKE_SOURCE_DIR}/prebuilt/Intersect_x64_debug.lib")
53+
set_target_properties(Intersect2 PROPERTIES IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/prebuilt/Intersect_x64_release.lib")
54+
elseif (APPLE)
55+
set_target_properties(Intersect2 PROPERTIES IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/prebuilt/libIntersect_mac_arm64.a")
56+
else()
57+
set_target_properties(Intersect2 PROPERTIES IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/prebuilt/libIntersect_linux_x64.a")
58+
endif()
59+
target_link_libraries(CGFinProjLib PUBLIC Intersect2)
60+
else()
61+
target_sources(CGFinProjLib PRIVATE "src/intersect.cpp")
62+
endif()
63+
64+
target_compile_definitions(CGFinProjLib PUBLIC
65+
"-DDATA_DIR=\"${CMAKE_CURRENT_LIST_DIR}/data/\"")
66+
67+
add_executable(SeminarImpl "src/main.cpp")
68+
target_link_libraries(SeminarImpl PUBLIC CGFinProjLib)
69+
target_compile_features(SeminarImpl PUBLIC cxx_std_20)
70+
enable_sanitizers(SeminarImpl)
71+
set_project_warnings(SeminarImpl)

framework/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
2+
project(ComputerGraphics C CXX)
3+
4+
# Slightly modified versions of the files from the cpp-starter-project by Jason Turner:
5+
# https://github.com/lefticus/cpp_starter_project/
6+
include("cmake/CompilerWarnings.cmake") # Enable almost all compiler warnings and CMake option to enable -Werror.
7+
include("cmake/Sanitizers.cmake") # CMake options to enable address, memory, UB and thread sanitizers.
8+
include("cmake/StaticAnalyzers.cmake") # CMake options to enable clang-tidy or cpp-check.
9+
10+
add_subdirectory("third_party")
11+
12+
if (FRAMEWORK_BASIC_LIBRARY)
13+
add_library(CGFramework INTERFACE)
14+
target_include_directories(CGFramework INTERFACE "include/")
15+
target_link_libraries(CGFramework INTERFACE fmt)
16+
target_compile_features(CGFramework INTERFACE cxx_std_20)
17+
else()
18+
set(OpenGL_GL_PREFERENCE GLVND) # Prevent CMake warning about legacy fallback on Linux.
19+
find_package(OpenGL REQUIRED)
20+
21+
add_library(CGFramework STATIC
22+
"src/trackball.cpp"
23+
"src/mesh.cpp"
24+
"src/image.cpp"
25+
"src/shader.cpp"
26+
"src/window.cpp"
27+
"src/imguizmo.cpp"
28+
"src/ImGuizmo/ImGuizmo.cpp")
29+
target_include_directories(CGFramework PRIVATE "include/framework/" PUBLIC "include/")
30+
target_link_libraries(CGFramework PUBLIC OpenGL::GL glad glm glfw imgui stb tinyobjloader fmt nativefiledialog toml)
31+
target_compile_features(CGFramework PUBLIC cxx_std_20)
32+
set_property(TARGET CGFramework PROPERTY POSITION_INDEPENDENT_CODE ON)
33+
endif()
34+
35+
# Prevent accidentaly picking up a system-wide install of another loader (e.g. GLEW).
36+
#target_compile_definitions(CGFramework PUBLIC "-DIMGUI_IMPL_OPENGL_LOADER_GLAD=1")

0 commit comments

Comments
 (0)