示例#1
0
文件: Lights.cpp 项目: m10914/tbill
void DXPointLight::CreateShadowMap(LPDIRECT3DDEVICE9 device, DWORD type, DWORD size)
{
	HRESULT hr;

	DXLight::CreateShadowMap(device, type, size);
	hr = device->CreateCubeTexture(size, 1, D3DUSAGE_RENDERTARGET, D3DFMT_G32R32F, D3DPOOL_DEFAULT, &shadowmap, NULL);

	if( SUCCEEDED(hr) )
		hr = device->CreateCubeTexture(size, 1, D3DUSAGE_RENDERTARGET, D3DFMT_G32R32F, D3DPOOL_DEFAULT, &blur, NULL);

	if( FAILED(hr) )
	{
		if( shadowmap )
			shadowmap->Release();

		shadowmap = blur = NULL;
	}

	if( !blurdeclforpoint )
	{
		D3DVERTEXELEMENT9 elem[] =
		{
			{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
			{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
			D3DDECL_END()
		};

		device->CreateVertexDeclaration(elem, &blurdeclforpoint);
	}
	else
		blurdeclforpoint->AddRef();
}
示例#2
0
HRESULT HookIDirect3DDevice9::CreateCubeTexture(LPVOID _this,
												UINT EdgeLength,
												UINT Levels,
												DWORD Usage,
												D3DFORMAT Format,
												D3DPOOL Pool,
												IDirect3DCubeTexture9** ppCubeTexture,
												HANDLE* pSharedHandle)
{
	LOG_API();
	return pD3Dev->CreateCubeTexture(EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
}
示例#3
0
bool Lighting::CreateNormalizationCubeMap(LPDIRECT3DDEVICE9 Device, 
										  unsigned long Size)
{
    HRESULT				Hr;
	unsigned long		i,x,y;
    LPDIRECT3DSURFACE9  CubeMapFace;
	D3DXVECTOR3			N;
    float				W,H;
	unsigned long		*Pixel;
    D3DLOCKED_RECT		Lock;


    if(FAILED(Hr = Device->CreateCubeTexture(Size,1,0,D3DFMT_X8R8G8B8, 
                                             D3DPOOL_MANAGED,&m_CubeNormal,NULL)))
	{
		return(false);
	}
    

    for(i=0; i < 6; i++)
    {
        m_CubeNormal->GetCubeMapSurface((D3DCUBEMAP_FACES)i,0,&CubeMapFace);

		Hr = CubeMapFace->LockRect(&Lock,NULL,0);

		if(FAILED(Hr))
		{
			return(false);
		}

        Pixel = (unsigned long *)Lock.pBits;

        for(y = 0; y < Size; y++)
        {
			H  = (float)y / (float)(Size - 1);			
			H  = (H * 2.0f) - 1.0f;					
            
			for(x = 0; x < Size; x++)
			{
				W = (float)x / (float)(Size - 1);		
				W = (W * 2.0f) - 1.0f;					

				switch(i)
                {
                    case D3DCUBEMAP_FACE_POSITIVE_X:    
							N.x = +1.0f;
							N.y = -H;
							N.z = -W;
							break;
                        
                    case D3DCUBEMAP_FACE_NEGATIVE_X:    
							N.x = -1.0f;
							N.y = -H;
							N.z = +W;
							break;
                        
                    case D3DCUBEMAP_FACE_POSITIVE_Y:    
							N.x = +W;
							N.y = +1.0f;
							N.z = +H;
							break;
                        
                    case D3DCUBEMAP_FACE_NEGATIVE_Y:    
							N.x = +W;
							N.y = -1.0f;
							N.z = -H;
							break;
                        
                    case D3DCUBEMAP_FACE_POSITIVE_Z:    
							N.x = +W;
							N.y = -H;
							N.z = +1.0f;
							break;
                        
                    case D3DCUBEMAP_FACE_NEGATIVE_Z:    
							N.x = -W;
							N.y = -H;
							N.z = -1.0f;
							break;
                }

                D3DXVec3Normalize(&N,&N);

                *Pixel++ = VectorToRGBA(&N);

            }

        }
        

        CubeMapFace->UnlockRect();
        CubeMapFace->Release();
    }

    return(true);

}