Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snowman
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
VILLAUME Lucas
snowman
Commits
f6315bbf
Commit
f6315bbf
authored
1 year ago
by
Lucas Villaume
Browse files
Options
Downloads
Patches
Plain Diff
corps du bonhomme
parent
dc631a9a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tinyraytracer.cpp
+13
-77
13 additions, 77 deletions
tinyraytracer.cpp
with
13 additions
and
77 deletions
tinyraytracer.cpp
+
13
−
77
View file @
f6315bbf
...
...
@@ -16,7 +16,6 @@
int
envmap_width
,
envmap_height
;
std
::
vector
<
Vec3f
>
envmap
;
Model
duck
(
"../duck.obj"
);
struct
Light
{
Light
(
const
Vec3f
&
p
,
const
float
i
)
:
position
(
p
),
intensity
(
i
)
{}
...
...
@@ -78,17 +77,6 @@ bool scene_intersect(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphe
}
}
float
tnear
;
for
(
size_t
i
=
0
;
i
<
duck
.
nfaces
();
++
i
)
{
if
(
duck
.
ray_triangle_intersect
(
i
,
orig
,
dir
,
tnear
))
{
spheres_dist
=
tnear
;
hit
=
orig
+
dir
*
tnear
;
N
=
Vec3f
(
0
,
0
,
1
);
material
=
Material
(
1.5
,
Vec4f
(
0.0
,
0.5
,
0.1
,
0.8
),
Vec3f
(
0.6
,
0.7
,
0.8
),
125.
);
}
}
float
checkerboard_dist
=
std
::
numeric_limits
<
float
>::
max
();
if
(
fabs
(
dir
.
y
)
>
1e-3
)
{
float
d
=
-
(
orig
.
y
+
4
)
/
dir
.
y
;
// the checkerboard plane has equation y = -4
...
...
@@ -97,7 +85,7 @@ bool scene_intersect(const Vec3f &orig, const Vec3f &dir, const std::vector<Sphe
checkerboard_dist
=
d
;
hit
=
pt
;
N
=
Vec3f
(
0
,
1
,
0
);
material
.
diffuse_color
=
(
int
(
.5
*
hit
.
x
+
1000
)
+
int
(
.5
*
hit
.
z
))
&
1
?
Vec3f
(
.3
,
.3
,
.3
)
:
Vec3f
(
.3
,
.2
,
.1
);
material
.
diffuse_color
=
Vec3f
(
.3
,
.3
,
.3
);
}
}
return
std
::
min
(
spheres_dist
,
checkerboard_dist
)
<
1000
;
...
...
@@ -162,66 +150,8 @@ void render(const std::vector<Sphere> &spheres, const std::vector<Light> &lights
pixmap
[
i
*
3
+
j
]
=
(
unsigned
char
)(
255
*
std
::
max
(
0.
f
,
std
::
min
(
1.
f
,
framebuffer
[
i
][
j
])));
}
}
int
decal
=
20
;
//Red map
std
::
vector
<
unsigned
char
>
redmap
(
width
*
height
*
3
);
for
(
size_t
i
=
0
;
i
<
height
*
width
;
++
i
)
{
Vec3f
&
c
=
framebuffer
[
i
];
float
max
=
std
::
max
(
c
[
0
],
std
::
max
(
c
[
1
],
c
[
2
]));
if
(
max
>
1
)
c
=
c
*
(
1.
/
max
);
for
(
size_t
j
=
0
;
j
<
3
;
j
++
)
{
if
(
j
==
0
)
{
// Red channel
redmap
[
i
*
3
+
j
]
=
(
unsigned
char
)(
255
*
std
::
max
(
0.
f
,
std
::
min
(
1.
f
,
framebuffer
[
i
][
j
])));
}
else
{
// Green and blue channels
redmap
[
i
*
3
+
j
]
=
0
;
}
}
}
std
::
vector
<
unsigned
char
>
shifted_redmap
(
width
*
height
*
3
);
for
(
size_t
y
=
0
;
y
<
height
;
++
y
)
{
for
(
size_t
x
=
0
;
x
<
width
;
++
x
)
{
if
(
x
>=
decal
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
shifted_redmap
[(
y
*
width
+
x
-
decal
)
*
3
+
j
]
=
redmap
[(
y
*
width
+
x
)
*
3
+
j
];
}
}
}
}
//blue map
std
::
vector
<
unsigned
char
>
bluemap
(
width
*
height
*
3
);
for
(
size_t
i
=
0
;
i
<
height
*
width
;
++
i
)
{
Vec3f
&
c
=
framebuffer
[
i
];
float
max
=
std
::
max
(
c
[
0
],
std
::
max
(
c
[
1
],
c
[
2
]));
if
(
max
>
1
)
c
=
c
*
(
1.
/
max
);
for
(
size_t
j
=
0
;
j
<
3
;
j
++
)
{
if
(
j
==
2
)
{
// blue channel
bluemap
[
i
*
3
+
j
]
=
(
unsigned
char
)(
255
*
std
::
max
(
0.
f
,
std
::
min
(
1.
f
,
framebuffer
[
i
][
j
])));
}
else
{
// Green and red channels
bluemap
[
i
*
3
+
j
]
=
0
;
}
}
}
std
::
vector
<
unsigned
char
>
shifted_bluemap
(
width
*
height
*
3
);
for
(
size_t
y
=
0
;
y
<
height
;
++
y
)
{
for
(
size_t
x
=
0
;
x
<
width
;
++
x
)
{
if
(
x
<
width
-
decal
)
{
for
(
size_t
j
=
0
;
j
<
3
;
++
j
)
{
shifted_bluemap
[(
y
*
width
+
x
+
decal
)
*
3
+
j
]
=
bluemap
[(
y
*
width
+
x
)
*
3
+
j
];
}
}
}
}
//anaglyph
std
::
vector
<
unsigned
char
>
anaglyph_image
(
width
*
height
*
3
);
for
(
size_t
i
=
0
;
i
<
height
*
width
;
++
i
)
{
anaglyph_image
[
i
*
3
]
=
shifted_redmap
[
i
*
3
];
// Red channel from red image
anaglyph_image
[
i
*
3
+
1
]
=
shifted_redmap
[
i
*
3
+
1
];
// Green channel from blue image
anaglyph_image
[
i
*
3
+
2
]
=
shifted_bluemap
[
i
*
3
+
2
];
// Blue channel from blue image
}
stbi_write_jpg
(
"out.jpg"
,
width
,
height
,
3
,
pixmap
.
data
(),
100
);
stbi_write_jpg
(
"red_left.jpg"
,
width
,
height
,
3
,
shifted_redmap
.
data
(),
100
);
stbi_write_jpg
(
"blue_right.jpg"
,
width
,
height
,
3
,
shifted_bluemap
.
data
(),
100
);
stbi_write_jpg
(
"anaglyph.jpg"
,
width
,
height
,
3
,
anaglyph_image
.
data
(),
100
);
stbi_write_jpg
(
"../out.jpg"
,
width
,
height
,
3
,
pixmap
.
data
(),
100
);
}
int
main
()
{
...
...
@@ -245,10 +175,16 @@ int main() {
Material
mirror
(
1.0
,
Vec4f
(
0.0
,
10.0
,
0.8
,
0.0
),
Vec3f
(
1.0
,
1.0
,
1.0
),
1425.
);
std
::
vector
<
Sphere
>
spheres
;
spheres
.
push_back
(
Sphere
(
Vec3f
(
-
3
,
0
,
-
16
),
2
,
ivory
));
spheres
.
push_back
(
Sphere
(
Vec3f
(
-
1.0
,
-
1.5
,
-
12
),
2
,
glass
));
spheres
.
push_back
(
Sphere
(
Vec3f
(
1.5
,
-
0.5
,
-
18
),
3
,
red_rubber
));
spheres
.
push_back
(
Sphere
(
Vec3f
(
7
,
5
,
-
18
),
4
,
mirror
));
//Corps du bonhomme de neige
spheres
.
push_back
(
Sphere
(
Vec3f
(
0
,
-
1.7
,
-
15
),
2.3
,
ivory
));
spheres
.
push_back
(
Sphere
(
Vec3f
(
0
,
1.9
,
-
15
),
1.9
,
ivory
));
spheres
.
push_back
(
Sphere
(
Vec3f
(
0
,
4.6
,
-
15
),
1.5
,
ivory
));
//spheres.push_back(Sphere(Vec3f(-1.0, -1.5, -12), 2, glass));
//spheres.push_back(Sphere(Vec3f( 1.5, -0.5, -18), 3, red_rubber));
//spheres.push_back(Sphere(Vec3f( 7, 5, -18), 4, mirror));
std
::
vector
<
Light
>
lights
;
lights
.
push_back
(
Light
(
Vec3f
(
-
20
,
20
,
20
),
1.5
));
...
...
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