March 20, 2019, 04:00:22 AM

Author Topic: SetFloat with float array in shader ?  (Read 839 times)

Offline Flanker

  • Jr. Member
  • **
  • Posts: 33
    • Youtube channel on Blitzmax programming prototypes
SetFloat with float array in shader ?
« on: November 02, 2017, 03:07:44 AM »
Hello, i'm trying to fill a GLSL float array from blitzmax, I tried SetFloat but I think I'm missing something.

Here is the array in the shader :
Code: [Select]
uniform float array[10];
And here is what I tried in blitzmax :
Code: [Select]
For Local i:Int = 0 To 9
SetFloat(shader,"array["+i+"]",value)
Next

Also, as I'm here, is there a way to unlock the vertices/triangles limits of meshes ? OpenB3D seems to have the same limit as Blitz3D, but with shaders it can be useful to have one big mesh (water for example, or a particle system).

Thank you.
Everyone knew it was impossible, until someone who didn't know made it.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 351
Re: SetFloat with float array in shader ?
« Reply #1 on: November 02, 2017, 04:26:32 AM »
Hi,

I can't remember if it's done different in #version 120 but I came up with a solution for arrays which works in #version 110.

First you need to declare a struct in the frag (I made these names up) then use it in the variable type instead of a float:
Code: BlitzMax
  1. struct FloatArray {
  2.     float Float;
  3. };
  4.  
  5. #define MAX_LIGHTS 8
  6. ..
  7. uniform FloatArray lightradius[MAX_LIGHTS];

Then in Bmx you have to use .Float to set FloatArray's field:
Code: BlitzMax
  1. For Local iradius%=0 To TLight.no_lights[0]-1
  2.         SetFloat(shader,"lightradius["+iradius+"].Float",0.2)
  3. Next

It's possible to get past the vertex/triangle limit with shaders, it's fairly advanced stuff so I'm not looking in to it now. I think you use vertex buffer objects and DrawArrays because they're non-indexed.

Offline Flanker

  • Jr. Member
  • **
  • Posts: 33
    • Youtube channel on Blitzmax programming prototypes
Re: SetFloat with float array in shader ?
« Reply #2 on: November 02, 2017, 01:52:35 PM »
Thank you it's working like that, and also with a vec2 array. I'm translating a Gerstner waves water shader I wrote a while back for Hardwired in HLSL, now the motion works fine, still need to add the effects.

I'll try to find more infos about the vertex/triangle creation in shaders, this could be very useful.
Everyone knew it was impossible, until someone who didn't know made it.