随便说说 post-processing
九月份一篇博都没更新,这段时间一直在unity的坑里爬不起来,感觉真的很绝望啊,仿佛对生活都失去了信心。
渲染问题并没有解决,目前方案只是减轻视觉冲突,降低违和感。项目AR产品也做的越来越艰难,开始经常想一个问题,我从哪里来,我该到哪里去。。。
好吧,唠叨这么多,言归正传,今天说说unity的Post-Processing后期处理的景深 Depth Of Field
官方文档 https://docs.unity3d.com/Manual/PostProcessingOverview.html
先贴完整代码,下载PostProcessing插件并import,将下面脚本挂在camera上,运行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing; public class DepthOfFieldTest : MonoBehaviour { public Transform nearBlurTarget;
public Transform farBlurTarget; private PostProcessingProfile profile; // Use this for initialization
void Start () {
AddPostProcessing ();
BlurEffect();
} /// <summary>
/// Adds the post processing 后期处理特效.
/// </summary>
public void AddPostProcessing ()
{
PostProcessingBehaviour postProcessingBehaviour = gameObject.AddComponent<PostProcessingBehaviour> ();
this.profile = new PostProcessingProfile ();
// this.profile = Resources.Load ("GreenArchPOST") as PostProcessingProfile;
postProcessingBehaviour.profile = profile; profile.depthOfField.enabled = false;
profile.antialiasing.enabled = true;
profile.ambientOcclusion.enabled = true; // AO参数设置,主要是要勾选ambientOnly选项
AmbientOcclusionModel.Settings aoSettings = new AmbientOcclusionModel.Settings () {
intensity = 1f,
radius = 0.3f,
sampleCount = AmbientOcclusionModel.SampleCount.Medium,
downsampling = true,
forceForwardCompatibility = false,
ambientOnly = true,
highPrecision = false
};
profile.ambientOcclusion.settings = aoSettings;
} /// <summary>
/// Blurs the effect景深模糊效果.
/// </summary>
/// <param name="jo">Jo.</param>
public void BlurEffect()
{
DepthOfFieldModel depthOfField = this.profile.depthOfField; Vector3 focusPosition = (1.5f * nearBlurTarget.position + farBlurTarget.position) / 2.5f; Plane cameraPlane = new Plane(gameObject.transform.forward, gameObject.transform.position);
float focusDistance = cameraPlane.GetDistanceToPoint (focusPosition);
float depthOfFeild = Mathf.Abs (cameraPlane.GetDistanceToPoint (farBlurTarget.position) - cameraPlane.GetDistanceToPoint (nearBlurTarget.position)); // 根据公式计算 景深ΔL=ΔL1+ΔL2=(2f^2FδL^2)/(f^4-F^2δ^2L^2)
// 容许弥散圆直径 δ=0.035mm
float ap = 5.6f * 0.035f / 1000f;
float focusDistancex2 = Mathf.Pow (focusDistance, 2f);
float lengthx2 = ap * focusDistancex2 + ap * focusDistance * Mathf.Sqrt(focusDistancex2 + Mathf.Pow (depthOfFeild, 2f));
float focalLengthByMath = Mathf.Sqrt (lengthx2 / depthOfFeild) * 1000f; Debug.Log ("清晰点距相机距离:" + focusDistance);
Debug.Log ("景深:" + depthOfFeild);
Debug.Log ("相机焦距 focalLengthByMath (mm):" + focalLengthByMath); depthOfField.enabled = true;
UnityEngine.PostProcessing.DepthOfFieldModel.Settings depthOfFieldSetting = new UnityEngine.PostProcessing.DepthOfFieldModel.Settings {
focusDistance = focusDistance,
aperture = 5.6f,
focalLength = focalLengthByMath,
useCameraFov = false,
kernelSize = DepthOfFieldModel.KernelSize.Medium
};
depthOfField.settings = depthOfFieldSetting;
}
}
采用PostProcessing摄像机后期处理特效,Depth Of Field模块,根据前端给的三个参数计算Focus Distance 焦点距离 和 focalLength镜头焦距。
1.Focus Distance具体含义是距离摄像机多远的“距离”拍摄最高清,这个距离是目标点与相机平面的垂直距离,相机平面可以这样确定,1.与nearPlane平面平行,过相机位置点。所以焦距Focus Distance可以通过以下代码求得并设置:
//相机辅助平面
Plane cameraPlane = new Plane(camera.transform.forward,camera.transform.position);
//计算目标距离相机的距离,焦点距离 focusDistance
float focusDistance = cameraPlane.GetDistanceToPoint (focusPosition);
2.focalLength 镜头焦距,通过景深 nearBlurPosition 和 farBlurPosition计算得到。景深计算方式如下:

