{"id":21912632,"url":"https://github.com/crossgl/crosstl","last_synced_at":"2025-04-04T15:07:00.821Z","repository":{"id":251063839,"uuid":"795144462","full_name":"CrossGL/crosstl","owner":"CrossGL","description":"Translates native shader languages into CrossGL universal shader language and vice versa.","archived":false,"fork":false,"pushed_at":"2025-03-29T08:37:25.000Z","size":728,"stargazers_count":67,"open_issues_count":1,"forks_count":92,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T05:31:20.788Z","etag":null,"topics":["apple","directx","game-development","gamedev","graphics","hacktoberfest","metal","modular","mojo","opengl","python","vulkan"],"latest_commit_sha":null,"homepage":"https://crossgl.net","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CrossGL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-02T17:08:27.000Z","updated_at":"2025-03-30T21:16:53.000Z","dependencies_parsed_at":"2024-08-17T15:31:10.730Z","dependency_job_id":"6c28e02b-9f5c-40c9-b6ad-919cbb047f02","html_url":"https://github.com/CrossGL/crosstl","commit_stats":null,"previous_names":["crossgl/crosstl"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGL%2Fcrosstl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGL%2Fcrosstl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGL%2Fcrosstl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CrossGL%2Fcrosstl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CrossGL","download_url":"https://codeload.github.com/CrossGL/crosstl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198444,"owners_count":20900079,"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":["apple","directx","game-development","gamedev","graphics","hacktoberfest","metal","modular","mojo","opengl","python","vulkan"],"created_at":"2024-11-28T18:11:39.223Z","updated_at":"2025-04-04T15:07:00.804Z","avatar_url":"https://github.com/CrossGL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"display: block;\" align=\"center\"\u003e\n    \u003cimg class=\"only-dark\" width=\"10%\" height=\"10%\" src=\"https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/logo.png#gh-dark-mode-only\"/\u003e\n\u003c/div\u003e\n\n\n------------------------------------------------------------------------\n\n\u003cdiv style=\"display: block;\" align=\"center\"\u003e\n    \u003cimg class=\"dark-light\" width=\"5%\" \u003e\n    \u003ca href=\"https://crossgl.net/\"\u003e\n        \u003cimg class=\"dark-light\" height=\"5%\" width=\"5%\" src=\"https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/web_icon.png\"\u003e\n    \u003c/a\u003e\n    \u003cimg class=\"dark-light\" width=\"5%\" \u003e\n    \u003ca href=\"https://crossgl.github.io/crossgl-docs/language.html\"\u003e\n        \u003cimg class=\"dark-light\" height=\"5%\" width=\"5%\" src=\"https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/docs.png\"\u003e\n    \u003c/a\u003e\n    \u003cimg class=\"dark-light\" width=\"5%\" \u003e\n    \u003ca href=\"https://github.com/CrossGL/demos\"\u003e\n        \u003cimg class=\"dark-light\" height=\"5%\" width=\"5%\" src=\"https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/written.png\"\u003e\n    \u003c/a\u003e\n    \u003cimg class=\"dark-light\" width=\"5%\" \u003e\n    \u003ca href=\"https://crossgl.github.io/crossgl-docs/design.html\"\u003e\n        \u003cimg class=\"dark-light\" height=\"5%\" width=\"5%\" src=\"https://github.com/CrossGL/crossgl-docs/blob/main/docs/assets/strategic-plan.png\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n\u003cdiv style=\"margin-top: 10px; margin-bottom: 10px; display: block;\" align=\"center\"\u003e\n    \u003ca href=\"https://github.com/CrossGL/crosstl/issues\"\u003e\n        \u003cimg class=\"dark-light\" style=\"padding-right: 4px; padding-bottom: 4px;\" src=\"https://img.shields.io/github/issues/CrossGL/crosstl\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/CrossGL/crosstl/network/members\"\u003e\n        \u003cimg class=\"dark-light\" style=\"padding-right: 4px; padding-bottom: 4px;\" src=\"https://img.shields.io/github/forks/CrossGL/crosstl\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/CrossGL/crosstl/stargazers\"\u003e\n        \u003cimg class=\"dark-light\" style=\"padding-right: 4px; padding-bottom: 4px;\" src=\"https://img.shields.io/github/stars/CrossGL/crosstl\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/CrossGL/crosstl/pulls\"\u003e\n        \u003cimg class=\"dark-light\" style=\"padding-right: 4px; padding-bottom: 4px;\" src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/crosstl/\"\u003e\n        \u003cimg class=\"dark-light\" style=\"padding-right: 4px; padding-bottom: 4px;\" src=\"https://badge.fury.io/py/crosstl.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://discord.com/invite/uyRQKXhcyW\"\u003e\n        \u003cimg class=\"dark-light\" style=\"padding-right: 4px; padding-bottom: 4px;\" src=\"https://img.shields.io/discord/1240998239206113330?color=blue\u0026label=%20\u0026logo=discord\u0026logoColor=white\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr clear=\"all\" /\u003e\n\n# CrossTL\n\nThe CrossTL is a core component of our platform, enabling the conversion of CrossGL shader code directly into various graphics APIs, such as DirectX, Metal, Vulkan, and OpenGL and vice-versa. This translator simplifies shader development by allowing a single, unified shader language to be used across multiple platforms.\n\n## 🌟 CrossGL-Graphica: Revolutionizing Shader Development\n\n### The Universal Shader Language\n\nIn the ever-evolving world of graphics programming, **CrossGL** emerges as a solution to bridge the gap between diverse graphics APIs.\n\n#### 🚀 Write Once, Run Everywhere\n\nImagine writing a shader _once_ and deploying it across:\n\n- 🍎 **Metal**\n- 🎮 **DirectX**\n- 🖥️ **OpenGL**\n- 🖥️ **Vulkan**\n- ⚙️  **Slang** \n- 🔥 **Mojo**\n\n...all without changing a single line of code!\n\n## Supported Backends\n\n- Metal\n- DirectX\n- OpenGL\n- Slang\n\n\n## 💡 Key Benefits\n\n1. **⏱️ Time-Saving**: Slash development time by eliminating the need for multiple shader versions.\n2. **🛠️ Consistency**: Ensure uniform behavior across all platforms.\n3. **🧠 Simplified Learning Curve**: Master one language instead of many.\n4. **🔍 Enhanced Debugging**: Develop universal tools for shader analysis.\n5. **🔮 Future-Proof**: Easily adapt to new graphics APIs as they emerge.\n\n## How It Works\n\nThe translator takes CrossGL shader code and processes it through several stages:\n\n1. **Parsing**: The code is parsed into an abstract syntax tree (AST).\n2. **Intermediate Representation**: The AST is converted into an intermediate representation (IR) for optimization.\n3. **Code Generation**: The IR is translated into the target backend code.\n4. **Optimization**: Various optimization passes are applied to ensure maximum performance.\n5. **Source Output**: The final output is produced and ready for use.\n\n## 🔄 Two-Way Translation: From Platform-Specific to CrossGL\n\nCrossGL doesn't just translate from a universal language to platform-specific shaders - it also works in reverse! This powerful feature allows developers to convert existing shaders from various platforms into CrossGL.\n\n## 🌈 CrossGL Shader\n\n```cpp\nshader main {\n    vertex {\n        input vec3 position;\n        output vec2 vUV;\n\n        void main() {\n            vUV = position.xy * 10.0;\n            gl_Position = vec4(position, 1.0);\n        }\n    }\n\n    float perlinNoise(vec2 p) {\n        return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);\n    }\n\n    fragment {\n        input vec2 vUV;\n        output vec4 fragColor;\n\n        void main() {\n            float noise = perlinNoise(vUV);\n            float height = noise * 10.0;\n            vec3 color = vec3(height / 10.0, 1.0 - height / 10.0, 0.0);\n            fragColor = vec4(color, 1.0);\n        }\n    }\n}\n\n```\n\n# Getting started\n\n\nFirst, install CrossGL's translation library using pip:\n\n```bash\npip install crosstl\n```\n\n#### Using CrossGL\n\n1. Create a CrossGL shader file (e.g., `shader.cgl`):\n\n```glsl\nshader main {\n    vertex {\n        input vec3 position;\n        output vec2 vUV;\n\n        void main() {\n            vUV = position.xy * 10.0;\n            gl_Position = vec4(position, 1.0);\n        }\n    }\n\n    fragment {\n        input vec2 vUV;\n        output vec4 fragColor;\n\n        void main() {\n            fragColor = vec4(vUV, 0.0, 1.0);\n        }\n    }\n}\n```\n\n2. Translate to your desired backend:\n\n```python\nimport crosstl\n\n# Translate to Metal\nmetal_code = crosstl.translate('shader.cgl', backend='metal', save_shader= 'shader.metal')\n\n# Translate to DirectX (HLSL)\nhlsl_code = crosstl.translate('shader.cgl', backend='directx', save_shader= 'shader.hlsl')\n\n# Translate to OpenGL\nopengl_code = crosstl.translate('shader.cgl', backend='opengl', save_shader= 'shader.glsl')\n\n```\n\n#### Converting from HLSL to CrossGL\n\n1. write your HLSL shader (e.g., `shader.hlsl`):\n\n```hlsl\nstruct VS_INPUT {\n    float3 position : POSITION;\n};\n\nstruct PS_INPUT {\n    float4 position : SV_POSITION;\n    float2 uv : TEXCOORD0;\n};\n\nPS_INPUT VSMain(VS_INPUT input) {\n    PS_INPUT output;\n    output.position = float4(input.position, 1.0);\n    output.uv = input.position.xy * 10.0;\n    return output;\n}\n\nfloat4 PSMain(PS_INPUT input) : SV_TARGET {\n    return float4(input.uv, 0.0, 1.0);\n}\n```\n\n2. Convert to CrossGL:\n\n```python\nimport crosstl\n\ncrossgl_code = crosstl.translate('shader.hlsl', backend='cgl', save_shader= 'shader.cgl')\nprint(crossgl_code)\n```\n\n#### Converting from Metal to CrossGL\n\n1. write your Metal shader (e.g., `shader.metal`):\n\n```metal\n#include \u003cmetal_stdlib\u003e\nusing namespace metal;\n\nstruct VertexInput {\n    float3 position [[attribute(0)]];\n};\n\nstruct VertexOutput {\n    float4 position [[position]];\n    float2 uv;\n};\n\nvertex VertexOutput vertexShader(VertexInput in [[stage_in]]) {\n    VertexOutput out;\n    out.position = float4(in.position, 1.0);\n    out.uv = in.position.xy * 10.0;\n    return out;\n}\n\nfragment float4 fragmentShader(VertexOutput in [[stage_in]]) {\n    return float4(in.uv, 0.0, 1.0);\n}\n```\n\n2. Convert to CrossGL:\n\n```python\nimport crosstl\n\ncrossgl_code = crosstl.translate('shader.metal', backend='cgl')\nprint(crossgl_code)\n```\n\nWith these examples, you can easily get started with CrossGL, translating between different shader languages, and integrating existing shaders into your CrossGL workflow. Happy shader coding! 🚀✨\n\nFor more deep dive into crosstl , check out our [Getting Started Notebook](https://colab.research.google.com/drive/1reF8usj2CA5R6M5JSrBKOQBtU4WW-si2?usp=sharing#scrollTo=D7qkQrpcQ7zF).\n\n\n# Contributing\n\n\nWe believe that everyone can contribute and make a difference. Whether\nit\\'s writing code, fixing bugs, or simply sharing feedback,\nyour contributions are definitely welcome and appreciated 🙌\n\nfind out more info in our [Contributing guide](CONTRIBUTING.md)\n\n\u003ca href=\"https://github.com/CrossGL/crosstl/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=CrossGL/crosstl\" /\u003e\n\u003c/a\u003e\n\n\n\n# Community\n\n\u003cb\u003e Stay connected and follow our latest updates and announcements \u003c/b\u003e\n\n- [Twitter](https://x.com/crossGL_)\n- [LinkedIn](https://www.linkedin.com/company/crossgl/?viewAsMember=true)\n- [Discord Channel](https://discord.com/invite/uyRQKXhcyW)\n- [YouTube](https://www.youtube.com/channel/UCxv7_flRCHp7p0fjMxVSuVQ)\n\n\u003cb\u003e See you there! \u003c/b\u003e\n\u003cbr\u003e\n\n\u003cbr\u003e\n\n\n## License\n\nThe CrossGL Translator is open-source and licensed under the [License](https://github.com/CrossGL/crosstl/blob/main/LICENSE).\n\n\u003cbr\u003e\n\nThank you for using the CrossGL Translator!\n\nThe CrossGL Team\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrossgl%2Fcrosstl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrossgl%2Fcrosstl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrossgl%2Fcrosstl/lists"}