Skip to content

Pixels

Pixels

Pixels(
    positions: Transform | Buffer,
    colors: Transform | Buffer | Color,
)

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.

IN/OUT variables
// Rendering stage 1
in uniform vec4 viewport;               // in("viewport")
in attribute [ vec2 | vec3 ] positions; // in("positions")
in [ attribute | uniform ] vec4 colors; // in("colors")

// Rendering stage 2
out attribute vec3 screen;              // out("screen[positions]")

// Rendering stage 3
out attribute vec4 colors;              // out("colors")
Example
positions = core.Buffer(3, np.dtype(np.float32))
pixels = visual.Pixels(positions, colors=(0,0,0,1))
1. COMMAND
     - METHOD: "core.Buffer" (str)
     - COMMAND_ID: 1 (int)
     - TIMESTAMP: 2024-08-21T12:52:34.023398 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - COUNT: 3 (int)
     - DTYPE: float32 (dtype)
     - DATA: None (memoryview | bytes)

2. COMMAND
     - METHOD: "visual.Pixels" (str)
     - COMMAND_ID: 2 (int)
     - TIMESTAMP: 2024-08-21T12:52:34.023470 (datetime)
   PARAMETERS
     - OBJECT_ID: 2 (int)
     - POSITIONS_ID: 1 (Transform | Buffer)
     - COLORS: Color(r=0, g=0, b=0, a=1) (converted) (Transform | Buffer | Color)

{
  "jsonrpc": "2.0",
  "commands": [
    {
      "method": "core.Buffer",
      "id": 1,
      "timestamp": 1724237554.023398,
      "parameters": {
        "id": 1,
        "count": 3,
        "dtype": "float32",
        "data": null
      }
    },
    {
      "method": "visual.Pixels",
      "id": 2,
      "timestamp": 1724237554.02347,
      "parameters": {
        "id": 2,
        "positions(id)": 1,
        "colors": [
          0,
          0,
          0,
          1
        ]
      }
    }
  ]
}

Create a Pixels visual at given positions and given colors. If positions is a transform, it is first evaluated and produce the "screen" and "depth" buffers. If the type of positions is vec2, the z coordinate of all pixels is set to the default z coordinate (0). If colors is a transform, it is first evaluated and produce the "colors" buffer.

Parameters:

Name Type Description Default
positions Transform | Buffer

Pixel positions (vec3 or vec2)

required
colors Transform | Buffer | Color

Pixel colors (vec4)

required

render

render(
    viewport: Viewport,
    model: Matrix = None,
    view: Matrix = None,
    proj: Matrix = None,
)

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