ShaderMaterial.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. *
  4. * parameters = {
  5. * defines: { "label" : "value" },
  6. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  7. *
  8. * fragmentShader: <string>,
  9. * vertexShader: <string>,
  10. *
  11. * shading: THREE.SmoothShading,
  12. * blending: THREE.NormalBlending,
  13. * depthTest: <bool>,
  14. * depthWrite: <bool>,
  15. *
  16. * wireframe: <boolean>,
  17. * wireframeLinewidth: <float>,
  18. *
  19. * lights: <bool>,
  20. *
  21. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  22. *
  23. * skinning: <bool>,
  24. * morphTargets: <bool>,
  25. * morphNormals: <bool>,
  26. *
  27. * fog: <bool>
  28. * }
  29. */
  30. THREE.ShaderMaterial = function ( parameters ) {
  31. THREE.Material.call( this );
  32. this.type = 'ShaderMaterial';
  33. this.defines = {};
  34. this.uniforms = {};
  35. this.attributes = null;
  36. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  37. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  38. this.shading = THREE.SmoothShading;
  39. this.linewidth = 1;
  40. this.wireframe = false;
  41. this.wireframeLinewidth = 1;
  42. this.fog = false; // set to use scene fog
  43. this.lights = false; // set to use scene lights
  44. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  45. this.skinning = false; // set to use skinning attribute streams
  46. this.morphTargets = false; // set to use morph targets
  47. this.morphNormals = false; // set to use morph normals
  48. // When rendered geometry doesn't include these attributes but the material does,
  49. // use these default values in WebGL. This avoids errors when buffer data is missing.
  50. this.defaultAttributeValues = {
  51. 'color': [ 1, 1, 1 ],
  52. 'uv': [ 0, 0 ],
  53. 'uv2': [ 0, 0 ]
  54. };
  55. this.index0AttributeName = undefined;
  56. this.setValues( parameters );
  57. };
  58. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  59. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  60. THREE.ShaderMaterial.prototype.clone = function () {
  61. var material = new THREE.ShaderMaterial();
  62. THREE.Material.prototype.clone.call( this, material );
  63. material.fragmentShader = this.fragmentShader;
  64. material.vertexShader = this.vertexShader;
  65. material.uniforms = THREE.UniformsUtils.clone( this.uniforms );
  66. material.attributes = this.attributes;
  67. material.defines = this.defines;
  68. material.shading = this.shading;
  69. material.wireframe = this.wireframe;
  70. material.wireframeLinewidth = this.wireframeLinewidth;
  71. material.fog = this.fog;
  72. material.lights = this.lights;
  73. material.vertexColors = this.vertexColors;
  74. material.skinning = this.skinning;
  75. material.morphTargets = this.morphTargets;
  76. material.morphNormals = this.morphNormals;
  77. return material;
  78. };
粤ICP备19079148号