Using GPUImage to Recreate iOS 7 Glass Effect

本文探讨了如何使用GPUImage库复现iOS 7的玻璃模糊效果,并针对性能问题进行了优化。通过调整多种滤镜参数,实现了接近苹果原生效果的表现。

from: http://www.unknownerror.org/opensource/BradLarson/GPUImage/q/stackoverflow/18404907/using-gpuimage-to-recreate-ios-7-glass-effect

I am trying to use the iOS 7 style glass effect in my glass by applying image effects to a screenshot of aMKMapViewThis UIImage category, provided by Apple, is what I am using as a baseline. This method desaturates the source image, applies a tint color, and blurs heavily using the input vals:

[image applyBlurWithRadius:10.0
                 tintColor:[UIColor colorWithRed:229/255.0f green:246/255.0f blue:255/255.0f alpha:0.33] 
     saturationDeltaFactor:0.66
                 maskImage:nil];

This produces the effect I am looking for, but takes way too long — between .3 and .5 seconds to render on an iPhone 4.

enter image description here

I would like to use the excellent GPUImage as my preliminary attempts have been about 5-10 times faster, but I just can't seem to get it right.

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:image];

GPUImageSaturationFilter *saturationFilter = [[GPUImageSaturationFilter alloc] init];
saturationFilter.saturation = 0.33; // 1.0 - 0.66;
[stillImageSource addTarget:saturationFilter];

GPUImageMonochromeFilter *monochromeFilter = [[GPUImageMonochromeFilter alloc] init];
[monochromeFilter setColor:(GPUVector4){229/255.0f, 246/255.0f, 1.0f, 0.33f}];
[monochromeFilter setIntensity:0.2];
[saturationFilter addTarget:monochromeFilter];

GPUImageFastBlurFilter *blurFilter = [[GPUImageFastBlurFilter alloc] init];
blurFilter.blurSize = 2;
blurFilter.blurPasses = 3;
[monochromeFilter addTarget:blurFilter];

[saturationFilter prepareForImageCapture];
[monochromeFilter prepareForImageCapture];

[stillImageSource processImage];
image = [blurFilter imageFromCurrentlyProcessedOutput];

This produces an image which is close, but not quite there

enter image description here

The blur doesn't seem to be deep enough, but when I try to increase the blurSize above, it becomes grid-like, almost like a kaleidoscope. You can actually see the grid here by zooming in on the second image. The tint-color I am trying to mimic seems to just wash out the image instead of overlaying and blending, which I think the Apple sample is doing.

I have tried to setup the filters according to comments made by @BradLarson in another SO question. Am I using the wrong GPUImage filters to reproduce this effect, or am I just setting them up wrong?

1 Answer

Brad Larson

OK, I've been working on something here for a little while, and I finally have it functional. I just rolled a number of changes to GPUImage's blur filters into the framework, and as a result I believe I have a reasonable replica of Apple's blur effect that they use for things like the control center view.

Previously, the blurs that I had in the framework used a single precalculated radius, and the only way to affect their intensity was to tweak the spacing at which they sampled pixels from the input image. With a limited number of samples per pixel, changing the multiple for the spacing between sampled pixels much above 1.5 started introducing serious blocking artifacts as pixels were skipped.

The new Gaussian blur implementation that I've built combines the performance benefits of precalculated Gaussian weights with the ability to use an arbitrary radius (sigma) for the Gaussian blur. It does this by generating shaders on the fly as they are needed for various radii. It also reduces the number of texture samples required for a given blur radius by using hardware interpolation to read two texels at a time for each sample point.

The new GPUImageiOSBlurFilter combines this tuned arbitrary-radius Gaussian blur filter with a color-correction filter that appears to replicate the adjustment Apple performs to the colors after they've been blurred. I added the below comparison to my answer here, but it shows Apple's built-in blurring from the control center view on the left, and my new GPUImage blur filter on the right:

Apple's blur GPUImage's blur

