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 colorfixed3 Normal;  // tangent space normal, if writtenfixed3 Emission;half Specular;  // specular power in 0..1 rangefixed Gloss;    // specular intensityfixed 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结构;一些常见光源。

转载于:https://www.cnblogs.com/sun-shadow/p/4749477.html

u3d_shader_surface_shader_1相关推荐

最新文章

  1. ❤比较两种模糊特效❤filter: blur(10px)和backdrop-filter: blur(10px)的区别
  2. MaxCompute Studio使用心得系列7—作业对比
  3. 南方科技大学唐圆圆组招聘环境相关领域科研人才(年薪33~50万)
  4. 微信小游戏 demo 飞机大战 代码分析(四)(enemy.js, bullet.js, index.js)
  5. java空值转datetime,关于java1.8中LocalDateTime实现日期,字符串互转小坑。
  6. struts2和springmvc实现文件上传
  7. unity3d 随机生成地形之随机山脉
  8. List的4种迭代方法
  9. 软件测试遇到的异常情况,豪之诺软件测试项目开发中遇到比较多的Bug总结
  10. 一个XML Schema及XML文档(联系人)
  11. php将数组值用 分开,PHP将数组分成基于相等值的组
  12. django学习----01HelloWorld
  13. Spring Boot RestTemplate 忽略证书访问https
  14. 面试题 | ISP 图像处理算法工程师
  15. 计算机u盘被禁用怎么办,电脑U盘启动被禁用了怎么解决 电脑禁用u盘怎样恢复...
  16. 目录_Java内存分配(直接内存、堆内存、Unsafel类、内存映射文件)
  17. 长治南垂驾校科目二经验总结
  18. uni-app设置页面背景及背景图片
  19. python set(集合) 与 and 、 | 与 or之间的区别
  20. 浪潮ps9.0 oracle,浪潮ERP-PS V9.1安装手册.doc

热门文章

  1. python读json文件太大github_GitHub上最火的开源项目是啥|JSON文件实战处理
  2. 【线性查询之间存在相关性误差】差分隐私系统学习记录(七)
  3. hive相关操作语句
  4. ubuntu内核损坏或误删除时的系统修复
  5. 从Ubuntu 14 04 LTS版升级到Ubuntu 16 04 LTS
  6. CentOs基础操作指令(vim、关机)
  7. 以太网接口MII,RMII,SMII,GMII总线接口简介
  8. 天正暖通天圆地方在哪_2020位于太白山景区海拔3511米天圆地方景点就变成了很多人望而却步的地方_天圆地方-评论-去哪儿攻略...
  9. mpi如何选择合适的进程数量_洗涤工厂如何选择合适的洗衣龙
  10. vue监听字符串长度_Vue 的 computed 和 watch 的区别