Unity中Shader学习笔记

1、Shader 中 Properties 属性:

Numbers and Sliders

name ("display name", 2D) = "defaulttexture" {}
name ("display name", Cube) = "defaulttexture" {}
name ("display name", 3D) = "defaulttexture" {}

Colors and Vectors

 

name ("display name", Color) = (number,number,number,number)

 

name ("display name", Vector) = (number,number,number,number)

Textures

 

name ("display name", 2D) = "defaulttexture" {}
name ("display name", Cube) = "defaulttexture" {}

 

name ("display name", 3D) = "defaulttexture" {}

2、Shader 中 #include 外部引用:

HLSLSupport.cginc ==>辅助宏和跨平台着色编译的定义。

UnityShaderVariables.cginc ==>常用的全局变量。

UnityCG.cginc ==>常用的辅助函数。

AutoLight.cginc ==>照明和阴影功能,例如,表面着色器在内部使用这个文件。

Lighting.cginc ==>标准的表面着色照明模型;当你在写表面着色器时自动包含。

TerrainEngine.cginc ==>地形和植被阴影的辅助功能。

3、Shader 中 #Pragma 编辑:

#pragma vertex name - 编译函数名作为顶点着色器。
#pragma fragment name - 编译函数名作为片段着色器。
#pragma geometry name编译函数名为DX10几何着色器。有了这个选项,就会自动打开“目标4.0”
#pragma hull name编译函数名为DX11外壳着色器。有了这个选项,就会自动打开目标5.0

#pragma domain name - 编译函数名为DX11域着色器。有了这个选项,就会自动打开目标5.0

//其他的编辑指令

#pragma target name - 哪个着色器目标要编译。有关详细信息,请参见着色器编译目标页面。
#pragma only_renderers space separated names 只对给定的渲染器编译着色器。默认的着色器是为所有渲染器编译的。请参阅下面的渲染器以获得详细信息。
#pragma exclude_renderers space separated names - 不要为给定的渲染器编译着色器。默认的着色器是为所有渲染器编译的。请参阅下面的渲染器以获得详细信息。
#pragma multi_compile … - 用于处理多个着色器变体。
#pragma enable_d3d11_debug_symbols - 为DirectX 11编译的着色器生成调试信息,这将允许您通过Visual Studio 2012(或更高)的图形调试器调试着色器。
#pragma hardware_tier_variants renderer name - 为每个可运行选定的渲染器的硬件层生成多个着色器硬件变体。请参阅下面的渲染器以获得详细信息。

//2018.09.20

1、Material { Material Block } 材质

定义了 1 个顶点光照管道使用的材质

2、Lighting On  \   Off     开启/关闭灯光

关闭或开启顶点光照

3、Cull Back / Front / Off    裁剪背面 / 前面 / 关闭

设置多边形的裁剪模式

4、 ZTest ( Less / Greater / LEqual / GEqual / Equal / NotEqual / Always )

设置深度测试模式(OpenGL 深度其实就是该象素点在3d世界中距离摄象机的距离,深度缓存中存储着每个象素点(绘制在屏幕上的)的深度值!深度测试决定了是否绘制较远的象素点(或较近的象素点),通常选用较近的,而较远优先能实现透视的效果!)

5、 ZWrite On / Off

设置深度写模式类型

6、 Fog { Fog Block }

设置雾化类型

7、 AlphaTest ( Less / Greater / LEqual / GEqual / Equal / NotEqual / Always ) CutoffValue

开启Alpha测试

8、 Blend SourceBlendMode DestBlendMode

设置Alpha混合模式

9、 Color color value

设置颜色,当顶点光效关闭时有效

10、 ColorMask RGB / A / 0 / any combination of R, G, B, A

设置颜色遮罩模式。将ColorMask设置为0表示关闭多有渲染的颜色管道。

11、 Offset OffsetFactor , OffsetUnits

设置深度偏移。提示:这个命令仅接受Unity3 3D的常数参数(不是Shader的参数)。
用于为图形设置深度的偏移
这个函数一般用于当两图形刚上处于同坐标或两个面在同一坐标重叠时。可以通过这个函数让其中一个图形或面的坐标自动偏移。 

