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
6e7017d9
Commit
6e7017d9
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Sphere refactor: Texels working correctly
parent
56276277
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/Sphere.cpp
+14
-5
14 additions, 5 deletions
RayTracer/shape/Sphere.cpp
RayTracer/shape/Sphere.h
+2
-0
2 additions, 0 deletions
RayTracer/shape/Sphere.h
with
16 additions
and
5 deletions
RayTracer/shape/Sphere.cpp
+
14
−
5
View file @
6e7017d9
...
@@ -25,16 +25,18 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const {
...
@@ -25,16 +25,18 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const {
util
::
Vec3
t1HitPoint
=
r
(
t1
);
util
::
Vec3
t1HitPoint
=
r
(
t1
);
float
theta
=
acos
(
t1HitPoint
.
y
()
/
radius
);
float
theta
=
acos
(
t1HitPoint
.
y
()
/
radius
);
float
phi
=
M_PI
+
atan2
(
t1HitPoint
.
x
(),
t1HitPoint
.
z
());
float
phi
=
M_PI
+
atan2
(
t1HitPoint
.
x
(),
t1HitPoint
.
z
());
return
std
::
optional
<
cam
::
Hit
>
(
return
std
::
optional
<
cam
::
Hit
>
({
t1HitPoint
,
t1HitPoint
,
{
t1HitPoint
,
t1HitPoint
,
t1
,
material
});
texture_coordinates
(
t1HitPoint
),
t1
,
material
});
}
else
{
}
else
{
float
t2
=
(
-
b
+
sqrt
(
b
*
b
-
4
*
a
*
c
))
/
(
2
*
a
);
float
t2
=
(
-
b
+
sqrt
(
b
*
b
-
4
*
a
*
c
))
/
(
2
*
a
);
if
(
r
.
in_range
(
t2
))
{
if
(
r
.
in_range
(
t2
))
{
util
::
Vec3
t2HitPoint
=
r
(
t2
);
util
::
Vec3
t2HitPoint
=
r
(
t2
);
float
theta
=
acos
(
t2HitPoint
.
y
()
/
radius
);
float
theta
=
acos
(
t2HitPoint
.
y
()
/
radius
);
float
phi
=
M_PI
+
atan2
(
t2HitPoint
.
x
(),
t2HitPoint
.
z
());
float
phi
=
M_PI
+
atan2
(
t2HitPoint
.
x
(),
t2HitPoint
.
z
());
return
std
::
optional
<
cam
::
Hit
>
(
return
std
::
optional
<
cam
::
Hit
>
({
t2HitPoint
,
t2HitPoint
,
{
t2HitPoint
,
t2HitPoint
,
t2
,
material
});
texture_coordinates
(
t2HitPoint
),
t2
,
material
});
}
else
{
}
else
{
return
std
::
nullopt
;
return
std
::
nullopt
;
}
}
...
@@ -43,6 +45,12 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const {
...
@@ -43,6 +45,12 @@ std::optional<cam::Hit> Sphere::intersect(const cam::Ray& r) const {
return
std
::
nullopt
;
return
std
::
nullopt
;
}
}
}
}
std
::
pair
<
float
,
float
>
Sphere
::
texture_coordinates
(
const
util
::
Vec3
&
pos
)
const
{
float
theta
=
std
::
acos
(
pos
.
y
()
/
radius
);
float
phi
=
M_PI
+
std
::
atan2
(
pos
.
x
(),
pos
.
z
());
return
std
::
pair
<
float
,
float
>
({
phi
/
(
2
*
M_PI
),
theta
/
M_PI
});
}
util
::
AxisAlignedBoundingBox
Sphere
::
bounds
()
const
{
util
::
AxisAlignedBoundingBox
Sphere
::
bounds
()
const
{
return
util
::
AxisAlignedBoundingBox
(
util
::
Vec3
(
-
radius
),
return
util
::
AxisAlignedBoundingBox
(
util
::
Vec3
(
-
radius
),
util
::
Vec3
(
radius
));
util
::
Vec3
(
radius
));
...
@@ -56,7 +64,8 @@ util::SurfacePoint Sphere::sampleLight() const {
...
@@ -56,7 +64,8 @@ util::SurfacePoint Sphere::sampleLight() const {
util
::
Vec3
point
(
radius
*
std
::
cos
(
theta
)
*
std
::
sin
(
phi
),
util
::
Vec3
point
(
radius
*
std
::
cos
(
theta
)
*
std
::
sin
(
phi
),
radius
*
std
::
sin
(
theta
)
*
std
::
sin
(
phi
),
radius
*
std
::
sin
(
theta
)
*
std
::
sin
(
phi
),
radius
*
std
::
cos
(
phi
));
radius
*
std
::
cos
(
phi
));
return
util
::
SurfacePoint
(
point
,
point
.
normalize
(),
material
);
return
util
::
SurfacePoint
(
point
,
point
.
normalize
(),
texture_coordinates
(
point
),
material
);
}
}
util
::
Vec3
Sphere
::
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
util
::
Vec3
Sphere
::
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
const
util
::
Vec3
&
d
)
const
{
const
util
::
Vec3
&
d
)
const
{
...
...
This diff is collapsed.
Click to expand it.
RayTracer/shape/Sphere.h
+
2
−
0
View file @
6e7017d9
...
@@ -8,6 +8,8 @@ class Sphere : public Light, public Shape {
...
@@ -8,6 +8,8 @@ class Sphere : public Light, public Shape {
public:
public:
Sphere
(
float
radius
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
);
Sphere
(
float
radius
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
);
std
::
optional
<
cam
::
Hit
>
intersect
(
const
cam
::
Ray
&
r
)
const
override
;
std
::
optional
<
cam
::
Hit
>
intersect
(
const
cam
::
Ray
&
r
)
const
override
;
std
::
pair
<
float
,
float
>
texture_coordinates
(
const
util
::
Vec3
&
pos
)
const
override
;
util
::
AxisAlignedBoundingBox
bounds
()
const
override
;
util
::
AxisAlignedBoundingBox
bounds
()
const
override
;
util
::
SurfacePoint
sampleLight
()
const
override
;
util
::
SurfacePoint
sampleLight
()
const
override
;
util
::
Vec3
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
util
::
Vec3
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
...
...
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