u3d_Shader_effects笔记5 第二章 通过UV,进行纹理移动
1.前面心情
公司最近打包,像我等小弟闲着,看代码容易困,没事偷着学shader,不过还是要多交流才行。
2.本文参考
这次参考比较多;由texture uv延伸问题多,主要是不明白变量定义;
http://blog.csdn.net/candycat1992/article/details/17754427 纹理移动,以及一个新shader,更改水纹理的效果
http://www.jianshu.com/p/7b9498e58659 介绍shaderLab比较详细了
u3d manual 必备
3.代码
本文做的事情,其实就是解释代码了。。主要是读http://blog.csdn.net/candycat1992/article/details/17754427的代码;顺便查UnityManual
首先是书中例子代码:
Shader "Custom/ScrollingUVs" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
// Add two properties
_ScrollXSpeed ("X Scroll Speed", Range(0, 10)) = 2
_ScrollYSpeed ("Y Scroll Speed", Range(0, 10)) = 2
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200 CGPROGRAM
#pragma surface surf Lambert sampler2D _MainTex;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed; struct Input {
float2 uv_MainTex;
}; void surf (Input IN, inout SurfaceOutput o) {
fixed2 scrolledUV = IN.uv_MainTex; fixed xScrollValue = _ScrollXSpeed * _Time.y;
fixed yScrollValue = _ScrollYSpeed * _Time.y; scrolledUV += fixed2(xScrollValue, yScrollValue); half4 c = tex2D (_MainTex, scrolledUV);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
其次是http://blog.csdn.net/candycat1992/article/details/17754427后面处理水的代码:
Shader "Mobile/Transparent/Vertex Color" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,0)
_Emission ("Emmisive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.1, 1)) = 0.7
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
} Category {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
Alphatest Greater 0
Blend SrcAlpha OneMinusSrcAlpha
SubShader {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Pass {
ColorMaterial AmbientAndDiffuse
Fog { Mode Off }
Lighting Off
SeparateSpecular On
SetTexture [_MainTex] {
Combine texture * primary, texture * primary
}
SetTexture [_MainTex] {
constantColor [_Color]
Combine previous * constant DOUBLE, previous * constant
}
}
}
}
}
4.我学到什么:
(1).内置变量的查看
http://docs.unity3d.com/Manual/SL-UnityShaderVariables.html
C:\Program Files (x86)\Unity\Editor\Data\UnityShaderVariables.cginc
CBUFFER_START(UnityPerCamera)
// Time values from Unity
uniform float4 _Time;
uniform float4 _SinTime;
uniform float4 _CosTime;
uniform float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt
fixed xScrollValue = _ScrollXSpeed * _Time.y;
Name | Type | Value |
_Time | float4 | Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders. |
_SinTime | float4 | Sine of time: (t/8, t/4, t/2, t). |
_CosTime | float4 | Cosine of time: (t/8, t/4, t/2, t). |
unity_DeltaTime | float4 | Delta time: (dt, 1/dt, smoothDt, 1/smoothDt). |
_Time.y 也就是float4中第二个值,t,即游戏开始到现在的时间; 如果用t/20的话,_ScrollXSpeed * _Time.y;每帧的差值会小一些;
不过smoothDt是什么?应该是dt每帧差值,更平滑的处理?
(2).材质属性的设置,Shininess:
_Shininess ("Shininess", Range (0.1, 1)) = 0.7
上上一章说明了光源的三种属性:ambient\diffuse\specular;
材质也有对应属性:
Material
{
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Shininess http://docs.unity3d.com/Manual/SL-Material.html
Shininess number: The sharpness of the highlight, between 0 and 1. At 0 you get a huge highlight that looks a lot like diffuse lighting, at 1 you get a tiny speck.
http://my.oschina.net/u/1469992/blog/273307
即和Specular相关的镜面指数,指定了镜面反射加亮的大小和集中性,0表示不聚焦,整个表面均匀加亮;1表示聚焦,光斑小,最亮。
(3). Alphatest Greater 0
http://docs.unity3d.com/Manual/SL-AlphaTest.html
Greater 0 即大于0的都通过,对于本此实验,没用
http://blog.sina.com.cn/s/blog_471132920101d8z1.html 讲了alphaTest实际使用,不过最后一个应该错了;
使用alphaTest,可以使场景更加柔和,同时有实体感;
(4). Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
内容有些多;http://docs.unity3d.com/Manual/SL-SubShaderTags.html
"Queue"="Transparent"
There are four pre-defined render queues, but there can be more queues in between the predefined ones. The predefined queues are:
一共四个预定义队列临界值,不过可以在此之间设置新预定义值
Background - this render queue is rendered before any others. You’d typically use this for things that really need to be in the background.
Geometry (default) - this is used for most objects. Opaque geometry uses this queue.
非透明几何数据使用此
AlphaTest - alpha tested geometry uses this queue. It’s a separate queue from Geometry one since it’s more efficient to render alpha-tested objects after all solid ones are drawn.
从geometry中分出来的,在所有solid绘制后,AlphaTest,更有效的操作
Transparent - this render queue is rendered after Geometry and AlphaTest, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).
透明,alpha混合操作;不进行z-write写入深度buffer;glass,particle效果
Overlay - this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares).
最上层效果,如镜头光晕
For special uses in-between queues can be used. Internally each queue is represented by integer index; Background is 1000, Geometry is 2000, AlphaTest is 2450,Transparent is 3000 and Overlay is 4000. If a shader uses a queue like this:
Tags { "Queue" = "Geometry+1" }
This will make the object be rendered after all opaque objects, but before transparent objects, as render queue index will be 2001 (geometry plus one). This is useful in situations where you want some objects be always drawn between other sets of objects. For example, in most cases transparent water should be drawn after opaque objects but before transparent objects.
+1,累加操作,会让此object绘制在所有opaque绘制后进行;同时在transparent之前; 当你想此object绘制顺序between其他object之间时,此很有用。比如,water在opaque和其他transparent之间绘制的;
Queues up to 2500 (“Geometry+500”) are consided “opaque” and optimize the drawing order of the objects for best performance. Higher rendering queues are considered for “transparent objects” and sort objects by distance, starting rendering from the furthest ones and ending with the closest ones. Skyboxes are drawn in between all opaque and all transparent objects.
天空盒在opaque和transparent之间???不应该在background吗?即opaque之前吗?
RenderType tag categorizes shaders into several predefined groups, e.g. is is an opaque shader, or an alpha-tested shader etc. This is used by Shader Replacement and in some cases used to produce camera’s depth texture. If IgnoreProjector tag is given and has a value of “True”, then an object that uses this shader will not be affected by Projectors. This is mostly useful on semitransparent objects, because there is no good way for Projectors to affect them.
以上两句不懂;1.RenderType的作用?是为了分类方便,调用不同类型的shader吗
2.Projector控件的使用。上句英文意思 应该是半透明物体不适合投影效果,如果渲染半透明object,IgnoreProjector设置true;可我对Projector是啥不熟悉,类似渲染到纹理效果吗?
(5) Blend SrcAlpha OneMinusSrcAlpha
分清楚source和des哦。。。 Source refers to the calculated color, Destination is the color already on the screen. The blend factors are ignored if BlendOp is using logical operations.
http://docs.unity3d.com/Manual/SL-Blend.html
(6)Combine previous * constant DOUBLE, previous * constant
http://docs.unity3d.com/Manual/SL-SetTexture.html
SetTexture [_MainTex] {
constantColor [_Color]
Combine previous * constant DOUBLE, previous * constant //rgb,a值;第二个参数为alpha
}
和ogl里setTexture类似;具体看文档吧
小Tips:我一直以为这段代码,去掉DOUBLE后,由于_Color是(1,1,1,1),得到的场景A,和删除此段代码得到场景B是一样的;但结果是A要浅一些;
一直有疑问,后来发现:是我在u3d编辑器把alpha值设置成0.5了;
(7)http://www.jianshu.com/p/7b9498e58659
上博客介绍u3d shaderLab的比较详细了
5.待解决的疑问;
即黄色的部分;
1.smoothDr是啥?
2.Skyboxes are drawn in between all opaque and all transparent objects.
3.1.RenderType的作用?
4.Projector控件的使用
几个问题都需要实验,估计时间比较久。
Tips,今天看到fog, fog在PS颜色合成之前,操作是:修改片元的颜色,达到雾化效果;是在PS管线内,即所有Test之前进行的
昨晚mipMap和滤波filter方式又看了下,概念不清晰。
u3d_Shader_effects笔记5 第二章 通过UV,进行纹理移动的更多相关文章
- u3d_Shader_effects笔记6 第二章 animating sprite
1.前面的心情 上班看shader我也是醉了.写完这篇看代码去了,不过看着看着恐怕就会困.... 还有就是上天,我该怎么做,下一步,大懒: 2.参考源头 http://blog.csdn.net/ca ...
- Stealth视频教程学习笔记(第二章)
Stealth视频教程学习笔记(第二章) 本文是对Unity官方视频教程Stealth的学习笔记.在此之前,本人整理了Stealth视频的英文字幕,并放到了优酷上.本文将分别对各个视频进行学习总结,提 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...
- Java编程思想_笔记_第二章_一切都是对象
第二章对于知识只是点到,会在以后章节会详细展开. 笔记的侧重会偏向记录自己知识模糊的地方.比如 xxx 很重要很难很实用,但是已经熟练使用就没有记录,而 “使用对象.成员名称来使用成员变量”,较简单而 ...
- 【vue.js权威指南】读书笔记(第二章)
[第2章:数据绑定] 何为数据绑定?答曰:数据绑定就是将数据和视图相关联,当数据发生变化的时候,可以自动的来更新视图. 数据绑定的语法主要分为以下几个部分: 文本插值:文本插值可以说是最基本的形式了. ...
- Javascript高级程序设计读书笔记(第二章)
第二章 在HTML中使用Javascript 2.1<script>元素 延迟脚本(defer = "defer")表明脚本在执行时不会影响页面的构造,脚本会被延迟到 ...
- win32多线程程序设计笔记(第二章)
第二章线程的第一次接触,主要讲了如何创建线程以及需要注意的几点. 一.创建线程 与调用函数的过程类似;线程只不过用CreateThread的API将函数封装起来,并产生一个与主程序同时执行的程序来调用 ...
- 流畅的python学习笔记:第二章
第二章开始介绍了列表这种数据结构,这个在python是经常用到的结构 列表的推导,将一个字符串编程一个列表,有下面的2种方法.其中第二种方法更简洁.可读性也比第一种要好 str='abc' strin ...
- java并发编程实战笔记---(第二章)线程安全:正确性
ThreadA__________ 同步 ______________ 异步 ___________ 异步 ThreadB__________ ____________ ...
随机推荐
- HTML 表单
HTML 表单包含表单元素. <form> 元素定义 HTML 表单 表单元素指的是不同类型的 input 元素.复选框.单选按钮.提交按钮等等. HTML 表单用于搜集不同类型的用户输入 ...
- SAP ALV内嵌(In-place)Excel的问与答
1.问题:点击ALV工具栏的"Excel"图标后,出现空白的内嵌Excel界面,无法正常显示报表数据.可按以下思路解决:(1)检查Excel中的宏安全设置选项.访问方法:启动Exc ...
- 关于sharepoint2013的SPUtility.GetGenericSetupPath()方法过期解决办法
有个时候需要读取layouts下的xml文件,因此需要知道路径,以前在SP2010用的SPUtility.GetGenericSetupPath()方法获取.现在SP2013提示过期否决 看2个结构分 ...
- Service和Thread的关系及如何启用Service,如何停用Service
Service和Thread的关系: 不少Android初学者都可能会有这样的疑惑,Service和Thread到底有什么关系呢?什么时候应该用Service,什么时候又应该用Thread?答案可能会 ...
- Android studio 如何查看当前git 分支的4种方式
1.第一种 2.第二种 3.第三种 4.第四种 前面3种都是通过android studio 操作的. 第四种是通过命令行操作.(可以在 git bash 中输入命 ...
- 让shell脚本在后台飞
1. 使用&符号在后台执行命令 你可以在Linux命令或者脚本后面增加&符号,从而使命令或脚本在后台执行,例如:. $ ./my-shell-script.sh & 2. 使用 ...
- php设计模式 数据对象映射模式
数据对象映射模式,是将对象和数据存储映射起来,对一个对象的操作会映射为对数据存储的操作. 在代码中实现数据对象映射模式,实现一个ORM类,将复杂的sql语句映射成对象属性的操作.对象关系映射(Obje ...
- Java集合框架的接口和类层次关系结构图
Collection和Collections的区别 首先要说的是,"Collection" 和 "Collections"是两个不同的概念: 如下图所示,&qu ...
- android中的万能适配器BaseAdapter的总结
有时候,列表不光会用来做显示用,我们同样可以在在上面添加按钮.添加按钮首先要写一个有按钮的xml文件,然后自然会想到用上面的方法定义一个适配器,然后将数据映射到布局文件上.但是事实并非这样,因为按钮是 ...
- 使用Source Safe for SQL Server解决数据库版本管理问题(转载)
简介 在软件开发过程中,版本控制是一个广为人知的概念.因为一个项目可能会需要不同角色人员的参与,通过使用版本控制软件,可以使得项目中不同角色的人并行参与到项目当中.源代码控制使得代码可以存在多个版本, ...