mercredi 6 avril 2016

PDI 2.0 morphing in real time powered with GPU shader OpenGL 3.2



With advances in graphics cards especially the GLSL programming language , analyzing the image pixel by pixel is become the new advantage and more powerful than the CPU , recently even the complex problems in physics are using the GPU instead the CPU for the engineering research, in this example I use the vertex shader unit to transform between the initial vertex of image to the final , also the same technic is using with the color blending of image in the pixel shader unit , as shown in video  the result of morphing in real time is impressive...

support : ( win32  OpenGL 3.2 , glut, glew )

article 1 "image deformation "

glsl code :

//shaderMorph.vert

#version 150

uniform float blend;
in vec2 v1; // v1 initial vertex
in vec2 v2; // v2 final vertex
out vec2 uv1; // texcoord 1
out vec2 uv2; // texcoord 2

void main() {
vec2 v = mix(v1,v2,blend); // transfrome v1 to v2 v = (1-blend)*v1+blend*v2
gl_Position = vec4(v,0.0,1.0);
uv1 =0.5*v1+vec2(0.5,0.5) ;
uv2 =0.5*v2+vec2(0.5,0.5) ;
}

//shaderMorph.frag

#version 150

in vec2 uv1;
in vec2 uv2;
uniform float blend;
uniform sampler2D gImage1;
uniform sampler2D gImage2;

void main() {
 float4 color1 = texture(gImage1,uv1);
float4 color2 = texture(gImage2,uv2);
gl_FragColor = mix(color1,color2,blend); // color = (1-blend)*color1+ blend*color2
}

Aucun commentaire:

Enregistrer un commentaire

Remarque : Seul un membre de ce blog est autorisé à enregistrer un commentaire.