123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /**
- * @author alteredq / http://alteredqualia.com/
- *
- * parameters = {
- * defines: { "label" : "value" },
- * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
- *
- * fragmentShader: <string>,
- * vertexShader: <string>,
- *
- * shading: THREE.SmoothShading,
- * blending: THREE.NormalBlending,
- * depthTest: <bool>,
- * depthWrite: <bool>,
- *
- * wireframe: <boolean>,
- * wireframeLinewidth: <float>,
- *
- * lights: <bool>,
- *
- * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
- *
- * skinning: <bool>,
- * morphTargets: <bool>,
- * morphNormals: <bool>,
- *
- * fog: <bool>
- * }
- */
- THREE.ShaderMaterial = function ( parameters ) {
- THREE.Material.call( this );
- this.type = 'ShaderMaterial';
- this.defines = {};
- this.uniforms = {};
- this.attributes = [];
- this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
- this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
- this.shading = THREE.SmoothShading;
- this.linewidth = 1;
- this.wireframe = false;
- this.wireframeLinewidth = 1;
- this.fog = false; // set to use scene fog
- this.lights = false; // set to use scene lights
- this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
- this.skinning = false; // set to use skinning attribute streams
- this.morphTargets = false; // set to use morph targets
- this.morphNormals = false; // set to use morph normals
- this.derivatives = false; // set to use derivatives
- // When rendered geometry doesn't include these attributes but the material does,
- // use these default values in WebGL. This avoids errors when buffer data is missing.
- this.defaultAttributeValues = {
- 'color': [ 1, 1, 1 ],
- 'uv': [ 0, 0 ],
- 'uv2': [ 0, 0 ]
- };
- this.index0AttributeName = undefined;
- if ( parameters !== undefined ) {
- if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
- console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
- parameters.attributes = Object.keys( parameters.attributes );
- }
- this.setValues( parameters );
- }
- };
- THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
- THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
- THREE.ShaderMaterial.prototype.clone = function () {
- var material = new THREE.ShaderMaterial();
- return material.copy( this );
- };
- THREE.ShaderMaterial.prototype.copy = function ( source ) {
- THREE.Material.prototype.copy.call( this, source );
- this.fragmentShader = source.fragmentShader;
- this.vertexShader = source.vertexShader;
- this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
- this.attributes = source.attributes;
- this.defines = source.defines;
- this.shading = source.shading;
- this.wireframe = source.wireframe;
- this.wireframeLinewidth = source.wireframeLinewidth;
- this.fog = source.fog;
- this.lights = source.lights;
- this.vertexColors = source.vertexColors;
- this.skinning = source.skinning;
- this.morphTargets = source.morphTargets;
- this.morphNormals = source.morphNormals;
- return this;
- };
- THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
- var data = THREE.Material.prototype.toJSON.call( this, meta );
- data.uniforms = this.uniforms;
- data.attributes = this.attributes;
- data.vertexShader = this.vertexShader;
- data.fragmentShader = this.fragmentShader;
- return data;
- };
|