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.float4
withCOLOR
semantic - 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 函数初探 (六)--- 闭包初探#1
首先我们来看一个函数: var a = 'global variable'; var F = function(){ var b = 'local variable'; var N = functio ...
- 直接拿来用!十大Material Design开源项目
来自:http://www.csdn.net/article/2014-11-21/2822753-material-design-libs/1 介于拟物和扁平之间的Material Design自面 ...
- Android Animation学习(四) ApiDemos解析:多属性动画
Android Animation学习(四) ApiDemos解析:多属性动画 如果想同时改变多个属性,根据前面所学的,比较显而易见的一种思路是构造多个对象Animator , ( Animator可 ...
- Xcode 7中http通信出现如下错误:Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
原因 在iOS9 beta1中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据. 解决方法 编辑 info.plist,加入如下设置: <plist> & ...
- JSONKit does not support Objective-C Automatic Reference Counting(ARC) / ARC forbids Objective-C objects in struct
当我们在使用JSONKit处理数据时,直接将文件拉进项目往往会报这两个错“JSONKit does not support Objective-C Automatic Reference Coun ...
- 编译生成IOS开发使用的FFmpeg的过程
前言:本篇随笔纯属是参照<iOS 使用 FFmpeg>的过程,本人自己操作了一遍,但是本人记性不好,觉得这样的过程可以记录在博客中,以后需要可以快速回头翻阅细节.所以特地参考<iOS ...
- google不能访问的根本解决方法
最近中国的防火墙又调皮了.直接出现404了.以前通过IP访问的方式也失效了.难道这种问题能难倒我们这些做技术的IT工程师么?! 经过我的查询,我发现还是有大神在研究这块的.大神针对开发经常访问的网站做 ...
- JavaScript Patterns 4.10 Curry
Function Application apply() takes two parameters: the first one is an object to bind to this inside ...
- Protocol 编码的三种常用方式
1.使用固定长度 2.使用固定长度的请求头,请求头中说明了body的长度. 例如HTTP 协议: http请求协议: http 响应协议: 3.使用界定符.例如有很多基于text(文本)协议都会在每个 ...
- AS与.net的交互——加载web上的xml
最近搞了个私活,需要用as去加载一个网站的xml,不过本人as也不咋滴,就去看看怎么玩,看完之后也蛮简单的. 由于业务上比较复杂,就随便说个小例子吧. 很多时候,为了页面区域更加灵活,生动,有吸引力, ...