WebGLProgram.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. </div>
  81. <h3>Fragment shader:</h3>
  82. <div>
  83. <code>
  84. uniform mat4 viewMatrix;
  85. uniform vec3 cameraPosition;
  86. </code>
  87. </div>
  88. <h2>Constructor</h2>
  89. <h3>[name]( [param:WebGLRenderer renderer], [param:Object code], [param:Material material], [param:Object parameters] )</h3>
  90. <p>For parameters see [page:WebGLRenderer WebGLRenderer]</p>
  91. <h2>Properties</h2>
  92. <h3>[property:String id]</h3>
  93. <p></p>
  94. <h3>[property:String code]</h3>
  95. <p></p>
  96. <h3>[property:Integer usedTimes]</h3>
  97. <p></p>
  98. <h3>[property:Object program]</h3>
  99. <p></p>
  100. <h3>[property:WebGLShader vertexShader]</h3>
  101. <p></p>
  102. <h3>[property:WebGLShader fragmentShader]</h3>
  103. <p></p>
  104. <h2>Methods</h2>
  105. <h3>[method:Object getUniforms]()</h3>
  106. <p>
  107. Returns a name-value mapping of all active uniform locations.
  108. </p>
  109. <h3>[method:Object getAttributes]()</h3>
  110. <p>
  111. Returns a name-value mapping of all active vertex attribute locations.
  112. </p>
  113. <h2>Source</h2>
  114. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  115. </body>
  116. </html>