Пример #1
0
//------------------------------------------------------------------------
// Date     : 30/6/2012
// Purpose  : Initialize Skybox here
//------------------------------------------------------------------------
void	Skybox::InitializeSky(const std::string& fileName, float radius)
{
	LPDIRECT3DDEVICE9 device = RenderDevice::GetInstance()->getDevice();

	m_fRadius = radius;

	D3DXCreateSphere(device, m_fRadius, 30, 30, &m_pSkySPhere, 0);
	D3DXCreateCubeTextureFromFile(device, fileName.c_str(), &m_pCubeTex);

	LPD3DXBUFFER	errors = NULL;
	HRESULT Hr = D3DXCreateEffectFromFile(device, "Shaders\\FX\\sky.fx", 0,0,0,0, &m_pFX, &errors);
	if (Hr != S_OK)
	{
		LogManager::GetInstance()->WriteToFile("ERROR -----> sky.fx() FAILED", (char*)errors->GetBufferPointer());
		return;
	}

	m_hTech   = m_pFX->GetTechniqueByName("SkyTech");
	m_hWVP    = m_pFX->GetParameterByName(0, "matWVP");
	m_hEnvMap = m_pFX->GetParameterByName(0, "gEnvMap");
	m_hDelta  = m_pFX->GetParameterByName(0, "delta");
	m_hTime   = m_pFX->GetParameterByName(0, "fTime");

	m_pFX->SetTechnique(m_hTech);
	m_pFX->SetTexture(m_hEnvMap, m_pCubeTex);

	LogManager::GetInstance()->WriteToFile("Sky Initialized Successfully...");

	UpdateEngineStats();
}
Пример #2
0
void sky::InitSky(const std::wstring& envmapFilename, float skyRadius)
{
	mRadius = skyRadius;
	HR(D3DXCreateSphere(g_app->m_pD3DDev, skyRadius, 30, 30, &mSphere, 0),L"sky::sky: Failed to create sky sphere: ");
	HR(D3DXCreateCubeTextureFromFile(g_app->m_pD3DDev, envmapFilename.c_str(), &mEnvMap),
		L"sky::sky: Failed to create sky texture from file: ");

	LPCWSTR shaderFile;
	switch(g_renderer->m_shaderVersion)
	{
	case 2: shaderFile = L"Shaders/sky_2_0.fx"; break;
	case 3: shaderFile = L"Shaders/sky_3_0.fx"; break;
	default: throw std::runtime_error("buildFX: m_shaderVersion must be 2 or 3."); break;
	}
	ID3DXBuffer* errors = 0;
	HR(D3DXCreateEffectFromFileEx(g_app->m_pD3DDev, shaderFile, 0, 0, 0, 0, 0, &m_FX, &errors),
		L"sky::sky: Failed to create sky effects: ");
	if( errors )
	{
		MessageBox(0, toWideString((char*)errors->GetBufferPointer(),-1).c_str(), 0, 0);
		throw std::runtime_error("sky::sky: errors exist in initializing sky");
	}

	mhTech   = m_FX->GetTechniqueByName("SkyTech");
	mhWVP    = m_FX->GetParameterByName(0, "gWVP");
	mhEnvMap = m_FX->GetParameterByName(0, "gEnvMap");

	// Set effect parameters that do not vary.
	HR(m_FX->SetTechnique(mhTech),L"sky::sky: Failed to set sky technique: ");
	HR(m_FX->SetTexture(mhEnvMap, mEnvMap),L"sky::sky: Failed to set sky texture: ");
}
Пример #3
0
Environment::Environment( std::string cubeTextureFileName )
{
	D3DXCreateSphere( g_pEngine->core->lpd3dd9, 256, 10, 10, &m_meshSphere, nullptr );

	D3DXCreateCubeTextureFromFile( g_pEngine->core->lpd3dd9, cubeTextureFileName.c_str(), &m_cubeTexture );

	m_environmentEffect = new EnvironmentEffect();
	m_environmentEffect->Init();
}
Пример #4
0
bool CubeEnvMapping::init(IDirect3DDevice9 *pD3DDevice)
{
	m_pEffect = DrawingUtil::getInst()->loadEffect(pD3DDevice,"Shader\\CubeEnvMapping.fx");

	m_pEffect->SetTechnique("myCubeEnvMap");
	
	HRESULT hr = D3DXCreateCubeTextureFromFile(pD3DDevice,"Media\\LobbyCube.dds",&m_pCubeMap);
	hr = D3DXCreateTextureFromFile(pD3DDevice,"Media\\spheremap.jpg",&m_pSphereMap);

	return ShaderSimpler::init(pD3DDevice);
}
Пример #5
0
Sky::Sky(std::string strSkyTextureFileName, float fSkyRadius)
	:m_fSkyRadius(fSkyRadius)
{
	D3DXCreateSphere(pDxDevice, m_fSkyRadius, 160, 160, &m_pSkyMesh, 0);
	D3DXCreateCubeTextureFromFile(pDxDevice, strSkyTextureFileName.c_str(), &m_pSkyTexture);

	D3DXCreateEffectFromFile(pDxDevice, "../../Resources/shaders/SkyShader.fx", 0, 0, 0, 0, &m_pEffect, 0);

	m_hEffectTechnique	= m_pEffect->GetTechniqueByName("SkyTech");
	m_hWVPMatrix		= m_pEffect->GetParameterByName(0, "WVP");
	m_hSkyTexture		= m_pEffect->GetParameterByName(0, "tex0");

	m_pEffect->SetTechnique(m_hEffectTechnique);
	m_pEffect->SetTexture(m_hSkyTexture, m_pSkyTexture);
}
Пример #6
0
	bool sCubeTexture::load(std_string const& filename)
	{
		std_string realPath;
		if (!_getFileSystem()->findRealPath(filename, realPath))
		{
			return false;
		}

		if (!checkHResultReturn(D3DXCreateCubeTextureFromFile(cD3DSystem::getD3DDevice(), realPath.c_str(), &m_tex)))
			return false;

		trace(_T("load texture : %s\n"), filename.c_str());

		return true;
	}
