Processing Shader Tool

Very much work in progress, but I’m curious if anyone has feedback.

(enable the subtitles by pressing CC)

What this tool tries to solve is the disconnection between the Processing IDE and the shader files, by making it easy to create new shader files based on templates, launch an external editor, rename, delete and in the future, update the Processing code related to shaders (renaming, creating) and link to the GLSL documentation. Any ideas?

9 Likes

Without wanting too much competition in the live programming sphere :wink: , and not sure if you have this already / in mind, but how about listening on the shader file being saved and automatically updating the PShader using reflection?

There’s the plan to make shader hot-reloading the default:


Is that what you mean?

Meanwhile for that purpose so far I use my own shader class which also catches malformed shaders with a try/catch, so the program doesn’t crash. I can share that too, maybe as a library.

Since I already have that shader-reloading class, I don’t need to do it via reflection :slight_smile: And it also works in other IDEs, unlike a Processing Tool.

Ah, yes, had noticed but forgotten that PShader enhancement issue. I was considering something that behaved transparently to the user, but might be difficult to integrate outside of PDE.

Great idea ! To learn it’s perfect. I hope to use it soon.

There’s a primitive work-in-progress version at https://funprogramming.org/ShaderTool-for-Processing/
Still much to do. To configure the editor launched by the tool, after opening the tool once, you can close Processing and edit its preferences.txt file. There should one of these 3 lines (depending on the OS):

tools.shadertool.editor=xterm,-e,cd %PATH% ; vi %FILE%
tools.shadertool.editor=notepad.exe,%PATH%/%FILE%"
tools.shadertool.editor=open,-e,%PATH%/%FILE%

which means that in Windows it opens notepad.exe, in Linux vi, and in Mac the default text editor. I only tested Linux. You could change the line to use atom, sublime or whatever you use.

I’ll make the tool better and safer soon (no confirmation dialogs when deleting a shader = dangerous!) and add documentation.

1 Like

Have you considered using https://docs.oracle.com/javase/8/docs/api/java/awt/Desktop.html#edit-java.io.File- for the default editor?

2 Likes

Thank you for the idea! So good to have people to learn from in the forum :slight_smile:

1 Like

A small video showing the latest version:

Download: https://funprogramming.org/ShaderTool-for-Processing/

GitHub: https://github.com/hamoid/edit-shaders-processing-tool

I wonder, does it work for anyone? :slight_smile:

1 Like

I really like the tool’s templating options. Those make this approach work well as a power user tool – especially if you want it to work outside PDE.

For PDE beginners, on the other hand I wish that PDE Java mode simply supported display and edit of .glsl file tabs – similar to the way that p5.js mode supports both .js and .html tabs.

My reasoning is that mentally tracking actions (and save states) across multiple text editors is something that many experienced programmers are quite familiar with, but it adds a lot of mental overhead for learners.

Now, granted, working with shaders isn’t generally a “beginners” thing. But if the topic is making shaders easier to work with and accessible (and easier to teach!) that is one direction my thinking goes…

2 Likes

Thank you @jeremydouglass . If the PDE supported editing glsl files I would not have created this tool :slight_smile:

I agree that built in editing would be the best option, but it’s more effort than I can do atm.

Since IDEs like Idea make things so easy, I wonder if instead of making the PDE more powerful it would be better to make Idea easier (provide a Processing project template, suggest configuration tips, tutorials, etc).

2 Likes

Yes @jeremydouglass never understood why PDE doesn’t support opening any text-based file from a sketch for editing. There was a bit of talk recently on a HTML / LSP editor to replace PDE. @hamoid maybe your IDEA idea :smile: could be integration with Atom / Visual Code?

Of course there’s another IDE for Processing that supports GLSL in tabs … :wink:

@hamoid – was Processing Shader Tool ever submitted to Contributions Manager?

I was just looking at a shader resources roundup alongside things like shader-mode and realized that I couldn’t find Shader Tool in the PDE tools menu.

1 Like

Hi @jeremydouglass

I never submitted it. I haven’t received almost any feedback so I don’t know if it’s useful for others or good enough. I think it makes it very easy to add shaders to a project.

I’m happy with it being submitted and open for pull requests. I may do small fixes but my focus has shifted so I won’t make big changes. Happy if someone wants to continue it though :slight_smile:

1 Like

Hi there @hamoid, i really liked your effort on this. I tried that but i get to see that error in the stack. Do you have any hint or idea to resolve that issue ? Since i would love to use your tool.

Hi hi :slight_smile:

Yes, that error is due to this line:

and I think it would be solved by doing this instead:

I’ll take a look. The thing I have to figure out is how to build the tool. I don’t remember :slight_smile:

1 Like

Ok, I had forgotten that inside Processing’s preferences.txt there should be a line like this:

tools.shadertool.editor=xterm,-e,cd %PATH% ; vi %FILE%

You can change it to fit your preferred GLSL code editor. For example to use the default editor in Ubuntu (gedit) you could use this:

tools.shadertool.editor=gedit,%PATH%/%FILE%

Note that the string gets split by the , character into an array whilch gets sent to the .exec() java command. The first element of the array should be a program and the remaining elements are arguments. In this example the program is gedit and there’s one argument with the full path to the GLSL file to open.

1 Like

Hi @hamoid

I was strongly suspecting that that xterm was another editor. So that is why i asked to get to see how i am going to open for example gedit, as you mentioned already. Will check and give you feedback.

Thanks a lot

@hamoid

String editor = Preferences.get(PREF_KEY_EDITOR);
private static final String PREF_KEY_EDITOR = "tools.shadertool.editor";

In my preferences.txt file of processing that string is missing, so its looking per OS.
xterm was not installed in my linux distro so that was the problem.
Installed xterm and everything is ok.

Maybe setting in the code and compiling with gedit for Ubuntu distros would be better though.

Thanks a lot

Oh strange… so even after using the tool, closing Processing, the string is not in the preferences file?

xterm is the terminal I had installed on Arch Linux. But it should be possible to specify any editor… Could it be that you have several preferences files? Mine is under ~/.processing/preferences.txt

You installed xterm and that may make you happy if you’re used to vi :slight_smile: which is the editor I was using. But that’s not a general solution, as many people will prefer editors that are easier to quit :wink:

Note that you should edit the preferences file only with Processing closed, as it will overwrite your changes otherwise.

1 Like