désolé, c'est encore moi

après ces deux problèmes vous n'entendrez plus parler de moi promis lol

bon, je suis entrain d'implémenter les reflet grace au stencil buffer dans mon moteur. Pour ça je me suis aidé de l'exemple du sdk... mais une fois de plus et après de longues crises de nerf je n'obtient pas l'effet désiré.

Pour l'instant les objets que je souhaite refleter apparaisse "en entier"
( sans que le mask du stencil buffer n'ai d'influence )

Y a t-il une initialisation particulière à faire ? En fait je ne comprend pas très bien cette technique, impossible donc de trouver l'erreur...

initialisation de l'app :

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
 
HRESULT InitD3D( HWND hWnd )
{
    // Create the D3D object.
    if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
        return E_FAIL;
 
    // Get the current desktop display mode, so we can set up a back
    // buffer of the same format
    D3DDISPLAYMODE d3ddm;
    if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
        return E_FAIL;
 
    // Set up the structure used to create the D3DDevice. Since we are now
    // using more complex geometry, we will create a device with a zbuffer.
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory( &d3dpp, sizeof(d3dpp) ); 
    d3dpp.Windowed = TRUE; 
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; 
    d3dpp.BackBufferFormat = d3ddm.Format; 
    d3dpp.EnableAutoDepthStencil = TRUE; 
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16; 
    d3dpp.BackBufferHeight = 768; 
    d3dpp.BackBufferWidth = 1024; 
    //d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; 
 
    // Create the D3DDevice
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) )
			return E_FAIL;
 
}

initialisation du v-buffer du "miroir"

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
 
 
 
HRESULT InitMirror()
{
 
	m_pMirrorVB         = NULL;
 
	D3DXMatrixIdentity( &m_matMirrorMatrix );
 
	// Create a big square for rendering the mirror
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(MIRRORVERTEX),
                                       D3DUSAGE_WRITEONLY, D3DFVF_MIRRORVERTEX,
                                       D3DPOOL_MANAGED, &m_pMirrorVB ) ) )
        return E_FAIL;
 
    MIRRORVERTEX* v;
    m_pMirrorVB->Lock( 0, 0, (BYTE**)&v, 0 );
    v[0].p = D3DXVECTOR3(-00.0f, 0.0f,-0.0f );
    v[0].n = D3DXVECTOR3( 0.0f,  1.0f,  0.0f );
    v[1].p = D3DXVECTOR3(-00.0f, 0.0f, 0.0f );
    v[1].n = D3DXVECTOR3( 0.0f,  1.0f,  0.0f );
    v[2].p = D3DXVECTOR3( 00.0f, 0.0f,-0.0f );
    v[2].n = D3DXVECTOR3( 0.0f,  1.0f,  0.0f );
    v[3].p = D3DXVECTOR3( 00.0f, 0.0f, 0.0f );
    v[3].n = D3DXVECTOR3( 0.0f,  1.0f,  0.0f );
    m_pMirrorVB->Unlock();
 
 
	return S_OK;
 
}

puis dans le render :

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
 
 
void RenderMirror()
{
    // Turn depth buffer off, and stencil buffer on
    g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC,     D3DCMP_ALWAYS );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILREF,      0x1 );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILMASK,     0xffffffff );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILWRITEMASK,0xffffffff );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILFAIL,  D3DSTENCILOP_KEEP );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS,  D3DSTENCILOP_REPLACE );
 
    // Make sure no pixels are written to the z-buffer or frame buffer
    g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE,  FALSE );
    g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
    g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_ZERO );
    g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
 
    // Draw the reflecting surface into the stencil buffer
    g_pd3dDevice->SetTexture( 0, NULL);
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matMirrorMatrix );
    g_pd3dDevice->SetVertexShader( D3DFVF_MIRRORVERTEX );
    g_pd3dDevice->SetStreamSource( 0, m_pMirrorVB, sizeof(MIRRORVERTEX) );
    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
 
    // Save the view matrix
    D3DXMATRIX matViewSaved;
    g_pd3dDevice->GetTransform( D3DTS_VIEW, &matViewSaved );
 
    // Reflect camera in X-Z plane mirror
    D3DXMATRIX matView2, matReflect;
    D3DXPLANE plane;
    D3DXPlaneFromPointNormal( &plane, &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,1,0) );
    D3DXMatrixReflect( &matReflect, &plane );
    D3DXMatrixMultiply( &matView2, &matReflect, &matViewSaved );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView2 );
 
    // Set a clip plane, so that only objects above the water are reflected
    g_pd3dDevice->SetClipPlane( 0, plane );
    g_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, 0x01 );
 
    // Setup render states to a blended render scene against mask in stencil
    // buffer. An important step here is to reverse the cull-order of the
    // polygons, since the view matrix is being relected.
    g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC,  D3DCMP_EQUAL );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS,  D3DSTENCILOP_KEEP );
    g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND,     D3DBLEND_DESTCOLOR );
    g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND,    D3DBLEND_ZERO );
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE,     D3DCULL_CW );
 
    // Clear the zbuffer (leave frame- and stencil-buffer intact)
    g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_ZBUFFER, 0L, 1.0f, 0L );
 
	g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
 
	if (arbres_mesh[3].visible) Afficher_Mesh( arbres_mesh[3] );
 
 
    // Restore render states
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE,         D3DCULL_CCW );
    g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE,    FALSE );
    g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    g_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE,  0x00 );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matViewSaved );
 
 
}
c'est ce bout de code ( le plus important ) que je ne saisis pas très bien... notament "Draw the reflecting surface into the stencil buffer"... chez moi si je vire ce bout de code rien ne change... je dois encore oublier d'initialiser quelque chose, snif...........

help me !!!!!!!!!!!!! please !!!!!!!!!!!!!!