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.1.tar.gz (38.0 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.1-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shaderbridge-1.0.1.tar.gz
  • Upload date:
  • Size: 38.0 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.1.tar.gz
Algorithm Hash digest
SHA256 ec968d8cf6daf873dac1a7f219dc1656ccbbcce524358ec5a97904e605b3ac56
MD5 c1bbaacbb53f9eaaacd5063428f7b887
BLAKE2b-256 e5c598f728f7393ab6853db3e94b41ad61bbf95e13e6903df57642d805f24692

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shaderbridge-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 35.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf86754060049b0155708659ad987e437ab059d84b2300e67b323315b9469aa3
MD5 d121064c5ed498e938dedc1732cece82
BLAKE2b-256 2e8023e5a9a1f75ee85bb7da9e2d64bf9b9215dc15a16a72bbb2087edbbac422

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