游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1843|回复: 2

为什么ShadowMap要是设置深度模板表面???

[复制链接]

22

主题

87

帖子

87

积分

注册会员

Rank: 2

积分
87
发表于 2010-5-18 22:29:00 | 显示全部楼层 |阅读模式
DirectX的例子, 下面这段:
    LPDIRECT3DSURFACE9 pOldDS = NULL;
    if( SUCCEEDED( pd3dDevice->GetDepthStencilSurface( &pOldDS ) ) )
        pd3dDevice->SetDepthStencilSurface( g_pDSShadow );

    {
        CDXUTPerfEventGenerator g( DXUT_PERFEVENTCOLOR, L"Shadow Map" );
        RenderScene( pd3dDevice, true, fElapsedTime, &mLightView, &g_mShadowProj );
    }

    if( pOldDS )
    {
        pd3dDevice->SetDepthStencilSurface( pOldDS );
        pOldDS->Release();
    }
如果不设置DepthStencilSurface就会发生未知错误, 但不知道这错误到底是怎么导致的?
哪位大大能稍微提点一下...

1

主题

24

帖子

31

积分

注册会员

Rank: 2

积分
31
发表于 2010-5-18 23:44:00 | 显示全部楼层

Re:为什么ShadowMap要是设置深度模板表面???

由于g_pDSShaodw是用于渲染深度图的深度缓冲,它与深度图的大小相同,而建立的窗口大小与深度图不同,因此在渲染深度图时,需要设置对应的深度缓冲区.
如果在建立窗口时将窗口设置的与深度图大小一样,都为512*512的话,就不会出错了.
这个在建立g_pDSShadow时有解释:
    // Create the depth-stencil buffer to be used with the shadow map
    // We do this to ensure that the depth-stencil buffer is large
    // enough and has correct multisample type/quality when rendering
    // the shadow map.  The default depth-stencil buffer created during
    // device creation will not be large enough if the user resizes the
    // window to a very small size.  Furthermore, if the device is created
    // with multisampling, the default depth-stencil buffer will not
    // work with the shadow map texture because texture render targets
    // do not support multisample.
    DXUTDeviceSettings d3dSettings = DXUTGetDeviceSettings();
    V_RETURN( pd3dDevice->CreateDepthStencilSurface( ShadowMap_SIZE,
                                                     ShadowMap_SIZE,
                                                     d3dSettings.d3d9.pp.AutoDepthStencilFormat,
                                                     D3DMULTISAMPLE_NONE,
                                                     0,
                                                     TRUE,
                                                     &g_pDSShadow,
                                                     NULL ) );


22

主题

87

帖子

87

积分

注册会员

Rank: 2

积分
87
 楼主| 发表于 2010-5-20 21:58:00 | 显示全部楼层

Re:为什么ShadowMap要是设置深度模板表面???

那窗口和全屏模式之间的切换是不是也是这样实现的?????
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-9 14:48

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表