WebGLRenderer.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. <div class="desc">The WebGL renderer displays your beautifully crafted scenes using WebGL, if your device supports it.</div>
  13. <h2>Constructor</h2>
  14. <h3>[name]( [page:Object parameters] )</h3>
  15. <div>
  16. parameters is an optional object with properties defining the renderer's behaviour.
  17. The constructor also accepts no parameters at all. In all cases, it will assume sane defaults
  18. when parameters are missing.
  19. </div>
  20. <div>
  21. canvas — A [link:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas canvas] where the renderer draws its output.
  22. This corresponds to the [page:WebGLRenderer.domElement .domElement] property below.<br />
  23. context — This can be used to attach the renderer to an existing <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext">RenderingContext</a>.<br />
  24. precision — Shader precision. Can be *"highp"*, *"mediump"* or *"lowp"*. Defaults to *"highp"* if supported by the device.<br />
  25. alpha — whether the canvas contains an alpha (transparency) buffer or not. Default is *false*.<br />
  26. premultipliedAlpha — whether the renderer will assume that colors have premultiplied alpha. Default is *true*.<br />
  27. antialias — whether to perform antialiasing. Default is *false*.<br />
  28. stencil — whether the drawing buffer has a stencil buffer of at least 8 bits. Default is *true*.<br />
  29. preserveDrawingBuffer — whether to preserve the buffers until manually cleared or overwritten. Default is *false*.<br />
  30. depth — whether the drawing buffer has a depth buffer of at least 16 bits. Default is *true*.<br />
  31. logarithmicDepthBuffer — whether to use a lograthimic depth buffer. Default is *false*.
  32. See the [example:webgl_camera_logarithmicdepthbuffer camera / logarithmicdepthbuffer] example.
  33. </div>
  34. <h2>Properties</h2>
  35. <h3>[property:Boolean autoClear]</h3>
  36. <div>Defines whether the renderer should automatically clear its output before rendering.</div>
  37. <h3>[property:Boolean autoClearColor]</h3>
  38. <div>If autoClear is true, defines whether the renderer should clear the color buffer. Default is *true*.</div>
  39. <h3>[property:Boolean autoClearDepth]</h3>
  40. <div>If autoClear is true, defines whether the renderer should clear the depth buffer. Default is *true*.</div>
  41. <h3>[property:Boolean autoClearStencil]</h3>
  42. <div>If autoClear is true, defines whether the renderer should clear the stencil buffer. Default is *true*.</div>
  43. <h3>[property:Object capabilities]</h3>
  44. <div>
  45. An object containing details about the capabilities of the current <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext">RenderingContext</a>.<br />
  46. - [property:Boolean floatFragmentTextures]: whether the context supports the <a href="https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_float">OES_texture_float</a> extension.
  47. According to <a href="https://webglstats.com/">WebGLStats</a>, as of February 2016 over 95% of WebGL enabled devices support this.<br />
  48. - [property:Boolean floatVertexTextures]: *true* if [property:Boolean floatFragmentTextures] and [property:Boolean vertexTextures] are both true.<br />
  49. - [property:Method getMaxAnisotropy](): see [page:WebGLRenderer.getMaxAnisotropy getMaxAnisotropy] below. <br />
  50. - [property:Method getMaxPrecision](): see [page:WebGLRenderer.getMaxPrecision getMaxPrecision] below. <br />
  51. - [property:Boolean logarithmicDepthBuffer]: *true* if the [property:parameter logarithmicDepthBuffer] was set to true in the constructor,
  52. the context supports the <a href="https://developer.mozilla.org/en-US/docs/Web/API/EXT_frag_depth">EXT_frag_depth</a> extension.
  53. According to <a href="https://webglstats.com/">WebGLStats</a>, as of February 2016 around 66% of WebGL enabled devices support this.<br />
  54. - [property:Integer maxAttributes]: The value of *gl.MAX_VERTEX_ATTRIBS*.<br />
  55. - [property:Integer maxCubemapSize]: The value of *gl.MAX_CUBE_MAP_TEXTURE_SIZE*.
  56. Maximum height * width of cube map textures that a shader can use.<br />
  57. - [property:Integer maxFragmentUniforms]: The value of *gl.MAX_FRAGMENT_UNIFORM_VECTORS*.
  58. The number of uniforms that can be used by a fragment shader.<br />
  59. - [property:Integer maxTextureSize]: The value of *gl.MAX_TEXTURE_SIZE*.
  60. Maximum height * width of a texture that a shader use.<br />
  61. - [property:Integer maxTextures]: The value of *gl.MAX_TEXTURE_IMAGE_UNITS*.
  62. The maximum number of textures that can be used by a shader.<br />
  63. - [property:Integer maxVaryings]: The value of *gl.MAX_VARYING_VECTORS*.
  64. The number of varying vectors that can used by shaders.<br />
  65. - [property:Integer maxVertexTextures]: The value of *gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS*.
  66. The number of textures that can be used in a vertex shader.<br />
  67. - [property:Integer maxVertexUniforms]: The value of *gl.MAX_VERTEX_UNIFORM_VECTORS*.
  68. The maximum number of uniforms that can be used in a vertex shader.<br />
  69. - [property:String precision]: The shader precision currently being used by the renderer.<br />
  70. - [property:Boolean vertexTextures]: *true* if [property:Integer maxVertexTextures] is greater than 0 (i.e. vertext textures can be used).<br />
  71. </div>
  72. <h3>[property:Array clippingPlanes]</h3>
  73. <div>
  74. User-defined clipping planes specified as THREE.Plane objects in world space.
  75. These planes apply globally. Points in space whose dot product with the plane is negative are cut away.
  76. Default is [].
  77. </div>
  78. <h3>[property:WebGLRenderingContext context]</h3>
  79. <div>
  80. The renderer obtains a <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext">RenderingContext</a> context
  81. from its [page:WebGLRenderer.domElement domElement][page:WebGLRenderer.domElement domElement] by default, using
  82. <a href="https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext">HTMLCanvasElement.getContext()</a>.<br /><br />
  83. You can create this manually, however it must correspond to the
  84. [page:WebGLRenderer.domElement domElement] in order to render to the screen.
  85. </div>
  86. <h3>[property:DOMElement domElement]</h3>
  87. <div>
  88. A [link:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas canvas] where the renderer draws its output.<br />
  89. This is automatically created by the renderer in the constructor (if not provided already);
  90. you just need to add it to your page like so:<br />
  91. <code>
  92. document.body.appendChild( renderer.domElement );
  93. </code>
  94. </div>
  95. <h3>[property:Object extensions]</h3>
  96. <div>
  97. A wrapper for the [page:WebGLRenderer.extensions.get .extensions.get] method, used internally to check whether
  98. various extensions are supported and set parameters accordingly.
  99. </div>
  100. <h3>[property:Boolean gammaFactor]</h3>
  101. <div>Default is *2*. </div>
  102. <h3>[property:Boolean gammaInput]</h3>
  103. <div>If set, then it expects that all textures and colors are premultiplied gamma. Default is *false*.</div>
  104. <h3>[property:Boolean gammaOutput]</h3>
  105. <div>If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is *false*.</div>
  106. <h3>[property:Object info]</h3>
  107. <div>An object with a series of statistical information about the graphics board memory and the rendering process. Useful for debugging or just for the sake of curiosity. The object contains the following fields:</div>
  108. <div>
  109. <ul>
  110. <li>memory:
  111. <ul>
  112. <li>geometries</li>
  113. <li>textures</li>
  114. </ul>
  115. </li>
  116. <li>render:
  117. <ul>
  118. <li>calls</li>
  119. <li>vertices</li>
  120. <li>faces</li>
  121. <li>points</li>
  122. </ul>
  123. </li>
  124. <li>programs
  125. </li>
  126. </ul>
  127. </div>
  128. <h3>[property:Boolean localClippingEnabled]</h3>
  129. <div>Defines whether the renderer respects object-level clipping planes. Default is *false*.</div>
  130. <h3>[property:Integer maxMorphTargets]</h3>
  131. <div>
  132. Default is 8. The maximum number of MorphTargets allowed in a shader.
  133. Keep in mind that the standard materials only allow 8 MorphTargets.
  134. </div>
  135. <h3>[property:Integer maxMorphNormals]</h3>
  136. <div>
  137. Default is 4. The maximum number of MorphNormals allowed in a shader.
  138. Keep in mind that the standard materials only allow 4 MorphNormals.
  139. </div>
  140. <h3>[property:Integer physicallyCorrectLights]</h3>
  141. <div>
  142. Whether to use physically correct lighting mode. Default is *false*.
  143. See the [example:webgl_lights_physical lights / physical] example.
  144. </div>
  145. <h3>[property:Object properties]</h3>
  146. <div>
  147. Used internally by the renderer to keep track of various sub object properties.
  148. </div>
  149. <h3>[property:WebGLShadowMap shadowMap]</h3>
  150. <div>
  151. This contains the reference to the shadow map, if used.
  152. </div>
  153. <h3>[property:Boolean shadowMap.enabled]</h3>
  154. <div>If set, use shadow maps in the scene. Default is *false*.</div>
  155. <h3>[property:Integer shadowMap.type]</h3>
  156. <div>Defines shadow map type (unfiltered, percentage close filtering, percentage close filtering with bilinear filtering in shader)</div>
  157. <div>Options are THREE.BasicShadowMap, THREE.PCFShadowMap (default), THREE.PCFSoftShadowMap. See [page:WebGLRenderer WebGLRenderer constants] for details.</div>
  158. <h3>[property:Boolean shadowMap.renderReverseSided]</h3>
  159. <div>
  160. Whether to render the opposite side as specified by the material into the shadow map.
  161. When disabled, an appropriate shadow.bias must be set on the light source for surfaces that can
  162. both cast and receive shadows at the same time to render correctly. Default is *true*.
  163. </div>
  164. <h3>[property:Boolean shadowMap.renderSingleSided]</h3>
  165. <div>
  166. Whether to treat materials specified as double-sided as if they were specified as front-sided
  167. when rendering the shadow map. When disabled, an appropriate shadow.bias must be set on the light
  168. source for surfaces that can both cast and receive shadows at the same time to render correctly.
  169. Default is *true*.
  170. </div>
  171. <h3>[property:Boolean sortObjects]</h3>
  172. <div>
  173. Defines whether the renderer should sort objects. Default is *true*.<br /><br />
  174. Note: Sorting is used to attempt to properly render objects that have some degree of transparency.
  175. By definition, sorting objects may not work in all cases. Depending on the needs of application,
  176. it may be neccessary to turn off sorting and use other methods to deal with transparency
  177. rendering e.g. manually determining the object rendering order.
  178. </div>
  179. <h3>[property:Object state]</h3>
  180. <div>
  181. Contains functions for setting various properties of the [page:WebGLRenderer.context] state.
  182. </div>
  183. <h3>[property:Constant toneMapping]</h3>
  184. <div>
  185. Default is [page:Renderer LinearToneMapping]. See the [page:Renderer Renderer constants] for other choices.
  186. </div>
  187. <h3>[property:Number toneMappingExposure]</h3>
  188. <div>
  189. Exposure level of tone mapping. Default is *1*.
  190. </div>
  191. <h3>[property:Number toneMappingWhitePoint]</h3>
  192. <div>
  193. Tone mapping white point. Default is *1*.
  194. </div>
  195. <h2>Methods</h2>
  196. <h3>[method:Object extensions.get]( [page:String extensionName] )</h3>
  197. <div>
  198. Used internally to check whether various extensions are supported and set parameters accordingly.<br /><br />
  199. </div>
  200. <h3>[method:WebGLRenderingContext getContext]()</h3>
  201. <div>
  202. Return the WebGL context.
  203. </div>
  204. <h3>[method:WebGLContextAttributes getContextAttributes]()</h3>
  205. <div>
  206. Returns an object that describes the attributes set on the WebGL context when it was created.
  207. </div>
  208. <h3>[method:Boolean supportsVertexTextures]()</h3>
  209. <div>
  210. Return a [page:Boolean] true if the context supports vertex textures.
  211. </div>
  212. <h3>[method:number getPixelRatio]()</h3>
  213. <div>Returns current device pixel ratio used.</div>
  214. <h3>[method:null setPixelRatio]( [page:number value] )</h3>
  215. <div>Sets device pixel ratio. This is usually used for HiDPI device to prevent bluring output canvas.</div>
  216. <h3>[method:Object getSize]()</h3>
  217. <div>Returns an object containing the width and height of the renderer's output canvas, in pixels.</div>
  218. <h3>[method:null setSize]( [page:Integer width], [page:Integer height], [page:Boolean updateStyle] )</h3>
  219. <div>Resizes the output canvas to (width, height) with device pixel ratio taken into account, and also sets the viewport to fit that size, starting in (0, 0). Setting updateStyle to true adds explicit pixel units to the output canvas style.</div>
  220. <h3>[method:null setViewport]( [page:Integer x], [page:Integer y], [page:Integer width], [page:Integer height] )</h3>
  221. <div>Sets the viewport to render from (x, y) to (x + width, y + height).</div>
  222. <h3>[method:null setScissor]( [page:Integer x], [page:Integer y], [page:Integer width], [page:Integer height] )</h3>
  223. <div>Sets the scissor area from (x, y) to (x + width, y + height).</div>
  224. <div>NOTE: The point (x, y) is the lower left corner of the area to be set for both of these methods. The area is defined from left to right in width but bottom to top in height. The sense of the vertical definition is opposite to the fill direction of an HTML canvas element.</div>
  225. <h3>[method:null setScissorTest]( [page:Boolean boolean] )</h3>
  226. <div>Enable or disable the scissor test. When this is enabled, only the pixels within the defined scissor area will be affected by further renderer actions.</div>
  227. <h3>[method:null setClearColor]( [page:Color color], [page:Float alpha] )</h3>
  228. <div>Sets the clear color and opacity.</div>
  229. <code>// Creates a renderer with red background
  230. var renderer = new THREE.WebGLRenderer();
  231. renderer.setSize( 200, 100 );
  232. renderer.setClearColor( 0xff0000 );
  233. </code>
  234. <h3>[method:Color getClearColor]()</h3>
  235. <div>Returns a [page:Color THREE.Color] instance with the current clear color.</div>
  236. <h3>[method:Float getClearAlpha]()</h3>
  237. <div>Returns a [page:Float float] with the current clear alpha. Ranges from 0 to 1.</div>
  238. <h3>[method:null clear]( [page:Boolean color], [page:Boolean depth], [page:Boolean stencil] )</h3>
  239. <div>Tells the renderer to clear its color, depth or stencil drawing buffer(s). This method initializes the color buffer to the current clear color value.</div>
  240. <div>Arguments default to true.</div>
  241. <h3>[method:null renderBufferImmediate]( [page:Object3D object], [page:shaderprogram program], [page:Material shading] )</h3>
  242. <div>object — an instance of [page:Object3D]<br />
  243. program — an instance of shaderProgram<br />
  244. shading — an instance of Material<br />
  245. </div>
  246. <div>
  247. Render an immediate buffer. Gets called by renderImmediateObject.
  248. </div>
  249. <h3>[method:null renderBufferDirect]( [page:Camera camera], [page:Array lights], [page:Fog fog], [page:Material material], [page:Object geometryGroup], [page:Object3D object] )</h3>
  250. <div>Render a buffer geometry group using the camera and with the correct material.</div>
  251. <h3>[method:null renderBuffer]( [page:Camera camera], [page:Array lights], [page:Fog fog], [page:Material material], [page:Object geometryGroup], [page:Object3D object] )</h3>
  252. <div>Render a geometry group using the camera and with the correct material.</div>
  253. <h3>[method:null render]( [page:Scene scene], [page:Camera camera], [page:WebGLRenderTarget renderTarget], [page:Boolean forceClear] )</h3>
  254. <div>Render a scene using a camera.</div>
  255. <div>The render is done to the renderTarget (if specified) or to the canvas as usual.</div>
  256. <div>If forceClear is true, the depth, stencil and color buffers will be cleared before rendering even if the renderer's autoClear property is false.</div>
  257. <div>Even with forceClear set to true you can prevent certain buffers being cleared by setting either the .autoClearColor, .autoClearStencil or .autoClearDepth properties to false.</div>
  258. <h3>[method:null readRenderTargetPixels]( [page:WebGLRenderTarget renderTarget], [page:Float x], [page:Float y], [page:Float width], [page:Float height], buffer )</h3>
  259. <div>Reads the pixel data from the renderTarget into the buffer you pass in. Buffer should be a Javascript Uint8Array instantiated with new Uint8Array( renderTargetWidth * renderTargetWidth * 4 ) to account for size and color information. This is a wrapper around gl.readPixels.</div>
  260. <h3>[method:null renderImmediateObject]( camera, lights, fog, material, object )</h3>
  261. <div>Renders an immediate Object using a camera.</div>
  262. <h3>[method:null setFaceCulling]( cullFace, frontFace )</h3>
  263. <div>
  264. See [page:WebGLRenderer WebGLRenderer constants] for all possible values for [page:String cullFace] and [page:String frontFace].<br />
  265. Used for setting the gl.frontFace and gl.cullFace states in the GPU, thus enabling/disabling face culling when rendering.<br />
  266. If cullFace is set to THREE.[page:String CullFaceNone], culling will be disabled.<br />
  267. </div>
  268. <h3>[method:null setTexture]( [page:Texture texture], [page:number slot] )</h3>
  269. <div>
  270. texture -- The [page:Texture texture] that needs to be set.<br />
  271. slot -- The number indicating which slot should be used by the texture.
  272. </div>
  273. <div>
  274. This method sets the correct texture to the correct slot for the wegl shader. The slot number can be found as a value of the uniform of the sampler.
  275. </div>
  276. <h3>[method:null setRenderTarget]( [page:WebGLRenderTarget renderTarget] )</h3>
  277. <div>
  278. renderTarget -- The [page:WebGLRenderTarget renderTarget] that needs to be activated (optional).<br />
  279. </div>
  280. <div>
  281. This method sets the active rendertarget. If the parameter is omitted the canvas is set as the active rendertarget.
  282. </div>
  283. <h3>[method:boolean supportsCompressedTextureS3TC]()</h3>
  284. <div>
  285. This method returns true if the webgl implementation supports compressed textures of the format S3TC.
  286. </div>
  287. <h3>[method:number getMaxAnisotropy]()</h3>
  288. <div>
  289. This returns the anisotropy level of the textures.
  290. </div>
  291. <h3>[method:string getPrecision]()</h3>
  292. <div>
  293. This gets the precision used by the shaders. It returns "highp","mediump" or "lowp".
  294. </div>
  295. <h3>[method:null setMaterialFaces]([page:Material material])</h3>
  296. <div>
  297. material -- The [page:Material material] with side that shouldn't be culled.
  298. </div>
  299. <div>
  300. This sets which side needs to be culled in the webgl renderer.
  301. </div>
  302. <h3>[method:boolean supportsStandardDerivatives]()</h3>
  303. <div>
  304. This method returns true if the webgl implementation supports standard derivatives.
  305. </div>
  306. <h3>[method:boolean supportsFloatTextures]()</h3>
  307. <div>
  308. This method returns true if the webgl implementation supports float textures.
  309. </div>
  310. <h3>[method:null clearTarget]([page:WebGLRenderTarget renderTarget], [page:boolean color], [page:boolean depth], [page:boolean stencil])</h3>
  311. <div>
  312. renderTarget -- The [page:WebGLRenderTarget renderTarget] that needs to be cleared.<br />
  313. color -- If set, then the color gets cleared. <br />
  314. depth -- If set, then the depth gets cleared. <br />
  315. stencil -- If set, then the stencil gets cleared.
  316. </div>
  317. <div>
  318. This method clears a rendertarget. To do this, it activates the rendertarget.
  319. </div>
  320. <h2>Source</h2>
  321. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  322. </body>
  323. </html>