Pixels
Pixels
Quick documentation
Pixels are the smallest entities that can be rendered on screen (pixel or fragment) or on paper (dot). They can be colored but have no dimension and correspond to the true mathematical notion of a point.
import numpy as np
import matplotlib.pyplot as plt
from gsp import glm, core, visual, transform
canvas = core.Canvas(512, 512, 100.0)
viewport = core.Viewport(canvas, 0, 0, 512, 512)
camera = glm.Camera("perspective", theta=10, phi=10)
P = glm.vec3(250_000)
P.xyz = np.random.uniform(-1, +1, (len(P),3))
pixels = visual.Pixels(P)
pixels.render(viewport, camera.transform)
camera.connect(viewport, "motion", pixels.render)
plt.savefig("../docs/assets/simple-pixels.png")
plt.show()
__init__
Create a visual of n pixels at given positions with given colors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
positions |
Transform | Buffer
|
Pixels position (vec3) |
required |
colors |
Transform | Buffer | Color
|
Pixels colors (vec4) |
Color(0, 0, 0, 1)
|
Notes on matplotlib implementation
Even with antialias off, marker coverage leaks on neighbouring pixels if the position is not an exact divider of viewport size (in pixels). Vertices coordinates vould be rounded at time of rendering but it is easier to set a very small size whose coverage is more or less guaranteed to be one pixel. However, this size seems to be wrong on Windows, dependng on the screen size.
render
Render the visual on viewport using the given model, view, proj matrices
Parameters:
Name | Type | Description | Default |
---|---|---|---|
viewport |
Viewport
|
Viewport where to render the visual |
required |
model |
mat4
|
Model matrix to use for rendering |
None
|
view |
mat4
|
View matrix to use for rendering |
None
|
proj |
mat4
|
Projection matrix to use for rendering |
None
|