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 with COLOR 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, use WorldReflectionVector (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, use WorldNormalVector (IN, o.Normal).

总结:surface shader为了快速开发。预先定义好了output和input结构;一些常见光源。

u3d_shader_surface_shader_1的更多相关文章

随机推荐

  1. 浅析css布局模型1

    css是网页的外衣,好不好看全凭css样式,而布局是css中比较重要的部分,下面来分析一下常见的几种布局. 流动模型 流动模型是网页布局的默认模式,也是最常见的布局模式,他有两个特点: 1.块状元素都 ...

  2. DEV控件:gridControl常用属性设置(转载)

    特别长,先撸下来再说 1.隐藏最上面的GroupPanel  gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值  sValue=T ...

  3. 分分钟学会系列:mac地址泛洪攻击实验

    一.实验目的: 通过实战深入理解mac地址泛洪攻击的原理. 二.实验原理: 交换机中有一张非常重要的表,叫做mac表,这个表是一个硬件组成的表,主要是完成快速转发.mac表有大小限制,不同的交换机的m ...

  4. git 新建服务器的版本以及项目的用户

    一, git客户端账号生成 1. git的客户端的公钥生成 ssh-keygen -t rsa -C "test@gmail.com" mac机器会在 /Users/用户/.ssh ...

  5. leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  6. Android Studio教程--给Android Studio安装Genymotion插件

    打开Android Studio,依次[File]-[Settings] 在打开的settings界面里找到plugins设置项,点击右侧的“Browser..”按钮 在搜索栏里输入genymotio ...

  7. 【VLC-Android】vlc-android简例

    前言 继续折腾vlc,做这个例子并不顺利,卡在只有声音没有图像这个问题好久,网上的例子有些API已经对不上,继续分享,,, 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cn ...

  8. store 加载异常处理与加载信息提示

    var msgTip = '';   // 一定要定义在使用前,且定义为全局变量 /--------------------------------store--------------------- ...

  9. Images.xcassets

    Images.xcassets 概述 功能 方便用户管理图像资源. 图片获取方式 Images.xcassets中的图片资源只能通过imageNamed:方法加载,通过NSBundle的pathFor ...

  10. IO流03--毕向东JAVA基础教程视频学习笔记

    提要 16 读取转换流17 写入转换流18 流操作规律-119 流操作规律-220 改变标准输入输出设备21 异常的日志信息22 系统信息 16 读取转换流 字符流体系中的InputStreamRea ...