send.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. return {
  2. tag = 'shaders',
  3. summary = 'Set the value of a shader variable.',
  4. description = [[
  5. Sends a value to a variable in the Pass's active `Shader`. The active shader is changed using
  6. `Pass:setShader`.
  7. ]],
  8. arguments = {
  9. name = {
  10. type = 'string',
  11. description = 'The name of the Shader variable.'
  12. },
  13. binding = {
  14. type = 'number',
  15. description = 'The binding number of the Shader variable.'
  16. },
  17. buffer = {
  18. type = 'Buffer',
  19. description = 'The Buffer to assign.'
  20. },
  21. offset = {
  22. type = 'number',
  23. default = '0',
  24. description = 'An offset from the start of the buffer where data will be read, in bytes.'
  25. },
  26. extent = {
  27. type = 'number',
  28. default = '0',
  29. description = [[
  30. The number of bytes that will be available for reading. If zero, as much data as possible
  31. will be bound, depending on the offset, buffer size, and the `uniformBufferRange` or
  32. `storageBufferRange` limit.
  33. ]]
  34. },
  35. texture = {
  36. type = 'Texture',
  37. description = 'The Texture to assign.'
  38. },
  39. sampler = {
  40. type = 'Sampler',
  41. description = 'The Sampler to assign.'
  42. },
  43. constant = {
  44. type = '*',
  45. description = 'Numbers, vectors, or tables to assign to the constant or uniform buffer.'
  46. }
  47. },
  48. returns = {},
  49. variants = {
  50. {
  51. arguments = { 'name', 'buffer', 'offset', 'extent' },
  52. returns = {}
  53. },
  54. {
  55. arguments = { 'name', 'texture' },
  56. returns = {}
  57. },
  58. {
  59. arguments = { 'name', 'sampler' },
  60. returns = {}
  61. },
  62. {
  63. arguments = { 'name', 'constant' },
  64. returns = {}
  65. },
  66. {
  67. arguments = { 'binding', 'buffer', 'offset', 'extent' },
  68. returns = {}
  69. },
  70. {
  71. arguments = { 'binding', 'texture' },
  72. returns = {}
  73. },
  74. {
  75. arguments = { 'binding', 'sampler' },
  76. returns = {}
  77. }
  78. },
  79. notes = [[
  80. Shader variables can be in different "sets". Variables changed by this function must be in set
  81. #2, because LÖVR uses set #0 and set #1 internally.
  82. The new value will persist until a new shader is set that uses a different "type" for the
  83. binding number of the variable. See `Pass:setShader` for more details.
  84. ]],
  85. example = [=[
  86. function lovr.load()
  87. shader = lovr.graphics.newShader([[
  88. layout(set = 2, binding = 0) uniform sampler mySampler;
  89. layout(set = 2, binding = 1) uniform Colors { vec4 colors[256]; };
  90. layout(set = 2, binding = 2) uniform texture2D rocks;
  91. Constants {
  92. uint constant;
  93. };
  94. vec4 lovrmain() {
  95. return DefaultPosition;
  96. }
  97. ]], 'unlit')
  98. clampler = lovr.graphics.newSampler({ wrap = 'clamp' })
  99. colorBuffer = lovr.graphics.newBuffer(256, 'vec4')
  100. rockTexture = lovr.graphics.newTexture('rocks.jpg')
  101. end
  102. function lovr.draw(pass)
  103. pass:setShader(shader)
  104. pass:send('mySampler', clampler)
  105. pass:send('Colors', colorBuffer)
  106. pass:send('rocks', rockTexture)
  107. pass:send('constant', 42)
  108. -- Draw
  109. end
  110. ]=]
  111. }