Unity抗锯齿,Unity3D模型花闪烁等效果优化。

最近在做全息投影项目,模型闪烁,锯齿明显,自己总结了一些优化方法。

方法一:在场景内摄像机上挂载如下抗锯齿脚本。摄像机改为Skybox或者SolidColor模式;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Antialiasing : MonoBehaviour
{private static GameObject renderTargetCam;private static TextureRenderer textureRenderer;private static RenderTexture renderTexture;public static float scale = 2;private Camera mainCam;private int screenX;private int screenY;private int targetX = 100;private int targetY = 100;private int hideFlagDontShowSave = 61;public bool restart;private bool rendering;public static RenderTextureFormat Format = RenderTextureFormat.ARGB32;public static GameObject RenderTargetCamera{get{return Antialiasing.renderTargetCam;}}public static RenderTexture RenderTexture{get{return Antialiasing.renderTexture;}}public Camera RenderingCamera{get{return this.mainCam;}}private void OnEnable(){this.mainCam = base.GetComponent<Camera>();if (this.mainCam == null){Debug.LogError("Missing Camera on GameObject!");base.enabled = false;return;}this.hideFlagDontShowSave = 13;this.targetX = Screen.width;this.targetY = Screen.height;new Shader();if (Application.isEditor){this.restart = true;return;}this.StartAntialiasing();}private void OnDisable(){this.StopAntialiasing();}private void Update(){if (this.screenX != Screen.width || this.screenY != Screen.height){this.restart = true;}if (this.restart){this.Restart();}}private void Restart(){this.StopAntialiasing();this.StartAntialiasing();this.restart = false;}private void OnPreCull(){if (this.rendering && (this.screenX != Screen.width || this.screenY != Screen.height)){this.targetX = Screen.width;this.targetY = Screen.height;this.restart = true;}if (this.rendering){this.mainCam.targetTexture = Antialiasing.renderTexture;}}private void FinishedRendering(){if (this.rendering){this.mainCam.targetTexture = null;}}public void StartAntialiasing(){if (this.mainCam == null){Debug.LogError("Missing Camera on Object!");return;}this.screenX = Screen.width;this.screenY = Screen.height;int num = (int)((float)Screen.width * Antialiasing.scale);int num2 = (int)((float)Screen.height * Antialiasing.scale);if (num <= 0){num = 100;}if (num2 <= 0){num2 = 100;}if (Antialiasing.renderTexture == null || Antialiasing.renderTexture.width != num || Antialiasing.renderTexture.height != num2){if (Antialiasing.renderTexture != null){Antialiasing.renderTexture.Release();}Antialiasing.renderTexture = new RenderTexture(num, num2, 2, Antialiasing.Format);Antialiasing.renderTexture.name = "SSAARenderTarget";Antialiasing.renderTexture.hideFlags = (HideFlags) this.hideFlagDontShowSave;}if (Antialiasing.renderTargetCam == null){Antialiasing.renderTargetCam = new GameObject("SSAARenderTargetCamera");Antialiasing.renderTargetCam.hideFlags = (HideFlags) this.hideFlagDontShowSave;Camera c = Antialiasing.renderTargetCam.AddComponent<Camera>();c.CopyFrom(this.mainCam);c.cullingMask = 0;c.targetTexture = null;c.depth = this.mainCam.depth + 0.5f;Antialiasing.textureRenderer = Antialiasing.renderTargetCam.AddComponent<TextureRenderer>();Antialiasing.textureRenderer.hideFlags = (HideFlags)this.hideFlagDontShowSave;}this.rendering = true;}public void StopAntialiasing(){if (this.mainCam != null && this.mainCam.targetTexture != null){this.mainCam.targetTexture = null;}if (renderTargetCam != null){GameObject.Destroy(renderTargetCam);}this.rendering = false;}
}
public class TextureRenderer : MonoBehaviour
{private Camera c;public bool stereoFirstPass = true;private void Awake(){this.c = gameObject.GetComponent<Camera>();if (this.c == null){Debug.LogError("TextureRenderer init fail! (no Camera)");base.enabled = false;}}private void OnRenderImage(RenderTexture source, RenderTexture destination){Graphics.Blit(Antialiasing.RenderTexture, destination);Antialiasing.RenderTexture.DiscardContents();}
}

方法二:unity系统设置:Edit-->ProjectSettings------>QualitySettungs-------->Ultra-------->AntiAlisaing-------->8XMulti Sampling,如下图所示:

方法三:

相机设置:

方法四:相机上挂载如下所示脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class QualitySetting : MonoBehaviour {void Start () {QualitySettings.shadowResolution = ShadowResolution.VeryHigh;QualitySettings.antiAliasing = 8;}}

好啦,这是最近做全息投影展示项目,模型锯齿的一些心得。