Пример #7
0
bool LoadAssets()
{
	// 텍스처 로딩
	gpStoneDM = LoadTexture("Fieldstone_DM.tga");
	if (!gpStoneDM)
	{
		return false;
	}

	gpStoneSM = LoadTexture("Fieldstone_SM.tga");
	if (!gpStoneSM)
	{
		return false;
	}

	gpStoneNM = LoadTexture("Fieldstone_NM.tga");
	if (!gpStoneNM)
	{
		return false;
	}

	D3DXCreateCubeTextureFromFile(gpD3DDevice, "Snow_ENV.dds", &gpSnowENV);
	if (!gpSnowENV)
	{
		return false;
	}

	// 쉐이더 로딩
	gpEnvironmentMappingShader = LoadShader("EnvironmentMapping.fx");
	if (!gpEnvironmentMappingShader)
	{
		return false;
	}

	// 모델 로딩
	gpTeapot = LoadModel("TeapotWithTangent.x");
	if (!gpTeapot)
	{
		return false;
	}

	return true;
}
Пример #8
0
Sky::Sky(const std::string& envmapFilename, float skyRadius)
: mRadius(skyRadius)
{
	HR(D3DXCreateSphere(gd3dDevice, skyRadius, 30, 30, &mSphere, 0));
	HR(D3DXCreateCubeTextureFromFile(gd3dDevice, envmapFilename.c_str(), &mEnvMap));

	ID3DXBuffer* errors = 0;
	HR(D3DXCreateEffectFromFile(gd3dDevice, "sky.fx", 0, 0, 0, 
		0, &mFX, &errors));
	if( errors )
		MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);

	mhTech   = mFX->GetTechniqueByName("SkyTech");
	mhWVP    = mFX->GetParameterByName(0, "gWVP");
	mhEnvMap = mFX->GetParameterByName(0, "gEnvMap");

	// Set effect parameters that do not vary.
	HR(mFX->SetTechnique(mhTech));
	HR(mFX->SetTexture(mhEnvMap, mEnvMap));
}
bool CLandEnvironment::LoadShadingFX()
{
	D3DXCreateSphere(m_pDirect3D9Device, m_fRadius, 30, 30, &m_pSphere, 0);
	D3DXCreateCubeTextureFromFile(m_pDirect3D9Device, L"LandEnvironment.dds", &m_pEnvironmentMap);

	// -------------------------------------------------------------------------
   // Sets the current working directory so the FX file will
   // always be found.
   // -------------------------------------------------------------------------
   char csModuleFilename[2048];
   ::GetModuleFileNameA(NULL, csModuleFilename, 2048); 
   string strModuleDirectory = csModuleFilename;

   strModuleDirectory = strModuleDirectory.substr(0, strModuleDirectory.find_last_of("\\"));
   ::SetCurrentDirectoryA(strModuleDirectory.c_str());

	if (S_OK != D3DXCreateEffectFromFileA(
      m_pDirect3D9Device, 
      (LPCSTR)"LandEnvironment.fx", 
		0, 
      0, 
      D3DXSHADER_DEBUG, 
      0, 
      &m_pFX, 
      NULL))
   {
      return false;
   } 

	m_hParam_EnvironmentTechnique = m_pFX->GetTechniqueByName("LandEnvironmentTechnique");
	m_hParam_WVP = m_pFX->GetParameterByName(0, "gWVP");
	m_hParam_EnvironmentMap = m_pFX->GetParameterByName(0, "gEnvMap");  

	m_pFX->SetTechnique(m_hParam_EnvironmentTechnique);
	m_pFX->SetTexture(m_hParam_EnvironmentMap, m_pEnvironmentMap);

   return true;
}
Пример #10
0
// キューブテクスチャをセット
void Deferred::CubeSet(char * name)
{
	HRESULT		hr;
	CubeTex  *cubeTex = NULL;
	LPCTSTR str = name;

	hr = D3DXCreateCubeTextureFromFile(tdnSystem::GetDevice(), str, &cubeTex);

	if (FAILED(hr))
	{

		if (hr == D3DERR_NOTAVAILABLE)
		{
			assert(0);
		}
		if (hr == D3DERR_OUTOFVIDEOMEMORY)
		{
			assert(0);
		}
		if (hr == D3DXERR_INVALIDDATA)
		{
			assert(0);
		}
		if (hr == E_OUTOFMEMORY)
		{
			assert(0);
		}
		if (hr == D3DERR_INVALIDCALL)
		{
			assert(0);

		}
	}
	shader->SetValue("cubeTex", cubeTex);

	cubeTex->Release();
}
Пример #11
0
//-----------------------------------------------------------------------------
HRESULT CDXUTMesh::CreateMaterials( LPCWSTR strPath, IDirect3DDevice9 *pd3dDevice, D3DXMATERIAL* d3dxMtrls, DWORD dwNumMaterials )
{
    // Get material info for the mesh
    // Get the array of materials out of the buffer
    m_dwNumMaterials = dwNumMaterials;
    if( d3dxMtrls && m_dwNumMaterials > 0 )
    {
        // Allocate memory for the materials and textures
        m_pMaterials = new D3DMATERIAL9[m_dwNumMaterials];
        if( m_pMaterials == NULL )
            return E_OUTOFMEMORY;
        m_pTextures = new LPDIRECT3DBASETEXTURE9[m_dwNumMaterials];
        if( m_pTextures == NULL )
            return E_OUTOFMEMORY;
        m_strMaterials = new CHAR[m_dwNumMaterials][MAX_PATH];
        if( m_strMaterials == NULL )
            return E_OUTOFMEMORY;

        // Copy each material and create its texture
        for( DWORD i=0; i<m_dwNumMaterials; i++ )
        {
            // Copy the material
            m_pMaterials[i]         = d3dxMtrls[i].MatD3D;
            m_pTextures[i]          = NULL;

            // Create a texture
            if( d3dxMtrls[i].pTextureFilename )
            {
                StringCchCopyA( m_strMaterials[i], MAX_PATH, d3dxMtrls[i].pTextureFilename );

                WCHAR strTexture[MAX_PATH];
                WCHAR strTextureTemp[MAX_PATH];
                D3DXIMAGE_INFO ImgInfo;

                // First attempt to look for texture in the same folder as the input folder.
                MultiByteToWideChar( CP_ACP, 0, d3dxMtrls[i].pTextureFilename, -1, strTextureTemp, MAX_PATH );
                strTextureTemp[MAX_PATH-1] = 0;

                StringCchCopy( strTexture, MAX_PATH, strPath );
                StringCchCat( strTexture, MAX_PATH, strTextureTemp );

                // Inspect the texture file to determine the texture type.
                if( FAILED( D3DXGetImageInfoFromFile( strTexture, &ImgInfo ) ) )
                {
                    // Search the media folder
                    if( FAILED( DXUTFindDXSDKMediaFileCch( strTexture, MAX_PATH, strTextureTemp ) ) )
                        continue;  // Can't find. Skip.

                    D3DXGetImageInfoFromFile( strTexture, &ImgInfo );
                }

                // Call the appropriate loader according to the texture type.
                switch( ImgInfo.ResourceType )
                {
                    case D3DRTYPE_TEXTURE:
                    {
                        IDirect3DTexture9 *pTex;
                        if( SUCCEEDED( D3DXCreateTextureFromFile( pd3dDevice, strTexture, &pTex ) ) )
                        {
                            // Obtain the base texture interface
                            pTex->QueryInterface( IID_IDirect3DBaseTexture9, (LPVOID*)&m_pTextures[i] );
                            // Release the specialized instance
                            pTex->Release();
                        }
                        break;
                    }
                    case D3DRTYPE_CUBETEXTURE:
                    {
                        IDirect3DCubeTexture9 *pTex;
                        if( SUCCEEDED( D3DXCreateCubeTextureFromFile( pd3dDevice, strTexture, &pTex ) ) )
                        {
                            // Obtain the base texture interface
                            pTex->QueryInterface( IID_IDirect3DBaseTexture9, (LPVOID*)&m_pTextures[i] );
                            // Release the specialized instance
                            pTex->Release();
                        }
                        break;
                    }
                    case D3DRTYPE_VOLUMETEXTURE:
                    {
                        IDirect3DVolumeTexture9 *pTex;
                        if( SUCCEEDED( D3DXCreateVolumeTextureFromFile( pd3dDevice, strTexture, &pTex ) ) )
                        {
                            // Obtain the base texture interface
                            pTex->QueryInterface( IID_IDirect3DBaseTexture9, (LPVOID*)&m_pTextures[i] );
                            // Release the specialized instance
                            pTex->Release();
                        }
                        break;
                    }
                }
            }
        }
    }
    return S_OK;
}
Пример #12
0
HRESULT KModelWater::LoadMesh(LPSTR pFileName)
{
	HRESULT hr = S_OK;

	m_dwNumPoly_X = 63;     //长方形网格的长,网格数
	m_dwNumPoly_Z = 63;     //长方形网格的宽,网格数

	LPD3DXMESH pMesh = m_pWaterUp;
	LPD3DXMESH pDMesh = m_pWaterDn;

	DWORD m_dNumPloy     = m_dwNumPoly_X * m_dwNumPoly_Z;
	DWORD m_dNumFaces    = m_dNumPloy * 2;
	DWORD m_dNumVertices = (m_dwNumPoly_X+1)*(m_dwNumPoly_Z+1);

	SAFE_RELEASE(pMesh);	
	SAFE_RELEASE(pDMesh);
	WORD *pwIndices;

	//建立水面网格 
	if(FAILED(hr = g_pd3dDevice->CreateIndexBuffer(m_dNumFaces * 3 * sizeof(WORD), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
		D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_pibIndices, NULL)))
	{
		return hr;
	}

	if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pMesh)))
	{
		return hr;
	}	
	if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pDMesh)))
	{
		return hr;
	}




	VFormat::FACES_NORMAL_TEXTURE1 * pVers = NULL;
	DWORD* pIndex = NULL;
	DWORD * pAttrib = NULL;	

	VFormat::FACES_NORMAL_TEXTURE1 * pDVers = NULL;
	DWORD* pDIndex = NULL;
	DWORD * pDAttrib = NULL;	
	if(FAILED(hr = m_pibIndices->Lock(0, m_dNumFaces *3 * sizeof(WORD), (void**) &pwIndices, D3DLOCK_DISCARD)))
		return E_FAIL;
	if (FAILED(pMesh->LockVertexBuffer(0,(void**)&pVers)))
		return E_FAIL;
	if (FAILED(pMesh->LockIndexBuffer (0,(void**)&pIndex)))
		return E_FAIL;
	if (FAILED(pMesh->LockAttributeBuffer(0,(DWORD**)&pAttrib)))
		return E_FAIL;

	if (FAILED(pDMesh->LockVertexBuffer(0,(void**)&pDVers)))
		return E_FAIL;
	if (FAILED(pDMesh->LockIndexBuffer (0,(void**)&pDIndex)))
		return E_FAIL;
	if (FAILED(pDMesh->LockAttributeBuffer(0,(DWORD**)&pDAttrib)))
		return E_FAIL;

	DWORD i = 0;
	float _X = 1.0f/m_dwNumPoly_X;
	float _Z = 1.0f/m_dwNumPoly_Z;

	float m_fPolyWidth  = 200;
	float m_fPolyHeight = 200;

	for(DWORD X =0;X<=m_dwNumPoly_X;X++)
	{
		for(DWORD Y =0;Y<=m_dwNumPoly_Z;Y++)
		{
			float PX = X * m_fPolyWidth;
			float PZ = Y * m_fPolyHeight;

			D3DXVECTOR2 Pos(PX,PZ);

			pVers[i].p = D3DXVECTOR3(PX,200,PZ);

			pVers[i].Normal = D3DXVECTOR3(0,1,0);

			pVers[i].tu1 = (X * _X);
			pVers[i].tv1 = (1 - Y *_Z);
			pDVers[i].p = D3DXVECTOR3(PX,0,PZ);
			pDVers[i].Normal = D3DXVECTOR3(0,1,0);
			pDVers[i].tu1 = (X * _X);
			pDVers[i].tv1 = (1 - Y *_Z);
			i++;
		}
	}

	DWORD  Weight = m_dwNumPoly_X + 1;

	for(X =0;X<m_dwNumPoly_X;X++)
	{
		for(DWORD Y =0;Y<m_dwNumPoly_Z;Y++)
		{
			DWORD PloyIndex = Y*m_dwNumPoly_X +X;

			DWORD PolyMaterialID = 0;

			DWORD Vertex_A = X    *Weight+ Y;
			DWORD Vertex_B = (X+1)*Weight+ Y;
			DWORD Vertex_C = (X+1)*Weight+(Y+1);
			DWORD Vertex_D = X    *Weight+(Y+1);

			DWORD Faces_A1 = (PloyIndex*2)*3;
			DWORD Faces_B1 = Faces_A1 + 1;
			DWORD Faces_C1 = Faces_B1 + 1;

			pIndex[Faces_A1] = Vertex_A;
			pIndex[Faces_B1] = Vertex_B;
			pIndex[Faces_C1] = Vertex_D;
			pAttrib[PloyIndex*2] = PolyMaterialID;
			pDIndex[Faces_A1] = Vertex_A;
			pDIndex[Faces_B1] = Vertex_B;
			pDIndex[Faces_C1] = Vertex_D;
			pDAttrib[PloyIndex*2] = PolyMaterialID;

			pwIndices[Faces_A1] = WORD(Vertex_A);
			pwIndices[Faces_B1] = WORD(Vertex_B);
			pwIndices[Faces_C1] = WORD(Vertex_D);

			DWORD Faces_A2 = (PloyIndex*2+1)*3;
			DWORD Faces_B2 = Faces_A2 + 1;
			DWORD Faces_C2 = Faces_B2 + 1;

			pIndex[Faces_A2] = Vertex_D;
			pIndex[Faces_B2] = Vertex_B;
			pIndex[Faces_C2] = Vertex_C;
			pAttrib[PloyIndex*2+1] = PolyMaterialID;
			pDIndex[Faces_A2] = Vertex_D;
			pDIndex[Faces_B2] = Vertex_B;
			pDIndex[Faces_C2] = Vertex_C;
			pDAttrib[PloyIndex*2+1] = PolyMaterialID;

			pwIndices[Faces_A2] = WORD(Vertex_D);
			pwIndices[Faces_B2] = WORD(Vertex_B);
			pwIndices[Faces_C2] = WORD(Vertex_C);

		}
	}	

	D3DXComputeBoundingBox((D3DXVECTOR3*)pVers,m_dNumVertices,sizeof(VFormat::FACES_NORMAL_TEXTURE1),
		&m_BBox_A,&m_BBox_B);
	D3DXComputeBoundingBox((D3DXVECTOR3*)pDVers,m_dNumVertices,sizeof(VFormat::FACES_NORMAL_TEXTURE1),
		&m_BBox_A,&m_BBox_B);

	if (FAILED(pMesh->UnlockVertexBuffer()))
		return E_FAIL;
	if (FAILED(pMesh->UnlockIndexBuffer()))
		return E_FAIL;
	if (FAILED(pMesh->UnlockAttributeBuffer()))
		return E_FAIL;

	if (FAILED(pDMesh->UnlockVertexBuffer()))
		return E_FAIL;
	if (FAILED(pDMesh->UnlockIndexBuffer()))
		return E_FAIL;
	if (FAILED(pDMesh->UnlockAttributeBuffer()))
		return E_FAIL;
	if (FAILED(m_pibIndices->Unlock()))
		return E_FAIL;
	m_pWaterUp = pMesh;		
	m_pWaterDn = pDMesh;	


	//水面网格的材质
	m_dNumMaterial = 1;
	m_lpMaterial = new MATERIAL[m_dNumMaterial];
	ZeroMemory(m_lpMaterial,sizeof(MATERIAL)*m_dNumMaterial);

	DWORD Def_Option = MATERIAL_OPTION_ZBUFFER_TRUE|
		MATERIAL_OPTION_FILL_SOLID|
		MATERIAL_OPTION_SHADE_GOURAUD|
		MATERIAL_OPTION_CULL_NONE|
		MATERIAL_OPTION_SPECULARENABLE;

	for(DWORD i=0;i<m_dNumMaterial;i++)
	{
		m_lpMaterial[i].m_sMaterial9.Diffuse.r = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.g = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.b = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.a = 1.0f ;
		m_lpMaterial[i].m_sMaterial9.Ambient = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Specular = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Power = 15;
		m_lpMaterial[i].m_dOption = Def_Option;
	} 

	TCHAR Name[256];
	wsprintf(Name,"%s\\Water.Mtl",g_Def_ModelDirectory);
	LoadMaterial(Name);  


	//天空盒的纹理
	wsprintf(Name,"%s\\%s",g_Def_AppDirectory,"Textures\\LobbyCube.dds");
	if( FAILED( hr = D3DXCreateCubeTextureFromFile( g_pd3dDevice,Name, &m_pSkyCubeTex ) ) )
		return hr; 
	//水面的纹理
	wsprintf(Name,"%s\\%s",g_Def_AppDirectory,"Textures\\Water.bmp");
	if( FAILED( hr = D3DXCreateTextureFromFileEx(g_pd3dDevice, Name, D3DX_DEFAULT, D3DX_DEFAULT, 
		D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, 
		D3DX_DEFAULT, 0, NULL, NULL, &m_pWaterTex) ))
		return hr;
	/*
	// Effect
	wsprintf(Name,"%s\\%s",g_Def_AppDirectory,"water.fx");
	if(FAILED(hr = D3DXCreateEffectFromFile(g_pd3dDevice, Name, NULL, NULL, 0, NULL, &m_pEffect, NULL)))
	return hr;
	m_pEffect->OnResetDevice();
	m_pEffect->SetTexture("tFLR", m_pWaterTex);
	m_pEffect->SetTexture("tENV", m_pSkyCubeTex);
	*/

	//创建水面bump纹理
	if( FAILED( InitBumpMap() ) )
		return E_FAIL;
	//	m_pEffect->SetTexture("tBump", m_pBumpMapTexture);
	WSea.Initialize(m_dwNumPoly_X,m_dwNumPoly_Z);
	Water.Initialize(m_pWaterUp,m_dwNumPoly_X,m_dwNumPoly_Z);   //初始化水纹
	Water.Drop();                                               //产生水纹  
	Ripple.Initialize(m_pWaterUp,m_dwNumPoly_X,m_dwNumPoly_Z);  //初始化涟漪纹


	return S_OK;

}
Пример #13
0
HRESULT InitScene()
{
	HRESULT hr;
	D3DDISPLAYMODE mode;

	if( FAILED(hr = direct3d->GetAdapterDisplayMode(0, &mode)) )
	{
		MYERROR("Could not get adapter mode");
		return hr;
	}
	
	if( FAILED(hr = direct3d->CheckDeviceFormat( 0, D3DDEVTYPE_HAL, mode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)) )
	{
		MYERROR("No floating point rendertarget support");
		return hr;
	}
	
	// más depth/stencil-el még müködhet
	if( FAILED(hr = direct3d->CheckDepthStencilMatch( 0, D3DDEVTYPE_HAL, mode.Format, D3DFMT_A16B16G16R16F, D3DFMT_D24S8)) )
	{
		MYERROR("D3DFMT_A16B16G16R16F does not support D3DFMT_D24S8");
		return hr;
	}

	D3DVERTEXELEMENT9 elem[] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0 },
		{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()
	};
	
	SetWindowText(hwnd, TITLE);

	MYVALID(D3DXLoadMeshFromX("../media/meshes/skullocc3.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &mesh1));
	MYVALID(D3DXLoadMeshFromX("../media/meshes//knot.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &mesh2));
	MYVALID(D3DXLoadMeshFromX("../media/meshes//teapot.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &mesh3));
	MYVALID(D3DXLoadMeshFromX("../media/meshes/sky.X", D3DXMESH_MANAGED, device, NULL, NULL, NULL, NULL, &skymesh));

	mesh = mesh1;

	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/altar.dds", &skytexture));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/altar_rough.dds", &roughspecular));
	MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/grace.dds", &skytexture));
	MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/grace_rough.dds", &roughspecular));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/beach.dds", &skytexture));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/beach_rough.dds", &roughspecular));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/stpeters.dds", &skytexture));
	//MYVALID(D3DXCreateCubeTextureFromFile(device, "../media/textures/stpeters_rough.dds", &roughspecular));

	MYVALID(D3DXCreateTextureFromFile(device, "../media/textures/gold.jpg", &texture));
	MYVALID(D3DXCreateTextureFromFile(device, "../media/textures/fresnel.png", &fresneltexture));

	// downsample & blur textures
	for( int i = 0; i < 5; ++i )
	{
		MYVALID(device->CreateTexture(screenwidth / (2 << i), screenheight / (2 << i), 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &dstargets[i], NULL));

		MYVALID(device->CreateTexture(screenwidth / (2 << i), screenheight / (2 << i), 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &blurtargets[i], NULL));

		MYVALID(blurtargets[i]->GetSurfaceLevel(0, &blursurfaces[i]));
		MYVALID(dstargets[i]->GetSurfaceLevel(0, &dssurfaces[i]));
	}

	// star textures (8x 1 MB @ 1080p)
	for( int i = 0; i < 4; ++i )
	{
		for( int j = 0; j < 2; ++j )
		{
			MYVALID(device->CreateTexture(screenwidth / 4, screenheight / 4, 1, D3DUSAGE_RENDERTARGET,
				D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &startargets[i][j], NULL));

			MYVALID(startargets[i][j]->GetSurfaceLevel(0, &starsurfaces[i][j]));
		}
	}

	// lens flare textures (2x 4 MB @ 1080p)
	for( int i = 0; i < 2; ++i )
	{
		MYVALID(device->CreateTexture(screenwidth / 2, screenheight / 2, 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &ghosttargets[i], NULL));

		MYVALID(ghosttargets[i]->GetSurfaceLevel(0, &ghostsurfaces[i]));
	}

	// luminance textures
	for( int i = 0; i < 4; ++i )
	{
		UINT j = 256 / (4 << (2 * i));

		MYVALID(device->CreateTexture(j, j, 1, D3DUSAGE_RENDERTARGET,
			D3DFMT_R16F, D3DPOOL_DEFAULT, &avglumtargets[i], NULL));

		MYVALID(avglumtargets[i]->GetSurfaceLevel(0, &avglumsurfaces[i]));
	}

	// adapted luminance textures
	MYVALID(device->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R16F, D3DPOOL_DEFAULT, &avglumtargets[4], NULL));
	MYVALID(device->CreateTexture(1, 1, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R16F, D3DPOOL_DEFAULT, &avglumtargets[5], NULL));

	MYVALID(avglumtargets[4]->GetSurfaceLevel(0, &avglumsurfaces[4]));
	MYVALID(avglumtargets[5]->GetSurfaceLevel(0, &avglumsurfaces[5]));

	// afterimage textures (2x 4 MB @ 1080p)
	MYVALID(device->CreateTexture(screenwidth / 2, screenheight / 2, 1, D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &afterimages[0], NULL));

	MYVALID(device->CreateTexture(screenwidth / 2, screenheight / 2, 1, D3DUSAGE_RENDERTARGET,
		D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &afterimages[1], NULL));

	MYVALID(afterimages[0]->GetSurfaceLevel(0, &aftersurfaces[0]));
	MYVALID(afterimages[1]->GetSurfaceLevel(0, &aftersurfaces[1]));

	// other
	MYVALID(device->CreateTexture(512, 512, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &text, NULL));
	MYVALID(device->CreateTexture(screenwidth, screenheight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &scenetarget, NULL));
	MYVALID(device->CreateVertexDeclaration(elem, &vertexdecl));

	// other
	MYVALID(scenetarget->GetSurfaceLevel(0, &scenesurface));

	MYVALID(DXCreateEffect("../media/shaders/hdreffects.fx", device, &hdreffect));
	MYVALID(DXCreateEffect("../media/shaders/hdrfresnel.fx", device, &fresnel));
	MYVALID(DXCreateEffect("../media/shaders/sky.fx", device, &skyeffect));

	device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
	device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
	device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

	device->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
	device->SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
	device->SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

	device->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
	device->SetSamplerState(2, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
	device->SetSamplerState(2, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

	device->SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(3, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	device->SetSamplerState(4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(4, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	device->SetSamplerState(5, D3DSAMP_MINFILTER, D3DTEXF_POINT);
	device->SetSamplerState(5, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
	device->SetSamplerState(5, D3DSAMP_MIPFILTER, D3DTEXF_NONE);

	DXRenderText(HELP_TEXT, text, 512, 512);

	// setup camera
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 3, (float)screenwidth / (float)screenheight, 1, 50);
	D3DXMatrixIdentity(&world);

	cameraangle				= D3DXVECTOR2(0.6f, 0.1f);
	objectangle				= D3DXVECTOR2(0, 0);
	exposurevelocity		= 0;
	destexposurevelocity	= 0;
	exposure				= 0.05f;
	targetluminance			= 0.03f;

	UpdateText();

	return S_OK;
}
Пример #14
0
bool LoadAssets()
{
	// loading textures
	gpStoneDM = LoadTexture("Fieldstone_DM.tga");
	if (!gpStoneDM)
	{
		return false;
	}

	gpStoneSM = LoadTexture("Fieldstone_SM.tga");
	if (!gpStoneSM)
	{
		return false;
	}

	gpStoneNM = LoadTexture("Fieldstone_NM.tga");
	if (!gpStoneNM)
	{
		return false;
	}

	D3DXCreateCubeTextureFromFile(gpD3DDevice, "Snow_ENV.dds", &gpSnowENV);
	if (!gpSnowENV)
	{
		return false;
	}

	// loading shaders
	gpEnvironmentMappingShader = LoadShader("EnvironmentMapping.fx");
	if (!gpEnvironmentMappingShader)
	{
		return false;
	}

	gpNoEffect = LoadShader("NoEffect.fx");
	if (!gpNoEffect)
	{
		return false;
	}

	gpGrayScale = LoadShader("Grayscale.fx");
	if (!gpGrayScale)
	{
		return false;
	}

	gpSepia = LoadShader("Sepia.fx");
	if (!gpSepia)
	{
		return false;
	}

	// loading models
	gpTeapot = LoadModel("TeapotWithTangent.x");
	if (!gpTeapot)
	{
		return false;
	}

	return true;
}