As a way of improving performance (Apple's blur appears to occur with a sigma of 48, which requires quite a large area to be sampled for each pixel), I use a 4X downsampling before the Gaussian blur, then a 4X upsampling afterward. This reduces the number of pixels that need to be blurred by 16X, and also reduces the blur sigma from 48 to 12. An iPhone 4S can blur the entire screen in roughly 30 ms using this filter.

Getting the blur right is one thing. Apple still does not provide a fast way of getting the image content behind your views, so that most likely will be your bottleneck here for rapidly changing content.


<think>好的,用户遇到了D3D11设备创建失败的问题,错误代码是8007000E。我需要先分析这个错误代码的含义。根据微软文档,8007000E通常对应E_OUTOFMEMORY,即内存不足。这可能意味着系统资源不足,或者驱动程序有问题,也可能是应用程序的内存管理存在缺陷。 首先,我应该建议用户检查系统内存使用情况,确保没有其他程序占用过多内存。接着,更新或重新安装显卡驱动,特别是与DirectX 11兼容的版本。用户可能使用的是过时或损坏的驱动,导致设备创建失败。此外,确认Windows系统和DirectX版本是否为最新,通过运行dxdiag可以查看相关信息。 引用中提到Win10 SDK不同版本对DX支持不一致,可能影响开发环境。用户如果是开发者,可能需要检查项目配置,确保引用了正确的SDK版本,并包含必要的头文件如d3d11.h。同时,检查代码中创建D3D11设备的参数,比如D3D_FEATURE_LEVEL是否正确设置,避免请求过高的特性级别。 另一个可能性是硬件不支持Direct3D 11。用户应确认显卡型号是否支持DX11,并尝试使用D3D11_CREATE_DEVICE_DEBUG标志获取更详细的错误信息。此外,第三方软件冲突,如杀毒软件或覆盖程序(如游戏覆盖),可能会干扰设备创建,建议临时禁用这些软件进行测试。 引用[3]提到使用dxva2代替d3d11va的情况,虽然与当前问题不完全相关,但说明不同硬件设备名称可能导致数据格式变化。如果在代码中指定了特定硬件适配器,可能需要检查适配器是否存在或是否正确初始化。 最后,如果以上步骤无效,建议用户尝试系统文件检查工具(sfc /scannow)修复系统文件,或者重新安装DirectX运行时。如果问题依旧存在,可能需要更深入的调试,如分析内存转储或使用PIX工具捕获GPU事件。</think>### 解决D3D11设备创建失败错误8007000E的步骤 #### 1. 错误代码解析 错误代码 `8007000E` 对应 `E_OUTOFMEMORY`(内存不足)。可能原因包括: - 系统可用内存不足 - 显卡驱动内存分配失败 - Direct3D资源管理异常 - 硬件/驱动不兼容 #### 2. 基础排查 $$ \text{可用内存} = \text{物理内存} - \text{已用内存} - \text{系统保留内存} $$ 建议检查任务管理器: - 关闭非必要进程释放内存 - 确保可用内存大于2GB(含显存) #### 3. 驱动更新 1. 通过设备管理器更新显卡驱动 2. 使用厂商工具(如NVIDIA GeForce Experience/AMD Adrenalin) 3. 手动下载最新驱动包[^2] ```powershell # 查看当前驱动版本 Get-WmiObject Win32_VideoController | Select-Object Name, DriverVersion ``` #### 4. DirectX环境验证 运行诊断工具: ```cmd dxdiag > DirectX诊断日志.txt ``` 检查: - 显示选项卡中D3D11是否启用 - 功能级别是否支持11.0/11.1 - 系统文件完整性: ```cmd sfc /scannow ``` #### 5. 开发环境配置(针对开发者) - 确保项目包含正确SDK路径[^2] ```cpp #include <d3d11.h> #pragma comment(lib, "d3d11.lib") ``` - 设备创建参数建议: ```cpp D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1 }; hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_DEBUG, // 调试时启用 featureLevels, 1, D3D11_SDK_VERSION, &device, &featureLevel, &context); ``` #### 6. 硬件兼容性测试 - 尝试软件渲染模式: ```cpp D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_WARP, ...) ``` - 使用兼容性诊断工具: ```powershell DxCap.exe -forcetdr ``` #### 7. 系统级修复 1. 重置虚拟内存设置 2. 执行内存诊断: ```cmd mdsched.exe ``` 3. 更新Windows至最新版本(需包含KB5005565补丁)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值