newShader.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. return {
  2. tag = 'graphicsObjects',
  3. summary = 'Create a new Shader.',
  4. description = 'Creates a new Shader.',
  5. arguments = {
  6. vertex = {
  7. type = 'string',
  8. description = [[
  9. The code or filename of the vertex shader. If nil, the default vertex shader is used.
  10. ]]
  11. },
  12. fragment = {
  13. type = 'string',
  14. description = [[
  15. The code or filename of the fragment shader. If nil, the default fragment shader is used.
  16. ]]
  17. },
  18. default = {
  19. type = 'DefaultShader',
  20. description = 'A builtin shader to use for the shader code.'
  21. },
  22. options = {
  23. type = 'table',
  24. default = '{}',
  25. description = 'Optional settings for the Shader.',
  26. table = {
  27. {
  28. name = 'flags',
  29. type = 'table',
  30. default = '{}',
  31. description = 'A table of key-value options passed to the Shader.'
  32. },
  33. {
  34. name = 'stereo',
  35. type = 'boolean',
  36. default = 'true',
  37. description = [[
  38. Whether the Shader should be configured for stereo rendering (Currently Android-only).
  39. ]]
  40. }
  41. }
  42. }
  43. },
  44. returns = {
  45. shader = {
  46. type = 'Shader',
  47. description = 'The new Shader.'
  48. }
  49. },
  50. variants = {
  51. {
  52. description = 'Create a Shader with custom GLSL code.',
  53. arguments = { 'vertex', 'fragment', 'options' },
  54. returns = { 'shader' },
  55. },
  56. {
  57. description = 'Create a new instance of a built-in Shader.',
  58. arguments = { 'default', 'options' },
  59. returns = { 'shader' },
  60. }
  61. },
  62. notes = [[
  63. The `flags` table should contain string keys, with boolean or numeric values. These flags can
  64. be used to customize the behavior of Shaders from Lua, by using the flags in the shader source
  65. code. Numeric flags will be available as constants named `FLAG_<flagName>`. Boolean flags can
  66. be used with `#ifdef` and will only be defined if the value in the Lua table was `true`.
  67. The following flags are used by shaders provided by LÖVR:
  68. - `animated` is a boolean flag that will cause the shader to position vertices based on the pose
  69. of an animated skeleton. This should usually only be used for animated `Model`s, since it
  70. needs a skeleton to work properly and is slower than normal rendering.
  71. - `alphaCutoff` is a numeric flag that can be used to implement simple "cutout" style
  72. transparency, where pixels with alpha below a certain threshold will be discarded. The value
  73. of the flag should be a number between 0.0 and 1.0, representing the alpha threshold.
  74. - `uniformScale` is a boolean flag used for optimization. If the Shader is only going to be
  75. used with objects that have a *uniform* scale (i.e. the x, y, and z components of the scale
  76. are all the same number), then this flag can be set to use a faster method to compute the
  77. `lovrNormalMatrix` uniform variable.
  78. - `multicanvas` is a boolean flag that should be set when rendering to multiple Textures
  79. attached to a `Canvas`. When set, the fragment shader should implement the `colors` function
  80. instead of the `color` function, and can write color values to the `lovrCanvas` array instead
  81. of returning a single color. Each color in the array gets written to the corresponding
  82. texture attached to the canvas.
  83. - `highp` is a boolean flag specific to mobile GPUs that changes the default precision for
  84. fragment shaders to use high precision instead of the default medium precision. This can fix
  85. visual issues caused by a lack of precision, but isn't guaranteed to be supported on some
  86. lower-end systems.
  87. - The following flags are used only by the `standard` PBR shader:
  88. - `normalMap` should be set to `true` to render objects with a normal map, providing a more
  89. detailed, bumpy appearance. Currently, this requires the model to have vertex tangents.
  90. - `emissive` should be set to `true` to apply emissive maps to rendered objects. This is
  91. usually used to apply glowing lights or screens to objects, since the emissive texture is
  92. not affected at all by lighting.
  93. - `indirectLighting` is an *awesome* boolean flag that will apply realistic reflections and
  94. lighting to the surface of an object, based on a specially-created skybox. See the
  95. `Standard Shader` guide for more information.
  96. - `occlusion` is a boolean flag that uses the ambient occlusion texture in the model. It only
  97. affects indirect lighting, so it will only have an effect if the `indirectLighting` flag is
  98. also enabled.
  99. - `skipTonemap` is a flag that will skip the tonemapping process. Tonemapping is an important
  100. process that maps the high definition physical color values down to a 0 - 1 range for
  101. display. There are lots of different tonemapping algorithms that give different artistic
  102. effects. The default tonemapping in the standard shader is the ACES algorithm, but you can
  103. use this flag to turn off ACES and use your own tonemapping.
  104. Currently, up to 32 shader flags are supported.
  105. The `stereo` option is only necessary for Android. Currently on Android, only stereo shaders
  106. can be used with stereo Canvases, and mono Shaders can only be used with mono Canvases.
  107. ]],
  108. related = {
  109. 'lovr.graphics.setShader',
  110. 'lovr.graphics.getShader',
  111. 'lovr.graphics.newComputeShader'
  112. }
  113. }