void FogDemo::UpdateAmbientLight(const GameTime& gameTime) { static float ambientIntensity = 0.0f; if (mGamePad->IsButtonHeldDown(GamePadButton::X) && ambientIntensity < 1.0f) { ambientIntensity += static_cast<float>(gameTime.GetElapsedSeconds()); ambientIntensity = min(ambientIntensity, 1.0f); mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f); } if (mGamePad->IsButtonHeldDown(GamePadButton::Y) && ambientIntensity > 0.0f) { ambientIntensity -= (float)gameTime.GetElapsedSeconds(); ambientIntensity = max(ambientIntensity, 0.0f); mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f); } }
void FogDemo::UpdateSpecularLight(const GameTime& gameTime) { static float specularIntensity = 1.0f; if (mGamePad->IsButtonHeldDown(GamePadButton::DPadUp) && specularIntensity < 1.0f) { specularIntensity += static_cast<float>(gameTime.GetElapsedSeconds()); specularIntensity = min(specularIntensity, 1.0f); mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity); } if (mGamePad->IsButtonHeldDown(GamePadButton::DPadDown) && 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->IsButtonHeldDown(GamePadButton::RightShoulder) && specularPower < UCHAR_MAX) { specularPower += LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds()); specularPower = min(specularPower, static_cast<float>(UCHAR_MAX)); mPixelCBufferPerObjectData.SpecularPower = specularPower; } if (mGamePad->IsButtonHeldDown(GamePadButton::LeftShoulder) && specularPower > 1.0f) { specularPower -= LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds()); specularPower = max(specularPower, 1.0f); mPixelCBufferPerObjectData.SpecularPower = specularPower; } }
void FogDemo::UpdateDirectionalLight(const GameTime& gameTime) { static float directionalIntensity = 1.0f; float elapsedTime = static_cast<float>(gameTime.GetElapsedSeconds()); if (mGamePad != nullptr) { auto gamePadState = mGamePad->CurrentState(); if (gamePadState.IsConnected()) { // Update directional light intensity if (mGamePad->IsButtonHeldDown(GamePadButton::A) && directionalIntensity < 1.0f) { directionalIntensity += elapsedTime; directionalIntensity = min(directionalIntensity, 1.0f); mPixelCBufferPerFrameData.LightColor = XMFLOAT4(directionalIntensity, directionalIntensity, directionalIntensity, 1.0f); mDirectionalLight->SetColor(mPixelCBufferPerFrameData.LightColor); } if (mGamePad->IsButtonHeldDown(GamePadButton::B) && directionalIntensity > 0.0f) { directionalIntensity -= elapsedTime; directionalIntensity = max(directionalIntensity, 0.0f); mPixelCBufferPerFrameData.LightColor = XMFLOAT4(directionalIntensity, directionalIntensity, directionalIntensity, 1.0f); mDirectionalLight->SetColor(mPixelCBufferPerFrameData.LightColor); } if (gamePadState.IsLeftTriggerPressed()) { // Rotate directional light XMFLOAT2 rotationAmount = Vector2Helper::Zero; rotationAmount.x = -gamePadState.thumbSticks.rightX; rotationAmount.y = gamePadState.thumbSticks.rightY; XMMATRIX lightRotationMatrix = XMMatrixIdentity(); if (rotationAmount.x != 0) { lightRotationMatrix = XMMatrixRotationY(rotationAmount.x); } if (rotationAmount.y != 0) { XMMATRIX lightRotationAxisMatrix = XMMatrixRotationAxis(mDirectionalLight->RightVector(), rotationAmount.y); lightRotationMatrix *= lightRotationAxisMatrix; } if (rotationAmount.x != 0.0f || rotationAmount.y != 0.0f) { mDirectionalLight->ApplyRotation(lightRotationMatrix); mProxyModel->ApplyRotation(lightRotationMatrix); const XMFLOAT3& lightdirection = mDirectionalLight->Direction(); mVertexCBufferPerFrameData.LightDirection = XMFLOAT4(lightdirection.x, lightdirection.y, lightdirection.z, 0.0f); } } } } }