iOS: Smooth button Glow effect by blending between images -


i creating custom button needs able glow varying degree

diamonds

how use these pictures make button 'glows' diamond when pressed, , have glow gradually fade inert state?

i want churn out several different colours of diamond well... hoping generate different coloured diamonds same stock images presented here.

i head around basic methods available, in enough detail can see each 1 through , make decision path take...


my tangled efforts far... ( delete of this, or move possibly several answers solution unfolds... )

i can see 3 potential solution paths:

  • gl
    looks though gl has takes complete fine-grained control on process, although functions exposed core graphics come tantalisingly close, , save several hundred lines of code spread on bunch of source files, seems bit ridiculous such basic task.

  • core graphics, , core animation accomplish blending

    chroma-key masking documentation goes on

    anything underneath unpainted samples, such current fill color or other drawing, shows through.

    so can chroma-key mask left image, setting {0,0,0} ie black key.

    this @ least secures transparent background, have work on making yellow instead of grey.

    so maybe have started instead setting yellow colour image context, use cgcontextsetblendmode(...) imprint diamond on yellow, use chroma-key masking transparent background

    ok, covers @ least getting basic unlit image on-screen

    now overlay sparkly image, using blend mode, maybe keep in current greyscale state, , boost colours of original

    only problem is lot of heavy real-time blending

    so maybe pre-calculate every image in animation... looking increasingly mucky...

  • cocos2d

    if allows me set blend mode additive blending composite glowing image on original image appropriate alpha setting.

after digging through lot of documentation, optimal solution seems to use core graphics functions source images single 2-component gl texture, , use gl blend between them.

i need pass uniform value glow_factor shader

the obvious solution might seem use

r,g,b = in_r,g,b * { (1 - glow_factor) * inertpixel + glow_factor * shinypixel } 

(where inertpixel appropriate pixel of inert diamond etc)...

it looks manufacture own sparkles , add them on top; gem should sparkle white irrespective of characteristic colour.


Comments