赞
踩
determinant
transpose
UnityObjectToWorldDir(v.tangent.xyz);
UnityObjectToWorldNormal(v.normal)
cross
UnpackNormal
TANGENT_SPACE_ROTATION
TANGENT_SPACE_ROTATION 宏 相当于嵌入如下两行代码:
float3 binormal = cross( v.normal, v.tangent.xyz ) * v.tangent.w;
float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal );
也就是构造出 tangent space 的坐标系, 定义转换world space的向量到tangent space的rotation 矩阵。
TANGENT_SPACE_ROTATION这行代码之后,就可以用rotation这个代表从世界坐标到切线空间的矩阵了。不过要记得TANGENT_SPACE_ROTATION后面要加分号“;”的,比如:
- struct v2f
-
- {
-
- float4 pos:SV_POSITION;
-
- float2 uv:TEXCOORD0;
-
- float3 lightDir:TEXCOORD1;
-
- };
-
- v2f vert (appdata_full v)
-
- {
-
- v2f o;
-
- o.pos=UnityObjectToClipPos(v.vertex);
-
- o.uv=v.texcoord.xy;
-
- TANGENT_SPACE_ROTATION;
-
- o.lightDir= mul(unity_WorldToObject, _WorldSpaceLightPos0).xyz;//Direction Light
-
- o.lightDir=mul(rotation,o.lightDir);
-
- return o;
-
- }
-
- float4 frag(v2f i):COLOR
-
- {
-
- float3 N=UnpackNormal(tex2D(_BumpMap,i.uv));
-
- float diff=max(0,dot(N,i.lightDir));
-
- float4 c=_LightColor0diff;
-
- return c2;
-
- }
ObjSpaceLightDir
ObjSpaceViewDir
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。