dimanche 10 janvier 2010

Scrolling with DisplacementMap effect

Bonne Année ! , Happy New Year !

For beginning this New Year, I added a sinusoidal effect to my scroll.
To do that, I added a
DisplacementMap effect to the scroll line.

DisplacementMap Effect
                    effect: DisplacementMap { mapData: map
                                              input:Reflection {
                                                   fraction: 0.75
                                                   topOffset: 0.0
                                                   topOpacity: 0.5
                                                   bottomOpacity: 0.0
                                               } 
                  } 

And I created a FloatMap to make the sinusoidal effect

FloatMap
var widthScroll = letterWidth * 10;    // 10 chars
var map = FloatMap { width: widthScroll height: letterHeight }
for (i:Integer in [0..<widthScroll]) {
    var v = (Math.sin(i/35.0*Math.PI)-0.5)/30.0;
    for (j:Integer in [0..<letterHeight]) {
        map.setSamples(i, j, 0.0, v);
    }
}
As you see in the code, the DisplacementMap effect take a FloatMap as parameter. And each individual entry in the FloatMap contains per-pixel offset information in the x and y direction.

For example if you have this image

My FloatMap contains offsets x and y to have

Download full Main.fx

Download StringConverter.fx

Aucun commentaire: