【发布时间】:2016-07-31 21:49:15
【问题描述】:
我有这个着色器,它以给定的速度偏移纹理(模拟水流、熔岩、通常的东西)。它工作正常,除了正常的纹理,由于某种原因,即使我使用相同的代码也不会偏移。谁能明白为什么?应用于对象时,主纹理会滚动,但法线保持在同一位置。
Shader "mrpmorris/Scrolling shader" {
Properties{
_MainTint("Diffuse tint", Color) = (1,1,1,1)
_MainTex("Base (RGB)", 2D) = "white" {}
_NormalTex("Normap map", 2D) = "bump" {}
_ScrollXSpeed("X scroll speed", Range(-10, 10)) = 0
_ScrollYSpeed("Y scroll speed", Range(-10, 10)) = -0.4
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
fixed4 _MainTint;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
sampler2D _MainTex;
sampler2D _NormalTex;
struct Input {
float2 uv_MainTex;
float2 uv_NormalTex;
};
void surf(Input IN, inout SurfaceOutputStandard o) {
fixed offsetX = _ScrollXSpeed * _Time;
fixed offsetY = _ScrollYSpeed * _Time;
fixed2 offsetUV = fixed2(offsetX, offsetY);
fixed2 normalUV = IN.uv_NormalTex + offsetUV;
fixed2 mainUV = IN.uv_MainTex + offsetUV;
float4 normalPixel = tex2D(_NormalTex, normalUV);
float3 n = UnpackNormal(normalPixel);
float4 c = tex2D(_MainTex, mainUV);
o.Albedo = c.rgb * _MainTint;
o.Normal = n.xyz;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
【问题讨论】: