Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <script type="x-shader/x-vertex" id="vertexshader">
  2.  
  3. varying vec3 vColor;
  4. attribute vec3 customColor;
  5.  
  6. void main() {
  7. vColor = customColor;
  8. }
  9.  
  10. </script>
  11.  
  12. <script type="x-shader/x-fragment" id="fragmentshader">
  13.  
  14. varying vec3 vColor;
  15.  
  16. void main() {
  17. gl_FragColor = vec4(vColor, 1.0 );
  18. }
  19.  
  20. </script>
  21.  
  22. var customColors = new Float32Array(_count*2*3); // 2 vertex by segment *length(RGB)
  23. for (var i = 0; i < customColors.length/3; i++) {
  24. var ratio = i / (customColors.length/3.0);
  25. customColors[(i*3)] = ratio;
  26. customColors[(i*3)+1] = ratio;
  27. customColors[(i*3)+2] = ratio;
  28. };
  29.  
  30. geo.addAttribute('customColor' , new THREE.BufferAttribute(customColors,3));
  31.  
  32.  
  33. var drawCount = _count * 2;
  34. geo.setDrawRange( 0, drawCount );
  35.  
  36.  
  37. var uniforms = {
  38. opacity : 0.5
  39.  
  40. };
  41.  
  42.  
  43. var customMaterial = new THREE.ShaderMaterial( {
  44. uniforms : uniforms,
  45. vertexShader : document.getElementById( 'vertexshader' ).textContent,
  46. fragmentShader : document.getElementById( 'fragmentshader' ).textContent,
  47. }
  48. );
  49. var lines = new THREE.LineSegments(geo, customMaterial);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement