Pixel Shaders - ZackWilde27/Z3dPy GitHub Wiki
The Z3dPy Pixel Shader draws textured triangles, with a performance cost.
I'd recommend using the uvpln.obj that comes with the pixel shader, as the UV calculations aren't the most stable
Textures
Right now, the only way to avoid writing textures manually is using PgLoadTexture()
You'll need NumPy installed.
# PgLoadTexture(filename, pygame)
myTexture = z3dpy.PgLoadTexture("z3dpy/textures/thatOne.png", pygame)
But textures can be written manually, with enough patience.
Textures are a matrix, or list of lists, creating a grid.
myTexture = (((255, 255, 255, True), (0, 0, 0, True)), ((0, 0, 0, True), (255, 255, 255, True)))
It might be easier to visualize if I write it like this:
myTexture = (
((255, 255, 255, True), (0, 0, 0, True)),
((0, 0, 0, True), (255, 255, 255, True))
)
It's a 2x2 black and white checker pattern
Each texel has a transparency bool. False ones are not drawn.
Drawing
PyGame
First, convert your surface into a pixel array
screen = pygame.display.set_mode((1280, 720))
screenArray = pygame.PixelArray(screen)
In order for the depth buffer to work, the screen needs to be filled with black.
screen.fill("black")
Now when drawing, use PgPixelShader instead of PgDrawTri
# Raster(*sortingMethod, *reverseSort)
# Make sure reverseSort is False when using the pixel shader
for tri in z3dpy.Raster(z3dpy.triSortAverage, False):
z3dpy.PgPixelShader(tri, screenArray, myTexture)
Tkinter
Tkinter needs no setup, use TkPixelShader instead of TkDrawTri
for tri in z3dpy.Raster(z3dpy.triSortAverage, False):
z3dpy.TkPixelShader(tri, canvas, myTexture)
Multiple textures
What I'd recommend is making a tuple of textures, and picking them based on mesh id
textures = (myTexture, myOtherTexture)
z3dpy.MeshSetId(myMesh, 0)
z3dpy.MeshSetId(myOtherMesh, 1)
# Then, when drawing...
z3dpy.PgPixelShader(tri, screenArray, textures[z3dpy.TriGetId(tri)])