游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2314|回复: 3

How to get the color of one pixel of shadow map

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2008-1-9 13:44:00 | 显示全部楼层 |阅读模式
How to get the color of one pixel of shadow map?
I try to lock the m_pShadowMapSurf by LockRect function, but it return error of -2005530516.

        LPDIRECT3DTEXTURE9                m_pShadowMapTexQuadNode;                        // shadow map objects
        LPDIRECT3DSURFACE9                m_pShadowMapSurf;
        LPDIRECT3DSURFACE9                m_pShadowMapZ;

        HRESULT hr;               

        V_RETURN(pd3dDevice->CreateTexture(
                QUADTREE_SM_SIZE,
                QUADTREE_SM_SIZE,
                1,
                D3DUSAGE_RENDERTARGET,
                SHADOW_MAP_FORMAT,
                D3DPOOL_DEFAULT,
                &m_pShadowMapTexQuadNode,
                NULL
                ));

        V_RETURN(m_pShadowMapTexQuadNode->GetSurfaceLevel(0, &m_pShadowMapSurf));

        V_RETURN(pd3dDevice->CreateDepthStencilSurface(
                QUADTREE_SM_SIZE,
                QUADTREE_SM_SIZE,
                D3DFMT_D24S8,
                D3DMULTISAMPLE_NONE,
                0,
                TRUE,
                &m_pShadowMapZ,
                NULL
                ));


void CALLBACK NodeData::OnFrameRender_Shadowmap(IDirect3DDevice9* pd3dDevice,BOOL bSave)
{
        HRESULT hr;
        LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer;

        D3DXHANDLE hTechnique = g_pEffect->GetTechniqueByName("TShader");
        g_pEffect->SetTechnique(hTechnique);
        V(g_pEffect->Begin(NULL, 0));

        // save old render target and set new render target with depth/stencil buffer
        pd3dDevice->GetRenderTarget(0, &pOldBackBuffer);
        pd3dDevice->GetDepthStencilSurface(&pOldZBuffer);
        pd3dDevice->SetRenderTarget(0, m_pShadowMapSurf);
        pd3dDevice->SetDepthStencilSurface(m_pShadowMapZ);

        // clear render target
        pd3dDevice->Clear(
                0L,
                NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                0xffffffff,
                1.0f,
                0L
                );

        V(g_pEffect->BeginPass(0));
        // render depth values into shadow map
        CreateShadowMap();
        V(g_pEffect->EndPass());

        CalculateShadowPixelNumber();
       
        // restore old backbuffer/stencil/depth-buffer and viewport
        pd3dDevice->SetRenderTarget(0, pOldBackBuffer);
        pd3dDevice->SetDepthStencilSurface(pOldZBuffer);
        pOldBackBuffer->Release();
        pOldZBuffer->Release();

        for (int i=0;i<4;i++)
        {
                if (children)
                        children->data.OnFrameRender_Shadowmap(pd3dDevice,bSave);
        }

}

void NodeData::CalculateShadowPixelNumber()
{
        #define WHITE   D3DCOLOR_XRGB(255, 255, 255)

        D3DLOCKED_RECT lrect;

        D3DDISPLAYMODE display;

        m_nShadowPixelNumber=0;

        HRESULT hr=m_pShadowMapSurf->LockRect(&lrect,NULL,D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_READONLY );
        //-2005530516

        for (int y=0;y<QUADTREE_SM_SIZE;y++)
        {
                for (int x=0;x<QUADTREE_SM_SIZE;x++)
                {
                        DWORD dwColor = ((DWORD*)lrect.pBits)[y*(lrect.Pitch/sizeof(DWORD))+x];//Y*Width+X

                        USHORT r=GetRValue(dwColor);
                        USHORT g=GetGValue(dwColor);
                        USHORT b=GetBValue(dwColor);

                        if (dwColor!=WHITE)
                        {
                                m_nShadowPixelNumber++;
                        }
                        //DXUTOutputDebugString(L"r=%d,g=%d,b=%d\n",r,g,b);
                }
        }

        m_pShadowMapSurf->UnlockRect();


        //DWORD* p=(DWORD*)(lrect.pBits);
        //p[y*(lrect.Pitch/sizeof(DWORD))+x]=RGB(255,0,0);

}

35

主题

1735

帖子

1739

积分

金牌会员

Rank: 6Rank: 6

积分
1739
QQ
发表于 2008-1-9 21:13:00 | 显示全部楼层

Re:How to get the color of one pixel of shadow map

哦,急会可不他又瓦额哀衫卡。

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
 楼主| 发表于 2008-1-10 00:06:00 | 显示全部楼层

Re:How to get the color of one pixel of shadow map

?大家到????站看一下
http://www.gamedev.net/community/forums/topic.asp?topic_id=478715
有人?臀一卮疳?我又有新的???了

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
 楼主| 发表于 2008-1-10 00:07:00 | 显示全部楼层

Re: Re:How to get the color of one pixel of shadow map

ricohcanon: Re:How to get the color of one pixel of shadow map

哦,急会可不他又瓦额哀衫卡。

?是什?意思我不懂,sorry!.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-23 22:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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