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
9fda80ee
Commit
9fda80ee
authored
3 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Added functions for potential MIS, new function to outsource, directLightning
parent
0d2aef63
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
+61
-21
61 additions, 21 deletions
RayTracer/sampling/Scene.cpp
RayTracer/sampling/Scene.h
+10
-1
10 additions, 1 deletion
RayTracer/sampling/Scene.h
with
71 additions
and
22 deletions
RayTracer/sampling/Scene.cpp
+
61
−
21
View file @
9fda80ee
...
...
@@ -34,8 +34,17 @@ util::Vec3 Scene::calculateRadiance(const cam::Ray& r, size_t depth,
cam
::
Ray
scatter_ray
=
h
->
scattered_ray
(
r
);
if
(
h
->
scatter
(
scatter_ray
.
d
,
h
->
normal
()))
{
result
=
h
->
emission
()
+
h
->
albedo
()
*
calculateRadiance
(
scatter_ray
,
depth
-
1
,
write
);
size_t
lightSamples
=
10
;
// lightSamples = lightSamples * lightSamples;
auto
cosine_term
=
util
::
dot
(
h
->
normal
(),
scatter_ray
.
d
.
normalize
());
auto
brdf
=
h
->
material
->
calculateLightMultiplier
(
-
scatter_ray
.
d
,
-
r
.
d
,
h
->
normal
());
auto
brdf_pdf
=
h
->
material
->
brdf_pdf
(
scatter_ray
.
d
,
h
->
normal
());
result
=
h
->
emission
()
+
(
h
->
albedo
()
*
calculateRadiance
(
scatter_ray
,
depth
-
1
,
write
)
*
brdf
*
cosine_term
)
/
brdf_pdf
;
// To investigate possible bugs
/*
...
...
@@ -45,37 +54,68 @@ util::Vec3 Scene::calculateRadiance(const cam::Ray& r, size_t depth,
if (depth == 20) assert(false);
}*/
#if true
for
(
auto
light
:
lights
)
{
int
nn
=
1
;
nn
=
nn
*
nn
;
util
::
Vec3
lightPart
;
for
(
int
i
=
0
;
i
<
nn
;
i
++
)
{
auto
samplePoint
=
light
->
sampleLight
(
h
.
value
());
auto
shadowRay
=
cam
::
Ray
(
samplePoint
.
point
(),
h
->
point
()
-
samplePoint
.
point
(),
cam
::
epsilon
,
1
-
cam
::
epsilon
,
false
);
auto
shadowHit
=
group
.
intersect
(
shadowRay
);
if
(
!
shadowHit
)
{
result
=
result
+
directLighting
(
h
,
r
,
lightSamples
);
#endif
}
else
{
if
(
this
->
depth
==
depth
)
result
=
h
->
emission
();
// result = util::Vec3(0);
// result = h->emission();
}
return
result
;
// return h->normal();
}
util
::
Vec3
Scene
::
directLighting
(
const
std
::
optional
<
cam
::
Hit
>&
h
,
cam
::
Ray
r
,
int
lightSamples
)
const
{
util
::
Vec3
result
;
for
(
auto
light
:
lights
)
{
util
::
Vec3
lightPart
;
for
(
int
i
=
0
;
i
<
lightSamples
;
i
++
)
{
auto
samplePoint
=
light
->
sampleLight
(
h
.
value
());
auto
shadowRay
=
cam
::
Ray
(
samplePoint
.
point
(),
h
->
point
()
-
samplePoint
.
point
(),
cam
::
epsilon
,
1
-
cam
::
epsilon
,
false
);
auto
shadowHit
=
group
.
intersect
(
shadowRay
);
if
(
!
shadowHit
)
{
auto
lightPdf
=
light
->
lightPdf
(
samplePoint
,
shadowRay
.
d
);
if
(
lightPdf
>
0
)
{
auto
lightEmission
=
light
->
calculateL
ightEmission
(
samplePoint
,
shadowRay
.
d
)
;
light
->
l
ightEmission
(
samplePoint
)
/
lightPdf
;
auto
lightMultiplier
=
h
->
calculateLightMultiplier
(
shadowRay
.
d
.
normalize
(),
-
r
.
d
,
h
->
normal
());
util
::
Vec3
scatterFunction
=
lightMultiplier
*
lightEmission
*
std
::
max
<
float
>
(
util
::
dot
(
-
shadowRay
.
d
.
normalize
(),
h
->
normal
()),
0
);
lightPart
=
lightPart
+
(
scatterFunction
);
}
else
{
result
=
result
;
}
}
result
=
result
+
(
h
->
albedo
()
*
(
lightPart
/
nn
));
}
#endif
}
else
{
result
=
h
->
emission
();
result
=
result
+
(
h
->
albedo
()
*
(
lightPart
/
lightSamples
));
}
return
result
;
// return h->normal();
}
float
Scene
::
bsdfMisWeight
(
const
std
::
optional
<
cam
::
Hit
>&
h
,
const
cam
::
Ray
&
scatterRay
,
size_t
lights_samples
)
const
{
float
numerator
=
h
->
material
->
brdf_pdf
(
scatterRay
.
d
,
h
->
normal
());
float
denominator
=
numerator
;
for
(
auto
light
:
lights
)
{
/*auto light_hit = light->intersect(scatterRay);
if (light_hit)
denominator += lights_samples *
light->lightPdf(light_hit.value(), -scatterRay.d);*/
}
return
numerator
/
denominator
;
}
float
Scene
::
lightMisWeight
(
std
::
shared_ptr
<
shapes
::
Light
>
light
,
const
std
::
optional
<
cam
::
Hit
>&
h
,
const
util
::
Vec3
&
d_in
,
const
util
::
SurfacePoint
&
samplePoint
,
size_t
light_samples
)
const
{
float
numerator
=
light_samples
*
light
->
lightPdf
(
samplePoint
,
d_in
);
float
denominator
=
numerator
+
h
->
material
->
brdf_pdf
(
-
d_in
,
h
->
normal
());
return
numerator
/
denominator
;
}
This diff is collapsed.
Click to expand it.
RayTracer/sampling/Scene.h
+
10
−
1
View file @
9fda80ee
...
...
@@ -3,7 +3,6 @@
#include
<vector>
#include
"../camera/CamObs.h"
#include
"../shape/Background.h"
#include
"../shape/Group.h"
#include
"../shape/Light.h"
#include
"Sampler.h"
...
...
@@ -18,6 +17,16 @@ class Scene : public util::Sampler {
bool
&
write
)
const
;
private:
util
::
Vec3
directLighting
(
const
std
::
optional
<
cam
::
Hit
>&
h
,
cam
::
Ray
r
,
int
nn
)
const
;
float
Scene
::
bsdfMisWeight
(
const
std
::
optional
<
cam
::
Hit
>&
h
,
const
cam
::
Ray
&
scatterRay
,
size_t
lights_samples
)
const
;
float
Scene
::
lightMisWeight
(
std
::
shared_ptr
<
shapes
::
Light
>
light
,
const
std
::
optional
<
cam
::
Hit
>&
h
,
const
util
::
Vec3
&
d_in
,
const
util
::
SurfacePoint
&
samplePoint
,
size_t
light_samples
)
const
;
shapes
::
Group
group
;
std
::
vector
<
std
::
shared_ptr
<
shapes
::
Light
>>
lights
;
cam
::
CamObs
cam
;
...
...
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