Skip to content

Commit 8e36eab

Browse files
committed
Lots of code changes - should work
1 parent f51f21a commit 8e36eab

File tree

333 files changed

+33950
-25505
lines changed

Some content is hidden

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

333 files changed

+33950
-25505
lines changed

.gitignore

+546-20
Large diffs are not rendered by default.

CMakeLists.txt

+73-78
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,94 @@
1-
cmake_minimum_required(VERSION 3.0.0)
1+
cmake_minimum_required(VERSION 3.0)
22

3-
#on OSX we have to explicitly set clang/clang++
4-
#set (CMAKE_C_COMPILER clang)
5-
#set (CMAKE_CXX_COMPILER clang++)
3+
project(cis565_rasterizer)
64

7-
project(Project4-Rasterizer)
5+
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
86

9-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
10-
11-
#External libs location (alternatively, /usr/local or something)
12-
set(EXTERNAL "external")
13-
14-
#Set up include and lib paths
15-
include_directories(${EXTERNAL}/include)
16-
include_directories(${EXTERNAL}/src)
7+
# Set up include and lib paths
8+
include_directories(.)
9+
include_directories("external")
10+
include_directories("external/include")
1711
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
18-
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${EXTERNAL}/lib/osx)
12+
set(EXTERNAL_LIB_PATH "external/lib/osx")
1913
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
20-
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${EXTERNAL}/lib/linux /usr/lib64)
14+
set(EXTERNAL_LIB_PATH "external/lib/linux" "/usr/lib64")
2115
elseif(WIN32)
22-
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${EXTERNAL}/lib/win)
16+
set(EXTERNAL_LIB_PATH "external/lib/win")
2317
endif()
18+
link_directories(${EXTERNAL_LIB_PATH})
19+
list(APPEND CMAKE_LIBRARY_PATH "${EXTERNAL_LIB_PATH}")
2420

25-
set(GLFW_INCLUDE_DIR ${EXTERNAL}/include)
26-
set(GLFW_LIBRARY_DIR ${CMAKE_LIBRARY_PATH})
27-
set(GLEW_INCLUDE_DIR ${EXTERNAL}/include)
28-
set(GLEW_LIBRARY_DIR ${CMAKE_LIBRARY_PATH})
2921

30-
#Find up and set up core dependency libs
31-
find_library(GLFW_LIBRARY "glfw3" HINTS ${GLFW_LIBRARY_DIR})
32-
find_package(GLUT)
33-
find_package(OpenGL)
22+
# Find up and set up core dependency libs
23+
24+
set(GLFW_INCLUDE_DIR "external/include")
25+
set(GLFW_LIBRARY_DIR "${CMAKE_LIBRARY_PATH}")
26+
find_library(GLFW_LIBRARY "glfw3" HINTS "${GLFW_LIBRARY_DIR}")
27+
28+
set(GLEW_INCLUDE_DIR "external/include")
29+
set(GLEW_LIBRARY_DIR "${CMAKE_LIBRARY_PATH}")
30+
add_definitions(-DGLEW_STATIC)
3431
find_package(GLEW)
3532

36-
set(CORELIBS ${GLFW_LIBRARY} ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${GLEW_LIBRARY})
33+
find_package(OpenGL)
3734

38-
#OSX-specific hacks/fixes
35+
set(CORELIBS
36+
"${GLFW_LIBRARY}"
37+
"${OPENGL_LIBRARY}"
38+
"${GLEW_LIBRARY}"
39+
)
40+
41+
# Enable C++11 for host code
42+
set(CMAKE_CXX_STANDARD 11)
43+
44+
# Set up different build configurations
45+
set(CMAKE_CONFIGURATION_TYPES Debug DebugFast Release)
46+
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
47+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
48+
set(CMAKE_CXX_FLAGS_DEBUGFAST "-O2 -g")
49+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
50+
list(APPEND CUDA_NVCC_FLAGS_DEBUG -O0 -G -g)
51+
list(APPEND CUDA_NVCC_FLAGS_DEBUGFAST -O2 -g -lineinfo)
52+
list(APPEND CUDA_NVCC_FLAGS_RELEASE -O3)
53+
54+
# OS X linker options
3955
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
40-
#Link IOKit because this is where we get GL stuff for OSX
41-
set(IOKIT "-framework IOKit")
42-
set(CORELIBS ${CORELIBS} ${IOKIT})
43-
#Link against libstdc++ since CUDA doesn't support libc++ yet
44-
set(CUDA_NVCC_FLAGS "--compiler-options;-stdlib=libstdc++;")
45-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
46-
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
47-
48-
#Linux specific hacks/fixes
49-
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
50-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lX11 -lXxf86vm -lXrandr -lpthread -lXi")
56+
list(APPEND CORELIBS "-framework IOKit")
57+
list(APPEND CORELIBS "-framework Cocoa")
58+
list(APPEND CORELIBS "-framework CoreVideo")
5159
endif()
5260

