gpt4 book ai didi

iphone - 如何重写以图像为背景的 GLCameraRipple 样本?

转载 作者:可可西里 更新时间:2023-11-01 03:29:13 24 4
gpt4 key购买 nike

我正在尝试重写 Apple 样本 GLCameraRipple代码,以图像为背景。实际上我正在尝试使用此代码在水图像上创建波纹效果,但代码适用于相机,相反我只想使用简单的水图像作为背景而不是相机。任何方向或任何示例代码都会有很大的帮助。提前致谢。

最佳答案

相机波纹效果的工作方式是它使三角形网格上的纹理坐标变形——所以好消息是您想要的效果与视频纹理完全不同;他们的纹理恰好是一个视频。要完成您想要的,您只需删除所有相机视频代码,并绑定(bind)您自己的纹理。

因此在 viewDidLoad 中,您将注释掉 [self setupAVCapture],然后继续在 SetupGL 中注释掉两个纹理制服,因为您将只使用一个(这两行是 glUniform1i(uniforms[UNIFORM_Y], 0);, glUniform1i(uniforms[UNIFORM_UV], 1);),然后创建并绑定(bind)你自己的纹理。

GLKit 是完成此类任务的最快方式。 GLKit 对您隐藏了很多 OpenGL 函数调用,但非常快速且有效。

//create the GLKTextureInfo object
NSError *error;
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:GLKTextureLoaderOriginBottomLeft];
GLKTextureInfo *texture = [GLKTextureLoader textureWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"] options:options error:&error];
if (error) NSLog(@"Ripple FRONT TEXTURE ERROR: %@", error);

//bind the texture to texture unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture.target, texture.name);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

现在您丢失了一些包含在 setupAVCapture 中的非常重要的设置。所以在viewDidLoad中把它放在上面代码之后:

if (_ripple == nil ||
texture.width != _textureWidth ||
texture.height != _textureHeight)
{
_textureWidth = texture.width;
_textureHeight = texture.height;

_ripple = [[RippleModel alloc] initWithScreenWidth:_screenWidth
screenHeight:_screenHeight
meshFactor:_meshFactor
touchRadius:5
textureWidth:_textureWidth
textureHeight:_textureHeight];

[self setupBuffers];
}

最后,您必须稍微更改片段着色器。

打开 Shader.fsh 并将主要功能更改为:

void main()
{
gl_FragColor = texture2D(SamplerY, texCoordVarying);
}

无论如何,应该这样做。试验 RippleModel 并看看您能做出什么样的古怪效果非常有趣。

关于iphone - 如何重写以图像为背景的 GLCameraRipple 样本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12372570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com