Jump to content
  • Advertisement
Sign in to follow this  
akira32

XNA, draw a quad(full screen) with shader

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I render a elephant into a render target and then use the render target to draw a quad(full screen).
But I can not use the quad in screen. I think that is rendering problem.

I also put my complete source code at: https://skydrive.liv...AFtjlRG9yqoz7d4
My quad max file: https://skydrive.liv...AMf6yH0lBxeac9E

My quad faces the position z axis and cullmode=none. In quad max file, the x is between -1 to +1, the y is between -1 to +1.
I put my shader code as below for rendering a full-screen quad:
Does somebody know how to solve this problem?


1 texture RenerTargetTexture
2 <
3 string ResourceName = "RT";
4 string UIName = "RenerTargetTexture";
5 string ResourceType = "Texture";
6 >;
7
8 sampler2D RT = sampler_state
9 {
10 Texture = <RenerTargetTexture>;
11 MinFilter = LINEAR;
12 MagFilter = LINEAR;
13 MipFilter = LINEAR;
14 };
15
16 struct VS_OUTPUT
17 {
18 float4 Pos : POSITION;
19 float2 TexCoord : TEXCOORD0;
20 };
21
22 VS_OUTPUT vs_main( float4 inPos: POSITION, float2 inTexCoord: TEXCOORD0)
23 {
24 VS_OUTPUT Out=(VS_OUTPUT)0;
25
26 Out.Pos = float4(inPos.xy, 0.0, 1.0);
27 Out.TexCoord.x = 0.5 * (1 + inPos.x);
28 Out.TexCoord.y = 0.5 * (1 - inPos.y);
29
30 return Out;
31 }
32
33 float4 ps_main( VS_OUTPUT input ) : COLOR
34 {
35 float4 Color1 = tex2D(RT, input.TexCoord);
36 return Color1;
37 }
38
39 technique Technique1
40 {
41 pass Pass1
42 {
43 VertexShader = compile vs_2_0 vs_main();
44 PixelShader = compile ps_2_0 ps_main();
45
46 CullMode = none;
47 }
48 } 47 } 48 }


In Draw function:


1 GraphicsDevice.SetRenderTarget(m_RenderTarget1);
2
3 GraphicsDevice.Clear(Color.Black);
4 m_ElephantModel.DrawWithEffect1(m_camera.view, m_camera.projection, m_effect_orginal_model);
5 GraphicsDevice.SetRenderTarget(null);
6
7 GraphicsDevice.Clear(Color.White);
8 m_QuadModel.DrawWithEffect2(null, m_effect_final_result);


Even I change the shader code as below, I also cannot see any red pixel on the screen.
33 float4 ps_main( VS_OUTPUT input ) : COLOR
34 {
35 float4 Color1 = tex2D(RT, input.TexCoord);
36 return float4(1,0,0,1);
37 }

Share this post


Link to post
Share on other sites
Advertisement
The shader looks right so I'm guessing the problem is with the quad.

The vertices of fullscreen quads are usually generated at runtime... (Whats the point of using storing 4 points in a file rolleyes.gif ).

Try to create the quad at runtime like this:

PosTexCVertex vertices[] =
{
PosTexCVertex(-1.0f, -1.0f, 0.0f, 0.0f, 1.0f),
PosTexCVertex(-1.0f, 1.0f, 0.0f, 0.0f, 0.0f),
PosTexCVertex(1.0f, 1.0f, 0.0f, 1.0f, 0.0f),
PosTexCVertex(1.0f, -1.0f, 0.0f, 1.0f, 1.0f)
};


You can also run your program in PIX and see whats happening in the quad draw call.

Share this post


Link to post
Share on other sites
I just downloaded the source code, ran the program in PIX and the problem is indeed in your quad max file.

As far as I can tell the y-coordinate of each vertice in the file is always 0, on the other hand, the both the x and z-coordinates are changing between -1 and -0.5 so you probably didn't create the quad correctly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!