这是“Unity Shaders and Effects Cookbook”中的一个示例。
它不应该对视图更改作出反应,但确实如此。
有人能说我吗?
我使用unity 5.0
Shader"CookbookShaders/Chapter05/LitSphere"
{
Properties
{
_MainTint ("Diffuse Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_NormalMap ("Normal Map", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Unlit vertex:vert
#pragma target 3.0
sampler2D _MainTex;
sampler2D _NormalMap;
float4 _MainTint;
inline fixed4 LightingUnlit (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c = fixed4(1,1,1,1);
c.rgb = c * s.Albedo;
c.a = s.Alpha;
return c;
}
struct Input
{
float2 uv_MainTex;
float2 uv_NormalMap;
float3 tan1;
float3 tan2;
};
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
TANGENT_SPACE_ROTATION;
o.tan1 = mul(rotation, UNITY_MATRIX_IT_MV[0].xyz);
o.tan2 = mul(rotation, UNITY_MATRIX_IT_MV[1].xyz);
}
void surf (Input IN, inout SurfaceOutput o)
{
float3 normals = UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));
o.Normal = normals;
float2 litSphereUV;
litSphereUV.x = dot(IN.tan1, o.Normal);
litSphereUV.y = dot(IN.tan2, o.Normal);
half4 c = tex2D (_MainTex, litSphereUV*0.5+0.5);
o.Albedo = c.rgb * _MainTint;
o.Alpha = c.a;
}
ENDCG
}
//FallBack "Diffuse"
}
答案 0 :(得分:0)
虽然没有viewDir,但UNITY_MATRIX_IT_MV会随着视图的变化而变化。