Sign in to follow this  
Noxil

2D with DirectX

Recommended Posts


Hello.

What I basically want to know is, is it possible to draw 2D (UI) with shaders?

I know how to use shaders to draw 3D objects.
But the only way I know how to draw 2D objects is:


sprite->Begin();
sprite->Draw(texture, 0, 0, 0, D3DCOLOR_XRGB(255, 255, 255));
sprite->End();



I have googled alot, but cant seem to find anything.

Share this post


Link to post
Share on other sites
There's two types of shader (In DX9), vertex shaders and pixel shaders. Vertex shaders take one input vertex do "something" to it, and spit out a vertex in screen space (Essentially). Pixel shaders take one pixel of a primitive, and decide what colour it should be.

For a vertex shader, you need to have an input vertex to do "something" to, so you can generate an output vertex.
For a pixel shader, you could in theory have a shader generate a pixel colour based on some variables like the pixel position and some other input parameters, and ignore everything else if you want.

What exactly are you trying to do with shaders that you can't get without them?

Share this post


Link to post
Share on other sites

Well id just like to experiment abit :)

And another reason would be, that I cant really do any cool UI cause im not
really sure how to do the alpha properly.

Im using D3DXCreateTextureFromFileEx to create my textures and it only takes one color as input for what to be alpha?

Share this post


Link to post
Share on other sites
Quote:
Original post by Noxil
Well id just like to experiment abit :)
Fair enough [smile]

Quote:
Original post by Noxil
And another reason would be, that I cant really do any cool UI cause im not
really sure how to do the alpha properly.

Im using D3DXCreateTextureFromFileEx to create my textures and it only takes one color as input for what to be alpha?
You should only be using the colour key from D3DXCreateTextureFromFileEx if your source image doesn't have an alpha channel. If you want "real" alpha, use a file format that has an alpha channel in it, like TGA or PNG and set the colour key parameter to 0 to disable it.

Share this post


Link to post
Share on other sites

Ah thank you, that will clearly help alot with the alpha problems :)

I have been looking around some more and come across, postprocess where you only use a pixleshader to affect the rendering.

How dose that work?

If im not mistaken you render your scene to a texture and then render only that texture?

Share this post


Link to post
Share on other sites
Yup, instead of rendering the scene to the screen, you render it to a texture. Then you render that texture to the screen as one big quad. That lets you perform various effects on the whole scene when you're rendering the quad to the screen, such as "wobbling" the screen (Render the texture as a grid, and move the vertices of the grid around), blurring, and various pixel shader things.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this