Material.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8"/>
  5. <base href="../../../"/>
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css"/>
  8. </head>
  9. <body>
  10. <h1>材质([name])</h1>
  11. <p class="desc">材质的抽象基类。<br/><br/>
  12. 材质描述了对象[page:Object objects]的外观。它们的定义方式与渲染器无关,
  13. 因此,如果您决定使用不同的渲染器,不必重写材质。<br/><br/>
  14. 所有其他材质类型都继承了以下属性和方法(尽管它们可能具有不同的默认值)。
  15. </p>
  16. <h2>构造函数(Constructor)</h2>
  17. <h3>[name]()</h3>
  18. <p>该方法创建一个通用材质。</p>
  19. <h2>属性(Properties)</h2>
  20. <h3>[property:Boolean alphaHash]</h3>
  21. <p>
  22. 启用alphaHash透明度,这是[page:.transparent]或[page:.alphaTest]的替代方案。如果不透明度低于随机阈值,则不会渲染材质。随机化会引入一些颗粒或噪点,但相较于传统的Alpha blend方式,避免了透明度引起的深度排序问题。使用TAARenderPass可以有效减少噪点。
  23. </p>
  24. <h3>[property:Float alphaTest]</h3>
  25. <p>设置运行alphaTest时要使用的alpha值。如果不透明度低于此值,则不会渲染材质。默认值为*0*。
  26. </p>
  27. <h3>[property:Boolean alphaToCoverage]</h3>
  28. <p>
  29. Enables alpha to coverage. Can only be used with MSAA-enabled contexts
  30. (meaning when the renderer was created with *antialias* parameter set to
  31. `true`). Enabling this will smooth aliasing on clip plane edges and alphaTest-clipped edges.
  32. Default is `false`.
  33. </p>
  34. <h3>[property:Integer blendDst]</h3>
  35. <p> 混合目标。默认值为[page:CustomBlendingEquation OneMinusSrcAlphaFactor]。
  36. 目标因子所有可能的取值请参阅[page:CustomBlendingEquation constants]。
  37. 必须将材质的[page:Constant blending]设置为[page:Materials CustomBlending]才能生效。<br/>
  38. </p>
  39. <h3>[property:Integer blendDstAlpha]</h3>
  40. <p> [page:.blendDst]的透明度。 默认值为 *null*.</p>
  41. <h3>[property:Integer blendEquation]</h3>
  42. <p> 使用混合时所采用的混合方程式。默认值为[page:CustomBlendingEquation AddEquation]。
  43. 混合方程式所有可能的取值请参阅[page:CustomBlendingEquation constants]。
  44. 必须将材质的[page:Constant blending]设置为[page:Materials CustomBlending]才能生效。<br/>
  45. </p>
  46. <h3>[property:Integer blendEquationAlpha]</h3>
  47. <p>[page:.blendEquation] 的透明度. 默认值为 *null*.</p>
  48. <h3>[property:Blending blending]</h3>
  49. <p> 在使用此材质显示对象时要使用何种混合。<br/>
  50. 必须将其设置为[page:Materials CustomBlending]才能使用自定义[page:Constant blendSrc], [page:Constant blendDst] 或者 [page:Constant
  51. blendEquation]。
  52. 混合模式所有可能的取值请参阅[page:Materials constants]。默认值为[page:Materials NormalBlending]。
  53. </p>
  54. <h3>[property:Integer blendSrc]</h3>
  55. <p> 混合源。默认值为[page:CustomBlendingEquation SrcAlphaFactor]。
  56. 源因子所有可能的取值请参阅[page:CustomBlendingEquation constants]。<br/>
  57. 必须将材质的[page:Constant blending]设置为[page:Materials CustomBlending]才能生效。
  58. </p>
  59. <h3>[property:Integer blendSrcAlpha]</h3>
  60. <p> [page:.blendSrc]的透明度。 默认值为 *null*.</p>
  61. <h3>[property:Boolean clipIntersection]</h3>
  62. <p>更改剪裁平面的行为,以便仅剪切其交叉点,而不是它们的并集。默认值为 *false*。
  63. </p>
  64. <h3>[property:Array clippingPlanes]</h3>
  65. <p>
  66. 用户定义的剪裁平面,在世界空间中指定为THREE.Plane对象。这些平面适用于所有使用此材质的对象。空间中与平面的有符号距离为负的点被剪裁(未渲染)。
  67. 这需要[page:WebGLRenderer.localClippingEnabled]为*true*。
  68. 示例请参阅[example:webgl_clipping_intersection WebGL / clipping /intersection]。默认值为 *null*。
  69. </p>
  70. <h3>[property:Boolean clipShadows]</h3>
  71. <p>定义是否根据此材质上指定的剪裁平面剪切阴影。默认值为 *false*。
  72. </p>
  73. <h3>[property:Boolean colorWrite]</h3>
  74. <p> 是否渲染材质的颜色。
  75. 这可以与网格的[page:Integer renderOrder]属性结合使用,以创建遮挡其他对象的不可见对象。默认值为*true*。
  76. </p>
  77. <h3>[property:Object defines]</h3>
  78. <p> 注入shader的自定义对象。 以键值对形式的对象传递,{ MY_CUSTOM_DEFINE: '' , PI2: Math.PI * 2 }。
  79. 这些键值对在顶点和片元着色器中定义。默认值为*undefined*。
  80. </p>
  81. <h3>[property:Integer depthFunc]</h3>
  82. <p> 使用何种深度函数。默认为[page:Materials LessEqualDepth]。
  83. 深度模式所有可能的取值请查阅[page:Materials constants]。
  84. </p>
  85. <h3>[property:Boolean depthTest]</h3>
  86. <p>是否在渲染此材质时启用深度测试。默认为 *true*。
  87. </p>
  88. <h3>[property:Boolean depthWrite]</h3>
  89. <p>渲染此材质是否对深度缓冲区有任何影响。默认为*true*。<br/><br/>
  90. 在绘制2D叠加时,将多个事物分层在一起而不创建z-index时,禁用深度写入会很有用。
  91. </p>
  92. <h3>[property:Boolean forceSinglePass]</h3>
  93. <p>
  94. 决定双面透明的东西是否强制使用单通道渲染,默认为`false`。<br /><br />
  95. 为了减少一些半透明物体的渲染错误,此引擎调用两次绘制来渲染渲染双面透明的东西。
  96. 但是此方案可能会导致在某些情况下使绘制调用次数翻倍,例如渲染一些平面的植物例如草精灵之类的。
  97. 在这些情况下,将`forceSinglePass`设置为`true`来使用单通道渲染来避免性能问题。
  98. </p>
  99. <h3>[property:Boolean isMaterial]</h3>
  100. <p>
  101. 检查这个对象是否为材质[name]的只读标记.
  102. </p>
  103. <h3>[property:Boolean stencilWrite]</h3>
  104. <p>
  105. 是否对模板缓冲执行模板操作,如果执行写入或者与模板缓冲进行比较,这个值需要设置为*true*。默认为*false*。
  106. </p>
  107. <h3>[property:Integer stencilWriteMask]</h3>
  108. <p>
  109. 写入模板缓冲区时所用的位元遮罩,默认为*0xFF*。
  110. </p>
  111. <h3>[property:Integer stencilFunc]</h3>
  112. <p>
  113. 使用模板比较时所用的方法,默认为[page:Materials AlwaysStencilFunc]。在模板函数 [page:Materials constants] 中查看可用的值
  114. </p>
  115. <h3>[property:Integer stencilRef]</h3>
  116. <p>
  117. 在进行模板比较或者模板操作的时候所用的基准值,默认为*0*。
  118. </p>
  119. <h3>[property:Integer stencilFuncMask]</h3>
  120. <p>
  121. 与模板缓冲进行比较时所使用的位元遮罩,默认为*0xFF*
  122. </p>
  123. <h3>[property:Integer stencilFail]</h3>
  124. <p>
  125. 当比较函数没有通过的时候要执行的模板操作,默认为[page:Materials KeepStencilOp],在模板操作 [page:Materials constants] 查看可用值。
  126. </p>
  127. <h3>[property:Integer stencilZFail]</h3>
  128. <p>
  129. 当比较函数通过了但是深度检测没有通过的时候要执行的模板操作, 默认为[page:Materials KeepStencilOp],在模板操作 [page:Materials constants] 查看可用值。
  130. </p>
  131. <h3>[property:Integer stencilZPass]</h3>
  132. <p>
  133. 当比较函数和深度检测都通过时要执行的模板操作,默认为[page:Materials KeepStencilOp],在模板操作[page:Materials constants] 中查看可用值。
  134. </p>
  135. <h3>[property:Integer id]</h3>
  136. <p>此材质实例的唯一编号。</p>
  137. <h3>[property:String name]</h3>
  138. <p>对象的可选名称(不必是唯一的)。默认值为空字符串。</p>
  139. <h3>[property:Boolean needsUpdate]</h3>
  140. <p>指定需要重新编译材质。
  141. </p>
  142. <h3>[property:Float opacity]</h3>
  143. <p> 在0.0 - 1.0的范围内的浮点数,表明材质的透明度。值*0.0*表示完全透明,*1.0*表示完全不透明。<br/>
  144. 如果材质的[page:Boolean transparent]属性未设置为*true*,则材质将保持完全不透明,此值仅影响其颜色。
  145. 默认值为*1.0*。 <br/>
  146. </p>
  147. <h3>[property:Boolean polygonOffset]</h3>
  148. <p> 是否使用多边形偏移。默认值为*false*。这对应于WebGL的*GL_POLYGON_OFFSET_FILL*功能。
  149. </p>
  150. <h3>[property:Integer polygonOffsetFactor]</h3>
  151. <p>设置多边形偏移系数。默认值为*0*。</p>
  152. <h3>[property:Integer polygonOffsetUnits]</h3>
  153. <p>设置多边形偏移单位。默认值为*0*。</p>
  154. <h3>[property:String precision]</h3>
  155. <p> 重写此材质渲染器的默认精度。可以是"*highp*", "*mediump*" 或 "*lowp*"。默认值为*null*。
  156. </p>
  157. <h3>[property:Boolean premultipliedAlpha]</h3>
  158. <p> 是否预乘alpha(透明度)值。有关差异的示例,请参阅[Example:webgl_materials_physical_transmission WebGL / Materials / Physical / Transmission]。
  159. 默认值为*false*。
  160. </p>
  161. <h3>[property:Boolean dithering]</h3>
  162. <p> 是否对颜色应用抖动以消除条带的外观。默认值为 *false*。
  163. </p>
  164. <h3>[property:Integer shadowSide]</h3>
  165. <p> 定义投影的面。设置时,可以是[page:Materials THREE.FrontSide], [page:Materials THREE.BackSide], 或[page:Materials]。默认值为 *null*。
  166. <br/>
  167. 如果为*null*, 则面投射阴影确定如下: <br/>
  168. <table>
  169. <thead>
  170. <tr>
  171. <th>[page:Material.side]</th>
  172. <th>Side casting shadows</th>
  173. </tr>
  174. </thead>
  175. <tbody>
  176. <tr>
  177. <td>THREE.FrontSide</td>
  178. <td>背面</td>
  179. </tr>
  180. <tr>
  181. <td>THREE.BackSide</td>
  182. <td>前面</td>
  183. </tr>
  184. <tr>
  185. <td>THREE.DoubleSide</td>
  186. <td>双面</td>
  187. </tr>
  188. </tbody>
  189. </table>
  190. </p>
  191. <h3>[property:Integer side]</h3>
  192. <p> 定义将要渲染哪一面 - 正面,背面或两者。
  193. 默认为[page:Materials THREE.FrontSide]。其他选项有[page:Materials THREE.BackSide] 和 [page:Materials THREE.DoubleSide]。
  194. </p>
  195. <h3>[property:Boolean toneMapped]</h3>
  196. <p>
  197. 定义这个材质是否会被渲染器的[page:WebGLRenderer.toneMapping toneMapping]设置所影响,默认为 *true* 。
  198. </p>
  199. <h3>[property:Boolean transparent]</h3>
  200. <p>
  201. 定义此材质是否透明。这对渲染有影响,因为透明对象需要特殊处理,并在非透明对象之后渲染。
  202. <br/>
  203. 设置为true时,通过设置材质的[page:Float opacity]属性来控制材质透明的程度。<br/>
  204. 默认值为*false*。
  205. </p>
  206. <h3>[property:String type]</h3>
  207. <p> 值是字符串'Material'。不应该被更改,并且可以用于在场景中查找此类型的所有对象。
  208. </p>
  209. <h3>[property:String uuid]</h3>
  210. <p> 此材质实例的[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID],会自动分配,不应该被更改。
  211. </p>
  212. <h3>[property:Integer version]</h3>
  213. <p>
  214. 开始为0,会记录[property:Boolean needsUpdate]设置为*true*的次数。
  215. </p>
  216. <h3>[property:Boolean vertexColors]</h3>
  217. <p>
  218. 是否使用顶点着色。默认值为false。
  219. 此引擎支持RGB或者RGBA两种顶点颜色,取决于缓冲 attribute 使用的是三分量(RGB)还是四分量(RGBA)。
  220. </p>
  221. <h3>[property:Boolean visible]</h3>
  222. <p> 此材质是否可见。默认为*true*。
  223. </p>
  224. <h3>[property:Object userData]</h3>
  225. <p> 一个对象,可用于存储有关Material的自定义数据。它不应该包含对函数的引用,因为这些函数不会被克隆。
  226. </p>
  227. <h2>方法(Methods)</h2>
  228. <p>[page:EventDispatcher EventDispatcher] 方法在此类中可用。</p>
  229. <h3>[method:Material clone]( )</h3>
  230. <p> 返回与此材质具有相同参数的新材质。</p>
  231. <h3>[method:this copy]( [param:material material] )</h3>
  232. <p> 将被传入材质中的参数复制到此材质中。</p>
  233. <h3>[method:undefined dispose]()</h3>
  234. <p> 处理材质。材质的纹理不会被处理。需要通过[page:Texture Texture]处理。
  235. </p>
  236. <h3>[method:undefined onBeforeCompile]( [param:Shader shader], [param:WebGLRenderer renderer] )</h3>
  237. <p> 在编译shader程序之前立即执行的可选回调。此函数使用shader源码作为参数。用于修改内置材质。
  238. </p>
  239. <p>
  240. 和其他属性不一样的是,这个回调在[page:Material.clone .clone](),[page:Material.copy .copy]() 和 [page:Material.toJSON .toJSON]() 中不支持。
  241. </p>
  242. <h3>[method:String customProgramCacheKey]()</h3>
  243. <p>
  244. 当用到onBeforeCompile回调的时候,这个回调函数可以用来定义在onBeforeCompile中使用的配置项,这样three.js就可以根据这个回调返回的字符串来判定使用一个缓存的编译好的着色器代码还是根据需求重新编译一段新的着色器代码。
  245. </p>
  246. <p>
  247. 例如一个onBeforeCompile回调函数包含了下面的条件语句:<br />
  248. <code>if ( black ) {
  249. shader.fragmentShader = shader.fragmentShader.replace('gl_FragColor = vec4(1)', 'gl_FragColor = vec4(0)')
  250. }
  251. </code>
  252. 那么 customProgramCacheKey 就可以设置为:<br />
  253. <code>material.customProgramCacheKey = function() {
  254. return black ? '1' : '0';
  255. }
  256. </code>
  257. </p>
  258. <p>
  259. 和其他属性不一样的是,这个回调在[page:Material.clone .clone](),[page:Material.copy .copy]() 和 [page:Material.toJSON .toJSON]() 中不支持。
  260. </p>
  261. <h3>[method:undefined setValues]( [param:Object values] )</h3>
  262. <p> values -- 具有参数的容器。
  263. 根据*values*设置属性。<br/>
  264. </p>
  265. <h3>[method:Object toJSON]( [param:Object meta] )</h3>
  266. <p>
  267. meta -- 包含有元数据的对象,例如该对象的纹理或图片。
  268. 将material对象转换为 three.js [link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format](three.js JSON 物体/场景格式)。
  269. </p>
  270. <h2>源码(Source)</h2>
  271. <p>
  272. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  273. </p>
  274. </body>
  275. </html>