MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / line

Function line

pyrender.py:1197–1231  ·  view source on GitHub ↗
(normal, left, right, y)

Source from the content-addressed store, hash-verified

1195
1196 def rasterize_solid(A, B, C, normal):
1197 def line(normal, left, right, y):
1198 # faster than max(...), min(...)
1199 if left[8] <= 0:
1200 x_start = 0
1201 else:
1202 x_start = left[8]
1203 if right[8] >= cam.width - 1:
1204 x_end = cam.width - 1
1205 else:
1206 x_end = right[8]
1207
1208 for x in range(x_start, x_end):
1209 p1 = (x - left[8]) / (right[8] - left[8])
1210 p2 = 1 - p1
1211 z3d = 1 / (p2 * left[2] + p1 * right[2])
1212 if z3d < depth_buffer[y][x]:
1213 if cam.obj_buffer:
1214 obj_buffer[y][x] = obj
1215 depth_buffer[y][x] = z3d
1216 # calculate the light
1217 x3d = (p2 * left[0] + p1 * right[0]) * z3d
1218 y3d = (p2 * left[1] + p1 * right[1]) * z3d
1219 if obj.shade_smooth and cam.mode <= 1:
1220 normal = (
1221 p2 * left[5] + p1 * right[5],
1222 p2 * left[6] + p1 * right[6],
1223 p2 * left[7] + p1 * right[7],
1224 )
1225 length = sqrt(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2])
1226 normal = (normal[0]/length, normal[1]/length, normal[2]/length)
1227
1228 luminance = get_luminance(normal, x3d, y3d, z3d)
1229 frame[y][x] = (min(int(127 * luminance[0]), 255),
1230 min(int(127 * luminance[1]), 255),
1231 min(int(127 * luminance[2]), 255))
1232
1233 # Sorting by y, from lowest to highest in value but from top to bottom in what u see
1234 if A[9] > B[9]:

Callers 3

rasterize_solidFunction · 0.85
rasterize_fullFunction · 0.85
textureFunction · 0.85

Calls 1

get_luminanceFunction · 0.85

Tested by

no test coverage detected