Пример #1
0
    def scatter(self, ray_in: vector.Ray, hit_record: hittable.HitRecord):
        attenuation = vector.Vec3(1.0, 1.0, 1.0)
        etai_over_etat = self.ref_idx

        if hit_record.front_face:
            etai_over_etat = 1.0 / self.ref_idx

        unit_direction = vector.unit_vector(ray_in.direction)

        cos_theta = min(vector.dot(-unit_direction, hit_record.normal), 1.0)
        sin_theta = math.sqrt(1.0 - cos_theta*cos_theta)

        if etai_over_etat * sin_theta > 1.0:
            reflected = vector.reflect(unit_direction, hit_record.normal)
            scattered = vector.Ray(hit_record.position, reflected)
            return True, attenuation, scattered

        reflect_prob = vector.schlick(cos_theta, etai_over_etat)
        if util.random_double() < reflect_prob:
            reflected = vector.reflect(unit_direction, hit_record.normal)
            scattered = vector.Ray(hit_record.position, reflected)
            return True, attenuation, scattered

        refracted = vector.refract(unit_direction, hit_record.normal, etai_over_etat)
        scattered = vector.Ray(hit_record.position, refracted)
        return True, attenuation, scattered
Пример #2
0
    def scatter(self, ray_in: vector.Ray, hit_record: hittable.HitRecord):


        reflected = vector.reflect(vector.unit_vector(ray_in.direction), hit_record.normal)
        scattered = vector.Ray(hit_record.position, reflected + vector.random_in_unit_sphere().times(self.fuzz))

        didscatter = (vector.dot(scattered.direction, hit_record.normal) > 0)

        return didscatter, self.color, scattered
Пример #3
0
    def get_ray(self, s: float, t: float):

        rd = vector.random_in_unit_disk().times(self.lens_radius)
        offset = self.u1.times(rd.x) + self.v1.times(rd.y)

        ret = vector.Ray(
            self.origin + offset,
            self.lower_left_corner + self.horizontal.times(s) +
            self.vertical.times(t) - self.origin - offset)
        return ret
Пример #4
0
 def scatter(self, ray_in: vector.Ray, hit_record: hittable.HitRecord):
     scatter_direction = hit_record.normal + vector.random_unit_vector()
     scattered = vector.Ray(hit_record.position, scatter_direction)
     return True, self.albedo, scattered
Пример #5
0
import vector
import cProfile
import re
import hittable

p = vector.Vec3(0.0, 0.0, 0.0)
norm = vector.Vec3(0.0, 1.0, 0.0)

hit_rec = hittable.HitRecord(p, norm, 0.0, None)

sum = 0.0
for i in range(100):
    target = hit_rec.position + vector.random_in_hemisphere(hit_rec.normal)
    sum = sum + target.x

print("avg x: " + str(sum / 100.0))

r = vector.Ray(vector.Vec3(0.0, 0.0, 0.0), vector.Vec3(1.0, 1.0, 1.0))

r2 = r.at(-0.5)

print("" + str(r))
print("" + str(r2))
Пример #6
0
 def getRay(self, sensorpos):
     return vector.Ray(self.pos, sensorpos - self.pos)