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. vue单页面程序

    gitHub地址:https://github.com/lily1010/vue_singlePage 举个栗子: <!DOCTYPE html> <html> <hea ...

  2. SharePoint 2013 WebPart 管理工具分享[开源]

    前言 之前做门户的时候,经常要导入导出WebPart,非常的频繁,然后就需要一个个导出,然后一个个导入,非常繁琐:闲暇之际,就考虑能不能自动化一下,把这个功能写成一个工具,可以方便的管理WebPart ...

  3. SharePoint 2013 Designer 自定义操作菜单

    众所周知,我们在SharePoint的二次开发中,经常会添加ECB菜单或者Ribbon菜单,通常我们会采取Feature的方式去添加一个Xml,或者采取JavaScript的方式,当然,除此之外,还可 ...

  4. Android 触摸手势基础 官方文档概览

    Android 触摸手势基础 官方文档概览 触摸手势检测基础 手势检测一般包含两个阶段: 1.获取touch事件数据 2.解析这些数据,看它们是否满足你的应用所支持的某种手势. 相关API: Moti ...

  5. 腾讯bugly团队提供的android国内镜像

    腾讯bugly团队提供的国内镜像   如果使用Android SDK Manager下载比较慢或者打不开,可以使用国内镜像 使用说明 http://android-mirror.bugly.qq.co ...

  6. popover带箭头弹框

    我们先来看一下效果吧: 分析:这个带箭头的弹框其实是一个控制器,通过Modal方式展现,但跟传统模态方式效果不一样,我们一眼就能看出. Xib方式实现popover: 1.segue的时候选择Pres ...

  7. android 显示 PDF 文件

    1.开源项目地址 : https://github.com/JoanZapata/android-pdfview 2.引用 compile 'com.joanzapata.pdfview:androi ...

  8. Java Collection Framework概述

    文章出自:听云博客 Collection概述 Java collection是java提供的工具包,包含了常用的数据结构:集合.链表.队列.栈.数组.映射等. Java集合主要可以划分为4个部分:Li ...

  9. iOS开发--Swift 最近项目开发中遇到的一些小问题与解决方法

    1, Swift 修改导航栏颜色 self.navigationController?.navigationBar.barTintColor 2, Swift button 属性设置时直接进行初始化 ...

  10. iOS沙盒目录结构解析

    iOS沙盒目录结构解析 原文地址:http://blog.csdn.net/wzzvictory/article/details/18269713     出于安全考虑,iOS系统的沙盒机制规定每个应 ...