Constant buffer render.draw() issue

I try to pass custom constants to shader programm.
I use this line of code for that:

render.draw(predicates.my_tag, { frustum = camera_world.frustum, constants = self.constants })

But I get errors in logs:

ERROR:SCRIPT: main/my_render_script.render_script:206: bad argument #5 to ‘draw’ (matrix4 expected, got table)
stack traceback:
[C]:-1: in function draw
main/my_render_script.render_script:206: in function <main/my_render_script.render_script:157>

Why does it happen and how should I pass constant buffer correctly?
In docs it says that table is a correct argument:

Oh I see. It looks like frustum related values have to be included into constant table itself.
It works like this:

render.draw(predicates.my_tag, { constants = self.constants })

No, the frustum needs to be included into the options table with the “frustum” key. The error says that the .frustum is a table and not a matrix, what happens if you print the table?

Hmm. I get this:

DEBUG:SCRIPT: frustum : vmath.matrix4(0.0020833334419876, 0, 0, -1, 0, 0.0031250000465661, 0, -1, 0, 0, -1, 0, 0, 0, 0, 1)

So the table is basicly key-value pair"frustum" == matrix

I have changed my code to this and it works:

render.draw(predicates.my_tag, { constants = self.constants, frustum = camera_world.frustum.frustum })

It’s a bit strange because this render script is 99% based on default one.

I think you can do this:

camera_world.frustum.constants = self.constants
render.draw(predicates.my_tag,  camera_world.frustum)

The naming of the table is a bit confusing yes, it should be called camera_world.options or something like that

1 Like

Thanks! Now I understand.