• Advertisement
Sign in to follow this  

Help with pixel shaders

This topic is 4519 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

Hi guys! I need some help because i dont find the way to do that. I have made a rectangle defining four vertexs. And I mapped inside a texture (image) of the same dimensions of my rectangle After that, y aplied him a transformation( rotarion and translation). So each vertex position will have fractional values but coordinate vales are unchanged. So, before pixel shader, the rasterizer will interpolate texture values. If I'm not wrong, the only thing it would do, is give values for each pixel between 0 and 1 with steps of 1/width and 1/height in x and y axes. Doesn't care about the transformation before. So, what I need is to have the position values for each pixel!!!!!! For example, if I have defined a rectangle of dimensions 200*256 and I make a translation of half pixel towards x axe. I need to have the values ... 0.5, 1.5, 2.5 ....! Because I'm looking to get the floor value (to address me after to another image) and fractional values ( to compute a kind of histogram). In ps_3_0 is written that oPos give you the pixel coordinates in screen space. What does mean exactly ?? Does it give me fractional values (o.5, 1.5, 2.5...) or always fllor values (0,1,2...)?? Does values will be in the range [0,1] or will be in the dimensions of my texture or backbuffer?? Or is exactly what I,m looking for?? It is possible to do that with earlier versions of pixel shader as ps_2.0 because, graphic cards that supports 3_0 are really expensiver. One thing more, does anyone have a list, of graphic cards that supports each version?? Thanks, and hope you will be able to help me!! Jesus

Share this post


Link to post
Share on other sites
Advertisement
Correct me if I'm wrong, but it sounds to me that you're just looking for the texture coordinate of the pixel, right? Well this should come straight from your program... for instance, if you're using FX files you will have a vertex shader with a TEXCOOD input, like so



VS_OUTPUT Transform(
float3 inputPosition : POSITION,
float2 inputTexCoord : TEXCOORD0
)
{
...
}

you can pass that inputTexCoord out to your pixel shader in a float2 TEXCOORD0 and then in your pixel shader you can access it (in ps2.0 and above). So suppose my variable in TEXCOORD0 is called texCoord... I can access the U coord with texCoord.x and the V coordinate with texCoord.y

I hope this helps. I can post more code if you don't quite follow the process. And let me know if I'm way off on what your asking.

PS. The ATI Radeon 9700 is relatively old, cheap, and a great card. It supports ps2.0 and I haven't upgraded yet since it runs about as well as the midrange "newer" cards anyway.

Share this post


Link to post
Share on other sites
All GeForce 6xxx support SM3 and the 6600 and 6200 aren't expensive at all.

GeForce 7xxx/6xxx - SM3
GeForce 5xxx - SM2
GeForce 4Ti - SM1.3
GeForce 3 - SM1.1
Radeon Xxxx - SM 2.0b
Radeon 9xxx - SM 2
Radeon 8500 - SM1.4

Share this post


Link to post
Share on other sites
Hi!
Thanks a lot...but is not exactly what I'm looking for.
Books in Cg ..I think is Opengl no? I'm programing in DirectX ...

About the code you propose me...!
Only a question...
Is it possible before give texture coordinates, transformate them in the vertex shader ??
If I have defined four vertex with this texture coordinates
vertex 1 (u,v) = (0, 0)
vertex 2 (u,v) = (1, 0)
vertex 3 (u,v) = (0, 1)
vertex 4 (u,v) = (1, 1)

Can I make a translation of 0.055 for example in x axe? image x dimension = 100
So a translation of 5.5 pixels ?? (5.5/100=0.055)

vertex 1 (u,v) = (0.055, 0)
vertex 2 (u,v) = (1.055, 0)
vertex 3 (u,v) = (0.055, 1)
vertex 4 (u,v) = (1.055 .1)

So when I get texture coordinates...and multypliing for the image size .. ! Watch that pixels in (3,0) it's now (3+5.5,0) = (8.5 , 0) and so
get the floor of this x coordinate (8) and the frac (0.5) ???

What will happen with 1.055 since texture coordinates must be in the range [0,1] ??

And finally...it's the interpolator of the rasterizer, going to make a good interpolation for each pixel, if in case of a simple translation I make a rotation??

This is exatly what I'm looking for but I don't know if it is possible.

Anny suggestion ??

Thanks again!
Jesus

Share this post


Link to post
Share on other sites
I think what you asking is mostly a matter of scale. If you divide you pixel shader by 100 you will change the scaling of the texture -- so Coord.x/100 will make the image smaller and it will then TILE, since that is the default setting. You can set other methods like clamp and stuff too. As for making transformations in the pixel shader, as I think I mentioned, you can do any transforms you want in shader model 2, but shader model 1 doesn't support it. In fact, games tend to make a lot of use of applying sine functions to the texture coordinates in pixel shader to create wavey "heat" effects. Ultimately, the best advice I can give you is to set up a quick program with a textured quad aligned toward the screen and just play around with the pixel and vertex shaders. See what you can do, see what gives an error, see what crashes it. It's really the only way to get a proper feel for it.

Oh, and you're right. HLSL is the directX standard for shaders, but you can program in whatever you like and save it as assembly and then it will work with any of the shader languages. But using assembly shaders requires a different implementation.

Share this post


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

  • Advertisement