jaxgl


Namejaxgl JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryAn simple JAX graphics library
upload_time2024-11-03 22:07:24
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JaxGL
<p align="center">
        <a href= "https://pypi.org/project/jaxgl/">
        <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue" /></a>
        <a href= "https://pypi.org/project/jaxgl/">
        <img src="https://img.shields.io/badge/pypi-1.0.1-green" /></a>
       <a href= "https://github.com/MichaelTMatthews/Craftax/blob/main/LICENSE">
        <img src="https://img.shields.io/badge/License-MIT-yellow" /></a>
       <a href= "https://github.com/psf/black">
        <img src="https://img.shields.io/badge/code%20style-black-000000.svg" /></a>
</p>

JaxGL is a simple and flexible graphics library written entirely in <a href="https://github.com/google/jax">JAX</a>.  JaxGL was created by [Michael Matthews](https://github.com/MichaelTMatthews) and [Michael Beukman](https://github.com/Michael-Beukman) for the [Kinetix](https://github.com/FLAIROx/Kinetix) project.

# 💻 Basic Usage
```python
# 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:

<p align="center">
 <img width="20%" src="images/simple_render.png" />
</p>

# 👨‍💻 Custom Shaders
Arbitrary rendering effects can be achieved by writing your own shaders.
```python
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)
```

<p align="center">
 <img width="20%" src="images/custom_shader.png" />
</p>

# 🔄 In Kinetix
JaxGL is used for rendering in [Kinetix](https://github.com/FLAIROx/Kinetix). Shown below is an example robotics grasping task.
<p align="center">
 <img width="40%" src="images/kinetix.png" />
</p>

# ⬇️ Installation
To use JaxGL in your work you can install via PyPi:
```commandline
pip install jaxgl
```

If you want to extend JaxGL you can install as follows:
```commandline
git clone https://github.com/FLAIROx/JaxGL
cd JaxGL
pip install -e ".[dev]"
pre-commit install
```

# 🔍 See Also
- [JAX Renderer](https://github.com/JoeyTeng/jaxrenderer) A more complete JAX renderer more suitable for 3D rendering.
- [Jax2D](https://github.com/MichaelTMatthews/Jax2D) 2D physics engine in JAX.
- [Kinetix](https://github.com/FLAIROx/Kinetix) physics-based reinforcement learning in JAX.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jaxgl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Michael Matthews <michael.matthews@eng.ox.ac.uk>, Michael Beukman <michael.beukman@eng.ox.ac.uk>",
    "download_url": "https://files.pythonhosted.org/packages/50/4d/bfa0f8bf4fd3e85312a77cacba2a507d22feb211e9151bc4ea5da14e6050/jaxgl-1.0.1.tar.gz",
    "platform": null,
    "description": "# JaxGL\n<p align=\"center\">\n        <a href= \"https://pypi.org/project/jaxgl/\">\n        <img src=\"https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12-blue\" /></a>\n        <a href= \"https://pypi.org/project/jaxgl/\">\n        <img src=\"https://img.shields.io/badge/pypi-1.0.1-green\" /></a>\n       <a href= \"https://github.com/MichaelTMatthews/Craftax/blob/main/LICENSE\">\n        <img src=\"https://img.shields.io/badge/License-MIT-yellow\" /></a>\n       <a href= \"https://github.com/psf/black\">\n        <img src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" /></a>\n</p>\n\nJaxGL is a simple and flexible graphics library written entirely in <a href=\"https://github.com/google/jax\">JAX</a>.  JaxGL was created by [Michael Matthews](https://github.com/MichaelTMatthews) and [Michael Beukman](https://github.com/Michael-Beukman) for the [Kinetix](https://github.com/FLAIROx/Kinetix) project.\n\n# \ud83d\udcbb Basic Usage\n```python\n# 512x512 pixels\nscreen_size = (512, 512)\n\n# Clear a fresh screen with a black background\nclear_colour = jnp.array([0.0, 0.0, 0.0])\npixels = clear_screen(screen_size, clear_colour)\n\n# We render to a 256x256 'patch'\npatch_size = (256, 256)\ntriangle_renderer = make_renderer(screen_size, fragment_shader_triangle, patch_size)\n\n# Patch position (top left corner)\npos = jnp.array([128, 128])\n\ntriangle_data = (\n    # Vertices (note these must be anti-clockwise)\n    jnp.array([[150, 200], [150, 300], [300, 150]]),\n    # Colour\n    jnp.array([255.0, 0.0, 0.0]),\n)\n\n# Render the triangle to the screen\npixels = triangle_renderer(pixels, pos, triangle_data)\n```\n\nThis produces the following image:\n\n<p align=\"center\">\n <img width=\"20%\" src=\"images/simple_render.png\" />\n</p>\n\n# \ud83d\udc68\u200d\ud83d\udcbb Custom Shaders\nArbitrary rendering effects can be achieved by writing your own shaders.\n```python\nscreen_size = (512, 512)\n\nclear_colour = jnp.array([0.0, 0.0, 0.0])\npixels = clear_screen(screen_size, clear_colour)\n\npatch_size = (256, 256)\n\n# We make our own variation of the circle shader\n# We give both a central and edge colour and interpolate between these\n\n# Each fragment shader has access to\n# position: global position in screen space\n# current_frag: the current colour of the fragment (useful for transparency)\n# unit_position: the position inside the patch (scaled to between 0 and 1)\n# uniform: anything you want for your shader.  These are the same for every fragment.\n\ndef my_shader(position, current_frag, unit_position, uniform):\n    centre, radius, colour_centre, colour_outer = uniform\n\n    dist = jnp.sqrt(jnp.square(position - centre).sum())\n    colour_interp = dist / radius\n\n    colour = colour_interp * colour_outer + (1 - colour_interp) * colour_centre\n\n    return jax.lax.select(dist < radius, colour, current_frag)\n\ncircle_renderer = make_renderer(screen_size, my_shader, patch_size)\n\n# Patch position (top left corner)\npos = jnp.array([128, 128])\n\n# This is the uniform that is passed to the shader\ncircle_data = (\n    # Centre\n    jnp.array([256.0, 256.0]),\n    # Radius\n    100.0,\n    # Colour centre\n    jnp.array([255.0, 0.0, 0.0]),\n    # Colour outer\n    jnp.array([0.0, 255.0, 0.0]),\n)\n\n# Render the triangle to the screen\npixels = circle_renderer(pixels, pos, circle_data)\n```\n\n<p align=\"center\">\n <img width=\"20%\" src=\"images/custom_shader.png\" />\n</p>\n\n# \ud83d\udd04 In Kinetix\nJaxGL is used for rendering in [Kinetix](https://github.com/FLAIROx/Kinetix). Shown below is an example robotics grasping task.\n<p align=\"center\">\n <img width=\"40%\" src=\"images/kinetix.png\" />\n</p>\n\n# \u2b07\ufe0f Installation\nTo use JaxGL in your work you can install via PyPi:\n```commandline\npip install jaxgl\n```\n\nIf you want to extend JaxGL you can install as follows:\n```commandline\ngit clone https://github.com/FLAIROx/JaxGL\ncd JaxGL\npip install -e \".[dev]\"\npre-commit install\n```\n\n# \ud83d\udd0d See Also\n- [JAX Renderer](https://github.com/JoeyTeng/jaxrenderer) A more complete JAX renderer more suitable for 3D rendering.\n- [Jax2D](https://github.com/MichaelTMatthews/Jax2D) 2D physics engine in JAX.\n- [Kinetix](https://github.com/FLAIROx/Kinetix) physics-based reinforcement learning in JAX.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "An simple JAX graphics library",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/FLAIROx/JaxGL",
        "Issues": "https://github.com/FLAIROx/JaxGL"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f3e13ac61628a0cc048a83a088a67603486d7fbfd68ee0e8f8a22b41a0ddecf6",
                "md5": "7565e739540785cd6ac841933df6d579",
                "sha256": "b9940ef8a578e4571a4a8ffcdb1e1a2b686df7f1cd46cb6e680437edbffe947e"
            },
            "downloads": -1,
            "filename": "jaxgl-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7565e739540785cd6ac841933df6d579",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6753,
            "upload_time": "2024-11-03T22:07:23",
            "upload_time_iso_8601": "2024-11-03T22:07:23.132988Z",
            "url": "https://files.pythonhosted.org/packages/f3/e1/3ac61628a0cc048a83a088a67603486d7fbfd68ee0e8f8a22b41a0ddecf6/jaxgl-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "504dbfa0f8bf4fd3e85312a77cacba2a507d22feb211e9151bc4ea5da14e6050",
                "md5": "2cfe88cc8463ec2d5c25f38338cea6b6",
                "sha256": "051a1975f2e1932c64b98e9770473ed5c102387f69fa2edded214439de8688e0"
            },
            "downloads": -1,
            "filename": "jaxgl-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2cfe88cc8463ec2d5c25f38338cea6b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 6478,
            "upload_time": "2024-11-03T22:07:24",
            "upload_time_iso_8601": "2024-11-03T22:07:24.623520Z",
            "url": "https://files.pythonhosted.org/packages/50/4d/bfa0f8bf4fd3e85312a77cacba2a507d22feb211e9151bc4ea5da14e6050/jaxgl-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-03 22:07:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "FLAIROx",
    "github_project": "JaxGL",
    "github_fetch_exception": true,
    "lcname": "jaxgl"
}
        
Elapsed time: 0.34420s