void PointLightRenderer::UpdateSpecularLight(const DX::StepTimer& gameTime) { static float specularIntensity = 1.0f; GamePad::State gamePadState = mGamePad->CurrentState(); if (gamePadState.IsConnected()) { if (gamePadState.IsLeftTriggerPressed() && specularIntensity <= 1.0f) { specularIntensity += static_cast<float>(gameTime.GetElapsedSeconds()); specularIntensity = min(specularIntensity, 1.0f); mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity); } if (gamePadState.IsRightTriggerPressed() && specularIntensity >= 0.0f) { specularIntensity -= (float)gameTime.GetElapsedSeconds(); specularIntensity = max(specularIntensity, 0.0f); mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity); } static float specularPower = mPixelCBufferPerObjectData.SpecularPower; if (mGamePad->IsButtonDown(GamePadButton::DPadUp) && specularPower < UCHAR_MAX) { specularPower += LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds()); specularPower = min(specularPower, static_cast<float>(UCHAR_MAX)); mPixelCBufferPerObjectData.SpecularPower = specularPower; } if (mGamePad->IsButtonDown(GamePadButton::DPadDown) && specularPower > 1.0f) { specularPower -= LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds()); specularPower = max(specularPower, 1.0f); mPixelCBufferPerObjectData.SpecularPower = specularPower; } } }
void PointLightRenderer::UpdatePointLight(const DX::StepTimer& gameTime) { static float pointLightIntensity = 1.0f; float elapsedTime = static_cast<float>(gameTime.GetElapsedSeconds()); GamePad::State gamePadState = mGamePad->CurrentState(); if (gamePadState.IsConnected()) { // Update point light intensity if (mGamePad->IsButtonDown(GamePadButton::X) && pointLightIntensity <= 1.0f) { pointLightIntensity += elapsedTime; pointLightIntensity = min(pointLightIntensity, 1.0f); mPixelCBufferPerFrameData.LightColor = XMFLOAT4(pointLightIntensity, pointLightIntensity, pointLightIntensity, 1.0f); mPointLight->SetColor(mPixelCBufferPerFrameData.LightColor); } if (mGamePad->IsButtonDown(GamePadButton::Y) && pointLightIntensity >= 0.0f) { pointLightIntensity -= elapsedTime; pointLightIntensity = max(pointLightIntensity, 0.0f); mPixelCBufferPerFrameData.LightColor = XMFLOAT4(pointLightIntensity, pointLightIntensity, pointLightIntensity, 1.0f); mPointLight->SetColor(mPixelCBufferPerFrameData.LightColor); } // Move point light XMFLOAT3 movementAmount = Vector3Helper::Zero; if (!bIsCameraControlled) { if (gamePadState.IsLeftThumbStickLeft()) { movementAmount.x = -1.0f; } if (gamePadState.IsLeftThumbStickRight()) { movementAmount.x = 1.0f; } if (gamePadState.IsLeftThumbStickUp()) { movementAmount.y = 1.0f; } if (gamePadState.IsLeftThumbStickDown()) { movementAmount.y = -1.0f; } if (gamePadState.IsRightThumbStickLeft()) { movementAmount.z = -1.0f; } if (gamePadState.IsRightThumbStickRight()) { movementAmount.z = 1.0f; } } XMVECTOR movement = XMLoadFloat3(&movementAmount) * LightMovementRate * elapsedTime; mPointLight->SetPosition(mPointLight->PositionVector() + movement); mProxyModel->SetPosition(mPointLight->Position()); mVertexCBufferPerFrameData.LightPosition = mPointLight->Position(); mPixelCBufferPerFrameData.LightPosition = mPointLight->Position(); } }