iOS/GLES2:如何实现发光效果 [英] iOS / GLES2: How to achieve Glow Effect

查看:185
本文介绍了iOS/GLES2:如何实现发光效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个罗盘式的针,可以自由旋转.

I have a compass style needle, free to spin.

当它接近某个方向(例如55度)时,我需要它发光.

I need it to glow when it approaches a certain orientation, say 55 degrees.

我想拥有NeedleView子类UIView,所以我可以像对待UIView一样操纵(NeedleView *)needleView,只需要几个额外的方法 -(void)feedAngle:(float)theta; -(void)feedGlow:(float)glow_01;

I want to have NeedleView subclass UIView, so I can manipulate (NeedleView*)needleView as if it was a UIView, just have a couple of extra methods - (void) feedAngle: (float) theta; - (void) feedGlow: (float) glow_01;

做一些研究,我发现常见的技术是对针的图像进行灰度复制,将其模糊,将其保存为GL纹理,然后将其包裹在实际针的后面的四边形上四.

doing a bit of research, I have found that the common technique is to take a greyscale copy of the needle's image, blur it, save it as a GL texture, and then wrap it onto a quad that sits behind the actual needle's quad.

那我有点毛茸茸....

then I am a bit woolly....

我想我将角点上的RGBA设置为我所需的发光颜色(r,g,b)a = glowFactorForThisFrame

I guess I set the RGBA on the corner points to be (r,g,b) of my desired glow colour, a=glowFactorForThisFrame

然后将glBlendmode设置为适当的值

and then I set glBlendmode to something appropriate

然后我绘制纹理四边形以进行模糊

and then I draw the textured quad for the blur

我想要的东西是原始针上的Alpha始终为1,但是随着我们移开,它会逐渐出血以完全透明化

what I want is something where Alpha is 1 everywhere on the original needle, but it bleeds gradually to complete transparency as we move further away

...

首先,我想找到一些代码来处理模糊的灰度位图,我宁愿从代码中实现,而不是在Photo shop中实现. (我意识到这在实际设备上会花费很多时间,所以也许我可以在应用程序首次运行时进行计算,将其保存到文件中,然后从文件中加载)

for a start, I would like to find some code that takes care of blurring a greyscale bitmap, I would rather do this from code than in photo shop. (I realize this would take a lot of time on an actual device, so maybe I can calculate it the first time the app is run, save it to file, and subsequently just load from file)

其次,我对要做的确切细节非常粗略.

secondly, I'm very sketchy on the precise details of what I have to do.

有人可以在这两个方面帮助我吗?

could someone help me in on either of these points?

推荐答案

我在这里尝试了很多方法.

I experimented with a lot of approaches here.

基本上,我缝了两张照片.一发光,一不发光.

basically I neeed two images; one glowing and one not.

然后我可以将它们作为CALayers相互绘制,并劫持CADisplayLink,进行设置

then I can draw them as CALayers on top of one another, and hijack CADisplayLink, setting

glowLayer.opacity = glowFac;
dullLayer.opacity = (1 - glowFac);

我还玩弄GL着色器,以统一的方式传递了发光因子,但这是大量的代码,可以完成相同的操作.

I also played with fiddling around in GL shaders, passing the glow factor as a uniform, but this is a ton of code to do basically the same thing.

请注意,我需要找到一名图形艺术家来发光"图像

NB I needed to find a graphic artist to 'glow' the image

这篇关于iOS/GLES2:如何实现发光效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