/** * @author alteredq / http://alteredqualia.com/ * * parameters = { * defines: { "label" : "value" }, * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } }, * * fragmentShader: , * vertexShader: , * * shading: THREE.SmoothShading, * blending: THREE.NormalBlending, * depthTest: , * depthWrite: , * * wireframe: , * wireframeLinewidth: , * * lights: , * * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors, * * skinning: , * morphTargets: , * morphNormals: , * * fog: * } */ THREE.ShaderMaterial = function ( parameters ) { THREE.Material.call( this ); this.type = 'ShaderMaterial'; this.defines = {}; this.uniforms = {}; 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.extensions = { derivatives: false, // set to use derivatives fragDepth: false, // set to use fragment depth values drawBuffers: false, // set to use draw buffers shaderTextureLOD: false // set to use shader texture LOD }; // 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 ) { console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' ); } this.setValues( parameters ); } }; THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype ); THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial; 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; this.extensions = source.extensions; 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; }; Object.defineProperties( THREE.ShaderMaterial.prototype, { derivatives: { get: function () { return this.extensions.derivatives; }, set: function ( value ) { console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' ); this.extensions.derivatives = value; } } } );