1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
|
static bool g_stbCubemapInited = false;
//--------------------------------------------------------------------------------------
// Nom: RenduCubeMap
// Desc: rendu cubemap
//--------------------------------------------------------------------------------------
ID3D10EffectShaderResourceVariable* g_ptxEnvMap; // pour technique rendu cubemap
ID3D10RenderTargetView* g_pEnvMapRTV; // Render target view for the alpha map
ID3D10DepthStencilView* g_pEnvMapOneDSV; // Depth stencil view for environment map for all 1 face
ID3D10EffectVectorVariable* g_pvDiffuse; // élciarage diffus
ID3D10EffectVectorVariable* g_pvSpecular; // éclairage spéculaire
ID3D10EffectVectorVariable* g_pvEye; // eye dir
ID3D10EffectMatrixVariable* g_pmViewCM; // matrice de vue globale cube map
ID3D10InputLayout* g_pVertexLayout = NULL;
ID3D10InputLayout* g_pVertexLayoutCM = NULL; // layout cube map
ID3D10InputLayout* g_pVertexLayoutCMInst = NULL; // layout cube map instancié
ID3D10InputLayout* g_pVertexLayoutEnv = NULL;
D3DXMATRIX g_amCubeMapViewAdjust[6]; // Adjustment for view matrices when rendering the cube map
void RenduCubeMap( ID3D10Device* pd3dDevice )
{
HRESULT hr = E_FAIL;
struct CubeMapVertex
{
D3DXVECTOR3 Pos;
D3DXVECTOR3 Normal;
D3DXVECTOR2 Tex;
};
D3DXMATRIX matCubeMapView[6]; // tableau de vues pour les face du cube
ID3D10EffectTechnique* g_pRenderCubeMapTech; // techniques shader
ID3D10EffectShaderResourceVariable* ptxDiffuse;
ID3D10EffectMatrixVariable* pmWorld;
ID3D10EffectMatrixVariable* pmView;
ID3D10EffectMatrixVariable* pmProj;
ID3D10EffectMatrixVariable* pmWorldView;
ID3D10EffectMatrixVariable* pmWorldViewProj;
D3DXMATRIX g_mProjCM; // Projection matrix for cubic env map rendering
ID3D10EffectTechnique* pSceneTechnique;
// initialisation procédure
if ( !g_stbCubemapInited )
{
g_stbCubemapInited = true; // maj drapeaux d'initialisation
// génère les cube map view matrices, orientées selon chaque face
float fHeight = 1.5f;
D3DXVECTOR3 vEyePt = D3DXVECTOR3( 0.0f, fHeight, 0.0f );
D3DXVECTOR3 vLookDir;
D3DXVECTOR3 vUpDir;
vLookDir = D3DXVECTOR3( 1.0f, fHeight, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &matCubeMapView[0], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( -1.0f, fHeight, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &matCubeMapView[1], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight + 1.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
D3DXMatrixLookAtLH( &matCubeMapView[2], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight - 1.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
D3DXMatrixLookAtLH( &matCubeMapView[3], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight, 1.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &matCubeMapView[4], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight, -1.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &matCubeMapView[5], &vEyePt, &vLookDir, &vUpDir );
// compilation shader
if ( !g_pCubeMapEffect )
{
WCHAR* szEffectFilePath = L"c://DOOM2011/Shaders/CubeMapGS.fx";
VerifHR( D3DX10CreateEffectFromFile(
szEffectFilePath,
NULL,
NULL,
"fx_4_0",
D3D10_SHADER_ENABLE_STRICTNESS||D3D10_SHADER_DEBUG,
0,
pd3dDevice,
NULL,
NULL,
&g_pCubeMapEffect,
NULL,
NULL
) );
if ( hr == S_OK )
OutputDebugString( L"compilation c://DOOM2011/Shaders/CubeMapGS.fx OK\n" );
}
// acquiert shader technique handles
g_pRenderCubeMapTech = g_pCubeMapEffect->GetTechniqueByName( "RenderCubeMap" );
// obtient les handles des paramètres variables shader
ptxDiffuse = g_pCubeMapEffect->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
g_ptxEnvMap = g_pCubeMapEffect->GetVariableByName( "g_txEnvMap" )->AsShaderResource();
g_pvDiffuse = g_pCubeMapEffect->GetVariableByName( "vMaterialDiff" )->AsVector();
g_pvSpecular = g_pCubeMapEffect->GetVariableByName( "vMaterialSpec" )->AsVector();
g_pvEye = g_pCubeMapEffect->GetVariableByName( "vEye" )->AsVector();
g_pmViewCM = g_pCubeMapEffect->GetVariableByName( "g_mViewCM" )->AsMatrix();
pmWorld = g_pCubeMapEffect->GetVariableByName( "mWorld" )->AsMatrix();
pmView = g_pCubeMapEffect->GetVariableByName( "mView" )->AsMatrix();
pmProj = g_pCubeMapEffect->GetVariableByName( "mProj" )->AsMatrix();
pmWorldView = g_pCubeMapEffect->GetVariableByName( "mWorldView" )->AsMatrix();
if ( pmWorldView->IsValid() != TRUE )
return;
pmWorldViewProj= g_pCubeMapEffect->GetVariableByName( "mWorldViewProj" )->AsMatrix();
// créé cubic depth stencil texture.
D3D10_TEXTURE2D_DESC dstex;
dstex.Width = ENVMAPSIZE;
dstex.Height = ENVMAPSIZE;
dstex.MipLevels = 1;
dstex.ArraySize = 6;
dstex.SampleDesc.Count = 1;
dstex.SampleDesc.Quality = 0;
dstex.Format = DXGI_FORMAT_D32_FLOAT;
dstex.Usage = D3D10_USAGE_DEFAULT;
dstex.BindFlags = D3D10_BIND_DEPTH_STENCIL;
dstex.CPUAccessFlags = 0;
dstex.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
VerifHR( pd3dDevice->CreateTexture2D( &dstex, NULL, &g_pEnvMapDepth ) );
// créé depth stencil view pour le cube entier
D3D10_DEPTH_STENCIL_VIEW_DESC DescDS;
DescDS.Format = DXGI_FORMAT_D32_FLOAT;
DescDS.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
DescDS.Texture2DArray.FirstArraySlice = 0;
DescDS.Texture2DArray.ArraySize = 6;
DescDS.Texture2DArray.MipSlice = 0;
VerifHR( pd3dDevice->CreateDepthStencilView( g_pEnvMapDepth, &DescDS, &g_pEnvMapDSV ) );
// créé un depth stencil view pour single face rendering
DescDS.Texture2DArray.ArraySize = 1;
VerifHR( pd3dDevice->CreateDepthStencilView( g_pEnvMapDepth, &DescDS, &g_pEnvMapOneDSV ) );
// créé texture cube map avec mips pour rendu avec env map render target
dstex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dstex.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
dstex.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS | D3D10_RESOURCE_MISC_TEXTURECUBE;
dstex.MipLevels = MIPLEVELS;
VerifHR( pd3dDevice->CreateTexture2D( &dstex, NULL, &g_pEnvMap ) );
// créé une render target view pour l'ensemble des 6 faces
D3D10_RENDER_TARGET_VIEW_DESC DescRT;
DescRT.Format = dstex.Format;
DescRT.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
DescRT.Texture2DArray.FirstArraySlice = 0;
DescRT.Texture2DArray.ArraySize = 6;
DescRT.Texture2DArray.MipSlice = 0;
VerifHR( pd3dDevice->CreateRenderTargetView( g_pEnvMap, &DescRT, &g_pEnvMapRTV ) );
// créé les target views pour chaque face du cube
DescRT.Texture2DArray.ArraySize = 1;
for( int i = 0; i < 6; ++i )
{
DescRT.Texture2DArray.FirstArraySlice = i;
VerifHR( pd3dDevice->CreateRenderTargetView( g_pEnvMap, &DescRT, &g_apEnvMapOneRTV[i] ) );
}
// créé shader resource view pour la cubic env map
D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
ZeroMemory( &SRVDesc, sizeof( SRVDesc ) );
SRVDesc.Format = dstex.Format;
SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
SRVDesc.TextureCube.MipLevels = MIPLEVELS;
SRVDesc.TextureCube.MostDetailedMip = 0;
VerifHR( pd3dDevice->CreateShaderResourceView( g_pEnvMap, &SRVDesc, &g_pEnvMapSRV ) );
// définit le vertex data layout
const D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};
g_pRenderCubeMapTech = g_pCubeMapEffect->GetTechniqueByName( "RenderCubeMap" );
// créé le vertex layout pour la cube map
D3D10_PASS_DESC PassDesc;
g_pRenderCubeMapTech->GetPassByIndex( 0 )->GetDesc( &PassDesc );
VerifHR( pd3dDevice->CreateInputLayout( layout, 3, PassDesc.pIAInputSignature,
PassDesc.IAInputSignatureSize, &g_pVertexLayoutCM ) );
// créé le layout mapping environnement
pSceneTechnique = g_pCubeMapEffect->GetTechniqueByName( "RenderEnvMappedScene_NoTexture" ); // aquiert handle technique
if ( pSceneTechnique->IsValid() != TRUE )
return;
pSceneTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
VerifHR( pd3dDevice->CreateInputLayout( layout, 3, PassDesc.pIAInputSignature,
PassDesc.IAInputSignatureSize, &g_pVertexLayoutEnv ) );
// créé matrice de projection cube map
D3DXMatrixPerspectiveFovLH( &g_mProjCM, D3DX_PI * 0.5f, 1.0f, .5f, 1000.f );
// créé un quad vertex buffer pour la visualisation
D3D10_BUFFER_DESC bufferdesc =
{
6 * sizeof( CubeMapVertex ),
D3D10_USAGE_DEFAULT,
D3D10_BIND_VERTEX_BUFFER,
0,
0
};
CubeMapVertex QuadVertices[6] =
{
{ D3DXVECTOR3( -1.0f, 1.0f, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
{ D3DXVECTOR3( 1.0f, 1.0f, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
{ D3DXVECTOR3( -1.0f, -1.0f, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
{ D3DXVECTOR3( -1.0f, -1.0f, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
{ D3DXVECTOR3( 1.0f, 1.0f, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
{ D3DXVECTOR3( 1.0f, -1.0f, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) }
};
D3D10_SUBRESOURCE_DATA InitData =
{
QuadVertices,
sizeof( QuadVertices ),
sizeof( QuadVertices )
};
VerifHR( pd3dDevice->CreateBuffer( &bufferdesc, &InitData, &g_pVBVisual ) ); // pour visualisation ???
} // fin de if !inited
// créé quad vb visualisation cube texture et rendu dans face
// acquiert dimensions du backbuffer
const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc = DXUTGetDXGIBackBufferSurfaceDesc();
int iXCoord = 0;
int iYCoord = 0;
int iLargeur = ENVMAPSIZE;
int iHauteur = ENVMAPSIZE;
// convertit de screen coordinates en clip space coordinates, ( 0, iWidth ) -> ( -1.0f, 1.0f )
float fLeft, fRight, fTop, fBottom;
fLeft = ( iXCoord * 2.0f /pBackBufferSurfaceDesc->Width )- 1.0f;
fRight = ( ( iXCoord + iLargeur ) * 2.0f / pBackBufferSurfaceDesc->Width ) - 1.0f;
fTop = 1.0f -( iYCoord * 2.0f / pBackBufferSurfaceDesc->Height );
fBottom = 1.0f - ( ( iYCoord + iHauteur ) * 2.0f / pBackBufferSurfaceDesc->Height );
float fQuadLargeur = fRight - fLeft;
float fQuadHauteur = fTop - fBottom;
struct QUADNORM_VERTEX // structure de description du quad screen vertex
{
D3DXVECTOR3 pos; // coord
D3DXVECTOR3 norm;
D3DXVECTOR2 tex; // coordonnées de mapping texture
};
QUADNORM_VERTEX QuadTestVertices[] =
{
{ D3DXVECTOR3( -fQuadLargeur, -fQuadHauteur, 0.5f ) , D3DXVECTOR3( 0.0f, 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ) },
{ D3DXVECTOR3( -fQuadLargeur, fQuadHauteur, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ) },
{ D3DXVECTOR3( fQuadLargeur, fQuadHauteur, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ) },
{ D3DXVECTOR3( fQuadLargeur, -fQuadHauteur, 0.5f ), D3DXVECTOR3( 0.0f, 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },
};
// copie nouveau vb quad
QUADNORM_VERTEX* pVB;
VerifHR( g_pQuadScreenVB->Map( D3D10_MAP_WRITE_DISCARD , 0, ( LPVOID* )&pVB ) ); // D3D10_MAP_READ_WRITE D3D10_MAP_WRITE
memcpy( pVB, QuadTestVertices, sizeof( QuadTestVertices ) );
g_pQuadScreenVB->Unmap();
// RenderSceneIntoCubeMap()
// construction de la cube map, sauve old render target et depth stencil
ID3D10RenderTargetView* apOldRTVs[1] = { NULL };
ID3D10DepthStencilView* pOldDS = NULL;
pd3dDevice->OMGetRenderTargets( 1, apOldRTVs, &pOldDS );
// sauve old viewport
D3D10_VIEWPORT OldVP;
UINT cRT = 1;
pd3dDevice->RSGetViewports( &cRT, &OldVP );
// créé un nouveau viewport pour la cube map
D3D10_VIEWPORT SMVP;
SMVP.Height = ENVMAPSIZE;
SMVP.Width = ENVMAPSIZE;
SMVP.MinDepth = 0;
SMVP.MaxDepth = 1;
SMVP.TopLeftX = 0;
SMVP.TopLeftY = 0;
pd3dDevice->RSSetViewports( 1, &SMVP );
// génère les cube map view matrices pour chaque face
float fHeight = 1.5f;
D3DXVECTOR3 vEyePt = D3DXVECTOR3( 0.0f, fHeight, 0.0f );
D3DXVECTOR3 vLookDir;
D3DXVECTOR3 vUpDir;
vLookDir = D3DXVECTOR3( 1.0f, fHeight, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &g_amCubeMapViewAdjust[0], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( -1.0f, fHeight, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &g_amCubeMapViewAdjust[1], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight + 1.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
D3DXMatrixLookAtLH( &g_amCubeMapViewAdjust[2], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight - 1.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
D3DXMatrixLookAtLH( &g_amCubeMapViewAdjust[3], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight, 1.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &g_amCubeMapViewAdjust[4], &vEyePt, &vLookDir, &vUpDir );
vLookDir = D3DXVECTOR3( 0.0f, fHeight, -1.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &g_amCubeMapViewAdjust[5], &vEyePt, &vLookDir, &vUpDir );
// Here, compute the view matrices used for cube map rendering.
// First, construct mViewAlignCM, a view matrix with the same orientation as m_mView but with eye point at the car position.
// matrice de positionnement de l'observateur pour générer chaque face
D3DXMATRIX mViewAlignCM;
D3DXMatrixIdentity( &mViewAlignCM );
mViewAlignCM._41 = 0; //g_matView._41;
mViewAlignCM._42 = 0; // g_matView._42;
mViewAlignCM._43 = 0; // g_matView._43;
// combine les 6 differentes view direction, corrigé par la position de l'oeil
// pour obtenir une matrice de vue pour chaque face
D3DXMATRIX amViewCM[6];
for( int view = 0; view < 6; ++view )
{
D3DXMatrixMultiply( &amViewCM[view], &mViewAlignCM, &g_amCubeMapViewAdjust[view] );
}
pd3dDevice->IASetInputLayout( g_pVertexLayoutCM ); // assigne le layout rendu cubemap
ID3D10EffectTechnique* pTechnique = g_pCubeMapEffect->GetTechniqueByName( "RenderCubeMap" ); // aquiert handle technique
if ( pTechnique->IsValid() != TRUE )
return;
// assigne variables shader
g_pmViewCM = g_pCubeMapEffect->GetVariableByName( "g_mViewCM" )->AsMatrix();
pmWorld = g_pCubeMapEffect->GetVariableByName( "mWorld" )->AsMatrix();
pmView = g_pCubeMapEffect->GetVariableByName( "mView" )->AsMatrix();
pmProj = g_pCubeMapEffect->GetVariableByName( "mProj" )->AsMatrix();
ptxDiffuse = g_pCubeMapEffect->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
ptxDiffuse->SetResource( g_pTestTex1_SRV ); // texture pour la face
if ( ptxDiffuse->IsValid() != TRUE )
return;
D3DXMATRIX mWorld;
D3DXMatrixIdentity( &mWorld );
// rendu de chaque face du cube
for( int view = 0; view < 6; ++view )
{
// efface cible et stencil buffer de la face
float ClearColor[4] = { 0.0f, 0.8f, 0.9f, 1.0f };
pd3dDevice->ClearRenderTargetView( g_apEnvMapOneRTV[view], ClearColor );
pd3dDevice->ClearDepthStencilView( g_pEnvMapOneDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );
// fixe cible de rendu selon la face
ID3D10RenderTargetView* aRTViews[ 1 ] = { g_apEnvMapOneRTV[view] };
pd3dDevice->OMSetRenderTargets( sizeof( aRTViews ) / sizeof( aRTViews[0] ), aRTViews, g_pEnvMapOneDSV );
// assigne variables shader
//mWorld *= g_matView;
pmWorld->SetMatrix( ( float* )&mWorld ); // matrice du monde
g_pmViewCM->SetMatrix( ( float* )&(amViewCM[view]) ); // matrice de vue de la face
pmProj->SetMatrix( ( float* )&g_matProj ); // matrice de projection
ptxDiffuse->SetResource( g_pTestTex1_SRV ); // assigne texture pour la face
// ICI, rendu de chaque face avec texture
Rendu_F9( pd3dDevice ); // rendu tableau d'étoiles instanciées sur la face du cube
RenduInfos( pd3dDevice ); // rendu text infos
} // fin de rendu faces du cube
pd3dDevice->RSSetViewports( 1, &OldVP ); // restaure old view port
pd3dDevice->OMSetRenderTargets( 1, apOldRTVs, pOldDS ); // restaure old RT and DS buffer views
pd3dDevice->GenerateMips( g_pEnvMapSRV ); // génère Mip Maps de la cubemap
//SAFE_RELEASE( apOldRTVs[0] ); // libère les cibles de rendu
//SAFE_RELEASE( pOldDS );
// fin de RenderSceneIntoCubeMap()
// DEBUG: sauve texture 2D de la map créée
// dimensions : 3072x512, 6*512 de large
//D3DX10_IMAGE_FILE_FORMAT loadinfo = D3DX10_IFF_DDS;
//VerifHR( D3DX10SaveTextureToFileW(
// g_pEnvMap,
// loadinfo,
// L"C://DOOM2011/Test_cubemap.dds"
// ) );
// DEBUG 13-2-2011
// exploitation du rendu cubemap qui se trouve dans g_pEnvMapSRV texture cube
// pour rendu sur un quad
// assigne layout mapping environnement
pd3dDevice->IASetInputLayout( g_pVertexLayoutEnv ); // assigne le layout rendu cubemap
// créé le layout mapping environnement
pSceneTechnique = g_pCubeMapEffect->GetTechniqueByName( "RenderEnvMappedScene_NoTexture" ); // aquiert handle technique
if ( pSceneTechnique->IsValid() != TRUE )
return;
pmWorld = g_pCubeMapEffect->GetVariableByName( "mWorld" )->AsMatrix();
pmView = g_pCubeMapEffect->GetVariableByName( "mView" )->AsMatrix();
pmProj = g_pCubeMapEffect->GetVariableByName( "mProj" )->AsMatrix();
pmWorldView = g_pCubeMapEffect->GetVariableByName( "mWorldView" )->AsMatrix();
if ( pmWorldView->IsValid() != TRUE )
return;
pmWorldViewProj= g_pCubeMapEffect->GetVariableByName( "mWorldViewProj" )->AsMatrix();
// obtient le input layout de la technique
D3D10_TECHNIQUE_DESC techDesc;
VerifHR( pSceneTechnique->GetDesc( &techDesc ) );
// Cleanup the Render Target View
ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
float ClearColor[4] = { 0.0, 0.5, 1.0, 1.0 };
pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
// Clear the depth stencil
ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );
// calcul matrices
D3DXMATRIX matView;
D3DXVECTOR3 vEye( 0.0f, 0.0f, -2.5f ); // distance de vue de la skybox
D3DXVECTOR3 vAt( 0.0f, 0.0f, 1.0f );
D3DXVECTOR3 vUp( 0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH( &matView, &vEye, &vAt, &vUp );
D3DXMATRIX mWorldRoom, mWorldView, mWorldViewProj, matTrans, mViewTrans;
mViewTrans = g_matView;
mViewTrans._41 = 0.0f;
mViewTrans._42 = 0.0f;
mViewTrans._43 = 0.0f;
mViewTrans._44 = 1.0f;
mWorld *= mViewTrans; // orientation vue skybox = orientation cam depuis pt 0
// orientation skybox
D3DXMatrixIdentity( &mWorldRoom );
D3DXMatrixScaling( &mWorldRoom, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, 0.0f );
mWorldRoom *= matTrans;
mWorldRoom *= mViewTrans; // mapping dans la avec angle de rotation caméra
pmWorld->SetMatrix( ( float* )&mWorldRoom );
// calcule matrice world*view*proj
mWorldView = mWorldRoom * matView;
mWorldViewProj = mWorldView*g_matProj;
//pmView->SetMatrix( ( float* )&matView );
pmWorldView->SetMatrix( ( float* )&mWorldView );
pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProj );
pmProj->SetMatrix( ( float* )&g_matProj ); // matrice de projection
// paramètre cube texture pour rendu sur quad
g_ptxEnvMap->SetResource( g_pEnvMapSRV );
g_pvDiffuse->SetFloatVector( (float*)&( D3DXVECTOR4( 1, 1, 1, 0 ) ) ); // couleur matériaux
g_pvSpecular->SetFloatVector( (float*)&( D3DXVECTOR4( 1, 1, 1, 0.0f ) ) );
ID3D10RasterizerState* pOldRaster;
pd3dDevice->RSGetState( &pOldRaster ); // sauve rasterizer
pd3dDevice->RSSetState( g_p2DRasterizerState ); // déactive culling pour affichage quad cubemap
// assigne le nouveau vb quad
UINT stride = sizeof(QUADNORM_VERTEX);
UINT offset = 0;
pd3dDevice->IASetVertexBuffers( 0, 1, &g_pQuadScreenVB, &stride, &offset ); // assigne VB entrée
pd3dDevice->IASetIndexBuffer( g_pQuadScreenIB, DXGI_FORMAT_R32_UINT, 0 ); // assigne IB
pd3dDevice->PSSetShaderResources( 0, 1, &g_pEnvMapSRV ); // assigne cube texture comme entrée shader
// rendu quad avec cubemap
for( UINT uiPass = 0; uiPass < techDesc.Passes; uiPass++ )
{
pSceneTechnique->GetPassByIndex( uiPass )->Apply( 0 );
pd3dDevice->DrawIndexed( 6, 0, 0 ); // draw quad indexé
}
pd3dDevice->RSSetState( pOldRaster ); // restaure rasterizer
//VerifHR ( ScreenShotJPG() ); // copie écran vers .jpg avec date et heure
return;
} |
Partager