MohmedAnik commited on
Commit
32e2f0d
·
verified ·
1 Parent(s): 4e1d694

Update render/speedup.py

Browse files
Files changed (1) hide show
  1. render/speedup.py +1 -14
render/speedup.py CHANGED
@@ -35,17 +35,8 @@ def cross_product(a0, a1, a2, b0, b1, b2):
35
  return x,y,z
36
 
37
 
38
- # @cython.boundscheck(False)
39
  def generate_faces(triangles, width, height):
40
- """ draw the triangle faces with z buffer
41
 
42
- Args:
43
- triangles: groups of vertices
44
-
45
- FYI:
46
- * zbuffer, https://github.com/ssloy/tinyrenderer/wiki/Lesson-3:-Hidden-faces-removal-(z-buffer)
47
- * uv mapping and perspective correction
48
- """
49
  i, j, k, length = 0, 0, 0, 0
50
  bcy, bcz, x, y, z = 0.,0.,0.,0.,0.
51
  a, b, c = [0.,0.,0.],[0.,0.,0.],[0.,0.,0.]
@@ -68,7 +59,7 @@ def generate_faces(triangles, width, height):
68
  pixels = []
69
  for j in range(minx, maxx + 2):
70
  for k in range(miny - 1, maxy + 2):
71
- # 必须显式转换成 double 参与底下的运算,不然结果是错的
72
  x = j
73
  y = k
74
 
@@ -80,18 +71,14 @@ def generate_faces(triangles, width, height):
80
  else:
81
  continue
82
 
83
- # here, -0.00001 because of the precision lose
84
  if bc[0] < -0.00001 or bc[1] < -0.00001 or bc[2] < -0.00001:
85
  continue
86
 
87
  z = 1 / (bc[0] / a[2] + bc[1] / b[2] + bc[2] / c[2])
88
 
89
- # Blender 导出来的 uv 数据,跟之前的顶点数据有一样的问题,Y轴是个反的,
90
- # 所以这里的纹理图片要旋转一下才能 work
91
  v = (uva[0] * bc[0] / a[2] + uvb[0] * bc[1] / b[2] + uvc[0] * bc[2] / c[2]) * z * width
92
  u = height - (uva[1] * bc[0] / a[2] + uvb[1] * bc[1] / b[2] + uvc[1] * bc[2] / c[2]) * z * height
93
 
94
- # https://en.wikipedia.org/wiki/Pairing_function
95
  idx = ((x + y) * (x + y + 1) + y) / 2
96
  if zbuffer.get(idx) is None or zbuffer[idx] < z:
97
  zbuffer[idx] = z
 
35
  return x,y,z
36
 
37
 
 
38
  def generate_faces(triangles, width, height):
 
39
 
 
 
 
 
 
 
 
40
  i, j, k, length = 0, 0, 0, 0
41
  bcy, bcz, x, y, z = 0.,0.,0.,0.,0.
42
  a, b, c = [0.,0.,0.],[0.,0.,0.],[0.,0.,0.]
 
59
  pixels = []
60
  for j in range(minx, maxx + 2):
61
  for k in range(miny - 1, maxy + 2):
62
+
63
  x = j
64
  y = k
65
 
 
71
  else:
72
  continue
73
 
 
74
  if bc[0] < -0.00001 or bc[1] < -0.00001 or bc[2] < -0.00001:
75
  continue
76
 
77
  z = 1 / (bc[0] / a[2] + bc[1] / b[2] + bc[2] / c[2])
78
 
 
 
79
  v = (uva[0] * bc[0] / a[2] + uvb[0] * bc[1] / b[2] + uvc[0] * bc[2] / c[2]) * z * width
80
  u = height - (uva[1] * bc[0] / a[2] + uvb[1] * bc[1] / b[2] + uvc[1] * bc[2] / c[2]) * z * height
81
 
 
82
  idx = ((x + y) * (x + y + 1) + y) / 2
83
  if zbuffer.get(idx) is None or zbuffer[idx] < z:
84
  zbuffer[idx] = z