exeldro / obs-shaderfilter

OBS Studio filter for applying an arbitrary shader to a source.
GNU General Public License v2.0
391 stars 41 forks source link

How to debug a shader? (Trying to use Halsu’s HybridKeyer) #59

Open pripple opened 1 month ago

pripple commented 1 month ago

Hi, I’m new to this excellent plugin and to shaders. I would like to use Halsu’s HybridKeyer V22 and there are errors:

Error (null) (429, 1): Error creating shader: ERROR: 0:88: 'f" : syntax error: syntax error

What are these errors referring to? Do they point to a line in the shader code? (If so, which line does the error point to? If it’s just a syntax error or something like that, I might spot the problem myself …) Or do they point to a line in the shaderfilter plugin? What are the next steps to find out what’s wrong?

Thank you and best regards –

Lorenz

pripple commented 1 month ago

So, while I would still like to find out how to efficiently debug a shader, I have found a rather inefficient approach: I deleted everything from the code of Halsu’s HybridKeyer V22 so that it only put out the original image. Then, I copied back in the rest of the code paragraph by paragraph, and as soon as an error appeared, I removed the last paragraph and copied back line by line. That way, I found out what was wrong:

In multiple places, Halsu used this type of assignment: float4 WhatEver = {1.0,1.0,1.0,1.0}; I changed this into float4 WhatEver = float4(1.0,1.0,1.0,1.0); in all applicable instances.

Then, in one line, there was color.rgb = float4(0.0, 0.0, 0.0, color.a);, and without really indepth understanding, I figured out that we were assigning rgba to rgb and changed it into color.rgb = float3(0.0, 0.0, 0.0);.

Now, everything works. Great! I haven’t found out yet how to suggest these changes to Halsu as I found his code in a Google Drive share, but it’s easy to fix his shader code as described.

I would still like to know how to efficiently debug a shader in your plugin, so I leave this issue open. (The problem was that the line numbers specified in the error message didn’t align with the actual erratic line. There was no line 429 at all and the first erratic line was not 88 but 70, so I don’t understand if these numbers correlate at all.)

Thank you and best regards –

Lorenz

exeldro commented 1 month ago

The issue you encountered with initializing variables, there is a pull request to fix that: https://github.com/obsproject/obs-studio/pull/10324 The issue with line numbers being wrong I made this pull request for: https://github.com/obsproject/obs-studio/pull/9831

pripple commented 1 month ago

Hi, thank you for your work on fixing the line number issue! As to the other pull request: On my system, it was the other way round. Halsu used the code you call „existing“, uniform float4 test = {1,0,0,1};, and this caused an error on my ARM Mac with OBS 30.2.3. When I changed it to the code you suggest to support additionally, uniform float4 test = float4(1,0,0,1);, it worked.

Thank you and best regards –

Lorenz