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的更多相关文章
随机推荐
- iOS 判断数组是否为空
有人说可以用([array count]==0 )来判断是否为空,都是坑,如果array为空的话,执行count就会直接报错,程序崩溃退出. 正确判断NSArray是否为空的方法:用 (!array) ...
- BPM配置故事之案例8-根据表单数据调整审批线路
Boss突然来到:小明啊,咱们的物资申请金额现在既然可以确定了,以后金额在1万以下的申请单,就不用我审批了.直接通过就行了. 小明:好的 然后小明把流程线路改成了这样. 线路条件1 线路条件2
- 如何为基于windows验证的站点的某个页面、文件或文件夹单独设置匿名访问
在MOSS的项目中,我们经常碰到要单独为基于windows验证的站点的某个页面.文件或文件夹单独设置匿名访问即不登录就可以直接访问.比如说站点的A的某些图片或文件URL存在B站点下的文件夹下.此时访问 ...
- git 删除远程源,新增加源
git remote remove origin git remote add origin git@XXXX
- Android Studio简单设置
IDE外观&行为 修改主题,修改全局字体 修改主题,想用炫酷的深色主题,就改成Darcula吧:字体的话,选一个带中文的,要不然会有很多口口,我这里用Microsoft YaHei UI,很不 ...
- (20160601)开源第三方学习之SVProgressHUD
SVProgressHUD相信在很多项目中都有运用,运用于弹出窗提示效果: 地址:https://github.com/SVProgressHUD/SVProgressHUD 一:插件的运用 1.1 ...
- 干货之运用CALayer创建星级评分组件(五角星)
本篇记录星级评分组件的创建过程以及CALayer的运用. 为了实现一个星级评分的组件,使用了CALayer,涉及到mask.CGPathRef.UIBezierPath.动画和一个计算多角星关键节点的 ...
- 【代码笔记】iOS-竖排文字
一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...
- OC NSArray 数组
# OC NSArray 数组 NSArray常用方法 获取数组中第一位元素 array.firstObject 获取数组中最后一个元素 array.lastObject 获取数组中指定索引下标的元素 ...
- 列式存储(三)JFinal DB.tx()事务
上一篇中说道了列式存储中新增表单时后台接收数据问题,在存入数据库时一次插入多条数据,就要用到事务. JFinal中有个封装好的事务应用,用起来非常方便简单. 写法1: Db.tx(new IAtom( ...