Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johannes Braun
glare
Commits
2240be3b
Commit
2240be3b
authored
Sep 05, 2017
by
Johannes Braun
Browse files
Fixed GBuffer PT ray generator
parent
53ba3c7b
Changes
12
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
2240be3b
build_VS
.vs
.idea
.vscode
.vscode
build
assets/screenshots/*
assets/meshes/*
assets/textures/*
!assets/screenshots/Readme.md
!assets/textures/ryfjallet
!assets/screenshots/Readme.md
!assets/textures/ryfjallet
!assets/textures/splash.png
!assets/textures/bricky.png
!assets/textures/bricky.png
*.hdr
bin/*.exe
bin/*.ilk
bin/*.pdb
\ No newline at end of file
bin/*.pdb
bin/*.lib
bin/*.exe.manifest
\ No newline at end of file
CMakeLists.txt
View file @
2240be3b
cmake_minimum_required
(
VERSION 3.
8
)
cmake_minimum_required
(
VERSION 3.
2
)
set
(
BINARY_DIR_REL
"
${
PROJECT_SOURCE_DIR
}
/bin/"
)
set
(
BINARY_DIR_DBG
"
${
BINARY_DIR_REL
}
"
)
...
...
assets/imgui/config.ini
View file @
2240be3b
...
...
@@ -4,12 +4,12 @@ Size=353,64
Collapsed
=
0
[Scene]
Pos
=
0
,6
4
Pos
=
-3
,6
6
Size
=
352,837
Collapsed
=
0
[Settings]
Pos
=
113
0,0
Pos
=
113
2,-3
Size
=
311,899
Collapsed
=
0
assets/preferences/pathtracer_default.xml
View file @
2240be3b
...
...
@@ -16,6 +16,6 @@
<item
name=
"distance"
value=
"25"
/>
</group>
<item
name=
"clamp-direct"
value=
"
8
"
/>
<item
name=
"clamp-indirect"
value=
"
8
"
/>
<item
name=
"clamp-direct"
value=
"
10.f
"
/>
<item
name=
"clamp-indirect"
value=
"
10.f
"
/>
</pathtracer>
assets/shaders/pathtracer/generators/gbuffer/depthtest.comp
View file @
2240be3b
...
...
@@ -12,17 +12,10 @@ layout(rgba32f) uniform image2DMS u_gbuffer_texture_01;
layout(rgba32f) uniform image2D u_render_target;
uniform Camera u_camera;
uniform int random_seed;
uniform int samples;
layout(local_size_variable) in;
void resetImportance(uint id)
{
traces_data[id].properties.accuracy_importance = 1.f;
traces_data[id].properties.shadow_importance = 1.f;
traces_data[id].properties.bounce_amount = 0;
traces_data[id].properties.travelled_distance = 0;
}
void main()
{
uint id = gl_GlobalInvocationID.x;
...
...
@@ -30,22 +23,17 @@ void main()
if (id < traces_data.length())
{
ivec2 target_size = u_render_target.imageSize();
vec2
pixel = vec2(id%
target_size.x
, id/
target_size.
x
);
int random_sample = random_seed % 8 + int(id
);
vec2
random = rand2D(random_seed + int(id),
target_size.x
*
target_size.
y
);
vec2 pixel = vec2(id%target_size.x, id/target_size.x) + random;
vec4 texel_01 = u_gbuffer_texture_01.imageLoad(ivec2(pixel), int(random.x * samples)
);
vec4 texel_01 = u_gbuffer_texture_01.imageLoad(ivec2(pixel), random_sample);
traces_data[id].ray = u_camera.getRayFromPixel(pixel, rand2D(random_seed + int(id), target_size.x * target_size.y), vec2(target_size));
traces_data[id].ray = u_camera.getRayFromPixel(pixel, random, vec2(target_size));
traces_data[id].hit.invalidate();
if (length(texel_01) != 0) {
traces_data[id].hit.barycentric = texel_01.xy;
traces_data[id].hit.triangle = uint(texel_01.z);
traces_data[id].hit.mesh = uint(texel_01.w);
}
resetImportance(id);
}
}
assets/shaders/util/math/random.glsl
View file @
2240be3b
...
...
@@ -76,6 +76,15 @@ vec3 randUniformSphere(vec2 rand)
return
randUniformSphere
(
rand
.
x
,
rand
.
y
);
}
vec2
randUnitDisk
(
float
u
,
float
v
,
float
radius
)
{
// Sample a point on a unit disk
float
r
=
sqrt
(
u
);
float
theta
=
2
*
PI
*
v
;
float
x
=
radius
*
r
*
cos
(
theta
);
float
y
=
radius
*
r
*
sin
(
theta
);
return
vec2
(
x
,
y
);
}
vec3
randDisk
(
float
u
,
float
v
,
vec3
normal
,
float
radius
)
{
// Sample a point on a unit disk
...
...
src/libraries/core/base/framebuffer.h
View file @
2240be3b
...
...
@@ -45,6 +45,11 @@ namespace glare::core
unsigned
attachments
()
const
;
unsigned
samples
()
const
;
unsigned
id
()
const
{
return
m_handle
;
}
private:
void
putAttachment
(
gl
::
Attachment
attachment
,
unsigned
texture
);
...
...
src/libraries/core/base/texture.cpp
View file @
2240be3b
...
...
@@ -16,6 +16,9 @@ namespace glare::core
{
m_latest_parameters
=
std
::
move
(
parameters
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eBaseLevel
,
m_latest_parameters
.
base_level
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eMaxLevel
,
m_latest_parameters
.
max_level
);
float
anisotropy
=
m_latest_parameters
.
anisotropy
;
if
(
anisotropy
==
-
1.
f
)
gl
::
getFloatv
(
gl
::
GetParameter
::
eMaxTextureMaxAnisotropy
,
&
anisotropy
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eMaxAnisotropy
,
anisotropy
);
...
...
@@ -28,9 +31,6 @@ namespace glare::core
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eCompareMode
,
m_latest_parameters
.
compare_mode
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eCompareFunc
,
m_latest_parameters
.
compare_func
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eBaseLevel
,
m_latest_parameters
.
base_level
);
gl
::
textureParameter
(
m_handle
,
gl
::
TextureParameter
::
eMaxLevel
,
m_latest_parameters
.
max_level
);
gl
::
generateTextureMipmap
(
m_handle
);
}
...
...
src/libraries/core/res/preferences.h
0 → 100644
View file @
2240be3b
#ifndef INCLUDE_PREFERENCES_H
#define INCLUDE_PREFERENCES_H
#include <sstream>
#include <pugixml/pugixml.hpp>
#include <util/files.h>
namespace
glare
::
core
{
struct
Preferences
{
Preferences
(
fs
::
path
path
)
:
m_path
(
path
)
{
m_document
.
load_file
(
path
.
c_str
());
}
void
apply
()
const
{
m_document
.
save_file
(
m_path
.
c_str
());
}
void
reload
()
{
m_document
.
load_file
(
m_path
.
c_str
());
}
const
pugi
::
xml_attribute
operator
[](
const
std
::
string
&
name
)
const
{
std
::
istringstream
iss
(
name
);
std
::
vector
<
std
::
string
>
tokens
;
std
::
string
token
;
std
::
string
last_token
=
""
;
pugi
::
xml_node
current
=
m_document
.
root
().
first_child
();
while
(
std
::
getline
(
iss
,
token
,
'/'
))
{
if
(
last_token
!=
""
)
{
current
=
current
.
find_child_by_attribute
(
"group"
,
"name"
,
last_token
.
c_str
());
}
if
(
!
token
.
empty
())
last_token
=
token
;
}
current
=
current
.
find_child_by_attribute
(
"item"
,
"name"
,
last_token
.
c_str
());
auto
attr
=
current
.
attribute
(
"value"
);
return
attr
;
}
pugi
::
xml_attribute
operator
[](
const
std
::
string
&
name
)
{
std
::
istringstream
iss
(
name
);
std
::
vector
<
std
::
string
>
tokens
;
std
::
string
token
;
std
::
string
last_token
=
""
;
pugi
::
xml_node
current
=
m_document
.
root
().
first_child
();
while
(
std
::
getline
(
iss
,
token
,
'/'
))
{
if
(
last_token
!=
""
)
{
auto
next
=
current
.
find_child_by_attribute
(
"group"
,
"name"
,
last_token
.
c_str
());
if
(
!
next
)
{
current
=
current
.
append_child
(
"group"
);
current
.
append_attribute
(
"name"
).
set_value
(
last_token
.
c_str
());
}
else
{
current
=
next
;
}
}
if
(
!
token
.
empty
())
last_token
=
token
;
}
auto
next
=
current
.
find_child_by_attribute
(
"item"
,
"name"
,
last_token
.
c_str
());
if
(
!
next
)
{
current
=
current
.
append_child
(
"item"
);
current
.
append_attribute
(
"name"
).
set_value
(
last_token
.
c_str
());
}
else
{
current
=
next
;
}
auto
attr
=
current
.
attribute
(
"value"
);
if
(
!
attr
)
attr
=
current
.
append_attribute
(
"value"
);
return
attr
;
}
template
<
typename
T
>
void
set
(
const
std
::
string
&
name
,
T
&&
value
)
{
(
*
this
)[
name
]
=
value
;
}
private:
fs
::
path
m_path
;
pugi
::
xml_document
m_document
;
};
}
#endif // !INCLUDE_PREFERENCES_H
\ No newline at end of file
src/libraries/core/state.cpp
View file @
2240be3b
...
...
@@ -12,6 +12,7 @@
#include "time.h"
#include "objects/skybox.h"
#include "objects/camera.h"
#include "res/preferences.h"
namespace
glare
::
core
{
...
...
@@ -65,21 +66,19 @@ namespace glare::core
void
Context
::
initialize
(
const
fs
::
path
&
preferences
)
{
pugi
::
xml_document
preferences_file
;
preferences_file
.
load_file
(
preferences
.
c_str
());
core
::
Preferences
context_preferences
(
preferences
);
// BASIC CONFIG
const
auto
config_child
=
preferences_file
.
child
(
"settings"
).
find_child_by_attribute
(
"group"
,
"name"
,
"config"
);
const
unsigned
window_width
=
config_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"window_size_x"
).
attribute
(
"value"
).
as_uint
(
1280
);
const
unsigned
window_height
=
config_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"window_size_y"
).
attribute
(
"value"
).
as_uint
(
720
);
const
unsigned
samples
=
config_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"msaa"
).
attribute
(
"value"
).
as_uint
(
4
);
const
std
::
string
window_title
=
config_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"window_title"
).
attribute
(
"value"
).
as_string
(
"GLARE"
);
const
std
::
string
splash_preferences
=
preferences_file
.
child
(
"settings"
).
find_child_by_attribute
(
"item"
,
"name"
,
"splash_screen"
).
attribute
(
"value"
).
as_string
();
const
unsigned
window_width
=
context_preferences
[
"config/window_size_x"
].
as_uint
(
1280
);
const
unsigned
window_height
=
context_preferences
[
"config/window_size_y"
].
as_uint
(
720
);
const
unsigned
samples
=
context_preferences
[
"config/msaa"
].
as_uint
(
4
);
const
std
::
string
window_title
=
context_preferences
[
"config/window_title"
].
as_string
(
"GLARE"
);
const
std
::
string
splash_preferences
=
context_preferences
[
"splash_screen"
].
as_string
();
initialize
(
window_width
,
window_height
,
samples
,
window_title
);
m_window
.
makeCurrent
();
const
VSync
vsync
=
static_cast
<
VSync
>
(
con
fig_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"vsync"
).
attribute
(
"value"
)
.
as_uint
(
0
));
const
VSync
vsync
=
static_cast
<
VSync
>
(
con
text_preferences
[
"config/vsync"
]
.
as_uint
(
0
));
m_window
.
setVSync
(
vsync
);
if
(
!
splash_preferences
.
empty
()
&&
m_current_context
==
this
)
...
...
src/libraries/raytrace/tracer/pathtracer.cpp
View file @
2240be3b
...
...
@@ -3,6 +3,7 @@
#include <pugixml/pugixml.hpp>
#include <core/rendering/texture_renderer.h>
#include <util/files.h>
#include <core/res/preferences.h>
namespace
glare
::
raytrace
{
...
...
@@ -38,32 +39,26 @@ namespace glare::raytrace
void
Pathtracer
::
loadSettings
(
const
fs
::
path
&
xml_file
)
{
pugi
::
xml_document
preferences_file
;
Log_Info
<<
"Pathtracer settings file load status: "
<<
preferences_file
.
load_file
(
xml_file
.
c_str
()).
description
();
//Pathtracer
const
auto
pt_child
=
preferences_file
.
child
(
"pathtracer"
);
core
::
Preferences
pt_preferences
(
xml_file
);
//bounces
const
auto
bounces_child
=
pt_child
.
find_child_by_attribute
(
"group"
,
"name"
,
"bounces"
);
m_bounce_thresholds
[
Effect
::
eDiffusion
]
=
static_cast
<
uint8_t
>
(
bounces_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"diffusion"
).
attribute
(
"value"
).
as_uint
(
2
));
m_bounce_thresholds
[
Effect
::
eReflection
]
=
static_cast
<
uint8_t
>
(
bounces_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"reflection"
).
attribute
(
"value"
).
as_uint
(
4
));
m_bounce_thresholds
[
Effect
::
eTransmission
]
=
static_cast
<
uint8_t
>
(
bounces_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"transmission"
).
attribute
(
"value"
).
as_uint
(
4
));
m_bounce_thresholds
[
Effect
::
eEmission
]
=
static_cast
<
uint8_t
>
(
bounces_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"emission"
).
attribute
(
"value"
).
as_uint
(
8
));
m_bounce_thresholds
[
Effect
::
eDiffusion
]
=
pt_preferences
[
"bounces/diffusion"
].
as_uint
(
2
);
m_bounce_thresholds
[
Effect
::
eReflection
]
=
pt_preferences
[
"bounces/reflection"
].
as_uint
(
4
);
m_bounce_thresholds
[
Effect
::
eTransmission
]
=
pt_preferences
[
"bounces/transmission"
].
as_uint
(
4
);
m_bounce_thresholds
[
Effect
::
eEmission
]
=
pt_preferences
[
"bounces/emission"
].
as_uint
(
8
);
//ls thresholds
const
auto
ls_thresholds_child
=
pt_child
.
find_child_by_attribute
(
"group"
,
"name"
,
"ls-thresholds"
);
m_linespace_bounces
[
Effect
::
eDiffusion
]
=
static_cast
<
uint8_t
>
(
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"diffusion"
).
attribute
(
"value"
).
as_uint
(
2
));
m_linespace_bounces
[
Effect
::
eReflection
]
=
static_cast
<
uint8_t
>
(
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"reflection"
).
attribute
(
"value"
).
as_uint
(
4
));
m_linespace_bounces
[
Effect
::
eTransmission
]
=
static_cast
<
uint8_t
>
(
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"transmission"
).
attribute
(
"value"
).
as_uint
(
4
));
m_linespace_bounces
[
Effect
::
eEmission
]
=
static_cast
<
uint8_t
>
(
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"emission"
).
attribute
(
"value"
).
as_uint
(
8
));
m_linespace_distance
=
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"distance"
).
attribute
(
"value"
).
as_float
(
10.
f
);
m_linespace_accuracy
=
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"accuracy"
).
attribute
(
"value"
).
as_float
(
0.5
f
);
m_linespace_shadow
=
ls_thresholds_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"shadow"
).
attribute
(
"value"
).
as_float
(
0.5
f
);
m_clamp_direct
=
pt_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"clamp-direct"
).
attribute
(
"value"
).
as_float
(
8
);
m_clamp_indirect
=
pt_child
.
find_child_by_attribute
(
"item"
,
"name"
,
"clamp-indirect"
).
attribute
(
"value"
).
as_float
(
8
);
m_linespace_bounces
[
Effect
::
eDiffusion
]
=
pt_preferences
[
"ls-thresholds/diffusion"
].
as_uint
(
2
);
m_linespace_bounces
[
Effect
::
eReflection
]
=
pt_preferences
[
"ls-thresholds/reflection"
].
as_uint
(
4
);
m_linespace_bounces
[
Effect
::
eTransmission
]
=
pt_preferences
[
"ls-thresholds/transmission"
].
as_uint
(
4
);
m_linespace_bounces
[
Effect
::
eEmission
]
=
pt_preferences
[
"ls-thresholds/emission"
].
as_uint
(
8
);
m_linespace_distance
=
pt_preferences
[
"ls-thresholds/distance"
].
as_float
(
10.
f
);
m_linespace_accuracy
=
pt_preferences
[
"ls-thresholds/accuracy"
].
as_float
(
0.5
f
);
m_linespace_shadow
=
pt_preferences
[
"ls-thresholds/shadow"
].
as_float
(
0.5
f
);
m_clamp_direct
=
pt_preferences
[
"clamp-direct"
].
as_float
(
8.
f
);
m_clamp_indirect
=
pt_preferences
[
"clamp-indirect"
].
as_float
(
8.
f
);
}
void
Pathtracer
::
reset
()
...
...
src/libraries/raytrace/tracer/raygenerator.cpp
View file @
2240be3b
...
...
@@ -63,7 +63,7 @@ namespace glare::raytrace
if
(
updated_size
)
{
framebuffer
=
std
::
make_unique
<
core
::
Framebuffer
>
(
pathtracer
.
width
(),
pathtracer
.
height
(),
8
);
framebuffer
->
attach
(
gl
::
Attachment
::
eColor0
);
framebuffer
->
attach
(
gl
::
Attachment
::
eDepth
Stencil
);
framebuffer
->
attach
(
gl
::
Attachment
::
eDepth
);
}
generator_program
->
use
();
...
...
@@ -95,6 +95,7 @@ namespace glare::raytrace
depthtest_program
->
use
();
depthtest_program
->
uniform
(
"u_gbuffer_texture_01"
,
framebuffer
->
attachment
(
gl
::
Attachment
::
eColor0
).
imageAddress
(
gl
::
Access
::
eReadOnly
));
depthtest_program
->
uniform
(
"u_render_target"
,
pathtracer
.
renderTarget
().
imageAddress
(
gl
::
Access
::
eReadWrite
));
depthtest_program
->
uniform
(
"samples"
,
pathtracer
.
renderTarget
().
samples
());
depthtest_program
->
storageBuffer
(
"trace_buffer"
,
pathtracer
.
traceBuffer
());
pathtracer
.
collector
()
->
apply
(
*
depthtest_program
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment