Jump to content

Phaser filter on on webcam feed


Recommended Posts

Hi everyone,


I've been trying to get a phaser filter working on a sprite that draws the webcam feed using the webcam plugin from Phaser's plugin repository. However, the filter does not exactly seem to be doing anything at all.  To try and solve things, I've currently set the filter to use a second sprite/bitmapdata object, while the filter gets its texture from the original (webcam) sprite. This hasn't solved any issues, however. Could you please have a look at the code to see if I'm doing anything seriously stupid?



	var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });	function preload () {	    game.load.script('webcam', 'phaser-plugins/WebCam.js');	}	var webcam;	var bmd;	var filterbmd;	var sprite;	var filtersprite;	var filter;	function create () {	    webcam = game.plugins.add(Phaser.Plugin.Webcam);	    bmd = game.make.bitmapData(256, 256);	    sprite = bmd.addToWorld();	    filterbmd = game.make.bitmapData(256, 256);	    filtersprite = filterbmd.addToWorld(256,0);		var uniforms = {			uSampler: {type: 'sampler2D', value: sprite.texture}		};					var fragmentSrc = [	        'precision lowp float;',	        'varying vec2 vTextureCoord;',	        'varying vec4 vColor;',	        'uniform sampler2D uSampler;',	        'void main(void) {',	        '   gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor ;',	        '}'		];		filter = new Phaser.Filter(game, uniforms, fragmentSrc);    	filter.setResolution(256, 256);	    filtersprite.filters = [filter];	    webcam.start(256, 256, bmd.context);	}	var i =0;	function update () {		i++;		if(i>100){			filter.uniforms.uSampler = {type: 'sampler2D', value: sprite.texture};		}		filter.update();	}
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...