WebGLProgram.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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">Constructor for the GLSL program sent to vertex and fragment shaders, including default uniforms and attributes.</p>
  13. <h2>Built-in uniforms and attributes</h2>
  14. <h3>Vertex shader (unconditional):</h3>
  15. <div>
  16. <code>
  17. // = object.matrixWorld
  18. uniform mat4 modelMatrix;
  19. // = camera.matrixWorldInverse * object.matrixWorld
  20. uniform mat4 modelViewMatrix;
  21. // = camera.projectionMatrix
  22. uniform mat4 projectionMatrix;
  23. // = camera.matrixWorldInverse
  24. uniform mat4 viewMatrix;
  25. // = inverse transpose of modelViewMatrix
  26. uniform mat3 normalMatrix;
  27. // = camera position in world space
  28. uniform vec3 cameraPosition;
  29. </code>
  30. <code>
  31. // default vertex attributes provided by Geometry and BufferGeometry
  32. attribute vec3 position;
  33. attribute vec3 normal;
  34. attribute vec2 uv;
  35. </code>
  36. <p>
  37. Note that you can therefore calculate the position of a vertex in the vertex shader by:
  38. <code>
  39. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  40. </code>
  41. or alternatively
  42. <code>
  43. gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );
  44. </code>
  45. </p>
  46. </div>
  47. <h3>Vertex shader (conditional):</h3>
  48. <div>
  49. <code>
  50. #ifdef USE_COLOR
  51. // vertex color attribute
  52. attribute vec3 color;
  53. #endif
  54. </code>
  55. <code>
  56. #ifdef USE_MORPHTARGETS
  57. attribute vec3 morphTarget0;
  58. attribute vec3 morphTarget1;
  59. attribute vec3 morphTarget2;
  60. attribute vec3 morphTarget3;
  61. #ifdef USE_MORPHNORMALS
  62. attribute vec3 morphNormal0;
  63. attribute vec3 morphNormal1;
  64. attribute vec3 morphNormal2;
  65. attribute vec3 morphNormal3;
  66. #else
  67. attribute vec3 morphTarget4;
  68. attribute vec3 morphTarget5;
  69. attribute vec3 morphTarget6;
  70. attribute vec3 morphTarget7;
  71. #endif
  72. #endif
  73. </code>
  74. <code>
  75. #ifdef USE_SKINNING
  76. attribute vec4 skinIndex;
  77. attribute vec4 skinWeight;
  78. #endif
  79. </code>
  80. <code>
  81. #ifdef USE_INSTANCING
  82. // Note that modelViewMatrix is not set when rendering an instanced model,
  83. // but can be calculated from viewMatrix * modelMatrix.
  84. //
  85. // Basic Usage:
  86. // gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
  87. attribute mat4 instanceMatrix;
  88. #endif
  89. </code>
  90. </div>
  91. <h3>Fragment shader:</h3>
  92. <div>
  93. <code>
  94. uniform mat4 viewMatrix;
  95. uniform vec3 cameraPosition;
  96. </code>
  97. </div>
  98. <h2>Constructor</h2>
  99. <h3>[name]( [param:WebGLRenderer renderer], [param:String cacheKey], [param:Object parameters] )</h3>
  100. <p>For parameters see [page:WebGLRenderer WebGLRenderer].</p>
  101. <h2>Properties</h2>
  102. <h3>[property:String name]</h3>
  103. <p>The name of the respective shader program.</p>
  104. <h3>[property:String id]</h3>
  105. <p>The identifier of this instance.</p>
  106. <h3>[property:String cacheKey]</h3>
  107. <p>This key enables the reusability of a single [name] for different materials.</p>
  108. <h3>[property:Integer usedTimes]</h3>
  109. <p>How many times this instance is used for rendering render items.</p>
  110. <h3>[property:Object program]</h3>
  111. <p>The actual shader program.</p>
  112. <h3>[property:WebGLShader vertexShader]</h3>
  113. <p>An instance of [page:WebGLShader] representing the vertex shader.</p>
  114. <h3>[property:WebGLShader fragmentShader]</h3>
  115. <p>An instance of [page:WebGLShader] representing the frament shader.</p>
  116. <h2>Methods</h2>
  117. <h3>[method:Object getUniforms]()</h3>
  118. <p>
  119. Returns a name-value mapping of all active uniform locations.
  120. </p>
  121. <h3>[method:Object getAttributes]()</h3>
  122. <p>
  123. Returns a name-value mapping of all active vertex attribute locations.
  124. </p>
  125. <h3>[method:null destroy]()</h3>
  126. <p>
  127. Destroys an instance of [name].
  128. </p>
  129. <h2>Source</h2>
  130. <p>
  131. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  132. </p>
  133. </body>
  134. </html>