2
0

WebGLProgram.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!DOCTYPE html>
  2. <html lang="it">
  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">Costruttore per il programma GLSL inviato agli shader vertex e fragment, comprese le uniformi e gli attributi.</p>
  12. <h2>Uniformi e attributi incorporati</h2>
  13. <h3>Vertex shader (incondizionato):</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. // = trasposizione inversa di modelViewMatrix
  25. uniform mat3 normalMatrix;
  26. // = posizione della telecamera nello spazio world
  27. uniform vec3 cameraPosition;
  28. </code>
  29. <code>
  30. // attributi di vertice predefiniti forniti da Geometry e BufferGeometry
  31. attribute vec3 position;
  32. attribute vec3 normal;
  33. attribute vec2 uv;
  34. </code>
  35. <p>
  36. Si noti che è possibile quindi calcolare la posizione di un vertice nel vertex shader con:
  37. <code>
  38. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  39. </code>
  40. o in alternativa
  41. <code>
  42. gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );
  43. </code>
  44. </p>
  45. </div>
  46. <h3>Vertex shader (condizionale):</h3>
  47. <div>
  48. <code>
  49. #if defined( USE_COLOR_ALPHA )
  50. // attributo del colore del vertice con alfa
  51. attribute vec4 color;
  52. #elif defined( USE_COLOR )
  53. // attributo del colore del vertice
  54. attribute vec3 color;
  55. #endif
  56. </code>
  57. <code>
  58. #ifdef USE_MORPHTARGETS
  59. attribute vec3 morphTarget0;
  60. attribute vec3 morphTarget1;
  61. attribute vec3 morphTarget2;
  62. attribute vec3 morphTarget3;
  63. #ifdef USE_MORPHNORMALS
  64. attribute vec3 morphNormal0;
  65. attribute vec3 morphNormal1;
  66. attribute vec3 morphNormal2;
  67. attribute vec3 morphNormal3;
  68. #else
  69. attribute vec3 morphTarget4;
  70. attribute vec3 morphTarget5;
  71. attribute vec3 morphTarget6;
  72. attribute vec3 morphTarget7;
  73. #endif
  74. #endif
  75. </code>
  76. <code>
  77. #ifdef USE_SKINNING
  78. attribute vec4 skinIndex;
  79. attribute vec4 skinWeight;
  80. #endif
  81. </code>
  82. <code>
  83. #ifdef USE_INSTANCING
  84. // Si noti che modelViewMatrix non è impostato durante il rendering di un modello istanziato,
  85. // ma può essere calcolato da viewMatrix * modelMatrix.
  86. //
  87. // Utilizzo di base:
  88. // gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
  89. attribute mat4 instanceMatrix;
  90. #endif
  91. </code>
  92. </div>
  93. <h3>Fragment shader:</h3>
  94. <div>
  95. <code>
  96. uniform mat4 viewMatrix;
  97. uniform vec3 cameraPosition;
  98. </code>
  99. </div>
  100. <h2>Costruttore</h2>
  101. <h3>[name]( [param:WebGLRenderer renderer], [param:String cacheKey], [param:Object parameters] )</h3>
  102. <p>Per i parametri vedere [page:WebGLRenderer WebGLRenderer].</p>
  103. <h2>Proprietà</h2>
  104. <h3>[property:String name]</h3>
  105. <p>Il nome del rispettivo programma di shader.</p>
  106. <h3>[property:String id]</h3>
  107. <p>L'identificativo di questa istanza.</p>
  108. <h3>[property:String cacheKey]</h3>
  109. <p>Questa chiave consente la riutilizzabilità di un unico [name] per diversi materiali.</p>
  110. <h3>[property:Integer usedTimes]</h3>
  111. <p>Quante volte questa istanza viene utilizzata per il rendering di elementi di rendering.</p>
  112. <h3>[property:Object program]</h3>
  113. <p>L'attuale programma di shader.</p>
  114. <h3>[property:WebGLShader vertexShader]</h3>
  115. <p>Il vertex shader.</p>
  116. <h3>[property:WebGLShader fragmentShader]</h3>
  117. <p>Il fragment shader.</p>
  118. <h2>Metodi</h2>
  119. <h3>[method:Object getUniforms]()</h3>
  120. <p>
  121. Restituisce una mappa nome-valore di tutte le posizioni uniformi attive.
  122. </p>
  123. <h3>[method:Object getAttributes]()</h3>
  124. <p>
  125. Restituisce una mappa nome-valore di tutte le posizioni degli attributi dei vertici attivi.
  126. </p>
  127. <h3>[method:undefined destroy]()</h3>
  128. <p>
  129. Distrugge un'istanza di [name].
  130. </p>
  131. <h2>Source</h2>
  132. <p>
  133. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  134. </p>
  135. </body>
  136. </html>