bool LightShaderClass::SetConstantBufferParameters(ID3D11DeviceContext* pDeviceContext, PointLightClass** ppLights, UINT NrOfLights, ObjectClass* pObject, FogClass* pDrawDistFog, CameraClass* pCamera) { HRESULT result; D3D11_MAPPED_SUBRESOURCE mappedResource; LightConstantBuffer* dataPtr; unsigned int bufferNumber; // Lock the constant buffer so it can be written to. result = pDeviceContext->Map(mLightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); if (FAILED(result)) { return false; } // Get a pointer to the data in the constant buffer. dataPtr = (LightConstantBuffer*)mappedResource.pData; ModelClass* pModel = pObject->GetModel(); MatrialDesc *pMaterials = pModel->GetMaterials(); UINT oCount = pModel->GetObjectCount(); dataPtr->LightCount_FogRange_ObjectCount_Unused = XMFLOAT4((float)NrOfLights, pDrawDistFog->GetRange(), (float)oCount, 0); dataPtr->fogColor = pDrawDistFog->GetColor(); dataPtr->CamPos = pCamera->GetPosition(); for (UINT i = 0; i < NrOfLights; i++) { dataPtr->lights[i].Pos = ppLights[i]->GetLightPos(); XMFLOAT3 color = ppLights[i]->GetLightColor(); dataPtr->lights[i].Color_LightRange = XMFLOAT4(color.x, color.y, color.z, ppLights[i]->GetRadius()); } for (UINT i = 0; i < oCount; i++) { dataPtr->materials[i].Ambient = pMaterials[i].Ambient; dataPtr->materials[i].Diffuse = pMaterials[i].Diffuse; dataPtr->materials[i].Specular = pMaterials[i].Specular; dataPtr->materials[i].Reflectivity = pMaterials[i].Reflectivity; dataPtr->materials[i].SpecPower_AlphaClip_Unused_Unused = XMFLOAT4(pMaterials[i].SpecPower, pMaterials[i].AlphaClip, 0, 0); } // Unlock the constant buffer. pDeviceContext->Unmap(mLightBuffer, 0); // Set the position of the constant buffer in the vertex shader. bufferNumber = 0; // Set the constant buffer in the shader with the updated values. pDeviceContext->PSSetConstantBuffers(bufferNumber, 1, &mLightBuffer); return true; }