Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Screen space quad problem

Started by akhin Mar 19, 2011 at 4:17 PM 2 replies 1k views
Original Post
akhin
akhin
Hi all ,

I have an interesting problem regarding the single quad I am using for my post processing :

The single quad I render is just covers top half of the screen as in links below :

Original Broken

That is how I create and render it :

...
ID3DXMesh* PPQuadMesh;

struct VertexPostProcess
{
VECTOR3 m_translation;
float u;
float v;

VertexPostProcess(float x, float y, float z, float tu, float tv)
{
m_translation.x = x;
m_translation.y = y;
m_translation.z = z;
u = tu;
v = tv;
}
};
#define VERTEXPOSTPROCESS_FVF (D3DFVF_XYZ | D3DFVF_TEX1 )
#define VERTEXPOSTPROCESS_FVF_SIZE D3DXGetFVFVertexSize( VERTEXPOSTPROCESS_FVF )
...

void CreateQuad()
{
D3DXCreateMeshFVF(2, 4, D3DXMESH_MANAGED, VERTEXPOSTPROCESS_FVF, m_graphicsDevice, &PPQuadMesh);

VertexPostProcess* v = 0;
PPQuadMesh->LockVertexBuffer(0, (void**)&v);

v[0] = VertexPostProcess( -1.0f, -1.0f, 1.0f, 0.0f, 1.0f);
v[1] = VertexPostProcess( -1.0f, 1.0f, 1.0f, 0.0f, 0.0f);
v[2] = VertexPostProcess( 1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
v[3] = VertexPostProcess( 1.0f, -1.0f, 1.0f, 1.0f, 1.0f);

PPQuadMesh->UnlockVertexBuffer();

WORD* i = 0;
PPQuadMesh->LockIndexBuffer(0, (void**)&i);

i[0] = 0; i[1] = 1; i[2] = 2;
i[3] = 0; i[4] = 2; i[5] = 3;

PPQuadMesh->UnlockIndexBuffer();

std::vector<DWORD> adjacencyBuffer(PPQuadMesh->GetNumFaces() * 3);
PPQuadMesh->GenerateAdjacency(0, &adjacencyBuffer[0]);
}

void Render()
{
m_effect.SetTexture("diffuseTexture",m_texture);

unsigned int nPass ;
m_effect->BeginRender(&nPass);

for(int i = 0 ;i<nPass;i++)
{
m_effect.BeginPass(i);

PPQuadMesh->DrawSubset(0);

m_effect->EndPass();
}

m_effect->EndRender();
}



That it the simple shader , as there is no transformations in vertex shaders :



texture diffuseTexture;

sampler ColorSampler = sampler_state
{
Texture = <diffuseTexture>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
};

struct A2V
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};

struct V2P
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};

void VS(in A2V IN, out V2P OUT)
{
OUT.Position = IN.Position;
OUT.TexCoord = IN.TexCoord;
}

float4 PSScene(in V2P IN) : COLOR0
{
return tex2D(ColorSampler, IN.TexCoord);
}

technique Scene
{
pass Pass0
{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PSScene();
}
}

akhin
akhin
Just to make a quick test , I returned [font="Consolas"][color="#0000ff"]float4([color="#000080"][color="#000080"][color="#000080"]1,[color="#000080"][color="#000080"][color="#000080"]1,[color="#000080"][color="#000080"][color="#000080"]1,[color="#000080"][color="#000080"][color="#000080"]1); from the pixel shader shading the screen quad and yeah it covers the whole screen So it is not my quad aligning with the screen . What would you suggest to look at for the problem ?

[/font][color="#0000ff"]

[font="Consolas"] [/font]

[font="Consolas"][font="Consolas"][/font][/font]
Magmatwister
Magmatwister

Just to make a quick test , I returned [font="Consolas"][color="#0000ff"]float4([color="#000080"][color="#000080"][color="#000080"]1,[color="#000080"][color="#000080"][color="#000080"]1,[color="#000080"][color="#000080"][color="#000080"]1,[color="#000080"][color="#000080"][color="#000080"]1); from the pixel shader shading the screen quad and yeah it covers the whole screen So it is not my quad aligning with the screen . What would you suggest to look at for the problem ?

[/font]






Ok, I haven't tested this, but try doing this: (Probably wrong but It's an attempt, I'm a bit rusty on this stuff) - and I suggest you check over your texture coordinates and or fullscreen texture (try using PIX?)


[color="#1C2837"][color="#000000"] v[color="#666600"][[color="#006666"]0[color="#666600"]] [color="#666600"]= [color="#660066"]VertexPostProcess[color="#666600"]( [color="#666600"]-[color="#006666"]1.0f[color="#666600"], [color="#666600"]-[color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]0.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"]);[color="#000000"]
v[color="#666600"][[color="#006666"]1[color="#666600"]] [color="#666600"]= [color="#660066"]VertexPostProcess[color="#666600"]( [color="#666600"]-[color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]0.0f[color="#666600"], [color="#006666"]0.0f[color="#666600"]);[color="#000000"]
v[color="#666600"][[color="#006666"]2[color="#666600"]] [color="#666600"]= [color="#660066"]VertexPostProcess[color="#666600"]( [color="#006666"]1.0f[color="#666600"],[color="#000000"] -[color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"]);[color="#000000"]
v[color="#666600"][[color="#006666"]3[color="#666600"]] [color="#666600"]= [color="#660066"]VertexPostProcess[color="#666600"]( [color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"], [color="#006666"]1.0f[color="#666600"],[color="#000000"] 0[color="#006666"].0f[color="#666600"]); [color="#660066"]PPQuadMesh[color="#666600"]->[color="#660066"]UnlockVertexBuffer[color="#666600"]();[color="#000000"]

WORD[color="#666600"]*[color="#000000"] i [color="#666600"]= [color="#006666"]0[color="#666600"]; [color="#660066"]PPQuadMesh[color="#666600"]->[color="#660066"]LockIndexBuffer[color="#666600"]([color="#006666"]0[color="#666600"], [color="#666600"]([color="#000088"]void[color="#666600"]**)&[color="#000000"]i[color="#666600"]);[color="#000000"]

i[color="#666600"][[color="#006666"]0[color="#666600"]] [color="#666600"]= [color="#006666"]0[color="#666600"];[color="#000000"] i[color="#666600"][[color="#006666"]1[color="#666600"]] [color="#666600"]= [color="#006666"]1[color="#666600"];[color="#000000"] i[color="#666600"][[color="#006666"]2[color="#666600"]] [color="#666600"]= [color="#006666"]2[color="#666600"];[color="#000000"]
i[color="#666600"][[color="#006666"]3[color="#666600"]] [color="#666600"]= [color="#006666"]2[color="#666600"];[color="#000000"] i[color="#666600"][[color="#006666"]4[color="#666600"]] [color="#666600"]= [color="#006666"]1[color="#666600"];[color="#000000"] i[color="#666600"][[color="#006666"]5[color="#666600"]] [color="#666600"]= [color="#006666"]3[color="#666600"];
Currently trying to make a planet renderer. After many hours of work, somehow I know It'll never be complete.
Also, If I help you, please give me an ++
akhin
akhin
I fixed it , the problem was I was passing wrong height and width for texture creation
now I am using a surface descriptor to find out backbuffer height and width programatically

Thanks for your reply

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.