2018年1月
Computer Shader 会产生一种特殊的Shader文件,这类Shader旨在利用GPU的并行性来进行一些与常规渲染流水线无关的计算
每个Pass定义了一次完整的渲染流程
git Cherry Pick
在Unity中,我们需要使用纹理名_ST的方式来声明某个纹理的属性.其中,ST是缩放(scale [Tilling])和平移(translation [Offset])的缩写
_纹理名_ST可以让我们得到该纹理的缩放和平移(偏移)值,_纹理名_ST.xy存储的是缩放值,而_纹理名_ST.zw存储的是偏移值
纹理Wrap Mode
它决定了当纹理坐标超过[0,1]范围后将会如何被平铺.Wrap Mode有两种模式:一种是Repeat,在这种模式下,如果纹理坐标超过了1,那么它的整数部分将会被舍弃,
而直接使用小数部分进行采样,这样的结果是纹理将会不断重复;另一种是Clamp,在这种模式下,如果纹理坐标大于1,那么将会截取到1,如果小于0,那么将会截取到0
// Declares 3x3 matrix 'rotation',filled with tangent space basis
#define TANGENT_SPACE_ROTATION \
// Compute the binormal
float3 binormal = cross( normalize(v.normal),normalize(v.tangent.xyz) ) * v.tangent.w; \
// Construct a matrix which transform vectors from object space to tangent space
float3x3 rotation = float3x3(v.tangent.xyz,binormal,v.normal);
#define UNITY_MATRIX_M unity_ObjectToWorld
// Computes object space light direction
inline float3 ObjSpaceLightDir(in float4 v) {
float3 objSpaceLightPos = mul(unity_WorldToObject,_WorldSpaceLightPos0).xyz;
#ifndef USING_LIGHT_MULTI_COMPILE
return objSpaceLightPos.xyz - v.xyz * _WorldSpaceLightPos0.w;
#else
#ifndef USING_DIRECTIONAL_LIGHT
return objSpaceLightPos.xyz - v.xyz;
#else
return objSpaceLightPos.xyz;
#endif
#endif
}
// Computes object space view direction
inline float3 ObjSpaceViewDir(in float4 v){
float3 objSpaceCameraPos = mul(unity_WorldToObject,float4(_WorldSpaceCameraPos.xyz,1)).xyz;
return objSpaceCameraPos - v.xyz;
}
inline fixed3 UnpackNormalDXT5nm(fixed4 packednormal){
fixed3 normal;
normal.xy = packednormal.wy * 2 - 1;
normal.z = sqrt(1 - saturate(dot(normal.xy,normal.xy)));
return normal;
}
// Unpack normal as DXT5nm(1,y,1,x) or BC5(x,y,0,1)
// Note neutral texture like "bump" is (0,0,1,1) to work with both plain RGB normal and DXT5nm/BC5
fixed3 UnpackNormalmapRGorAG(fixed4 packednormal){
// This do the trick
packednormal.x *= packednormal.w;
fixed3 normal;
normal.xy = packednormal.xy * 2 - 1;
normal.z = sqrt(1 - saturate(dot(normal.xy,normal.xy));
return normal;
}
inline fixed3 UnpackNormal(fixed4 packednormal){
#if defined(UNITY_NO_DXT5nm)
return packednormal.xyz * 2 - 1;
#else
return UnpackNormalmapRGorAG(packednormal);
#endif
}
// Transforms 2D UV by scale/bias property
#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
// Transforms direction from object to world space
inline float3 UnityObjectToWorldDir(in float3 dir){
return normalize(mul((float3x3)unity_ObjectToWorld,dir));
}
// Transforms direction from world to object space
inline float3 UnityWorldToObjectDir(in float3 dir){
return normalize(mul((float3x3)unity_WorldToObject,dir));
}
// Transform normal from object to world space
inline float3 UnityObjectToWorldNormal(in float3 norm) {
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return UnityObjectToWorldDir(norm);
#else
// mul(IT_M,norm) => mul(norm,I_M) => {dot(norm,I_M.col0),dot(norm,I_M.col1),dot(norm,I_M.col2)}
return normalize(mul(norm,(float3x3)unity_WorldToObject));
}
// Computes world space light direction,from world space position
inline float3 UnityWorldSpaceLightDir(in float3 worldPos){
#ifndef USING_LIGHT_MULTI_COMPILE
return _WorldSpaceLightPos0.xyz - worldPos * _WorldSpaceLightPos0.w;
#else
#ifndef USING_DIRECTIONAL_LIGHT
return _WorldSpaceLightPos0.xyz - worldPos;
#else
return _WorldSpaceLightPos0.xyz;
#endif
#endif
}
// Computes world space light direction,from object space position
// *Legacy* Please use UnityWorldSpaceLightDir instead
inline float3 WorldSpaceLightDir(in float4 localPos) {
float3 worldPos = mul(unity_ObjectToWorld,localPos).xyz;
return UnityWorldSpaceLightDir(worldPos);
}
// Computes world space view direction, from object space position
inline float3 UnityWorldSpaceViewDir(in float3 worldPos){
return _WorldSpaceCameraPos.xyz - worldPos;
}
// Computes world space view direction,from object space position
// *Legacy* Please use UnityWorldSpaceViewDir instead
inline float3 WorldSpaceViewDir(in float4 localPos){
float3 worldPos = mul(unity_ObjectToWorld,localPos).xyz;
return UnityWorldSpaceViewDir(worldPos);
}
Blend SrcAlpha OneMinusSrcAlpha
DstColor[new] = SrcAlpha x SrcColor + (1-SrcAlhpa) x DstColor[old]
ColorMask RGB | A | 0 | 其他任何R,G,B,A的组合