Sunday, October 12, 2014

Having Fun with OpenGL, Android and Hardware Decoding

OpenGL is a good technology, and playing around with it on Android can be real fun! :-) By streaming a video to texture it is possible to create interesting effects, like it is possible to do with Qt. With a simple shader, for instance, lightning effects can be added:


#extension GL_OES_EGL_image_external : require

precision mediump float;
uniform samplerExternalOES u_Texture;
uniform vec3 u_LightPos;      // The position of the light in eye space.
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
varying vec3 v_Position;      // Interpolated position for this fragment.
varying vec4 v_Color; 
varying vec3 v_Normal;        // Interpolated normal.
void main()
{
   float distance = length(u_LightPos - v_Position);
   vec3 lightVector = normalize(u_LightPos - v_Position);
   float diffuse = max(dot(v_Normal, lightVector), 0.0);
   diffuse = diffuse*(1.0/(1.0 + (0.10*distance)));
   diffuse = diffuse + 0.3;
   gl_FragColor = v_Color*diffuse*texture2D(u_Texture, v_TexCoordinate);

}


This is the result on a couple of different devices (Nexus 7 with Qualcomm Snapdragon and an Allwinner A31s chip):

No comments:

Post a Comment