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
d62ce49b
Commit
d62ce49b
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Bounds now calculated in constructor
parent
e5d4d5c3
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/shape/Triangle.cpp
+48
-19
48 additions, 19 deletions
RayTracer/shape/Triangle.cpp
RayTracer/shape/Triangle.h
+3
-1
3 additions, 1 deletion
RayTracer/shape/Triangle.h
with
51 additions
and
20 deletions
RayTracer/shape/Triangle.cpp
+
48
−
19
View file @
d62ce49b
...
@@ -2,32 +2,17 @@
...
@@ -2,32 +2,17 @@
#include
"Triangle.h"
#include
"Triangle.h"
#include
"../tools/Random.h"
#include
"math.h"
namespace
shapes
{
namespace
shapes
{
Triangle
::
Triangle
(
util
::
Vertex
p1
,
util
::
Vertex
p2
,
util
::
Vertex
p3
,
Triangle
::
Triangle
(
util
::
Vertex
p1
,
util
::
Vertex
p2
,
util
::
Vertex
p3
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
)
const
std
::
shared_ptr
<
material
::
Material
>&
material
)
:
p1
(
p1
),
p2
(
p2
),
p3
(
p3
),
material
(
material
)
{
:
p1
(
p1
),
p2
(
p2
),
p3
(
p3
),
material
(
material
)
{
recalculateBB
();
recalculateBB
();
}
}
util
::
AxisAlignedBoundingBox
Triangle
::
bounds
()
const
{
return
bb
;
}
void
Triangle
::
recalculateBB
()
{
const
util
::
Vec3
xx
=
p1
.
position
;
const
util
::
Vec3
yy
=
p2
.
position
;
const
util
::
Vec3
zz
=
p3
.
position
;
const
util
::
Vec3
minBound
=
util
::
Vec3
(
std
::
min
<
float
>
({
xx
.
x
(),
yy
.
x
(),
zz
.
x
()}),
std
::
min
<
float
>
({
xx
.
y
(),
yy
.
y
(),
zz
.
y
()}),
std
::
min
<
float
>
({
xx
.
z
(),
yy
.
z
(),
zz
.
z
()}));
const
util
::
Vec3
maxBound
=
util
::
Vec3
(
std
::
max
<
float
>
({
xx
.
x
(),
yy
.
x
(),
zz
.
x
()}),
std
::
max
<
float
>
({
xx
.
y
(),
yy
.
y
(),
zz
.
y
()}),
std
::
max
<
float
>
({
xx
.
z
(),
yy
.
z
(),
zz
.
z
()}));
bb
=
util
::
AxisAlignedBoundingBox
(
minBound
,
maxBound
);
}
std
::
optional
<
cam
::
Hit
>
Triangle
::
intersect
(
const
cam
::
Ray
&
r
)
const
{
std
::
optional
<
cam
::
Hit
>
Triangle
::
intersect
(
const
cam
::
Ray
&
r
)
const
{
// std::cout << "In tri intersect" << std::endl;
util
::
Vec3
e1
=
p2
.
position
-
p1
.
position
;
util
::
Vec3
e1
=
p2
.
position
-
p1
.
position
;
util
::
Vec3
e2
=
p3
.
position
-
p1
.
position
;
util
::
Vec3
e2
=
p3
.
position
-
p1
.
position
;
util
::
Vec3
pvec
=
util
::
cross
(
r
.
d
,
e2
);
util
::
Vec3
pvec
=
util
::
cross
(
r
.
d
,
e2
);
...
@@ -62,4 +47,48 @@ std::optional<cam::Hit> Triangle::intersect(const cam::Ray& r) const {
...
@@ -62,4 +47,48 @@ std::optional<cam::Hit> Triangle::intersect(const cam::Ray& r) const {
// std::cout << "Hm" << std::endl;
// std::cout << "Hm" << std::endl;
return
std
::
optional
<
cam
::
Hit
>
(
cam
::
Hit
(
hit
,
cross_normal
,
t
,
material
));
return
std
::
optional
<
cam
::
Hit
>
(
cam
::
Hit
(
hit
,
cross_normal
,
t
,
material
));
}
}
util
::
AxisAlignedBoundingBox
Triangle
::
bounds
()
const
{
// std::cout << "In tri bounds" << std::endl;
return
bb
;
}
// TODO
util
::
SurfacePoint
Triangle
::
sampleLight
()
const
{
// X coord of the sampled point.
float
x
=
util
::
disMinus1To1
(
util
::
gen
)
*
1
/
2
;
// Z coord of the sampled point.
float
z
=
util
::
disMinus1To1
(
util
::
gen
)
*
1
/
2
;
return
util
::
SurfacePoint
(
util
::
Vec3
(
x
,
0
,
z
),
util
::
Vec3
(
0
,
1
,
0
),
material
);
// The sampled point will be in local coordinates.
}
// TODO
util
::
Vec3
Triangle
::
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
const
util
::
Vec3
&
d
)
const
{
// Basically this is just the emission at a surface point. And the pdf dimms
// the light in regard to the angle.
// Uniform pdf of shape is 1/area, converting to pdf over solid angle is
// pdf/(dot/length^2).
auto
emission
=
p
.
emission
();
auto
dot
=
std
::
max
<
float
>
(
util
::
dot
(
p
.
normal
(),
d
.
normalize
()),
0
);
auto
area
=
1
;
auto
pdf
=
std
::
pow
(
d
.
length
(),
2
)
/
(
dot
*
area
);
return
emission
/
pdf
;
}
void
Triangle
::
recalculateBB
()
{
const
util
::
Vec3
xx
=
p1
.
position
;
const
util
::
Vec3
yy
=
p2
.
position
;
const
util
::
Vec3
zz
=
p3
.
position
;
const
util
::
Vec3
minBound
=
util
::
Vec3
(
std
::
min
<
float
>
({
xx
.
x
(),
yy
.
x
(),
zz
.
x
()}),
std
::
min
<
float
>
({
xx
.
y
(),
yy
.
y
(),
zz
.
y
()}),
std
::
min
<
float
>
({
xx
.
z
(),
yy
.
z
(),
zz
.
z
()}));
const
util
::
Vec3
maxBound
=
util
::
Vec3
(
std
::
max
<
float
>
({
xx
.
x
(),
yy
.
x
(),
zz
.
x
()}),
std
::
max
<
float
>
({
xx
.
y
(),
yy
.
y
(),
zz
.
y
()}),
std
::
max
<
float
>
({
xx
.
z
(),
yy
.
z
(),
zz
.
z
()}));
bb
=
util
::
AxisAlignedBoundingBox
(
minBound
,
maxBound
);
}
}
// namespace shapes
}
// namespace shapes
This diff is collapsed.
Click to expand it.
RayTracer/shape/Triangle.h
+
3
−
1
View file @
d62ce49b
...
@@ -6,9 +6,11 @@
...
@@ -6,9 +6,11 @@
#include
"../camera/Hit.h"
#include
"../camera/Hit.h"
#include
"../tools/AxisAlignedBoundingBox.h"
#include
"../tools/AxisAlignedBoundingBox.h"
#include
"../tools/Vertex.h"
#include
"../tools/Vertex.h"
#include
"Light.h"
#include
"Shape.h"
namespace
shapes
{
namespace
shapes
{
class
Triangle
{
class
Triangle
:
public
Light
,
public
Shape
{
public:
public:
Triangle
(
util
::
Vertex
p1
,
util
::
Vertex
p2
,
util
::
Vertex
p3
,
Triangle
(
util
::
Vertex
p1
,
util
::
Vertex
p2
,
util
::
Vertex
p3
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
);
const
std
::
shared_ptr
<
material
::
Material
>&
material
);
...
...
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