Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Formatting and special variables #3

Open
woudsma opened this issue Feb 20, 2023 · 2 comments
Open

Formatting and special variables #3

woudsma opened this issue Feb 20, 2023 · 2 comments

Comments

@woudsma
Copy link

woudsma commented Feb 20, 2023

Promising project! I've been struggling with creating procedural textures and ping-pong shaders using Processing, JS (with three, react-three-fiber, drei, etc). This project does it out-of-the-box!

I'm trying to get up to speed with swissgl's workflow, but I'm still a bit dazed by all the magic / special variables, and what each glsl call actually does. For example in the Particle Life demo. The following creates and stores a WebGLTexture:

const F = glsl(`
    float(I.x==I.y) + 0.1*float(I.x==I.y+1)`,
    {size:[K,K], format:'r16f'});

This renders the texture to the canvas:

glsl({F}, `F(I/20).x*3.0`);

Here we call glsl two more times to update points - without using the i variable (is this intentional?):

for (let i=0; i<2; ++i) {
    glsl({K, seed:123}, `
        vec2 pos = (hash(ivec3(I, seed)).xy-0.5)*10.0;
        float color = floor(P.x*K);           // why is uv renamed to P?
        out0 = vec4(pos, 0.0, color);`,
        points);
}

Then we call glsl again, providing only a fragment shader function and points as target.
To render to the screen, glsl is called again but this time with a vertex and fragment shader function.
It's somewhat confusing what each glsl() is doing to the stored variables like F, points and the canvas.

The README.md mentions:

invitation to discuss compact and expressive graphics library design

I hope I can provide some constructive initial feedback:

  • I think the project could benefit from some JS / GLSL code formatting for better readability, I could create a PR for that. Please let me know what you think.
  • Maybe more descriptive (and less terse) variable names? K, I, P, F, etc.
  • I'm missing an overview and description of the special variables that can be used with swissgl
  • This really is very nice, but makes the examples quite hard to read sometimes when a texture is called F or S:

    Uniform textures can be accessed with usual GLSL functions, or with a helper macro that has the same name as the texture uniform.

@znah
Copy link
Collaborator

znah commented Feb 21, 2023

Thank you for the feedback! I'll make a table of special variables with their scopes, and try to make names used in examples more descriptive.

@woudsma
Copy link
Author

woudsma commented Feb 21, 2023

Let me know if I can assist anywhere!
Running all code through a formatter/linter wouldn't take me much time/effort for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants