projectm icon indicating copy to clipboard operation
projectm copied to clipboard

New/alternate syntax for milk presets?

Open mbellew opened this issue 7 years ago • 12 comments

I'm just curious if there is any interest in trying a new syntax for milkdrop presets. I find the current syntax a little painful and started imagining a more user friendly format. If there is interest I could think on it more and make a proposal...

mbellew avatar Dec 09 '18 18:12 mbellew

I have no doubt it's possible and not so hard. The multiline syntax is really terrible. The downside is, of course, losing compatibility with milkdrop. Some syntax to specify using GLSL (instead of the current shader language, HLSL) would be cool while you're at it. Even better would be a (web-based?) interactive editor that generates the preset file from some input fields and widgets. Then it could be consistent and compatible with milkdrop. Combine with live preview and it'd be a game changer.

revmischa avatar Dec 09 '18 21:12 revmischa

Compatibility is important, I was thinking we'd provide a python script for two-way conversion. I'll try to play with this over the holiday.

mbellew avatar Dec 10 '18 02:12 mbellew

@mbellew you can also write any parser you want by implementing your own preset factory implementation. Python does seem like the right choice.

struktured avatar Dec 10 '18 02:12 struktured

step one (for the glsl part): I wrote a tool (src//hlsl2glsl/h2g) to convert hlsl preset into a glsl preset. I did this I would be something to test. You can't load the new format yet, but progress. Feedback welcome.

https://github.com/mbellew/projectm/tree/glsl

mbellew avatar Dec 20 '18 20:12 mbellew

@mbellew that’s awesome but projectM already transpiles HLSL to GLSL.....

On Dec 20, 2018, at 8:19 PM, mbellew [email protected] wrote:

step one (for the glsl part): I wrote a tool (src//hlsl2glsl/h2g) to convert hlsl preset into a glsl preset. I did this I would be something to test. You can't load the new format yet, but progress. Feedback welcome.

https://github.com/mbellew/projectm/tree/glsl

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

revmischa avatar Dec 20 '18 20:12 revmischa

Yes, I reused that functionality to rewrite a .milk file with hlsl into a .milk file wth glsl.

mbellew avatar Dec 20 '18 21:12 mbellew

So this program converts a .milk file to a GLSL milk file to make it editable as a "new preset version" file? The goal being to make the preset easier to edit?

revmischa avatar Dec 20 '18 23:12 revmischa

Step 2: now I can load glsl .milk presets. It looks like this:

warp_lang=glsl_330 warp_1=`shader_body { warp_2=` ret = texture(sampler_main, uv).xyz; warp_3=` ret += texture(sampler_blur2, uv).xyz * vec3 (0.1); warp_4=` ret /= vec3 (1.1); warp_5=` ret -= vec3 (0.02); warp_6=`} comp_lang=glsl_330 comp_1=`shader_body { comp_2=` ret = texture(sampler_main, uv).xyz * vec3 (1) + GetBlur1(uv) * vec3 (3) + GetBlur2(uv) * vec3 (0) + GetBlur3(uv) * vec3 (0) + vec3 (0); comp_3=` ret += GetBlur2((uv - vec2 (0.5)) * vec2 (0.333) + vec2 (0.5)); comp_4=` ret *= vec3 (1); comp_5=`}

mbellew avatar Dec 21 '18 18:12 mbellew

@mbellew is it possible with what you've created to transform an HLSL .milk preset into, not a GLSL .milk preset, but instead into a GLSL shader itself? I'm looking for a way to take projectM HLSL milk presets and import them into other apps that use GLSL shaders like ShaderToy.com 😅

ghost avatar Feb 11 '19 17:02 ghost

@G-9999 Wrong pull request, check out https://github.com/projectM-visualizer/projectm/pull/134

There I added code to convert an existing .milk file to use glsl see src/hlsl2glsl/h2g_main.cpp

For getting the actual compiled GLSL, you can output generator.GetResult() near the end of ShaderEngine::compilePresetShader()

I'm not sure how useful that would be in other tools, there's the issue of setting up the predefined textures (the main source texture, and the noise textures).

mbellew avatar Feb 11 '19 20:02 mbellew

@mbellew is it possible with what you've created to transform an HLSL .milk preset into, not a GLSL .milk preset, but instead into a GLSL shader itself? I'm looking for a way to take projectM HLSL milk presets and import them into other apps that use GLSL shaders like ShaderToy.com 😅

Converting the presets into a ShaderToy shader might be problematic as the shader code in the preset will be wrapped in a huge shader specification that provides 50+ uniforms, many of which change every frame according to the per_pixel/per_frame equations, which currently solely run on the CPU, and the waveform and spectrum data from Audio. The shaders also take the CPU-rendered equation-based image as a basis in most presets, so you would have to also convert the equations into shader code as well. This should be possible as the set of functions is quite small, but there's no code for that as of now. Might be an other feature to automatically convert the classic equations into vertex and fragment shader code and have the presets run exclusively on the GPU. Equation outputs (e.g. the q variables) are an issue though as they need to be passed from one shader to the next.

kblaschke avatar Aug 26 '21 09:08 kblaschke

If we really want to enable preset authors to add GLSL shaders, I'd rather use a different prefix for the shader code while keeping the original ones as-is, e.g. using glsl_comp and glsl_warp. Auto-converting the shaders will be quite hard, as I've seen plenty that use global variables in HLSL, which aren't supported by GLSL. Even SPIRV-Cross can't translate these shaders to GLSL or SPIR-V after preprocessing them to (totally valid) HLSL. One has to manually rewrite these shaders to only use local variables and parameters.

I think this will be the one big compatibility issue we'll not be able to solve properly without editing the original presets.

kblaschke avatar Sep 15 '22 16:09 kblaschke