[C/C++] [DirectX] Schatten Problem

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von Pac_-_man, 3. Juli 2007 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 3. Juli 2007
    [DirectX] Schatten Problem

    Hi!

    Also ich habe folgendes Problem. Und zwar wird, immer wenn ich in meiner 3D-Welt die Kamera-Perspektive wechsle, der Schatten auf dem Terrain total komisch... vlt kennt jemand das problem. Es ist aber immer erst so, wenn ich die Kamera-Perspektive wechsle (z.B. von First-Person in die Vogel-Perspektive). Ich hab mal nen Screenshot davon gemacht:

    //EDIT: neue Screenshots:

    vorher (neuer screenshot):
    Download offline!

    nachher (neuer screenshot):
    Download offline!

    Falls jemand das Problem kennt, kann er/sie mir ja vlt helfen...

    MFG
    Pacman
     
  2. 3. Juli 2007
    AW: [DirectX] Schatten Problem

    Hi,
    könntest du vllt ein Screen von der ganzen Scene machen? Weil auf den kleinen Dingern erkenn ich nix^^

    mfg r90
     
  3. 3. Juli 2007
    AW: [DirectX] Schatten Problem

    sieht nach falschem drehsinn bei der texturierung aus

    könnt aber auch fehlender filter sein
     
  4. 3. Juli 2007
    AW: [DirectX] Schatten Problem

    für mich als laie siehts mehr so aus, als würde man vergleichweise wie beim desktop-hintergrund von 'gestreckt' auf 'nebeneinander' schalten, also wenns sowas gibt...mfg coach
     
  5. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    Das könnte eher sein. Hab von den Filtern nämlich nich so viel ahnung... kenn nur wenige... gibts dafür denn nen bestimmten filter?

    neue screenshots sind drin...

    //Edit: Hab außerdem das Gefühl, das es immer dann auftritt, wenn die Kamera zu weit vom Terrain entfernt ist. Denn immer wenn ich in die Vogelperspektive wechsle, dann tritt dieser Fehler auf, dass die Schattierungen halt so komisch geriffelt gerendert werden...
     
  6. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    ja, das sollte der filter sein
    .SetTextureStageState filter - Google-Suche
     
  7. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    Ja, ok, aber welches Flag muss ich denn setzen? Mit SetTextureStage() setzt man ja alle möglichen Sachen... müsste jetzt noch wissen welches Flag für das Schatten-Rendern ist...
     
  8. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    im normalfall ist das dir überlassen. mir reicht lineare filterung
     
  9. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    Ich gib dir mal nen alten source von meinen ersten schatten versuchen...vielleicht helfen die dir weiter.
    Die heads muss ich noch suchen...die hab ich irgendwo verbuddelt...

    Code:
    #define STRICT
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <mmsystem.h>
    #include <d3d9.h>
    #include <d3dx9.h>
    #include "resource.h"
    #include "shadow_volume.h"
    
    //Die Globals...
    
    HWND g_hWnd = NULL;
    LPDIRECT3D9 g_pD3D = NULL;
    LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
    
    D3DLIGHT9 g_light0;
    
    LPDIRECT3DVERTEXBUFFER9 g_pFloorVB = NULL;
    LPDIRECT3DTEXTURE9 g_pFloorTex = NULL;
    D3DMATERIAL9 g_pFloorMtrl;
    
    LPD3DXMESH g_pTeapotMesh = NULL;
    D3DMATERIAL9 *g_pTeapotMtrls = NULL;
    LPDIRECT3DTEXTURE9 *g_pTeapotTextures = NULL;
    unsigned long g_dwTeapotNumMtrls = 0L;
    
    D3DXMATRIXA16 m_matTeapot;
    LPDIRECT3DVERTEXBUFFER9 m_pBigSquareVB;
    ShadowVolume *m_pShadowVolume;
    
    bool g_bMakeShadowVolumeVisible = false;
    bool g_bTwoSidedStencilsAvailable = false;
    
    POINT g_ptLastMousePosit_L;
    POINT g_ptCurrentMousePosit_L;
    bool g_bMousing_L = false;
    POINT g_ptLastMousePosit_R;
    POINT g_ptCurrentMousePosit_R;
    bool g_bMousing_R = false;
    float g_fMoveSpeed = 25.0f;
    float g_fElpasedTime;
    double g_dCurTime;
    double g_dLastTime;
    
    D3DXVECTOR3 g_vEye(0.0f, 0.0f, -10.0f); 
    D3DXVECTOR3 g_vLook(0.0f, 0.0f, 1.0f); 
    D3DXVECTOR3 g_vUp(0.0f, 1.0f, 0.0f); 
    D3DXVECTOR3 g_vRight(1.0f, 0.0f, 0.0f); 
    
    float g_fSpinX = 0.0f;
    float g_fSpinY = 0.0f;
    
    struct FloorVertex
    {
     float x, y, z;
     float nx, ny, nz;
     float tu, tv;
    
     enum FVF
     {
     FVF_Flags = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1
     };
    };
    
    FloorVertex g_quadVertices[] =
    {
     {-1.0f, 0.0f,-1.0f, 0.0f,1.0f,0.0f, 0.0f, 1.0f },
     {-1.0f, 0.0f, 1.0f, 0.0f,1.0f,0.0f, 0.0f, 0.0f },
     { 1.0f, 0.0f,-1.0f, 0.0f,1.0f,0.0f, 1.0f, 1.0f },
     { 1.0f, 0.0f, 1.0f, 0.0f,1.0f,0.0f, 1.0f, 0.0f }
    };
    
    //Die protoypen...
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
     LPSTR lpCmdLine, int nCmdShow);
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
    void init(void);
    void initGeometryAndLighting(void);
    void shutDown(void);
    void render(void);
    void getRealTimeUserInput(void);
    void updateViewMatrix(void);
    void renderShadowToStencilBuffer(void);
    void renderShadowToScene(void);
    
    
    // WinMain..der entrypoint begintn dann hier...
    
    
    int WINAPI WinMain( HINSTANCE hInstance,
     HINSTANCE hPrevInstance,
     LPSTR lpCmdLine,
     int nCmdShow )
    {
     WNDCLASSEX winClass; 
     MSG uMsg;
    
     memset(&uMsg,0,sizeof(uMsg));
    
     winClass.lpszClassName = "MY_WINDOWS_CLASS";
     winClass.cbSize = sizeof(WNDCLASSEX);
     winClass.style = CS_HREDRAW | CS_VREDRAW;
     winClass.lpfnWndProc = WindowProc;
     winClass.hInstance = hInstance;
     winClass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON);
     winClass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON);
     winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
     winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
     winClass.lpszMenuName = NULL;
     winClass.cbClsExtra = 0;
     winClass.cbWndExtra = 0;
    
     if( !RegisterClassEx(&winClass) )
     return E_FAIL;
    
     g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", 
     "Direct3D (DX9) - Shadow Volume",
     WS_OVERLAPPEDWINDOW | WS_VISIBLE,
     0, 0, 640, 480, NULL, NULL, hInstance, NULL );
    
     if( g_hWnd == NULL )
     return E_FAIL;
    
     ShowWindow( g_hWnd, nCmdShow );
     UpdateWindow( g_hWnd );
    
     init();
    
     while( uMsg.message != WM_QUIT )
     {
     if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
     {
     TranslateMessage( &uMsg );
     DispatchMessage( &uMsg );
     }
     else
     {
     g_dCurTime = timeGetTime();
     g_fElpasedTime = (float)((g_dCurTime - g_dLastTime) * 0.001);
     g_dLastTime = g_dCurTime;
    
     render();
     }
     }
    
     shutDown();
    
     UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance );
    
     return uMsg.wParam;
    }
    
    
    // WindowProc...windoofs message handler...
    
    
    LRESULT CALLBACK WindowProc( HWND hWnd, 
     UINT msg, 
     WPARAM wParam, 
     LPARAM lParam )
    {
     static POINT ptLastMousePosit_R;
     static POINT ptCurrentMousePosit_R;
     static bool bMousing_R;
    
     switch( msg )
     {
     case WM_KEYDOWN:
     {
     switch( wParam )
     {
     case VK_ESCAPE:
     PostQuitMessage(0);
     break;
    
     case VK_F1:
     g_bMakeShadowVolumeVisible = !g_bMakeShadowVolumeVisible;
     break;
     }
     }
     break;
    
     case WM_LBUTTONDOWN:
     {
     g_bMousing_L = true;
     }
     break;
    
     case WM_LBUTTONUP:
     {
     g_bMousing_L = false;
     }
     break;
    
     case WM_RBUTTONDOWN:
     {
     g_bMousing_R = true;
     }
     break;
    
     case WM_RBUTTONUP:
     {
     g_bMousing_R = false;
     }
     break;
    
     case WM_CLOSE:
     {
     PostQuitMessage(0); 
     }
     
     case WM_DESTROY:
     {
     PostQuitMessage(0);
     }
     break;
    
     default:
     {
     return DefWindowProc( hWnd, msg, wParam, lParam );
     }
     break;
     }
    
     return 0;
    }
    
    
    // Echtzeit eingaben
    
    void getRealTimeUserInput( void )
    {
    
    
     POINT mousePosit;
     GetCursorPos( &mousePosit );
     ScreenToClient( g_hWnd, &mousePosit );
    
     g_ptCurrentMousePosit_L.x = mousePosit.x;
     g_ptCurrentMousePosit_L.y = mousePosit.y;
    
     g_ptCurrentMousePosit_R.x = mousePosit.x;
     g_ptCurrentMousePosit_R.y = mousePosit.y;
    
     D3DXMATRIX matRotation;
    
     if( g_bMousing_L )
     {
     int nXDiff = (g_ptCurrentMousePosit_L.x - g_ptLastMousePosit_L.x);
     int nYDiff = (g_ptCurrentMousePosit_L.y - g_ptLastMousePosit_L.y);
     
     if( nYDiff != 0 )
     {
     D3DXMatrixRotationAxis( &matRotation, &g_vRight, D3DXToRadian((float)nYDiff / 3.0f));
     D3DXVec3TransformCoord( &g_vLook, &g_vLook, &matRotation );
     D3DXVec3TransformCoord( &g_vUp, &g_vUp, &matRotation );
     }
    
     if( nXDiff != 0 )
     {
     D3DXMatrixRotationAxis( &matRotation, &D3DXVECTOR3(0,1,0), D3DXToRadian((float)nXDiff / 3.0f) );
     D3DXVec3TransformCoord( &g_vLook, &g_vLook, &matRotation );
     D3DXVec3TransformCoord( &g_vUp, &g_vUp, &matRotation );
     }
     }
    
     if( g_bMousing_R )
     {
     g_fSpinX -= (g_ptCurrentMousePosit_R.x - g_ptLastMousePosit_R.x);
     g_fSpinY -= (g_ptCurrentMousePosit_R.y - g_ptLastMousePosit_R.y);
     }
    
     g_ptLastMousePosit_L.x = g_ptCurrentMousePosit_L.x;
     g_ptLastMousePosit_L.y = g_ptCurrentMousePosit_L.y;
    
     g_ptLastMousePosit_R.x = g_ptCurrentMousePosit_R.x;
     g_ptLastMousePosit_R.y = g_ptCurrentMousePosit_R.y;
    
    
     unsigned char keys[256];
     GetKeyboardState( keys );
    
     D3DXVECTOR3 tmpLook = g_vLook;
     D3DXVECTOR3 tmpRight = g_vRight;
    
     if( keys[VK_UP] & 0x80 )
     g_vEye -= tmpLook*-g_fMoveSpeed*g_fElpasedTime;
    
     if( keys[VK_DOWN] & 0x80 )
     g_vEye += (tmpLook*-g_fMoveSpeed)*g_fElpasedTime;
    
     if( keys[VK_LEFT] & 0x80 )
     g_vEye -= (tmpRight*g_fMoveSpeed)*g_fElpasedTime;
    
     if( keys[VK_RIGHT] & 0x80 )
     g_vEye += (tmpRight*g_fMoveSpeed)*g_fElpasedTime;
    
     if( keys[VK_HOME] & 0x80 )
     g_vEye.y += g_fMoveSpeed*g_fElpasedTime; 
    
     if( keys[VK_END] & 0x80 )
     g_vEye.y -= g_fMoveSpeed*g_fElpasedTime;
    }
    
    void updateViewMatrix( void )
    {
     D3DXMATRIX view;
     D3DXMatrixIdentity( &view );
    
     D3DXVec3Normalize( &g_vLook, &g_vLook );
     D3DXVec3Cross( &g_vRight, &g_vUp, &g_vLook );
     D3DXVec3Normalize( &g_vRight, &g_vRight );
     D3DXVec3Cross( &g_vUp, &g_vLook, &g_vRight );
     D3DXVec3Normalize( &g_vUp, &g_vUp );
    
     view._11 = g_vRight.x;
     view._12 = g_vUp.x;
     view._13 = g_vLook.x;
     view._14 = 0.0f;
    
     view._21 = g_vRight.y;
     view._22 = g_vUp.y;
     view._23 = g_vLook.y;
     view._24 = 0.0f;
    
     view._31 = g_vRight.z;
     view._32 = g_vUp.z;
     view._33 = g_vLook.z;
     view._34 = 0.0f;
    
     view._41 = -D3DXVec3Dot( &g_vEye, &g_vRight );
     view._42 = -D3DXVec3Dot( &g_vEye, &g_vUp );
     view._43 = -D3DXVec3Dot( &g_vEye, &g_vLook );
     view._44 = 1.0f;
    
     g_pd3dDevice->SetTransform( D3DTS_VIEW, &view ); 
    }
    
    void init( void )
    {
     g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    
    
     D3DCAPS9 d3dCaps;
     g_pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps );
     if( ( d3dCaps.StencilCaps & D3DSTENCILCAPS_TWOSIDED ) != 0 )
     g_bTwoSidedStencilsAvailable = true;
    
     D3DDISPLAYMODE d3ddm;
     g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
    
     D3DPRESENT_PARAMETERS d3dpp;
     ZeroMemory( &d3dpp, sizeof(d3dpp) );
    
     d3dpp.Windowed = TRUE;
     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
     d3dpp.BackBufferFormat = d3ddm.Format;
     d3dpp.EnableAutoDepthStencil = TRUE;
     d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
     d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
     d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    
     g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
     &d3dpp, &g_pd3dDevice );
    
     g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
     g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
    
     D3DXMATRIX matProj;
     D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 
     640.0f / 480.0f, 0.1f, 500.0f );
     g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
    
     initGeometryAndLighting();
    }
    
    void initGeometryAndLighting( void )
    {
     
     LPD3DXBUFFER pD3DXMtrlBuffer;
    
     D3DXLoadMeshFromX( "teapot.x", D3DXMESH_SYSTEMMEM, g_pd3dDevice, NULL, 
     &pD3DXMtrlBuffer, NULL, &g_dwTeapotNumMtrls, &g_pTeapotMesh );
    
     D3DXMATERIAL *d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
     g_pTeapotMtrls = new D3DMATERIAL9[g_dwTeapotNumMtrls];
     g_pTeapotTextures = new LPDIRECT3DTEXTURE9[g_dwTeapotNumMtrls];
    
     for( unsigned long i = 0; i < g_dwTeapotNumMtrls; ++i )
     {
     g_pTeapotMtrls[i] = d3dxMaterials[i].MatD3D;
    
     g_pTeapotMtrls[i].Ambient = g_pTeapotMtrls[i].Diffuse;
     
     g_pTeapotTextures[i] = NULL;
     D3DXCreateTextureFromFile( g_pd3dDevice, d3dxMaterials[i].pTextureFilename, 
     &g_pTeapotTextures[i] );
     }
    
     pD3DXMtrlBuffer->Release();
    
     g_pd3dDevice->CreateVertexBuffer( 4*sizeof(FloorVertex),0, FloorVertex::FVF_Flags,
     D3DPOOL_DEFAULT, &g_pFloorVB, NULL );
     void *pVertices = NULL;
    
     g_pFloorVB->Lock( 0, sizeof(g_quadVertices), (void**)&pVertices, 0 );
     memcpy( pVertices, g_quadVertices, sizeof(g_quadVertices) );
     g_pFloorVB->Unlock();
    
     D3DXCreateTextureFromFile( g_pd3dDevice, "floor_tile.bmp", &g_pFloorTex );
    
     ZeroMemory( &g_pFloorMtrl, sizeof(D3DMATERIAL9) );
     g_pFloorMtrl.Diffuse.r = 1.0f;
     g_pFloorMtrl.Diffuse.g = 1.0f;
     g_pFloorMtrl.Diffuse.b = 1.0f;
     g_pFloorMtrl.Diffuse.a = 1.0f;
     g_pFloorMtrl.Ambient.r = 1.0f;
     g_pFloorMtrl.Ambient.g = 1.0f;
     g_pFloorMtrl.Ambient.b = 1.0f;
     g_pFloorMtrl.Ambient.a = 1.0f;
    
     ZeroMemory( &g_light0, sizeof(D3DLIGHT9) );
     g_light0.Type = D3DLIGHT_POINT;
     g_light0.Position = D3DXVECTOR3( 2.0f, 2.0f, 0.0f );
     g_light0.Diffuse.r = 1.0f;
     g_light0.Diffuse.g = 1.0f;
     g_light0.Diffuse.b = 1.0f;
     g_light0.Range = 100.0f;
     g_light0.Attenuation0 = 1.0f;
     g_light0.Attenuation1 = 0.0f;
    
     g_pd3dDevice->SetLight( 0, &g_light0 );
     g_pd3dDevice->LightEnable( 0, TRUE );
    
     g_pd3dDevice->CreateVertexBuffer( 4*sizeof(ShadowVertex),
     D3DUSAGE_WRITEONLY, ShadowVertex::FVF_Flags,
     D3DPOOL_MANAGED, &m_pBigSquareVB, NULL );
    
     LPDIRECT3DSURFACE9 pBackBuffer = NULL;
     D3DSURFACE_DESC d3dsd;
     g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
     pBackBuffer->GetDesc( &d3dsd );
     pBackBuffer->Release();
     float sx = (float)d3dsd.Width;
     float sy = (float)d3dsd.Height;
    
     ShadowVertex *v;
    
     m_pBigSquareVB->Lock( 0, 0, (void**)&v, 0 );
     {
     v[0].p = D3DXVECTOR4( 0, sy, 0.0f, 1.0f );
     v[1].p = D3DXVECTOR4( 0, 0, 0.0f, 1.0f );
     v[2].p = D3DXVECTOR4( sx, sy, 0.0f, 1.0f );
     v[3].p = D3DXVECTOR4( sx, 0, 0.0f, 1.0f );
     v[0].color = 0x7f000000;
     v[1].color = 0x7f000000;
     v[2].color = 0x7f000000;
     v[3].color = 0x7f000000;
     }
     m_pBigSquareVB->Unlock();
    
     m_pShadowVolume = new ShadowVolume();
    }
    
    void shutDown( void )
    {
     if( g_pTeapotMtrls != NULL )
     delete[] g_pTeapotMtrls;
    
     if( g_pTeapotTextures != NULL )
     {
     for( unsigned long i = 0; i < g_dwTeapotNumMtrls; ++i )
     {
     if( g_pTeapotTextures[i] != NULL )
     g_pTeapotTextures[i]->Release();
     }
     
     delete[] g_pTeapotTextures;
     }
    
     if( g_pFloorVB != NULL )
     g_pFloorVB->Release(); 
    
     if( g_pTeapotMesh != NULL )
     g_pTeapotMesh->Release();
     
     if( g_pd3dDevice != NULL )
     g_pd3dDevice->Release();
    
     if( g_pD3D != NULL )
     g_pD3D->Release();
    }
    
    void renderShadowToStencilBuffer( void )
    {
     g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
    
     g_pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );
    
     g_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );
    
     g_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_INCR );
    
     g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
     g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
    
     if( g_bTwoSidedStencilsAvailable == true )
     {
     g_pd3dDevice->SetRenderState( D3DRS_TWOSIDEDSTENCILMODE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_CCW_STENCILFUNC, D3DCMP_ALWAYS );
     g_pd3dDevice->SetRenderState( D3DRS_CCW_STENCILZFAIL, D3DSTENCILOP_KEEP );
     g_pd3dDevice->SetRenderState( D3DRS_CCW_STENCILFAIL, D3DSTENCILOP_KEEP );
     g_pd3dDevice->SetRenderState( D3DRS_CCW_STENCILPASS, D3DSTENCILOP_DECR );
    
     g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
     g_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matTeapot );
     m_pShadowVolume->render( g_pd3dDevice );
    
     g_pd3dDevice->SetRenderState( D3DRS_TWOSIDEDSTENCILMODE, FALSE );
     }
     else
     {
     g_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matTeapot );
     m_pShadowVolume->render( g_pd3dDevice );
    
     g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
    
     g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_DECR );
    
     g_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matTeapot );
     m_pShadowVolume->render( g_pd3dDevice );
     }
    
     g_pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
     g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
     g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, FALSE );
     g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    }
    
    void renderShadowToScene( void )
    {
     g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
     g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
    
     g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
     g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
     g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
     g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
     g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
     g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
    
     g_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
    
     g_pd3dDevice->SetFVF( ShadowVertex::FVF_Flags );
     g_pd3dDevice->SetStreamSource( 0, m_pBigSquareVB, 0, sizeof(ShadowVertex) );
     g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
    
     g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
     g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, FALSE );
     g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    }
    
    void render( void )
    {
    
     D3DXMatrixIdentity( &m_matTeapot );
     D3DXMatrixRotationYawPitchRoll( &m_matTeapot,
     D3DXToRadian(g_fSpinX),
     D3DXToRadian(g_fSpinY),
     0.0f );
    
     D3DXVECTOR3 vLightInWorldSpace( g_light0.Position.x, g_light0.Position.y, g_light0.Position.z );
     D3DXVECTOR3 vLightInObjectSpace;
     D3DXMATRIXA16 matInverse;
     D3DXMatrixInverse( &matInverse, NULL, &m_matTeapot );
     D3DXVec3TransformNormal( &vLightInObjectSpace, &vLightInWorldSpace, &matInverse );
    
     m_pShadowVolume->reset();
     m_pShadowVolume->buildShadowVolume( g_pTeapotMesh, vLightInObjectSpace );
    
     g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,
     D3DCOLOR_COLORVALUE(0.35f, 0.53f, 0.7, 1.0f), 1.0f, 0 );
    
     getRealTimeUserInput();
     updateViewMatrix();
    
     g_pd3dDevice->BeginScene();
    
     g_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matTeapot );
    
     for( unsigned long n = 0; n < g_dwTeapotNumMtrls; ++n )
     {
     g_pd3dDevice->SetMaterial( &g_pTeapotMtrls[n] );
     g_pd3dDevice->SetTexture( 0, g_pTeapotTextures[n] );
     g_pTeapotMesh->DrawSubset( n );
     }
    
     g_pd3dDevice->SetTexture( 0, g_pFloorTex );
     g_pd3dDevice->SetMaterial( &g_pFloorMtrl );
     g_pd3dDevice->SetStreamSource( 0, g_pFloorVB, 0, sizeof(FloorVertex) );
     g_pd3dDevice->SetFVF( FloorVertex::FVF_Flags );
    
     D3DXMATRIX matFloor;
     float x = 0.0f;
     float z = 0.0f;
    
     for( int i = 0; i < 25; ++i )
     {
     for( int j = 0; j < 25; ++j )
     {
     D3DXMatrixTranslation( &matFloor, x - 25.0f, -3.0f, z - 25.0f );
     g_pd3dDevice->SetTransform( D3DTS_WORLD, &matFloor );
     g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2);
    
     x += 2.0f;
     }
     x = 0.0f;
     z += 2.0f;
     }
    
    
     if( g_bMakeShadowVolumeVisible == true )
     {
     g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
     g_pd3dDevice->SetTransform( D3DTS_WORLD, &m_matTeapot );
     m_pShadowVolume->render( g_pd3dDevice );
     g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
     }
    
     renderShadowToStencilBuffer();
     renderShadowToScene();
    
     g_pd3dDevice->EndScene();
     g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
    }
    
    ist zwar nicht direkt für terrian...aber soltle dir trotzdem helfen.

    MfG
    .iNC
     
  10. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    aber diesen Filter verwende ich schon... immer wenn ich mich zu weit von dem Terrain entferne tritt das problem auf...

    @breaKdown.iNC: thx für den code... schau ich mir mal an...
     
  11. 4. Juli 2007
    AW: [DirectX] Schatten Problem

    dann probier doch mal anistrophsche filterung

    eigentlich isses ja nichts anderes als nen moire effekt, welcher auch durch anti alising verbessert werden kann.
     
  12. 5. Juli 2007
    AW: [DirectX] Schatten Problem

    Aaalsoo, hab den Fehler gefunden... Es waren nicht mal RenderStates. Scheinbar mag DirectX es nicht, wenn man auf F1 drückt. Darauf hate ich die "Vogelperspektive" gelegt. Und dieser moire effekt trat immer genau dann auf. Also ich hab echt kp woran as liegt, jedenfalls hab ih das jetzt umgelegt und nun ist dieser Fehler weg. Er kommt aber immer wieder wenn man auf F1 drückt... Hammer komisch, naja, ich close dann mal an der Stelle.

    Totzdem vielen, vielen Dank für eure Hilfe!! Bin froh das ich das Board hier hab...

    MFG
    Pacman
     
  13. 5. Juli 2007
    AW: [DirectX] Schatten Problem

    das hat was mit dem device zu tun. kannst ja mal strg+alt+entf machen und dann schaun was deine anwendung macht

    das dann auftretende "problem" nennt sich dann devicelost. das mit f1 hat bestimmt auch nen namen, glaube aber, dass das durch dein system bedingt ist.

    ps:
    du hast vergessen zu closen
     
  14. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.