2
0

Uniform.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <p class="desc">Uniforms are global [link:https://www.opengl.org/documentation/glsl/ GLSL] variables. They are passed to shader programs.
  13. </p>
  14. <h3>Example</h3>
  15. <p>
  16. When declaring a uniform of a [page:ShaderMaterial], it is declared by value or by object.
  17. </p>
  18. <code>
  19. uniforms: {
  20. time: { value: 1.0 },
  21. resolution: new THREE.Uniform(new THREE.Vector2())
  22. }
  23. </code>
  24. <h3>Uniform types</h3>
  25. <p>
  26. Each uniform must have a *value* property. The type of the value must correspond to the
  27. type of the uniform variable in the GLSL code as specified for the primitive GLSL types
  28. in the table below. Uniform structures and arrays are also supported. GLSL arrays of primitive
  29. type must either be specified as an array of the corresponding THREE objects or as a flat
  30. array containing the data of all the objects. In other words; GLSL primitives in arrays
  31. must not be represented by arrays. This rule does not apply transitively.
  32. An array of *vec2* arrays, each with a length of five vectors, must be an array of arrays,
  33. of either five [page:Vector2] objects or ten *number*s.
  34. </p>
  35. <table>
  36. <caption><a id="uniform-types">Uniform types</a></caption>
  37. <thead>
  38. <tr>
  39. <th>GLSL type</th>
  40. <th>JavaScript type</th>
  41. </tr>
  42. </thead>
  43. <tbody>
  44. <tr>
  45. <td>int</td>
  46. <td>[page:Number]</td>
  47. </tr>
  48. <tr>
  49. <td>float</td>
  50. <td>[page:Number]</td>
  51. </tr>
  52. <tr>
  53. <td>bool</td>
  54. <td>[page:Boolean]</td>
  55. </tr>
  56. <tr>
  57. <td>bool</td>
  58. <td>[page:Number]</td>
  59. </tr>
  60. <tr>
  61. <td>vec2</td>
  62. <td>[page:Vector2 THREE.Vector2]</td>
  63. </tr>
  64. <tr>
  65. <td>vec2</td>
  66. <td>[page:Float32Array Float32Array] (*)</td>
  67. </tr>
  68. <tr>
  69. <td>vec2</td>
  70. <td>[page:Array Array] (*)</td>
  71. </tr>
  72. <tr>
  73. <td>vec3</td>
  74. <td>[page:Vector3 THREE.Vector3]</td>
  75. </tr>
  76. <tr>
  77. <td>vec3</td>
  78. <td>[page:Color THREE.Color]</td>
  79. </tr>
  80. <tr>
  81. <td>vec3</td>
  82. <td>[page:Float32Array Float32Array] (*)</td>
  83. </tr>
  84. <tr>
  85. <td>vec3</td>
  86. <td>[page:Array Array] (*)</td>
  87. </tr>
  88. <tr>
  89. <td>vec4</td>
  90. <td>[page:Vector4 THREE.Vector4]</td>
  91. </tr>
  92. <tr>
  93. <td>vec4</td>
  94. <td>[page:Quaternion THREE.Quaternion]</td>
  95. </tr>
  96. <tr>
  97. <td>vec4</td>
  98. <td>[page:Float32Array Float32Array] (*)</td>
  99. </tr>
  100. <tr>
  101. <td>vec4</td>
  102. <td>[page:Array Array] (*)</td>
  103. </tr>
  104. <tr>
  105. <td>mat2</td>
  106. <td>[page:Float32Array Float32Array] (*)</td>
  107. </tr>
  108. <tr>
  109. <td>mat2</td>
  110. <td>[page:Array Array] (*)</td>
  111. </tr>
  112. <tr>
  113. <td>mat3</td>
  114. <td>[page:Matrix3 THREE.Matrix3]</td>
  115. </tr>
  116. <tr>
  117. <td>mat3</td>
  118. <td>[page:Float32Array Float32Array] (*)</td>
  119. </tr>
  120. <tr>
  121. <td>mat3</td>
  122. <td>[page:Array Array] (*)</td>
  123. </tr>
  124. <tr>
  125. <td>mat4</td>
  126. <td>[page:Matrix3 THREE.Matrix4]</td>
  127. </tr>
  128. <tr>
  129. <td>mat4</td>
  130. <td>[page:Float32Array Float32Array] (*)</td>
  131. </tr>
  132. <tr>
  133. <td>mat4</td>
  134. <td>[page:Array Array] (*)</td>
  135. </tr>
  136. <tr>
  137. <td>ivec2, bvec2</td>
  138. <td>[page:Float32Array Float32Array] (*)</td>
  139. </tr>
  140. <tr>
  141. <td>ivec2, bvec2</td>
  142. <td>[page:Array Array] (*)</td>
  143. </tr>
  144. <tr>
  145. <td>ivec3, bvec3</td>
  146. <td>[page:Int32Array Int32Array] (*)</td>
  147. </tr>
  148. <tr>
  149. <td>ivec3, bvec3</td>
  150. <td>[page:Array Array] (*)</td>
  151. </tr>
  152. <tr>
  153. <td>ivec4, bvec4</td>
  154. <td>[page:Int32Array Int32Array] (*)</td>
  155. </tr>
  156. <tr>
  157. <td>ivec4, bvec4</td>
  158. <td>[page:Array Array] (*)</td>
  159. </tr>
  160. <tr>
  161. <td>sampler2D</td>
  162. <td>[page:Texture THREE.Texture]</td>
  163. </tr>
  164. <tr>
  165. <td>samplerCube</td>
  166. <td>[page:CubeTexture THREE.CubeTexture]</td>
  167. </tr>
  168. </tbody>
  169. </table>
  170. <p>
  171. (*) Same for an (innermost) array (dimension) of the same GLSL type, containing the components of all vectors or matrices in the array.
  172. </p>
  173. <h2>Constructor</h2>
  174. <h3>[name]( [param:Object value] )</h3>
  175. <p>
  176. value -- An object containing the value to set up the uniform. It's type must be one of the Uniform Types described above.
  177. </p>
  178. <h2>Properties</h2>
  179. <h3>[property:Object value]</h3>
  180. <p>
  181. Current value of the uniform.
  182. </p>
  183. <h2>Methods</h2>
  184. <h3>[method:Uniform clone]()</h3>
  185. <p>
  186. Returns a clone of this uniform.<br />
  187. If the uniform's value property is an [page:Object] with a clone() method, this is used, otherwise the value is copied by assignment.
  188. Array values are shared between cloned [page:Uniform]s.<br /><br />
  189. See [example:webgldeferred_animation WebGL deferred animation] for an example of this method in use.
  190. </p>
  191. <h2>Source</h2>
  192. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  193. </body>
  194. </html>