游戏开发论坛

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

关于 mirror的wenti

[复制链接]

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2004-12-2 14:26:00 | 显示全部楼层 |阅读模式
请问各位高人,我在做stencilmirror时,为何前端的teapot没有遮挡住在墙壁中反射的倒影!让我很困惑!请指教
sf_2004122142641.jpg

0

主题

10

帖子

10

积分

新手上路

Rank: 1

积分
10
发表于 2004-12-2 16:41:00 | 显示全部楼层

Re:关于 mirror的wenti

先画镜子里的壶再画外面的?

1

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2004-12-4 12:43:00 | 显示全部楼层

Re:关于 mirror的wenti

        Device->Clear(0, 0, D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L);
    Device->SetRenderState(D3DRS_STENCILENABLE,    true);
    Device->SetRenderState(D3DRS_STENCILFUNC,      D3DCMP_ALWAYS);
    Device->SetRenderState(D3DRS_STENCILREF,       0x1);
    Device->SetRenderState(D3DRS_STENCILMASK,      0xffffffff);
    Device->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
    Device->SetRenderState(D3DRS_STENCILZFAIL,     D3DSTENCILOP_KEEP);
    Device->SetRenderState(D3DRS_STENCILFAIL,      D3DSTENCILOP_KEEP);
    Device->SetRenderState(D3DRS_STENCILPASS,      D3DSTENCILOP_REPLACE);

        // disable writes to the depth and back buffers
    Device->SetRenderState(D3DRS_ZWRITEENABLE, false);
    Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
    Device->SetRenderState(D3DRS_SRCBLEND,  D3DBLEND_ZERO);
    Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

    // draw the mirror to the stencil buffer
        Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
        Device->SetFVF(Vertex::FVF);
        /*
        Device->SetMaterial(&MirrorMtrl);
        Device->SetTexture(0, MirrorTex);
        */
        Device->SetMaterial(&WallMtrl);
        Device->SetTexture(0, WallTex);
        D3DXMATRIX I;
        D3DXMatrixIdentity(&I);
        Device->SetTransform(D3DTS_WORLD, &I);
        Device->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 4);

        // re-enable depth writes
        Device->SetRenderState( D3DRS_ZWRITEENABLE, true );

        // only draw reflected teapot to the pixels where the mirror
        // was drawn to.
问题在这里,如果用下面的渲染方式这没有这种问题
        Device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
        Device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
而用下面三句,则会造成上面图中所表示的样子,请问高手这其中的原因在哪
//        Device->SetRenderState(D3DRS_STENCILFUNC,  D3DCMP_GREATER);
//        Device->SetRenderState(D3DRS_STENCILPASS,  D3DSTENCILOP_INVERT);
//        Device->SetRenderState(D3DRS_STENCILFAIL,  D3DSTENCILOP_REPLACE);

        // position reflection
        D3DXMATRIX W, T, R;
        D3DXPLANE plane(0.0f, 0.0f, 1.0f, 0.0f); // xy plane
        D3DXMatrixReflect(&R, &plane);

        D3DXMatrixTranslation(&T,
                TeapotPosition.x,
                TeapotPosition.y,
                TeapotPosition.z);

        D3DXMatrixMultiply(&W, &T, &R);

        // clear depth buffer and blend the reflected teapot with the mirror

        Device->Clear(0, 0, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

        Device->SetRenderState(D3DRS_SRCBLEND,  D3DBLEND_DESTCOLOR);
        Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);

        // Finally, draw the reflected teapot
        Device->SetTransform(D3DTS_WORLD, &W);
        TeapotMtrl = d3d::GREEN_MTRL;
        Device->SetMaterial(&TeapotMtrl);
        Device->SetTexture(0, 0);

//        Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
        Teapot->DrawSubset(0);
       
        // Restore render states.
        Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
        Device->SetRenderState( D3DRS_STENCILENABLE, false);
        Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);

5

主题

12

帖子

15

积分

新手上路

Rank: 1

积分
15
发表于 2006-2-3 21:02:00 | 显示全部楼层

Re:关于 mirror的wenti

Device->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 4);
执行这里的时候出了两边的墙为0x1外,其它object在模板缓冲中的值都为0x0.包括茶壶本身。
Device->SetRenderState(D3DRS_STENCILFUNC,  D3DCMP_GREATER);
表明ref > value即0x1 > value。所以茶壶本身也会通过测试,所以它也会和自己的倒影相混合,进而进行渲染。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-23 09:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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