Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f0240e4
enable linux compilation
D7ry May 11, 2024
3fda1bf
functional cuda
D7ry May 11, 2024
2ed37f0
clean up some code, set up more CUDA
D7ry May 11, 2024
ed37aa0
image inedxing
D7ry May 11, 2024
9cd3c97
update
D7ry May 11, 2024
ac47174
update
D7ry May 11, 2024
59fc6b1
update
D7ry May 11, 2024
5dfae4b
progress
D7ry May 11, 2024
c82166a
progress
D7ry May 11, 2024
549f308
bunch
D7ry May 12, 2024
dd84272
at least it compiles
D7ry May 12, 2024
01de770
wip
D7ry May 12, 2024
2acdc4b
wip
D7ry May 12, 2024
c78d65f
buggy
D7ry May 12, 2024
77c9176
getting there
D7ry May 12, 2024
fb47b14
rtx on let's fucking go
D7ry May 12, 2024
ded6bda
fix pbr
D7ry May 12, 2024
da4cc79
clean up mean
D7ry May 12, 2024
cb3d589
add pch
D7ry May 12, 2024
20475f2
misc
D7ry May 12, 2024
f329c84
update
D7ry May 12, 2024
bfcd822
random
D7ry May 12, 2024
5b21854
wip ambience
D7ry May 12, 2024
9ba0809
update
D7ry May 12, 2024
af24ae2
fix env light shading
D7ry May 12, 2024
6c91826
better rng
D7ry May 12, 2024
cd26565
add sphere bound checking for random sphere spawn
D7ry May 12, 2024
93f982b
clean up camera pos
D7ry May 12, 2024
69fa6fb
cleanup
D7ry May 12, 2024
c82d866
clean up CUDA code
D7ry May 12, 2024
d215d34
fix aspect ratio
D7ry May 12, 2024
1e56105
add solar system
D7ry May 12, 2024
893d80b
add readme
D7ry May 12, 2024
8f4264e
update readme
D7ry May 12, 2024
c73416c
update readme
D7ry May 12, 2024
12e7d3b
camel case cuda code
D7ry May 12, 2024
c5e1e56
normal calculation is off, everything else working
D7ry May 13, 2024
16c403b
cleanup
D7ry May 13, 2024
5fb3a4b
update
D7ry May 13, 2024
11cb119
add texture mapping
D7ry May 13, 2024
fa0daee
update
D7ry May 13, 2024
f4eb109
update
D7ry May 13, 2024
bf10ca3
update
D7ry May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
BasedOnStyle: LLVM
IndentWidth: 4
ContinuationIndentWidth: 4
PointerAlignment: Left
ColumnLimit: 80

# Function declaration and definition
AlignAfterOpenBracket: BlockIndent
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AlwaysBreakAfterReturnType: None
PenaltyReturnTypeOnItsOwnLine: 1000 # add big penalty so that return type never has its own line

AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: false
BinPackParameters: false

BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
MaxEmptyLinesToKeep: 1

AlwaysBreakTemplateDeclarations: Yes

BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterEnum: true
AfterStruct: true
AfterFunction: false
AfterNamespace: true
SplitEmptyFunction: true

SeparateDefinitionBlocks: Always

SortIncludes: CaseSensitive
# multipel declarations are aligned to right
# AlignConsecutiveDeclarations:
# Enabled: true
# AcrossEmptyLines: true
# AcrossComments: false
# AlignCompound: true
# PadOperators: true
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# dependencies
/Dependencies

# temp files
/.cache

# building
/debug
/Debug
/Release
/x64
/build

# Visual Studio Project Files
.vs/
Expand All @@ -15,4 +20,4 @@

# renders
*.png
renders/
renders/
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/debug/rodent_raytracer",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/debug/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}

]
}
49 changes: 49 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.22)
# set(CMAKE_C_COMPILER "/usr/bin/gcc")
# set(CMAKE_CXX_COMPILER "/usr/bin/g++")
# set(CMAKE_CUDA_COMPILER "/usr/local/cuda-12/bin/nvcc")

enable_language(CUDA)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(rodent_raytracer LANGUAGES CXX CUDA)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

# SFML fuckery
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.x)
FetchContent_MakeAvailable(SFML)

add_executable(
rodent_raytracer
src/main.cpp
src/Primitive.cpp
src/Renderer.cpp
src/util/Math.cpp
src/util/Window.cpp
src/gpu.cu
src/Camera.cpp
src/Image.cpp
src/Rotor.cpp
)


set(SFML_LIBRARIES sfml-graphics sfml-window sfml-system)

