content/hifi-content/dave/walk-tools/walkTools/libraries/three.js/materials/ShaderMaterial.js
2022-02-13 22:49:05 +01:00

111 lines
2.7 KiB
JavaScript

/**
* @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 = null;
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
// 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;
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();
THREE.Material.prototype.clone.call( this, material );
material.fragmentShader = this.fragmentShader;
material.vertexShader = this.vertexShader;
material.uniforms = THREE.UniformsUtils.clone( this.uniforms );
material.attributes = this.attributes;
material.defines = this.defines;
material.shading = this.shading;
material.wireframe = this.wireframe;
material.wireframeLinewidth = this.wireframeLinewidth;
material.fog = this.fog;
material.lights = this.lights;
material.vertexColors = this.vertexColors;
material.skinning = this.skinning;
material.morphTargets = this.morphTargets;
material.morphNormals = this.morphNormals;
return material;
};