I'll help you create a basic Gouraud shader for Unity's built-in render pipeline. Gouraud shading interpolates lighting calculations at vertices rather than per-pixel like Phong shading.
shader Copy code
Shader "Custom/GouraudShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf GouraudShading fullforwardshadows vertex:vert
#pragma target 3.0
sampler2D _MainTex;
fixed4 _Color;
half _Glossiness;
half _Metallic;
struct Input
{
float2 uv_MainTex;
float3 vertexLighting;
};
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
// Calculate vertex lighting
o.vertexLighting = 0;
#ifdef VERTEXLIGHT_ON
o.vertexLighting = Shade4PointLights(
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb,
unity_LightColor[2].rgb, unity_LightColor[3].rgb,
unity_4LightAtten0, worldPos, worldNormal
);
#endif
}
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Emission = IN.vertexLighting;
}
half4 LightingGouraudShading(SurfaceOutput s, half3 lightDir, half atten)
{
half NdotL = max(0, dot(s.Normal, lightDir));
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}
Would you like me to explain any particular part in more detail or add specific features like specular highlighting?