2
0

WebGLProgram.html 4.0 KB

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