WebGLProgram.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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">发送到顶点着色器和片元着色器的GLSL程序的构造函数, 包含默认的变量(uniforms)和属性</p>
  12. <h2>内置的变量(uniforms)和属性</h2>
  13. <h3>顶点着色器(无条件的):</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 Geometry and BufferGeometry
  31. attribute vec3 position;
  32. attribute vec3 normal;
  33. attribute vec2 uv;
  34. </code>
  35. <p>
  36. 注意,可以通过以下方式计算顶点着色器中顶点的位置:
  37. <code>
  38. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  39. </code>
  40. 或者也可以这样:
  41. <code>
  42. gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );
  43. </code>
  44. </p>
  45. </div>
  46. <h3>顶点着色器(有条件的):</h3>
  47. <div>
  48. <code>
  49. #ifdef USE_COLOR
  50. #ifdef USE_VERTEX_ALPHA
  51. // vertex color attribute with alpha channel
  52. attribute vec4 color;
  53. #else
  54. // vertex color attribute without alpha channel
  55. attribute vec3 color;
  56. #endif
  57. #endif
  58. </code>
  59. <code>
  60. #ifdef USE_MORPHTARGETS
  61. attribute vec3 morphTarget0;
  62. attribute vec3 morphTarget1;
  63. attribute vec3 morphTarget2;
  64. attribute vec3 morphTarget3;
  65. #ifdef USE_MORPHNORMALS
  66. attribute vec3 morphNormal0;
  67. attribute vec3 morphNormal1;
  68. attribute vec3 morphNormal2;
  69. attribute vec3 morphNormal3;
  70. #else
  71. attribute vec3 morphTarget4;
  72. attribute vec3 morphTarget5;
  73. attribute vec3 morphTarget6;
  74. attribute vec3 morphTarget7;
  75. #endif
  76. #endif
  77. </code>
  78. <code>
  79. #ifdef USE_SKINNING
  80. attribute vec4 skinIndex;
  81. attribute vec4 skinWeight;
  82. #endif
  83. </code>
  84. </div>
  85. <h3>片元着色器:</h3>
  86. <div>
  87. <code>
  88. uniform mat4 viewMatrix;
  89. uniform vec3 cameraPosition;
  90. </code>
  91. </div>
  92. <h2>构造器</h2>
  93. <h3>[name]( [param:WebGLRenderer renderer], [param:String cacheKey], [param:Object parameters] )</h3>
  94. <p>参数详见[page:WebGLRenderer WebGLRenderer].</p>
  95. <h2>属性</h2>
  96. <h3>[property:String name]</h3>
  97. <p>The name of the respective shader program.</p>
  98. <h3>[property:String id]</h3>
  99. <p>The identifier of this instance.</p>
  100. <h3>[property:String cacheKey]</h3>
  101. <p>This key enables the reusability of a single [name] for different materials.</p>
  102. <h3>[property:Integer usedTimes]</h3>
  103. <p>How many times this instance is used for rendering render items.</p>
  104. <h3>[property:Object program]</h3>
  105. <p>The actual shader program.</p>
  106. <h3>[property:WebGLShader vertexShader]</h3>
  107. <p>An instance of [page:WebGLShader] representing the vertex shader.</p>
  108. <h3>[property:WebGLShader fragmentShader]</h3>
  109. <p>An instance of [page:WebGLShader] representing the frament shader.</p>
  110. <h2>方法</h2>
  111. <h3>[method:Object getUniforms]()</h3>
  112. <p>
  113. 返回所有活动态的变量(uniform)位置的name-value映射
  114. </p>
  115. <h3>[method:Object getAttributes]()</h3>
  116. <p>
  117. 返回所有活动态的顶点属性位置的name-value映射
  118. </p>
  119. <h3>[method:null destroy]()</h3>
  120. <p>
  121. Destroys an instance of [name].
  122. </p>
  123. <h2>源码</h2>
  124. <p>
  125. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  126. </p>
  127. </body>
  128. </html>