Giter VIP home page Giter VIP logo

glslx's Introduction

glslx's People

Contributors

disjukr avatar evanw avatar ryankaplan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glslx's Issues

Multi line comments

Multi-line comments such as:

/*
This is a comment
*/

are not parsed correctly. All comments must be on one line. Not a show stopper but users should be aware of this limitation.

Evan,

Thanks for making this available! On a side note, I was disappointed to see Figma pivot. I was looking forward to what kind of image editor you would come up with. Photoshop, with its featuritis, is ripe to be taken down a peg or two.

Pete

4 space tab checkbox

This currently only supports 2 spaced tabs, would be nice to have 4 spaced option

Including the same file multiple times causes errors

Hi Evan!!!

I have files with a dependency chain like this...

  • main.sk includes helpers1.glslx and helpers2.glslx
  • helpers1.glslx and helpers2.glslx both include random.glslx

This is a problem because main indirectly includes two copies of random.glslx which causes syntax errors. I remember you calling this out when you implemented include statements, but now I want to fix it :)

The way include statements currently work is that the parser replaces them with the content of the file that they reference. I think we could "fix" this by having it do this only for the first include it encounters for a particular file.

Are you open to a pull request that does this? Can you think of any reasons why it wouldn't work or would be hard? LMK!

Template variable support

Is it possible to add support of template variables like $x (variable symbol can be configurable) to work with shader templates. At the moment parser returns syntax error on symbol $

const vectors are not removed from shaders that don't use them

The following shaders:

const vec4 someConst = vec4(3.0);

export void vertex() {
  gl_Position = vec4(0.0);
}

export void colorFragment() {
  gl_FragColor = vec4(0.0);
}

Include a constant declaration for someConst in every output shader, even though it's unused:

{
  "shaders": [
    {
      "name": "vertex",
      "contents": "const vec4 a=vec4(3.);void main(){gl_Position=vec4(0.);}"
    },
    {
      "name": "colorFragment",
      "contents": "const vec4 a=vec4(3.);void main(){gl_FragColor=vec4(0.);}"
    }
  ],
  "renaming": {}
}

The expected output in this case should be:

{
  "shaders": [
    {
      "name": "vertex",
      "contents": "void main(){gl_Position=vec4(0.);}"
    },
    {
      "name": "colorFragment",
      "contents": "void main(){gl_FragColor=vec4(0.);}"
    }
  ],
  "renaming": {}
}

errors on symbols that will later be dynamically #defined

I currently use google's compiler and I was giving glslx a try.

I'm running into one issue. I have several #defines that get dynamically added to my shaders after the minimization process. For example, I use "SRGB_EXT_DEFINE" in my glsl code and then in javascript I add #define SRGB_EXT_DEFINE to true or false based on what is actually available. This doesn't work in glslx because the SRGB_EXT_DEFINE symbol can't be found. How do I modify glslx to not complain about specific symbols that have yet to be defined? Thanks!

Pete

Bug: `inout` values should not be inlined

Example input:

void foo(inout float x) {
  x = 2.0;
}

export void bar() {
  float x = 1.0;
  foo(x);
}

Example output (incorrect):

void a(inout float b){b=2.;}void main(){a(1.);}

Preprocessor support

Since glslx doesn't support preprocessing, how to check e.g. if highp is available in a fragment shader ?

#ifndef GL_FRAGMENT_PRECISION_HIGH
precision mediump float;
#else
precision highp float;
#endif

Question: instead of returning "renaming" return a dictionary in all cases

Evan,

Have you considered returning a dictionary/mapping of variables, regardless if renaming is done or not? For example, returning the following when no renaming is done.

map = {
image: "image",
loopCnt: "loopCnt"
}

That way the output result is better abstracted and the interfacing code has no idea if the code was minimized or not. Currently, the interfacing code has to interpret the renaming value and decide what to do.

Pete

Support `import` in GLSLX code

I've been using GLSLX for a few days and it is amazing. I'm running into an issue where I would like to have some code modularity (between files), and do not want to use a rendering engine like Babylon or Three to create multiple materials using the different shader code and send variables between them. Would it be possible to support import? Here is a simple idea for the syntax (ESM style):

random.glslx

precision highp float;

export float random(vec2 seed) {
    return fract(cos(dot(seed.xy, vec2(12.9898, 78.233))) * 43758.5453);
}

shader.glslx

precision highp float;

import { random } from './random';

uniform vec2 seed;

export void fragment(){
    gl_FragColor = vec3(random(seed));
}

GLSLX imports in GLSLX can be handled like GLSLX imports in Typescript by having a .d.ts declaration to go with the .glslx shader.

License?

Hello, Thank you for this library. It is really useful. Can I ask for the license? It is free software? I hope yes :D

webgl2 (glsl 300 es) support

At the moment only glsl version 100 appears to compile correctly. webgl2 uses glsl with version 300 es, which does not compile with glslx.

Here is a fragment shader example:

#version 300 es
precision highp float;
in vec2 v_st;
out vec4 color;
void main()
{
    color = vec4(1.0, 1.0, 0.0, 1.0);
}

Feature Request: additional renaming control

Evan,

I was thinking it would be nice to have the ability to selectively turn renaming off/on for varying vars and uniforms. This is needed to better support the ability to share a common vertex shader with multiple fragment shaders, or vice-versa. Currently, you can do this either by turning off renaming of all uniforms, attribute and varying or you can include multiple shaders in one file. I think there is a third option where you turn off renaming of varying (they tightly couple vertex and uniforms), always rename attributes (no coupling) and only rename uniforms in the fragment or vertex shader that you really want to protect. (normally you only need to protect one or the other). This third option could easily be accomplished if we had an option to selectively control renaming of varying and uniforms. At a minimum only control of varying is needed.

Pete

no constant replacement in array declarations

Hello,

a hypothetical shader example:

const int COUNT = 100;
uniform float data[COUNT];

export void pixelShader() {
  float sum;
  for (int i = 0; i < COUNT; i++)
    sum += data[i];
  gl_FragColor = vec4(sum, data[0], 0.0, float(COUNT));
}

will compile pixelShader to

uniform float data[COUNT];

void main(){
  float sum;
  for(int i=0;i<100;i++)
    sum+=data[i];
  gl_FragColor=vec4(sum,data[0],0.,float(100));
}

Note how the COUNT constant was removed and replaced with its value almost everywhere, except in the first line. Thus, glslx outputs an invalid shader.

(Aside: it would be great if I could prevent just this constant from being inlined at all. I need to recompile my shader with different values of COUNT depending on the data points I have. So far, my workaround is shader = shader.replace(/COUNT/g, count).replace(/100/g, count);, but I can imagine a few scenarios where that will break.)

export parser only

Hi Evan,

I checked the demo and it looks very impressive! I'm not familiar withSkew, I'm just curious if it would be possible to add a make target which would export only parser part of the library?

Crash in for loop with conditionals that use variables

The following relatively simple shader crashes the compiler for me. Making either start or stop a float literal seems to fix the issue.

export void textureFragment() {
  float start = 1.0;
  float stop = 2.0;
  for (float t = start; t < stop;) { }
}

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.