Skip to content

Instantly share code, notes, and snippets.

@almarklein
Last active July 2, 2025 15:03
Show Gist options
  • Select an option

  • Save almarklein/4d05f26939bcc17832c8f7bc1a27334b to your computer and use it in GitHub Desktop.

Select an option

Save almarklein/4d05f26939bcc17832c8f7bc1a27334b to your computer and use it in GitHub Desktop.
import time
import numpy as np
import imageio.v2 as iio
import pygfx as gfx
from rendercanvas.offscreen import RenderCanvas
canvas = RenderCanvas(size=(1920, 1080), pixel_ratio=1)
renderer = gfx.renderers.WgpuRenderer(canvas,
pixel_ratio=1,
# pixel_filter='nearest'
ppaa="fxaa"
)
im = iio.imread("/Users/almar/dev/py/ppaa-experiments/images_all/synthetic.png")
canvas.set_logical_size(im.shape[1], im.shape[0])
scene = gfx.Scene()
tex = gfx.Texture(im, dim=2)
mesh = gfx.Image(
gfx.Geometry(grid=tex),
gfx.ImageBasicMaterial(clim=(0, 255))
)
scene.add(mesh)
camera = gfx.OrthographicCamera()
camera.show_object(scene, match_aspect=True)
camera.local.scale_y = -1
canvas.request_draw(lambda: renderer.render(scene, camera))
im2 = np.asarray(canvas.draw())
print(np.allclose(im, im2[:,:,:3]))
t0 = time.perf_counter()
n = 0
while time.perf_counter() - t0 < 1:
for _ in range(100):
canvas.draw()
n += 100
t1 = time.perf_counter()
print(f"{1000 * (t1 - t0)/n:0.1f} ms per frame")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment