Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add vite-plugin-glsl to support GLSL external shader files and add de… #2

Merged
merged 2 commits into from
Jul 6, 2022

Conversation

AxiomeCG
Copy link
Contributor

@AxiomeCG AxiomeCG commented Jun 30, 2022

…claration file to help Typescript to resolve shader import

  • vite-plugin-glsl added to the dev dependencies and vite.config.js to configurate the project.
    • Special care to glsl.default() in the config file. glsl() was not found by Vite while trying the documentation configuration. The workaround is described in the following issue of vite-plugin-glsl
  • glsl.d.ts added to the shaders folder I created to help Typescript to resolve the import (see this post for reference).
  • Basic vertex.glsl and fragment.glsl added to provide an example that this is working.

Resolves #1

…claration file to help Typescript to resolve shader import
version "0.141.0"
resolved "https://registry.yarnpkg.com/@types/three/-/three-0.141.0.tgz#d9d81a54b28ebc2a56931dfd4d9c54d25c20d6c8"
integrity sha512-OJdKDgTPVBUgc+s74DYoy4aLznbFFC38Xm4ElmU1YwGNgR7GGFVvFCX7lpVgOsT6S1zSJtGdajTsOYE8/xY9nA==
"integrity" "sha512-OJdKDgTPVBUgc+s74DYoy4aLznbFFC38Xm4ElmU1YwGNgR7GGFVvFCX7lpVgOsT6S1zSJtGdajTsOYE8/xY9nA=="
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, this formatting diff is probably caused by different yarn versions. I should specify which one the project uses, and also upgrade my own 😅

I'll do that and update the yarn.lock before this merges so that the diff is clearer.

src/shaders/example/fragment.glsl Show resolved Hide resolved
import { defineConfig } from "vite";

export default defineConfig({
plugins: [glsl.default()] //For some reason, cannot resolve glsl(). Workaround found on vite-plugin-glsl issue (https://github.com/UstymUkhman/vite-plugin-glsl/issues/1#issuecomment-972660771)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for leaving a comment about this! 🙌

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason for this might be this line. It forces all JS files to be loaded as ES6 Modules, but video-glsl-plugin compiles to CommonJS, that's why you need to use it as glsl.default(). Since this seems to be a front-end project, I don't think you really need that line in package.json. More info here.

@mayacoda mayacoda merged commit a3810ff into mayacoda:main Jul 6, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Imported GLSL shaders are unsupported by the configuration
3 participants