DirectX:2 个精灵多边形之间的小变形

发布于 2024-10-19 13:40:52 字数 1055 浏览 10 评论 0原文

您好,我很长时间以来都使用相同的方式使用 directx 渲染精灵,但在这里我在纹理中渲染屏幕,然后在屏幕上使用大精灵渲染它。

对于相机我使用的是: vUpVec=D3DXVECTOR3(0,1,0); vLookatPt=D3DXVECTOR3(0,0,0); vFromPt=D3DXVECTOR3(0,0,-1);

D3DXMatrixLookAtRH( &matView, &vFromPt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

D3DXMatrixOrthoRH( &matProj, 1,1, 0.5f, 20 );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

并渲染精灵: 自定义顶点* v; spritevb->Lock( 0, 0, (void**)&v, 0 );

v[0].position = D3DXVECTOR3(-0.5f,-0.5f,0); v[0].u=0; v[0].v=1;
v[1].position = D3DXVECTOR3(-0.5f,0.5f,0); v[1].u=0; v[1].v=0;
v[2].position = D3DXVECTOR3(0.5f,-0.5f,0); v[2].u=1; v[2].v=1;
v[3].position = D3DXVECTOR3(0.5f,0.5f,0); v[3].u=1; v[3].v=0;

spritevb->Unlock();


g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

这是非常基本的并且有效,我的精灵在屏幕上完整渲染。 但通过仔细观察,我发现屏幕上有一条小对角线(在两个多边形之间),不是彩色的,但就像它们没有完美定位一样。

我考虑过过滤并尝试删除所有内容,但也许我忘记了一些东西......

谢谢

Hello I use the same way to render sprites with directx from a long time but here I am rendering the screen in a texture and then render it with a big sprite on the screen.

For the camera I use that:
vUpVec=D3DXVECTOR3(0,1,0);
vLookatPt=D3DXVECTOR3(0,0,0);
vFromPt=D3DXVECTOR3(0,0,-1);

D3DXMatrixLookAtRH( &matView, &vFromPt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

D3DXMatrixOrthoRH( &matProj, 1,1, 0.5f, 20 );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

And to render the sprite:
CUSTOMVERTEX* v;
spritevb->Lock( 0, 0, (void**)&v, 0 );

v[0].position = D3DXVECTOR3(-0.5f,-0.5f,0); v[0].u=0; v[0].v=1;
v[1].position = D3DXVECTOR3(-0.5f,0.5f,0); v[1].u=0; v[1].v=0;
v[2].position = D3DXVECTOR3(0.5f,-0.5f,0); v[2].u=1; v[2].v=1;
v[3].position = D3DXVECTOR3(0.5f,0.5f,0); v[3].u=1; v[3].v=0;

spritevb->Unlock();


g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

This is very basic and works, my sprite is rendered on the screen full.
But by looking closer I see that there's a small diagonal line through the screen (between the 2 polygons) not a colored one but like if them weren't perfectly positionned.

I thought about filtering and tried removing everything but maybe I forget something...

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-10-26 13:40:52

渲染到全屏的最佳方法是不定义任何相机位置。

用作输入位置

SimpleVertex vertices[] =
    {
        { XMFLOAT3( -1.0f, 1.0f, 0.5f ), XMFLOAT2( 0.0f, 0.0f ) },
        { XMFLOAT3( 1.0f, 1.0f, 0.5f ), XMFLOAT2( 1.0f, 0.0f ) },
        { XMFLOAT3( 1.0f, -1.0f, 0.5f ), XMFLOAT2( 1.0f, 1.0f ) },
        { XMFLOAT3( -1.0f, -1.0f, 0.5f ), XMFLOAT2( 0.0f, 1.0f ) },
    };

如果您在顶点着色器中

VS_OUTPUT RenderSceneVS( VS_INPUT input )
{
    VS_OUTPUT Output;

    Output.Position = input.Position;

    Output.TextureUV = input.TextureUV; 

    return Output;    
}

,您也可以全屏渲染,而不必担心视锥体。使用这个我从来没有看到两个三角形之间有任何线。

To render to full screen best way is to not define any camera positions.

If you use as input positions

SimpleVertex vertices[] =
    {
        { XMFLOAT3( -1.0f, 1.0f, 0.5f ), XMFLOAT2( 0.0f, 0.0f ) },
        { XMFLOAT3( 1.0f, 1.0f, 0.5f ), XMFLOAT2( 1.0f, 0.0f ) },
        { XMFLOAT3( 1.0f, -1.0f, 0.5f ), XMFLOAT2( 1.0f, 1.0f ) },
        { XMFLOAT3( -1.0f, -1.0f, 0.5f ), XMFLOAT2( 0.0f, 1.0f ) },
    };

and in the Vertex Shader do

VS_OUTPUT RenderSceneVS( VS_INPUT input )
{
    VS_OUTPUT Output;

    Output.Position = input.Position;

    Output.TextureUV = input.TextureUV; 

    return Output;    
}

you get a render to full screen as well without having to worry about the viewing frustrum. Using this I never saw any lines between the two triangles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文