Skip to main content

Convert Unity ShaderLab/HLSL shaders to Godot 4.x GDShader — CLI, Python API, and Web UI

Project description

ShaderBridge

Convert Unity ShaderLab/HLSL shaders to Godot 4.x GDShader — CLI, Python API, and Web UI.

PyPI version Python 3.8+ License: MIT


Features

  • Full ShaderLab parser — Properties, SubShaders, Passes, CGPROGRAM/HLSLPROGRAM
  • HLSL → GDShader translator — types, functions, matrices, time, lighting
  • Surface shader supportsurf()fragment() with PBR output mapping
  • Compatibility checker — scores shaders 0–100%, flags unsupported features
  • Rich CLI — convert, batch, validate, info, watch, serve, pipe
  • Python API — import and use in your own tools
  • Web UI — browser-based editor with live validation and 3D preview
  • AI conversion — optional Groq LLM fallback for complex shaders

Install

# Core CLI only (no web server)
pip install shaderbridge

# With web UI server
pip install "shaderbridge[web]"

# With file-watch mode
pip install "shaderbridge[watch]"

# Everything
pip install "shaderbridge[all]"

CLI Usage

Convert a single shader

shaderbridge convert MyShader.shader
shaderbridge convert MyShader.shader -o out/MyShader.gdshader
shaderbridge convert MyShader.shader --validate --verbose --show-output

Batch convert a directory

shaderbridge batch ./Assets/Shaders/ -o ./GodotProject/shaders/
shaderbridge batch ./Assets/ -o ./out/ --validate --fail-fast

Validate compatibility

shaderbridge validate MyShader.shader
shaderbridge validate MyShader.shader --json

Inspect shader metadata

shaderbridge info MyShader.shader

Watch mode (auto-convert on save)

pip install "shaderbridge[watch]"
shaderbridge watch ./Assets/Shaders/ -o ./GodotProject/shaders/

Launch web UI

pip install "shaderbridge[web]"
shaderbridge serve
shaderbridge serve --port 8080 --no-browser

Pipe / stdin mode (CI-friendly)

cat MyShader.shader | shaderbridge pipe > MyShader.gdshader
cat MyShader.shader | shaderbridge pipe --validate --json

JSON output for scripting

shaderbridge convert MyShader.shader --json
shaderbridge batch ./shaders/ --json | jq '.results[] | select(.success == false)'

Python API

from shader_converter.parser.unity_shader_parser import UnityShaderParser
from shader_converter.generator.godot_shader_generator import AdvancedGodotShaderGenerator
from shader_converter.validator.compatibility_checker import DetailedCompatibilityChecker

unity_code = open("MyShader.shader").read()

# Parse
parser = UnityShaderParser()
ast = parser.parse(unity_code)

# Validate
checker = DetailedCompatibilityChecker()
report = checker.check_compatibility(ast)
print(f"Compatibility: {report['compatibility_score'] * 100:.0f}%")

# Generate
generator = AdvancedGodotShaderGenerator()
result = generator.generate(ast)

if result["success"]:
    open("MyShader.gdshader", "w").write(result["code"])
    print(result["code"])

What Gets Converted

Unity / HLSL Godot 4.x
float4, half4, fixed4 vec4
float3x3, float4x4 mat3, mat4
tex2D(tex, uv) texture(tex, uv)
lerp(a, b, t) mix(a, b, t)
saturate(x) clamp(x, 0.0, 1.0)
frac(x) fract(x)
ddx / ddy dFdx / dFdy
clip(x) if (x < 0.0) discard;
UNITY_MATRIX_MVP MODELVIEWPROJECTION_MATRIX
unity_ObjectToWorld MODEL_MATRIX
_Time.y TIME
UnityObjectToClipPos(v) MODELVIEWPROJECTION_MATRIX * vec4(v, 1.0)
TRANSFORM_TEX(uv, tex) uv * tex_ST.xy + tex_ST.zw
o.Albedo = ALBEDO =
o.Metallic = METALLIC =
o.Smoothness = ROUGHNESS = 1.0 -
o.Emission = EMISSION =
o.Normal = NORMAL_MAP =

Unsupported Features

These Unity features have no direct Godot equivalent and will be flagged:

  • Geometry shaders (#pragma geometry)
  • Tessellation (#pragma hull / #pragma domain)
  • Compute shaders (#pragma kernel)
  • GrabPass (use Godot viewport textures instead)
  • Ray tracing (RayQuery, RayDesc)
  • UAV / RW resources

Web UI

shaderbridge serve
# Opens http://localhost:5000

Features:

  • Side-by-side Unity / Godot editor
  • Live compatibility validation
  • 3D WebGL preview (Three.js)
  • AI-powered conversion (requires GROQ_API_KEY)
  • Conversion history
  • Download / copy output

Environment Variables

Variable Description
GROQ_API_KEY Groq API key for AI-powered conversion (optional)

Create a .env file in the project root:

GROQ_API_KEY=your_key_here

Development

git clone https://github.com/Sreejith-nair511/SWC-Redux-2033
pip install -e ".[all]"
pytest tests/ -v

License

MIT — see LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shaderbridge-1.0.2.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shaderbridge-1.0.2-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file shaderbridge-1.0.2.tar.gz.

File metadata

  • Download URL: shaderbridge-1.0.2.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for shaderbridge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ad824f159e9f6c5d4e2fe4207a14fa4e41030c2f34d645210ac927b603bcebd9
MD5 c0370d237b4cf3c40a4bbfd4d10d75c7
BLAKE2b-256 64b1e6d22b8800d2ff81128f8e38ebae1aa5644ad2fa270665926cf35446329c

See more details on using hashes here.

File details

Details for the file shaderbridge-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: shaderbridge-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for shaderbridge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 335ecad13ed01b38374932402e8f2c434f0f63dad79df4d0f4f7df7f17ccd3ff
MD5 b4e8d28efe2eea5554e137e44f750b15
BLAKE2b-256 db51e9a39163f22ab546cb8c70dc0a072c32581172d614a031c8aafcaa0ff1d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page