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
c40617e9
Commit
c40617e9
authored
3 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
direct lighting fixes
parent
0973a0f9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/sampling/Scene.cpp
+17
-15
17 additions, 15 deletions
RayTracer/sampling/Scene.cpp
RayTracer/sampling/Scene.h
+1
-2
1 addition, 2 deletions
RayTracer/sampling/Scene.h
with
18 additions
and
17 deletions
RayTracer/sampling/Scene.cpp
+
17
−
15
View file @
c40617e9
...
...
@@ -50,23 +50,25 @@ util::Vec3 Scene::calculateRadiance(const cam::Ray& r, size_t depth) const {
auto
scatter_function
=
(
brdf
*
L_i
*
cosine_term
)
/
brdf_pdf
;
util
::
Vec3
L_direct
;
if
(
direct
)
L_direct
=
directLighting
(
h
,
r
,
light_n
);
else
util
::
Vec3
L_e
;
if
(
direct
)
{
L_direct
=
directLighting
(
h
.
value
(),
r
);
L_e
=
(
max_depth
==
depth
)
?
h
->
emission
()
:
util
::
Vec3
(
0
);
}
else
{
L_direct
=
util
::
Vec3
(
0
);
auto
L_e
=
(
max_depth
==
depth
)
?
h
->
emission
()
:
util
::
Vec3
(
0
);
L_e
=
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
{
util
::
Vec3
Scene
::
directLighting
(
const
cam
::
Hit
&
h
,
cam
::
Ray
r
)
const
{
util
::
Vec3
result
;
for
(
auto
light
:
lights
)
{
util
::
Vec3
light_part
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
auto
sample_point
=
light
->
sampleLight
(
h
.
value
()
);
auto
shadow_ray
=
cam
::
Ray
(
sample_point
.
point
(),
h
->
point
()
-
sample_point
.
point
(),
cam
::
epsilon
,
1
-
cam
::
epsilon
,
false
);
for
(
int
i
=
0
;
i
<
light_
n
;
i
++
)
{
auto
sample_point
=
light
->
sampleLight
(
h
);
auto
shadow_ray
=
cam
::
Ray
(
sample_point
.
point
(),
h
.
point
()
-
sample_point
.
point
(),
cam
::
epsilon
,
1
-
cam
::
epsilon
,
false
);
// When the surface normal and the shadowray dont point in the same
// hemisphere, the ray hits the surface, so we can break
if
(
util
::
dot
(
shadow_ray
.
d
,
sample_point
.
normal
())
<=
0
)
break
;
...
...
@@ -78,19 +80,19 @@ util::Vec3 Scene::directLighting(const std::optional<cam::Hit>& h, cam::Ray r,
// This happens when the shaodow ray is beyond the surfaces normal.
// This means, that the shadow ray hits the surface and we can break
if
(
light_pdf
<=
0
)
break
;
auto
brdf
=
h
->
calculateLightMultiplier
(
shadow_ray
.
d
.
normalize
(),
-
r
.
d
,
h
->
normal
());
auto
brdf
=
h
.
calculateLightMultiplier
(
shadow_ray
.
d
.
normalize
(),
-
r
.
d
,
h
.
normal
());
auto
L
=
light
->
lightEmission
(
sample_point
);
// Dot product could be negative, in that case break
auto
cosine_term
=
std
::
max
<
float
>
(
util
::
dot
(
-
shadow_ray
.
d
.
normalize
(),
h
->
normal
()),
0
);
util
::
dot
(
-
shadow_ray
.
d
.
normalize
(),
h
.
normal
()),
0
);
if
(
cosine_term
<=
0
)
break
;
auto
scatterFunction
=
(
brdf
*
L
*
cosine_term
)
/
light_pdf
;
// Add the values from this light to the others
light_part
=
light_part
+
scatterFunction
;
}
result
=
result
+
(
light_part
/
n
);
result
=
result
+
(
light_part
/
light_
n
);
}
return
result
;
}
This diff is collapsed.
Click to expand it.
RayTracer/sampling/Scene.h
+
1
−
2
View file @
c40617e9
...
...
@@ -18,8 +18,7 @@ class Scene : public util::Sampler {
cam
::
CamObs
cam
;
private:
util
::
Vec3
directLighting
(
const
std
::
optional
<
cam
::
Hit
>&
h
,
cam
::
Ray
r
,
int
n
)
const
;
util
::
Vec3
directLighting
(
const
cam
::
Hit
&
h
,
cam
::
Ray
r
)
const
;
shapes
::
Group
group
;
std
::
vector
<
std
::
shared_ptr
<
shapes
::
Light
>>
lights
;
size_t
max_depth
;
...
...
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