colors - How can i create an image morpher inside a graphics shader? -
image morphing graphic design sfx adapt 1 picture 1 using points decided artist, has match eyes key zones on 1 portrait another, , kinds of algorithms adapt entire picture change 1 another.
i bit similar shader, can load 2 graphics , automatically choose zones of similar colors in same kinds of zone of picture , automatically morph 2 pictures in real time processing. perhaps shader based version logically alot faster @ task? except don't understand how works @ all.
if know, please don't worry complete reply process, great if have save vague background concepts , keywords, how attempt 2d texture morph in graphics shader.
there more morphing methods out there 1 describing based on geometry.
morph interpolation
you have 2 data sets similar properties (for example 2 images both 2d) , interpolate between them parameter. in case of 2d images can use linear interpolation if both images same resolution or trilinear interpolation if not.
so pick corresponding pixels each images , interpolate actual color parameter
t=<0,1>
. same resolution this:for (y=0;y<img1.height;y++) (x=0;x<img1.width;x++) img.pixel[x][y]=(1.0-t)*img1.pixel[x][y] + t*img2.pixel[x][y];
where
img1,img2
input images ,img
ouptput. bewaret
float need overtype avoid integer rounding problems or use scalet=<0,256>
, correct result bit shift right 8 bits or/256
different sizes need bilinear-ly interpolate corresponding(x,y)
position in both of source images first.all can done in fragment shader. bind
img1,img2
texture units0,1
pick texel them interpolate , output final color. bilinear coordinate interpolation done automatically glsl because texture coordinates normalized<0,1>
no matter resolution. in vertex pass texture , vertex coordinates. , in main program side draw single quad covering final image output...morph geometry
you have 2 polygons (or matching points) , interpolate positions between 2. example this: morph cube coil. suited vector graphics. need have points corespondency , interpolation similar #1.
for (i=0;i<points;i++) { p(i).x=(1.0-t)*p1.x + t*p2.x p(i).y=(1.0-t)*p1.y + t*p2.y }
where
p1(i),p2(i)
i-th
point each input geometry set ,p(i)
point final result...to enhance visual appearance linear interpolation exchanged specific trajectory (like bezier curves) morph more cool. example see
to acomplish need use geometry shader (or maybe tesselation shader). need pass both polygons single primitive, geometry shader should interpolate actual polygon , pass vertex shader.
morph particle swarms
in case find corresponding pixels in source images matching colors. handle each pixel particle , create path position in
img1
img2
parametert
. s same #2 instead polygon areas got points. particle hascolor,position
interpolate both ... because there slim chance exact color matches , count ... (histograms same) in-probable.hybrid morphing
it combination of #1,#2,#3
i sure there more methods morphing these ones know of. morphing can done not in spatial domain...
Comments
Post a Comment