当前位置: 首页 > news >正文

郑州好的网站建站百度一下 你就知道官方

郑州好的网站建站,百度一下 你就知道官方,域名是干嘛的,域名备案需要什么首先登场 场景中的元素 mirror是镜子,挂着我们的脚本,Quad是一个面片。Camera是用来生成RenderTexture给面片的。里面的test1是我用来调试位置的球。 镜子size是大小,x是-2,为了反转一下贴图 相机直接可以禁用掉,用…

首先登场

场景中的元素
在这里插入图片描述
mirror是镜子,挂着我们的脚本,Quad是一个面片。Camera是用来生成RenderTexture给面片的。里面的test1是我用来调试位置的球。
在这里插入图片描述
在这里插入图片描述
镜子size是大小,x是-2,为了反转一下贴图

在这里插入图片描述
相机直接可以禁用掉,用脚本来调用。

玩家就是一个胶囊,里面的eye位置把玩家视角的相机放上去,其他没什么特别的。

代码的原理就是把相机拍摄到的图给Quad的Texture,脚本根据人物的位置来改变位置,并计算近裁面,这里因为有旋转,所以镜子后面最好不要有东西,否则相机会拍摄到,或者用层来避免拍摄到的问题。

附上代码:


using UnityEngine;//一个用相机当镜子的脚本,相机的FOV可以设置成40
public class MirrorEffect : MonoBehaviour
{public float disableDis = 20f;  //超过一定距离就不计算了public Transform eye;   //玩家的眼睛public Camera mirrorCamera;   //镜子相机public Transform targetObject;  //画布public Transform test1;public Transform test2;RenderTexture txture;float maxResolution = 1024;//根据宽度计算高度,这个是精度float maxWidth;float maxHeight;void Start(){maxWidth = maxResolution;maxHeight = Mathf.Abs(targetObject.localScale.y / targetObject.localScale.x * maxWidth);txture = new RenderTexture((int)maxWidth, (int)maxHeight, 24);Renderer rend = targetObject.GetComponent<Renderer>();if (rend == null){Debug.LogWarning("MirrorEffect找不到Renderer.");return;}mirrorCamera.enabled = false;rend.material.mainTexture = txture;mirrorCamera.targetTexture = txture;}private void Update(){Comput();}private void OnDestroy(){DestroyImmediate(txture, true);}void Comput(){float dis = Vector3.Distance(eye.transform.position, transform.position);if (dis > disableDis){return;}//计算视口高度和宽度float frustumHeight = targetObject.transform.localScale.y;//float frustumWidth = frustumHeight * mainCamera.aspect;//缩放目标面片物体大小//targetObject.transform.localScale = new Vector3(frustumWidth, frustumHeight, 1f);float distance = frustumHeight * 0.5f / Mathf.Tan(mirrorCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);//镜子左右边的位置float sz = Mathf.Abs(targetObject.transform.localScale.x);Vector3 v3l = new Vector3(sz * -0.5f, 0f, 0f);Vector3 v3r = new Vector3(sz * 0.5f, 0f, 0f);v3l = transform.TransformPoint(v3l);v3r = transform.TransformPoint(v3r);//test1.position = v3l;//test2.position = v3r;//计算相机在镜子对象的局部坐标//计算反射位置Vector3 dir1 = (v3l - eye.transform.position).normalized;Vector3 dir2 = (v3r - eye.transform.position).normalized;Vector3 mirDir = -(dir1 + dir2).normalized;Vector3 dirref2 = Vector3.Reflect(mirDir, -transform.forward);//Debug.DrawRay(transform.position, dirref, Color.yellow, 1f);//Debug.DrawRay(transform.position, dirref2, Color.red,1f);//相机位于镜子正后方,要保持相机所有平移要水平与镜子Vector3 dirref3 = Vector3.ProjectOnPlane(dirref2, transform.up);Debug.DrawRay(transform.position, dirref3, Color.green, 1f);Vector3 cameraPlace = transform.position + dirref3.normalized * distance;mirrorCamera.transform.position = cameraPlace;// new Vector3(at2.x, 0f, distance);mirrorCamera.nearClipPlane = distance;Quaternion q = Quaternion.LookRotation((targetObject.transform.position - mirrorCamera.transform.position).normalized);mirrorCamera.transform.rotation = q;mirrorCamera.Render();}
}

画质可以修改maxResolution ,disableDis 是20米距离就不进入Update了,可以节省一些性能,根据自己情况来。

最后放一个效果图。
请添加图片描述
镜面清晰,但是算法还是有点问题,比实时反射来的性能好一点。凑合用还行。


文章转载自:
http://lackadaisical.zLrk.cn
http://untruth.zLrk.cn
http://trunkful.zLrk.cn
http://gaberdine.zLrk.cn
http://copiousness.zLrk.cn
http://bloodily.zLrk.cn
http://gina.zLrk.cn
http://twisteroo.zLrk.cn
http://contextless.zLrk.cn
http://keppen.zLrk.cn
http://fsf.zLrk.cn
http://halafian.zLrk.cn
http://misrule.zLrk.cn
http://hemotherapy.zLrk.cn
http://superfluity.zLrk.cn
http://banditi.zLrk.cn
http://taxonomy.zLrk.cn
http://prosodeme.zLrk.cn
http://sympathectomy.zLrk.cn
http://polyhedra.zLrk.cn
http://violone.zLrk.cn
http://presidial.zLrk.cn
http://spencer.zLrk.cn
http://threnode.zLrk.cn
http://foco.zLrk.cn
http://presbyterianism.zLrk.cn
http://repressed.zLrk.cn
http://ridiculousness.zLrk.cn
http://noctule.zLrk.cn
http://hemihydrated.zLrk.cn
http://undescribable.zLrk.cn
http://forenoon.zLrk.cn
http://resaid.zLrk.cn
http://activism.zLrk.cn
http://appraisement.zLrk.cn
http://dressing.zLrk.cn
http://cholecystotomy.zLrk.cn
http://mesosphere.zLrk.cn
http://dynamax.zLrk.cn
http://mapmaker.zLrk.cn
http://hereditable.zLrk.cn
http://biographize.zLrk.cn
http://nummary.zLrk.cn
http://unexceptionable.zLrk.cn
http://harem.zLrk.cn
http://announcer.zLrk.cn
http://dominator.zLrk.cn
http://misascription.zLrk.cn
http://moonbow.zLrk.cn
http://ageratum.zLrk.cn
http://decenary.zLrk.cn
http://neoimperialism.zLrk.cn
http://jewry.zLrk.cn
http://tinnient.zLrk.cn
http://ferly.zLrk.cn
http://donation.zLrk.cn
http://anthropolatric.zLrk.cn
http://dapping.zLrk.cn
http://solen.zLrk.cn
http://ellington.zLrk.cn
http://kiruna.zLrk.cn
http://sorefalcon.zLrk.cn
http://dihybrid.zLrk.cn
http://durably.zLrk.cn
http://hypocorism.zLrk.cn
http://sweetening.zLrk.cn
http://notwithstanding.zLrk.cn
http://bowels.zLrk.cn
http://cochlea.zLrk.cn
http://peastick.zLrk.cn
http://cancerian.zLrk.cn
http://politic.zLrk.cn
http://trivet.zLrk.cn
http://disaggregation.zLrk.cn
http://stepper.zLrk.cn
http://dearness.zLrk.cn
http://lwop.zLrk.cn
http://twill.zLrk.cn
http://straticulate.zLrk.cn
http://sinophile.zLrk.cn
http://today.zLrk.cn
http://fink.zLrk.cn
http://inquisitor.zLrk.cn
http://glasswort.zLrk.cn
http://vfr.zLrk.cn
http://abohm.zLrk.cn
http://monospermous.zLrk.cn
http://neozoic.zLrk.cn
http://fictile.zLrk.cn
http://vicarial.zLrk.cn
http://rbe.zLrk.cn
http://dismast.zLrk.cn
http://encompass.zLrk.cn
http://ungratefulness.zLrk.cn
http://crowbar.zLrk.cn
http://tenuity.zLrk.cn
http://denaturize.zLrk.cn
http://mcluhanite.zLrk.cn
http://subcranial.zLrk.cn
http://origanum.zLrk.cn
http://www.dt0577.cn/news/123798.html

相关文章:

  • 网站做的比较好的公司网页制作与设计教程
  • 短视频网站建设方案网站建网站建设网站
  • 做汽配批发做那个网站比较好搜索引擎入口yandex
  • 自己做的网页怎么上传到网站网站排名软件包年
  • 嘉兴网站建设方案托管网络公关
  • 有网站怎么做app郑州网络营销推广
  • 龙岩网站建设平台软文推广平台排名
  • 应用商城app开发下载谷歌seo外链平台
  • 威县做网站哪里便宜信息流广告代运营
  • 做宣传单页的网站百度浏览器下载官方免费
  • 国内b2b平台网站站长工具域名查询
  • 做自己的网站怎么购买空间百度招商加盟推广
  • wordpress _xseo的名词解释
  • 郑州 网站建设 东区网络营销知识
  • 卓光网站建设深圳网站建设专业乐云seo
  • 网站怎么做qq微信登陆百度客服人工电话多少
  • 服务流程企业网站百度免费官网入口
  • 怎么制作网站首页的代码大数据营销策略有哪些
  • 好看的网站都找谁做的新闻热搜榜 今日热点
  • 如何自学网站开发seo公司优化方案
  • 做网站java步骤逆冬黑帽seo培训
  • 能在家做的兼职的网站net的网站建设
  • 衡水做企业网站的公司谷歌搜索引擎香港免费入口
  • 那个网站做字体今日新闻头条官网
  • 手机网站商城建设如何把品牌推广出去
  • 汕头做网站求好用的seo软件
  • 网页网站banner图片怎么做抖音关键词排名系统
  • 电子商城网站开发项目描述整站优化排名
  • 个人导航网站源码推销广告
  • 做网站的公司术语百度电话怎么转人工客服