Hey all!
So I am working on a mobile shader where I want it to transition from one texture to the next according to a noise map and a slider. Right now I manage to lerp between the two according to the slider position, but it struggles when it comes to using the noise texture. Anyone got any tips and tricks for this? I have tried some different approaches without any luck, but below you can see the shader as it is now:
Shader "Extra/MobileShader" {
Properties {
_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
_MainTexDirty ("Dirty Base (RGB) Gloss (A)", 2D) = "white" {}
_MainTexClean ("Clean Base (RGB) Glass (A)", 2D) = "white" {}
_NoiseTex ("Noise Texture", 2D) = "white" {}
_CleanSlider ("Cleaning the frame", Range (0 , 1)) = -1
[NoScaleOffset] _BumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 250
CGPROGRAM
#pragma target 3.0
#pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview interpolateview
inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
{
fixed diff = max (0, dot (s.Normal, lightDir));
fixed nh = max (0, dot (s.Normal, halfDir));
fixed spec = pow (nh, s.Specular*128) * s.Gloss;
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.b * spec) * atten;
UNITY_OPAQUE_ALPHA(c.a);
return c;
}
sampler2D _MainTexDirty;
sampler2D _MainTexClean;
sampler2D _NoiseTex;
sampler2D _BumpMap;
half _Shininess;
float _CleanSlider;
struct Input {
float2 uv_MainTexDirty;
float2 uv_MainTexClean;
float2 uv_NoiseTex;
//float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 color1 = tex2D(_MainTexDirty, IN.uv_MainTexDirty);
fixed4 color2 = tex2D(_MainTexClean, IN.uv_MainTexClean);
half4 n = tex2D(_NoiseTex, IN.uv_NoiseTex.xy);
fixed4 tex = lerp (color1, color2, n.r - _CleanSlider);
o.Albedo = tex.rgb;
o.Gloss = lerp (color1.a, color2.a, _CleanSlider);
o.Alpha = tex.a;
o.Specular = _Shininess;
o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_MainTexDirty));
}
ENDCG
}
FallBack "Mobile/VertexLit"
}