u3d_shader_surface_shader_1
http://docs.unity3d.com/Manual/SL-SurfaceShaders.html
一:surface shader是啥
Writing shaders that interact with lighting is complex. There are different light types, different shadow options, different rendering paths (forward and deferred rendering), and the shader should somehow handle all that complexity.
Surface Shaders in Unity is a code generation approach that makes it much easier to write lit shaders than using low levelvertex/pixel shader programs. Note that there are no custom languages, magic or ninjas involved in Surface Shaders; it just generates all the repetitive code that would have to be written by hand. You still write shader code in Cg / HLSL.
就是说直接写shader太复杂,为了提高效率,使用了surface shader,“using low levelvertex/pixel shader programs”,surface shader不是一种定义的语言,只是VS PS的上层,surface shader编译后还是会转化为相应的vs ps的。从u3d编辑器的"show generated code"中也可以看出来。
同样的,输入输出,“Standard output structure of surface shaders is this:”
标准的输出是:
struct SurfaceOutput
{
fixed3 Albedo; // diffuse color
fixed3 Normal; // tangent space normal, if written
fixed3 Emission;
half Specular; // specular power in 0..1 range
fixed Gloss; // specular intensity
fixed Alpha; // alpha for transparencies
};
u3d5中又新加了SurfaceOutputStandard和SurfaceOutputStandardSpecular输出
二:编译指令:
和其他shader一样,也是在“CGPROGRAM..ENDCG block”块内部的,区别是:
- It must be placed inside SubShader block, not inside Pass. Surface shader will compile into multiple passes itself.
- It uses
#pragma surface ...directive to indicate it’s a surface shader.
1.置在SubShader内,surface shader会自动编译进多pass
2.使用#pragma surface指令来告知俺是surface shader;#pragma surface surfaceFunction lightModel [optionalparams]
三:输入结构:
The input structure Input generally has any texture coordinates needed by the shader. Texture coordinates must be named “uv” followed by texture name (or start it with “uv2” to use second texture coordinate set).
纹理坐标名必须使用 uv开头,后面跟上纹理名
float3 viewDir- will contain view direction, for computing Parallax effects, rim lighting etc.float4withCOLORsemantic - will contain interpolated per-vertex color.float4 screenPos- will contain screen space position for reflection or screenspace effects.- 已经定义好了屏幕坐标...不要在WVP了...
float3 worldPos- will contain world space position.float3 worldRefl- will contain world reflection vector if surface shader does not write to o.Normal. See Reflect-Diffuse shader for example.float3 worldNormal- will contain world normal vector if surface shader does not write to o.Normal.float3 worldRefl; INTERNAL_DATA- will contain world reflection vector if surface shader writes to o.Normal. To get the reflection vector based on per-pixel normal map, useWorldReflectionVector (IN, o.Normal). See Reflect-Bumped shader for example.float3 worldNormal; INTERNAL_DATA- will contain world normal vector if surface shader writes to o.Normal. To get the normal vector based on per-pixel normal map, useWorldNormalVector (IN, o.Normal).
总结:surface shader为了快速开发。预先定义好了output和input结构;一些常见光源。
u3d_shader_surface_shader_1的更多相关文章
随机推荐
- javascript --- 实时监听输入框值的变化
实时监听文本框值变化是非常常见的功能,通常最简单的办法就是用keyup,keydown来实现,但是这种方法有两个问题,一个是当直接复制粘贴的时候没法监听到事件,另外一个问题是在移动端,使用删除键删除输 ...
- HTML <base> 标签 为页面上的所有链接规定默认地址或默认目标
定义和用法 <base> 标签为页面上的所有链接规定默认地址或默认目标. 通常情况下,浏览器会从当前文档的 URL 中提取相应的元素来填写相对 URL 中的空白. 使用 <base& ...
- MS15-020漏洞测试
名称:Microsoft DLL植入远程代码执行漏洞(CVE-2015-0096)(MS15-020) 了解:Microsoft Windows没有正确处理DLL文件的加载,存在远程代码执行漏洞,通过 ...
- 为什么你找不到优秀的GISer?
每年的三四月是招聘的黄金时节,故有金三银四的说法.求贤纳才对于处在发展上升期的公司来说,是全年性的常态化工作.只是这俩月市场上求职者数量较别的月份多.基数大了,淘到金子的概率自然会增加.大部分公司的伯 ...
- Android 项目实战--手机卫士(实现splash)
从今天开始根据之前学习的android的基础知识,实战一下,实现一个简单功能的android手机卫士 本文地址:http://www.cnblogs.com/wuyudong/p/5899283.ht ...
- 深入浅出Block的方方面面
内容大纲: 1.Blocks概要 2.Blocks模式 3.Block实质(面试常问重点) 1.Blocks概要 什么是Blocks:Blocks是C语言的扩充的功能,可以用一句话来表示Blocks的 ...
- 转:JQuery.Ajax之错误调试帮助信息
今天发现一篇讲Ajax比较好的文章,汇总下,作为自己的知识储备. 下面是Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. typ ...
- mac 终端 常用指令
开始正式研究ios 应用开发,由于是从C开始学起,所以学习下常用的mac终端指令,方便后续常用操作. mac 终端 常用指令: 1.ls指令 用途:列出文件 常用参数 -w 以简洁的形式列出所有文件和 ...
- ORACLE关于索引是否需要定期重建争论的整理
ORACLE数据库中的索引到底要不要定期重建呢? 如果不需要定期重建,那么理由是什么? 如果需要定期重建,那么理由又是什么?另外,如果需要定期重建,那么满足那些条件的索引才需要重建呢?关于这个问题,网 ...
- Java并发之工具类 ForkJoin 任务分解
Fork/Join框架的介绍 第一步分割任务.首先我们需要有一个fork类来把大任务分割成子任务,有可能子任务还是很大,所以还需要不停的分割,直到分割出的子任务足够小. 第二步执行任务并合并结果.分割 ...