Friday, September 18, 2009

Video: Shader Transitions in Flex 4

First, some housekeeping announcements:

  • The Adobe TV site (where my CodeDependent show is hosted) has been completely redone. The new site is much more searchable and functional than the previous one, so it's easier to browse around there and find the content you like. I'll continue to embed my CodeDependent videos here on my blog, but I encourage you to also check out the TV site itself and see what else is there.
  • The embedded player from the TV site has been improved, so now you can expand the video below to run fullscreen.
  • The URLs for shows like CodeDependent have also changed. The old links still work (for now at least), but I'll be using the new links from now on to link to the more comprehensible page http://tv.adobe.com/watch/codedependent instead of the older more obtuse "#vi+f16095" page.

And now, back to our show.

Shader Transitions in Flex 4, the next episode in the gripping and suspenseful series CodeDependent, is now available from Adobe TV.

In this show, we see how shaders created in Pixel Bender Toolkit are used in the new Wipe and CrossFade effects to create easy and powerful transitions. These new effects are subclasses of the new AnimateShaderTransition effect which allows you to supply completely custom shaders to get your own shader-based effects for transitions, although you are welcome to simply use Wipe and CrossFade and not worry about the pesky details of shaders if you just want some simple transitions. We covered shaders in a previous episode, where we talked about how to use the new AnimateFilter effect to animate shader properties, and filter properties in general. Now see how we use shaders and shader animations internally to implement some standard transition effects.

Here's the video (note the new ability to expand the player to run in fullscreen mode):

Here is the demo application (pretty SF pictures courtesy photographer and Android-hacker Romain Guy):

And here is the source code.

Finally, here's where you can find the CodeDependent videos on iTunes.

Enjoy.

5 comments:

Anogar said...

I'm getting an error on the example:

ArgumentError: Error #2164: The Shader input src0 is missing or an unsupported type.
at flash.display::DisplayObject/set filters()
at mx.core::UIComponent/set filters()
at spark.effects.supportClasses::AnimateTransitionShaderInstance/setValue()
at spark.effects.supportClasses::AnimateInstance/applyValues()
at spark.effects.supportClasses::AnimateInstance/animationUpdate()
at spark.effects.animation::Animation/sendUpdateEvent()
at spark.effects.animation::Animation/end()
at spark.effects.supportClasses::AnimateInstance/end()
at mx.effects::Effect/end()
at mx.core::UIComponent/commitCurrentState()
at mx.core::UIComponent/setCurrentState()
at mx.core::UIComponent/set currentState()
at ShaderTransitions/__button_click()

Chet Haase said...

@Anogar: I've seen this error when running early versions of Flash Player 10 - I think the interface for shaders in Flash changed along the way. Specifically, I saw this error when running the version of Flash that came with Flash CS4 (the authoring tool).

Try installing the latest version of Flash 10 (like from here) and see if that fixes it.

canon said...

thanks for sharing...

Agustin Lopez said...

I like this very much. I have been learning about this types of transitions but I would like to know if it is possible to use a transition of this type without using states.

Imagine that I have a collection of images and I want to display and effect of this type. Is it possible? Or are transitions only for states?

Thanks for sharing.

Anonymous said...

Do I understand correctly that:
1) Pixel Bender shaders in Flash are CPU only,
2) There is no way to control framerate of these effects and by default it's 100 FPS (judjing by TIMER_RESOLUTION constant in Animation.as),
3) In case of the Wipe effect instead of just copying small changed part of the image on each frame the shader does several floating point comparisons for each pixel of the entire image?

I made a 5 second long Wipe on a 600x400 image and it created 60-70% CPU load on my 2GHz Core 2 Duo regardless of project and application framerate. But when I implemented the same wipe using Timer (40 fps), BitmapImage and BitmapData.copyPixels it took just 2-4% of CPU.