Git Product home page Git Product logo

Comments (5)

docd27 avatar docd27 commented on June 4, 2024

Hi 👋

Since I guess glslify is quite a common use-case and there wasn't really any other solution to clean interoperation with rollup-plugin-glslify, I went ahead and implemented basic support* for processing shader sources through glslify directly in this plugin.

If you set glslify: true and install it to your dev dependencies with npm i -D glslify you can give it a try.

Interested to hear how it goes!

* A possible future enhancement is meaningful glslangValidator/browser error messages referencing the right file glslify files and line numbers, like you already get via #include and this plugin alone. But that's a significant undertaking considering glslify itself won't emit #line directives.

from rollup-plugin-glsl-optimize.

Qix- avatar Qix- commented on June 4, 2024

I appreciate that! :) Thank you so much.

I'm having a bit of trouble getting it to work - currently I just run my code through rollup-plugin-glslify with no additional parameters, and then my imports are more or less import VertexShader from './my-vert-shader.glsl'.

However, replacing rollup-plugin-glslify with rollup-plugin-glsl-optimize followed by rollup-plugin-glsl (as mentioned in the docs) results in the shaders still having the #pragma glslify directives in there:

	rollupGlslOptimize({
		glslify: true
	}),
	rollupGlsl({
		include: '**/*.glsl',
		exclude: '**/*.js',
		sourceMap: false
	}),

Results in

// Snipped for brevity
var VERTEX = "... \n#pragma glslify: noise = require('glsl-noise/simplex/3d');\n...";

Any ideas on how to fix this? :)

As for the line directives I (personally) care much less about those as debugging shader syntax errors is more or less easy to deal with in this case. Just getting it to build right and optimize is the main goal :)

Thanks again, I really appreciate it!

from rollup-plugin-glsl-optimize.

docd27 avatar docd27 commented on June 4, 2024

That's strange - I added some tests in cab815c involving glsl-noise that confirm #pragma glslify is correctly processed. It's the example from the glslify readme - though I did wrap snoise3 in a vec3() due to the increased strictness of glslangValidator / GLSL ES 3.0 (but imo that's a good thing!)

You shouldn't need rollup-plugin-glsl - could you try without it? Also confirm that you're definitely on v0.0.9 :)

from rollup-plugin-glsl-optimize.

docd27 avatar docd27 commented on June 4, 2024

Also another potential issue in your example is that my-vert-shader.glsl will need to be my-vert-shader.vert.glsl or the other options given in the shader stages table

This is because the Khronos binaries need to know the shader stage (though the error should be self explanatory)

from rollup-plugin-glsl-optimize.

Qix- avatar Qix- commented on June 4, 2024

Aha, okay - in the real project they were just called vert.glsl and frag.glsl - changing them to foo.vert.glsl etc appears to be triggering SPIRV correctly. Previously there were no errors.

Also confirm that you're definitely on v0.0.9

Yep yep!

$  cat package.json | grep glsl-opt
"rollup-plugin-glsl-optimize": "0.0.9",

You shouldn't need rollup-plugin-glsl - could you try without it?

Yep you're right, works fine :)


All appears to be working now! I appreciate the help, this is great! Thank you so much :)

from rollup-plugin-glsl-optimize.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.