hy.

I have created a simple phong model shader in cg,

The problem is that if i debug the shader in fx composer work fine , but if i insert it in opengl c++ project, the mesh appear black and without any light.

In c++ opengl project i dont have any light so.

There is a corrispondence or a relation with opengl lights and shaders light other the cg costant buffer that i can send to the shader?

```
float4x4 WMatrix;
float4x4 WMatrixIT;
float4x4 WVPMatrix ;
float4 Light0WorldDirection ;
float4 Light1WorldDirection ;
float4 Light2WorldDirection ;
float4 CameraModelPosition;
float AmbientIntensity = 0.1;
float4 AmbientColor : Ambient = float4(.5,.5,.5,1);
#define MaxLights 3
float DiffuseIntensity[MaxLights] = {1,1,1};
float4 DiffuseColor[MaxLights] : Diffuse = {float4(1,0,0,1),float4(0,1,0,1),float4(0,0,1,1)};
float3 LightDirection[MaxLights] : Direction = {float3(1,0,0),float3(0,1,0),float3(0,0,1)};
struct VS_IN
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float3 Tex : TEXCOORD0;
};
struct VS_OUT
{
float4 Position : POSITION;
float3 Light[MaxLights] : TEXCOORD0;
float3 Normal : TEXCOORD3;
float4 View : TEXCOORD4;
float3 Tex : TEXCOORD5;
};
struct PS_OUT
{
float4 Color : COLOR;
};
VS_OUT mainVS(VS_IN input)
{
VS_OUT output;
output.Position = mul(input.Position,WVPMatrix);
// Normalize the light directions
if(length(Light0WorldDirection)>0)
output.Light[0] = normalize(Light0WorldDirection).xyz;
else
output.Light[0] = float3(0, 0, 0);
if(length(Light1WorldDirection)>0)
output.Light[1] = normalize(Light1WorldDirection).xyz;
else
output.Light[1] = float3(0, 0, 0);
if(length(Light2WorldDirection)>0)
output.Light[2] = normalize(Light2WorldDirection).xyz;
else
output.Light[2] = float3(0, 0, 0);
Light0WorldDirection = float4(1, 0 ,0, 0);
output.Light[0] = Light0WorldDirection.xyz;
Light1WorldDirection = float4(0, 1 ,0, 0);
output.Light[1] = Light1WorldDirection.xyz;
Light2WorldDirection = float4(-1, 1 ,0, 0);
output.Light[2] = Light2WorldDirection.xyz;
float3 norNormal;
float3 NormalN = (mul(float4(input.Normal.xyz,1),WMatrixIT)).xyz;
if(length(NormalN)!=0)
norNormal = normalize(NormalN);
else
norNormal = float3(0, 0, 0);
float4 PosWorld = normalize(mul(input.Position, WMatrix)).xyzw;
output.View = CameraModelPosition - PosWorld; // V
float3 NN =mul(float4(norNormal,1), WMatrix).xyz;
if(length(NN)!=0 )
output.Normal = normalize(NN); // N
else
output.Normal = float3(0, 0, 0); // N
output.Tex = input.Tex;
return output;
}
PS_OUT mainPS(VS_OUT input)
{
PS_OUT output = (PS_OUT)0;
// Get ambient light
float4 diffuse = { 1.0f, 0.0f, 0.0f, 1.0f};
float4 ambient = {0.1, 0.0, 0.0, 1.0};
// Get diffuse light
float4 TotalDiffuseColor = float4(0,0,0,0);
float4 TotalReflectColor = float4(0,0,0,0);
float4 TotalSpecularColor = float4(0,0,0,0);
float3 ViewDir;
if(length(input.View)!=0)
ViewDir = normalize(input.View).xyz;
else
ViewDir = float3(0, 0, 0);
float3 LightDir;
float3 Reflect = float3(0, 0, 0);
float4 specular = float4(0, 0, 0, 0);
float4 Diff = float4(0, 0, 0, 0);
for(int l=0;l<MaxLights;l++){
LightDir = (input.Light[l]);
Diff = (DiffuseIntensity[l] * DiffuseColor[l]) * saturate(dot(input.Normal,LightDir));
//Reflect = 2 * Diff.xyz * input.Normal - LightDir;
//specular = pow(saturate(dot(Reflect, ViewDir)), 8); //
TotalDiffuseColor += Diff;
//TotalReflectColor += float4(Reflect,1);
//TotalSpecularColor += specular;
}
//float4 diffuseColorTexture = tex2D(BaseSampler,input.Tex);
output.Color = ambient + diffuse * TotalDiffuseColor + TotalSpecularColor;
return output;
}
technique technique0 {
pass p0 {
CullFaceEnable = false;
VertexProgram = compile vp40 mainVS();
FragmentProgram = compile fp40 mainPS();
}
}
```

thanks.