{"id":14525043,"url":"https://github.com/DragonJoker/ShaderWriter","last_synced_at":"2025-09-01T11:31:01.774Z","repository":{"id":37848924,"uuid":"152320153","full_name":"DragonJoker/ShaderWriter","owner":"DragonJoker","description":"Library used to write shaders from C++, and export them in either GLSL, HLSL or SPIR-V.","archived":false,"fork":false,"pushed_at":"2025-07-08T07:57:15.000Z","size":9880,"stargazers_count":257,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"development","last_synced_at":"2025-09-01T07:56:20.002Z","etag":null,"topics":["cpp17","glsl","hlsl","spirv"],"latest_commit_sha":null,"homepage":"","language":"C++","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/DragonJoker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-10-09T20:56:26.000Z","updated_at":"2025-08-04T08:55:59.000Z","dependencies_parsed_at":"2023-10-15T06:22:11.453Z","dependency_job_id":"87d5efa3-f75a-41a9-8f67-c35e0ed19ce0","html_url":"https://github.com/DragonJoker/ShaderWriter","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/DragonJoker/ShaderWriter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonJoker%2FShaderWriter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonJoker%2FShaderWriter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonJoker%2FShaderWriter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonJoker%2FShaderWriter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DragonJoker","download_url":"https://codeload.github.com/DragonJoker/ShaderWriter/tar.gz/refs/heads/development","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DragonJoker%2FShaderWriter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273114746,"owners_count":25048253,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cpp17","glsl","hlsl","spirv"],"created_at":"2024-09-04T14:00:35.588Z","updated_at":"2025-09-01T11:31:01.768Z","avatar_url":"https://github.com/DragonJoker.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Vcpkg Version\" src=\"https://img.shields.io/vcpkg/v/shaderwriter\"\u003e\n  \u003ca href=\"https://github.com/DragonJoker/ShaderWriter/actions?query=workflow%3ABuild\"\u003e\u003cimg alt=\"Build status\" src=\"https://github.com/DragonJoker/ShaderWriter/workflows/Build/badge.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/DragonJoker/ShaderWriter\"\u003e\u003cimg src=\"https://codecov.io/gh/DragonJoker/ShaderWriter/graph/badge.svg?token=DG48IQUK64\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n# ShaderWriter\n\nThis library is used to write shaders directly from C++ code.\n\nIt is split in two main libraries (ShaderAST and ShaderWriter) and a \"compiler\" library for each front end language (CompilerGLSL, CompilerHLSL and CompilerSpirV).\n\nShaderAST holds the base architecture (expressions and statements, roughly) used to describe a shader.\n\nShaderWriter is based on ShaderAST, and is fully typed, to be able to write GLSL-like shaders in C++.\n\nThe compiler libraries allow exporting the generated AST in either of these shader languages. \n\n## How to build\n### Using packages repositories\nYou can find shaderwriter on several packages repositories:\n- ArchLinux's \u003ca href=\"https://aur.archlinux.org/packages/shaderwriter-git/\"\u003eAUR\u003c/a\u003e (thanks to \u003ca href=\"https://github.com/Arthapz\"\u003eArthapz\u003c/a\u003e)\n- \u003ca href=\"https://github.com/xmake-io/xmake-repo\"\u003exmake-repo\u003c/a\u003e (thanks to \u003ca href=\"https://github.com/WubiCookie\"\u003eWubiCookie\u003c/a\u003e)\n- \u003ca href=\"https://github.com/microsoft/vcpkg\"\u003evcpkg\u003c/a\u003e\n\n### Using cmake\nThe following command line should be a good start to build ShaderWriter:\n```bash\ncmake \u003cshaderwriter_root\u003e -DCMAKE_BUILD_TYPE=Release\n```\n\nBy default, all libraries (ShaderAST, ShaderWriter and all compilers) will be built as dynamic libraries.\n\nYou can use the option `-DSDW_BUILD_STATIC=ON` to force static build for all of them.\n\n## Examples\n\nLet's take the following vertex shader code, written in C++:\n\n```cpp\ntemplate\u003c sdw::var::Flag FlagT \u003e\nusing PosColStructT = sdw::IOStructInstanceHelperT\u003c FlagT\n\t, \"PosCol\"\n\t, sdw::IOStructFieldT\u003c sdw::Vec4, \"position\", 0u \u003e\n\t, sdw::IOStructFieldT\u003c sdw::Vec4, \"colour\", 1u \u003e \u003e;\n\ntemplate\u003c sdw::var::Flag FlagT \u003e\nstruct PosColT\n\t: public PosColStructT\u003c FlagT \u003e\n{\n\tusing PosColStructT\u003c FlagT \u003e::PosColStructT;\n\n\tauto position()const { return this-\u003egetMember\u003c \"position\" \u003e(); }\n\tauto colour()const { return this-\u003egetMember\u003c \"colour\" \u003e(); }\n};\n\nvoid vertex()\n{\n\tusing namespace sdw;\n\tVertexWriter writer;\n\n\twriter.implementMainT\u003c PosColT, PosColT \u003e( [\u0026]( VertexInT\u003c PosColT \u003e in\n\t\t, VertexOutT\u003c PosColT \u003e out )\n\t\t{\n\t\t\tout.colour() = in.colour();\n\t\t\tout.position() = in.position();\n\t\t\tout.vtx.position = in.position();\n\t\t} );\n\n\t// Select your weapon !\n\tauto glsl = compileGlsl( writer.getShader()\n\t\t, SpecialisationInfo{}\n\t\t, glsl::GlslConfig{} );\n\tauto hlsl = compileHlsl( writer.getShader()\n\t\t, SpecialisationInfo{}\n\t\t, hlsl::HlslConfig{} );\n\tauto binSpirV = serialiseSpirv( writer.getShader()\n\t\t, spirv::SpirVConfig{} );\n\tauto textSpirV = writeSpirv( writer.getShader()\n\t\t, spirv::SpirVConfig{} );\n}\n```\n\nThis shader will generate the following GLSL:\n```glsl\n#version 430\nlayout(location=0) in vec4 sdwIn_position;\nlayout(location=1) in vec4 sdwIn_colour;\nlayout(location=0) out vec4 sdwOut_position;\nlayout(location=1) out vec4 sdwOut_colour;\nout gl_PerVertex\n{\n\tvec4 gl_Position;\n\tfloat gl_PointSize;\n\tfloat gl_ClipDistance[];\n\tfloat gl_CullDistance[];\n};\n\nvoid main()\n{\n\tsdwOut_colour = sdwIn_colour;\n\tsdwOut_position = sdwIn_position;\n\tgl_Position = sdwIn_position;\n}\n```\n\nThe following HLSL (Shader Model 5):\n```hlsl\nstruct HLSL_SDW_GlobalVertInput\n{\n\tfloat4 colour: TEXCOORD1;\n\tfloat4 position: TEXCOORD0;\n};\n\nstruct HLSL_SDW_MainVertOutput\n{\n\tfloat4 colour: TEXCOORD1;\n\tfloat4 position: TEXCOORD0;\n\tfloat4 Position: SV_Position;\n};\n\nvoid main(in HLSL_SDW_GlobalVertInput sdwGlobalInput\n\t, out HLSL_SDW_MainVertOutput sdwMainOutput)\n{\n\tsdwMainOutput.colour = sdwGlobalInput.colour;\n\tsdwMainOutput.position = sdwGlobalInput.position;\n\tsdwMainOutput.Position = sdwGlobalInput.position;\n}\n```\n\nAnd the following SPIR-V 1.6 listing:\n```\n; Magic:     0x07230203\n; Version:   0x00010600\n; Generator: 0x00210280\n; Bound:     17\n; Schema:    0\n\n        Capability Shader\n   %1 = ExtInstImport \"GLSL.std.450\"\n        MemoryModel Logical GLSL450\n        EntryPoint Vertex %13 \"main\" %2 %6 %7 %9 %10\n\n; Debug Names and Sources\n        Source LanguageGLSL 460\n        Name %2(sdwIn_colour) \"sdwIn_colour\"\n        Name %6(sdwIn_position) \"sdwIn_position\"\n        Name %7(sdwOut_colour) \"sdwOut_colour\"\n        Name %9(sdwOut_position) \"sdwOut_position\"\n        Name %10(OutPosition) \"OutPosition\"\n        Name %13(main) \"main\"\n\n; Decorations\n        Decorate %10(OutPosition) BuiltIn Position\n        Decorate %7(sdwOut_colour) Location 1\n        Decorate %2(sdwIn_colour) Location 1\n        Decorate %9(sdwOut_position) Location 0\n        Decorate %6(sdwIn_position) Location 0\n\n; Constants and Types\n   %4 = TypeFloat 32\n   %3 = TypeVector %4(f32) 4\n   %5 = TypePointer Input %3(v4f32)\n   %8 = TypePointer Output %3(v4f32)\n  %12 = TypeVoid\n  %14 = TypeFunction %12(void)\n\n; Global Variables\n   %2 = Variable %5(InputPtr\u003cv4f32\u003e) Input\n   %6 = Variable %5(InputPtr\u003cv4f32\u003e) Input\n   %7 = Variable %8(OutputPtr\u003cv4f32\u003e) Output\n   %9 = Variable %8(OutputPtr\u003cv4f32\u003e) Output\n  %10 = Variable %8(OutputPtr\u003cv4f32\u003e) Output\n\n; Functions\n %13(main) = Function %12(void) [None]  %14(func)\n  %11 = Label\n  %15 = Load %3(v4f32) %2(sdwIn_colour)\n        Store %7(sdwOut_colour) %15\n  %16 = Load %3(v4f32) %6(sdwIn_position)\n        Store %9(sdwOut_position) %16\n        Store %10(OutPosition) %16\n        Return\n        FunctionEnd\n```\n\n## Contact\n\nYou can reach me on the Discord server dedicated to my projects: [DragonJoker's Lair](https://discord.gg/9A97r44tgP)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDragonJoker%2FShaderWriter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDragonJoker%2FShaderWriter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDragonJoker%2FShaderWriter/lists"}