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

Glshaders in ronin #122

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

XiNNiW
Copy link
Contributor

@XiNNiW XiNNiW commented Apr 2, 2020

Hi @neauoire,

I took a shot at cleaning up the gl tools and packaging them up in their own module.

I also made a library function called kaleid that makes a kaleidoscope of the current image on the canvas. It was helpful to have a concrete example to build toward.

This was fun to play with and I'm happy to iterate on this more!

I'd love to hear what you think.

Thanks,

David

@neauoire
Copy link
Member

neauoire commented Apr 2, 2020

This is very nice, almost perfect ;)
I was wondering for the kaleid shader, I don't think the way to go is to add new changes to the source everytime you want to add a new shader, the idea would be to do this in lisp space.

The simplest way would be to be able to load shaders, like we're currently loading an image, so it's kept in the Source module(source.js), and linked into the lisp file. Do you want to try and make it so you can load shaders instead of storing kaleid as a js function?

@XiNNiW
Copy link
Contributor Author

XiNNiW commented Apr 3, 2020 via email

@XiNNiW
Copy link
Contributor Author

XiNNiW commented Apr 3, 2020

What if it worked like this?
There is a library function called glsl that you could use like so:

(import "path/to/image")
(glsl "path/to/kaleid.shader.json" 4 (rect 0 0 600 600) )

Where the "kaleid.shader.json" was a file defining the shader code and the meta-data required to tell Ronin how to bind its arguments and attributes.

Here is a gist describing how the shader.json might look.

I think this solves the problem of not having to change the source code of Ronin every time you want a new shader. However, there are things I don't love about this approach:

  1. Representing glsl code in json is a bit clunky
  2. The design might be assuming that the user knows how Ronin works on the inside.
  3. The json file is big. Although, this could be partially addressed by making the vertex shader optional and making it bind the canvas to a texture and the frame to position by default

Anyway, I would love to hear what you think. :)

@XiNNiW
Copy link
Contributor Author

XiNNiW commented Apr 5, 2020

I took a shot at implementing what I described above. It seemed to work pretty good! I updated the kaleid.lisp example in the example folder to match the new implementation.

I had to add some functions outside the gl module in order to make it work though. The most challenging aspect is correctly binding the attributes that the user specifies. These attributes could represent colors, shapes, or other arbitrary data. I implemented a method on rect called getGlRepresentation that can return the shape in a format acceptable to the gl shader attribute. It feels like each data type (most common being colors and shapes) would need to be able to tell you their glRepresentation in order to allow binding as an attribute. Is that OK?
EDIT: I found a way to keep all the changes inside the gl module. The gl module now identifies the data type and provides the gl representation. Only rectangle is implemented so far.

There are probably other ways to solve this problem that I'm not seeing.

There are also some improvements on this that would be easy to make, such as adding a default vertex shader that binds the canvas and the frame.

@neauoire
Copy link
Member

neauoire commented Apr 7, 2020

I'm a bit swamped at the moment, give me a day or two to look this over :)
Sorry for the delay ^^;

@XiNNiW
Copy link
Contributor Author

XiNNiW commented Apr 7, 2020

No problem and no rush. Sorry I kept spamming the thread. I think I may have problem sniped myself with this one. :)

I hope your well and staying safe.

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

Successfully merging this pull request may close these issues.

2 participants