Code Monkey home page Code Monkey logo

glslify-import's Introduction

glslify-import

A transform stream for glslify that adds an import directive to your shaders.

Usage

Given a basic shader:

// main.frag
#pragma glslify: import('./common.glsl')

void main() {
  gl_FragColor = vec4(color, 1.0);
}

You can import ./common.glsl:

// common.glsl
varying vec3 color;

And have the contents inlined into your shader:

varying vec3 color;

void main() {
  gl_FragColor = vec4(color, 1.0);
}

You can also use glslify pragmas and the like from your imported files as well. Useful for the cases when you want to include a common "base" set of definitions in your shaders without losing the niceties of glslify.

glslify-import's People

Contributors

ahem avatar gregtatum avatar hughsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

glslify-import's Issues

Add full ESM imports/exports

Similar to glsl-fancy-imports, but more familiar.
Mb a matter of a separate package, but I'd rework this one.

Apparently not working with glslify 6.1.0 (current)

Imports fail in with the latest glslify 6.1.0 .
I tried to run the tests with 6.1.0, and they fail. It seems that existing tests used to run with glslify 2.1.2.

Any hope you could check that...? In any case, opportunity to thank you for the great stuff that you share :)

Syntax error when compiling shader

Hello,
when i try to compile the shader, i get the following error message:

An error occurred compiling the shaders: ERROR: 0:? : '' : syntax error

My code is:

#pragma glslify: import("./src/utils/constants.glsl")

If i output the compiled shader, the constant is there, just as it is supposed to be:

#pragma glslify: import("./src/utils/constants.glsl")
const float PI_2 = 3.14159265359;

I am not sure if the macro line should be still there, too. Any ideas what i am doing wrong? My platform is OS X, using npm.

And of course, thanks for the awesome module!
Cheers!

Relative require paths need updating

I'm running into this while working on: gregtatum/gl-engine#6

Take a folder structure like this:

  • /glam/fog/struct.glsl
  • /glam/fog/vars.glsl
  • /glam/material/index.glsl

In /glam/material/index.glsl I have

#pragma glslify: import('../fog/vars.glsl')

void main() { ... }

Then in /glam/fog/vars.glsl

#pragma glslify: Fog = require('./struct.glsl')
uniform Fog uFog;

The #pragma glslify: Fog = require('./struct.glsl') gets inlined without the relative path being updated, so the glslify require step can't find my struct.glsl file.

done is not a function

I think I'm missing something completely obvious but I'm getting an error on https://github.com/hughsk/glslify-import/blob/master/index.js#L45 that done is not a function. My build statement is:

budo index.js --live -- -t [ babelify --optional runtime ] -t glslify -t glslify-import

And my import statement is:

#pragma glslify: import('./shader-chunk-lambert-vert.glsl')

Should glslify-import be provided as a transform for glslify instead of browsrify? How would I go about that?

Not recursive

This module doesn't appear to be recursive with further glslify commands that are imported. I have some command line stuff set up to fix it in my case right now, but it would be nice if it continued down into the imported files. Not sure how feasible that is with the architecture of glslify.

If this wouldn't work I could send in a PR with a small explanation on the readme mentioning this.

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.