laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code
https://ctrl-alt-test.fr/minifier/
Apache License 2.0
439 stars 32 forks source link

Feature Request: Add Support for ReShade FX #241

Open martymcmodding opened 1 year ago

martymcmodding commented 1 year ago

Great tool! Was able to handle all regular HLSL shaders I threw at it so far. However, would it be possible to add support for ReShade FX? ReShade is a generic postprocessing injector for video games, and it uses its own shading language that gets translated into whatever the underlying game uses and compiled there, so it's necessary to provide the shaders in source code format.

Its syntax is virtually identical to SM3 HLSL, with a few extensions that allow for e.g. namespaces, inline texture declaration with sizes, control dispatch size of compute shaders and so on. The language is also backed by Nvidia, as Nvidia FreeStyle/Nvidia Ansel allow loading of ReShade shaderfiles.

It would help tremendously if I could minify my shaders using your software. Porting to HLSL and backporting to ReShade FX is very tedious and I haven't succeeded in minifying standalone pixel shader passes even though they should adhere to regular HLSL syntax...

Here is the software itself: https://github.com/crosire/reshade Here is a basic list of effects but if you require others, there are many more: https://github.com/crosire/reshade-shaders/tree/slim/Shaders

Please let me know what you think. If you require additional and more complex shaders for unit testing, I'm happy to assist :)

laurentlb commented 1 year ago

Thanks for the request. What is the motivation for minifying these files?

I think the feature request makes sense, but I'm afraid it will benefit very few people (so I might not be able to prioritize it soon).

martymcmodding commented 1 year ago

Sorry, have been sick and wasn't able to follow up. Thanks for considering it! Here's some more detail:

Motivation for myself is code protection and faster compilation times. I provide my softwares partially free, partially on Patreon. Also, shaders take long to compile on old platforms, shortening the tokens helps with that significantly. Its installer fetches the files from various github repositories, getting golfed branches would help with compilation on the target PCs which is... millions of users. The shaders recompile on every game start, during context changes and so on, so this happens frequently.

ReShade is the powerhouse behind I'd guess 95% of graphics modifications for video games in total, because it can inject the shaders into every game no matter if x86/x64, OpenGL, DirectX 8-12, Vulkan, you name it. Many games have no files to easily edit so for most games, modding capabilities are really basic. So it's really widespread. Accelerating code compilation would help all users.

From what I've been hearing, ReShade FX has gained traction inside of Nvidia as well, due to its ability to handle things that otherwise require CPU side code. Lots of shader pseudolanguages appeared somewhat recently, like shader slang.

You'd probably be able to ignore most of these additional features (except namespaces which work identical to C++) because they show in different technique/pass/texture/sampler declarations and not actually in pixel/vertex/compute shader bodies.