Closed ghost closed 3 years ago
On the Windows platform, shaders in OBS are written in the Microsoft HLSL shader language by default, which is similar but incompatible to the GLSL shaders used in OpenGL. As such all of the shaders that come with the various shader plugins for OBS use HLSL as that's what OBS officially supports.
On Linux, and Mac however, OpenGL is used as there is no DirectX, and GLSL would be the native shader language. I'm not certain either way whether OBS includes any compatibility layers to automatically translate HLSL to GLSL on the fly or not, but assuming it does not, then any HLSL shaders provided would need to be manually ported to the GLSL language in order to be used with OpenGL.
The example HLSL shaders included are thus more or less Windows-specific examples. The GLSL and HLSL languages do have more similarities with each other than differences however, so it would not be inherently difficult for someone to convert the HLSL shaders that come with StreamFX or other shader plugins into GLSL for use in Linux or other platforms. There are resources online that I've found to be quite useful for example in converting Shadertoy.com's GLSL shaders to HLSL for use in StreamFX and OBS Shaderfilter.
If anyone stumbling upon this is interested, just search the web for "HLSL to GLSL" and there are a lot of cheat sheets out there for easing the conversion process. Feel free also to join the StreamFX Discord server for tips and tricks for converting between the two languages, or converting Shadertoy shaders for use in OBS etc. It's a fun topic that is surely to come up more in the future.
I'm guessing that the similarity to GLSL is enough that that's why some of them Just Work? But this is good to know, thank you.
It's unlikely for any shaders to be compatible between the two languages directly without some kind of auto-translation layer between them. The overall syntax between the two is practically the same, but a fair number of intrinsic functions and data types differ in name and/or implementation between the two that require automatic or manual translation of some sort. Some constructs I believe would be difficult to impossible to automatically convert, at least based on what I've learned so far and the experience I've gained in converting Shadertoy GLSL shaders to HLSL for use in OBS. Many are easily converted, but some are next to impossible without major restructuring.
As an example, this week I attempted to convert a simple Shadertoy shader that was only about 10 lines of code. GLSL supports passing arrays as function arguments, while HLSL does not. Also, global arrays are more or less broken in OBS. I spent 2 days trying to convert 10 lines of code into working HLSL that OBS could actually run. It's equally likely that trying to convert in the other direction from HLSL to GLSL could encounter such difficulties also.
At the same time it's also potentially difficult for auto-translation to work flawlessly from what I've read. Xaymar could probably comment more knowledgeably on this than I, but if some shaders are just working and some are not, I would presume that there is automatic translation occurring somewhere and that it is working with some things and not with others. Note that this is pure educated speculation on my part however and not solid fact.
Nonetheless, any shaders that work in HLSL with OBS can most likely be manually translated into GLSL to work in OBS also at least in theory. I have only tried it once, using the OBS Shaderfilter Plus plugin successfully but I ended up learning enough about both languages that I'm able to just convert directly to HLSL easily enough most of the time now that I haven't bothered tinkering with GLSL in OBS any more since.
I'm not sure exactly when it's going to happen but in the future I am planning to collect all of what I've learned about this, including a lot of things learned from Xaymar and put it all together in a blog or some other resource people can use to help get started working with this stuff. It'd be great to see more people writing and porting shaders to OBS either for their own personal use, or sharing with others.
Dropping in to update: https://obsproject.com/docs/graphics.html specifies that OBS is using its own slightly modified HLSL setup for effects files, for both OpenGL and DirectX. Checking the differences, the streamfx example files definitely use this, not HLSL itself, so your assumptions seem to be a bit off-base.
The HLSL syntax in OBS Studio is a mashup of CGSL and XNA FXSL, neither of which are fully implemented. This results in weird issues when it directly transpiles OBS-HLSL into GLSL or HLSL, which have been really annoying problems up until now. Ideally I want to use the official Microsoft HLSL to SPIR-V compiler, and then transpile that to GLSL or HLSL, but for now I don't have the necessary APIs extracted from OBS, and it's also low priority.
As for the example shaders, they're examples. Since there have been no submissions for linux example shaders, and my main OS is Windows, all the examples are only guaranteed to work on Windows.
Closing as explained above.
Description
Loading some of the example shaders in linux fails, possibly due to some platform-specific features? All I've done is added the 19.10 clang build to ~/.config/obs-studio/plugins, which loads successfully, then added a shader, then played with selecting shaders for filters, transitions, and sources. An example error of this error of examples, from the "crt curvature" filter shader:
I can give a full log file from trying to load some if it's absolutely necessary, as well, it just didn't seem to be.
System Information