...
 
Commits (72)
......@@ -4,6 +4,7 @@
!.vscode/tasks.json
bin/
obj/
__pycache__
*.vcxproj.user
*.spv
......@@ -24,6 +25,8 @@ build_debug/
build_release/
# Verzeichnis für Profiling & Debugging mithilfe von Nsights
nsights
#seltsame Datei von imgui
imgui.ini
#Latex-Artefakte
__latexindent_temp.tex
......
......@@ -18,3 +18,13 @@
url = https://github.com/google/shaderc
ignore = untracked
branch = master
[submodule "dearImGui"]
path = src/submodules/dearImGui
url = https://github.com/ocornut/imgui.git
ignore = untracked
branch = master
[submodule "stb"]
path = src/submodules/stb
url = https://github.com/nothings/stb.git
ignore = untracked
branch = master
......@@ -149,6 +149,48 @@
"reveal": "always"
},
"problemMatcher": []
},
//----------------------------------------------------------------------------------------------------
// Texterzeugung
//----------------------------------------------------------------------------------------------------
{
"label": "tex - Forschungspraktikum",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "doc/common/build.py",
"args": [
"doc/Forschungspraktikum"
],
"problemMatcher": []
},
{
"label": "tex - Themenvorschlag",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "doc/common/build.py",
"args": [
"doc/Themenvorschlag"
],
"problemMatcher": []
},
{
"label": "tex - Masterarbeit",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": "doc/common/build.py",
"args": [
"doc/Masterarbeit"
],
"problemMatcher": []
}
]
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
cmake_minimum_required(VERSION 3.5)
project(Raytracing VERSION 1.0.2 LANGUAGES CXX)
project(Raytracing VERSION 1.1.0 LANGUAGES CXX)
cmake_policy(SET CMP0048 NEW)
#------------------------------------------------------------------------------------------------------------------
......@@ -18,7 +18,7 @@ add_subdirectory(./src/submodules/glfw)
set(SHADERC_SKIP_TESTS on)
set(SHADERC_ENABLE_SHARED_CRT on)
add_subdirectory(./src/submodules/shaderc/src)
add_subdirectory(./src/submodules/shaderc/)
# set(ASSIMP_NO_EXPORT on)
set(ASSIMP_BUILD_TESTS off)
......@@ -39,6 +39,9 @@ add_library(
src/Lib/src/Core/AppCreateInfo.cpp
src/Lib/src/Core/CgContext.cpp
src/Lib/src/Core/CgContext.Basics.cpp
src/Lib/src/Core/CgContext.ImGui.cpp
src/Lib/src/Core/CgContext.Rasterization.cpp
src/Lib/src/Core/CgContext.Raytracing.cpp
src/Lib/src/Core/CoreInitException.cpp
src/Lib/src/Core/DeviceInfo.cpp
src/Lib/src/Core/SwapChainInfo.cpp
......@@ -56,17 +59,28 @@ add_library(
src/Lib/src/Util/FileIo.cpp
src/Lib/src/Util/Logging.cpp
src/Lib/src/Util/VectorConversions.cpp
src/Lib/src/Util/PerlinGenerator.cpp
src/Lib/src/VkUtil/CompileShader.cpp
src/Lib/src/VkUtil/AccelerationStructureBase.cpp
src/Lib/src/VkUtil/BottomLevelAccelerationStructure.cpp
src/Lib/src/VkUtil/FindOptimalMemoryType.cpp
src/Lib/src/VkUtil/VkUtil.cpp
src/Lib/src/VkUtil/NoUsableMemoryException.cpp
src/Lib/src/VkUtil/TopLevelAccelerationStructure.cpp
src/Lib/src/VkUtil/VkResult.cpp
src/Lib/src/VkUtil/Buffer.cpp
src/Lib/src/VkUtil/Texture.cpp
src/Lib/src/VkUtil/RenderTarget.cpp
src/Lib/src/VkUtil/StagedBuffer.cpp
src/Lib/src/VkUtil/OneTimeCommandBuffer.cpp
src/Lib/src/VkUtil/StbImageImpl.cpp
src/submodules/dearImGui/imgui_demo.cpp
src/submodules/dearImGui/imgui_draw.cpp
src/submodules/dearImGui/imgui_widgets.cpp
src/submodules/dearImGui/imgui.cpp
src/submodules/dearImGui/examples/imgui_impl_vulkan.cpp
src/submodules/dearImGui/examples/imgui_impl_glfw.cpp
)
target_include_directories(Lib
......@@ -76,9 +90,12 @@ target_include_directories(Lib
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glm
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/.shaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc_util/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/assimp/include
${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/vulkannv
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui/examples
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/stb
)
target_link_libraries(Lib
......@@ -104,6 +121,7 @@ target_compile_features(Lib
add_executable(App
src/App/src/main.cpp
src/App/src/VkrtApp.cpp
src/App/src/Animation.cpp
)
target_include_directories(App
......@@ -113,8 +131,12 @@ target_include_directories(App
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glm
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/src/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc_util/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/assimp/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui/examples
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/stb
${CMAKE_CURRENT_SOURCE_DIR}/src/App/include
)
......@@ -143,8 +165,12 @@ target_include_directories(Playground
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/glm
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/src/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/shaderc/libshaderc_util/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/assimp/include
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/dearImGui/examples
${CMAKE_CURRENT_SOURCE_DIR}/src/submodules/stb
${CMAKE_CURRENT_SOURCE_DIR}/src/Lib/include
${CMAKE_CURRENT_SOURCE_DIR}/src/App/include
)
......
# Forschungsprokect Raytracing mit Vulkan
# Masterarbeit Godrays mittels Raytracing
Forschungspraktikum bei der Professur GDV (Graphische Datenverarbeitung) an der TU-Chemnitz.
Masterarbeit bei der Professur GDV (Graphische Datenverarbeitung) an der TU-Chemnitz.
## Zielsetzung
Das Erarbeiten einer Anwendung, die eine einfache Szene mittels Raytracing rendern kann. Die Raytracing-Shader sollen dabei im laufenden Programm angepasst und neu geladen werden können, um das Herumspielen mit verschiedenen Konfigurationen zu ermöglichen.
Das Darstellen von Strahlenbüscheln (a.k.a) Godrays soll mittels Raytracing umgesetzt werden um so eine höhere
Qualität als mit bisherigen Ansätzen zu erreichen.
## Voraussetzungen
- Git
- Python
- Python 3.x
- cmake 3.5 oder neuer
- Installiertes Vulkan-SDK von [LunarG](https://vulkan.lunarg.com) in der Version 1.1.130.0 oder neuer (alte Versionen sind nicht erprobt, können aber auch funktionieren)
- Belibige CMake-kompatible Buildtools, z.B. Visual Studio, oder gnu make
- Installiertes Vulkan-SDK von [LunarG](https://vulkan.lunarg.com) in der Version 1.2.141.0 oder neuer (andere Versionen sind nicht erprobt, können aber auch funktionieren)
- Beliebige CMake-kompatible Buildtools, z.B. Visual Studio, oder gnu make
## Initialisierung
......@@ -23,11 +24,14 @@ Das Erarbeiten einer Anwendung, die eine einfache Szene mittels Raytracing rende
- [Assimp](https://github.com/assimp/assimp) -> `src/submodules/assimp`
- [glm](https://github.com/g-truc/glm) -> `src/submodules/glm`
- [shaderc (known good-branch)](https://github.com/google/shaderc/tree/known-good) -> `src/submodules/shaderc`
3. Skript `src/submodules/shaderc/update_shaderc_sources.py` ausführen um die Abhänigkeiten von `libshaderc` herunterzuladen.
- [Dear ImGui](https://github.com/ocornut/imgui) -> `src/submodules/dearImGui`
- [stb](https://github.com/nothings/stb) -> `src/submodules/stb`
3. Skript `src/submodules/shaderc/update_shaderc_sources.py` ausführen um die Abhängigkeiten von `libshaderc` herunterzuladen.
## Build
Es ist empfohlen eine Out-Of-Source-Build zu nutzen. Dazu im Stammverzeichnis zunächst ein build-Verzeichnis erstellen und hinein wechseln:
Es ist empfohlen ein Out-Of-Source-Build zu nutzen. Dazu im Stammverzeichnis zunächst ein build-Verzeichnis erstellen und hinein wechseln:
``` bash
mkdir build
......@@ -125,3 +129,12 @@ beschrieben
- Anforderungen in Readme aktualisiert.
- FPS können nun im Fenstertitel angezeigt werden
### 1.1
- Diverse Optimierungen
- Integration von Dear ImGui
- Post-Processing-Stage mit einstellbaren Shadern
- beliebige Anzahl an Hitgroups und Miss-Shadern kann geladen werden.
- Jitter-Cam
- Neue Szenen (Cornell-Box)
......@@ -17,7 +17,7 @@ Ka 1.000000 1.000000 1.000000
Kd 0.154638 0.194287 0.137156
Ks 0.100362 0.100362 0.100362
Ke 0.077319 0.097143 0.068578
Ni 1.000000
Ni 1.300000
d 1.000000
illum 2
......
# Blender MTL File: 'cornell-box-cycles.blend'
# Material Count: 3
newmtl Light
Ns 00.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl DarkGreen
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.000000 0.320000 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl Khaki
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.659341 0.439560
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl BloodyRed
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.445000 0.000000 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
# Blender v2.79 (sub 0) OBJ File: 'cornell-box-cycles.blend'
# www.blender.org
mtllib cornell-box.mtl
o area_light
v -0.884011 5.319334 -2.517968
v -0.884011 5.318497 -3.567968
v 0.415989 5.318497 -3.567968
v 0.415989 5.319334 -2.517968
vn 0.0000 -1.0000 0.0008
usemtl Light
s off
f 2//1 4//1 1//1
f 2//1 3//1 4//1
o back_wall
v -2.950011 -0.162686 -5.835598
v 2.545989 -0.162686 -5.835598
v 2.545989 5.325313 -5.839967
v -3.014011 5.325313 -5.839967
vn 0.0000 0.0008 1.0000
usemtl Khaki
s off
f 5//2 7//2 8//2
f 5//2 6//2 7//2
o ceiling
v -3.014011 5.329765 -0.247969
v -3.014011 5.325313 -5.839968
v 2.545989 5.325313 -5.839968
v 2.545989 5.329765 -0.247969
vn 0.0000 -1.0000 0.0008
usemtl Khaki
s off
f 10//3 12//3 9//3
f 10//3 11//3 12//3
o floor
v -2.982011 -0.158233 -0.243599
v 2.545989 -0.158233 -0.243599
v 2.545989 -0.162686 -5.835598
v -2.950011 -0.162686 -5.835598
vn 0.0000 1.0000 -0.0008
usemtl Khaki
s off
f 14//4 16//4 13//4
f 14//4 15//4 16//4
o left_wall
v -2.982011 -0.158233 -0.243599
v -2.950011 -0.162686 -5.835598
v -3.014011 5.325313 -5.839968
v -3.014011 5.329765 -0.247969
vn 1.0000 0.0058 -0.0000
vn 0.9999 0.0117 0.0057
usemtl BloodyRed
s off
f 17//5 19//5 20//5
f 17//6 18//6 19//6
o right_wall
v 2.545989 -0.162686 -5.835598
v 2.545989 -0.158233 -0.243599
v 2.545989 5.329765 -0.247969
v 2.545989 5.325313 -5.839968
vn -1.0000 0.0000 0.0000
usemtl DarkGreen
s off
f 22//7 24//7 21//7
f 22//7 23//7 24//7
o short_box
v 1.245989 1.491249 -0.894913
v 1.725989 1.489975 -2.494912
v 0.145989 1.489601 -2.964912
v -0.354011 1.490859 -1.384912
v -0.354011 -0.159141 -1.383599
v -0.354011 1.490859 -1.384912
v 0.145989 1.489601 -2.964912
v 0.145989 -0.160399 -2.963598
v 1.245989 -0.158750 -0.893599
v 1.245989 1.491249 -0.894913
v -0.354011 1.490859 -1.384912
v -0.354011 -0.159141 -1.383599
v 1.725989 -0.160024 -2.493598
v 1.725989 1.489975 -2.494912
v 1.245989 1.491249 -0.894913
v 1.245989 -0.158750 -0.893599
v 0.145989 -0.160399 -2.963598
v 0.145989 1.489601 -2.964912
v 1.725989 1.489975 -2.494912
v 1.725989 -0.160024 -2.493598
vn 0.0000 1.0000 -0.0008
vn -0.9534 -0.0002 -0.3017
vn -0.2928 0.0008 0.9562
vn 0.9578 0.0002 0.2873
vn 0.2851 -0.0008 -0.9585
usemtl Khaki
s off
f 25//8 27//8 28//8
f 30//9 32//9 29//9
f 34//10 36//10 33//10
f 38//11 40//11 37//11
f 42//12 44//12 41//12
f 25//8 26//8 27//8
f 30//9 31//9 32//9
f 34//10 35//10 36//10
f 38//11 39//11 40//11
f 42//12 43//12 44//12
o tall_box
v -1.684011 3.139799 -2.716226
v -0.104011 3.139409 -3.206226
v -0.594011 3.138135 -4.806226
v -2.174011 3.138533 -4.306226
v -1.684011 -0.160200 -2.713598
v -1.684011 3.139799 -2.716226
v -2.174011 3.138533 -4.306226
v -2.174011 -0.161466 -4.303598
v -2.174011 -0.161466 -4.303598
v -2.174011 3.138533 -4.306226
v -0.594011 3.138135 -4.806226
v -0.594011 -0.161864 -4.803598
v -0.594011 -0.161864 -4.803598
v -0.594011 3.138135 -4.806226
v -0.104011 3.139409 -3.206226
v -0.104011 -0.160590 -3.203598
v -0.104011 -0.160590 -3.203598
v -0.104011 3.139409 -3.206226
v -1.684011 3.139799 -2.716226
v -1.684011 -0.160200 -2.713598
vn -0.0000 1.0000 -0.0008
vn -0.9556 0.0002 0.2945
vn -0.3017 -0.0008 -0.9534
vn 0.9562 -0.0002 -0.2928
vn 0.2962 0.0008 0.9551
usemtl Khaki
s off
f 46//13 48//13 45//13
f 49//14 51//14 52//14
f 54//15 56//15 53//15
f 58//16 60//16 57//16
f 62//17 64//17 61//17
f 46//13 47//13 48//13
f 49//14 50//14 51//14
f 54//15 55//15 56//15
f 58//16 59//16 60//16
f 62//17 63//17 64//17
......@@ -3,21 +3,27 @@
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_nonuniform_qualifier : require
#include "raycommon.glsl"
#include "common/raycommon.glsl"
#include "common/random.glsl"
#include "common/lighting.glsl"
layout(push_constant) uniform Constants
{
uint rngSeed;
};
layout(binding = 8) uniform sampler2D texSampler;
layout(location = 0) rayPayloadInNV HitPayload payload;
layout(location = 1) rayPayloadInNV bool isShadowed;
hitAttributeNV vec3 attribs;
layout(binding = 0, set = 0) uniform accelerationStructureNV topLevelAS;
layout(binding = 2, set = 0) uniform SimpleSceneDescriptionBlock {
SimpleSceneDescription s;
} scene;
layout(binding = 3, set = 0) buffer Materials { Material m[]; } materials;
layout(binding = 4, set = 0) buffer ObjectInstances { Object o[]; } objectInstances;
layout(binding = 5, set = 0) buffer LightSources { LightSource l[]; } lightSources;
layout(binding = 6, set = 0) buffer Vertices { Vertex v[]; } vertices[];
layout(binding = 7, set = 0) buffer Indices { uint i[]; } indices[];
......@@ -49,63 +55,31 @@ void main()
VertexPosition(v1) * barycentrics.y +
VertexPosition(v2) * barycentrics.z;
vec2 texCoord = VertexTexCoord(v0) * barycentrics.x +
VertexTexCoord(v1) * barycentrics.y +
VertexTexCoord(v2) * barycentrics.z;
N = normalize(vec3(obj.transformInverseTranspose * vec4(N, 0.0)));
worldPos = vec3(obj.transformInverseTranspose * vec4(worldPos, 1.0));
LightSource light = scene.s.light;
vec3 res = vec3(0);
vec3 L;
float a;
float tMax;
uint seed = tea(gl_LaunchIDNV.y * gl_LaunchSizeNV.x + gl_LaunchIDNV.x, rngSeed);
if(LightTypeIsDirectional(light))
{
L = LightPosition(light);
a = 1.0;
tMax = RayTMax;
}
else if(LightTypeIsPoint(light)) {
const vec3 camPos = CameraPos(scene.s.camera);
const vec3 toL = LightPosition(light) - worldPos;
const float rayLen = length(toL);
L = normalize(toL);
a = 1.0 / (1 + pow(rayLen, 2));
tMax = rayLen;
}
else {
payload.value = vec3(0);
return;
}
isShadowed = true;
traceNV(topLevelAS,
gl_RayFlagsTerminateOnFirstHitNV | gl_RayFlagsOpaqueNV | gl_RayFlagsSkipClosestHitShaderNV,
0xFF, 0, 0, 1,
gl_WorldRayOriginNV + gl_WorldRayDirectionNV * gl_HitTNV, // ray origin
RayTMin, L, tMax, 1
);
const vec3 ambient = LightColor(light) * MaterialAmbient(mat) * LightAmbientFactor(light);
const vec3 emission = MaterialEmission(mat);
vec3 diffuse = vec3(0);
vec3 specular = vec3(0);
float NDotL = max(dot(N, L), 0.0);
if(NDotL > 0 && !isShadowed)
for(int i = 0; i < MaxLights; i++)
{
diffuse = a * NDotL * LightColor(light) * MaterialDiffuse(mat);
vec3 viewDir = normalize(scene.s.camera.viewInverse[3].xyz - worldPos);
vec3 reflectDir = reflect(-L, N);
LightSource light = scene.s.lights[i];
specular = LightColor(light) * MaterialSpecular(mat) * a * pow(max(dot(viewDir, reflectDir), 0.0), MaterialSpecularExponent(mat));
if(LightEnabled(light) && distance(camPos, LightPosition(light)) < LightEffectiveRange(light)) {
res += CalcLight(light, mat, N, worldPos, camPos, seed);
}
}
payload.value = vec3(
ambient +
emission +
diffuse +
specular
);
float reflectivity = MaterialRefractionIndex(mat) - 1;
vec3 reflection = payload.value;
vec3 texture = texture(texSampler, texCoord).rgb;
payload.value = (MaterialEmission(mat) + reflectivity * reflection + (1 - reflectivity) * res);
}
#include "raycommon.glsl"
#define Softness (0.2)
#define NShadowSamples (4)
#define NGlobalLightSamples (0)
layout(location = 1) rayPayloadInNV bool isShadowed;
layout(binding = 0, set = 0) uniform accelerationStructureNV topLevelAS;
vec3 CalcLight(LightSource light, Material mat, vec3 N, vec3 worldPos, vec3 camPos, uint seed)
{
vec3 L;
float a;
float tMax;
if(LightTypeIsPoint(light))
{
const vec3 toL = LightPosition(light) - worldPos;
const float rayLen = length(toL);
L = normalize(toL);
a = 1.0 / (1 + pow(rayLen, 2));
tMax = rayLen;
}
else
{
L = LightPosition(light);
a = 1.0;
tMax = RayTMax;
}
int nHits = 0;
for(int i = 0; i < NShadowSamples; i++) {
vec2 offset = vec2(rnd(seed), rnd(seed)) * Softness;
isShadowed = true;
traceNV(topLevelAS,
gl_RayFlagsTerminateOnFirstHitNV | gl_RayFlagsOpaqueNV | gl_RayFlagsSkipClosestHitShaderNV,
0xFF, 0, 0, 1,
gl_WorldRayOriginNV + gl_WorldRayDirectionNV * gl_HitTNV, // ray origin
RayTMin, L + vec3(offset.x, 0, offset.y), tMax, 1
);
if(!isShadowed) {
nHits++;
}
}
float hitRate = float(nHits) / float(NShadowSamples);
const vec3 ambient = LightColor(light) * MaterialAmbient(mat) * LightAmbientFactor(light);
vec3 diffuse = vec3(0);
vec3 specular = vec3(0);
float NDotL = max(dot(N, L), 0.0);
if(NDotL > 0 && nHits > 0)
{
diffuse = a * NDotL * LightColor(light) * MaterialDiffuse(mat) * hitRate;
vec3 viewDir = normalize(camPos - worldPos);
vec3 reflectDir = reflect(-L, N);
specular = LightColor(light) * MaterialSpecular(mat) * a * pow(max(dot(viewDir, reflectDir), 0.0), MaterialSpecularExponent(mat)) * hitRate;
}
return ambient + diffuse + specular;
}
\ No newline at end of file
// Quelle: https://github.com/nvpro-samples/vk_raytracing_tutorial/blob/master/ray_tracing_jitter_cam/shaders/random.glsl
// Generate a random unsigned int from two unsigned int values, using 16 pairs
// of rounds of the Tiny Encryption Algorithm. See Zafar, Olano, and Curtis,
// "GPU Random Numbers via the Tiny Encryption Algorithm"
uint tea(uint val0, uint val1)
{
uint v0 = val0;
uint v1 = val1;
uint s0 = 0;
for(uint n = 0; n < 16; n++)
{
s0 += 0x9e3779b9;
v0 += ((v1 << 4) + 0xa341316c) ^ (v1 + s0) ^ ((v1 >> 5) + 0xc8013ea4);
v1 += ((v0 << 4) + 0xad90777d) ^ (v0 + s0) ^ ((v0 >> 5) + 0x7e95761e);
}
return v0;
}
// Generate a random unsigned int in [0, 2^24) given the previous RNG state
// using the Numerical Recipes linear congruential generator
uint lcg(inout uint prev)
{
uint LCG_A = 1664525u;
uint LCG_C = 1013904223u;
prev = (LCG_A * prev + LCG_C);
return prev & 0x00FFFFFF;
}
// Generate a random float in [0, 1) given the previous RNG state
float rnd(inout uint prev)
{
return (float(lcg(prev)) / float(0x01000000));
}
\ No newline at end of file
#ifndef RAYCOMMON_GLSL
#define RAYCOMMON_GLSL
/*
Enthält Strukturen und Funktionen, die von allen anderen Shadern genutzt werden können.
*/
#define MaxLights 8
#define RayTMin 0.001
#define RayTMax 100000.0
/*
* Hit payload.
*/
......@@ -18,15 +24,16 @@ struct Material {
vec4 specular;
vec4 ambient;
vec4 emission;
vec4 specularExponent_refractionIndex_2unused;
vec4 specularExponent_refractionIndex_dissolve_unused;
};
#define MaterialDiffuse(obj) (obj.diffuse.rgb)
#define MaterialSpecular(obj) (obj.specular.rgb)
#define MaterialAmbient(obj) (obj.ambient.rgb)
#define MaterialEmission(obj) (obj.emission.rgb)
#define MaterialSpecularExponent(obj) (obj.specularExponent_refractionIndex_2unused.x)
#define MaterialRefractionIndex(obj) (obj.specularExponent_refractionIndex_2unused.y)
#define MaterialSpecularExponent(obj) (obj.specularExponent_refractionIndex_dissolve_unused.x)
#define MaterialRefractionIndex(obj) (obj.specularExponent_refractionIndex_dissolve_unused.y)
#define MaterialDissolve(obj) (obj.specularExponent_refractionIndex_dissolve_unused.z)
/*
* Vertex, wie lib::Vertex_NoColor_Align16 in GenericVertex.hpp.
......@@ -61,18 +68,20 @@ struct Object
*/
struct LightSource
{
vec4 position;
vec4 color;
vec4 ambientFactor_enabled_type_unused;
vec4 positionXYZ_enabled;
vec4 colorRGB_ambientFactor;
vec4 type_customAttribsXYZ;
};
#define LightPosition(obj) (obj.position.xyz)
#define LightColor(obj) (obj.color.rgb)
#define LightAmbientFactor(obj) (obj.ambientFactor_enabled_type_unused.x)
#define LightEnabled(obj) (obj.ambientFactor_enabled_type_unused.y)
#define LightType(obj) (obj.ambientFactor_enabled_type_unused.z)
#define LightTypeIsDirectional(obj) (obj.ambientFactor_enabled_type_unused.z == 1.0)
#define LightTypeIsPoint(obj) (obj.ambientFactor_enabled_type_unused.z == 0.0)
#define LightPosition(obj) (obj.positionXYZ_enabled.xyz)
#define LightEnabled(obj) (obj.positionXYZ_enabled.w != 0)
#define LightColor(obj) (obj.colorRGB_ambientFactor.rgb)
#define LightAmbientFactor(obj) (obj.colorRGB_ambientFactor.w)
#define LightType(obj) (obj.type_customAttribsXYZ.x)
#define LightEffectiveRange(obj) (1000)
#define LightTypeIsPoint(obj) (obj.type_customAttribsXYZ.x == 0.0)
#define LightTypeIsDirectional(obj) (obj.type_customAttribsXYZ.x == 1.0)
#define LightTypeIsSquare(obj) (obj.type_customAttribsXYZ.x == 2.0)
struct Camera
{
......@@ -82,14 +91,15 @@ struct Camera
mat4 projectionInverse;
};
#define CameraPos(obj) (obj.viewInverse[3].xyz)
struct SimpleSceneDescription
{
Camera camera;
LightSource light;
vec4 clearColor;
vec4 clearColor_1unused;
LightSource lights[MaxLights];
};
#define SceneClearColor(obj) (obj.clearColor.xyz)
#define SceneClearColor(obj) (obj.clearColor_1unused.xyz)
#define RayTMin 0.1
#define RayTMax 100000.0
#endif /*RAYCOMMON_GLSL*/
\ No newline at end of file
#version 460
#extension GL_NV_ray_tracing : require
#extension GL_GOOGLE_include_directive : enable
#include "raycommon.glsl"
#include "common/raycommon.glsl"
layout(location = 0) rayPayloadInNV HitPayload payload;
......
#version 460
#extension GL_GOOGLE_include_directive : enable
layout(location = 0) in vec2 texCoord;
layout(location = 0) out vec4 color;
layout(binding = 0) uniform sampler2D texSampler[4];
void main() {
vec2 offsets[9] = {
{-1, 1}, {0, 1}, {1, 1},
{-1, 0}, {0, 0}, {1, 0},
{-1, -1}, {0, -1}, {1, -1},
};
float edgeDetectKernel[9] = {
0, 1, 0,
1, -4, 1,
0, 1, 0,
};
float blurKernel[9] = {
1.0 / 84.0, 4.0 / 84.0, 1.0 / 84.0,
4.0 / 84.0, 16.0 / 84.0, 4.0 / 84.0,
1.0 / 84.0, 4.0 / 84.0, 1.0 / 84.0,
};
vec2 relativePixelSize = vec2(1.0) / textureSize(texSampler[0], 0);
vec4 samples[9];
for(int i = 0; i < 9; i++) {
samples[i] = texture(texSampler[0], texCoord + offsets[i] * relativePixelSize);
}
vec3 edge = vec3(0);
for(int i = 0; i < 9; i++) {
edge += samples[i].rgb * edgeDetectKernel[i];
}
vec3 blur = vec3(0);
for(int i = 0; i < 9; i++) {
blur += samples[i].rgb * blurKernel[i];
}
float l = length(edge);
vec3 res = vec3(0);
res = l * blur + (1 - l) * samples[5].rgb;
// color = vec4(vec3(samples[5].a * 0.5), 1.0);
color = vec4(res, 1.0);
}
\ No newline at end of file
#version 450
#extension GL_GOOGLE_include_directive : enable
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) out vec2 texCoord;
void main() {
texCoord = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
gl_Position = vec4(texCoord * 2.0 - 1.0, 0.0, 1.0);
}
\ No newline at end of file
......@@ -2,7 +2,13 @@
#extension GL_NV_ray_tracing : require
#extension GL_EXT_scalar_block_layout : enable
#extension GL_GOOGLE_include_directive : enable
#include "raycommon.glsl"
#include "common/raycommon.glsl"
#include "common/random.glsl"
layout(push_constant) uniform Constants
{
uint rngSeed;
};
layout(binding = 0, set = 0) uniform accelerationStructureNV topLevelAS;
layout(binding = 1, set = 0, rgba8) uniform image2D image;
......@@ -12,21 +18,26 @@ layout(binding = 2, set = 0) uniform SimpleSceneDescriptionBlock {
layout(location = 0) rayPayloadNV HitPayload payload;
layout(binding = 8) uniform sampler2D texSampler;
void main()
{
const vec2 inUv = (vec2(gl_LaunchIDNV) + vec2(0.5)) / vec2(gl_LaunchSizeNV.xy);
vec4 origin = scene.s.camera.viewInverse * vec4(0, 0, 0, 1);
vec4 target = scene.s.camera.projectionInverse * vec4(inUv * 2.0 - 1.0, 1, 1);
vec4 direction = scene.s.camera.viewInverse * vec4(normalize(target.xyz), 0);
{
uint rayFlags = gl_RayFlagsOpaqueNV;
uint cullMask = 0xff;
float tMin = 0.001;
float tMax = 10000.0;
uint seed = tea(gl_LaunchIDNV.y * gl_LaunchSizeNV.x + gl_LaunchIDNV.x, rngSeed);
vec2 offset = vec2(rnd(seed), rnd(seed));
const vec2 inUv = (vec2(gl_LaunchIDNV.xy) + offset) / vec2(gl_LaunchSizeNV.xy);
const vec4 origin = scene.s.camera.viewInverse * vec4(0, 0, 0, 1);
const vec4 target = scene.s.camera.projectionInverse * vec4(inUv * 2.0 - 1.0, 1, 1);
const vec4 direction = scene.s.camera.viewInverse * vec4(normalize(target.xyz), 0);
traceNV(topLevelAS, rayFlags, cullMask,
0, 0, 0,
origin.xyz, tMin,
direction.xyz, tMax, 0);
imageStore(image, ivec2(gl_LaunchIDNV.xy), vec4(payload.value, 0));
origin.xyz, RayTMin,
direction.xyz, RayTMax, 0);
vec3 res = payload.value;
imageStore(image, ivec2(gl_LaunchIDNV.xy), vec4(res, length(res)));
}
\ No newline at end of file
\section{Motivation}
\gquote{Ich bin ein Test}, sagte \cite{Haines2019}
\ No newline at end of file
\subsection{Grundlagen}
\ No newline at end of file
\subsection{Hardwareunterstützung}
\ No newline at end of file
\section{Einführung zum Raytracing}
\input{components/2_Raytracing/grundlagen.tex}
\input{components/2_Raytracing/umsetzung.tex}
\input{components/2_Raytracing/hardware.tex}
\ No newline at end of file
\subsection{Umsetzung mit Vulkan und NV\_VK\_RAY\_TRACING}
\ No newline at end of file
\section{Die Rendergleichung und ihre Umsetzung im Raytracing}
\ No newline at end of file
\section{Implementierung eines Raytracers mit Vulkan}
\ No newline at end of file
\section{Godrays/Strahlenbüschel}
\input{components/5_Strahlenbüschel/physik.tex}
\ No newline at end of file
\subsection{Physikalische Grundlagen}
\ No newline at end of file
\section{Implementierung der entwickelten Algorithmen}
\ No newline at end of file
\section{Ergebnisse und Auswertung}
\ No newline at end of file
\section{DummyA}
\section{DummyB}
\ No newline at end of file
\begin{abstract}
\end{abstract}
\ No newline at end of file
%-------------------------------------------------------------------------------------------------------------
% Bibliotheken für tikz
%-------------------------------------------------------------------------------------------------------------
\usetikzlibrary{arrows, arrows.meta, shapes, trees, calc, decorations.pathreplacing, positioning}
%-------------------------------------------------------------------------------------------------------------
% Stile für Tikz
%-------------------------------------------------------------------------------------------------------------
\tikzset{current/.style = {draw, circle, fill=yellow!30, inner sep=1pt, minimum size=6mm}}
\tikzset{unvisited/.style = {draw, circle, fill=white, inner sep=1pt, minimum size=6mm}}
\tikzset{visited/.style = {draw, circle, fill=green!20, inner sep=1pt, minimum size=6mm}}
\tikzset{goodResult/.style = {draw, rectangle, fill=green!30, inner sep=1pt, minimum width=3cm}}
\tikzset{badResult/.style = {draw, rectangle, fill=red!30, inner sep=1pt, minimum width=3cm}}
\tikzset{variableNode/.style = {draw, circle, fill=white, inner sep=1pt, minimum size=6mm}}
\tikzset{currentVariableNode/.style = {draw, circle, fill=green!20, inner sep=1pt, minimum size=6mm}}
\tikzset{activeVariableNode/.style = {draw, circle, fill=orange!20, inner sep=1pt, minimum size=6mm}}
\tikzset{clauseNode/.style = {draw, rectangle, fill=white, inner sep=1pt, minimum size=6mm}}
\tikzset{activeClauseNode/.style = {draw, rectangle, fill=orange!20, inner sep=1pt, minimum size=6mm}}
\tikzset{emptyNode/.style = {inner sep=0pt, outer sep=0pt, anchor=base, baseline}}
%-------------------------------------------------------------------------------------------------------------
% Abkürzungen, Displaystyles, etc.
%-------------------------------------------------------------------------------------------------------------
\newcommand\todo[1]{\textcolor{red}{[#1]}\message{TODO: #1}}
\newcommand\dprod[0]{\displaystyle\prod}
\newcommand\tprod[0]{\textstyle\prod}
\newcommand\dsum[0]{\displaystyle\sum}
\newcommand\tsum[0]{\textstyle\sum}
%-------------------------------------------------------------------------------------------------------------
% Messages
%-------------------------------------------------------------------------------------------------------------
\newcommand\xamsg[4]{
\frac{
\dprod_{b\in N(#1)\setminus #2}m_{b\to #1}^{[#4]}(#3)
}
{
\dprod_{b\in N(#1)\setminus #2}m_{b\to #1}^{[#4]}(1) +
\dprod_{b\in N(#1)\setminus #2}m_{b\to #1}^{[#4]}(0)
}
}
\newcommand\axmsg[3]{
1-\dprod_{y\in N(#1)\setminus #2}m_{y\to #1}^{[#3]}(1-value(y, #1))
}
\newcommand\xmsg[2]{
\frac{
\dprod_{b\in N(#1)}m_{b\to #1}^{[#2]}(1)
}
{
\dprod_{b\in N(#1)}m_{b\to #1}^{[#2]}(1) +
\dprod_{b\in N(#1)}m_{b\to #1}^{[#2]}(0)
}
}
\newcommand\xamsgempty{
\frac{
\dprod_{\emptyset}
}
{
\dprod_{\emptyset} +
\dprod_{\emptyset}
}
}
%-------------------------------------------------------------------------------------------------------------
% true/false
%-------------------------------------------------------------------------------------------------------------
\newcommand\true{\textit{wahr}}
\newcommand\false{\textit{falsch}}
%-------------------------------------------------------------------------------------------------------------
% besondere Elemente für tikz
%-------------------------------------------------------------------------------------------------------------
\newcommand\connection[3][]{
\ifthenelse
{
\equal{#1}{}
}
{
\draw (#2) -- (#3);
}
{
\draw (#2) -- (#3) node[midway, fill=white] {\small{#1}};
}
}
\newcommand\negConnection[3][]{
\ifthenelse
{
\equal{#1}{}
}
{
\draw[dashed] (#2) -- (#3);
}
{
\draw[dashed] (#2) -- (#3) node[midway, fill=white] {\small{#1}};
}
}
\newcommand\fadingConnection[3][]{
\ifthenelse
{
\equal{#1}{}
}
{
\draw[dash pattern=on 1cm off 0.1cm on 0.1cm off 0.05cm on 0.05cm off 0.05cm on 0.05cm off 5cm] (#2) -- (#3);
}
{
\draw[dash pattern=on 1cm off 0.1cm on 0.1cm off 0.05cm on 0.05cm off 0.05cm on 0.05cm off 5cm] (#2) -- (#3) node[near start, fill=white] {\small{#1}};
}
}
\newcommand\arrowconnection[3][]{
\ifthenelse
{
\equal{#1}{}
}
{
\draw[draw, -latex] (#2) -- (#3);
}
{
\draw[draw, -latex] (#2) -- (#3) node[midway, fill=white] {\small{#1}};
}
}
%-------------------------------------------------------------------------------------------------------------
% Seitenumbrüche und abstract Title
%-------------------------------------------------------------------------------------------------------------
\newcommand\emptypage{
\newpage\null\thispagestyle{empty}\newpage
}
\newcommand\file[1]{
\texttt{#1}
}
\ifcsname abstitlestyle\endcsname
\renewcommand{\abstitlestyle}[1]{\centering\Large{\textbf{#1}}}
\fi
\ifcsname\glossaryname\endcsname
\renewcommand*{\glossaryname}{Glossar}
\fi
\newcommand\gquote[1]{\glqq#1\grqq}
\sisetup{
output-decimal-marker = {,}
}
\ No newline at end of file
\begin{center}
\includegraphics[width=0.75\textwidth]{data/icons/TU_Chemnitz_positiv_gruen.eps}
\\
\large{Fakultät für Informatik}
\\
\small{Professur Grafische Datenverarbeitung}
\\
\vspace*{1.5cm}
\Huge{Masterarbeit}
\\
\Large{Darstellung von Godrays mit Raytracing}
\\
\vspace{2cm}
Lukas Tietze
\\
Chemnitz, den \today
\\
\vspace{3cm}
\textbf{1. Prüfer: }Prof. Dr. Guido Brunnett \\
\textbf{2. Prüfer: }Daniel Rösner, M.Sc.\\
\end{center}
@book{Haines2019,
title = {Ray Tracing Gems},
editor = {Eric Haines and Tomas Akenine-M\"oller},
publisher = {Apress},
year = {2019},
note ={\url{http://raytracinggems.com}},
}
\ No newline at end of file
\newglossaryentry{Ray}{name={Ray},description={Ein Ray ist ein Strahl, definiert durch Startpunkt und Richtung.}}
\ No newline at end of file
% \documentclass[twoside, openright, 11pt, a4paper]{article}
\documentclass[11pt,a4paper]{article}
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{xifthen}
\usepackage[onehalfspacing]{setspace}
\usepackage{cite}
\usepackage{subcaption}
\usepackage{ngerman}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{algorithmicx}
\usepackage[Algorithmus]{algorithm}
\usepackage{algpseudocode}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{pdfpages}
\usepackage[numberedsection, nonumberlist]{glossaries}
\usepackage{gnuplot-lua-tikz}
\usepackage{chngcntr}
\usepackage[style]{abstract}
\usepackage[hidelinks]{hyperref}
%------------------------------
% Initialisierung
%------------------------------
\pdfminorversion=7
\counterwithin{figure}{section}
\counterwithin{table}{section}
\counterwithin{equation}{section}
\counterwithin{algorithm}{section}
\setcounter{secnumdepth}{3}
\input{components/commands.tex}
\makeglossaries
\loadglsentries{data/glossary.tex}
\glsaddall
\begin{document}
%------------------------------
% Titel
%------------------------------
\pagenumbering{gobble}
\thispagestyle{empty}
\input{components/title.tex}
\emptypage
%------------------------------
% Einleitung & Referenzen
%------------------------------
\pagenumbering{roman}
\input{components/abstract.tex}
\tableofcontents
\clearpage
\listoffigures
\clearpage
\listoftables
% \clearpage
% \printglossaries
%------------------------------
% Inhalt
%------------------------------
\pagenumbering{arabic}
\cleardoublepage
\input{components/1_Einführung/part.tex}
\input{components/2_Raytracing/part.tex}
\input{components/3_Rendergleichung/part.tex}
\input{components/4_Grundgerüst/part.tex}
\input{components/5_Strahlenbüschel/part.tex}
\input{components/6_Implementierung/part.tex}
\input{components/7_Auswertung/part.tex}
%------------------------------
% Anhänge
%------------------------------
\appendix
\input{components/X_Anhänge/part.tex}
\printglossaries[type=main, title={Glossar}]
\clearpage
\bibliographystyle{amsplain}
\bibliography{data/bibliography.bib}
\clearpage
\includepdf{data/statement_of_authorship.pdf}
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Common style file for TeX, LaTeX and ConTeXt
%%
%% It is associated with the 'gnuplot.lua' script, and usually generated
%% automatically. So take care whenever you make any changes!
%%
% check for the correct TikZ version
\def\gpchecktikzversion#1.#2\relax{%
\ifnum#1<2%
\errmessage{PGF/TikZ version >= 2.0 is required!}%
\fi}
\expandafter\gpchecktikzversion\pgfversion\relax
% FIXME: is there a more elegant way to determine the output format?
\def\pgfsysdriver@a{pgfsys-dvi.def} % ps
\def\pgfsysdriver@b{pgfsys-dvipdfm.def} % pdf
\def\pgfsysdriver@c{pgfsys-dvipdfmx.def} % pdf
\def\pgfsysdriver@d{pgfsys-dvips.def} <