Jump to content

flickering neon light effect


Van Halen
 Share

Recommended Posts

Hi,

For my website i created a neon effect with PixiJS v4 and i'm not happy with the results i was wondering if anyone could improve upon or has a better idea how create a neon effect which works across multiple desktop/mobile devices.

The neon light is a simple transparent png image overlaid on top of static background image. It works for time been 'good enough' for desktop browsers, but i had to disabled it for iPad, etc. because of the slow performance combined with rain (pixi-particles) and fog (custom particle effect).

Live version:
http://5701.nl

Code:

//PIXI
var PIXI;

var Container = PIXI.Container,
	autoDetectRenderer = PIXI.autoDetectRenderer,
	loader = PIXI.loader,
	resources = PIXI.loader.resources,
	Sprite = PIXI.Sprite,
	ParticleContainer = PIXI.particles.ParticleContainer,
	extras = PIXI.extras;

var street = new Container();
var weatherType = new Container();

var renderer = new autoDetectRenderer(3600, 720, {antialias: false, transparent: true, resolution: 1});

document.getElementById('street').appendChild(renderer.view);

//View
renderer.view.style.display = 'block';
renderer.autoResize = true;

//Variables
var neonSign,
neonFilter,
colorMatrix,
count = 1;

function animateScene() {

	//Animate neonSign
	neonSign.alpha = 0.1;
	count += 2;
	var bright = 2 + Math.sin(count);
	neonFilter.brightness(bright, false);
	
	requestAnimationFrame(animateScene);

	renderer.render(street);

}

function setup() {

	//Setup neonSign

	neonSign = new Sprite(resources['images/one-stop-copy-shop_glow.png'].texture);
	neonSign.width = 1200;
	neonSign.height = 300;
	neonSign.position.set(1200,0);		

	colorMatrix = [
		1, 0, 0, 0,
		0, 1, 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1
	];

	neonFilter = new PIXI.filters.ColorMatrixFilter();
	neonFilter.matrix = colorMatrix;
	neonSign.filters = [neonFilter];

	//Add neonSign		
	street.addChild(neonSign);

	//Start
	animateScene();

}

//Setup
loader
	.add('images/one-stop-copy-shop_glow.png')
	.load(setup);

 

screenshot.png

Link to comment
Share on other sites

You could achieve much the same effect without using filters. Just have a png of the glow state layered in front of the main text image. Then on a short randomised interval of milliseconds set it to a random alpha, possibly tweening between the alpha values. That would be a much less expensive operation and should only look quite subtly different.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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