Page 1 of 2

Using modf in shader

Posted: Wed Jan 31, 2018 8:27 am
by agargara
I want to use the modf function in a shader, but the compiler tells me
global function modf requires "#version 130" or later


So I tried adding #version 130 to my shader, but the compiler complains:
version directive must be first statement and may not be repeated
Is it possible to use a newer version of GLSL so that I can use the modf function?

Re: Using modf in shader

Posted: Wed Jan 31, 2018 12:01 pm
by grump
The #version line is automatically prepended when you create a new shader. I don't think there is a way to change it.

I use this function when I need modf in a shader:

Code: Select all

float _modf(float a, float b) {
	return a - b * floor(a / b);
}
(typed off the top of my head, I hope it's correct)

Re: Using modf in shader

Posted: Thu Feb 01, 2018 8:49 am
by fluffy
Another modf that might be more performant:

Code: Select all

float _modf(float a, float b) {
    return b*fract(a/b);
}

Re: Using modf in shader

Posted: Fri Feb 02, 2018 10:17 am
by agargara
Thank you grump and fluffy, I'll try those!

So I guess it's not possible to modify the header to use another version of GLSL?

Re: Using modf in shader

Posted: Fri Feb 02, 2018 10:47 am
by grump
It's hardcoded in src/modules/graphics/wrap_Graphics.lua, so you'd have to change the source code. The upcoming 0.11 seems to have support for newer versions.

Re: Using modf in shader

Posted: Fri Feb 02, 2018 12:45 pm
by pgimeno
Well, the defaults are hardcoded, but to me it seems that would be possible to study the code and use love.graphics._setDefaultShaderCode to work around that limitation, without modifying the Löve sources.

Re: Using modf in shader

Posted: Fri Feb 02, 2018 2:38 pm
by grump
pgimeno wrote: Fri Feb 02, 2018 12:45 pm Well, the defaults are hardcoded, but to me it seems that would be possible to study the code and use love.graphics._setDefaultShaderCode to work around that limitation, without modifying the Löve sources.
It would certainly be possible, but that requires to actually read the code and not just skim through it before making premature assumptions. Not my cup of tea, obviously :)

Related question: I have trouble viewing the 0.10.2 tagged wrap_Graphics.lua when browsing the repository in a browser. The link Bitbucket gave me is a 404. It almost worked another time, but half the files didn't show up. Is it just me or is it impossible to browse the 0.10.2 source code on Bitbucket?

Re: Using modf in shader

Posted: Fri Feb 02, 2018 3:30 pm
by pgimeno
Bitbucket is quite broken for me at present. It always felt broken, so no big change there.

In this case, however, your link

https://bitbucket.org/rude/love/src/afc ... ?at=0.10.2

is wrong. You miss opengl/ there. The right link is:

https://bitbucket.org/rude/love/src/afc ... ?at=0.10.2

Re: Using modf in shader

Posted: Fri Feb 02, 2018 3:43 pm
by grump
Thanks, this one works. I wonder how I managed to make Bitbucket give me a broken link.

Re: Using modf in shader

Posted: Fri Feb 02, 2018 3:45 pm
by zorg
pgimeno wrote: Fri Feb 02, 2018 3:30 pm Bitbucket is quite broken for me at present. It always felt broken, so no big change there.

In this case, however, your link

https://bitbucket.org/rude/love/src/afc ... ?at=0.10.2

is wrong. You miss opengl/ there. The right link is:

https://bitbucket.org/rude/love/src/afc ... ?at=0.10.2
I believe the discrepancy arises because the file grump tried to test this with was moved between versions outside of the opengl directory (check the default branch), hence why bitbucket fails to find it with an older tag... still weird, but it's an explanation; i'm suprised you found the correct link though.