-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GLSL FFT Issue #10
Comments
Interesting… it looks… to me… like both are exactly the complex conjugate. I wonder if this generalizes. If so, I wouldn't necessarily know the cause, the the solution would sure be easy… Also, regarding the triangle, the motivation is simply that it (might) have better cache performance than a quad: https://michaldrobot.com/2014/04/01/gcn-execution-patterns-in-full-screen-passes/ It should otherwise be exactly identical. |
Ah, and regarding coordinate systems, I'm not sure I'd say the texture coordinates origin is in the top-left. I visualize normalized device coords and texture coords the same, except one is in |
Thanks for taking a look! Regarding the coordinate systems, I was going off this image and that when I have a very simple shader that does something like void main(void) {
// resolution is a vec2 with the screen width and height
vec2 pos = gl_FragCoord.xy / resolution;
gl_FragColor = texture(lena, pos);
} I get an upside down image. Regarding the complex conjugate idea. I don't think thats right, because there are several entries in the result matrix that actually match the expected result, so taking the conjugate of those would result in an incorrect answer. For example in Example 1 above the expected and actual result at I'll keep digging. Let me know if you have other ideas :) |
Ah, I guess that argument works. I've always instead thought of textures as upright and if something accidentally gets flipped, I prefer to flip the input on texture creation (regl has a flipY flag for this purpose). Also, you are probably right about complex conjugate not being the right answer, though to be clear, in the above examples, I think the complex conjugate would solve it—though it probably doesn't generalize. |
And just in case anything was lost in translation, my implementation was reworked from this code, and then fairly carefully tested against ndarray-fft: https://david.li/filtering/ |
Ah, yes you are right. I missed that -0 and +0 are the same thing :-S Also, now that I think about it, the geometric interpretation of the conjugate is flipping the I'll try calculating the conjugate, and running it through a bunch more examples and see if that works. |
It seems to work for any real valued input with dimensions <= 8 i.e. 2,4,8 Thats an odd result for sure. |
FWIW I find that 4x4 is a very effective size for testing, but think 0/1 might be too degenerate. Sometimes even just a serial counter e.g. |
Yeah I ran a test with a few thousand randomly generated inputs with various combinations of dimension 2,4 and 8 with the real values between -100 and 100 and 0 imaginary value. Applying the complex conjugate worked every time. |
Isn't the complex conjugate equivalent to time reversal (in 1d)? A flipped input dimension would be consistent with that. |
Right, thats what I was thinking when I said
Also noticing that the size issue was just a matter of precision. My tolerance was 0.001 which was too small apparently. Making that larger means that my tests pass at larger sizes up to 128x128. Though the precision issues get larger as the size goes up. I'll try flipping the y dimension on the input, and see if that works out. |
No dice, when trying various transformations of the input I still get wrong results. Below is the result from inverting the y axis. Input:
Inverted to:
Expected:
Actual:
I think there is something else going on, because I start getting the wrong answer when the input has non-zero imaginary components even when applying the conjugate after reading the data. |
I figured it out 🥳🕺 |
Ok, next issue is non-square matrices. Its never easy 😭 |
I didn't see your previous comment at the time, but glad it worked! FWIW apart from initial pass setup, I didn't need any particular changes for non-square matrices as long as they were power-of-two, but ymmv 😄 |
Thanks! |
I've been looking for the error that cases failure on non-square input, but with no success. If you have any ideas where to look, I'd very much welcome any input! I'm running on a 4x2 input. Below is the input and output for each pass. Input
Pass configurations:
Expected result
|
I'm getting some weird results when attempting to port glsl-fft to processing
The only notable difference I can see between the two implementations is the way the vertexes are defined. In glsl-fft a triangle is drawn, whereas in my implementation a quad is drawn. I don't see how this could make a difference.
One thing that I thought may have an impact on this, is the different in the coordinate systems for
gl_FragCoord
and texture coordinates. AFAIKgl_FragCoord
has the origin at the bottom left corner, whereas texture coordinates have the origin at the upper left corner. Perhapsregl
is doing some adjustment to the coordinate system that is not being done in my solution?Example 1
Input (all real components):
Expected:
Actual:
Notice that column 1 and 3 (0 indexed) are swapped in the actual output as compared to the expected output.
Example 2
Input (all real components):
Expected:
Actual:
Notice that row 1 and 3 (0 indexed) are swapped in the actual output as compared to the expected output.
The text was updated successfully, but these errors were encountered: