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

Amateur Managed DirectX question (pixel shaders)

Started by LTKeene Feb 2, 2010 at 12:15 PM 2 replies 1.2k views
Original Post
LTKeene
LTKeene
Hi folks, amateur question here regarding managed directX usage: I've got an EXTREMELY basic application wherein I am always drawing to the same screen coordinates...specifically, I have two triangles arranged into a square on which I am mapping a texture. Therefore, I am using transformed vertices and just hard-coding the coordinates to make life easy so that I don't have to set-up a camera, World/View transformation matrices, etc. After drawing these transformed and texture mapped vertices, I would then like to draw another two transformed triangles, arranged the same way (into a square), overlapping a portion of the original two texture mapped triangles I drew initially. The pixels that make up this new triangle pair need to be colored/alpha-blended according to the content of a second texture. I plan on using the pixel shader to do this since it's time consuming to use the CPU. My question is: it IS possible to use a pixel shader with transformed vertices, right? All the tutorials I'm reading only use vertex buffers that are fed to the vertex shader and transformed in there according to a vertex shader program, followed by a pixel shader program. I haven't actually seen anyone using just pixel shaders with the "Transformed" vertex format (probably because there is hardly any situation when you would do this...except mine).
MJP
MJP
Quote:
Original post by LTKeene
My question is: it IS possible to use a pixel shader with transformed vertices, right?


Yes, you can do that. Just set your pixel shader and then set your vertex shader to NULL.
LTKeene
LTKeene
Great! Thanks for the reply.
JohnnyCode
JohnnyCode
yes, you do not need to transform verticies but hardcoding projection space vectors ... sounds strange. What if you wanted to position twice smaller quad at a certain position on screen? You add values to positon and scale positions. That is what transformation matrix is doing.If you want to position a twice smaller quad in the middle of left upper part of screen you compose the scale component and translate component of transformation matrix.

scalebyx,0,0,positionx
0,scalebyy,0,positiony
0,0,scalebyz,positionz
0,0,0,1.0

It is very benefitial to do instructions in vertex shaders.
There are few hundrets of GPU processors computing vertex data paralely upon data streams you provided for elements. the computed data are written to processor register memory, not GPU heap(local variables, vertex outputs). So if GPU prepars pointers for every processor(devide verticies) to access shared memory... you should not have vfunction null.

realize what time it takes to render a triangle and what time it takes to render 1000 triangles , in one draw call(mesh). The time is nearly the same, so 1000 triangles add up to the final value 2 percents.

In fact, vertex shader does not read heap memory (you can not sample in vs for example), the pixel shader only if it samples a texture or at z succed when it draws to render target.

So if you get yourself a shader that does not sample a texture, you will be having instructions computed parallel, writing only to proccessor register memory .Graphic card is one insane computer . It is designed to compute instructions on stream of elemts in insane amount of time.

The most time in applications is spent on writing to RAM, then on reading from RAM, and then on CPU instructions with register values.
Consider:

int v=2,s=3;
while (1==1)
{
if (v==s)
continue;
callbackforexit();
}
And consider:

int v=2,s=3;
while (1==1)
{
if (v==s)
continue;
++v;++v;
callbackforexit();
}

so minimaze writing to memory, 1333Mhz RAM frequency means that you write 4 bytes to a memory in about 1/40 000 of a second.

Topic Locked

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

Sign in to reply to this topic.