IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

DirectX Discussion :

Cube map [DirectX 10]


Sujet :

DirectX

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut Cube map
    bonjour
    je suis entrain d'étudier l'exemple CubeMapGS_2010 du SDK,
    et j'ai du mal à comprendre comment exploiter la TEXTURECUBE générée lors
    de la fonction RenderIntoCubeMap()

    j'ai repris cette fonction et j'obtiens la création d'une texturecube avec la technique shader "RenderCubeMap"

    j'obtiens une texture avec les 6 faces du cube rendu une à une,
    mais je vois pas comment afficher le résultat

    faut-il utiliser une autre technique du shader "RenderEnvMappedScene", ou "RenderScene" avec le résultat de la technique "RenderCubeMap" ?

    j'avoue que je suis perdu dans la logique de fonctionnement de l'exemple
    et que la doc est pour le moins succincte

    quelqu'un peut il m'éclairer sur la logique de fonctionnement du programme ?

    un autre exemple de cube mapping quelque part ?

    voici le code que j'ai utilisé pour générer la texture cube
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    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;
     
    	ID3D10Texture2D*                    g_pEnvMap;					// Environment map
    	ID3D10RenderTargetView*             g_pEnvMapRTV;				// Render target view for the alpha map
    	ID3D10Texture2D*                    g_pEnvMapDepth;				// Depth stencil for the environment map
    	ID3D10DepthStencilView*             g_pEnvMapDSV;				// Depth stencil view for environment map for all 6 faces
    	ID3D10DepthStencilView*             g_pEnvMapOneDSV;			// Depth stencil view for environment map for all 1 face
    	//ID3D10Buffer*                       g_pVBVisual;				// Vertex buffer for quad used for visualization
    	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
    	D3DXMATRIX                          g_mProjCM;						// Projection matrix for cubic env map rendering
     
    	// 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" );
     
    		//g_pRenderCubeMapInstTech = g_pCubeMapEffect->GetTechniqueByName( "RenderCubeMap_Inst" );
    		//g_pRenderSceneTech = g_pCubeMapEffect->GetTechniqueByName( "RenderScene" );
    		//g_pRenderEnvMappedSceneTech = g_pCubeMapEffect->GetTechniqueByName( "RenderEnvMappedScene" );
    		//g_pRenderEnvMappedSceneNoTexTech = g_pCubeMapEffect->GetTechniqueByName( "RenderEnvMappedScene_NoTexture" );
    		//g_pRenderEnvMappedGlassTech = g_pCubeMapEffect->GetTechniqueByName( "RenderEnvMappedGlass" );
     
    		// obtient les handles des paramètres variables shader
    		ptxDiffuse = g_pCubeMapEffect->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
    		//g_ptxEnvMap = g_pCubeMapEffect->GetVariableByName( "g_txEnvMap" )->AsShaderResource();
    		//g_ptxFalloffMap = g_pCubeMapEffect->GetVariableByName( "g_txFalloff" )->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();
    		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 ) );
     
    		//g_pRenderCubeMapInstTech->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    		//VerifHR( pd3dDevice->CreateInputLayout( layout, 3, PassDesc.pIAInputSignature,
    		//	PassDesc.IAInputSignatureSize, &g_pVertexLayoutCMInst ) );
     
    		//g_pRenderEnvMappedSceneTech->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
     
     
    	// 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 = -g_matView._41;
    	mViewAlignCM._42 = -g_matView._42;
    	mViewAlignCM._43 = -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();
     
    	// 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
    		pmWorld->SetMatrix( ( float* )&g_matWorld );		// 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 );			// texture pour la face
     
     
    		// MANQUE QUELQUE CHOSE ICI ??
     
    		// rendu tableau instancié étoiles sur la face du cube
    		Rendu_F9( pd3dDevice );
    	}
     
     
    	pd3dDevice->RSSetViewports( 1, &OldVP );					// restaure old view port
    	pd3dDevice->OMSetRenderTargets( 1, apOldRTVs, pOldDS );		// restaure old RT and DS buffer views
     
    	pd3dDevice->GenerateMips( g_pEnvMapSRV );					// Generate Mip Maps ???
     
    	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
    	// à faire exploiter le résultat du rendu cubemap qui de setrouve dans g_pEnvMapSRV texture cube
     
    	return;
    }
    le shader utilisé dans l'exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    //--------------------------------------------------------------------------------------
    // File: CubeMapGS.fx
    //
    // The effect file for the CubeMapGS sample.
    //	modif 12-1-2011
    //--------------------------------------------------------------------------------------
     
    #define IOR 2.5
     
    cbuffer cbMultiPerFrameFrame
    {
    	matrix mWorldViewProj : WORLDVIEWPROJECTION;
    	matrix mWorldView : WORLDVIEW;
    	matrix mWorld : WORLD;
    	matrix mView : VIEW;
    	matrix mProj : PROJECTION;
    	float3 vEye;										// Eye point in world space
    };
     
    cbuffer cbPerMaterial
    {
    	float4 vMaterialDiff;
    	float4 vMaterialSpec;
    };
     
    cbuffer cbPerCubeRender
    {
    	matrix g_mViewCM[6];			// View matrices for cube map rendering
    };
     
     
    cbuffer cbConstants
    {
    	float fReflectivity = 1.0f;
    	float3 skyDir = { 0.0,1.0,0.0 };
    	float R0Constant = ((1.0- (1.0/IOR) )*(1.0- (1.0/IOR) ))/((1.0+ (1.0/IOR) )*(1.0+ (1.0/IOR) ));
    	float R0Inv = 1.0 - ((1.0- (1.0/IOR) )*(1.0- (1.0/IOR) ))/((1.0+ (1.0/IOR) )*(1.0+ (1.0/IOR) ));
    	float4 vFrontColor = { 0.3, 0.1, 0.6, 1.0 };
    	float4 vBackColor = { 0.0, 0.3, 0.3, 1.0 };
    	float4 vHighlight1 = { 0.9, 0.8, 0.9, 1.0 };
    	float4 vHighlight2 = { 1.0, 1.0, 0.6, 1.0 };
    	float lightMul = 3.0;
    	float4 vOne = { 1,1,1,1 };
    };
     
    Texture2D g_txDiffuse;
    Texture2D g_txFalloff;				// falloff texture for diffuse color shifting
    TextureCube g_txEnvMap;
    Texture2D g_txVisual;
     
    SamplerState g_samLinear
    {
        Filter = MIN_MAG_MIP_LINEAR;
        AddressU = Wrap;
        AddressV = Wrap;
    };
     
    SamplerState g_samPoint
    {
        Filter = MIN_MAG_MIP_POINT;
        AddressU = Clamp;
        AddressV = Clamp;
    };
     
    SamplerState g_samCube
    {
        Filter = ANISOTROPIC;
        AddressU = Clamp;
        AddressV = Clamp;
    };
     
     
    RasterizerState RasNoCull
    {
        CullMode = None;
    };
     
     
    BlendState NoBlend
    {
        BlendEnable[0] = FALSE;
    };
     
     
    //--------------------------------------------------------------------------------------
    // Cubemap via Geometry Shader
    //--------------------------------------------------------------------------------------
    struct VS_CUBEMAP_IN
    {
    	float4 Pos		: POSITION;
    	float3 Normal	: NORMAL;
    	float2 Tex		: TEXCOORD0;
    };
     
    struct GS_CUBEMAP_IN
    {
    	float4 Pos		: SV_POSITION;				// World position
        float2 Tex		: TEXCOORD0;				// Texture coord
    };
     
     
    struct PS_CUBEMAP_IN
    {
        float4 Pos : SV_POSITION;					// Projection coord
        float2 Tex : TEXCOORD0;						// Texture coord
        uint RTIndex : SV_RenderTargetArrayIndex;
    };
     
     
     
     
    GS_CUBEMAP_IN VS_CubeMap( VS_CUBEMAP_IN input )
    {
        GS_CUBEMAP_IN output = (GS_CUBEMAP_IN)0.0f;
     
        // Compute world position
        output.Pos = mul( input.Pos, mWorld );
     
        // Propagate tex coord
        output.Tex = input.Tex;
     
        return output;
    }
     
    [maxvertexcount(18)]
    void GS_CubeMap( triangle GS_CUBEMAP_IN input[3], inout TriangleStream<PS_CUBEMAP_IN> CubeMapStream )
    {
        for( int f = 0; f < 6; ++f )
        {
            // Compute screen coordinates
            PS_CUBEMAP_IN output;
            output.RTIndex = f;
            for( int v = 0; v < 3; v++ )
            {
                output.Pos = mul( input[v].Pos, g_mViewCM[f] );				// oriente vertices  selon matrice de vue de la face
                output.Pos = mul( output.Pos, mProj );
                output.Tex = input[v].Tex;
                CubeMapStream.Append( output );
            }
            CubeMapStream.RestartStrip();
        }
    }
     
     
    float4 PS_CubeMap( PS_CUBEMAP_IN input ) : SV_Target
    {
        return g_txDiffuse.Sample( g_samLinear, input.Tex );
    }
     
     
     
     
    //--------------------------------------------------------------------------------------
    // Techniques
    //--------------------------------------------------------------------------------------
     
     
    technique10 RenderCubeMap
    {
        pass p0
        {
            SetVertexShader( CompileShader( vs_4_0, VS_CubeMap() ) );
            SetGeometryShader( CompileShader( gs_4_0, GS_CubeMap() ) );
            SetPixelShader( CompileShader( ps_4_0, PS_CubeMap() ) );
     
            SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
    };
     
     
     
    //--------------------------------------------------------------------------------------
    // Scene rendering
    //--------------------------------------------------------------------------------------
     
     
    struct VS_OUTPUT_SCENE
    {
        float4 Pos : SV_POSITION;
        float2 Tex : TEXCOORD0;
    };
     
     
    VS_OUTPUT_SCENE VS_Scene( float4 Pos : POSITION, float3 Normal : NORMAL, float2 Tex : TEXCOORD )
    {
        VS_OUTPUT_SCENE o = (VS_OUTPUT_SCENE)0.0f;
     
        // Output position
        o.Pos = mul( Pos, mWorldViewProj );
     
        // Propagate tex coord
        o.Tex = Tex;
     
        return o;
    }
     
     
    float4 PS_Scene( VS_OUTPUT_SCENE vin ) : SV_Target
    {
        return g_txDiffuse.Sample( g_samLinear, vin.Tex );
    }
     
     
     
    technique10 RenderScene
    {
        pass p0
        {
            SetVertexShader( CompileShader( vs_4_0, VS_Scene() ) );
            SetGeometryShader( NULL );
            SetPixelShader( CompileShader( ps_4_0, PS_Scene() ) );
     
            SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
    };
     
     
     
     
    //--------------------------------------------------------------------------------------
    // Environment-mapped scene
    //--------------------------------------------------------------------------------------
     
    struct VS_OUTPUT_SCENEENV
    {
        float4 Pos : SV_POSITION;
        float2 Bary : TEXCOORD0;	// Barycentric interpolants
        float4 wPos : TEXCOORD1; // World space position
        float4 wvPos : TEXCOORD2; // WorldView space position
        float3 wN : TEXCOORD3;       // World space normal
     
        float3 Normals[6] : SIXNORMS; // 6 normal positions
    };
     
    float4 ColorApprox( float3 incident, float3 normal )
    {
        float d = saturate( dot(incident,normal)-0.01 );
        float Ramp = (float)g_txFalloff.Sample( g_samPoint, float2(d,0) );
        d = d*Ramp;
     
        return vFrontColor*(d) + vBackColor*(1.0-d);
    }
     
    float FresnelApprox( float3 incident, float3 normal )
    {
         return R0Constant + R0Inv * pow( 1.0-dot(incident,normal),5.0 );
    }
     
    VS_OUTPUT_SCENEENV VS_EnvMappedScene( float4 Pos : POSITION, float3 Normal : NORMAL, float2 Tex : TEXCOORD )
    {
        VS_OUTPUT_SCENEENV o = (VS_OUTPUT_SCENEENV)0.0f;
     
        // Output position
        o.Pos = mul( Pos, mWorldViewProj );
     
        // Compute world space position
        o.wPos = mul( Pos, mWorld );
     
        // Compute worldview space position
        o.wvPos = mul( Pos, mWorldView );
     
        // Propogate the normal
        o.wN = Normal;
     
        return o;
    }
     
    [maxvertexcount(3)]
    void GS_SetupNormalInterp( triangle VS_OUTPUT_SCENEENV In[3], inout TriangleStream<VS_OUTPUT_SCENEENV> SceneEnvStream )
    {	
    	In[0].Bary = float2(0,0);
    	In[1].Bary = float2(1,0);
    	In[2].Bary = float2(0,1);
     
    	float3 nNorm1 = normalize( In[0].wN + In[1].wN );
    	float3 nNorm3 = normalize( In[2].wN + In[0].wN );
    	float3 nNorm5 = normalize( In[1].wN + In[2].wN );
     
    	In[0].Normals[0] = In[0].wN;
    	In[0].Normals[1] = nNorm1;
    	In[0].Normals[2] = In[1].wN;
    	In[0].Normals[3] = nNorm3;
    	In[0].Normals[4] = In[2].wN;
    	In[0].Normals[5] = nNorm5;
    	SceneEnvStream.Append( In[0] );
     
    	In[1].Normals[0] = In[0].wN;
    	In[1].Normals[1] = nNorm1;
    	In[1].Normals[2] = In[1].wN;
    	In[1].Normals[3] = nNorm3;
    	In[1].Normals[4] = In[2].wN;
    	In[1].Normals[5] = nNorm5;
    	SceneEnvStream.Append( In[1] );
     
    	In[2].Normals[0] = In[0].wN;
    	In[2].Normals[1] = nNorm1;
    	In[2].Normals[2] = In[1].wN;
    	In[2].Normals[3] = nNorm3;
    	In[2].Normals[4] = In[2].wN;
    	In[2].Normals[5] = nNorm5;
    	SceneEnvStream.Append( In[2] );
     
    	SceneEnvStream.RestartStrip();
    }
     
    float3 HighOrderInterpolate( float3 normals[6], float x, float y )
    {
    	float p0 = 2*x*x + 2*y*y + 4*x*y - 3*x - 3*y + 1;
    	float p1 = -4*x*x - 4*x*y + 4*x;
    	float p2 = 2*x*x - x;
    	float p3 = -4*y*y - 4*x*y + 4*y;
    	float p4 = 2*y*y - y;
    	float p5 = 4*x*y;
     
    	return p0*normals[0] + p1*normals[1] + p2*normals[2] + p3*normals[3] + p4*normals[4] + p5*normals[5];
    }
     
    float4 PS_EnvMappedScene( VS_OUTPUT_SCENEENV vin ) : SV_Target
    {
        float3 wN = HighOrderInterpolate( vin.Normals, vin.Bary.x, vin.Bary.y );
        float3 wvN = ( mul( wN, (float3x3)mWorldView ) );
        wN = ( mul( wN, (float3x3)mWorld ) );
     
     
        float3 I = vin.wPos.xyz - vEye;
        float3 wR = I - 2.0f * dot( I, wN ) * wN;
        float4 CubeSample = lightMul*g_txEnvMap.Sample( g_samCube, wR ); 
        float4 Diff = ColorApprox( float3(0,0,-1), wvN );
        float4 Shellac = FresnelApprox( float3(0,0,-1), wvN );
     
         // Compute Specular for the Diffuse and Shellac layers of paint in view space
        float3 L = skyDir;
        float3 wvSHV = normalize(2 * dot(wvN, L) * wvN - L);
        float3 V = -normalize( vin.wvPos );
     
        float4 SpecDiff = pow(max(0, dot(wvSHV, V)), 32)*vHighlight1;   // specular for base paint
        float4 SpecShellac = pow(max(0, dot(wvSHV, V)), 64)*vHighlight2;   // specular for shellac layer
     
        //combine them all
        float4 DiffColor = dot(wN, skyDir)*Diff + 1.25*SpecDiff;
        float4 ShellacColor = Shellac*(CubeSample) + 1.60*SpecShellac;
        return DiffColor + fReflectivity*ShellacColor;
    }
     
     
     
    technique10 RenderEnvMappedScene
    {
        pass p0
        {
            SetVertexShader( CompileShader( vs_4_0, VS_EnvMappedScene() ) );
            SetGeometryShader( CompileShader( gs_4_0, GS_SetupNormalInterp() ) );
            SetPixelShader( CompileShader( ps_4_0, PS_EnvMappedScene() ) );
     
            SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
    };
    merci d'avance de votre aide

  2. #2
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    l'utilisation d'une cubemap se fait en 2 étapes :
    - rendu de la scène dans la cubemap
    - rendu de la scène avec un objet utilisant la cubemap comme "matériau"

    Code code de OnFrameRender simplifié : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
    {
        // Construct the cube map
        RenderSceneIntoCubeMap( pd3dDevice );
     
        RenderScene( pd3dDevice, mView, mProj, false, g_pRenderSceneTech );
    }

    Code code de RenderScene simplifié : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    HRESULT RenderScene( ID3D10Device* pd3dDevice, D3DXMATRIX& mView, D3DXMATRIX& mProj, bool bRenderCubeMap, ID3D10EffectTechnique* pTechnique )
    {
        //
        // Render room
        //
     
        //
        // Render environment-mapped objects
        //
        // Just render a shiny ball
        g_MeshBall.Render( pd3dDevice, g_pRenderEnvMappedSceneNoTexTech, NULL, NULL, NULL, g_pvDiffuse, g_pvSpecular );
    }

    et finalement l'initialisation de pRenderEnvMappedSceneNoTexTech et le contenus de la technique dans le shader :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    g_pRenderEnvMappedSceneNoTexTech = g_pEffect->GetTechniqueByName( "RenderEnvMappedScene_NoTexture" );
     
    technique10 RenderEnvMappedScene_NoTexture
    {
        pass p0
        {
            SetVertexShader( CompileShader( vs_4_0, VS_EnvMappedScene() ) );
            SetGeometryShader( CompileShader( gs_4_0, GS_SetupNormalInterp() ) );
            SetPixelShader( CompileShader( ps_4_0, PS_EnvMappedScene_NoTexture() ) );
     
            SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        }
    };
    donc il faut bien que tu utilises ta cubemap dans le rendu de l'objet où tu veux l'avoir affiché.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut
    donc si j'ai bien compris
    on génère la cube texture au format D3D10_RESOURCE_MISC_TEXTURECUBE
    avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    // Construct the cube map
        RenderSceneIntoCubeMap( pd3dDevice );
    puis pour les objets avec lesquels on veut que l'environnement soit avec la cubemap générée
    il faut utiliser la technique "RenderEnvMappedScene_NoTexture"
    qui utilise la cubemap précédemment générée et doit aussi rendre notre objet ?

    c'est ça ?

    mais si l' objet avec lequel on veut utiliser la cubemap comme environnement utilise un autre shader lors de son rendu?

  4. #4
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    ton shader pour ton objet DOIT prendre en compte la cubemap pour qu'elle soit visible; si le shader que tu veux utiliser ne gère pas la cubemap, il faut faire en sorte qu'il l'utilise.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut
    donc en utilisant cette partie du pixel shader de la technique
    PS_EnvMappedScene_NoTexture
    qui, je crois génère l'échantillonnage de la cubemap sur un cube
    et en générant les vertices du cube pour le mapping
    avec le geometry shader GS_SetupNormalInterp()

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     
        float3 wN = HighOrderInterpolate( vin.Normals, vin.Bary.x, vin.Bary.y );
        wN = mul( wN, (float3x3)mWorld );
     
        float fLight = saturate( dot( skyDir, wN ) ) + 0.2f;
     
        float3 I = vin.wPos.xyz - vEye;
        float3 wR = I - 2.0f * dot( I, wN ) * wN;
        float4 CubeSample = g_txEnvMap.Sample( g_samCube, wR );
    et en rendant ensuite le résultat de "CubeSample" sur un quad,
    je dois pouvoir obtenir l'environnement avec la cubemap en forme de cube indépendamment du rendu des autres objets de ma scène ?


  6. #6
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    regarde chez nvidia, il y a un exemple de cubemap plus basique que celui de microsoft. (et sinon oui il faut aussi récupérer le gs)

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut
    quel exemple chez NVidia ?

    je ne trouve que des exemples OpenGL

  8. #8
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    http://developer.nvidia.com/page/directx.html

    en haut à gauche, NVIDIA Graphics SDK, mais bon j'ai raconté une connerie, l'exemple simple de mes souvenirs, c'est un truc que j'avais modifié.

    sinon pour rattraper ça, le sample HDRCubeMap de dx9, le shader a des commentaires partout, jettes y un oeil.

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut
    après quelques tests vite fait, à part quelques petits problèmes de matrices, ça a l'air de fonctionner, j'ai l'affichage de la cubemap dans un quad qui me restitue ainsi mon environnement

    en résumé
    1. on génère en dynamique les faces de la cubemap avec
    la technique "RenderCubeMap"

    2. on recupère la cube texture créé dans g_pEnvMapSRV ou g_EnvMap,

    3. on affiche sur un quad avec la technique "RenderEnvMappedScene_NoTexture"

    4. puis on dessine les autres objets indépendamment du shader cubemap pour le reste de la scène

    vois tu un problème de logique dans le processus ?

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut
    je fais des tests

  11. #11
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    ton algo semble bon.

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Mars 2006
    Messages : 143
    Points : 112
    Points
    112
    Par défaut
    avec quelques modification ça marche

    1. création cube map avec la technique "RenderCubeMap"

    2. on recupère la cube texture créé dans g_pEnvMapSRV ou g_EnvMap,

    3. on affiche sur un quad avec la technique "RenderEnvMappedScene_NoTexture" modfiée, afin que les vertices du quad restent en local space et en désactivant le culling des faces

    4. puis on dessine les autres objets indépendamment du shader cubemap pour le reste de la scène

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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;
    }
    et dans le shader, on modifie RenderEnvMappedScene_NoTexture ainsi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
        // Output position
        o.Pos = Pos;							// désactive mapping quad vertices en Worldspace, pour affichage 2D
    	//mul( Pos, mWorldViewProj );
    pour que le quad sur lequel est rendu la cubemap reste en 2D
    et on désactive le culling pour voir le quad dans n'importe quelle position

    c'est du vrac, mais le principe fonctionne

    merci beaucoup pour le coup de main

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Appliquer cube mapping a deux fenetre différente en meme temps
    Par LaDeveloppeuse dans le forum OpenGL
    Réponses: 5
    Dernier message: 29/07/2009, 12h01
  2. Cube mapping dynamique
    Par LaDeveloppeuse dans le forum OpenGL
    Réponses: 3
    Dernier message: 28/04/2009, 17h43
  3. Texture avec Cube mapping
    Par LaDeveloppeuse dans le forum OpenGL
    Réponses: 5
    Dernier message: 27/04/2009, 14h47
  4. Réponses: 4
    Dernier message: 27/02/2008, 12h48
  5. Rotation d'un cube map
    Par ShevchenKik dans le forum OpenGL
    Réponses: 1
    Dernier message: 08/02/2008, 16h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo