
[vIDeoOutput setVIDeoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVIDeoRange] forKey:(ID)kCVPixelBufferPixelFormatTypeKey]];
我将像素数据传递给我的纹理,如下所示:
glTexImage2D(GL_TEXTURE_2D,GL_RGBA,bufferWIDth,bufferHeight,GL_RGB_422_APPLE,GL_UNSIGNED_SHORT_8_8_REV_APPLE,CVPixelBufferGetBaseAddress(cameraFrame));
我的fragement着色器是:
varying highp vec2 textureCoordinate;uniform sampler2D vIDeoFrame; voID main() { lowp vec4 color; color = texture2D(vIDeoFrame,textureCoordinate); lowp vec3 convertedcolor = vec3(-0.87075,0.52975,-1.08175); convertedcolor += 1.164 * color.g; // Y convertedcolor += vec3(0.0,-0.391,2.018) * color.b; // U convertedcolor += vec3(1.596,-0.813,0.0) * color.r; // V gl_Fragcolor = vec4(convertedcolor,1.0); } 我的顶点着色器是
attribute vec4 position;attribute vec4 inputTextureCoordinate;varying vec2 textureCoordinate;voID main(){ gl_position = position; textureCoordinate = inputTextureCoordinate.xy;} 当我使用BGRA图像时,这很好用,而我的片段着色器只能这样做
gl_Fragcolor = texture2D(vIDeoFrame,textureCoordinate);
如果我在这里遗失了什么?谢谢!
解决方法 好.我们在这里取得了成功.关键是将Y和UV作为两个单独的纹理传递给片段着色器.这是最终的着色器:#ifdef GL_ESprecision mediump float;#endifvarying vec2 textureCoordinate;uniform sampler2D vIDeoFrame; uniform sampler2D vIDeoFrameUV;const mat3 yuv2rgb = mat3( 1,1.2802,1,-0.214821,-0.380589,2.127982,0 );voID main() { vec3 yuv = vec3( 1.1643 * (texture2D(vIDeoFrame,textureCoordinate).r - 0.0625),texture2D(vIDeoFrameUV,textureCoordinate).r - 0.5,textureCoordinate).a - 0.5 ); vec3 rgb = yuv * yuv2rgb; gl_Fragcolor = vec4(rgb,1.0);} 你需要像这样创建纹理:
int bufferHeight = CVPixelBufferGetHeight(cameraFrame);int bufferWIDth = CVPixelBufferGetWIDth(cameraFrame);glBindTexture(GL_TEXTURE_2D,vIDeoFrameTexture);glTexImage2D(GL_TEXTURE_2D,GL_luminance,GL_UNSIGNED_BYTE,CVPixelBufferGetBaseAddressOfPlane(cameraFrame,0));glBindTexture(GL_TEXTURE_2D,vIDeoFrameTextureUV);glTexImage2D(GL_TEXTURE_2D,GL_luminance_Alpha,bufferWIDth/2,bufferHeight/2,1));
然后像这样传递它们:
glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D,vIDeoFrameTexture);glActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D,vIDeoFrameTextureUV);glActiveTexture(GL_TEXTURE0);gluniform1i(vIDeoFrameUniform,0);gluniform1i(vIDeoFrameUniformUV,1);
男孩,我松了一口气!
附: yuv2rgb矩阵的值来自这里http://en.wikipedia.org/wiki/YUV,我从这里复制代码http://www.ogre3d.org/forums/viewtopic.php?f=5&t=25877,以找出如何获得正确的YUV值.
总结以上是内存溢出为你收集整理的在iOS 4.3中将YpCbCr iPhone 4相机框架渲染为OpenGL ES 2.0纹理全部内容,希望文章能够帮你解决在iOS 4.3中将YpCbCr iPhone 4相机框架渲染为OpenGL ES 2.0纹理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)