Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

New version of Codea and shader table support

edited April 2014 in Shaders Posts: 20

So in the updated version of Codea it says it supports sending tables to shaders, this is totally awesome but after Googling, checking the docs and checking this forum I can't seem to find any notes on how to send a structure like this

data = {
  {
    colour = color(125, 125, 125, 255),
    x = 100,
    y = 100
  },
  {
    colour = color(125, 125, 125, 255),
    x = 100,
    y = 100
  },
  {
    colour = color(125, 125, 125, 255),
    x = 100,
    y = 100
  }
}

To the shader for consumption, or have I totally misunderstood that particular note in the release notes?
I've played around with the buffers but can't seem to find anything that works.

Comments

  • Posts: 1,595

    @dmackintosh88 Shaders support 1D arrays as far as I'm aware, not the same as tables. It may have been called a table because lua only supports tables (but we can make a table look like a 1D array to be passed to the shader).

  • So I can't specify a struct and use it to pass data through in a sane way but I have to use flat arrays?

  • edited April 2014 Posts: 1,595

    Well in my experience nothing in shaders can be classed as sane, so that's probably a no ;) a work around would be to use texture2D as an array by using the colour values r,g,b as these go from 0-1 they can be multiplied to any value and be read from inside the shader, very quickly too.

  • Jmv38Jmv38 Mod
    edited April 2014 Posts: 3,295

    @luatee i asked a similar question recently, and got a similar answer from Ignatz.
    I did pass some uniform data array data via a texture, but it is not so obvious, because you read interpolated data from the texture, not quite like reading from an array. It is ok for reading a smooth curve, but for reading a random-like set of value? You would have to be very cautious on your texture coordinates to get the exact value!
    @dmackintosh88 the tables you can associate to an array are dedicated to the vertex shader, not to the fragment shader. And you can't assign and pass a uniform array from the vertex shader to the fragment shader (this is out of spec..). So, AFAIK, there is no easy way. If you find some, please let us know!
    Thanks.

Sign In or Register to comment.