Camera插件之CinematicCamera

继承自PerspectiveCame

构造函数引用的PerspectiveCamera的构造函数, 代码如下

var CinematicCamera = function ( fov, aspect, near, far ) {

	PerspectiveCamera.call( this, fov, aspect, near, far );
...
}

那么说到底, CinematicCamera还是PerspectiveCamera!!!

效果演示

有没有发现其中的奥秘呢?

这种相机可以设置焦点哦, 突出想要关注的地方, 其他地方比较模糊

1. 属性介绍

属性名: 类型 功能 默认值
type : 字符串 描述信息 'CinematicCamera'
postprocessing : 对象 对相机的全部设置 { enabled: true }
shaderSettings : 对象 渲染设置, 最后应用在postprocessing { rings: 3, samples: 4 }
depthShader : 未知 组成ShaderMaterial给materialDepth BokehDepthShader
materialDepth : ShaderMaterial 赋予了scene.overrideMaterial materialDepth

materialDepth

this.materialDepth = new ShaderMaterial( {
uniforms: depthShader.uniforms,
vertexShader: depthShader.vertexShader,
fragmentShader: depthShader.fragmentShader
} )
this.materialDepth.uniforms[ 'mNear' ].value = near;
this.materialDepth.uniforms[ 'mFar' ].value = far;
scene.overrideMaterial = this.materialDepth;

2. 方法介绍

方法名: 返回类型 功能 具体内容
类方法 : setLens( focalLength, filmGauge, fNumber, coc ) setLens
类方法 : linearize( depth ) linearize
类方法 : smoothstep( near, far, depth ) smoothstep
类方法 : saturate( x ) saturate
类方法 : focusAt( focusDistance ) focusAt
类方法 : initPostProcessing() initPostProcessing
类方法 : renderCinematic( scene, renderer ) renderCinematic

3. 方法详情

setLens

function ( focalLength, filmGauge, fNumber, coc ) {

 // In case of cinematicCamera, having a default lens set is important
if ( focalLength === undefined ) focalLength = 35;
if ( filmGauge !== undefined ) this.filmGauge = filmGauge; this.setFocalLength( focalLength ); // if fnumber and coc are not provided, cinematicCamera tries to act as a basic PerspectiveCamera
if ( fNumber === undefined ) fNumber = 8;
if ( coc === undefined ) coc = 0.019; this.fNumber = fNumber;
this.coc = coc; // fNumber is focalLength by aperture
this.aperture = focalLength / this.fNumber; // hyperFocal is required to calculate depthOfField when a lens tries to focus at a distance with given fNumber and focalLength
this.hyperFocal = ( focalLength * focalLength ) / ( this.aperture * this.coc ); };

linearize

function ( depth ) {

 var zfar = this.far;
var znear = this.near;
return - zfar * znear / ( depth * ( zfar - znear ) - zfar ); };

smoothstep

function ( near, far, depth ) {

 var x = this.saturate( ( depth - near ) / ( far - near ) );
return x * x * ( 3 - 2 * x ); };

saturate

function ( x ) {

 return Math.max( 0, Math.min( 1, x ) );

}

focusAt

function ( focusDistance ) {

 if ( focusDistance === undefined ) focusDistance = 20;

 var focalLength = this.getFocalLength();

 // distance from the camera (normal to frustrum) to focus on
this.focus = focusDistance; // the nearest point from the camera which is in focus (unused)
this.nearPoint = ( this.hyperFocal * this.focus ) / ( this.hyperFocal + ( this.focus - focalLength ) ); // the farthest point from the camera which is in focus (unused)
this.farPoint = ( this.hyperFocal * this.focus ) / ( this.hyperFocal - ( this.focus - focalLength ) ); // the gap or width of the space in which is everything is in focus (unused)
this.depthOfField = this.farPoint - this.nearPoint; // Considering minimum distance of focus for a standard lens (unused)
if ( this.depthOfField < 0 ) this.depthOfField = 0; this.sdistance = this.smoothstep( this.near, this.far, this.focus ); this.ldistance = this.linearize( 1 - this.sdistance ); this.postprocessing.bokeh_uniforms[ 'focalDepth' ].value = this.ldistance; };

