Skip to content

Commit

Permalink
Remove texcoords calculation in case of PhongMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
Makar Solomatin committed Apr 7, 2021
1 parent 798ec44 commit 91e62d4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pyrt/geometry/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ..geometry import Shape
from ..math import Ray, HitRecord, Vec2, Vec3, dot3, G_EPSILON
from ..material import Material, PhongMaterial
from ..material import Material, PhongMaterial, TextureMaterial, NormalMappedMaterial
from .bbox import BBox
from math import sqrt, pi, asin, atan2

Expand Down Expand Up @@ -73,7 +73,8 @@ def hit(self, ray: Ray, hitrecord: HitRecord) -> bool:
hitrecord.normal = hitrecord.normal_g
hitrecord.color = Vec3(1., 1., 1.) # spheres don't have interpolated colors, set to white
hitrecord.material = self.material
hitrecord.texcoord = self.calcTexcoord(hitrecord.point)
if isinstance(hitrecord.material, TextureMaterial) or isinstance(hitrecord.material, NormalMappedMaterial):
hitrecord.texcoord = self.calcTexcoord(hitrecord.point)
return True
return False

Expand Down
5 changes: 3 additions & 2 deletions pyrt/geometry/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from ..geometry import Shape, Vertex
from ..material import PhongMaterial
from ..material import PhongMaterial, TextureMaterial, NormalMappedMaterial
from ..math import *


Expand Down Expand Up @@ -202,7 +202,8 @@ def hit(self, ray: Ray, hitrecord: HitRecord) -> bool:
cV = self.c.color - self.a.color
hitrecord.color = self.a.color + cU * u + cV * v
hitrecord.material = self.material
hitrecord.texcoord = self.calcTexcoord(hitrecord.point)
if isinstance(hitrecord.material, TextureMaterial) or isinstance(hitrecord.material, NormalMappedMaterial):
hitrecord.texcoord = self.calcTexcoord(hitrecord.point)

# why would we?
# hitrecord.point = ray.start + t * ray.direction
Expand Down
4 changes: 2 additions & 2 deletions pyrt/renderer/simplert.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _recurse_shade(self, scene: Scene, ray: Ray, iteration_num: int) -> tuple:
if not hit or iteration_num == 0:
return r, g, b

if hitrecord.material.reflectivity > G_EPSILON:
if abs(hitrecord.material.reflectivity) > G_EPSILON:
reflect_ray = Ray(hitrecord.point, reflect3(hitrecord.normal_g, ray.direction))
new_r, new_g, new_b = self._recurse_shade(scene, reflect_ray, iteration_num - 1)

Expand All @@ -90,7 +90,7 @@ def _recurse_shade(self, scene: Scene, ray: Ray, iteration_num: int) -> tuple:

self.num_secondary_rays += 1

if hitrecord.material.transparency > G_EPSILON:
if abs(hitrecord.material.transparency) > G_EPSILON:
refract_ray = Ray(
hitrecord.point + ray.direction * G_REFRACTION_EPSILON,
refract3(normalize3(hitrecord.normal_g), normalize3(ray.direction), hitrecord.material.refraction)
Expand Down

0 comments on commit 91e62d4

Please sign in to comment.