[D3D10] Render to Texture

Started by
4 comments, last by pierceblaylock 16 years, 1 month ago
Question about performing a render to texture. I had a look at the SDK examples to work out how to perform a RTT, and finally have something working that just renders a quad to my texture. The problem is, that my quad is being rendered using a vertex shader so the vertices for the quad are going through the full vertex shader transformation. Since I'm just rendering a color to a 2D texture, I'm wondering if I can perform a RTT using the pixel shader only. I just want to be able to calculate the color of each pixel in the texture within a pixel shader. I don't care about vertices or geometry. If I try and set up a technique that uses only a pixel shader (i.e. set the vertex shader to NULL), then the CreateInputLayout function fails. I'm assuming it fails because it cannot locate the input signature required for the vertices that will be passed to the vertex shader. Therefore, my question is, how can I do away with the vertex shader and only run a pixel shader on my RTT? Do I still need my quad vertices (which are stored in a vertex and index buffer) that I render to the texture? Should I be rendering my quad using transformed vertices? If so, how do I do that (link to some info showing an example would be great). My attempts at this have failed. It forces me to pass untransformed vertices to the shader, which I then need to transform in the vertex shader, which is the whole thing I'm trying to do away with...
Advertisement
I'm not sure if this is what you want, but look up

"Using the Input-Assembler Stage without Buffers"

in the documentation index.
-----Quat
Hmmm... I just looked up your reference. It is on the right path, but I notice that they still use a vertex shader to render triangles.

The reason why I'm asking this question in the first place is because I have some D3D9/SM3 code that I'm trying to convert to D3D10/SM4. I'll show you some important parts of the D3D9/SM3 code.

Firstly, there is the vertex declaration, which you can see describes a pre-transformed vertex with a single texture coordinate.

struct 2dvertex{	D3DXVECTOR4 xyzw;	D3DXVECTOR2 uv;};
In D3D9, the code uses DrawPrimitiveUp to render the quad. D3D10 doesn't have this, so instead I just build a small vertex and index buffer to render the quad using an indexed draw call. Seems like a total overkill, but not sure of any other way to do it at this stage.

The D3D9 pixel shader uses the following code.

struct pixelinput {	float4 pos : POSITION;	float2 t0 : TEXCOORD0;};float4 ps(pixelinput in) : COLOR{    return float4(0, 0, 1, 1);}technique render {	pass 0	{	 		ZEnable = false;		ZWriteEnable = false;		AlphaBlendEnable = false;    		FVF = XYZRHW | TEX1;    		PixelShader = compile ps_3_0 ps();	}		}
As you can see, there is no vertex shader there. I can't seem to reproduce this in D3D10/SM4.
Your DX9 code is using the fixed function pipeline for vertices. That's why there's no vertex shader. The line in your technique that says "FVF = XYZRHW | TEX1;" is what gives this away. FVF stands for Flexible Vertex Format and is used for the fixed function pipeline. XYZRHW means that the vertices have already been transformed and therefor the code doesn't need to set the associated matrices.

DX10 does not have a fixed function pipeline. You have to include at least a minimal vertex shader. Now, this shader can just be a pass-through if you're using transformed vertices. Your shader could output just the position and texture coordinates exactly as it receives them.

neneboricua
My understanding is that neneboricua19 is correct. Here are a couple of further comments which might help.

I found a comment about 2D drawing at the end of the FixedFuncEMU sample docs. You might want to take a look at it.

You don't need to create an index buffer for a quad. Use a triangle strip representation.
Thank you neneboricua19. I know all about the lack of a FFP in D3D10, I just can't believe I overlooked that. Thanks for pointing that out.

ET3D, you have raised a good point about using a triangle strip. I'll do that and get rid of the index buffer. However, I couldn't find the reference you were speaking of. I looked up the FixedFuncEMU sample documentation and had a read through it, but couldn't find what you may have been referring to. Were you just referring to the triangle strip here? If not, can you provide some more details on the information you refer to. Thanks.

This topic is closed to new replies.

Advertisement