A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Displacement filter cpu usage problem

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    2

    Displacement filter cpu usage problem

    Hi, i'm using the displacement filter to create a magnify glass effect on my image.

    Using similar code to the example from adobe found at:

    http://livedocs.adobe.com/flex/3/htm...bjects_18.html

    Using adobes example uses about 22% of my cpu. (Pentium 4 3.4 ghz)

    The image im using the effect on is quite large at over 1000 px * 1000 px and layer masking is involved so this pushes cpu usage up to 85%.

    However, i have code which moves the magnified image and the magnifier at the same time and this way cpu usage is simply too high and it stutters.

    Does anyone know how I can reduce the cpu usage used by the displacement filter?

    This is a snippet of my code:

    Code:
    	
    
    var filterX:Number = houseBig.mouseX;     //(houseBig.mouseY) - (map.width / 2);
    var filterY:Number = houseBig.mouseY;       //(houseBig.mouseY) - (map.height / 2); 
    var xyFilter:DisplacementMapFilter = new DisplacementMapFilter(); 
    
    
    the code below inside a function which has to be repeated
    
    
    filterX = (magnify.x) - (houseBig.x) ;
    	filterY = (magnify.y) - (houseBig.y) ;        
    	
    
    	var pt = new Point(filterX, filterY); 
    	mapBitmap.x = mouseX;
    	mapBitmap.y = mouseY;
        xyFilter.mapBitmap = map; 
        xyFilter.mapPoint = pt; 
        // The red in the map image will control x displacement. 
        xyFilter.componentX = BitmapDataChannel.RED; 
        // The blue in the map image will control y displacement. 
        xyFilter.componentY = BitmapDataChannel.BLUE; 
        xyFilter.scaleX = 25; //MANIFY STRENGTH
        xyFilter.scaleY = 25; //MANIFY STRENGTH
    	xyFilter.mode = DisplacementMapFilterMode.IGNORE;
    	houseBig.filters = [xyFilter];
    I just want to reposition the filter more efficiently when this code repeats and the houseBig variables have changed.

    Thanks, Phil

  2. #2
    Senior Member
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    166
    is the full 1000x1000px viewable? if not try using a mask to render only the viewable area

  3. #3
    Senior Member
    Join Date
    Jul 2006
    Location
    San Jose, CA
    Posts
    334
    Yea dude, displacement in any form of computer graphics is CPU intensive. I would go with the mask technique. Much easier on the 'puter.
    I (Love | Hate) Flash.
    ----
    Save a version back so others may help you!

  4. #4
    Junior Member
    Join Date
    Jan 2010
    Posts
    2
    Thanks for help. Thing is, as im using this for a magnifying glass effect, only a small area of the image is visible anyway. Ive tried adding another mask of the whole stage using:

    houseBig.mask = stageMask;

    However this removes my displacement filter effect.
    Last edited by phil7; 01-08-2010 at 07:06 AM.

  5. #5
    Senior Member
    Join Date
    Jul 2006
    Location
    San Jose, CA
    Posts
    334
    Keep in mind also that, unless you're creating this for educational purposes, if you distribute, people are going to be on everything from netbooks to workstations. If a 3.4 is being pushed to 85%, no way a dinky netbook/laptop will be able to use it gracefully.

    My advice is to scrap the displacement idea. It's just too expensive, especially with interactivity.
    I (Love | Hate) Flash.
    ----
    Save a version back so others may help you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center