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

Function orthographic_render_shadow

pyrender.py:3021–3308  ·  view source on GitHub ↗

Only for shadow rendering now, so some features are disabled and others are set for shadow rendering solely

(objects:list, cam:Camera)

Source from the content-addressed store, hash-verified

3019
3020
3021def orthographic_render_shadow(objects:list, cam:Camera):
3022 """
3023 Only for shadow rendering now, so some features are disabled and
3024 others are set for shadow rendering solely
3025 """
3026 # depth only
3027 def depth(A, B, C):
3028 # Sorting by y, from lowest to highest in value but from top to bottom in what u see
3029 if A[4] > B[4]:
3030 A, B = B, A
3031 if B[4] > C[4]:
3032 B, C = C, B
3033 if A[4] > B[4]:
3034 A, B = B, A
3035 # Remove some of those out of screen
3036 if A[4] >= cam.height or C[4] < 0 or A[4] == C[4]:
3037 return
3038
3039 if A[4] == B[4]:
3040 # If line AB can be seen, add line AB
3041 if A[3] < B[3]:
3042 left = A
3043 right = B
3044 else:
3045 left = B
3046 right = A
3047 if A[4] >= 0:
3048 for x in range(max(0, left[3]), min(cam.width - 1, right[3])):
3049 p1 = (x - left[3]) / (right[3] - left[3])
3050 p2 = 1 - p1
3051 z3d = p2 * left[2] + p1 * right[2]
3052 if z3d < depth_buffer[A[4]][x]:
3053 depth_buffer[A[4]][x] = z3d
3054 # The rest of the triangle
3055 t1 = (A[3] - C[3]) / (A[4] - C[4])
3056 b1 = A[3] - A[4] * t1
3057 t2 = (B[3] - C[3]) / (B[4] - C[4])
3058 b2 = B[3] - B[4] * t2
3059 for y in range(max(0, B[4]), min(cam.height - 1, C[4])):
3060 m1 = (y - A[4]) / (C[4] - A[4])
3061 m2 = 1 - m1
3062 # x, z, u, v, s, x2d, y2d
3063 left = (m2 * A[0] + m1 * C[0],
3064 m2 * A[1] + m1 * C[1],
3065 m2 * A[2] + m1 * C[2],
3066 int(t1 * y + b1),
3067 y,
3068 )
3069 right = (m2 * B[0] + m1 * C[0],
3070 m2 * B[1] + m1 * C[1],
3071 m2 * B[2] + m1 * C[2],
3072 int(t2 * y + b2),
3073 y,
3074 )
3075
3076 if left[3] > right[3]:
3077 left, right = right, left
3078 for x in range(max(0, left[3]), min(cam.width - 1, right[3])):

Callers 1

render_shadowMethod · 0.85

Calls 1

depthFunction · 0.85

Tested by

no test coverage detected