Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CppRaytracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yoel
CppRaytracer
Commits
0973a0f9
Commit
0973a0f9
authored
3 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Small scene fix
parent
1132a058
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
RayTracer/sampling/Scene.cpp
+6
-5
6 additions, 5 deletions
RayTracer/sampling/Scene.cpp
with
6 additions
and
5 deletions
RayTracer/sampling/Scene.cpp
+
6
−
5
View file @
0973a0f9
...
...
@@ -26,19 +26,20 @@ util::Vec3 Scene::calculateRadiance(const cam::Ray& r, size_t depth) const {
if
(
depth
==
0
)
return
util
::
Vec3
(
0
);
std
::
optional
<
cam
::
Hit
>
h
=
group
.
intersect
(
r
);
assert
(
h
);
auto
scatter_ray
=
h
->
scattered_ray
(
r
);
// If the material does not scatter, return
if
(
!
scatter_ray
)
{
// if we are at the first depth, we have to count the materials emission
// as we did not account for it with directLightning
if
(
direct
)
{
if
(
this
->
max_depth
==
depth
)
return
h
->
emission
();
if
(
max_depth
==
depth
)
return
h
->
emission
();
return
util
::
Vec3
(
0
);
}
else
return
h
->
emission
();
}
auto
brdf
=
h
->
calculateLightMultiplier
(
-
scatter_ray
->
d
,
-
r
.
d
,
h
->
normal
());
auto
L
=
calculateRadiance
(
scatter_ray
.
value
(),
depth
-
1
);
auto
L
_i
=
calculateRadiance
(
scatter_ray
.
value
(),
depth
-
1
);
auto
cosine_term
=
util
::
dot
(
h
->
normal
(),
scatter_ray
->
d
.
normalize
());
// This can not happen
if
(
cosine_term
<=
0
)
{
...
...
@@ -46,15 +47,15 @@ util::Vec3 Scene::calculateRadiance(const cam::Ray& r, size_t depth) const {
}
auto
brdf_pdf
=
h
->
material
->
brdf_pdf
(
scatter_ray
->
d
,
h
->
normal
());
auto
scatter_function
=
(
brdf
*
L
*
cosine_term
)
/
brdf_pdf
;
auto
scatter_function
=
(
brdf
*
L
_i
*
cosine_term
)
/
brdf_pdf
;
util
::
Vec3
L_direct
;
if
(
direct
)
L_direct
=
directLighting
(
h
,
r
,
light_n
);
else
L_direct
=
util
::
Vec3
(
0
);
return
h
->
albedo
()
*
(
scatter_function
+
L_direct
);
auto
L_e
=
(
max_depth
==
depth
)
?
h
->
emission
()
:
util
::
Vec3
(
0
);
return
L_e
+
(
h
->
albedo
()
*
(
scatter_function
+
L_direct
)
)
;
}
util
::
Vec3
Scene
::
directLighting
(
const
std
::
optional
<
cam
::
Hit
>&
h
,
cam
::
Ray
r
,
int
n
)
const
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment