Could anybody tell me why

why cant direction light be accessed in vertex Shader,can anybody figure out why
//
Shader “Tut/Vertex/Direction_1_VertexLit” {
Properties {
_Color (“Base Color”, Color) =(1,1,1,1)
}
SubShader {
pass{
Tags{ “LightMode”=“Vertex”}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
#include “Lighting.cginc”

uniform float4 _Color;

struct vertOut{
float4 pos:SV_POSITION;
float4 color:COLOR;
};
vertOut vert(appdata_base v)
{
float3 n=float3(mul(float4(v.normal,0.0),_World2Object));
n=normalize(n);

float3 lightDir=normalize(float3(_WorldSpaceLightPos0));
float diff=max(0.0,dot(n,lightDir));
float4 diffColor=_LightColor0*_Color*diff;

vertOut o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
o.color=float4(diffColor);
return o;
}
float4 frag(vertOut i):COLOR
{
return i.color;
}
ENDCG
}//end pass
}
}
//
Shader “Tut/Vertex/Direction_2_ForwardBase” {
Properties {
_Color (“Base Color”, Color) =(1,1,1,1)
}
SubShader {
pass{
Tags{ “LightMode”=“ForwardBase”}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
#include “Lighting.cginc”

uniform float4 _Color;

struct vertOut{
float4 pos:SV_POSITION;
float4 color:COLOR;
};
vertOut vert(appdata_base v)
{
float3 n=float3(mul(float4(v.normal,0.0),_World2Object));
n=normalize(n);

float3 lightDir=normalize(float3(_WorldSpaceLightPos0));
float diff=max(0.0,dot(n,lightDir));
float4 diffColor=_LightColor0*_Color*diff;

vertOut o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
o.color=float4(diffColor);
return o;
}
float4 frag(vertOut i):COLOR
{
return i.color;
}
ENDCG
}//end pass
}
}
//
Shader “Tut/Vertex/Direction_2_ForwardAdd” {
Properties {
_Color (“Base Color”, Color) =(1,1,1,1)
}
SubShader {
pass{
Tags{ “LightMode”=“ForwardBase”}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
#include “Lighting.cginc”

uniform float4 _Color;

struct vertOut{
float4 pos:SV_POSITION;
float4 color:COLOR;
};
vertOut vert(appdata_base v)
{
float3 n=float3(mul(float4(v.normal,0.0),_World2Object));
n=normalize(n);

float3 lightDir=normalize(float3(_WorldSpaceLightPos0));
float diff=max(0.0,dot(n,lightDir));
float4 diffColor=_LightColor0*_Color*diff;

vertOut o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
o.color=float4(diffColor);
return o;
}
float4 frag(vertOut i):COLOR
{
return i.color;
}
ENDCG
}//end pass

pass{
Tags{ “LightMode”=“ForwardAdd”}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
#include “Lighting.cginc”

uniform float4 _Color;

struct vertOut{
float4 pos:SV_POSITION;
float4 color:COLOR;
};
vertOut vert(appdata_base v)
{
float3 n=float3(mul(float4(v.normal,0.0),_World2Object));
n=normalize(n);

float3 lightDir=normalize(float3(_WorldSpaceLightPos0));
float diff=max(0.0,dot(n,lightDir));
float4 diffColor=_LightColor0*_Color*diff;

vertOut o;
o.pos=mul(UNITY_MATRIX_MVP,v.vertex);
o.color=float4(diffColor);
return o;
}
float4 frag(vertOut i):COLOR
{
return i.color;
}
ENDCG
}//end pass
}
}


No one would spend any time 2 check so many lines of codes… you hava to do it all by yourself

It is a simple code

Please use [ CODE ] … [ / CODE ] (without the spaces) for code.

I don’t think “_WorldSpaceLightPos0” is set for a shader with “LightMode”=“Vertex”.

See the discussion for vertex lights here: Cg Programming/Unity/Multiple Lights - Wikibooks, open books for an open world
as opposed to pixel lights: Cg Programming/Unity/Diffuse Reflection - Wikibooks, open books for an open world

Thanks Martin,I will take a look

I got it,But is it now still unclear “whether a vertex light is a directional light, a point light, or a spotlight”,so werid?
after thank u martin,i will take a try to fix my code.

Actually, I don’t know how the Vertex Lit path works. From the description in the reference (Unity - Manual: Vertex Lit Rendering Path ), I concluded that there are no pixel lights. But a directional light source without cookie might be supported. But then I would expect to see the position in _WorldSpaceLightPos0. As far as I know, vertex lights are only point lights without cookies (but directional lights and spot lights (with and without cookies) might internally be approximated by point lights).

I conclued that ,
first: the pass tag ‘LightMode’ works at any situation,vertex or forward.

second:there must be some kind of internal steps about how Light is passed in,
Lights are setted base on thei Render Mode, so there are two group of lights,one group is vertex light,another group is pixel light,
but, first of all, pixel lights are always more important ,so Unity will try to pick enough lights from the group of pixel light,but at this situation,
we put the direction light at vertex light,so if unity cant pick enough counts of lights in pixel light group,then ,it will not continue to check the vertex light group,
it thinks it is empty,
Does this works?
I think it at least could explain my situation .

I tried many ways and was messed up by different combination between different camera rendering path * light render mode * shader LightMode,
but i believe i am coming close to the truth. if lucky, i will figure out all the combination later on.at least It seems that the unity_LightPosition is same as unity_4LightPosX0 in unity edition 3.5, it makes my try a little easy