08-09-2006, 03:13 AM
|
#11
|
|
Registered User
Join Date: May 2006
Posts: 25
|
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.
|
|
|
08-09-2006, 03:47 AM
|
#12
|
|
Registered User
Join Date: Jun 2005
Posts: 145
|
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.
|
|
|
08-09-2006, 03:11 PM
|
#13
|
|
the ever-living
Join Date: Jan 2006
Location: inside this plane
Posts: 113
|
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.
|
|
|
08-09-2006, 06:42 PM
|
#14
|
|
Registered User
Join Date: May 2006
Posts: 25
|
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];
}
}
}
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 03:19 AM.
///
|
|