RPG Maker Forums

Hello I have a problem with not working custom (made by me), I search for mistakes really hard but can't find solution what i get is few lines of errors which sounds like 

Cannot read property 'bind' of undefined
 which is called when trying to bind texture method from uniform which is by the way null, but from what i see in examples from pixi there weren't any example with setting example texture.


here is my code of filter class

Code:
	function ChangeColorPallete(usedColors, newColors, epsilon){
		var vertexSrc = [
			'attribute vec2 aVertexPosition;',
			'attribute vec2 aTextureCoord;',
			'uniform mat3 projectionMatrix;',
			'varying vec2 vTextureCoord;',

			'void main(void){',
			'	gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);',
			'	vTextureCoord = aTextureCoord;',
			'}'
    	].join('\n');

     	var fragmentSrc = [
			 'varying vec2 vTextureCoord;',
			 'uniform sampler2D texture;',
			 'uniform vec3 originalColor[10];',
			 'uniform vec3 newColor[10];',
			 'uniform float epsilon;',

			 'void main(void) {',
			 '	vec4 currentColor = texture2D(texture, vTextureCoord);',
			 '	if (currentColor.r - originalColor[0].r < epsilon && currentColor.g - originalColor[0].g < epsilon && currentColor.b - originalColor[0].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[0].r, newColor[0].g, newColor[0].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[1].r < epsilon && currentColor.g - originalColor[1].g < epsilon && currentColor.b - originalColor[1].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[1].r, newColor[1].g, newColor[1].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[2].r < epsilon && currentColor.g - originalColor[2].g < epsilon && currentColor.b - originalColor[2].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[2].r, newColor[2].g, newColor[2].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[3].r < epsilon && currentColor.g - originalColor[3].g < epsilon && currentColor.b - originalColor[3].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[3].r, newColor[3].g, newColor[3].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[4].r < epsilon && currentColor.g - originalColor[4].g < epsilon && currentColor.b - originalColor[4].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[4].r, newColor[4].g, newColor[4].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[5].r < epsilon && currentColor.g - originalColor[5].g < epsilon && currentColor.b - originalColor[5].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[5].r, newColor[5].g, newColor[5].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[6].r < epsilon && currentColor.g - originalColor[6].g < epsilon && currentColor.b - originalColor[6].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[6].r, newColor[6].g, newColor[6].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[7].r < epsilon && currentColor.g - originalColor[7].g < epsilon && currentColor.b - originalColor[7].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[7].r, newColor[7].g, newColor[7].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[8].r < epsilon && currentColor.g - originalColor[8].g < epsilon && currentColor.b - originalColor[8].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[8].r, newColor[8].g, newColor[8].b, currentColor.a);',
			 ' 	else if (currentColor.r - originalColor[9].r < epsilon && currentColor.g - originalColor[9].g < epsilon && currentColor.b - originalColor[9].b < epsilon)',
			 '		gl_FragColor = vec4(newColor[9].r, newColor[9].g, newColor[9].b, currentColor.a);',
			 '}'
     	].join('\n');
		PIXI.Filter.call(this, vertexSrc, fragmentSrc);

		this.uniforms.epsilon = epsilon;
		console.log(this);
		this.uniforms.originalColor = usedColors;
		this.uniforms.newColor = newColors;
	}

	ChangeColorPallete.prototype = Object.create(PIXI.Filter.prototype);
	ChangeColorPallete.prototype.constructor = ChangeColorPallete;

	Object.defineProperty(ChangeColorPallete.prototype, 'epsilon', {
  		set: function (value) {
    		this.uniforms.epsilon = value;
			console.log(value);
 		}
	});

	Object.defineProperty(ChangeColorPallete.prototype, 'originalColor', {
  		set: function (value) {
			var colors = [10]  
			var emptyValue = new Float32Array([0, 0, 0])
			for (var i = 0; i < 10; i++){
				var nvalue = new Float32Array([1, 1, 1]);
				if (value.length > i)
					nvalue = value[i];
				colors[i] = {type: "v3v", value:[{x:nvalue[0], y: nvalue[1], z: nvalue[2]}]};
			}  
			console.log(this.uniforms);
    		this.uniforms.originalColor = colors;
			
  		}
	});

		Object.defineProperty(ChangeColorPallete.prototype, 'newColor', {
  			set: function (value) {
				  console.log(value);
    			var colors = [10]  
			var emptyValue = new Float32Array([0, 0, 0])
			for (var i = 0; i < 10; i++){
				var nvalue = new Float32Array([1, 1, 1]);
				if (value.length > i)
					nvalue = value[i];
				colors[i] = {type: "v3v", value:[{x:nvalue[0], y: nvalue[1], z: nvalue[2]}]};
			}  
			console.log(this.uniforms);
    		this.uniforms.newColor = colors;
  			}
	});

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,050
Messages
1,018,548
Members
137,835
Latest member
yetisteven
Top