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
eab7b922
Commit
eab7b922
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Added base for reflective material. Currently same as diffuse
parent
a84c2bdb
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/material/ReflectiveMaterial.cpp
+60
-0
60 additions, 0 deletions
RayTracer/material/ReflectiveMaterial.cpp
RayTracer/material/ReflectiveMaterial.h
+30
-0
30 additions, 0 deletions
RayTracer/material/ReflectiveMaterial.h
with
90 additions
and
0 deletions
RayTracer/material/ReflectiveMaterial.cpp
0 → 100644
+
60
−
0
View file @
eab7b922
#define _USE_MATH_DEFINES
#include
"ReflectiveMaterial.h"
#include
<cassert>
#include
"../tools/Random.h"
#include
"texture/Constant.h"
namespace
material
{
ReflectiveMaterial
::
ReflectiveMaterial
(
const
std
::
shared_ptr
<
util
::
Sampler
>&
albedo_texture
,
const
std
::
shared_ptr
<
util
::
Sampler
>&
emission_texture
,
float
clearness
)
:
albedo_texture
(
albedo_texture
),
emission_texture
(
emission_texture
),
clearness
(
clearness
)
{
}
ReflectiveMaterial
::
ReflectiveMaterial
(
const
std
::
shared_ptr
<
util
::
Sampler
>&
albedo_texture
,
float
clearness
)
:
albedo_texture
(
albedo_texture
),
emission_texture
(
std
::
make_shared
<
Constant
>
(
Constant
(
util
::
Vec3
(
0
,
0
,
0
)))),
clearness
(
clearness
)
{
}
ReflectiveMaterial
::
ReflectiveMaterial
(
const
util
::
Vec3
&
color
,
float
clearness
)
:
albedo_texture
(
std
::
make_shared
<
Constant
>
(
Constant
(
color
))),
emission_texture
(
std
::
make_shared
<
Constant
>
(
Constant
(
util
::
Vec3
(
0
,
0
,
0
)))),
clearness
(
clearness
)
{
}
util
::
Vec3
ReflectiveMaterial
::
albedo
(
float
texel_x
,
float
texel_y
)
const
{
return
albedo_texture
->
color
(
texel_x
,
texel_y
);
}
util
::
Vec3
ReflectiveMaterial
::
emission
(
float
texel_x
,
float
texel_y
)
const
{
return
emission_texture
->
color
(
texel_x
,
texel_y
);
}
util
::
Vec3
ReflectiveMaterial
::
scattered_d
(
const
util
::
Vec3
&
d
,
const
util
::
Vec3
&
n
)
const
{
util
::
Vec3
rand
=
util
::
rand_vec3_in_circle
(
clearness
);
util
::
Vec3
reflected
=
reflection
(
d
,
n
);
return
reflected
+
rand
;
}
bool
ReflectiveMaterial
::
scatter
(
const
util
::
Vec3
&
d
,
const
util
::
Vec3
&
n
)
const
{
return
util
::
dot
(
d
,
n
)
>
0
;
}
float
ReflectiveMaterial
::
calculateLightMultiplier
(
const
util
::
Vec3
&
d_in
,
const
util
::
Vec3
&
d_out
,
const
util
::
Vec3
&
n
)
const
{
util
::
Vec3
reflected
=
reflection
(
-
d_out
,
n
).
normalize
();
/*if (std::pow(util::dot(reflected, -d_in), 1) < 0.7) {
std::cout << reflected << " " << -d_in << " "
<< util::dot(reflected, -d_in) << std::endl;
assert(false);
}*/
auto
dot
=
util
::
dot
(
reflected
,
-
d_in
);
auto
theta
=
std
::
acos
(
dot
);
return
std
::
cos
(
std
::
min
<
float
>
(
theta
*
3
,
M_PI
/
2
));
}
}
// namespace material
\ No newline at end of file
This diff is collapsed.
Click to expand it.
RayTracer/material/ReflectiveMaterial.h
0 → 100644
+
30
−
0
View file @
eab7b922
#pragma once
#include
"Material.h"
namespace
material
{
class
ReflectiveMaterial
:
public
Material
{
public:
ReflectiveMaterial
(
const
std
::
shared_ptr
<
util
::
Sampler
>&
albedo_texture
,
const
std
::
shared_ptr
<
util
::
Sampler
>&
emission_texture
,
float
clearness
);
ReflectiveMaterial
(
const
std
::
shared_ptr
<
util
::
Sampler
>&
albedo
,
float
clearness
);
ReflectiveMaterial
(
const
util
::
Vec3
&
color
,
float
clearness
);
util
::
Vec3
albedo
(
float
texel_x
,
float
texel_y
)
const
override
;
util
::
Vec3
emission
(
float
texel_x
,
float
texel_y
)
const
override
;
util
::
Vec3
scattered_d
(
const
util
::
Vec3
&
d
,
const
util
::
Vec3
&
n
)
const
override
;
bool
scatter
(
const
util
::
Vec3
&
d
,
const
util
::
Vec3
&
n
)
const
override
;
float
calculateLightMultiplier
(
const
util
::
Vec3
&
d_in
,
const
util
::
Vec3
&
d_out
,
const
util
::
Vec3
&
n
)
const
override
;
private:
std
::
shared_ptr
<
util
::
Sampler
>
albedo_texture
;
std
::
shared_ptr
<
util
::
Sampler
>
emission_texture
;
float
clearness
;
};
}
// namespace 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