target_include_directories(rodent_raytracer PUBLIC ${SFML_INCLUDE_DIRS})
target_link_libraries(rodent_raytracer PRIVATE ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
target_precompile_headers(rodent_raytracer PRIVATE src/PCH.h)


# CUDA stuff
# set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_60")

# set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=sm_60")
set_target_properties(rodent_raytracer PROPERTIES CUDA_ARCHITECTURES "86")

42 changes: 42 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Geosim-RTX

CUDA-based real-time ray marcher for physically-based rendering of geometries in H3 space.

## Results

|![solar system naive](results/solar_system_naive.gif)|
|:--:|
| _Looks just like a naive solar system from afar_|

|![solar system](results/solar_system.gif)|
|:--:|
| _Light doesn't travel in straight path_|

|![solar system 2](results/solar_system_2.gif)|
|:--:|
| _Spheres rotating appear to be "moving away"_ |

## Build

### Requirements

- `CUDA 11.8` or above && `nvcc`
- `CMake`
- `make`
- `gcc`
- `glm`

```bash
mkdir build
cd build
cmake ..
make
```


## Reference

[Ray-marching Thurston geometries](https://arxiv.org/abs/2010.15801)

[Non-euclidean virtual reality I: explorations of ℍ3](https://arxiv.org/abs/1702.04004)

Binary file added resource/2k_neptune.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/2k_uranus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/8k_earth_daymap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/8k_jupiter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/8k_mars.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/8k_mercury.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/8k_saturn.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/8k_venus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/berkeley.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/cubemap.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/env_map.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/env_map.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/pillars_of_creation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/starmap_g4k.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/starmap_g8k.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added results/solar_system.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added results/solar_system_2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added results/solar_system_naive.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Camera.h"

void Camera::updateViewMat() {
// derive forward direction of camera from its euler angles
forwardDir.x = cosf(yaw) * cosf(pitch);
forwardDir.y = sinf(pitch);
forwardDir.z = sinf(yaw) * cosf(pitch);

static constexpr glm::vec3 GLOBAL_UP{0.f, 1.f, 0.f};

// unitize and calculate relative up and right direction of the camera
forwardDir = glm::normalize(forwardDir);
rightDir = glm::normalize(glm::cross(forwardDir, GLOBAL_UP));
upDir = glm::normalize(glm::cross(rightDir, forwardDir));

const glm::vec3 targetPosition{position + forwardDir};
viewMat = glm::lookAt(position, targetPosition, upDir);
}
20 changes: 2 additions & 18 deletions src/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,5 @@ struct Camera

glm::mat4 viewMat{ 1.f };

void updateViewMat()
{
// derive forward direction of camera from its euler angles
forwardDir.x = cosf(yaw) * cosf(pitch);
forwardDir.y = sinf(pitch);
forwardDir.z = sinf(yaw) * cosf(pitch);

static constexpr glm::vec3 GLOBAL_UP{ 0.f, 1.f, 0.f };

// unitize and calculate relative up and right direction of the camera
forwardDir = glm::normalize(forwardDir);
rightDir = glm::normalize(glm::cross(forwardDir, GLOBAL_UP));
upDir = glm::normalize(glm::cross(rightDir, forwardDir));

const glm::vec3 targetPosition{ position + forwardDir };
viewMat = glm::lookAt(position, targetPosition, upDir);
}
};
void updateViewMat();
};
32 changes: 32 additions & 0 deletions src/Image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <SFML/Graphics/Image.hpp>

#include "Image.h"


void Image::setPixel(const glm::vec2& ndc, const glm::vec3& pixelData) {
glm::uvec2 pixelCoord{ndc.x * width, ndc.y * height};

int index = pixelCoord.x + (pixelCoord.y * width);

pixels[index] = pixelData;
}
void Image::saveToFile(const std::string& filename) {
std::vector<sf::Uint8> uint8Pixels;

for (const glm::vec3& pixel : pixels) {
uint8Pixels.push_back(pixel.r * 255);
uint8Pixels.push_back(pixel.g * 255);
uint8Pixels.push_back(pixel.b * 255);

static constexpr bool ALWAYS_OPAQUE{true};

if constexpr (ALWAYS_OPAQUE)
uint8Pixels.push_back(255);
// else
// uint8Pixels.push_back(pixel.a * 255);
}

sf::Image i;
i.create(width, height, uint8Pixels.data());
i.saveToFile(filename + " hash" + std::to_string((uint64_t)&i) + ".png");
}
65 changes: 14 additions & 51 deletions src/Image.h
Original file line number Diff line number Diff line change
@@ -1,57 +1,20 @@
#pragma once

#include <string>
#include <glm/glm.hpp>

#include <vector>

#include <SFML/Graphics/Image.hpp>

struct Image
{
const unsigned width;
const unsigned height;

std::vector<glm::vec3> pixels;

Image(unsigned width, unsigned height)
:
width{ width },
height{ height },
pixels{ width * height }
{}

void setPixel(const glm::vec2& ndc, const glm::vec3& pixelData)
{
glm::uvec2 pixelCoord{
ndc.x * width,
ndc.y * height
};

int index = pixelCoord.x + (pixelCoord.y * width);

pixels[index] = pixelData;
}

void saveToFile(const std::string& filename)
{
std::vector<sf::Uint8> uint8Pixels;

for (const glm::vec3& pixel : pixels)
{
uint8Pixels.push_back(pixel.r * 255);
uint8Pixels.push_back(pixel.g * 255);
uint8Pixels.push_back(pixel.b * 255);

static constexpr bool ALWAYS_OPAQUE{ true };

if constexpr (ALWAYS_OPAQUE)
uint8Pixels.push_back(255);
//else
// uint8Pixels.push_back(pixel.a * 255);
}

sf::Image i;
i.create(width, height, uint8Pixels.data());
i.saveToFile(filename + " hash" + std::to_string((unsigned)&i) + ".png");
}
};

struct Image {
const unsigned width;
const unsigned height;

std::vector<glm::vec3> pixels;

Image(unsigned width, unsigned height) : width{width}, height{height}, pixels{width * height} {}

void setPixel(const glm::vec2& ndc, const glm::vec3& pixelData);

void saveToFile(const std::string& filename);
};
2 changes: 2 additions & 0 deletions src/PCH.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CUDA_ONCE 0
#define CUDA 1
Loading