   DirectX10: Problem with Lightning
  HiI've the following problem:I wanted to implement a very simple light shader into my scene. Therefore I looked into the DirectX Documentation and took the shader code to test it with my scene. In my scene there are two cubes which uses exactly the same .fx file. But only one cube uses the light calculations. The other cube is completly black (look at the screenshoot to see my problem)http://img4.abload.de/img/test18mtj.jpgSo I don't know why this isn't work!Here is the code for the .fx file which both cubes are usingmatrix World;matrix View;matrix Projection;float4 g_vLightColors;float4 g_vLightDirections;    struct PS_INPUT{float4 Pos : SV_POSITION;float3 Norm : NORMAL;float4 Color : COLOR0;};////////////////////////////////////////////////// Vertex Shader - Main Function///////////////////////////////////////////////PS_INPUT VS(float4 Pos : POSITION, float3 Norm : NORMAL, float4 Color : COLOR){PS_INPUT psInput;psInput.Pos = mul( Pos, World );psInput.Pos = mul( psInput.Pos, View );psInput.Pos = mul( psInput.Pos, Projection );psInput.Norm = mul(Norm, World);psInput.Color = Color;return psInput;}///////////////////////////////////////////////// Pixel Shader///////////////////////////////////////////////float4 PS(PS_INPUT psInput) : SV_Target{float4 finalColor = 0;finalColor += saturate(dot((float3)g_vLightDirections, psInput.Norm) * g_vLightColors);return finalColor;}// Define the techniquetechnique10 Render{pass P0{SetVertexShader( CompileShader( vs_4_0, VS() ) );SetGeometryShader( NULL );SetPixelShader( CompileShader( ps_4_0, PS() ) );}}And here is the code for initialising and updating a cubeBruteOCuboid::BruteOCuboid(BruteInitD3D10* engine, BruteLight *light, D3DXVECTOR3 pos, D3DXVECTOR3 rot, D3DXVECTOR3 scale, D3DXVECTOR3 size, LPCWSTR effectFilename, LPCSTR effectTechniqueName) : BruteObject(pos, rot, scale, effectFilename, effectTechniqueName){ // Create the effectif(FAILED(D3DX10CreateEffectFromFile(effectFilename, NULL, NULL, "fx_4_0",D3D10_SHADER_ENABLE_STRICTNESS, 0, engine->pD3DDevice, NULL, NULL, &pEffect, NULL,NULL))){BruteGlobals::ShutdownEngine("BruteOCuboid", "Failed to create Effect");   return ;}// Obtain the techniquepTechnique = pEffect->GetTechniqueByName(effectTechniqueName);// Bind the projection matrix to the Projection variable in the shaderpWorldVariable = pEffect->GetVariableByName( "World" )->AsMatrix();    pViewVariable = pEffect->GetVariableByName( "View" )->AsMatrix();    pProjectionVariable = pEffect->GetVariableByName( "Projection" )->AsMatrix();light->pLightColorVar = pEffect->GetVariableByName("g_vLightColors")->AsVector();light->pLightDirVar  = pEffect->GetVariableByName("g_vLightDirections")->AsVector();    // The vertex input layout    D3D10_INPUT_ELEMENT_DESC layout[] =    {   { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },  { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },};// Calculate the number of elements in the layout array    UINT numElements = (sizeof(layout) / sizeof(layout[0]));    // Create the vertex input layout    D3D10_PASS_DESC PassDesc;    pTechnique->GetPassByIndex(0)->GetDesc(&PassDesc);    if(FAILED(engine->pD3DDevice->CreateInputLayout(layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &pVertexLayout))){BruteGlobals::ShutdownEngine("BruteOCuboid", "Failed to create InputLayout");   return ;}    // Create vertex buffer    VertexPosColorStruct vertices[] =    {// 1{ D3DXVECTOR3(-size.x,  size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  -size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},// 2{ D3DXVECTOR3(-size.x,  size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  -size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},// 3{ D3DXVECTOR3(-size.x, size.y,  size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, size.y,  size.z),  D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, size.y, size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, size.y, -size.z),  D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},// 4{ D3DXVECTOR3(-size.x, -size.y,  size.z), D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, -size.z), D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, -size.y,  size.z),  D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, -size.y,  size.z),  D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, -size.z), D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, -size.y, -size.z),  D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f)},// 5{ D3DXVECTOR3(size.x,  size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y,  size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, -size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, -size.y, -size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y,  size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x, -size.y,  size.z), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f)},// 6{D3DXVECTOR3(-size.x,  size.y, -size.z), D3DXVECTOR4(0.5f,0.0f,0.0f,0.0f)},{D3DXVECTOR3(-size.x, -size.y, -size.z), D3DXVECTOR4(0.5f,0.0f,0.0f,0.0f)},{D3DXVECTOR3(-size.x,  size.y,  size.z), D3DXVECTOR4(0.5f,0.0f,0.0f,0.0f)},{D3DXVECTOR3(-size.x,  size.y,  size.z), D3DXVECTOR4(0.5f,0.0f,0.0f,0.0f)},{D3DXVECTOR3(-size.x, -size.y, -size.z), D3DXVECTOR4(0.5f,0.0f,0.0f,0.0f)},{D3DXVECTOR3(-size.x, -size.y,  size.z), D3DXVECTOR4(0.5f,0.0f,0.0f,0.0f)},    };// Calculate the number of vertices in the arrayuiNumVertices = sizeof(vertices) / sizeof(VertexPosColorStruct);D3D10_BUFFER_DESC bd;    bd.Usage = D3D10_USAGE_DEFAULT;bd.ByteWidth = sizeof(VertexPosColorStruct) * uiNumVertices;    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;    bd.CPUAccessFlags = 0;    bd.MiscFlags = 0;    D3D10_SUBRESOURCE_DATA InitData;    InitData.pSysMem = vertices;// Do the creation of the actual vertex buffer    if(FAILED(engine->pD3DDevice->CreateBuffer(&bd, &InitData, &pVertexBuffer))){BruteGlobals::ShutdownEngine("BruteOCuboid", "Failed to create VertexBuffer");   return ;}ePrimitiveTopology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST;    //set stride and offset    uiStride = sizeof(VertexPosColorStruct);    uiOffset = 0;}void BruteOCuboid::Update(BruteCamera *camera, BruteLight *light){//Calculate final(world) matrixcamera->mWorld = mScale * mRot * mTrans;//Send variable to the ShaderpWorldVariable->SetMatrix( (float*)&camera->mWorld );    pViewVariable->SetMatrix( (float*)&camera->mView );    pProjectionVariable->SetMatrix( (float*)&camera->mProj );light->pLightColorVar->SetFloatVector((float*)&light->vLightColors);light->pLightDirVar->SetFloatVector((float*)&light->vLightDirs);}The vLightDirs variable is set to (0.0, 1.0, 0.0, 1.0)I really hope you can help my with that problem   
  Hey, could you provide the actual rendering code where you call the effect Begin and BeginPAass functions, thanks.   ;  Hi.Yeah here is the Draw method which i call in my main()void BruteRender::DrawVertexObject(BruteObject* object, BruteInitD3D10* engine){engine->pD3DDevice->ClearRenderTargetView(engine->pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.5f, 1.0f));// clear the depth bufferengine->pD3DDevice->ClearDepthStencilView(engine->pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 );// Set the input layoutengine->pD3DDevice->IASetInputLayout(object->pVertexLayout);    // Set vertex buffer// Before drawing can take place, the vertex buffer must be bound to the Direct3D pipelineengine->pD3DDevice->IASetVertexBuffers(0,//starting slot   1,//number of vertex buffers in the array   &object->pVertexBuffer,//pointer to the array of vertex buffers. If only one buffer is being used, this will point to the single buffer.   &object->uiStride,//the number of bytes, that each vertex in the buffer requires   &object->uiOffset);//the offset value defines the first vertex in each buffer to be used. If you intend to use all the vertices in the buffer than this value should be 0  // Set primitive topologyengine->pD3DDevice->IASetPrimitiveTopology(object->ePrimitiveTopology);    // Get the technique description    D3D10_TECHNIQUE_DESC techniqueDescription;    object->pTechnique->GetDesc(&techniqueDescription);// Loop through the technique passes    for(UINT p=0; p < techniqueDescription.Passes; ++p)    {   object->pTechnique->GetPassByIndex(p)->Apply(0);// draw all verticesengine->pD3DDevice->Draw(object->uiNumVertices,0);    }// Get a pointer to the back buffer textureID3D10Texture2D *pBackBuffer;HRESULT hr = engine->pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);if(FAILED(hr)){return;}// display the next item in the swap chainengine->pSwapChain->Present(0, 0);};  Does nobody has any ideas?   ;  Your layout is: Position, Normal, Color.But in your vertex array every vertex has this structure:{ D3DXVECTOR3(-size.x,  size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)}So the problem is in Normals.   ;  Yup, I concur with EpicLand - your declarations and inputs don't match up, thus all bets are off for rendering as it'll almost certainly not use the data you expect it to!To be honest, I'm surprised you got a sane rendering out of that code - a lot of times when I've made that mistake it starts interpretting colour as position (for example) and you get a total mess on the screen [lol]hthJack   ;  Oh I didn't know that I have to manually set the vertex normals for an object. I thought DirectX would automatically calculate them for me xDCan you give me a hint how to set teh vertex normals for my cube object? So what for example I have to put after the Position and color Information. I didn't found any hint in the DirectX Documentation for that    VertexPosColorStruct vertices[] =    {// 1{ D3DXVECTOR3(-size.x,  size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(-size.x, -size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},{ D3DXVECTOR3(size.x,  size.y, size.z), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f)},....};  a normal points perpendicular to the faceYou can either:1) draw it on paper and figure it out with intution for simple shaped2) calculate it using the vertices that make up a face3) let your 3d modeler do it for youa cube typically has 6 sidesso you'd have something line// Top normals0 1 00 1 00 1 00 1 00 1 00 1 0// Bottom normals0 -1 00 -1 00 -1 00 -1 00 -1 00 -1 0// Right normals1 0 01 0 01 0 0 1 0 0 1 0 0 1 0 0 // Left normals-1 0 0-1 0 0-1 0 0-1 0 0-1 0 0-1 0 0.etc etc.Essentially draw a line from the middle of the face that is 90 degrees from the plane containing the face.;  Thank you for your detailed description! I set the normals for the cube by hand and now the light calulations are right. So a small problem is solved!But again only the right cube is lit. The other one is black like in the picture of my first post.What's very strange is that wenn I create for example three cubes, only the last one which I have created is lit. The other two are black.But I don't know why. Because every cube object has it's own Vertex Buufer, Effect Variables, own Draw call etc..I can't find the error in my code   ;  Step through the render of the last cube with PIX and see what the values of the effect variables are for the last cube by debugging a pixel of the last cube.