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.0.tar.gz (31.6 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.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shaderbridge-1.0.0.tar.gz
  • Upload date:
  • Size: 31.6 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.0.tar.gz
Algorithm Hash digest
SHA256 270b09ffaae8f73d664c8a85012448483e15583da50d0448e4b87103619c2068
MD5 891e01deb0e9a0aa2d09c88faeded342
BLAKE2b-256 e766ad974e9b813ae1322403aa06ea97ef51635d3b5b9a43f8c138c777454003

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shaderbridge-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a23c08a04d4edf5ae9f693103e8895e88b3f97fa4070ff08e242a2b7426e4b85
MD5 2b8efd3c1c84ce452807dd81c057c516
BLAKE2b-256 e3fb6ff6f3104f5e459a2d85b8b7d21f87a6533e16ecb77e2a32d1ae0a81a2b2

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