newMaterial.lua 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. return {
  2. tag = 'graphics-objects',
  3. summary = 'Create a new Material.',
  4. description = [[
  5. Creates a new Material from a table of properties and textures. All fields are optional. Once
  6. a Material is created, its properties can not be changed. Instead, a new Material should be
  7. created with the updated properties.
  8. ]],
  9. arguments = {
  10. properties = {
  11. type = 'table',
  12. description = 'Material properties.',
  13. table = {
  14. {
  15. name = 'color',
  16. type = 'Vec4',
  17. default = '{ 1, 1, 1, 1 }',
  18. description = [[
  19. The base color of the surface. Can be a `Vec3`, `Vec4`, table of numbers, or hexcode.
  20. Can be toggled in shaders using the `materialColor` flag, which defaults to `true`.
  21. ]]
  22. },
  23. {
  24. name = 'glow',
  25. type = 'Vec4',
  26. default = '{ 0, 0, 0, 0 }',
  27. description = [[
  28. The glow color of the surface, sometimes called "emissive". The glow is not affected by
  29. lighting, so it's a good fit for e.g. headlights on a car or LED lights on a panel. The
  30. alpha of the glow color is used as the glow strength. Can be a `Vec3`, `Vec4`, table of
  31. numbers, or hexcode. Can be toggled in shaders using the `glow` flag, which defaults to
  32. `false`.
  33. ]]
  34. },
  35. {
  36. name = 'uvShift',
  37. type = 'Vec2',
  38. default = '{ 0, 0 }',
  39. description = [[
  40. An offset to apply to the UV coordinates used to sample textures. The offset is not
  41. affected by `uvScale`. This can be used to map UV coordinates to a sub-rectangle of a
  42. texture atlas. Can be a `Vec2`, table of numbers, or a single number which gets
  43. assigned to both axes. Can be toggled in shaders using the `uvTransform` flag, which
  44. defaults to `true`.
  45. ]]
  46. },
  47. {
  48. name = 'uvScale',
  49. type = 'Vec2',
  50. default = '{ 1, 1 }',
  51. description = [[
  52. A scale factor to apply to the UV coordinates used to sample textures. The scale is not
  53. affected by `uvOffset`. This can be used to map UV coordinates to a sub-rectangle of a
  54. texture atlas, or repeat a texture multiple times across a surface. Can be a `Vec2`,
  55. table of numbers, or a single number which gets assigned to both axes. Can be toggled in
  56. shaders using the `uvTransform` flag, which defaults to `true`.
  57. ]]
  58. },
  59. {
  60. name = 'metalness',
  61. type = 'number',
  62. default = '0',
  63. description = [[
  64. The metalness the surface, used for physically-based rendering. 1.0 means the surface
  65. is metallic (conductor), and 0.0 means the surface is non-metallic (dielectric). Values
  66. in between are seldom used and are only used in textures to transition between a
  67. metallic and non-metallic surface. Metals reflect light differently than non-metals.
  68. Used by the lighting helper functions `initSurface` and `getLighting`.
  69. ]]
  70. },
  71. {
  72. name = 'roughness',
  73. type = 'number',
  74. default = '0',
  75. description = [[
  76. The roughness of the surface, used for physically-based rendering. 1.0 means the
  77. surface is rough (blurry reflections), and 0.0 means the surface is smooth (sharp
  78. reflections). Used by the lighting helper functions `initSurface` and `getLighting`.
  79. ]]
  80. },
  81. {
  82. name = 'clearcoat',
  83. type = 'number',
  84. default = '0',
  85. description = 'The clearcoat factor. Not currently used by LÖVR.'
  86. },
  87. {
  88. name = 'clearcoatRoughness',
  89. type = 'number',
  90. default = '0',
  91. description = 'The roughness of the clearcoat layer. Not currently used by LÖVR.'
  92. },
  93. {
  94. name = 'occlusionStrength',
  95. type = 'number',
  96. default = '1',
  97. description = [[
  98. The strength of the ambient occlusion effect. Ambient occlusion only affects indirect
  99. lighting. Used by the lighting helper functions `initSurface` and
  100. `getIndirectLighting`. Can be toggled in shaders using the `ambientOcclusion` flag,
  101. which defaults to `true`.
  102. ]]
  103. },
  104. {
  105. name = 'normalScale',
  106. type = 'number',
  107. default = '1',
  108. description = [[
  109. The strength of the normal map. Used by the `initSurface` function to bend the surface
  110. normal. Can be toggled in shaders using the `normalMap` flag, which defaults to
  111. `false`.
  112. ]]
  113. },
  114. {
  115. name = 'alphaCutoff',
  116. type = 'number',
  117. default = '0',
  118. description = [[
  119. The alpha cutoff. At the end of the fragment shader, if the alpha of the final color is
  120. below the alpha cutoff, then the pixel will be "discarded" which means that it won't
  121. write a depth value. Often used for transparent textures, especially with the "alpha to
  122. coverage" state set by `Pass:setAlphaToCoverage`. Can be toggled in shaders using the
  123. `alphaCutoff` flag, which defaults to `false`.
  124. ]]
  125. },
  126. {
  127. name = 'texture',
  128. type = 'Texture',
  129. description = [[
  130. The base color texture. In shaders this gets multiplied with the `color` property to
  131. get the base color of the pixel. Can be toggled in shaders using the `colorTexture`
  132. flag, which defaults to `true`.
  133. ]]
  134. },
  135. {
  136. name = 'glowTexture',
  137. type = 'Texture',
  138. description = [[
  139. The glow color texture. In shaders, samples from this texture get multiplied with the
  140. `glow` property to get the glow color of the pixel. Can be toggled in shaders using the
  141. `glowTexture` flag, which defaults to `true` (also requires the `glow` flag to be
  142. enabled).
  143. ]]
  144. },
  145. {
  146. name = 'metalnessTexture',
  147. type = 'Texture',
  148. description = [[
  149. The metalness texture. In shaders, samples from the blue channel of this texture get
  150. multiplied with the `metalness` property to get the metalness value of the pixel. Can
  151. be toggled in shaders using the `metalnessTexture` flag, which defaults to `true`.
  152. ]]
  153. },
  154. {
  155. name = 'roughnessTexture',
  156. type = 'Texture',
  157. description = [[
  158. The roughness texture. In shaders, samples from the green channel of this texture get
  159. multiplied with the `roughness` property to get the roughness value of the pixel. Can
  160. be toggled in shaders using the `roughnessTexture` flag, which defaults to `true`.
  161. ]]
  162. },
  163. {
  164. name = 'clearcoatTexture',
  165. type = 'Texture',
  166. description = 'Not currently used by LÖVR.'
  167. },
  168. {
  169. name = 'occlusionTexture',
  170. type = 'Texture',
  171. description = [[
  172. The ambient occlusion texture. In shaders, samples from the red channel of this texture
  173. get multiplied with the `occlusionStrength` property to get the ambient occlusion value
  174. of the pixel. Used by the lighting helper functions `initSurface` and
  175. `getIndirectLighting`. Can be toggled in shaders using the `ambientOcclusion` flag,
  176. which defaults to `true`.
  177. ]]
  178. },
  179. {
  180. name = 'normalTexture',
  181. type = 'Texture',
  182. description = [[
  183. The normal map, used to apply details to a surface without adding mesh geometry. The
  184. `normalScale` property can be used to control how strong the effect is. Can be toggled
  185. in shaders using the `normalMap` flag, which defaults to `false`.
  186. ]]
  187. }
  188. }
  189. }
  190. },
  191. returns = {
  192. material = {
  193. type = 'Material',
  194. description = 'The new material.'
  195. }
  196. },
  197. variants = {
  198. {
  199. arguments = { 'properties' },
  200. returns = { 'material' }
  201. }
  202. },
  203. notes = [[
  204. The non-texture material properties can be accessed in shaders using `Material.<property>`,
  205. where the property is the same as the Lua table key. The textures use capitalized names in
  206. shader code, e.g. `ColorTexture`.
  207. ]]
  208. }