Exemple #1
0
void CGameCursor::Draw()
{
	if (state == view)
	{
		(*graphicsDevice()).SetRenderState(D3DRS_ZENABLE, FALSE);
		m_2Dobj.Draw(vec3Position, vec3Scale);
		(*graphicsDevice()).SetRenderState(D3DRS_ZENABLE, TRUE);
	}
}
Exemple #2
0
void ShadowsDemo::onInitialize() {
	App::onInitialize();

	printf("Device: %s\n", graphicsDevice()->getGpuName());
	printf("API: %s\n", graphicsDevice()->getApiInfo());

	_camera.setAspect((float)window()->getWidth() / (float)window()->getHeight());
	_camera.setPlanes(1.0f, 100.0f);
	_camera.setSensitivity(100.0f, 10.0f);
}
Exemple #3
0
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	MSG msg; 
	
	MyRegisterClass(hInstance);
	InitInstance(hInstance, nCmdShow);

	Initialize();

	// メッセージ ループ
	do{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else{
			Update();
			Draw();
		}
	} while (msg.message != WM_QUIT);

	graphicsDevice().FreeDX();

	return 0;
}
Exemple #4
0
void ShadowsDemo::onLoadContent() {
	App::onLoadContent();

	// load shaders
	loadShaders();

	// load states
	ciri::RasterizerDesc rasterDesc;
	rasterDesc.cullMode = ciri::CullMode::Clockwise;
	//rasterDesc.fillMode = ciri::FillMode::Wireframe;
	_rasterState = graphicsDevice()->createRasterizerState(rasterDesc);
	_additiveBlendState = graphicsDevice()->getDefaultBlendAdditive();

	// create shadow map stuff
	_shadowTarget = graphicsDevice()->createRenderTarget2D(2048, 2048, ciri::TextureFormat::RGBA32_Float, ciri::DepthStencilFormat::Depth24);
	ciri::SamplerDesc shadowSamplerDesc;
	shadowSamplerDesc.filter = ciri::SamplerFilter::Point;
	shadowSamplerDesc.wrapU=shadowSamplerDesc.wrapV=shadowSamplerDesc.wrapW = ciri::SamplerWrap::Border;
	shadowSamplerDesc.borderColor[0]=shadowSamplerDesc.borderColor[1]=shadowSamplerDesc.borderColor[2]=shadowSamplerDesc.borderColor[3] = 1.0f;
	_shadowSampler = graphicsDevice()->createSamplerState(shadowSamplerDesc);

	// load some models
	_ground = std::make_shared<Model>();
	_ground->addFromObj("data/demos/shadows/ground.obj");
	_ground->build(graphicsDevice());
	if(_ground->isValid()){_models.push_back(_ground);}
	_helicopterBody = std::make_shared<Model>();
	_helicopterBody->addFromObj("data/demos/shadows/helicopter_body.obj");
	_helicopterBody->build(graphicsDevice());
	if(_helicopterBody->isValid()){_models.push_back(_helicopterBody);}
	_helicopterBlades = std::make_shared<Model>();
	_helicopterBlades->addFromObj("data/demos/shadows/helicopter_blades.obj");
	_helicopterBlades->build(graphicsDevice());
	if(_helicopterBlades->isValid()){_models.push_back(_helicopterBlades);}
	_helicopterTail = std::make_shared<Model>();
	_helicopterTail->addFromObj("data/demos/shadows/helicopter_tail.obj");
	_helicopterTail->build(graphicsDevice());
	if(_helicopterTail->isValid()){_models.push_back(_helicopterTail);}

	// add some lights
	Light light0(Light::Type::Directional);
	light0.setDirection(cc::Vec3f(0.75f, -0.8f, 0.72f));
	light0.setCastShadows(true);
	_lights.push_back(light0);
	Light light1(Light::Type::Spot);
	light1.setPosition(cc::Vec3f(0.0f, 20.0f, 0.0f));
	light1.setRange(200.0f);
	light1.setConeInnerAngle(10.0f);
	light1.setConeOuterAngle(12.0f);
	light1.setCastShadows(true);
	light1.setDiffuseIntensity(1.0f);//0.25f);
	//_lights.push_back(light1);
	_cameraLight = &_lights.back();
}
void CParticleEmitter::Init(CRandom& random, Ccamera& camera, const SParicleEmitParameter& param, const D3DXVECTOR3& emitPosition)
{
	this->random = &random;
	this->camera = &camera;
	this->param = param;
	this->emitPosition = emitPosition;
	timer = 0.0f;

	{
		D3DXLoadMeshFromX(
			"XFile\\itapori.x",
			D3DXMESH_MANAGED,
			graphicsDevice(),
			NULL,
			&m_pMaterials,
			NULL,
			&m_NumMaterials,
			&m_pMesh
			);
		D3DXCreateTextureFromFileA(graphicsDevice(), param.texturePath, &m_pTextures);

		LPD3DXBUFFER  compileErrorBuffer = NULL;
		HRESULT hr = NULL;
		hr = D3DXCreateEffectFromFile(
			graphicsDevice(),
			"shader\\particle.fx",
			NULL,
			NULL,
			D3DXSHADER_DEBUG,
			NULL,
			&m_pEffect,
			&compileErrorBuffer
			);
		if (FAILED(hr)) {
			MessageBox(NULL, (char*)(compileErrorBuffer->GetBufferPointer()), "error", MB_OK);
			abort();
		}
	}
}
Exemple #6
0
void Initialize()
{
	graphicsDevice().InitD3d(hWnd);
	GetKeyDevice().Initialize(hWnd);
	//SceneManagerのinitialize
	g_bulletPhysics.InitPysics();				//物理エンジン初期化
	SINSTANCE(CSceneManager)->InitializeScene();

	gamen.Initialize();
	RT.Create(BACKWINDOW_WIDTH, BACKWINDOW_HEIGHT, 1, D3DFMT_A8R8G8B8, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0);

	BR.Create(true);
}
Exemple #7
0
void CStage9::Draw()
{
	g_Shadow.Draw(m_camera.GetProjectionMatrix());
	m_Back1.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());
	m_Ground9.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());//ステージ1を描画
	m_pointa.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());//ポインタ描画
	m_Player.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());//Playerを描画
	m_gimmick.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());
	//m_flower.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());

	if (GAMEFLG->Getflg() == false)
	{
		//Zバッファをクリア
		m_GCursorWind.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());//ゲームカーソル風
	}

	m_goal.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());

	/************これを実行すると半透明になる(半透明にするオブジェクトのときにする)***********/
	(*graphicsDevice()).SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	(*graphicsDevice()).SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	(*graphicsDevice()).SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	/*******************************************************************************************/
	m_GameCursor.Draw();//ゲームカーソル(一番前に表示)
	m_GameCursor3D.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());//ゲームカーソル3D
	/***************************これ以降は半透明にならない処理*********************************/
	(*graphicsDevice()).SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	/*******************************************************************************************/

	if (GAMEFLG->Getflg() == true)
	{
		//Zバッファをクリア
		(*graphicsDevice()).Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
		m_GCursorWind.Draw(m_camera.GetViewMatrix(), m_camera.GetProjectionMatrix());//ゲームカーソル風
	}

}
void CCBManager::Initialize()
{
	m_interval = 0.2f;
	m_timer = 0.0f;
	m_numCreate = 0;
	/*for (int i = 0; i < CHOCO_NUM; i++)
	{
		int rate = 100.0f / (rand() % 100+1);
		if (rand() % 2){
			rate *= -1.0f;
		}
		D3DXVECTOR3 pos(GetStartPosition());
		pos.z += fabsf(rate);
		pos.y += rate;
		D3DXVECTOR3 Epos(GetEndPosition());
		Epos.z += fabsf(rate);
		Epos.y += rate;
		m_Choco[i].Initialize(pos, Epos);
	}*/
	SetAlive(true);

	m_IsFirst = true;

	SInstancingVertex vertices[] = {
		{ -1.0f, -1.0f, 0.0f, 1.0f, 0xffffffff, 0.0f, 1.0f, },
		{ -1.0f, 1.0f, 0.0f, 1.0f, 0xffffffff, 0.0f, 0.0f, },
		{ 1.0f, -1.0f, 0.0f, 1.0f, 0xffffffff, 1.0f, 1.0f, },
		{ 1.0f, -1.0f, 0.0f, 1.0f, 0xffffffff, 1.0f, 1.0f, },
		{ -1.0f, 1.0f, 0.0f, 1.0f, 0xffffffff, 0.0f, 0.0f, },
		{ 1.0f, 1.0f, 0.0f, 1.0f, 0xffffffff, 1.0f, 0.0f, },
	};
	

	(*graphicsDevice()).CreateVertexBuffer(6 * sizeof(SInstancingVertex), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVertexBuffer, NULL);

}
/*!
* @brief	作成。
*/
void CDofRender::Create()
{
	int w = SINSTANCE(CRenderContext)->GetWindowWidth();
	int h = SINSTANCE(CRenderContext)->GetWindowHeight();

	//レンダリングターゲットを作成。
	//深度情報抽出用
	(*graphicsDevice()).CreateDepthStencilSurface(w, h, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_DepthSamplingTarget, NULL);
	(*graphicsDevice()).CreateTexture(w, h, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pDepthSamplingTexture, NULL);
	m_pDepthSamplingTexture->GetSurfaceLevel(0, &m_DepthSamplingTarget);
	//横ブラー用。
	(*graphicsDevice()).CreateDepthStencilSurface(w, h, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_RenderTarget[0], NULL);
	(*graphicsDevice()).CreateTexture(w, h, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pBlurTexture[0], NULL);
	m_pBlurTexture[0]->GetSurfaceLevel(0, &m_RenderTarget[0]);
	//縦ブラー用。
	(*graphicsDevice()).CreateDepthStencilSurface(w, h, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_RenderTarget[1], NULL);
	(*graphicsDevice()).CreateTexture(w, h, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pBlurTexture[1], NULL);
	m_pBlurTexture[1]->GetSurfaceLevel(0, &m_RenderTarget[1]);

	m_pEffect = SINSTANCE(CEffect)->LoadEffect(_T("Shader/DepthOfField.hlsl"));

	m_FarNear = D3DXVECTOR2(100.0f, 1.0f);
	m_isEnable = true;
};
Exemple #10
0
void ShadowsDemo::loadShaders() {
	const std::string shaderExt = graphicsDevice()->getShaderExt();

	//
	// spotlight
	//
	if( nullptr == _spotlightShader ) {
		_spotlightShader = graphicsDevice()->createShader();
		_spotlightShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float3, ciri::VertexUsage::Position, 0));
		_spotlightShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float3, ciri::VertexUsage::Normal, 0));
		_spotlightShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float4, ciri::VertexUsage::Tangent, 0));
		_spotlightShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float2, ciri::VertexUsage::Texcoord, 0));
	}
	const std::string spotVS = "data/demos/shadows/spot_vs" + shaderExt;
	const std::string spotPS = "data/demos/shadows/spot_ps" + shaderExt;
	if( ciri::failed(_spotlightShader->loadFromFile(spotVS.c_str(), nullptr, spotPS.c_str())) ) {
		printf("Failed to load spotlight shader:\n");
		std::for_each(_spotlightShader->getErrors().begin(), _spotlightShader->getErrors().end(), [](auto err){printf("%s\n", err.msg.c_str());});
	}
	if( nullptr == _spotlightConstantsBuffer ) {
		_spotlightConstantsBuffer = graphicsDevice()->createConstantBuffer();
	}
	if( ciri::failed(_spotlightConstantsBuffer->setData(sizeof(SpotlightConstants), &_spotlightConstants)) ) {
		printf("Failed to set spotlight constants.\n");
	} else {
		if( ciri::failed(_spotlightShader->addConstants(_spotlightConstantsBuffer, "SpotlightConstants", ciri::ShaderStage::Vertex)) ) {
			printf("Failed to assign spotlight constants.\n");
		}
	}

	//
	// directional
	//
	if( nullptr == _directionalShader ) {
		_directionalShader = graphicsDevice()->createShader();
		_directionalShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float3, ciri::VertexUsage::Position, 0));
		_directionalShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float3, ciri::VertexUsage::Normal, 0));
		_directionalShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float4, ciri::VertexUsage::Tangent, 0));
		_directionalShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float2, ciri::VertexUsage::Texcoord, 0));
	}
	const std::string dirVS = "data/demos/shadows/dir_vs" + shaderExt;
	const std::string dirPS = "data/demos/shadows/dir_ps" + shaderExt;
	if( ciri::failed(_directionalShader->loadFromFile(dirVS.c_str(), nullptr, dirPS.c_str())) ) {
		printf("Failed to load directional light shader:\n");
		std::for_each(_directionalShader->getErrors().begin(), _directionalShader->getErrors().end(), [](auto err){printf("%s\n", err.msg.c_str());});
	}
	if( nullptr == _directionalConstantsBuffer ) {
		_directionalConstantsBuffer = graphicsDevice()->createConstantBuffer();
	}
	if( ciri::failed(_directionalConstantsBuffer->setData(sizeof(DirectionalConstants), &_directionalConstants)) ) {
		printf("Failed to set directional light constants.\n");
	} else {
		if( ciri::failed(_directionalShader->addConstants(_directionalConstantsBuffer, "DirectionalConstants", ciri::ShaderStage::Vertex)) ) {
			printf("Failed to assign directional light constants.\n");
		}
	}

	//
	// depth
	//
	if( nullptr == _depthShader ) {
		_depthShader = graphicsDevice()->createShader();
		_depthShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float3, ciri::VertexUsage::Position, 0));
		_depthShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float3, ciri::VertexUsage::Normal, 0));
		_depthShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float4, ciri::VertexUsage::Tangent, 0));
		_depthShader->addInputElement(ciri::VertexElement(ciri::VertexFormat::Float2, ciri::VertexUsage::Texcoord, 0));
	}
	const std::string depthVS = "data/demos/shadows/depth_vs" + shaderExt;
	const std::string depthPS = "data/demos/shadows/depth_ps" + shaderExt;
	if( ciri::failed(_depthShader->loadFromFile(depthVS.c_str(), nullptr, depthPS.c_str())) ) {
		printf("Failed to load depth shader.\n");
		std::for_each(_depthShader->getErrors().begin(), _depthShader->getErrors().end(), [](auto err){printf("%s\n", err.msg.c_str());});
	}
	if( nullptr == _depthConstantsBuffer ) {
		_depthConstantsBuffer = graphicsDevice()->createConstantBuffer();
	}
	if( ciri::failed(_depthConstantsBuffer->setData(sizeof(DepthConstants), &_depthConstants)) ) {
		printf("Failed to set depth constants.\n");
	} else {
		if( ciri::failed(_depthShader->addConstants(_depthConstantsBuffer, "DepthConstants", ciri::ShaderStage::Vertex)) ) {
			printf("Failed to assign depth constants.\n");
		}
	}
}
Exemple #11
0
void ShadowsDemo::onDraw() {
	App::onDraw();

	const auto device = graphicsDevice();

	device->setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	device->clear(ciri::ClearFlags::Color | ciri::ClearFlags::Depth);

	device->setRasterizerState(_rasterState);
	device->restoreDefaultBlendState();

	if( _spotlightShader->isValid() && _directionalShader->isValid() ) {
		const cc::Mat4f& cameraViewProj = _camera.getProj() * _camera.getView();

		bool firstLight = true;
		Light::Type boundLightType = Light::Type::Invalid;
		for( auto& light : _lights ) {
			// compute light matrices
			//const cc::Mat4f& lightView = light.view();
			//const cc::Mat4f& lightProj = light.proj();//cc::math::perspectiveRH(45.0f, 1.0f, 0.1f, light.range());//light.proj();
			//const cc::Mat4f lightViewProj = lightProj * lightView;
			if( light.type() == Light::Type::Directional ) {
				//light.computeViewProjFromFrustum(BoundingFrustum(cameraViewProj));
				light.computeViewProjFromFrustum(BoundingFrustum(_camera.getFov(), _camera.getAspect(), _camera.getNearPlane(), _camera.getFarPlane(), _camera.getPosition(), _camera.getFpsFront(), _camera.getUp()));
				//light.computeViewProjOrtho(_camera.getView(), _camera.getFov(), _camera.getAspect(), _camera.getNearPlane(), _camera.getFarPlane());
			}
			const cc::Mat4f lightViewProj = light.proj() * light.view();

			if( light.castShadows() ) {
				device->setDepthStencilState(device->getDefaultDepthStencilDefault());
				// set and clear render target
				ciri::IRenderTarget2D* depthTarget = _shadowTarget.get();
				device->setRenderTargets(&depthTarget, 1);
				device->setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
				device->clear(ciri::ClearFlags::Color | ciri::ClearFlags::Depth);
				// apply depth shader
				device->applyShader(_depthShader);
				// set viewport to depth size
				device->setViewport(ciri::Viewport(0, 0, _shadowTarget->getDepth()->getWidth(), _shadowTarget->getDepth()->getHeight()));
				// render all models
				for( auto& mdl : _models ) {
					_depthConstants.xform = lightViewProj * mdl->getXform().getWorld();
					_depthConstantsBuffer->setData(sizeof(DepthConstants), &_depthConstants);
					device->setVertexBuffer(mdl->getVertexBuffer());
					if( mdl->getIndexBuffer() != nullptr ) {
						device->setIndexBuffer(mdl->getIndexBuffer());
						device->drawIndexed(ciri::PrimitiveTopology::TriangleList, mdl->getIndexBuffer()->getIndexCount());
					} else {
						device->drawArrays(ciri::PrimitiveTopology::TriangleList, mdl->getVertexBuffer()->getVertexCount(), 0);
					}
				}

				// reser viewport to screen
				device->setViewport(ciri::Viewport(0, 0, window()->getWidth(), window()->getHeight()));
				// restore default render targets
				device->restoreDefaultRenderTargets();
			}
			switch( light.type() ) {
				case Light::Type::Directional: {
					if( boundLightType != Light::Type::Directional || light.castShadows() ) {
						boundLightType = Light::Type::Directional;
						device->applyShader(_directionalShader);
						device->setTexture2D(0, _shadowTarget->getDepth(), ciri::ShaderStage::Pixel);
						device->setSamplerState(0, _shadowSampler, ciri::ShaderStage::Pixel);
					}
					_directionalConstants.LightDirection = light.direction();
					_directionalConstants.LightColor = light.diffuseColor();
					_directionalConstants.LightIntensity = light.diffuseIntensity();
					_directionalConstants.campos = _camera.getPosition();
					_directionalConstants.CastShadows = light.castShadows();
					_directionalConstants.lightViewProj = lightViewProj;
					for( auto& mdl : _models ) {
						if( !mdl->isValid() ) {
							continue;
						}
						_directionalConstants.world = mdl->getXform().getWorld();
						_directionalConstants.xform = cameraViewProj * _directionalConstants.world;
						_directionalConstantsBuffer->setData(sizeof(DirectionalConstants), &_directionalConstants);
						device->setVertexBuffer(mdl->getVertexBuffer());
						if( mdl->getIndexBuffer() != nullptr ) {
							device->setIndexBuffer(mdl->getIndexBuffer());
							device->drawIndexed(ciri::PrimitiveTopology::TriangleList, mdl->getIndexBuffer()->getIndexCount());
						} else {
							device->drawArrays(ciri::PrimitiveTopology::TriangleList, mdl->getVertexBuffer()->getVertexCount(), 0);
						}
					}
					break;
				}
				case Light::Type::Spot: {
					if( boundLightType != Light::Type::Spot || light.castShadows() ) {
						boundLightType = Light::Type::Spot;
						device->applyShader(_spotlightShader);
						device->setTexture2D(0, _shadowTarget->getDepth(), ciri::ShaderStage::Pixel);
						device->setSamplerState(0, _shadowSampler, ciri::ShaderStage::Pixel);
					}
					_spotlightConstants.LightPosition = light.position();
					_spotlightConstants.LightDirection = light.direction();
					_spotlightConstants.LightColor = light.diffuseColor();
					_spotlightConstants.LightCosInner = light.cosConeInnerAngle(true);
					_spotlightConstants.LightCosOuter = light.cosConeOuterAngle(true);
					_spotlightConstants.LightIntensity = light.diffuseIntensity();
					_spotlightConstants.LightRange = light.range();
					_spotlightConstants.CastShadows = light.castShadows();
					_spotlightConstants.lightViewProj = lightViewProj;
					for( auto& mdl : _models ) {
						_spotlightConstants.world = mdl->getXform().getWorld();
						_spotlightConstants.xform = cameraViewProj * _spotlightConstants.world;
						_spotlightConstantsBuffer->setData(sizeof(SpotlightConstants), &_spotlightConstants);
						device->setVertexBuffer(mdl->getVertexBuffer());
						if( mdl->getIndexBuffer() != nullptr ) {
							device->setIndexBuffer(mdl->getIndexBuffer());
							device->drawIndexed(ciri::PrimitiveTopology::TriangleList, mdl->getIndexBuffer()->getIndexCount());
						} else {
							device->drawArrays(ciri::PrimitiveTopology::TriangleList, mdl->getVertexBuffer()->getVertexCount(), 0);
						}
					}
					break;
				}
			}

			if( firstLight ) {
				firstLight = false;
				device->setBlendState(_additiveBlendState);
			}
		}
	}

	device->present();
}
/*!
* @brief	描画。
*/
void CDofRender::Draw(LPDIRECT3DTEXTURE9 tex)
{

	if (m_isEnable) {
		UpdateWeight(200.0f);
		LPDIRECT3DSURFACE9 RenderingTarget;
		LPDIRECT3DSURFACE9 m_SavedMapZ;

		// もとのレンダリングターゲットを保存
		(*graphicsDevice()).GetRenderTarget(0, &RenderingTarget);
		(*graphicsDevice()).GetDepthStencilSurface(&m_SavedMapZ);

		m_Primitive = SINSTANCE(CRenderContext)->GetPrimitive();

		// 深度情報抽出
		{
			(*graphicsDevice()).SetRenderTarget(0, m_DepthSamplingTarget);
			(*graphicsDevice()).Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

			vector<OBJECT_DATA*> Objects = SINSTANCE(CObjectManager)->GetObjectList();
			int size = Objects.size();
			for (PRIORTY priorty = PRIORTY::PLAYER; priorty < PRIORTY::OBJECT2D; priorty = static_cast<PRIORTY>(priorty + 1)){	// 優先度の高いものから更新
				for (int idx = 0; idx < size; idx++){
					if (Objects[idx]->object->GetAlive()){
						if (Objects[idx]->priority == priorty){
							Objects[idx]->object->DrawDepth(m_pEffect,m_FarNear);
							//static_cast<C3DImage*>(Objects[idx]->object)->DrawDepth();
							//if (/*アニメーションするか*/){
							//	//(*graphicsDevice()).DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

							//}
							//else{

							//	//(*graphicsDevice()).DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
							//}
						}
					}
				}
			}
		}
		int w = SINSTANCE(CRenderContext)->GetWindowWidth();
		int h = SINSTANCE(CRenderContext)->GetWindowHeight();

		//XBlur
		{
			(*graphicsDevice()).SetRenderTarget(0, m_RenderTarget[0]);
			//(*graphicsDevice()).Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
			m_pEffect->SetTechnique("XBlur");
			m_pEffect->Begin(NULL, D3DXFX_DONOTSAVESHADERSTATE);
			m_pEffect->BeginPass(0);
			float size[2] = {
				static_cast<float>(w),
				static_cast<float>(h)
			};
			float offset[] = {
				16.0f / static_cast<float>(w),
				0.0f
			};
			m_pEffect->SetValue("g_TexSize", size, sizeof(size));
			m_pEffect->SetValue("g_offset", offset, sizeof(offset));
			m_pEffect->SetValue("g_weight", m_weights, sizeof(m_weights));

			m_pEffect->SetTexture("g_blur", tex);
			m_pEffect->CommitChanges();

			(*graphicsDevice()).SetVertexDeclaration(m_Primitive->GetVertexDecl());
			(*graphicsDevice()).SetStreamSource(0, m_Primitive->GetVertexBuffer(), 0, sizeof(SShapeVertex_PT));
			(*graphicsDevice()).SetIndices(m_Primitive->GetIndexBuffer());

			(*graphicsDevice()).DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

			m_pEffect->EndPass();
			m_pEffect->End();

		}
		//YBlur
		{
			(*graphicsDevice()).SetRenderTarget(0, m_RenderTarget[1]);
			//(*graphicsDevice()).Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
			m_pEffect->SetTechnique("YBlur");
			m_pEffect->Begin(NULL, D3DXFX_DONOTSAVESHADERSTATE);
			m_pEffect->BeginPass(0);
			float size[2] = {
				static_cast<float>(w),
				static_cast<float>(h)
			};
			float offset[] = {
				0.0f,
				16.0f / static_cast<float>(h)
			};
			m_pEffect->SetValue("g_TexSize", size, sizeof(size));
			m_pEffect->SetValue("g_offset", offset, sizeof(offset));
			m_pEffect->SetValue("g_weight", m_weights, sizeof(m_weights));

			m_pEffect->SetTexture("g_blur", m_pBlurTexture[0]);
			m_pEffect->CommitChanges();
			(*graphicsDevice()).SetVertexDeclaration(m_Primitive->GetVertexDecl());
			(*graphicsDevice()).SetStreamSource(0, m_Primitive->GetVertexBuffer(), 0, sizeof(SShapeVertex_PT));
			(*graphicsDevice()).SetIndices(m_Primitive->GetIndexBuffer());

			(*graphicsDevice()).DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

			m_pEffect->EndPass();
			m_pEffect->End();
		}

		{
			float offset[] = {
				0.5f / static_cast<float>(w),
				0.5f / static_cast<float>(h)
			};
			//戻す。
			(*graphicsDevice()).SetRenderTarget(0, RenderingTarget);
			(*graphicsDevice()).SetDepthStencilSurface(m_SavedMapZ);

			//深度情報を参照して合成。
			m_pEffect->SetTechnique("Final");
			m_pEffect->Begin(NULL, D3DXFX_DONOTSAVESHADERSTATE);
			m_pEffect->BeginPass(0);
			m_pEffect->SetTexture("g_Texture", tex);
			m_pEffect->SetTexture("g_DepthSample", m_pDepthSamplingTexture);
			m_pEffect->SetTexture("g_blur", m_pBlurTexture[1]);
			m_pEffect->SetValue("g_offset", offset, sizeof(offset));
			m_pEffect->CommitChanges();
			(*graphicsDevice()).SetVertexDeclaration(m_Primitive->GetVertexDecl());
			(*graphicsDevice()).SetStreamSource(0, m_Primitive->GetVertexBuffer(), 0, sizeof(SShapeVertex_PT));
			(*graphicsDevice()).SetIndices(m_Primitive->GetIndexBuffer());

			(*graphicsDevice()).DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

			m_pEffect->EndPass();
			m_pEffect->End();
		}
	}

};
Exemple #13
0
void Draw()
{
	//(*graphicsDevice()).Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	(*graphicsDevice()).Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);

	(*graphicsDevice()).BeginScene();


	(*graphicsDevice()).GetViewport(&m_viewport);
	(*graphicsDevice()).GetRenderTarget(0, &m_Backbuffer);
	(*graphicsDevice()).GetDepthStencilSurface(&m_BackZ);

	(*graphicsDevice()).SetRenderTarget(0, RT.GetSurfaceDx());
	(*graphicsDevice()).SetDepthStencilSurface(RT.GetDepthSurfaceDx());
	//(*graphicsDevice()).Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	(*graphicsDevice()).Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);


	D3DVIEWPORT9 viewport = { 0, 0, BACKWINDOW_WIDTH, BACKWINDOW_HEIGHT, 0.0f, 1.0f };
	(*graphicsDevice()).SetViewport(&viewport);
	(*graphicsDevice()).SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	SINSTANCE(CSceneManager)->DrawScene();


	(*graphicsDevice()).SetRenderTarget(0, m_Backbuffer);
	(*graphicsDevice()).SetDepthStencilSurface(m_BackZ);
	(*graphicsDevice()).SetViewport(&m_viewport);
	(*graphicsDevice()).SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);


	gamen.SetTex(RT.GetTexture());

	static float a=0,b=0;
//	a+=0.5f*1.5;	
	//b += 1;
	gamen.Draw(D3DXVECTOR3(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 1.0f), D3DXVECTOR3(WINDOW_WIDTH - (WINDOW_WIDTH / 100)*b, WINDOW_HEIGHT - (WINDOW_HEIGHT / 100)*b, 0.0f), a);

	BR.Render();

	(*graphicsDevice()).EndScene();
	(*graphicsDevice()).Present(NULL, NULL, NULL, NULL);

}