Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. //Set x,y position coordinates to be used to extract data from one plane of our data cube
  2. //remember, z we handle as a 1 layer of our cube which is composed of a stack of x-y planes.
  3. const oneLayerVertices = new Float32Array(size * size * 2);
  4. count = 0;
  5. for (var j = 0; j < (size); j++) {
  6. for (var i = 0; i < (size); i++) {
  7. oneLayerVertices[count] = i;
  8. count++;
  9.  
  10. oneLayerVertices[count] = j;
  11. count++;
  12.  
  13. //oneLayerVertices[count] = 0;
  14. //count++;
  15.  
  16. //oneLayerVertices[count] = 0;
  17. //count++;
  18.  
  19. }
  20. }
  21.  
  22. const bufferInfo = twgl.createBufferInfoFromArrays(gl, {
  23. position: {
  24. numComponents: 2,
  25. data: oneLayerVertices,
  26. },
  27. });
  28.  
  29. gl.useProgram(computeProgramInfo.program);
  30. twgl.setBuffersAndAttributes(gl, computeProgramInfo, bufferInfo);
  31.  
  32. gl.viewport(0, 0, size, size); //remember size = 4
  33.  
  34. outFramebuffers.forEach((fb, ndx) => {
  35. gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
  36. gl.drawBuffers([
  37. gl.COLOR_ATTACHMENT0,
  38. gl.COLOR_ATTACHMENT1,
  39. gl.COLOR_ATTACHMENT2,
  40. gl.COLOR_ATTACHMENT3
  41. ]);
  42.  
  43. const baseLayerTexCoord = (ndx * numLayersPerFramebuffer);
  44. console.log("My baseLayerTexCoord is "+baseLayerTexCoord);
  45. twgl.setUniforms(computeProgramInfo, {
  46. baseLayerTexCoord,
  47. u_kernel: [
  48. 0, 0, 0,
  49. 0, 0, 0,
  50. 0, 0, 0,
  51.  
  52. 0, 0, 1,
  53. 0, 0, 0,
  54. 0, 0, 0,
  55.  
  56. 0, 0, 0,
  57. 0, 0, 0,
  58. 0, 0, 0,
  59. ],
  60. u_position: inPos,
  61. u_velocity: inVel,
  62. loopCounter: loopCounter,
  63.  
  64. numLayersPerFramebuffer: numLayersPerFramebuffer
  65. });
  66. gl.drawArrays(gl.POINTS, 0, (16));
  67. });
  68.  
  69. const compute_vs = `#version 300 es
  70. precision highp float;
  71. in vec4 position;
  72. void main() {
  73. gl_Position = position;
  74. }
  75. `;
  76.  
  77. const compute_fs = `#version 300 es
  78. precision highp float;
  79.  
  80. out vec4 ourOutput[4];
  81.  
  82. void main() {
  83. ourOutput[0] = vec4(0,1,0,1);
  84. ourOutput[1] = vec4(0,1,0,1);
  85. ourOutput[2] = vec4(0,1,0,1);
  86. ourOutput[3] = vec4(0,1,0,1);
  87. }
  88. `;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement