Skip to main content

JaxGL

JaxGL is a simple and flexible graphics library written entirely in JAX. JaxGL was created by Michael Matthews and Michael Beukman for the Kinetix project.

💻 Basic Usage

# 512x512 pixels
screen_size = (512, 512)

# Clear a fresh screen with a black background
clear_colour = jnp.array([0.0, 0.0, 0.0])
pixels = clear_screen(screen_size, clear_colour)

# We render to a 256x256 'patch'
patch_size = (256, 256)
triangle_renderer = make_renderer(screen_size, fragment_shader_triangle, patch_size)

# Patch position (top left corner)
pos = jnp.array([128, 128])

triangle_data = (
    # Vertices (note these must be anti-clockwise)
    jnp.array([[150, 200], [150, 300], [300, 150]]),
    # Colour
    jnp.array([255.0, 0.0, 0.0]),
)

# Render the triangle to the screen
pixels = triangle_renderer(pixels, pos, triangle_data)

This produces the following image:

👨‍💻 Custom Shaders

Arbitrary rendering effects can be achieved by writing your own shaders.

screen_size = (512, 512)

clear_colour = jnp.array([0.0, 0.0, 0.0])
pixels = clear_screen(screen_size, clear_colour)

patch_size = (256, 256)

# We make our own variation of the circle shader
# We give both a central and edge colour and interpolate between these

# Each fragment shader has access to
# position: global position in screen space
# current_frag: the current colour of the fragment (useful for transparency)
# unit_position: the position inside the patch (scaled to between 0 and 1)
# uniform: anything you want for your shader.  These are the same for every fragment.

def my_shader(position, current_frag, unit_position, uniform):
    centre, radius, colour_centre, colour_outer = uniform

    dist = jnp.sqrt(jnp.square(position - centre).sum())
    colour_interp = dist / radius

    colour = colour_interp * colour_outer + (1 - colour_interp) * colour_centre

    return jax.lax.select(dist < radius, colour, current_frag)

circle_renderer = make_renderer(screen_size, my_shader, patch_size)

# Patch position (top left corner)
pos = jnp.array([128, 128])

# This is the uniform that is passed to the shader
circle_data = (
    # Centre
    jnp.array([256.0, 256.0]),
    # Radius
    100.0,
    # Colour centre
    jnp.array([255.0, 0.0, 0.0]),
    # Colour outer
    jnp.array([0.0, 255.0, 0.0]),
)

# Render the triangle to the screen
pixels = circle_renderer(pixels, pos, circle_data)

🔄 In Kinetix

JaxGL is used for rendering in Kinetix. Shown below is an example robotics grasping task.

⬇️ Installation

To use JaxGL in your work you can install via PyPi:

pip install jaxgl

If you want to extend JaxGL you can install as follows:

git clone https://github.com/FLAIROx/JaxGL
cd JaxGL
pip install -e ".[dev]"
pre-commit install

🔍 See Also

  • JAX Renderer A more complete JAX renderer more suitable for 3D rendering.
  • Jax2D 2D physics engine in JAX.
  • Kinetix physics-based reinforcement learning in JAX.

Metadata

Release files for jaxgl 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jaxgl 1.0.1
File Size Uploaded Provenance Actions
jaxgl-1.0.1.tar.gz 6.5 kB Without provenance Details for jaxgl-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jaxgl 1.0.1
File Interpreter ABI Platform Actions
jaxgl-1.0.1-py3-none-any.whl Python 3 none any Details for jaxgl-1.0.1-py3-none-any.whl

Total release size: 13.2 kB

Release files / jaxgl-1.0.1.tar.gz

Download URL jaxgl-1.0.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
051a1975f2e1932c64b98e9770473ed5c102387f69fa2edded214439de8688e0
BLAKE2b-256 checksum
How to use checksums
504dbfa0f8bf4fd3e85312a77cacba2a507d22feb211e9151bc4ea5da14e6050
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / jaxgl-1.0.1-py3-none-any.whl

Download URL jaxgl-1.0.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9940ef8a578e4571a4a8ffcdb1e1a2b686df7f1cd46cb6e680437edbffe947e
BLAKE2b-256 checksum
How to use checksums
f3e13ac61628a0cc048a83a088a67603486d7fbfd68ee0e8f8a22b41a0ddecf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for jaxgl 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page