MaterialPropertyBlock
在unity中,有这样一种情形,有许多的物体,都使用了相同的材质球,但是呢,具体的细节又有些微的不同,如果想要些微的改变每一个 网格的颜色,改变 渲染状态是不行的。
这时,就可以使用MaterialPropertyBlock这个API。这个类将被传递给 Graphics.DrawMesh 或者Renderer.SetPropertyBlock,所以说,最高效的使用方式是创造一个block,然后在每一个网格 绘制 调用中复用。
如果要改变颜色,那么可以使用 MaterialPropertyBlock.SetColor(string name,Color value)。
需要注意的是,这里的value参数是 sRGB格式,并且如果激活颜色空间是线性的,那么这个值也会转换为线性的。如果你在不同的颜色格式中设置值,那么你需要手动转换。
using UnityEngine; // Draws 3 meshes with the same material but with different colors.
public class ExampleClass : MonoBehaviour
{
public Mesh mesh;
public Material material;
private MaterialPropertyBlock block;
private int colorID; void Start()
{
block = new MaterialPropertyBlock();
colorID = Shader.PropertyToID("_Color");
} void Update()
{
// red mesh
block.SetColor(colorID, Color.red);
Graphics.DrawMesh(mesh, new Vector3(, , ), Quaternion.identity, material, , null, , block); // green mesh
block.SetColor(colorID, Color.green);
Graphics.DrawMesh(mesh, new Vector3(, , ), Quaternion.identity, material, , null, , block); // blue mesh
block.SetColor(colorID, Color.blue);
Graphics.DrawMesh(mesh, new Vector3(-, , ), Quaternion.identity, material, , null, , block);
}
}
MaterialPropertyBlock的更多相关文章
- [Unity优化]批处理04:MaterialPropertyBlock
参考链接: https://blog.csdn.net/liweizhao/article/details/81937590 1.在场景中放一些Cube,赋予一个新材质,使用内置shader(Unli ...
- Unity3D核心类型一览
Unity3D核心类型一览 本文记录了Unity3D的最基本的核心类型.包括Object.GameObject.Component.Transform.Behaviour.Renderer.Colli ...
- Unity3D PerRendererData
http://nordicedu.com/tkokblog/wordpress/?tag=perrendererdata MaterialPropertyBlock and SpriteRendere ...
- [转]unity3d 脚本参考-技术文档
unity3d 脚本参考-技术文档 核心提示:一.脚本概览这是一个关于Unity内部脚本如何工作的简单概览.Unity内部的脚本,是通过附加自定义脚本对象到游戏物体组成的.在脚本对象内部不同志的函数被 ...
- Unity3D脚本中文系列教程(十二)
http://dong2008hong.blog.163.com/blog/static/4696882720140313545332/ GameObject类,继承自Object Unity场景中所 ...
- Unity3D脚本中文系列教程(八)
◆ static var matrix : Matrix4x4 描述:设置用于渲染所有gizmos的矩阵. 类方法 ◆ Static function DrawCube(center:Vector3, ...
- Unity之2D Sprite Outline外轮廓效果
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Unity5.3.8f1 Unity提供了2D Object Sprite对象,但是没有提供外轮廓Outline效果的支持 ...
- 1.2:Properties
文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本系列原更新于作者的github博客,这里给出链接. 上一节我们了解了一个Shader的基本结构,这一节,我们从 Propert ...
- Unity Post-Processing的一些分享
讲些什么? 绝大多数的游戏或多或少都会使用些后处理效果. 早期版本中,Unity在提供的接口有限,优化空间不大,属于放任自流.官方推出了Post-Processing(下文简称PP)并在Github上 ...
随机推荐
- ftp服务器的安装
vsftp的安装: 1.安装: yum -y install vsftpd 2.添加ftp用户: useradd ftpuser 3.给ftp用户添加密码: passwd ftpuser 输入两次密码 ...
- SmartDb代码修改
在之前的一篇博客中介绍过SmartDB(https://blog.csdn.net/wuquan_1230/article/details/89145012),在使用的过程中发现一个问题,会造成内存泄 ...
- linux下的node版本管理利器:nvm
nvm是一款node版本管理工具,简单来说,如果你想在一个环境下安装多个node版本,并向自由地切换相关版本,那你就需要使用nvm进行版本管理,有点类似pyenv,也是一款python版本管理工具. ...
- Codechef July Challenge 2020 Division 1 记录
目录 Missing a Point Chefina and Swaps Doctor Chef Chef and Dragon Dens LCM Constraints Weird Product ...
- git使用-分支管理
1.查看分支 git branch 2.创建分支 git branch name 3.切换分支 git checkout name 4.合并分支上的内容到master分支 切换到master分支上 g ...
- java Struts 多种表单写法
1.html:form(struts标签) 缺点:必须指定一个有效的action属性. 优点:可以使用struts token机制. 调用方法通过submit的name属性. <table al ...
- java方法中参数传递与随机点名器、库存管理案例
一 参数传递 1.定义: 参数传递,可以理解当我们要调用一个方法时,我们会把指定的数值,传递给方法中的参数, 这样方法中的参数就拥有了这个指定的值,可以使用该值,在方法中运算了.这种传递方式,我 们称 ...
- NOSQL基础
一.mongoDB介绍和使用 1.分布式文件储存数据库,使用C++开发的,可以存储任意数据(文件),允许在服务器端执行脚本,使用JSON形式储存数据{key:value} 2.支持的编程语言有:PHP ...
- 笔记:Windows Server2008R2服务安装
Windows Server2008R2 服务安装 服务一:IIS,internet information services,互联网信息服务,微软开发的运行在Windows系统中互联网服务,提供了w ...
- 修改linux服务器的时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ntpdate 1.asia.pool.ntp.org 如果出现如下错误 21 Jul 01:0 ...