예제 #1
0
파일: Lights.cpp 프로젝트: m10914/tbill
void DXPointLight::DrawShadowMap(LPDIRECT3DDEVICE9 device, LPD3DXEFFECT effect, void (*drawcallback)(LPD3DXEFFECT))
{
	if( !shadowmap || !needsredraw )
		return;

	LPDIRECT3DSURFACE9 surface = NULL;
	D3DXMATRIX vp;

	effect->SetVector("lightPos", (D3DXVECTOR4*)&position);

	for( int j = 0; j < 6; ++j )
	{
		GetViewProjMatrix(vp, j);
		effect->SetMatrix("matViewProj", &vp);

		shadowmap->GetCubeMapSurface((D3DCUBEMAP_FACES)j, 0, &surface);

		device->SetRenderTarget(0, surface);
		device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);

		drawcallback(effect);
		surface->Release();
	}

	if( shadowtype == Static )
		needsredraw = false;
}
예제 #2
0
파일: Camera.cpp 프로젝트: wolves3d/idea
		bool Unproject( vec3 * pOutRay, const ivec2 & vScreen )
		{
			if ( NULL == pOutRay )
				return false;

			mat4 mInvViewProj( GetViewProjMatrix() );

			// inverting ViewProj matrix
			if ( false == mInvViewProj.Inverse())
				return false;

			// Позиция курсора считается от левого верхнего угла
			// а нужно от левого нижнего
			const float fScreenY = float(m_vViewport.w - vScreen.y);

			vec4 vNearPoint(
				( 2 * (float)vScreen.x / m_vViewport.z ) - 1,	// Map to range -1 to 1
				( 2 * (float)fScreenY / m_vViewport.w ) - 1,	// Map to range -1 to 1
				-1, 1 );										// Near plane 

			vec4 vFarPoint(
				( 2 * (float)vScreen.x / m_vViewport.z ) - 1,	// Map to range -1 to 1
				( 2 * (float)fScreenY / m_vViewport.w ) - 1,	// Map to range -1 to 1
				1, 1 );											// Far plane 

			// transforming form screen_space to world_space
			vNearPoint.Multiply( mInvViewProj );

			if ( 0.f == vNearPoint.w )
				return false;

			// transforming form screen_space to world_space
			vFarPoint.Multiply( mInvViewProj );

			if ( 0.f == vFarPoint.w )
				return false;

			vNearPoint.w	= 1.f / vNearPoint.w;
			vFarPoint.w		= 1.f / vFarPoint.w;

			pOutRay[ 0 ].Set(	vNearPoint.x * vNearPoint.w,
								vNearPoint.y * vNearPoint.w,
								vNearPoint.z * vNearPoint.w );

			pOutRay[ 1 ].Set(	vFarPoint.x * vFarPoint.w,
								vFarPoint.y * vFarPoint.w,
								vFarPoint.z * vFarPoint.w );

			return true;
		}
예제 #3
0
파일: Lights.cpp 프로젝트: m10914/tbill
void DXDirectionalLight::DrawShadowMap(LPDIRECT3DDEVICE9 device, LPD3DXEFFECT effect, void (*drawcallback)(LPD3DXEFFECT))
{
	if( !shadowmap || !needsredraw )
		return;

	LPDIRECT3DSURFACE9 surface = NULL;
	D3DXMATRIX vp;

	GetViewProjMatrix(vp, D3DXVECTOR3(0, 0, 0));

	effect->SetVector("lightPos", &direction);
	effect->SetMatrix("matViewProj", &vp);

	shadowmap->GetSurfaceLevel(0, &surface);

	device->SetRenderTarget(0, surface);
	device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);

	drawcallback(effect);
	surface->Release();

	if( shadowtype == Static )
		needsredraw = false;
}