예제 #1
0
void StencilProgram::preRender()
{
	static float elapsed = 0.0f;
	static mcg::Timer timer;	
	float fSec = timer.elapsedSecF();
	elapsed += fSec;

	// Riportiamo elapsed tra 0 a 2PI.
	float r = elapsed / DirectX::XM_2PI;
	if(r > 1.0f)
		elapsed /= std::ceil(r);

	timer.start();

	// Aggiorniamo la camera.
	// Input
	XMFLOAT4 cameraRotationAxe(0.0f, 0.0f, 0.0f, 0.0f);
	if(keys[ROTATE_CAMERA_LEFT])
		mCamera.yRotation(fSec);
	if(keys[ROTATE_CAMERA_RIGHT])
		mCamera.yRotation(-fSec);
	if(keys[ROTATE_CAMERA_UP])
		mCamera.xRotation(-fSec);
	if(keys[ROTATE_CAMERA_DOWN])
		mCamera.xRotation(fSec);
	if(keys[MOVE_CAMERA_FOREWARD])
		mCamera.translate(-fSec);
	if(keys[MOVE_CAMERA_BACKWARD])
		mCamera.translate(fSec);

	mTransforms.view = mCamera.getViewMatrix();
	mTransforms.cameraPosition = mCamera.getCameraPositionFlaot4();

	mPd3dDeviceContext->UpdateSubresource( mTranfCBuffer, 0, nullptr, &mTransforms, 0, 0 );

	// Aggiorniamo il colore da utilizzare per gli outline
	mOutlineColor = XMFLOAT4(std::abs(std::cos(elapsed)), 0.0f, std::abs(std::sin(elapsed)), 1.0f);
	mPd3dDeviceContext->UpdateSubresource( mOutlineColorCBuffer, 0, nullptr, &mOutlineColor, 0, 0 );

	// Aggiorniamo le luci.
	if(!pauseLightsRotation)
	{
		XMMATRIX lightRotation = XMMatrixRotationY(fSec);
		XMVECTOR newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[0]), lightRotation);
		XMStoreFloat4(&mLights.position[0], newLightPosition);

		XMVECTOR lightRotationAxe = {1.0f, 1.0f, 0.0f, 0.0f};
		lightRotation = XMMatrixRotationAxis(lightRotationAxe, 1.2f * fSec);
		newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[1]), lightRotation);
		XMStoreFloat4(&mLights.position[1], newLightPosition);

		mPd3dDeviceContext->UpdateSubresource( mLightsCBuffer, 0, nullptr, &mLights, 0, 0 );
	}
}
void BumpMappingProgram::preRender()
{
	static mcg::Timer timer;
	float fSec = timer.elapsedSecF();
	timer.start();

	// Aggiorniamo la camera.
	// Input
	XMFLOAT4 cameraRotationAxe(0.0f, 0.0f, 0.0f, 0.0f);
	if(keys[ROTATE_CAMERA_LEFT])
		mCamera.yRotation(fSec);
	if(keys[ROTATE_CAMERA_RIGHT])
		mCamera.yRotation(-fSec);
	if(keys[ROTATE_CAMERA_UP])
		mCamera.xRotation(-fSec);
	if(keys[ROTATE_CAMERA_DOWN])
		mCamera.xRotation(fSec);
	if(keys[MOVE_CAMERA_FOREWARD])
		mCamera.translate(-fSec);
	if(keys[MOVE_CAMERA_BACKWARD])
		mCamera.translate(fSec);

	mTransforms.view = mCamera.getViewMatrix();
	mTransforms.cameraPosition = mCamera.getCameraPositionFlaot4();

	mPd3dDeviceContext->UpdateSubresource( mTransfCBuffer, 0, nullptr, &mTransforms, 0, 0 );

	// Aggiorniamo le luci.
	if(!pauseLightsRotation)
	{
		XMMATRIX lightRotation = XMMatrixRotationY(fSec);
		XMVECTOR newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[0]), lightRotation);
		XMStoreFloat4(&mLights.position[0], newLightPosition);

		XMVECTOR lightRotationAxe = {1.0f, 1.0f, 0.0f, 0.0f};
		lightRotation = XMMatrixRotationAxis(lightRotationAxe, 1.2f * fSec);
		newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[1]), lightRotation);
		XMStoreFloat4(&mLights.position[1], newLightPosition);

		mPd3dDeviceContext->UpdateSubresource( mLightsCBuffer, 0, nullptr, &mLights, 0, 0 );
	}
}
예제 #3
0
void BloomProgram::preRender()
{
	static mcg::Timer timer;
	float fSec = timer.elapsedSecF();
	timer.start();

	// Aggiorniamo la camera.
	// Input
	XMFLOAT4 cameraRotationAxe(0.0f, 0.0f, 0.0f, 0.0f);
	if(keys[ROTATE_CAMERA_LEFT])
		mCamera.yRotation(fSec);
	if(keys[ROTATE_CAMERA_RIGHT])
		mCamera.yRotation(-fSec);
	if(keys[ROTATE_CAMERA_UP])
		mCamera.xRotation(-fSec);
	if(keys[ROTATE_CAMERA_DOWN])
		mCamera.xRotation(fSec);
	if(keys[MOVE_CAMERA_FOREWARD])
		mCamera.translate(-fSec);
	if(keys[MOVE_CAMERA_BACKWARD])
		mCamera.translate(fSec);

	mTransforms.view = mCamera.getViewMatrix();
	mTransforms.cameraPosition = mCamera.getCameraPositionFlaot4();

	mPd3dDeviceContext->UpdateSubresource( mTranfCBuffer, 0, nullptr, &mTransforms, 0, 0 );

	// Aggiorniamo le luci.
	if(keys[CPOS_INC] || keys[CPOS_DEC])
	{

		if(keys[CPOS_INC])
			shiftPos = 0.001f;
		if(keys[CPOS_DEC])
			shiftPos = -0.001f;

		//sysref rosso
		XMMATRIX lightRotation = XMMatrixRotationY(shiftPos);
		XMVECTOR newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[2]), lightRotation);
		XMStoreFloat4(&mLights.position[2], newLightPosition);
		//sysref verde
		lightRotation = XMMatrixRotationZ(shiftPos);
		newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[3]), lightRotation);
		XMStoreFloat4(&mLights.position[3], newLightPosition);
		//sysref blu
		lightRotation = XMMatrixRotationX(shiftPos);
		newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[4]), lightRotation);
		XMStoreFloat4(&mLights.position[4], newLightPosition);
	}

	//aggiorniamo il blur level
	if(keys[BLUR_LEVEL_INC] || keys[BLUR_LEVEL_DEC])
		updateBlurLevel(keys[BLUR_LEVEL_INC]);
	else
	{
		floatBlurLevel = (float) intBlurLevel;
	}

	if(!pauseLightsRotation)
	{
		XMMATRIX lightRotation = XMMatrixRotationZ(fSec);
		XMVECTOR newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[0]), lightRotation);
		XMStoreFloat4(&mLights.position[0], newLightPosition);

		XMVECTOR lightRotationAxe = {1.0f, 1.0f, 0.0f, 0.0f};
		lightRotation = XMMatrixRotationAxis(lightRotationAxe, 1.2f * fSec);
		newLightPosition = XMVector4Transform(XMLoadFloat4(&mLights.position[1]), lightRotation);
		XMStoreFloat4(&mLights.position[1], newLightPosition);
	}

	if(keys[CPOS_INC] || keys[CPOS_DEC] || !pauseLightsRotation)
		mPd3dDeviceContext->UpdateSubresource( mLightsCBuffer, 0, nullptr, &mLights, 0, 0 );

	if(keys[BTHRESH_DEC] || keys[BTHRESH_INC])
	{
		if(keys[BTHRESH_DEC])
			cThresh -= 0.0001f;
		else
			cThresh += 0.0001f;

		BrightThresh thresh;
		thresh.threshold = cThresh;

		mPd3dDeviceContext->UpdateSubresource(mBrightThreshBuffer, 0, nullptr, &thresh, 0, 0);
	}
}