Search code examples
flashassemblyvertex-shaderstage3d

What exactly does Adobe mean by VertexShader have a limit of 8 inputs?


Does it mean only a total of 8 float values can be passed per vertices's set of data?

Does this mean you can only have one of the following?

  • 2 inputs of FLOAT_4.
  • 4 inputs of FLOAT_2.
  • 8 inputs of FLOAT_1.
  • Any mixture that will add up to a total of 8 float values?

Is this the case? Because if it is, it's really misleading in their documentation to say 8 inputs can be used.

Maybe I'm having trouble because I haven't formatted my data correctly, but I'm trying to use 9 floats per vertices, as in:

  • va0 would be a FLOAT_4, offset set at 0.
  • va1 would be a FLOAT_4, offset set at 4.
  • va2 would be a FLOAT_1, offset set at 8.

But nothing appears on the screen with this experiment. Am I exceeding the VertexShader inputs limit?


Solution

  • Okay, so I found the problem.

    If you define more values in your vertex-data (per vertices), such as making a modification from this format:

    position: x  va0.x
              y  va0.y
              z  va0.z
              w  va0.w
    color:    r  va1.r
              g  va1.g
              b  va1.b
              a  va1.a
    

    to something like this:

    position: x  va0.x
              y  va0.y
              z  va0.z
              w  va0.w
    color:    r  va1.r
              g  va1.g
              b  va1.b
              a  va1.a
    uv:       u  va2.x
              v  va2.y
    

    Great... you added a new register to the mix. But what you have to do is:

    • Make sure to pass in the right values in:

      context3D.createVertexBuffer(numOfVertices, vertexDataLength); and...

      uploadFromVector(_vertexData, 0, numOfVertices);

    • Make sure you set the right offsets in your calls to:

      context3D.setVertexBufferAt(2, vertexBuffer, 8, Context3DVertexBufferFormat.FLOAT_4);

    • Last but certainly not least (exactly what I was missing)... make USE of that register in your shader!

    If you added a new vertex-attribute but you don't use it in your AGAL code... it won't render!

    Hopefully this saves others some time wondering where they went wrong with their shaders!

    Note: I know, common sense - if you create something, why wouldn't you use it anyways? I was testing if the previous shader still worked with the extra data. It does, as long I don't assign my new vertex-attribute (va2) in the mix. So if you're testing, make sure to only use setVertexBufferAt(...) with the input registers you'll actually use.