看成景深、镜头焦距、光圈值的一个方程,将镜头焦距作为要求的跟,根据一元二次方程的解:

得到 :

随便说说 post-processing的更多相关文章
- 转债---Pregel: A System for Large-Scale Graph Processing(译)
转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/ 作者:Grzegorz Malewicz, Matthew ...
- struts2与struts1整合,java.lang.InstantiationException, Exception occurred during processing request: null
做了2个action,其中一个运行没有问题,另一个报错,看下面的报错信息,再看了看struts.xml,因为没有给GetBooks这个action配置actionform,所以就导致报null.下面是 ...
- Pregel: A System for Large-Scale Graph Processing(译)
[说明:Pregel这篇是发表在2010年的SIGMOD上,Pregel这个名称是为了纪念欧拉,在他提出的格尼斯堡七桥问题中,那些桥所在的河就叫Pregel.最初是为了解决PageRank计算问题,由 ...
- Processing 中玩增强现实 Argument Reality
其实2009年Processing就能做AR了,只是我不知道而已~ 需要以下几个东西: 1.JMyron 2.GSVideo 3.nyar4psg 4.Picking 5.OBJLoader 或者大伙 ...
- 随便记录下系列 - node->express
随便记录下系列 - node->express 文章用啥写?VsCode. 代码用啥写?VsCode. 编辑器下载:VsCode 一.windows下安装node.js环境: 下载地址 相比以前 ...
- OLTP(on-line transaction processing)与OLAP(On-Line Analytical Processing)
OLTP与OLAP的介绍 数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing).联机分析处理OLAP(On-Line Analytical ...
- 新书到手 TRANSACTION PROCESSING:CONCEPTS AND TECHNIQUES
新书到手 TRANSACTION PROCESSING:CONCEPTS AND TECHNIQUES Jim Gray大神的著作 本文版权归作者所有,未经作者同意不得转载.
- Report processing of Microsoft Dynamic AX
Report processing of Microsoft Dynamic AX 版权声明:本文为博主原创文章,未经博主允许不得转载. The implementation of a general ...
- Java基础-多线程编程-1.随便选择两个城市作为预选旅游目标。实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内),哪个先显示完毕,就决定去哪个城市。分别用Runnable接口和Thread类实现。
1.随便选择两个城市作为预选旅游目标.实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内),哪个先显示完毕,就决定去哪个城市.分别用Runnable接口和Thread ...
- ANNOTATION PROCESSING 101 by Hannes Dorfmann — 10 Jan 2015
原文地址:http://hannesdorfmann.com/annotation-processing/annotationprocessing101 In this blog entry I wo ...
随机推荐
- google软件测试之道读后感(一)
这几天在抽空读一本新书,久负盛名的<google软件测试之道>.之前在网络上一点一点地看过它的英文版,很受触动,还做了很长的读书笔记,现在看到了中文版,才恍觉之前的好些理解存在不恰当的地方 ...
- jq,返回上一页,小记history.back(-1)和history.go(-1)区别
<input type="button" name="back" value="重新填写" onclick="javascr ...
- 计算器的单元测试dome
通过上一篇文章,Appium环境已经搭建好了,下面我们通过Python脚本来测试原生的计算器程序 --------------------------------------------------- ...
- SQL Server Profiler的使用
最近一个项目,使用微软的Entity Framework的ORM框架的项目,部署到现场后,出现了系统缓慢,多个客户端的内存溢出崩溃的问题. 打开了SQL Server Profiler排查,发现有全表 ...
- QQ互联申请及配置
今天要说的只是针对QQ互联的操作,其他的互联请参考相关网站. 第一步:需要申请API接口的两码 自行登录QQ互联https://connect.qq.com/index.html,然后按照要求申请就O ...
- hdoj 1285 确定比赛名次 【拓扑排序】
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 使用asyncsocket群聊
#import "ViewController.h" #import "AsyncSocket.h" @interface ViewController ()& ...
- TCP/IP具体解释--UDP数据报中的IP分片
1.UDP首部 2.UDP分片 在第二章,讲链路层是,提到过以太网.刨除数据帧帧头.最多传输的长度为1500.也就是说,假设一个ip数据报,长度大于1500,则须要分片. 分片方法: 在ip头中3位标 ...
- Windows 下Oracle database 9i 64bit 仅仅有 Windows Itanium 64bit
Windows 下Oracle database 9i 64bit 仅仅有 Windows Itanium 64bit,没有Windows x86-64bit的 详细请见例如以下的certificat ...
- HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
1.什么操作出现:当我在项目中添加产品或者修改时,浏览器出现HTTP Status 500 - Request processing failed; nested exception is org.h ...