initPostProcessing

function () {

 if ( this.postprocessing.enabled ) {

  this.postprocessing.scene = new Scene();

  this.postprocessing.camera = new OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, - 10000, 10000 );

  this.postprocessing.scene.add( this.postprocessing.camera );

  var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBFormat };
this.postprocessing.rtTextureDepth = new WebGLRenderTarget( window.innerWidth, window.innerHeight, pars );
this.postprocessing.rtTextureColor = new WebGLRenderTarget( window.innerWidth, window.innerHeight, pars ); var bokeh_shader = BokehShader; this.postprocessing.bokeh_uniforms = UniformsUtils.clone( bokeh_shader.uniforms ); this.postprocessing.bokeh_uniforms[ "tColor" ].value = this.postprocessing.rtTextureColor.texture;
this.postprocessing.bokeh_uniforms[ "tDepth" ].value = this.postprocessing.rtTextureDepth.texture; this.postprocessing.bokeh_uniforms[ "manualdof" ].value = 0;
this.postprocessing.bokeh_uniforms[ "shaderFocus" ].value = 0; this.postprocessing.bokeh_uniforms[ "fstop" ].value = 2.8; this.postprocessing.bokeh_uniforms[ "showFocus" ].value = 1; this.postprocessing.bokeh_uniforms[ "focalDepth" ].value = 0.1; //console.log( this.postprocessing.bokeh_uniforms[ "focalDepth" ].value ); this.postprocessing.bokeh_uniforms[ "znear" ].value = this.near;
this.postprocessing.bokeh_uniforms[ "zfar" ].value = this.near; this.postprocessing.bokeh_uniforms[ "textureWidth" ].value = window.innerWidth; this.postprocessing.bokeh_uniforms[ "textureHeight" ].value = window.innerHeight; this.postprocessing.materialBokeh = new ShaderMaterial( {
uniforms: this.postprocessing.bokeh_uniforms,
vertexShader: bokeh_shader.vertexShader,
fragmentShader: bokeh_shader.fragmentShader,
defines: {
RINGS: this.shaderSettings.rings,
SAMPLES: this.shaderSettings.samples,
DEPTH_PACKING: 1
}
} ); this.postprocessing.quad = new Mesh( new PlaneBufferGeometry( window.innerWidth, window.innerHeight ), this.postprocessing.materialBokeh );
this.postprocessing.quad.position.z = - 500;
this.postprocessing.scene.add( this.postprocessing.quad ); } };

renderCinematic

function ( scene, renderer ) {

 if ( this.postprocessing.enabled ) {

  var currentRenderTarget = renderer.getRenderTarget();

  renderer.clear();

  // Render scene into texture

  scene.overrideMaterial = null;
renderer.setRenderTarget( this.postprocessing.rtTextureColor );
renderer.clear();
renderer.render( scene, this ); // Render depth into texture scene.overrideMaterial = this.materialDepth;
renderer.setRenderTarget( this.postprocessing.rtTextureDepth );
renderer.clear();
renderer.render( scene, this ); // Render bokeh composite renderer.setRenderTarget( null );
renderer.render( this.postprocessing.scene, this.postprocessing.camera ); renderer.setRenderTarget( currentRenderTarget ); } };