12、 SeparateSpecular On | Off

关闭或打开顶点照明单独的镜面反射光的颜色。

13、 ColorMaterial AmbientAndDiffuse | Emission 环境和漫反射|放射

计算顶点照明时使用的每个顶点颜色

14、 Texture Setup 纹理设置

当渲染状态设置以后,你可以用SetTexture命令指定这些纹理和他们的结合方式。

15、 SetTexture texture property { [Combine options] } 设置纹理

纹理设置固定功能的多纹理管线,如果使用定制的片断着色器将被忽略。

16、 Per-pixel Lighting 逐像素光照

逐像素光照管道的工作依赖于渲染对象在多个pass中。Unity3D一旦获得环境光和任何顶点的光照就开始渲染物体。然后,它在一个单独添加的pass中影响渲染的物体每1个光照的像素。

17、Per-vertex Lighting 逐顶点光照

逐顶点光照是Direct3d/OpenGl的标准光照模式,它的计算依赖于每一个顶点。打开光照后才能启动逐顶点光照。光照受Materialblock, ColorMaterial 和 SeparateSpecular命令影响。 

 

//Shader中Blending 模式

Blend operations

The following blend operations can be used:

  
AddAdd source and destination together.
SubSubtract destination from source.
RevSubSubtract source from destination.
MinUse the smaller of source and destination.
MaxUse the larger of source and destination.
LogicalClearLogical operation: Clear (0) DX11.1 only.
LogicalSetLogical operation: Set (1) DX11.1 only.
LogicalCopyLogical operation: Copy (s) DX11.1 only.
LogicalCopyInvertedLogical operation: Copy inverted (!s) DX11.1 only.
LogicalNoopLogical operation: Noop (d) DX11.1 only.
LogicalInvertLogical operation: Invert (!d) DX11.1 only.
LogicalAndLogical operation: And (s & d) DX11.1 only.
LogicalNandLogical operation: Nand !(s & d) DX11.1 only.
LogicalOrLogical operation: Or (s | d) DX11.1 only.
LogicalNorLogical operation: Nor !(s | d) DX11.1 only.
LogicalXorLogical operation: Xor (s ^ d) DX11.1 only.
LogicalEquivLogical operation: Equivalence !(s ^ d) DX11.1 only.
LogicalAndReverseLogical operation: Reverse And (s & !d) DX11.1 only.
LogicalAndInvertedLogical operation: Inverted And (!s & d) DX11.1 only.
LogicalOrReverseLogical operation: Reverse Or (s | !d) DX11.1 only.
LogicalOrInvertedLogical operation: Inverted Or (!s | d) DX11.1 only.

 

Blend factors

All following properties are valid for both SrcFactor & DstFactor in the Blend command. Source refers to the calculated color, Destination is the color already on the screen. The blend factors are ignored if BlendOp is using logical operations.

  
OneThe value of one - use this to let either the source or the destination color come through fully.
ZeroThe value zero - use this to remove either the source or the destination values.
SrcColorThe value of this stage is multiplied by the source color value.
SrcAlphaThe value of this stage is multiplied by the source alpha value.
DstColorThe value of this stage is multiplied by frame buffer source color value.
DstAlphaThe value of this stage is multiplied by frame buffer source alpha value.
OneMinusSrcColorThe value of this stage is multiplied by (1 - source color).
OneMinusSrcAlphaThe value of this stage is multiplied by (1 - source alpha).
OneMinusDstColorThe value of this stage is multiplied by (1 - destination color).
OneMinusDstAlphaThe value of this stage is multiplied by (1 - destination alpha).

 

Details

Below are the most common blend types
:

Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency
Blend One OneMinusSrcAlpha // Premultiplied transparency
Blend One One // Additive
Blend OneMinusDstColor One // Soft Additive
Blend DstColor Zero // Multiplicative
Blend DstColor SrcColor // 2x Multiplicative
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值