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
1279311c
Commit
1279311c
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
RectanglePlane implemented as Shape and as Light
parent
d4606b97
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/shape/RectanglePlane.cpp
+63
-0
63 additions, 0 deletions
RayTracer/shape/RectanglePlane.cpp
RayTracer/shape/RectanglePlane.h
+23
-0
23 additions, 0 deletions
RayTracer/shape/RectanglePlane.h
with
86 additions
and
0 deletions
RayTracer/shape/RectanglePlane.cpp
0 → 100644
+
63
−
0
View file @
1279311c
#define _USE_MATH_DEFINES
#include
"RectanglePlane.h"
#include
"../tools/Random.h"
#include
"math.h"
namespace
shapes
{
RectanglePlane
::
RectanglePlane
(
float
width
,
float
depth
,
bool
twofaced
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
)
:
width
(
width
),
depth
(
depth
),
twofaced
(
twofaced
),
material
(
material
)
{
}
std
::
optional
<
cam
::
Hit
>
RectanglePlane
::
intersect
(
const
cam
::
Ray
&
r
)
const
{
util
::
Vec3
n
(
0
,
1
,
0
);
util
::
Vec3
x0
=
r
.
x0
;
util
::
Vec3
d
=
r
.
d
;
float
a
=
util
::
dot
(
d
,
n
);
if
(
a
==
0
)
{
return
std
::
nullopt
;
}
else
if
(
a
>
0
)
{
if
(
twofaced
)
n
=
-
n
;
else
return
std
::
nullopt
;
}
float
t
=
-
x0
[
1
]
/
d
[
1
];
util
::
Vec3
t_hitpoint
=
r
(
t
);
if
(
r
.
in_range
(
t
)
&&
std
::
abs
(
t_hitpoint
.
x
())
<=
width
/
2
&&
std
::
abs
(
t_hitpoint
.
z
())
<=
depth
/
2
)
{
return
std
::
optional
<
cam
::
Hit
>
({
t_hitpoint
,
n
,
t
,
material
});
}
else
{
return
std
::
nullopt
;
}
}
util
::
AxisAlignedBoundingBox
RectanglePlane
::
bounds
()
const
{
return
util
::
AxisAlignedBoundingBox
(
util
::
Vec3
(
-
width
/
2
,
0
,
-
depth
/
2
),
util
::
Vec3
(
width
/
2
,
0
,
depth
/
2
));
}
util
::
SurfacePoint
RectanglePlane
::
sampleLight
()
const
{
// X coord of the sampled point.
float
x
=
util
::
disMinus1To1
(
util
::
gen
)
*
width
/
2
;
// Z coord of the sampled point.
float
z
=
util
::
disMinus1To1
(
util
::
gen
)
*
width
/
2
;
return
util
::
SurfacePoint
(
util
::
Vec3
(
x
,
0
,
z
),
util
::
Vec3
(
0
,
1
,
0
),
material
);
// The sampled point will be in local coordinates.
}
util
::
Vec3
RectanglePlane
::
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
=
width
*
depth
;
auto
pdf
=
std
::
pow
(
d
.
length
(),
2
)
/
(
dot
*
area
);
return
emission
/
pdf
;
}
}
// namespace shapes
This diff is collapsed.
Click to expand it.
RayTracer/shape/RectanglePlane.h
0 → 100644
+
23
−
0
View file @
1279311c
#pragma once
#include
"Light.h"
#include
"Shape.h"
namespace
shapes
{
class
RectanglePlane
:
public
Light
,
public
Shape
{
public:
RectanglePlane
(
float
width
,
float
depth
,
bool
twofaced
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
);
std
::
optional
<
cam
::
Hit
>
intersect
(
const
cam
::
Ray
&
r
)
const
override
;
util
::
AxisAlignedBoundingBox
bounds
()
const
override
;
util
::
SurfacePoint
sampleLight
()
const
override
;
util
::
Vec3
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
const
util
::
Vec3
&
d
)
const
override
;
private:
std
::
shared_ptr
<
material
::
Material
>
material
;
const
float
width
,
depth
;
const
bool
twofaced
;
};
}
// namespace shapes
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