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