12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 3666|回复: 11
打印 上一主题 下一主题

Unity的shader,帮助手册(三)

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-12-19 17:24:32 |只看该作者 |倒序浏览


  假如你开启一个既有的复合shader,刚开始看可能会觉得有点难,在开始以前,我们将详细说明unity内建的VertexLit shader。这个shader使用fixed function pipeline产生标准的per-vertex照明。
Shader "VertexLit" {   

     Properties {   

         _Color ("Main Color", Color) = (1,1,1,0.5)   

         _SpecColor ("Spec Color", Color) = (1,1,1,1)   

         _Emission ("Emmisive Color", Color) = (0,0,0,0)   

         _Shininess ("Shininess", Range (0.01, 1)) = 0.7   

         _MainTex ("Base (RGB)", 2D) = "white" { }   

     }   

  

     SubShader {   

         Pass {   

             Material {   

                Diffuse [_Color]   

                 Ambient [_Color]   

                Shininess [_Shininess]   

                 Specular [_SpecColor]   

                 Emission [_Emission]   

             }   

             Lighting On   

             SeperateSpecular On   

             SetTexture [_MainTex] {   

                 constantColor [_Color]   

                 Combine texture * primary DOUBLE, texture * constant   

             }   

         }   

     }   

}  

Shader "VertexLit" {

     Properties {

         _Color ("Main Color", Color) = (1,1,1,0.5)

         _SpecColor ("Spec Color", Color) = (1,1,1,1)

         _Emission ("Emmisive Color", Color) = (0,0,0,0)

         _Shininess ("Shininess", Range (0.01, 1)) = 0.7

         _MainTex ("Base (RGB)", 2D) = "white" { }

     }
     SubShader {

         Pass {

             Material {

                Diffuse [_Color]

                 Ambient [_Color]

                Shininess [_Shininess]

                 Specular [_SpecColor]

                 Emission [_Emission]

             }

             Lighting On

             SeperateSpecular On

             SetTexture [_MainTex] {

                 constantColor [_Color]

                 Combine texture * primary DOUBLE, texture * constant

             }

         }

     }

}


All shaders start with the keyword Shader followed by a string that represents the name of the shader. This is the name that is shown in the Inspector. All code for this shader must be put within the curly braces after it: { } (called a block).

  所有的shaders都必须以Shader作为开始,接着是这个shader的名称(例如:VertexLit),这个名称将会显示于检视器(Inspector)。所有的语法都必须放在{ }之内。
The name should be short and descriptive. It does not have to match the .shader file name.

  这个名称必须短且足以代表其功能,它并不会等于.shader的档案名称
To put shaders in submenus in Unity, use slashes - eg MyShaders/Test would be shown as Test in a submenu called MyShaders, or MyShaders->Test.

  如果要把shaders放在unity的submenus下面,请使用斜线,例如:MyShaders/Test,你将会看到有个submenu名为MyShaders,下面有个shader名为Test,或是像这样MyShaders->Test
The shader is composed of a Properties block followed by SubShader blocks. Each of these is described in sections below.

  在Properties block下面接着的是SubShader block,每个描述都在这个段落中

Properties
At the beginning of the shader block you can define any properties that artists can edit in the Material Inspector. In the VertexLit example the properties look like this:

properties位于shader block一开始的位置,你可以定义任何性质,这些性质将可在材质检视器中编辑,在VertexLit的个范例中,properties block看起来像这样:

图片一
The properties are listed on separate lines within the Properties block. Each property starts with the internal name (Color, MainTex). After this in parentheses comes the name shown in the inspector and the type of the property. After that, the default value for this property is listed:

   properties block内的语法都是单行的,每一个性质描述都由内名称开始(例如:Color, MainTex),在后方的括弧号中所显示的名字也会显示于inspector检视器上,在此之后,描述的是该性质的预设值

图片二
The list of possible types are in the Properties Reference. The default value depends on the property type. In the example of a color, the default value should be a four component vector.

  可用的性质类型请参考Properties Reference。预设值与性质有关,以color为例,预设值应该由四个值组成
We now have our properties defined, and are ready to start writing the actual shader.

  现在我们已经定义了四个性质,可以开始撰写实际的shader了
The Shader Body

Before we move on, let's define the basic s***cture of a shader file.

  在开始以前,先了解shader的结构是如何定义的
Different graphic hardware has different capabilities. For example, some graphics cards support fragment programs and others don't; some can lay down four textures per pass while the others can do only two or one; etc. To allow you to make full use of whatever hardware your user has, a shader can contain multiple SubShaders. When Unity renders a shader, it will go over all subshaders and use the first one that the hardware supports.

  不同的绘图卡有不同的能力,例如:有的绘图卡支援fragment programs但有些没有,有些可以一次处理四个贴图?(four textures)其他的可能只能处理两个或一个,为了要符合所有用户的硬体需求,一个shader可以包涵多个SubShaders,当unity在运算shader时,它将详细察看所有的subshaders而且使用硬体可支持的第一个。
Shader "S***cture Example" {   

     Properties { /* ...shader properties... }   

     SubShader {   

         // ...subshader that uses vertex/fragment programs...   

     }   

     SubShader {   

         // ...subshader that uses four textures per pass...   

     }   

     SubShader {   

         // ...subshader that uses two textures per pass...   

     }   

     SubShader {   

         // ...subshader that might look ugly but***ns on anything : )   

     }   

}  

Shader "S***cture Example" {

     Properties { /* ...shader properties... }

     SubShader {

         // ...subshader that uses vertex/fragment programs...

     }

     SubShader {

         // ...subshader that uses four textures per pass...

     }

     SubShader {

         // ...subshader that uses two textures per pass...

     }

     SubShader {

         // ...subshader that might look ugly but***ns on anything : )

     }

}
This system allows Unity to support all existing hardware and maximize the quality on each one. It does, however, result in some long shaders.
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-3-2 23:28:06 |只看该作者
精典,学习了!
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-3-22 23:22:02 |只看该作者
既来之,则看之!
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-4-5 23:19:48 |只看该作者
读铁系缘分,顶铁系友情
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

5#
发表于 2012-4-11 23:18:18 |只看该作者
读铁系缘分,顶铁系友情
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-5-12 23:24:16 |只看该作者
呵呵,很好,方便罗。
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

7#
发表于 2012-6-8 23:25:38 |只看该作者
谢谢楼主,真是太实用了
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

8#
发表于 2012-6-24 23:26:12 |只看该作者
有意思!学习了!
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

9#
发表于 2012-8-8 01:40:24 |只看该作者
其实楼主所说的这些,俺支很少用!
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

10#
发表于 2012-9-28 23:20:40 |只看该作者
“再次路过……”我造一个-----特别路过
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-9-20 15:27 , Processed in 0.096539 second(s), 32 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部