I have a need to update a standard unity shader, in this case the Mobile/Diffuse shader. Essentially I want to add in some extra effects such as clouds and waves etc. The code for the built in shader is:
Shader "Mobile/Diffuse" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 150
CGPROGRAM
#pragma surface surf Lambert noforwardadd
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
I have implemented these effects already in my own shader, where I used vertex and frag functions to create the effects. My shader can be seen here:
Shader "Unlit/MyShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Clouds ("Clouds", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct MeshData
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
};
sampler2D _MainTex;
sampler2D _Clouds;
float4 _MainTex_ST; // optional - Scaling and Tiling options in the editor
v2f vert (MeshData v)
{
v2f o;
o.worldPos = mul(UNITY_MATRIX_M, v.vertex); // object to world
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.uv += _Time.y * 0.03;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 topDownProjection = i.worldPos.xz; // shade according to xz world position
fixed4 moss = tex2D(_MainTex, topDownProjection); // read the moss texture from top down
float clouds = tex2D(_Clouds, i.uv); // sample the clouds texture
// Create a lerp effect between the moss and a white color, using the clouds
float4 finalColor = lerp(float4(1,1,1,1), moss, clouds);
return finalColor;
}
ENDCG
}
}
}
The problem is that I don’t know how to adapt my code into the standard shader, since it does not have vert or frag functions. I’ve tried hacking together a solution but I always get errors. I’m new to shaders so if anyone could point me in the right direction that would be really appreciated. Can I somehow adapt my code into the “Input” or “surf” functions? I never saw these when doing shader tutorials so I’m not sure what they mean.