WebGLProgram.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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">Constructor for the GLSL program sent to vertex and fragment shaders, including default uniforms and attributes.</div>
  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. attribute vec2 uv2;
  36. </code>
  37. <p>
  38. Note that you can therefore calculate the position of a vertex in the vertex shader by:
  39. <code>
  40. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  41. </code>
  42. or alternatively
  43. <code>
  44. gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );
  45. </code>
  46. </p>
  47. </div>
  48. <h3>Vertex shader (conditional):</h3>
  49. <div>
  50. <code>
  51. #ifdef USE_COLOR
  52. // vertex color attribute
  53. attribute vec3 color;
  54. #endif
  55. </code>
  56. <code>
  57. #ifdef USE_MORPHTARGETS
  58. attribute vec3 morphTarget0;
  59. attribute vec3 morphTarget1;
  60. attribute vec3 morphTarget2;
  61. attribute vec3 morphTarget3;
  62. #ifdef USE_MORPHNORMALS
  63. attribute vec3 morphNormal0;
  64. attribute vec3 morphNormal1;
  65. attribute vec3 morphNormal2;
  66. attribute vec3 morphNormal3;
  67. #else
  68. attribute vec3 morphTarget4;
  69. attribute vec3 morphTarget5;
  70. attribute vec3 morphTarget6;
  71. attribute vec3 morphTarget7;
  72. #endif
  73. #endif
  74. </code>
  75. <code>
  76. #ifdef USE_SKINNING
  77. attribute vec4 skinIndex;
  78. attribute vec4 skinWeight;
  79. #endif
  80. </code>
  81. </div>
  82. <h3>Fragment shader:</h3>
  83. <div>
  84. <code>
  85. uniform mat4 viewMatrix;
  86. uniform vec3 cameraPosition;
  87. </code>
  88. </div>
  89. <h2>Constructor</h2>
  90. <h3>[name]( [page:WebGLRenderer renderer], [page:Object code], [page:Material material], [page:Object parameters] )</h3>
  91. <div>For parameters see [page:WebGLRenderer WebGLRenderer]</div>
  92. <h2>Properties</h2>
  93. <h3>[property:String id]</h3>
  94. <div></div>
  95. <h3>[property:String code]</h3>
  96. <div></div>
  97. <h3>[property:Integer usedTimes]</h3>
  98. <div></div>
  99. <h3>[property:Object program]</h3>
  100. <div></div>
  101. <h3>[property:WebGLShader vertexShader]</h3>
  102. <div></div>
  103. <h3>[property:WebGLShader fragmentShader]</h3>
  104. <div></div>
  105. <h2>Methods</h2>
  106. <h3>[method:Object getUniforms]()</h3>
  107. <div>
  108. Returns a name-value mapping of all active uniform locations.
  109. </div>
  110. <h3>[method:Object getAttributes]()</h3>
  111. <div>
  112. Returns a name-value mapping of all active vertex attribute locations.
  113. </div>
  114. <h2>Source</h2>
  115. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  116. </body>
  117. </html>