Post by linuxdeveloper on Jan 16, 2021 11:39:10 GMT
Hello,
I have all tests passing up until page 97.
I then run into this error on "The color when a ray hits" :
As you can see my color is .36, .45, .27 making it off by a very small margin of about .1
If I increase my EPSILON to 0.1 then the tests all pass, but I believe we are not supposed to do that, and I don't see why that would make sense in this case.
What could I possibly be doing wrong that could cause such a small error, but still have all my other tests pass up to page 97, including "The color with an intersection behind the ray"
Any tips appreciated.
Nate
-----
Here are some of my relevant functions:
I have all tests passing up until page 97.
I then run into this error on "The color when a ray hits" :
Scenario: The color when a ray hits # features/world.feature:56
Given w ← default_world() # features/steps/world_steps.py:62 0.000s
And r ← ray(point(0, 0, -5), vector(0, 0, 1)) # features/steps/spheres_steps.py:9 0.000s
When c ← color_at(w, r) # features/steps/world_steps.py:138 0.013s
Then c = color(0.38066, 0.47583, 0.2855)
Captured stdout:
0.36494287900649 0.4538741139549163 0.27601164405806367
As you can see my color is .36, .45, .27 making it off by a very small margin of about .1
If I increase my EPSILON to 0.1 then the tests all pass, but I believe we are not supposed to do that, and I don't see why that would make sense in this case.
What could I possibly be doing wrong that could cause such a small error, but still have all my other tests pass up to page 97, including "The color with an intersection behind the ray"
Any tips appreciated.
Nate
-----
Here are some of my relevant functions:
def lighting(material, light, point, eyev, normalv):
effective_color = material.color * light.intensity
lightv = normalize(light.position - point)
ambient = effective_color * material.ambient
light_dot_normal = dot(lightv, normalv)
black = color(0, 0, 0)
if light_dot_normal < 0:
diffuse = black
specular = black
else:
diffuse = effective_color * material.diffuse * light_dot_normal
reflectv = reflect(-lightv, normalv)
reflect_dot_eye = dot(reflectv, eyev)
if reflect_dot_eye <= 0:
specular = black
else:
factor = reflect_dot_eye ** material.shininess
specular = light.intensity * material.specular * factor
return ambient + diffuse + specular
def shade_hit(world, comps):
return lighting(comps.object.material, world.light, comps.point, comps.eyev, comps.normalv)
def color_at(world, ray):
xs = intersect_world(world, ray)
if len(xs) == 0:
return color(0, 0, 0)
else:
for i in xs:
print(i.t)
if i.t > 0:
comps = prepare_computations(i, ray)
print(comps)
return shade_hit(world, comps)
return color(0, 0, 0)
def default_world():
w = world()
w.light = point_light(point(-10, 10, -10), color(1, 1, 1))
s1 = sphere()
s1.material.color = color(0.8, 1.0, 0.6)
s1.material.diffuse = 0.7
s1.material.specular = 0.2
w.objects.append(s1)
s2 = sphere()
s2.transform = scaling(0.5, 0.5, 0.5)
w.objects.append(s2)
return w
def intersect_world(world, ray):
s = []
for o in world.objects:
i = intersect(o, ray)
if len(i) != 0:
for j in i:
s.append(j)
s = sorted(s, key=lambda x: x.t)
return s