Custom Render Pipeline - ZackWilde27/Z3dPy GitHub Wiki
This page goes over how to code the render pipeline. An explanation of what each stage does can be found here
The original pipeline is easy to use but doesn't offer much control
for tri in z3dpy.Raster():
Instead, Rastering can be split up into the various stages:
def myRenderPipeline(thingList):
viewed = []
for t in thingList:
# Code that runs for each thing
for m in t[0]:
# Code that runs for each mesh
forward = z3dpy.RotTo(z3dpy.MeshGetRot(m), [0, 0, 1])
up = z3dpy.RotTo(z3dpy.MeshGetRot(m), [0, 1, 0])
transformed = z3dpy.TransformTris(z3dpy.MeshGetTris(m), zp.MeshGetPos(m), forward, up))
for t in transformed:
# Code that runs for each world-space triangle
for r in z3dpy.ViewTris(transformed):
# Code that runs for each view-space triangle
viewed.append(r)
projected = z3dpy.ProjectTris(viewed)
for i in projected:
# Code that runs for each 2D triangle
return projected
# Now, when drawing the screen:
for tri in myRenderPipeline([myThing], myCamera):
The built-in raster functions do quite a lot of extra features that speed things up, like clipping, and making sure that triangles facing away from the camera are not rendered.
in 0.2.8+, TransformTris() does culling automatically
def myRenderPipeline(thingList):
viewed = []
for th in thingList:
for m in th[0]:
for t in z3dpy.ViewTris(z3dpy.TransformTris(z3dpy.MeshGetTris(m), z3dpy.RotTo(z3dpy.MeshGetRot(m), [0, 0, 1]), z3dpy.RotTo(z3dpy.MeshGetRot(m), [0, 1, 0])))
# Clipping triangles behind the camera
for r in z3dpy.TriClipAgainstZ(t):
viewed.append(r)
# Sorting triangles by their center point's distance from the camera
viewed.sort(key=zp.triSortAverage, reverse=True)
for i in zp.ProjectTris(viewed):
# Clip against the 4 edges of the screen
for s in zp.TriClipAgainstScreenEdges(i):
yield s