   problem normal,z = -1
  Hy .In my cg,phong shader i have this two instructions:LightDir = (input.Light[l]);Diff = (DiffuseIntensity[l] * DiffuseColor[l]) * saturate(dot(input.Normal,LightDir));is always 0!these are the values that i try:Lightdir = 1,0,0normal= 0, 0, -1Diff=0Lightdir = 0,1,0normal= 0, 0, -1Diff=0Lightdir = 0,0,1normal= 0, 0, -1Diff=0hou i must involve when the normals have -1?It's a simple cube.this is my complete code: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 3float 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 directionsif(length(Light0WorldDirection)>0)output.Light[0] = normalize(Light0WorldDirection).xyz;elseoutput.Light[0] = float3(0, 0, 0);if(length(Light1WorldDirection)>0)output.Light[1] = normalize(Light1WorldDirection).xyz;elseoutput.Light[1] = float3(0, 0, 0);if(length(Light2WorldDirection)>0)output.Light[2] = normalize(Light2WorldDirection).xyz;elseoutput.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);elsenorNormal = 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);// Nelseoutput.Normal = float3(0, 0, 0);// Noutput.Tex = input.Tex;return output;}PS_OUT mainPS(VS_OUT input){PS_OUT output = (PS_OUT)0;// Get ambient lightfloat4 diffuse = { 1.0f, 0.0f, 0.0f, 1.0f};    float4 ambient = {0.1, 0.0, 0.0, 1.0}; // Get diffuse lightfloat4 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; elseViewDir = 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();}}
  :)Revise the formula for a dot-product. The results are correct.   ;  Thanks, but when i debug the shader in fc composer all work fine , but when i insert the shader in opengl c++ project the mesh appear withowt profondity , always black.Must i activete the opengl light?or ther is an error in the shader?the shader is indipendent from the light of the opengl scene?In the shader i place 3 light but in opengl i don't have any light.And the materials what role can have in cg shader and opengl ?I insert the material parameter in my shader , but i don't see in opengl.thanks   ;  I don't think you understand how a dot product is calculated, or what the saturate() function does.Revise them both: Dot Product  Saturate Also, you say:"In the shader i place 3 light but in opengl i don't have any light."I don't think you understand what the semantics in your shader are doing. The lines where you declare the lights are not where you are "placing" them. Your actually binding them to the lights in your application. So no lights in your application = no lights being passed to your shader.   ;Quote:Original post by Joshi9999I don't think you understand how a dot product is calculated, or what the saturate() function does.Revise them both: Dot Product  Saturate Also, you say:"In the shader i place 3 light but in opengl i don't have any light."I don't think you understand what the semantics in your shader are doing. The lines where you declare the lights are not where you are "placing" them. Your actually binding them to the lights in your application. So no lights in your application = no lights being passed to your shader.thanks alot , i'm understand the dot product and the saturate ,but i'm not understand the corrispondence from the shader light and the opengl light .In the shader i declare the directions of the lights why there are a corrispondence with opengl?I no have parameters or constant buffer that manage the light in the shader , why i need of the light in opengl?up in this topic i post my shader.whats wrong?thanks   ;  up   ;  nobody?   ;  As the previous posters have stated, take a closer look at the dot product and the values you have provided.  Write out the math, do the calculations by hand, and consider the results :)   