Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-09-2006, 03:13 AM   #11
pet-theory
Registered User
 
Join Date: May 2006
Posts: 25
Default got it

I made a mistake regarding the alpha channel:

the DisplacementMapFilter looks at the pixel values of its active channel and DOES NOT multiply that value by the alpha. so, if you have a gradient going from full alpha to no alpha, the filter does not care--all it cares about are the pre-multiplied pixel values

So if you try using a displacement map with a gradient that depends on alpha, it will ignore the gradient

After a couple of hackish workarounds (using merge and the ColorMatrixFilter), I hit upon a simple solution:

1) Make the initial map transparent before you create a gradient for it

1st=new Bitmap(w, h, true, 0x00FFFFFF)//true--so it is transparent

2) then create the texture in the new Bitmap and overlay a gradient however you like

3) Then create another bitmap that is opaque, and draw() the initial map

2d=new Bitmap (1st width, 1st height)//false is the preset
2d.draw(1st)

4) use this 2d bitmap as your displacement map in the filter

that's one way of feathering a displacement effect

FYI: after playing around with BitmapData for a couple of days, I find most stumpers are due to the weirdness of alpha, which is both co-equal to RGB in ARGB, and its multiplier

FYI: here's any easy way to superimpose a gradient on a texture map

textureBitmap.copyPixels(textureBitmap, new Rectangle(), new Point(), gradientBitmap);

the last parameter basically basic masks the textureBitmap while the textureBitmap copies itself

Last edited by pet-theory; 08-09-2006 at 02:24 PM.
pet-theory is offline   Reply With Quote
Old 08-09-2006, 03:47 AM   #12
csdstudio
Registered User
 
Join Date: Jun 2005
Posts: 145
Default

Quote:
Originally Posted by Incrue
cos f8 has changed it from a long time, Bitmapdata masks are not an AS3 new object.
Pet theory was asking how to do in AS3 some old f8 stuff
That's why I said I stand corrected.

How can Flash 8 be old, it's the most current version IDE and the player won't be used by most of the population for some time yet. Adoption of player upgrades is slower than people would like to admit, especially with the lies and deception aboard the internet fear train.
csdstudio is offline   Reply With Quote
Old 08-09-2006, 03:11 PM   #13
Incrue
the ever-living
 
Incrue's Avatar
 
Join Date: Jan 2006
Location: inside this plane
Posts: 113
Send a message via MSN to Incrue
Default

Quote:
Originally Posted by csdstudio
That's why I said I stand corrected.

How can Flash 8 be old, it's the most current version IDE and the player won't be used by most of the population for some time yet. Adoption of player upgrades is slower than people would like to admit, especially with the lies and deception aboard the internet fear train.
The latest is f9 alpha.Thats what pros should be learning.
Adoption of fplayer 8 was the fastest and bigger of all history of flash player
But this has nothing to do with the case
What pet theory was asking to other developers was how to make in f9 something already possible in f8, the goal was to learn this f9 thing,so for learning porpouses doesnt matter if the adoption of fp8 was slow or fast
This is all off topic, anyway.
Incrue is offline   Reply With Quote
Old 08-09-2006, 06:42 PM   #14
pet-theory
Registered User
 
Join Date: May 2006
Posts: 25
Default code for feathering displacement FX

Code:
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DisplacementMapFilter;
	import flash.geom.*;

	public class TestIt extends Sprite
	{
		//embed your own picture
		[Embed(source="images/desert.jpg")] internal var Desert:Class;
		internal var picture:Bitmap;
		internal var seenMap:Bitmap;
		internal var map:BitmapData;
		internal var opaqueMap:BitmapData;
		internal var gradient:Shape;
		internal var gradientBitmap:BitmapData;
		internal var ripple:DisplacementMapFilter;
		internal var fillType:String
		internal var colors:Array
		internal var alphas:Array
		internal var ratios:Array
		internal var matr:Matrix
		//
		public function TestIt()
		{	
                        //make a bitmap from the embedded picture, and show it
			picture=new Desert();
			addChild (picture);
			//create the gradient shape
  			fillType= GradientType.LINEAR;
  			colors= [0xFF0000, 0xFF00FF];
  			alphas = [0, 100];
  			ratios= [0, 150];
  			matr = new Matrix();
  			matr.createGradientBox(picture.width, picture.height, Math.PI/2);
  			gradient=new Shape()
  			gradient.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr);  
			gradient.graphics.drawRect(0, 0, picture.width, picture.height);
			//turn the gradient into a transparent bitmap
			gradientBitmap=new BitmapData(picture.width, picture.height, true, 0x00FFFFFF);
			gradientBitmap.draw(gradient)
			//prepare two displacement maps, one transparent, one not
			map=new BitmapData(picture.width, picture.height, true, 0x00FF000000);
			opaqueMap=new BitmapData(picture.width, picture.height)
			//this is the actual filter 
			ripple=new DisplacementMapFilter(opaqueMap, new Point(0,0), 1, 1, 30, 5, "clamp");
			//start the animation
			addEventListener(Event.ENTER_FRAME, makeRipple);*/
		}
		internal function makeRipple (evt:Event):void {
			/*
			//keep animating the displacement map using noise or perlin noise
			//map.perlinNoise(150, 30, 1, 50+Math.random()*10, false, false, 1, true);
			map.noise(Math.random()*100, 100, 200, 1, true);
			//keep re-applying the gradient mask to feather the noise
			//gradientBitmap "masks" the map
			map.copyPixels(map, new Rectangle(0, 0, picture.width, picture.height), new Point (0, 0), gradientBitmap);
			//make a non-transparent map to convert an alpha fade into a color fade
			opaqueMap.draw(map);
			//opaqueMap has a pre-existing relation to the ripple filter
			picture.filters=[ripple];

		}
		}
		}
pet-theory is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is mask work for dynamic text field ? tiru ActionScript 1.0 (and below) 16 02-05-2007 03:08 PM
dynamic changes in the mask (movie clip does not duplicate itself in the mask layer) enfant2soleil ActionScript 2.0 5 08-12-2005 04:50 PM
Dynamic text under dynamic mask w/ MS+ scroller....... G-Rard B Other Flash General Questions 0 12-22-2004 11:13 PM
Gradient Mask Away Dynamic Text with Scroll c2kman ActionScript 1.0 (and below) 4 03-29-2004 08:39 AM
gradient mask?? Trinidad Animation and Effects 1 07-28-2002 10:46 PM


All times are GMT. The time now is 11:19 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.