2D with DirectX

Started by
5 comments, last by Noxil 13 years, 6 months ago

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.
Advertisement
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?

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?
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.

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?
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.

Ah, thanks! :)

I think I got what I came for, time to try some stuff out!

This topic is closed to new replies.

Advertisement