unity3d-中学透镜成像规律-实验

透镜成像规律: 

使用unity3d版本为2018.3.0f2

透镜成像满足透镜成像公式:\frac{1}{u}+\frac{1}{v}=\frac{1}{f}

解决成像问题:使用RenderTexture

① 新建一个材质球,修改shader为Unlit/Texture

② 新建RenterTexture ,拖入建好的材质球中

③ 在蜡烛前,添加一个Camera,调整相机参数,将②的RenterTexture加入相机中


④在成像白板上新建一个panel,将材质球拖入Image中,这里,我使用了一个高斯模糊shader,用来表现成像的模糊度,将panel上的shader修改为高斯模糊的shader。

模糊程度Size:需要后续其他计算来

shader参数修改:、

 _ImageObj.transform.GetComponent<Image>().material.shader = Shader.Find("shader名字");
_ImageObj.transform.GetComponent<Image>().material.SetFloat("_Size", sizeValue);

这样蜡烛移动成像在白板上,就出现了。(蜡烛火焰暂时用图片代替,后续需要更改为粒子效果,unity2018版本粒子效果很强大的)





成像大小变化算法:

物距:u  焦距:f 像距 v

假设蜡烛大小为1

一、凸透镜成实像:

u>f,v>0

①设放大倍数m,则m=\frac{u}{v} (相似三角形tan函数公式可得)

②透镜成像公式:\frac{1}{u}+\frac{1}{v}=\frac{1}{f}

根据①②可以得到m=\frac{f}{u-f}

白板上成像大小/白板与透镜的距离=m/像距

二、计算模糊程度

模糊度=(白板距离-像距)的绝对值/像距

三、小知识点

1、两个物体之间的距离:

magnitude:

Description描述

Returns the length of this vector (Read Only).

返回向量的长度(只读)。

The length of the vector is square root of (x*x+y*y+z*z).

向量的长度是(x*x+y*y+z*z)的平方根。

If you only need to compare magnitudes of some vectors, you can compare squared magnitudes of them using sqrMagnitude (computing squared magnitudes is faster).

如果你需要比较一些向量的长度,你可以比较它们长度的平方,使用sqrMagnitude(计算平方很快)

两个物体之间的距离:float distance=(a.trannsform.position-b.transform.positon).magnitude;

2、保留x数点后两位

mathf.round(x*100)/100

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容