{"id":23815256,"url":"https://github.com/markusmoenig/rpu","last_synced_at":"2025-09-06T23:32:24.437Z","repository":{"id":237444573,"uuid":"790092682","full_name":"markusmoenig/RPU","owner":"markusmoenig","description":"RPU is a GLSL compatible programming language for rendering procedural graphics on the CPU.","archived":false,"fork":false,"pushed_at":"2024-05-14T05:42:05.000Z","size":2385,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T17:47:19.633Z","etag":null,"topics":["embedded-scripting-languages","glsl","graphics-programming","procedural-generation","programming-language","rendering","rust-lang"],"latest_commit_sha":null,"homepage":"https://rpu-lang.org","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markusmoenig.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"markusmoenig"}},"created_at":"2024-04-22T08:50:05.000Z","updated_at":"2024-06-25T09:07:09.000Z","dependencies_parsed_at":"2024-05-01T23:44:11.646Z","dependency_job_id":"db82533d-d1cf-40ce-9a50-af1c2c621963","html_url":"https://github.com/markusmoenig/RPU","commit_stats":null,"previous_names":["markusmoenig/rpu"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FRPU","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FRPU/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FRPU/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markusmoenig%2FRPU/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markusmoenig","download_url":"https://codeload.github.com/markusmoenig/RPU/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232150098,"owners_count":18479580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded-scripting-languages","glsl","graphics-programming","procedural-generation","programming-language","rendering","rust-lang"],"created_at":"2025-01-02T04:15:32.881Z","updated_at":"2025-01-02T04:15:33.898Z","avatar_url":"https://github.com/markusmoenig.png","language":"Rust","readme":"![header](/images/header.png)\n\nRPU is a GLSL compatible programming language for rendering procedural graphics on the CPU.\n\nAs GPU shaders can limit the complexity of what you can render, RPU aims to provide an alternative way of rendering complex, unlimited procedural graphics on the CPU, in 64-bit or 32-bit precision.\n\nRPU strives to be compatible with GLSL which means that you can easily port your existing shaders to RPU.\n\nAlternatively you can also use RPU as a general purpose mathematical scripting language, as it is designed to be fast and embeddable in your applications.\n\n## Features\n\n- GLSL compatible\n- 64-bit or 32-bit precision (decide on compile time)\n- Unlimited procedural graphics\n- Easy to port existing shaders\n- Fast and embeddable in your applications\n- Run shaders in your terminal via rpuc (see [Usage](./usage) for more info)\n\nRPU compiles to WebAssembly (WAT) and uses [wasmer](https://github.com/wasmerio/wasmer) as a runtime. Which means RPU has near native speed, is hot-reloadable and can run on any platform that wasmer supports.\n\nFor shaders it uses a multi-threaded tiled rendering approach, which splits the image into tiles and renders each tile in parallel.\n\n## Current Limitations\n\n- Only signed integers are supported at the moment, i.e. no unsigned integer types and their associated bit operations. As RPU has a `rand()` function which generates high quality random numbers on the Rust side, I do not see unsigned integers as a priority right now.\n\n- Function parameters do not support `in`, `out` or `inout` right now. Vectors and matrices are passed by value, structs are passed by reference. **I will add support for inout parameters in the near future.**\n\n- No textures yet, coming soon.\n\n- No preprocessor yet, coming soon.\n\n## Goals\n\n- Create a fast and embeddable GLSL compatible language for procedural graphics\n\n- Create a module system to easily import noise libraries, renderers, cameras etc (TBD)\n\n- Mesh generation for 3D SDF maps (TBD)\n\n## Getting Started\n\nUse the `export` keyword to export the function you want to run. For example to run a fibonacci sequence:\n\n```glsl\nint fib(int n) {\n  if (n \u003c= 1) return n;\n  return fib(n - 2) + fib(n - 1);\n}\n\nexport int main(int x) {\n  return fib(x);\n}\n```\n\nYou could then run this with `rpuc --source fib.rpu -f main -a 42` to get the fibonacci sequence of 42 which takes around a second on my machine.\n\nShaders have a signature of\n\n```glsl\nexport vec4 shader(vec2 coord, vec2 resolution) {\n  return vec4(1); // For an all white image\n}\n```\n\nYou could run this via `rpuc --source myshader.rpu -f shader --write`.\n\nThe resulting image will be saved by _rpuc_ as `myshader.png`. The `--write` flag tells rpuc to write the image to disk every time a tile is completed. Giving a live preview of the rendering process.\n\nRPU assumes that your shader uses stochastic sampling for anti-aliasing. You can pass the `--iterations` flag to _rpuc_ to specify the number of samples per pixel.\n\nA simple raymarching example:\n\n```glsl\n// Based on https://www.shadertoy.com/view/WtGXDD\n\nfloat sdBox(vec3 p, vec3 s) {\n    p = abs(p)-s;\n\treturn length(max(p, 0.))+min(max(p.x, max(p.y, p.z)), 0.);\n}\n\nfloat GetDist(vec3 p) {\n    float d = sdBox(p, vec3(.5));\n    return d;\n}\n\nvec3 GetRayDir(vec2 uv, vec3 p, vec3 l, float z) {\n    vec3 f = normalize(l-p);\n    vec3 r = normalize(cross(vec3(0,1,0), f));\n    vec3 u = cross(f,r);\n    vec3 c = f*z;\n    vec3 i = c + uv.x*r + uv.y*u;\n    return normalize(i);\n}\n\nvec3 GetNormal(vec3 p) {\n    vec2 e = vec2(0.001, 0.);\n    vec3 n = GetDist(p) - vec3(GetDist(p-e.xyy), GetDist(p-e.yxy), GetDist(p-e.yyx));\n    return normalize(n);\n}\n\nexport vec4 shader(vec2 coord, vec2 resolution) {\n    // Generate the uv with jittering for anti-aliasing\n    vec2 uv = (2.0 * (coord + vec2(rand(), rand())) - resolution.xy) / resolution.y;\n\n    vec3 ro = vec3(.7, .8, -1.);\n    vec3 rd = GetRayDir(uv, ro, vec3(0), 1.);\n\n    float t = 0.;\n    float max_t = 2.;\n\n    vec4 col = vec4(uv.x, uv.y, 0., 1.);\n\n    while (t \u003c max_t) {\n        vec3 p = ro + rd * t;\n        float d = GetDist(p);\n        if (abs(d) \u003c 0.001) {\n            vec3 n = GetNormal(p);\n            float dif = dot(n, normalize(vec3(1, 2, 3))) * 0.5 + 0.5;\n            col.xyz = pow(vec3(dif), .4545);\n\n            break;\n        }\n        t += d;\n    }\n\n    return col;\n}\n```\n\nBy executing the shader it generates the following image:\n![Raymarch](examples/raymarch.png)\n\n# Sponsors\n\nNone yet, but you can [sponsor me on GitHub](https://github.com/sponsors/markusmoenig/).\n","funding_links":["https://github.com/sponsors/markusmoenig","https://github.com/sponsors/markusmoenig/"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusmoenig%2Frpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkusmoenig%2Frpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkusmoenig%2Frpu/lists"}