Unity Lights in my vertex/fragment shader

Hi,

I am trying to understand how to include and use unity autolight macros in my shader.

I tried exactly the code described here :
http://docs.unity3d.ru/Components/SL-Attenuation.html

But I am getting unxepected result: it doesn’t matter how I try to modify the output color variable, it seems that a perfect lambert which interacts with unity lights overwrites all my edits.

Just for example, I modified this:

// Vertex program
v2f vert (appdata_base v)
{
    v2f o;
    PositionFog( v.vertex, o.pos, o.fog );

    // compute a simple diffuse per-vertex
    float3 ldir = normalize( ObjSpaceLightDir( v.vertex ) );
    float diffuse = dot( v.normal, ldir );
    o.color = diffuse * _ModelLightColor0;

    // compute&pass data for attenuation/shadows
    TRANSFER_VERTEX_TO_FRAGMENT(o);
    return o;
}

into this:

v2f vert (appdata_base v)
{
    v2f o;
    PositionFog( v.vertex, o.pos, o.fog );

    o.color = float4(0.5, 0.5, 0.5, 0.5);

    // compute&pass data for attenuation/shadows
    TRANSFER_VERTEX_TO_FRAGMENT(o);
    return o;
}

It seems that adding "LIGHTING_COORDS " to the vert struct is enough to enable this strange behaviour
The only thing I can suppose, is that the shader goes to the line ‘Fallback “VertexLit”’, but I don’t know why this should happpen.

Help !

Sorry I have seen that Farfarer already asked about this here, but I didn’t get the reply.
Can someone give an example of how to use them in unity 3?

The best examples are the built-in shaders. Add the #pragma debug directive and then open the compiled shader to see the Cg produced by the surface shader compiler.

At a first sight I didn’t catch what you said, until I tried.
Oh my, I didn’t get that writing surface shaders is much less verbose than traditional vert/frag ones…
Thank you, this will be of great help !!!