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的更多相关文章
随机推荐
- SAP用户权限解剖及自修改
通常BASIS会使用PFCG做权限管理,时你保存时会产生一个系统外的profile name,记得SU01时用户有profile 和role两栏位吗?它们的关系如何呢? 首先明白几个概念.1.acti ...
- SharePoint 2013 同步FBA认证用户
SharePoint 开启了基于FBA的身份认证,经常会遇到用户组用户的问题,当我加入一个AD账号,无法同时加入Form认证的用户,这时,只能手动添加,比较麻烦:所以,写了一个服务,用来每天晚上同步一 ...
- [ javascript canvas isPointInPath(x,y) 判断点是否在最后绘制的图形中 ] javascript canvas isPointInPath(x,y) 判断点是否在最后绘制的图形中方法演示 效果之三
<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...
- Thoughts on an Article from Science 'A network framework of cultural history'
Apparently, this is an excellent interdisciplinary study. This paper drawn on a simple but large dat ...
- iOS开发UINavigation——导航控制器UINavigationController
iOS开发UINavigation系列一——导航栏UINavigtionBar摘要iOS中的导航条可以附着于导航控制器之中使用,也可以在controller中单独使用,这篇博客,主要讨论有关导航栏的使 ...
- Eclipse中Maven+Spring3.2.17+SpringMVC HelloWorld
遇到的问题 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path ...
- iOS 为视图添加抖动效果
抖动效果在开发中比较少用到,不过有时使用了确有个很好的装逼效果,用的时候就例如一些用户错误操作之类的 效果如下,不过gif看到的效果没实际的好看 上代码 - (void)shakeAnimationF ...
- 后台管理UI皮肤的选择
后台管理UI的选择 目录 一.EasyUI 二.DWZ JUI 三.HUI 四.BUI 五.Ace Admin 六.Metronic 七.H+ UI 八.Admin LTE 九.INSPINIA 十. ...
- Extjs插入图片
Extjs并没有提供直接的组件来显示图片.网上通过设置textfield的InputType为Image然后再修改dom对象来实现,其实 image的属性值并没有包含在Extjs的官方文档当中.可以通 ...
- MySQL 系列(五) 多实例、高可用生产环境实战
MySQL 系列(五) 多实例.高可用生产环境实战 第一篇:MySQL 系列(一) 生产标准线上环境安装配置案例及棘手问题解决 第二篇:MySQL 系列(二) 史上最屌.你不知道的数据库操作 第三 ...