Sending value to specific index in an external shader array

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.
Post Reply
AxisAngles
Prole
Posts: 12
Joined: Mon Feb 22, 2016 9:02 am

Sending value to specific index in an external shader array

Post by AxisAngles »

So currently, I have a deal where I edit an array in Lua, and then I need to update it in the shader. I generally only change one element of the array, yet I have to resend the entire array just to change the one index.

At least this is what I think. I've tried

Code: Select all

:send("lower[127]",{x,y})
but it errors.

Is there a better way to do this?
User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: Sending value to specific index in an external shader array

Post by Skeiks »

I'm not that great with GLSL but I've always heard that sending externs/uniforms to shaders didn't have that much overhead. If you're only sending this one array, and this array isn't huge, would it even be worth it to try and optimize that? The only thing I can think of is to:

1: Have a separate, smaller array that you use as an override for values in your shader when you only need to change one value.
2: Split your array into a butt-ton of externs.
3: Depending on what you're using your shader for, do multiple passes with your shader per every 10 or so array values so you don't have to send them all.

All of those suggestions are trash by the way, and would probably result in more slowdown than if you just sent the array every time it changed. I mean I send vec4's to my array multiple times a second without slowdown, and after looking into it I can't find anything about updating a single value of an array like that.
AxisAngles
Prole
Posts: 12
Joined: Mon Feb 22, 2016 9:02 am

Re: Sending value to specific index in an external shader array

Post by AxisAngles »

Thanks for the help. What I'll do is I'll continue resending the entire array 60 times per second or whatever (ugh). It's not that slow, but it's still just gross conceptually.

Love2d really needs to add some kind of support for that.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Sending value to specific index in an external shader array

Post by s-ol »

AxisAngles wrote:Thanks for the help. What I'll do is I'll continue resending the entire array 60 times per second or whatever (ugh). It's not that slow, but it's still just gross conceptually.

Love2d really needs to add some kind of support for that.
Regardless of whether Löve creates an API to do this or not, OpenGL still requries that the whole Uniform be loaded to the GPU every time it is changed so there is no performance benefit if you reuse the same lua table every frame.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
AxisAngles
Prole
Posts: 12
Joined: Mon Feb 22, 2016 9:02 am

Re: Sending value to specific index in an external shader array

Post by AxisAngles »

AxisAngles wrote:(ugh). It's not that slow, but it's still just gross conceptually.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 208 guests