Unity抗锯齿,Unity3D模型花闪烁等效果优化。相关推荐

  1. Unity抗锯齿设置

    Unity抗锯齿设置 问题 方法 方法一 方法二 方法三 方法四 方法五 方法六 参考 问题 有时候在Unity中的模型边缘.棱角会出现锯齿的情况. 如图: 方法 一般情况,下面有以下几种方法: 方法 ...

  2. Unity 抗锯齿Antialiasing

    直接放到相机上用即可,可以有效降低锯齿(相对于其他插件而言),另外这个脚本跟NatCorder录制视频冲突,具体原因后续再详查. 最近突然发现PC端用Antialiasing修改窗口分辨率时会黑屏,后 ...

  3. 【游戏开发创新】使用Unity ShaderGraph实现在模型上涂鸦的效果,那么,纹个手吧

    文章目录 一.前言 二.思考 三.实操 1.Render Texture 2.笔刷图案 3.写脚本:DrawOn3D.cs 4.ShaderGraph 5.模型 6.材质球 7.挂脚本 四.运行测试 ...

  4. 图形学中的抗锯齿讨论以及在unity中的应用

    抗锯齿(Anti-Aliasing)是图形学中,很重要的一个部分.本文旨在做一些分析总结,并对平时不理解的细节,做了调研,但毕竟不是做GPU行家,所以有不对的地方,欢迎拍砖^^. 1 什么是锯齿 下图 ...

  5. 各种抗锯齿效果的记录

    抗锯齿介绍 SSAA :超级采样抗锯齿 描述 最早期的全屏抗锯齿,方法简单直接, 超级采样抗锯齿就是把当前分辨率成倍提高(如当前分辨率为1024×768,开启2倍的SSAA后,画面放大到2048×15 ...

  6. QT QPainter::antialiasing QPainter::textAntialiasing 反走样、抗锯齿探究

    QT中使用QPainter 进行自行绘图的时候,为了防止"锯齿"的出现,我们会经常使用抗锯齿属性,也叫反走样, 既: QPainter::Antialiasing //绘图抗锯齿 ...

  7. Unity3D学习(七):Unity多重采样抗锯齿设置无效的解决办法

    前言 学习Shader的过程中发现模型锯齿严重,于是去Edit--Project Settings--Quality选项下将反锯齿设置为了8X Multi Sampling.结果没有任何改变,如图: ...

  8. unity终极抗锯齿抗白边黑边投影阴影不正常问题解决

    写这篇时是自己的总结,也是综合了很多其他文章的 因为一般的提问只能解决很少的问题,而且通常不管用,所以自己总结了下 1.首先在edit-project setting-quality可以试着调整里面的 ...

  9. Unity后期处理-抗锯齿

    一.产生原因 顶点插值可以产生任意位置的顶点.但是像素不是,像素着色器如何着色是通过他的中心点是否被三角形覆盖决定的.所以会产生突变,在外围看来就是锯齿.      二 解决方案 1.  MSAA首先 ...

最新文章

  1. 知识图谱推理问答:如何让机器像人类一样学会推理
  2. Python按行读取文件、写文件
  3. NR 5G 零基础看5G
  4. 3.9 YOLO算法-深度学习第四课《卷积神经网络》-Stanford吴恩达教授
  5. Activiti总体框架分析
  6. IE浏览器error:Promise未定义
  7. 《ASP.NET Core项目开发实战入门》送书活动结果公布
  8. 高性能 高可用 可弹性伸缩_性能,可伸缩性和活力
  9. 支持多并发的单例有哪几种写法
  10. React hooks + antd前台实现input搜索框实时搜索table表格
  11. 数据库课程设计—超市零售信息管理系统(Python实现)
  12. mysql server安装及配置
  13. HAL库配置STM32F1系列定时器驱动步进电机(三)
  14. 【计算理论】图灵机 ( 图灵机引入 | 公理化 | 希尔伯特纲领 | 哥德尔不完备定理 | 原始递归函数 )
  15. egg入门指引,你绝对用得到
  16. 用了都说好的PDF转JPG免费在线工具
  17. 恰到好处的挫折:在最深的绝望,遇见最美的意外 ~ 【美】 格雷格 · S · 里德...
  18. ov9712雄迈模组分析
  19. 【2023秋招面经】经纬恒润前端面经总结
  20. fdisk -l文件详解

热门文章

  1. Remix编辑器连接本地(最新)
  2. 中级育婴师证怎么考,需要些什么条件
  3. 缺乏技术专利支撑的小米还能走多远
  4. 西山居剑心数据分析笔面试题
  5. 【学习笔记】大数据技术之HBase
  6. 一次zabbix连接不上mysql数据库的经历
  7. ad绘制箭头_上传单张/多张图片并绘制箭头
  8. excel中使用datedif出现#value和#num问题
  9. web端的shader效果九 three.js里shader实现较平静的水面
  10. JS脚本错误80020101以及FCKedito未定义的一种解决办法