mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-18 06:09:30 -07:00
Initial commit
This commit is contained in:
54
js/HorizontalColorationPass.js
Normal file
54
js/HorizontalColorationPass.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @author rezmason
|
||||
*/
|
||||
|
||||
THREE.HorizontalColorationPass = function (colors) {
|
||||
const values = new Uint8Array([].concat(...colors.map(color => color.toArray().map(component => Math.floor(component * 255)))));
|
||||
|
||||
this.dataTexture = new THREE.DataTexture(
|
||||
values,
|
||||
values.length / 3,
|
||||
1,
|
||||
THREE.RGBFormat,
|
||||
THREE.UnsignedByteType,
|
||||
THREE.UVMapping);
|
||||
this.dataTexture.magFilter = THREE.LinearFilter;
|
||||
this.dataTexture.needsUpdate = true;
|
||||
|
||||
this.shader = {
|
||||
uniforms: {
|
||||
tDiffuse: { value: null },
|
||||
tColorData: { value: this.dataTexture },
|
||||
},
|
||||
|
||||
vertexShader: `
|
||||
varying vec2 vUv;
|
||||
void main() {
|
||||
vUv = uv;
|
||||
gl_Position = vec4( position, 1.0 );
|
||||
}
|
||||
`,
|
||||
|
||||
fragmentShader: `
|
||||
uniform sampler2D tDiffuse;
|
||||
uniform sampler2D tColorData;
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
float value = texture2D(tDiffuse, vUv).r;
|
||||
vec3 value2 = texture2D(tColorData, vUv).rgb;
|
||||
gl_FragColor = vec4(value2 * value, 1.0);
|
||||
}
|
||||
`
|
||||
};
|
||||
|
||||
THREE.ShaderPass.call(this, this.shader);
|
||||
};
|
||||
|
||||
THREE.HorizontalColorationPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
|
||||
constructor: THREE.HorizontalColorationPass,
|
||||
render: function() {
|
||||
this.uniforms[ "tColorData" ].value = this.dataTexture;
|
||||
THREE.ShaderPass.prototype.render.call(this, ...arguments);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user