Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Courses
Scotty3D
Commits
f959bd58
Commit
f959bd58
authored
Oct 13, 2020
by
TheNumbat
Browse files
pathtracer adjustments
parent
11754c5c
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/gui/manager.h
View file @
f959bd58
...
...
@@ -89,7 +89,7 @@ private:
void
frame
(
Scene
&
scene
,
Camera
&
cam
);
static
inline
const
char
*
scene_file_types
=
"dae,obj,fbx,glb,gltf,3ds,blend,stl,ply"
;
static
inline
const
char
*
image_file_types
=
"exr,jpg,jpeg,png,tga,bmp,psd,gif"
;
static
inline
const
char
*
image_file_types
=
"exr,
hdr,hdri,
jpg,jpeg,png,tga,bmp,psd,gif"
;
void
render_selected
(
Scene_Object
&
obj
);
void
load_scene
(
Scene
&
scene
,
Undo
&
undo
,
bool
clear
);
...
...
src/gui/widgets.cpp
View file @
f959bd58
...
...
@@ -635,7 +635,7 @@ std::string Widget_Render::step(Animate &animate, Scene &scene) {
return
"Failed to write output!"
;
}
pathtracer
.
begin_render
(
scene
,
cam
,
true
);
pathtracer
.
begin_render
(
scene
,
cam
);
next_frame
++
;
}
}
...
...
src/rays/pathtracer.cpp
View file @
f959bd58
...
...
@@ -20,35 +20,6 @@ Pathtracer::Pathtracer(Gui::Widget_Render &gui, Vec2 screen_dim)
Pathtracer
::~
Pathtracer
()
{
thread_pool
.
stop
();
}
void
Pathtracer
::
refit_scene
(
Scene
&
layout_scene
)
{
std
::
unordered_map
<
Scene_ID
,
Object
>
obj_map
;
std
::
vector
<
Object
>
objs
=
scene
.
destructure
();
for
(
auto
&
o
:
objs
)
obj_map
.
insert
({
o
.
id
(),
std
::
move
(
o
)});
std
::
set
<
Scene_ID
>
light_ids
;
for
(
auto
&
l
:
lights
)
light_ids
.
insert
(
l
.
id
());
layout_scene
.
for_items
([
&
](
const
Scene_Item
&
item
)
{
auto
entry
=
obj_map
.
find
(
item
.
id
());
if
(
entry
!=
obj_map
.
end
())
{
entry
->
second
.
set_trans
(
item
.
pose
().
transform
());
if
(
light_ids
.
count
(
entry
->
first
))
{
obj_map
.
erase
(
entry
);
}
}
});
objs
.
clear
();
for
(
auto
&
o
:
obj_map
)
objs
.
push_back
(
std
::
move
(
o
.
second
));
build_lights
(
layout_scene
,
objs
);
scene
.
build
(
std
::
move
(
objs
));
}
void
Pathtracer
::
build_lights
(
Scene
&
layout_scene
,
std
::
vector
<
Object
>
&
objs
)
{
lights
.
clear
();
...
...
@@ -160,7 +131,7 @@ void Pathtracer::build_scene(Scene &layout_scene) {
obj_list
.
push_back
(
Object
(
std
::
move
(
shape
),
obj
.
id
(),
idx
,
obj
.
pose
.
transform
()));
}
else
{
Tri_Mesh
mesh
(
obj
.
posed_mesh
());
Tri_Mesh
mesh
(
obj
.
posed_mesh
()
,
obj
.
get_mesh
().
flipped
()
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
obj_mut
);
obj_list
.
push_back
(
Object
(
std
::
move
(
mesh
),
obj
.
id
(),
idx
,
obj
.
pose
.
transform
()));
...
...
@@ -236,7 +207,7 @@ size_t Pathtracer::visualize_bvh(GL::Lines &lines, GL::Lines &active, size_t dep
return
scene
.
visualize
(
lines
,
active
,
depth
,
Mat4
::
I
);
}
void
Pathtracer
::
begin_render
(
Scene
&
layout_scene
,
const
Camera
&
cam
,
bool
refit
)
{
void
Pathtracer
::
begin_render
(
Scene
&
layout_scene
,
const
Camera
&
cam
)
{
size_t
n_threads
=
std
::
thread
::
hardware_concurrency
();
size_t
samples_per_epoch
=
std
::
max
(
size_t
(
1
),
n_samples
/
(
n_threads
*
10
));
...
...
@@ -247,10 +218,7 @@ void Pathtracer::begin_render(Scene &layout_scene, const Camera &cam, bool refit
total_epochs
=
n_samples
/
samples_per_epoch
+
!!
(
n_samples
%
samples_per_epoch
);
build_time
=
SDL_GetPerformanceCounter
();
if
(
refit
)
refit_scene
(
layout_scene
);
else
build_scene
(
layout_scene
);
build_scene
(
layout_scene
);
render_time
=
SDL_GetPerformanceCounter
();
build_time
=
render_time
-
build_time
;
...
...
src/rays/pathtracer.h
View file @
f959bd58
...
...
@@ -32,7 +32,7 @@ public:
const
GL
::
Tex2D
&
get_output_texture
(
float
exposure
);
size_t
visualize_bvh
(
GL
::
Lines
&
lines
,
GL
::
Lines
&
active
,
size_t
level
);
void
begin_render
(
Scene
&
scene
,
const
Camera
&
camera
,
bool
refit
=
false
);
void
begin_render
(
Scene
&
scene
,
const
Camera
&
camera
);
void
cancel
();
bool
in_progress
()
const
;
float
progress
()
const
;
...
...
@@ -41,7 +41,6 @@ public:
private:
// Internal
void
build_scene
(
Scene
&
scene
);
void
refit_scene
(
Scene
&
scene
);
void
build_lights
(
Scene
&
scene
,
std
::
vector
<
Object
>
&
objs
);
void
do_trace
(
size_t
samples
);
void
accumulate
(
const
HDR_Image
&
sample
);
...
...
src/rays/tri_mesh.h
View file @
f959bd58
...
...
@@ -32,7 +32,7 @@ private:
class
Tri_Mesh
{
public:
Tri_Mesh
()
=
default
;
Tri_Mesh
(
const
GL
::
Mesh
&
mesh
);
Tri_Mesh
(
const
GL
::
Mesh
&
mesh
,
bool
flip
=
false
);
BBox
bbox
()
const
;
Trace
hit
(
const
Ray
&
ray
)
const
;
...
...
@@ -44,6 +44,7 @@ public:
private:
std
::
vector
<
Tri_Mesh_Vert
>
verts
;
BVH
<
Triangle
>
triangles
;
bool
flip_normals
=
false
;
};
}
// namespace PT
src/student/shapes.cpp
View file @
f959bd58
...
...
@@ -25,6 +25,10 @@ Trace Sphere::hit(const Ray &ray) const {
// but only the _later_ one is within ray.time_bounds, you should
// return that one!
// Note: ray.dir is not necessarily a unit vector if this object has a scale transform.
// If you want it to be so, you should use ray.dir.unit(), and also note that you will
// have to re-scale ret.time to be the distance along the original non-unit ray.dir.
Trace
ret
;
ret
.
hit
=
false
;
// was there an intersection?
ret
.
time
=
0.0
f
;
// at what time did the intersection occur?
...
...
src/student/tri_mesh.cpp
View file @
f959bd58
...
...
@@ -57,11 +57,15 @@ void Tri_Mesh::build(const GL::Mesh &mesh) {
triangles
.
build
(
std
::
move
(
tris
),
4
);
}
Tri_Mesh
::
Tri_Mesh
(
const
GL
::
Mesh
&
mesh
)
{
build
(
mesh
);
}
Tri_Mesh
::
Tri_Mesh
(
const
GL
::
Mesh
&
mesh
,
bool
flip
)
{
build
(
mesh
);
flip_normals
=
flip
;
}
BBox
Tri_Mesh
::
bbox
()
const
{
return
triangles
.
bbox
();
}
Trace
Tri_Mesh
::
hit
(
const
Ray
&
ray
)
const
{
return
triangles
.
hit
(
ray
);
}
Trace
Tri_Mesh
::
hit
(
const
Ray
&
ray
)
const
{
Trace
t
=
triangles
.
hit
(
ray
);
if
(
flip_normals
)
t
.
normal
=
-
t
.
normal
;
return
t
;
}
size_t
Tri_Mesh
::
visualize
(
GL
::
Lines
&
lines
,
GL
::
Lines
&
active
,
size_t
level
,
const
Mat4
&
trans
)
const
{
...
...
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