Using modf in shader

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
agargara
Prole
Posts: 5
Joined: Fri Aug 18, 2017 9:44 am

Using modf in shader

Post 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?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Using modf in shader

Post 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)
fluffy
Prole
Posts: 7
Joined: Fri Feb 24, 2017 8:18 am

Re: Using modf in shader

Post by fluffy »

Another modf that might be more performant:

Code: Select all

float _modf(float a, float b) {
    return b*fract(a/b);
}
agargara
Prole
Posts: 5
Joined: Fri Aug 18, 2017 9:44 am

Re: Using modf in shader

Post 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?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Using modf in shader

Post 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.
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: Using modf in shader

Post 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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Using modf in shader

Post 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?
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: Using modf in shader

Post 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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Using modf in shader

Post by grump »

Thanks, this one works. I wonder how I managed to make Bitbucket give me a broken link.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Using modf in shader

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest