@@ -12,6 +12,7 @@ Plane::Plane(
12
12
float d,
13
13
const Material *material,
14
14
const Texture *texture,
15
+ const Texture *normal_texture,
15
16
float texture_scale,
16
17
const Vector2f &texture_translate,
17
18
const Vector3f &texture_up
@@ -24,28 +25,25 @@ Plane::Plane(
24
25
this ->texture_right = Vector3f::cross (texture_up, normal );
25
26
}
26
27
27
- bool Plane::Intersect (const Ray &r, Hit &h , float tmin) const {
28
+ bool Plane::Intersect (const Ray &r, Hit &hit , float tmin) const {
28
29
const Vector3f &dir = r.GetDirection ();
29
30
float t = (d - Vector3f::dot (r.GetOrigin (), normal )) / Vector3f::dot (dir, normal );
30
- if (t > tmin && t < h.GetT ()) {
31
- h.Set (t, material, normal , r.PointAtParameter (t), this );
31
+ if (t > tmin && t < hit.GetT ()) {
32
+ auto color = material->ambientColor ;
33
+ if (texture != nullptr ) {
34
+ const auto &hit_point = hit.GetPos ();
35
+ auto x = (Vector3f::dot (hit_point, texture_right) + texture_translate.x ()) / texture_scale;
36
+ auto y = (Vector3f::dot (hit_point, texture_up) + texture_translate.y ()) / texture_scale;
37
+ auto u = x - std::floor (x);
38
+ auto v = y - std::floor (y);
39
+ color = texture->At (u, v);
40
+ }
41
+ // TODO: change texture
42
+ hit.Set (t, material, normal , r.PointAtParameter (t), color, this );
32
43
return true ;
33
44
} else {
34
45
return false ;
35
46
}
36
47
}
37
48
38
- Vector3f Plane::AmbientColorAtHit (const Hit &hit) const {
39
- if (texture != nullptr ) {
40
- const auto &hit_point = hit.GetPos ();
41
- auto x = (Vector3f::dot (hit_point, texture_right) + texture_translate.x ()) / texture_scale;
42
- auto y = (Vector3f::dot (hit_point, texture_up) + texture_translate.y ()) / texture_scale;
43
- auto u = x - std::floor (x);
44
- auto v = y - std::floor (y);
45
- return texture->At (u / 2 , v / 2 );
46
- } else {
47
- return material->ambientColor ;
48
- }
49
- }
50
-
51
49
} // namespace RT
0 commit comments