53-
#Compiler flag magic
54-
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
55-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -m64 -msse2")
56-
elseif(WIN32)
57-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
61+
# Linux linker options
62+
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
63+
list(APPEND CMAKE_EXE_LINKER_FLAGS "-lX11 -lXxf86vm -lXrandr -lXi")
5864
endif()
5965

60-
#Crucial magic for CUDA linking
66+
# CUDA linker options
67+
find_package(Threads REQUIRED)
6168
find_package(CUDA REQUIRED)
6269
set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ON)
63-
6470
set(CUDA_SEPARABLE_COMPILATION ON)
6571

66-
#Make NVCC run silently
67-
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
68-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}-w;")
69-
endif()
70-
71-
#Force Visual Studio to link against MT versions of libs
72-
if(MSVC)
73-
set(CompilerFlags
74-
CMAKE_CXX_FLAGS
75-
CMAKE_CXX_FLAGS_DEBUG
76-
CMAKE_CXX_FLAGS_RELEASE
77-
CMAKE_C_FLAGS
78-
CMAKE_C_FLAGS_DEBUG
79-
CMAKE_C_FLAGS_RELEASE
80-
)
81-
foreach(CompilerFlag ${CompilerFlags})
82-
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
83-
endforeach()
84-
set(CUDA_NVCC_FLAGS_RELEASE ${CUDA_NVCC_FLAGS_RELEASE} "--compiler-options /MT; --linker-options /MT")
85-
set(CUDA_NVCC_FLAGS_DEBUG ${CUDA_NVCC_FLAGS_DEBUG} "--compiler-options /MT; --linker-options /MT")
86-
endif()
87-
88-
#Add all source files. Headers don't need to be listed here since the compiler will find them;
89-
#we just need the actual files being fed directly to the compiler
90-
set(SOURCE_FILES "src/main.cpp")
91-
set(SOURCE_FILES ${SOURCE_FILES} "src/rasterizeKernels.cu")
92-
set(SOURCE_FILES ${SOURCE_FILES} "src/utilities.cpp")
93-
set(SOURCE_FILES ${SOURCE_FILES} "${EXTERNAL}/src/glslUtil/glslUtility.cpp")
94-
set(SOURCE_FILES ${SOURCE_FILES} "${EXTERNAL}/src/objUtil/obj.cpp")
95-
set(SOURCE_FILES ${SOURCE_FILES} "${EXTERNAL}/src/objUtil/objloader.cpp")
96-
97-
cuda_add_executable(Project4-Rasterizer ${SOURCE_FILES} OPTIONS -arch=sm_20)
98-
99-
target_link_libraries(Project4-Rasterizer ${CORELIBS})
72+
#add_subdirectory(stream_compaction) # TODO: uncomment if using your own stream compaction
73+
add_subdirectory(src)
74+
add_subdirectory(util)
75+
76+
cuda_add_executable(${CMAKE_PROJECT_NAME}
77+
"src/main.h"
78+
"src/main.cpp"
79+
)
80+
81+
target_link_libraries(${CMAKE_PROJECT_NAME}
82+
src
83+
util
84+
#stream_compaction # TODO: uncomment if using your own stream compaction
85+
${CORELIBS}
86+
)
87+
88+
add_custom_command(
89+
TARGET ${CMAKE_PROJECT_NAME}
90+
POST_BUILD
91+
COMMAND ${CMAKE_COMMAND} -E copy_directory
92+
${CMAKE_SOURCE_DIR}/shaders
93+
${CMAKE_BINARY_DIR}/shaders
94+
)

GNUmakefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CMAKE_ALT1 := /usr/local/bin/cmake
2+
CMAKE_ALT2 := /Applications/CMake.app/Contents/bin/cmake
3+
CMAKE := $(shell \
4+
which cmake 2>/dev/null || \
5+
([ -e ${CMAKE_ALT1} ] && echo "${CMAKE_ALT1}") || \
6+
([ -e ${CMAKE_ALT2} ] && echo "${CMAKE_ALT2}") \
7+
)
8+
9+
all: DebugFast
10+
11+
12+
Debug: build
13+
(cd build && ${CMAKE} -DCMAKE_BUILD_TYPE=$@ .. && make)
14+
15+
DebugFast: build
16+
(cd build && ${CMAKE} -DCMAKE_BUILD_TYPE=$@ .. && make)
17+
18+
Release: build
19+
(cd build && ${CMAKE} -DCMAKE_BUILD_TYPE=$@ .. && make)
20+
21+
22+
run:
23+
build/cis565_path_tracer scenes/sphere.txt
24+
25+
build:
26+
mkdir -p build
27+
28+
clean:
29+
((cd build && make clean) 2>&- || true)
30+
31+
.PHONY: all Debug DebugFast Release clean

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -133,31 +133,32 @@ modern hardware (DX/OpenGL). Yours need not match precisely. To begin, try to
133133
write a minimal amount of code as described here. This will reduce the
134134
necessary time spent debugging.
135135

136+
* Clear the depth buffer with some default value.
136137
* Vertex shading:
137138
* `VertexIn[n] vs_input -> VertexOut[n] vs_output`
138139
* A minimal vertex shader will apply no transformations at all - it draws
139-
directly in normalized device coordinates (NDC).
140+
directly in normalized device coordinates (-1 to 1 in each dimension).
140141
* Primitive assembly.
141-
* `vertexOut[n] vs_output -> triangle[n/3] primitives`
142+
* `VertexOut[n] vs_output -> Triangle[n/3] primitives`
142143
* Start by supporting ONLY triangles.
143144
* Rasterization.
144-
* `triangle[n/3] primitives -> fragmentIn[m] fs_input`
145+
* `Triangle[n/3] primitives -> FragmentIn[m] fs_input`
145146
* Scanline: TODO
146147
* Tiled: TODO
147148
* Fragment shading.
148-
* `fragmentIn[m] fs_input -> fragmentOut[m] fs_output`
149+
* `FragmentIn[m] fs_input -> FragmentOut[m] fs_output`
149150
* A super-simple test fragment shader: output same color for every fragment.
150151
* Also try displaying various debug views (normals, etc.)
151152
* Fragments to depth buffer.
152-
* `fragmentOut[m] -> fragmentOut[resolution]`
153+
* `FragmentOut[m] -> FragmentOut[width][height]`
153154
* Can really be done inside the fragment shader.
154155
* Results in race conditions - don't bother to fix these until it works!
155156
* A depth buffer for storing and depth testing fragments.
156-
* `fragmentOut[resolution] depthbuffer`
157+
* `FragmentOut[width][height] depthbuffer`
157158
* An array of `fragment` objects.
158159
* At the end of a frame, it should contain the fragments drawn to the screen.
159160
* Fragment to framebuffer writing.
160-
* `fragmentOut[resolution] depthbuffer -> vec3[resolution] framebuffer`
161+
* `FragmentOut[width][height] depthbuffer -> vec3[width][height] framebuffer`
161162
* Simply copies the colors out of the depth buffer into the framebuffer
162163
(to be displayed on the screen).
163164

@@ -167,10 +168,11 @@ INSTRUCTOR TODO
167168

168169
* Rasterization.
169170
* Scanline:
170-
* Optimization: scissor around rasterized triangle
171+
* Optimization: when rasterizing a triangle, only scan over the box around
172+
the triangle (`getAABBForTriangle`).
171173

172174
* Fragments to depth buffer.
173-
* `fragmentOut[m] -> fragmentOut[resolution]`
175+
* `fragmentOut[m] -> fragmentOut[width][height]`
174176
* Can really be done inside the fragment shader.
175177
* This allows you to do depth tests before spending execution time in
176178
complex fragment shader code.

0 commit comments

Comments
 (0)