Camera插件之CinematicCamera介绍的更多相关文章

  1. android.hardware.Camera类及其标准接口介绍

    android.hardware.Camera类及其标准接口介绍,API level 19 http://developer.android.com/reference/android/hardwar ...

  2. 【转】android camera(一):camera模组CMM介绍

    关键词:android  camera CMM 模组 camera参数平台信息:内核:linux系统:android 平台:S5PV310(samsung exynos 4210)  作者:xubin ...

  3. Notepad++插件下载和介绍

    20款Notepad++插件下载和介绍 - findumars - 博客园https://www.cnblogs.com/findumars/p/5180562.html

  4. Cordova - 安装camera插件之后编译错误解决方法!

    安装camera插件之后,编译出错,错误截图如下: 刚开始以为是AAPT编译导致的,尝试关闭AAPT编译选项,但是不行,认真看了一下编译出错信息,应该是缺少文件导致的,随后在对应的目录中加入了缺失的文 ...

  5. android camera(一):camera模组CMM介绍【转】

    转自:https://blog.csdn.net/kevinx_xu/article/details/8821818 androidcmm图像处理工作手机三星 关键词:android  camera ...

  6. jQuery图片播放插件prettyPhoto使用介绍

    演示效果  http://www.17sucai.com/preview/131993/2014-07-09/mac-Bootstrap/gallery.html 点击之后的效果 使用方法 Query ...

  7. Vue.js 使用cordova camera插件调取相机

    本文给出在vue.js里如何使用cordova的插件完成调取相机及图库,并完成图片上传的操作.具体的操作步骤如下 第一步:在cordova项目下安装cordova-plugin-camera插件 co ...

  8. 32款iOS开发插件和工具介绍[效率]

    插件和工具介绍内容均收集于网络,太多了就不一一注明了,在此谢过!   1.Charles 为了调试与server端的网络通讯协议.经常须要截取网络封包来分析. Charles通过将自己设置成系统的网络 ...

  9. html-webpack-plugin插件的详细介绍和使用

    var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exp ...

随机推荐

  1. 重要bug记录

    导唱功能:需求点分析:本地已下载歌曲播放,判断是否有音频原唱伴奏版权,无版权按钮显示“导唱”,有版权显示“播原唱”.程序实现逻辑: 1.下载歌曲时调用一个歌曲信息接口,返回歌曲的一些属性信息,其中包括 ...

  2. vue学习笔记一

    vue 颠覆式的开发方式 解疑 为什么要学习vue? 降低项目的复杂度 就业需要 vue难不难? 特别简单 相比于React,vue有什么优势? 前端三大框架:Angular.React.Vue Vu ...

  3. Azure Storage 系列(二) .NET Core Web 项目中操作 Blob 存储

    一,引言 上一篇文章,我们介绍到在实际项目中系统会产生大量的日志文件,用户上传的头像等等,同时也介绍到可以使用Azure Blob Storage 来存储项目中的一些日志文件,用户头像,用户视频等等. ...

  4. Mybatis参数传递及返回类型

    mybatis参数传递: 单个参数:不做特殊处理        #{参数名}:取出参数值    多个参数:做特殊处理        多个参数会被封装成一个map            key:para ...

  5. MVC里面调用webservice

    调用WebService报错404问题 (转载)   我想在MVC4的项目添加一个webservice文件,访问没问题,但是最后调用方法就报404错误.但是如果我全新ASP.NET 空Web应用程序  ...

  6. 转:brpc的研发经历

    转载自:https://www.jianshu.com/p/124dc2c7d9d3 RPC是个老概念,五花八门的实现非常多.在14年我刚转到基础架构部时,其实是不想做RPC框架的.我的想法可能和很多 ...

  7. yum wget rpm

    wget 类似于迅雷,是一种下载工具          下载安装包 yum: 是redhat, centos 系统下的软件安装方式 下载安装包并自动安装 以及一些依赖关系 基于RPM包管理,能够从指定 ...

  8. javascript事件环微任务和宏任务队列原理

    哈喽!大家好!我是木瓜太香,我又来嘞,今天来说说前端面试中经常别问到的 JS 事件环问题. JS 事件环 JS 程序的运行是离不开事件环机制的,这个机制保证在发生某些事情的时候我们有机会执行一个我们事 ...

  9. 性能测试1:loadrunner介绍及代理录制

    一.安装loadrunner lr安装环境要求: Lr11只支持ie9及一下,火狐30以下,不支持chrome.  操作系统只支持到win7.Lr打开时必须用管理员身份打开 在虚拟机中安装的win7, ...

  10. 抽象工厂模式详解 —— head first 设计模式

    项目实例 假设你有一家 pizza 店,你有很多种 pizza,要在系统中显示你所有 pizza 种类.实现这个功能并不难,使用普通方式实现: public class PizzaStore { Pi ...