コード例 #1
0
ファイル: ray.py プロジェクト: glass5er/Python-RayTracing
    def calcColor(self, light, objlist):
        dest, i_obj = self.checkInter(objlist)
        occluded = self.checkShadow(dest, light, objlist)

        light2dest = vector3.nrm_vec(vector3.sub_vec(dest, light.point))
        if i_obj.radius > 0.0 :
            obj_normal = vector3.nrm_vec(vector3.sub_vec(dest,i_obj.point))
        else :
            obj_normal = i_obj.normal
        shading = -vector3.dot_vec(light2dest, obj_normal)
        if shading < 0.2 : shading = 0.2

        d_color = i_obj.color
        d_red = d_color & 255
        d_grn = (d_color>>8) & 255
        d_blu = (d_color>>16) & 255
        d_red *= shading
        d_grn *= shading
        d_blu *= shading

        if occluded > 0 :
            penalty = 128
            if d_red >= penalty : d_red -= penalty
            else : d_red = 0
            if d_grn >= penalty : d_grn -= penalty
            else : d_grn = 0
            if d_blu >= penalty : d_blu -= penalty
            else : d_blu = 0
        d_red = int(d_red)
        d_grn = int(d_grn)
        d_blu = int(d_blu)
        return (int(d_red) + (int(d_grn)<<8) + (int(d_blu)<<16))
コード例 #2
0
ファイル: ray.py プロジェクト: glass5er/Python-RayTracing
 def checkShadow(self, start, light, objlist):
     occluded = 0
     o2light = vector3.nrm_vec(vector3.sub_vec(light.point, start))
     min_length = vector3.norm(o2light)
     if min_length > 1.0e6 : print "a"; return 0
     ray2light = ray(vector3.sub_vec(start,vector3.mul_vec(o2light, -1.0e-8)), o2light)
     for element in objlist:
         dest = ray2light.intersection(element)
         if vector3.norm(dest) < min_length :
             occluded = 1
     return occluded
コード例 #3
0
ファイル: ray.py プロジェクト: glass5er/Python-RayTracing
 def __init__(self, ppnt, pdir):
     self.point = ppnt
     self.direction = vector3.nrm_vec(pdir)