{"id":13774528,"url":"https://github.com/docd27/rollup-plugin-glsl-optimize","last_synced_at":"2025-05-11T06:33:15.750Z","repository":{"id":52355894,"uuid":"340525486","full_name":"docd27/rollup-plugin-glsl-optimize","owner":"docd27","description":"Import GLSL source files. Pre-processed, validated and optimized with Khronos Group SPIRV-Tools. Supports glslify.","archived":false,"fork":false,"pushed_at":"2021-09-18T13:38:46.000Z","size":201,"stargazers_count":35,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-05T07:06:03.372Z","etag":null,"topics":["glsl","glsl-es","glslang","glslify","optimize","plugin","rollup","rollup-plugin-glsl","shader","shaders","spir-v","spirv","webgl","webgl-shader","webgl2"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/docd27.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-20T00:43:52.000Z","updated_at":"2025-02-19T06:43:18.000Z","dependencies_parsed_at":"2022-09-05T22:50:48.921Z","dependency_job_id":null,"html_url":"https://github.com/docd27/rollup-plugin-glsl-optimize","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docd27%2Frollup-plugin-glsl-optimize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docd27%2Frollup-plugin-glsl-optimize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docd27%2Frollup-plugin-glsl-optimize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docd27%2Frollup-plugin-glsl-optimize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docd27","download_url":"https://codeload.github.com/docd27/rollup-plugin-glsl-optimize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253528412,"owners_count":21922623,"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":["glsl","glsl-es","glslang","glslify","optimize","plugin","rollup","rollup-plugin-glsl","shader","shaders","spir-v","spirv","webgl","webgl-shader","webgl2"],"created_at":"2024-08-03T17:01:27.627Z","updated_at":"2025-05-11T06:33:15.265Z","avatar_url":"https://github.com/docd27.png","language":"JavaScript","readme":"# rollup-plugin-glsl-optimize\n[![NPM Package][npm]][npm-url]\n[![Changelog][changelog]][changelog-url]\n[![Node Version][node-version]](#)\n[![Types][types]](#)\n[![Maintainability][cc-maintainability]][cc-maintainability-url]\\\n[![Dependencies][dependencies]][dependencies-url]\n[![Dev Dependencies][dev-dependencies]][dev-dependencies-url]\n[![Coverage Status][coverage]][coverage-url]\n[![Node.js CI][ci]][ci-url]\n\nImport GLSL source files as strings. Pre-processed, validated and optimized with [Khronos Group SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools).\n\nPrimary use-case is processing WebGL2 / GLSL ES 300 shaders.\n\n```js\nimport frag from './shaders/myShader.frag';\nconsole.log(frag);\n```\n\n## Features\n\n### GLSL Optimizer\n*For WebGL2 / GLSL ES \u003e= 300*\n\nWith ``optimize: true`` (default) shaders will be compiled to SPIR-V (opengl semantics) and optimized for performance using the [Khronos SPIR-V Tools Optimizer](https://github.com/KhronosGroup/SPIRV-Tools) before being cross-compiled back to GLSL.\n\n### Shader Preprocessor\nShaders are preprocessed and validated using the [Khronos Glslang Validator](https://github.com/KhronosGroup/glslang).\n\nMacros are run at build time with support for C-style ``#include`` directives: \\*\n\n```glsl\n#version 300 es\n#include \"postProcessingShared.glsl\"\n#include \"dofCircle.glsl\"\n\nvoid main() {\n  outColor = CircleDof(UVAndScreenPos, Color, ColorCoc);\n}\n```\n*\\* Via the ``GL_GOOGLE_include_directive`` extension. But an ``#extension`` directive is not required nor recommended in your final inlined code.*\n\n### Supports glslify\nSpecify ``glslify: true`` to process shader sources with [glslify](https://github.com/glslify/glslify) (a node.js-style module system for GLSL).\n\n*And install glslify in your devDependencies with ``npm i -D glslify``*\n\n## Installation\n\n```sh\nnpm i rollup-plugin-glsl-optimize -D\n```\n\n### Khronos tools\nThis plugin uses the [Khronos Glslang Validator](https://github.com/KhronosGroup/glslang), [Khronos SPIRV-Tools Optimizer](https://github.com/KhronosGroup/SPIRV-Tools) and [Khronos SPIRV Cross compiler](https://github.com/KhronosGroup/SPIRV-Cross).\n\nBinaries are automatically installed for:\n* Windows 64bit (MSVC 2017)\n* MacOS x86_64 (clang)\n* Ubuntu Trusty / Debian Buster amd64 (clang)\n\n*Paths can be manually provided / overridden with the ``GLSLANG_VALIDATOR``, ``GLSLANG_OPTIMIZER``, ``GLSLANG_CROSS`` environment variables.*\n\n## Usage\n```js\n// rollup.config.mjs\nimport {default as glslOptimize} from 'rollup-plugin-glsl-optimize';\n\nexport default {\n    // ...\n    plugins: [\n        glslOptimize(),\n    ]\n};\n```\n\n## Shader stages\n\nThe following shader stages are supported by the Khronos tools and recognized by file extension:\n\n| Shader Stage | File Extensions                       |\n| ------------ | ------------------------------------- |\n| Vertex       | ``.vs, .vert, .vs.glsl, .vert.glsl``  |\n| Fragment     | ``.fs, .frag, .fs.glsl, .frag.glsl``  |\n| Geometry*     | ``.geom, .geom.glsl``                |\n| Compute*      | ``.comp, .comp.glsl``                |\n| Tess Control* | ``.tesc, .tesc.glsl``                |\n| Tess Eval*    | ``.tese, .tese.glsl``                |\n\n*\\* Unsupported in WebGL2*\n\n## Options\n- `include` : `PathFilter` (default table above) File extensions within rollup to include. Though this option can be reconfigured, shader stage detection still operates based on the table above.\n- `exclude` : `PathFilter` (default ``undefined``) File extensions within rollup to exclude.\n- ``includePaths`` : ``string[]`` (default undefined) Additional search paths for ``#include`` directive (source file directory is always searched)\n### Features\n- `optimize` : ``boolean`` (default true) Optimize via SPIR-V as described in the Optimization section [requires WebGL2 / GLSL ES \u003e= 300]. When disabled simply runs the preprocessor [all supported GLSL versions].\n- ``compress`` : ``boolean`` (default true) Strip all whitespace in the sources\n### Debugging\n- ``sourceMap`` : ``boolean`` (default true) Emit source maps. These contain the final preprocessed/optimized GLSL source (but not stripped of whitespace) to aid debugging.\n- ``emitLineDirectives`` : ``boolean`` (default false) Emit ``#line NN \"original.file\"`` directives for debugging - useful with ``#include``. Note this requires the ``GL_GOOGLE_cpp_style_line_directive`` extension so the shader will fail to run in drivers that lack support.\n### Preprocessor\n- ``optimizerPreserveUnusedBindings`` : ``boolean`` (default true) Ensure that the optimizer preserves all declared bindings, even when those bindings are unused.\n- ``preamble`` : ``string`` (default undefined) Prepended to the shader source (after the #version directive, before the preprocessor runs)\n### glslify\n- ``glslify`` : ``boolean`` (default false) Process sources using glslify prior to all preprocessing, validation and optimization.\n- ``glslifyOptions`` (default undefined) When ``glslify`` enabled, pass these [additional options](https://github.com/glslify/glslify#var-src--glslcompilesrc-opts) to ``glslify.compile()``.\n### Advanced Options\n- ``optimizerDebugSkipOptimizer`` : ``boolean`` (default false) When ``optimize`` enabled, skip the SPIR-V optimizer - compiles to SPIR-V then cross-compiles back to GLSL immediately.\n- ``suppressLineExtensionDirective`` : ``boolean`` (default false) When `emitLineDirectives` enabled, suppress the ``GL_GOOGLE_cpp_style_line_directive`` directive.\n- ``extraValidatorParams``, ``extraOptimizerParams``, ``extraCrossParams`` : ``string[]`` (default undefined) Additional parameters for the Khronos Glslang Validator [here](doc/glslangValidator.md), the Khronos SPIR-V Optimizer [here](doc/spirv-opt.md), and the Khronos SPIR-V Cross compiler [here](doc/spirv-cross.md).\n- ``glslangValidatorPath``, ``glslangOptimizerPath``, ``glslangCrossPath`` : ``string`` (default undefined) Provide / override binary tool paths.\\\n*It's recommended to instead use the environment variables ``GLSLANG_VALIDATOR``, ``GLSLANG_OPTIMIZER``, ``GLSLANG_CROSS`` where needed. They always take precedence if set.*\n\n## Changelog\nAvailable in [CHANGES.md](CHANGES.md).\n\n#### Caveats \u0026 Known Issues\n* This plugin handles glsl and glslify by itself. Use with conflicting plugins (e.g. rollup-plugin-glsl, rollup-plugin-glslify) will cause unpredictable results.\n* Optimizer: ``lowp`` precision qualifier - emitted as ``mediump``\\\n  *SPIR-V has a single ``RelaxedPrecision`` decoration for 16-32bit precision. However most implementations actually treat ``mediump`` and ``lowp`` equivalently, hence the lack of need for it in SPIR-V.*\n\n## License\n\nReleased under the [MIT license](LICENSE).\\\n*Strip whitespace function adapted from code by Vincent Wochnik ([rollup-plugin-glsl](https://github.com/vwochnik/rollup-plugin-glsl)).*\n\nKhronos tool binaries (built by the upstream projects) are distributed and installed with this plugin under the terms of the Apache License Version 2.0. See the corresponding LICENSE files installed in the ``bin`` folder and the [binary releases](https://github.com/docd27/rollup-plugin-glsl-optimize/releases/).\n\n[ci]: https://github.com/docd27/rollup-plugin-glsl-optimize/actions/workflows/node-ci.yml/badge.svg\n[ci-url]: https://github.com/docd27/rollup-plugin-glsl-optimize/actions/workflows/node-ci.yml\n[npm]: https://badgen.net/npm/v/rollup-plugin-glsl-optimize\n[npm-url]: https://www.npmjs.com/package/rollup-plugin-glsl-optimize\n[node-version]: https://badgen.net/npm/node/rollup-plugin-glsl-optimize\n[types]: https://badgen.net/npm/types/rollup-plugin-glsl-optimize\n[changelog]: https://badgen.net/badge/changelog/SemVer/blue\n[changelog-url]: https://github.com/docd27/rollup-plugin-glsl-optimize/blob/master/CHANGES.md\n[dependencies]: https://status.david-dm.org/gh/docd27/rollup-plugin-glsl-optimize.svg\n[dependencies-url]: https://david-dm.org/docd27/rollup-plugin-glsl-optimize\n[dev-dependencies]: https://status.david-dm.org/gh/docd27/rollup-plugin-glsl-optimize.svg?type=dev\n[dev-dependencies-url]: https://david-dm.org/docd27/rollup-plugin-glsl-optimize?type=dev\n[cc-maintainability]: https://badgen.net/codeclimate/maintainability/docd27/rollup-plugin-glsl-optimize\n[cc-maintainability-url]: https://codeclimate.com/github/docd27/rollup-plugin-glsl-optimize/maintainability\n[coverage]: https://codecov.io/gh/docd27/rollup-plugin-glsl-optimize/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/gh/docd27/rollup-plugin-glsl-optimize\n","funding_links":[],"categories":["Plugins"],"sub_categories":["Other File Imports"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocd27%2Frollup-plugin-glsl-optimize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocd27%2Frollup-plugin-glsl-optimize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocd27%2Frollup-plugin-glsl-optimize/lists"}